com.tecnick.junitconv
Class JUnitConv

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by com.tecnick.junitconv.JUnitConv
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class JUnitConv
extends java.applet.Applet

Title: JRelaxTimer
Description: JUnitConv is an universal Units of Measure Converter, it converts numbers from one unit of measure to another. Built as a Java Applet, JUnitConv is platform-independent and highly-configurable, it supports an unlimited number of Units Categories, Units of Measure and Multiplier Prefixes that could be customized using external text files. You could setup your own data files using your preferred spoken language, units categories, units definitions and multiplier prefixes. The default configuration data files contains 580 basic units of measure definitions divided in 31 categories and 27 multiplier prefixes for a total of 15660 composed units.
Copyright (c) 2002-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com
Project homepage: http://junitconv.sourceforge.net
License: http://www.gnu.org/copyleft/gpl.html GPL 2

Version:
1.0.004
Author:
Nicola Asuni [www.tecnick.com].
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private)  java.applet.Applet a
           
private  java.awt.Choice category_selector
          Selector for units category.
private  int current_category
          Current category.
private  int current_in_multiplier
          Current input multiplier.
private  int current_in_unit
          Current input unit.
private  java.lang.Double current_in_value
          Current input value.
private  int current_out_multiplier
          Current output multiplier.
private  int current_out_unit
          Current output unit.
private  java.lang.Double current_out_value
          Current output value.
private  int current_precision
          Current precision (number of decimals).
private  int current_unit_offset
          Current unit offset.
(package private)  java.awt.Font default_font
          Default font.
(package private)  java.awt.Font group_font
          Font for applet description.
private  java.awt.TextArea in_description
          Input unit of measure description (definition).
private  java.awt.Choice in_multiplier_selector
          Selector for input multiplier (SI prefixes).
private  java.awt.Choice in_unit_selector
          Selector for input unit type.
private  java.awt.TextField in_value
          Input value.
(package private)  java.awt.event.ActionListener jumpToUrl
          When a menu item is clicked, jump to corresponding URL
private static java.lang.String JUNITCONV_VERSION
          Software version
(package private)  java.awt.Font label_font
          Font for labels.
private  java.awt.TextArea out_description
          Output unit of measure description (definition).
private  java.awt.Choice out_multiplier_selector
          Selector for output multiplier (SI prefixes).
private  java.awt.Choice out_unit_selector
          Selector for output unit type.
private  java.awt.TextField out_value
          Output value.
(package private)  java.awt.Color p_background_color
          Background color.
(package private)  java.lang.String p_category_data_file
          URL of text data file containing units categories data.
(package private)  java.lang.String[] p_category_name
          Array of category names.
private  java.lang.String p_copyright
          Label for the link button.
(package private)  java.lang.String p_encoding
          Charset encoding.
(package private)  java.lang.String p_font
          Font name.
(package private)  int p_font_size
          Font size.
(package private)  int p_font_style
          Font style (PLAIN, BOLD, ITALIC).
(package private)  java.awt.Color p_foreground_color
          Foreground color.
(package private)  java.lang.String[] p_label
          Array of string labels.
(package private)  java.lang.String p_labels_data_file
          URL of text data file containing labels definitions.
private  java.lang.String p_link
          Author's homepage.
(package private)  java.lang.String p_multiplier_data_file
          URL of text data file containing multiplier definitions.
(package private)  java.lang.String[] p_multiplier_description
          Array of Multiple/Submultiple descriptions.
(package private)  java.lang.String[] p_multiplier_name
          Array of Multiple/Submultiple names.
(package private)  java.lang.Double[] p_multiplier_value
          Array of Multiple/Submultiple values.
(package private)  java.lang.String p_page_encoding
          HTML page encoding.
private  java.lang.String p_target
          Default frame target where to open author homepage
(package private)  java.lang.Integer[] p_unit_category_id
          Array of category ID (link to category table: p_category_id).
(package private)  java.lang.String p_unit_data_file
          URL of text data file containing units data.
(package private)  java.lang.String[] p_unit_description
          Array of unit of measure descriptions.
(package private)  java.lang.String[] p_unit_name
          Array of unit of measure names.
(package private)  java.lang.Double[] p_unit_offset
          Array of unit of measure conversion offsets.
