NameJUnitConv
Version1.0.004
Date2006-12-09
AuthorNicola Asuni
CopyrightTecnick.com S.r.l.
Via Ugo Foscolo n.19
09045 Quartu Sant'Elena (CA)
ITALY
www.tecnick.com
LicenseGNU LESSER GENERAL PUBLIC LICENSE v.2.1

Source Code and Documentation

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.

Main Features


Note: the conversion accuracy is influenced by a couple of factors such as client machine precision and units data definitions.

Example

Setup

To display the JUnitConv, copy the .jar file on your site and add the applet tag to your XHTML/HTML document. To customize quickly the applet, I suggest to cut and paste the applet tag code used in the online example and modify it to fit your needs.

The following tables illustrates the meaning and function of each parameter.

Applet Attributes
(<applet attribute_name="attribute_value" ... >)
name values default required
codebase relative path to applet archive directory (e.g.: "../java/")   yes
archive junitconv.jar (name of applet archive)   yes
code com.tecnick.junitconv.JUnitConv.class (name of main class)   yes
width applet width in pixels   yes
height applet height in pixels   yes
hspace applet horizontal space   no
vspace applet vertical space   no
align applet alignment
  • left
  • right
  • top
  • middle
  • bottom
  no
name applet name   no
id applet id   no
alt applet alternate text content   no


The following are the main applet parameters.


Main Parameters
(<param name="param_name" value="param_value" />)
name values default required
background_color applet background color
- the color format is a set of three hexadecimal numbers (from 00 to FF) representing primary colors RRGGBB (R=Red, G=Green, B=Blue)
CCCCCC no
foreground_color applet foreground color (text color)
- the color format is a set of three hexadecimal numbers (from 00 to FF) representing primary colors RRGGBB (R=Red, G=Green, B=Blue)
000000 no
font font name Helvetica, Verdana, Arial no
font_style font style
  • PLAIN
  • BOLD
  • ITALIC
  • BOLD+ITALIC
PLAIN no
font_size font height in pixels 11 no
page_encoding encoding character set of the html page where the applet is loaded iso-8859-1 no
encoding encoding character set for the applet iso-8859-1 no
labels_data_file relative path to text file containing the applet labels (fields names) eng/labels.txt yes
multiplier_data_file relative path to text file containing the multipliers definitions eng/muldata.txt yes
categories_data_file relative path to text file containing the units categories eng/catdata.txt yes
units_data_file relative path to text file containing the units definitions eng/unitdata.txt yes


Customize Units

Conversion Formula

All conversions are performed using the following formula:

OV = ( ( IV · IS · IMIP ) + IO - OO ) / ( OS · OMOP)

where:

Data Files

Labels, Categories, Units and Multipliers are specified on external text files (data files). These data files can be changed manually using a simple text editor or using a spreadsheet editor such as Microsoft Excel (open and save files using the Tab delimited Text format).

Tab delimited Text means that each file row identify one element (one category, one unit, one multiplier or one label). Each row terminate with newline character '\n' (rows separator). The data values of each single element are separated by tabulation character '\t' (columns separator), even if not present.

labels_data_file

On this file each row represent one JUnitConv label (field name).

multiplier_data_file

This file contains the Multiplier Prefixes definitions (e.g.: k = kilo = 103 = 1000)
The columns fields are:

categories_data_file

This file contains the Units Categories Names.
The row number of each category represent the CATEGORY_ID index.

units_data_file

This file contains the Units of Measure definitions.
The columns fields are:

Numeric Fields

On data files, each numeric field support scientific notation (e.g.: 3.7E-2 = 3.7 · 10-2 = 0.037) but can be also specified using basic formulas and constants.

On formulas the following symbols are used (in order of precedence):
Note that parenthesis are not supported, so please check twice the operators precedence.

Examples:

References

The following documents, books and software applications has been used as reference to build the default units data file (unitdata.txt).

SourceForge.net LogoSupport This Project



Open Source projects from the same author >>