(package private)  java.lang.Double[] p_unit_power
          Array of powers to apply to unit multipliers.
(package private)  java.lang.Double[] p_unit_scale
          Array of unit of measure conversion scale factors.
(package private)  java.lang.String[] p_unit_symbol
          Array of unit of measure symbols.
(package private)  java.awt.Panel panel
           
private  java.awt.Choice precision_selector
          Selector for required precision.
private static long serialVersionUID
          serialVersionUID
private  int textarea_cols
          Number of columns for textarea (the area that display unit-of-measure definition).
private  int textarea_rows
          Number of rows for textarea (the area that display unit-of-measure definition).
(package private)  java.awt.Font title_font
          Font for title.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JUnitConv()
          Applet constructor (void)
 
Method Summary
private  java.awt.Component addLabel(java.awt.Component comp, java.lang.String label)
          add label to a component
private  void category_selector_itemStateChanged(java.awt.event.ItemEvent e)
          change units on units selctors by selected category
 void destroy()
          Destroy the applet
private  void fillUnitsSelector(int category)
          Fill units selectors filtering by category
 java.lang.String getAppletInfo()
          Get Applet information.
private  java.lang.String getDefaultValue(java.lang.String str, java.lang.String def)
          Return "def" if "str" is null or empty.
private  java.lang.String getEncodedString(java.lang.String original, java.lang.String encoding_in, java.lang.String encoding_out)
          Convert string to specified encoding.
private  int getFontStyleCode(java.lang.String stylename)
          return the int associated to font style
private  java.lang.String getParameter(java.lang.String key, java.lang.String def)
          Get applet parameter value, return default if void.
(package private)  void getParameters()
          Get the applet parameters from HTML page.
private  void getSelectedIndexes()
          get current selected index on selectors
private  void in_multiplier_selector_itemStateChanged(java.awt.event.ItemEvent e)
          get selected input multiplier index
private  void in_unit_selector_itemStateChanged(java.awt.event.ItemEvent e)
          get selected input unit index
private  void in_value_itemStateChanged(java.awt.event.TextEvent e)
          get input value
 void init()
          Initialize the applet
private  void jbInit()
          Component initialization
private  void out_multiplier_selector_itemStateChanged(java.awt.event.ItemEvent e)
          get selected output multiplier index
private  void out_unit_selector_itemStateChanged(java.awt.event.ItemEvent e)
          get selected output unit index
private  java.lang.Double parseNumber(java.lang.String num)
          simple number parser (allows to use math operators operators: +,-,*,/,^,P=PI,X=exp) operator precedence: P X * / + - ^
private  void precision_selector_itemStateChanged(java.awt.event.ItemEvent e)
          change result precision (number of decimals)
 void readDataFile(int filetype, java.lang.String filename)
          Read menu items data from external text file "\n" separate items "\t" separate values
private  double roundNumber(double in_number, int precision)
          return a rounded number
private  void setCategoriesArraySize(int i)
          set arrays size for unit categories
private  void setMultipliersArraySize(int i)
          set arrays size for unit categories
private  void setUnitCategory()
          get selected category and set other parameters
private  void setUnitsArraySize(int i)
          set arrays size for units
private  java.net.URL setURL(java.lang.String link)
          Computes full, canonical URL from a relative specification.
private  java.lang.String[] splitData(java.lang.String input_string, char sep_ch, int size)
          Split a string in array of predefined size
 void start()
          Start the applet
 void stop()
          Stop the applet
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
serialVersionUID

See Also:
Constant Field Values

JUNITCONV_VERSION

private static final java.lang.String JUNITCONV_VERSION
Software version

See Also:
Constant Field Values

panel

java.awt.Panel panel

a

final java.applet.Applet a

p_background_color

java.awt.Color p_background_color
Background color.


p_foreground_color

java.awt.Color p_foreground_color
Foreground color.


default_font

java.awt.Font default_font
Default font.


label_font

java.awt.Font label_font
Font for labels.


title_font

java.awt.Font title_font
Font for title.


group_font

java.awt.Font group_font
Font for applet description.


p_font

java.lang.String p_font
Font name.


p_font_style

int p_font_style
Font style (PLAIN, BOLD, ITALIC).


p_font_size

int p_font_size
Font size.


p_encoding

java.lang.String p_encoding
Charset encoding.


p_page_encoding

java.lang.String p_page_encoding
HTML page encoding.


p_target

private java.lang.String p_target
Default frame target where to open author homepage


p_link

private java.lang.String p_link
Author's homepage.


p_copyright

private java.lang.String p_copyright
Label for the link button.


p_labels_data_file

java.lang.String p_labels_data_file
URL of text data file containing labels definitions.


p_multiplier_data_file

java.lang.String p_multiplier_data_file
URL of text data file containing multiplier definitions.


p_category_data_file

java.lang.String p_category_data_file
URL of text data file containing units categories data.


p_unit_data_file

java.lang.String p_unit_data_file
URL of text data file containing units data.


p_label

java.lang.String[] p_label
Array of string labels.


p_category_name

java.lang.String[] p_category_name
Array of category names.


p_multiplier_name

java.lang.String[] p_multiplier_name
Array of Multiple/Submultiple names.


p_multiplier_value

java.lang.Double[] p_multiplier_value
Array of Multiple/Submultiple values.


p_multiplier_description

java.lang.String[] p_multiplier_description
Array of Multiple/Submultiple descriptions.


p_unit_category_id

java.lang.Integer[] p_unit_category_id
Array of category ID (link to category table: p_category_id).


p_unit_symbol

java.lang.String[] p_unit_symbol
Array of unit of measure symbols.


p_unit_name

java.lang.String[] p_unit_name
Array of unit of measure names.


p_unit_description

java.lang.String[] p_unit_description
Array of unit of measure descriptions.


p_unit_scale

java.lang.Double[] p_unit_scale
Array of unit of measure conversion scale factors.


p_unit_offset

java.lang.Double[] p_unit_offset
Array of unit of measure conversion offsets.


p_unit_power

java.lang.Double[] p_unit_power
Array of powers to apply to unit multipliers.


current_category

private int current_category
Current category.


current_unit_offset

private int current_unit_offset
Current unit offset.


current_in_multiplier

private int current_in_multiplier
Current input multiplier.


current_out_multiplier

private int current_out_multiplier
Current output multiplier.


current_in_unit

private int current_in_unit
Current input unit.


current_out_unit

private int current_out_unit
Current output unit.


current_precision

private int current_precision
Current precision (number of decimals). default value = 3


current_in_value

private java.lang.Double current_in_value
Current input value.


current_out_value

private java.lang.Double current_out_value
Current output value.


category_selector

private java.awt.Choice category_selector
Selector for units category.


precision_selector

private java.awt.Choice precision_selector
Selector for required precision.


in_unit_selector

private java.awt.Choice in_unit_selector
Selector for input unit type.


out_unit_selector

private java.awt.Choice out_unit_selector
Selector for output unit type.


in_multiplier_selector

private java.awt.Choice in_multiplier_selector
Selector for input multiplier (SI prefixes).


out_multiplier_selector

private java.awt.Choice out_multiplier_selector
Selector for output multiplier (SI prefixes).


in_value

private java.awt.TextField in_value
Input value.


out_value

private java.awt.TextField out_value
Output value.


textarea_rows

private int textarea_rows
Number of rows for textarea (the area that display unit-of-measure definition). Default = 2.


textarea_cols

private int textarea_cols
Number of columns for textarea (the area that display unit-of-measure definition). Default = 50.


in_description

private java.awt.TextArea in_description
Input unit of measure description (definition).


out_description

private java.awt.TextArea out_description
Output unit of measure description (definition).


jumpToUrl

java.awt.event.ActionListener jumpToUrl
When a menu item is clicked, jump to corresponding URL

Constructor Detail

JUnitConv

public JUnitConv()
Applet constructor (void)

Method Detail

setURL

private java.net.URL setURL(java.lang.String link)
Computes full, canonical URL from a relative specification.

Parameters:
link - string containing URL
Returns:
canonical URL

getEncodedString

private java.lang.String getEncodedString(java.lang.String original,
                                          java.lang.String encoding_in,
                                          java.lang.String encoding_out)
Convert string to specified encoding.

Parameters:
original - original string
encoding_in - input encoding table
encoding_out - output encoding table
Returns:
encoded string

getFontStyleCode

private int getFontStyleCode(java.lang.String stylename)
return the int associated to font style

Parameters:
stylename - name of style
Returns:
style int code

getParameter

private java.lang.String getParameter(java.lang.String key,
                                      java.lang.String def)
Get applet parameter value, return default if void.

Parameters:
key - name of parameter to read
def - default value
Returns:
parameter value or default

getDefaultValue

private java.lang.String getDefaultValue(java.lang.String str,
                                         java.lang.String def)
Return "def" if "str" is null or empty.

Parameters:
str - value to return if not null
def - default value to return
Returns:
def or str by case

getParameters

void getParameters()
Get the applet parameters from HTML page.


setMultipliersArraySize

private void setMultipliersArraySize(int i)
set arrays size for unit categories

Parameters:
i - size of array

setCategoriesArraySize

private void setCategoriesArraySize(int i)
set arrays size for unit categories

Parameters:
i - size of array

setUnitsArraySize

private void setUnitsArraySize(int i)
set arrays size for units

Parameters:
i - size of array

splitData

private java.lang.String[] splitData(java.lang.String input_string,
                                     char sep_ch,
                                     int size)
Split a string in array of predefined size

Parameters:
input_string - string to split
sep_ch - separator character
size - max elements to retrieve, remaining elements will be filled with empty string
Returns:
splitted_array of strings

readDataFile

public void readDataFile(int filetype,
                         java.lang.String filename)
Read menu items data from external text file "\n" separate items "\t" separate values

Parameters:
filetype - 0=multiplier file, 1= category file, 2=units file
filename - the text file containing menu data

init

public void init()
Initialize the applet

Overrides:
init in class java.applet.Applet

fillUnitsSelector

private void fillUnitsSelector(int category)
Fill units selectors filtering by category

Parameters:
category - selected units category (filter)

jbInit

private void jbInit()
             throws java.lang.Exception
Component initialization

Throws:
java.lang.Exception

addLabel

private java.awt.Component addLabel(java.awt.Component comp,
                                    java.lang.String label)
add label to a component

Parameters:
comp - component
label - label string
Returns:
labeled component

start

public void start()
Start the applet

Overrides:
start in class java.applet.Applet

stop

public void stop()
Stop the applet

Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
Destroy the applet

Overrides:
destroy in class java.applet.Applet

getAppletInfo

public java.lang.String getAppletInfo()
Get Applet information.

Overrides:
getAppletInfo in class java.applet.Applet
Returns:
applet info

category_selector_itemStateChanged

private void category_selector_itemStateChanged(java.awt.event.ItemEvent e)
change units on units selctors by selected category

Parameters:
e - event

precision_selector_itemStateChanged

private void precision_selector_itemStateChanged(java.awt.event.ItemEvent e)
change result precision (number of decimals)

Parameters:
e - event

in_multiplier_selector_itemStateChanged

private void in_multiplier_selector_itemStateChanged(java.awt.event.ItemEvent e)
get selected input multiplier index

Parameters:
e - event

out_multiplier_selector_itemStateChanged

private void out_multiplier_selector_itemStateChanged(java.awt.event.ItemEvent e)
get selected output multiplier index

Parameters:
e - event

in_unit_selector_itemStateChanged

private void in_unit_selector_itemStateChanged(java.awt.event.ItemEvent e)
get selected input unit index

Parameters:
e - event

out_unit_selector_itemStateChanged

private void out_unit_selector_itemStateChanged(java.awt.event.ItemEvent e)
get selected output unit index

Parameters:
e - event

in_value_itemStateChanged

private void in_value_itemStateChanged(java.awt.event.TextEvent e)
get input value

Parameters:
e - event

setUnitCategory

private void setUnitCategory()
get selected category and set other parameters


getSelectedIndexes

private void getSelectedIndexes()
get current selected index on selectors


roundNumber

private double roundNumber(double in_number,
                           int precision)
return a rounded number

Parameters:
in_number - numer to round
precision - max decimal numbers
Returns:
rounded number

parseNumber

private java.lang.Double parseNumber(java.lang.String num)
simple number parser (allows to use math operators operators: +,-,*,/,^,P=PI,X=exp) operator precedence: P X * / + - ^

Parameters:
num - string to parse
Returns:
Double parsed number