Units Class Reference

Inheritance diagram for Units:

Centimeters Feet Inches Meters Millimeters PatternDots Percentage Pixels Points PrinterDots List of all members.

Public Member Functions

 Units (double val, String name)
 Used when you want to create (and name) an anonymous unit.
Override boolean equals (Object o)
 Check if the lengths match.
double getConversionTo (Units destUnits)
Units getCopy ()
 Returns a copy of this unit.
String getUnitName ()
Units getUnitsObjectOfSameLengthIn (Units destUnits)
 Gets a new Units object of the same type as destUnits, with the same physical length as this object.
Units getUnitsObjectOfSameTypeWithValue (double val)
 Gets a new Units object of the same type as this unit, but with a new value.
double getValue ()
double getValueIn (Units destUnits)
 Gets the value in a new unit.
double getValueInCentimeters ()
double getValueInInches ()
 This is a CONVENIENCE method.
double getValueInMillimeters ()
double getValueInPatternDots ()
 CONVENIENCE method for converting this unit to PatternDots.
double getValueInPixels ()
 CONVENIENCE method for converting to Pixels.
double getValueInPoints ()
 CONVENIENCE method for converting this unit to Points.
Inches toInches ()
 Get an Inches object representing the same physical length.
Pixels toPixels ()
Points toPoints ()
 Get a Points object representing the same physical length.
String toString ()

Static Public Member Functions

static Units add (Units a, Units b)
static Units subtract (Units a, Units b)

Static Public Attributes

static final double POINTS_PER_INCH = 72
 Java handles everything in 1/72nd of an inch (1 point).

Protected Member Functions

 Units (double val)
 The only time you can set the value.
Units clone ()
abstract double getNumberOfUnitsInOneInch ()

Detailed Description

Allows fluid conversion between length measurements in different units.

This software is distributed under the BSD License.

Author:
Ron B Yeh (ronyeh(AT)cs.stanford.edu)

Definition at line 14 of file Units.java.


Constructor & Destructor Documentation

Units ( double  val  )  [protected]

The only time you can set the value.

A Units object should be immutable.

Parameters:
val 

Definition at line 53 of file Units.java.

Units ( double  val,
String  name 
)

Used when you want to create (and name) an anonymous unit.

This is useful in situations where you need a temporary unit.

Parameters:
val 
name 

Definition at line 65 of file Units.java.


Member Function Documentation

static Units add ( Units  a,
Units  b 
) [static]

Parameters:
a 
b 
Returns:
a unit object of type a representing a+b

Definition at line 27 of file Units.java.

References Units.getUnitsObjectOfSameTypeWithValue(), Units.getValue(), and Units.getValueIn().

Units clone (  )  [protected]

See also:
java.lang.Object.clone()

Definition at line 73 of file Units.java.

References Units.clone().

Referenced by Units.clone(), Size.clone(), Units.getUnitsObjectOfSameLengthIn(), and Units.getUnitsObjectOfSameTypeWithValue().

Override boolean equals ( Object  o  ) 

Check if the lengths match.

See also:
java.lang.Object.equals(java.lang.Object)

Definition at line 88 of file Units.java.

References Units.getValueIn().

Referenced by Sheet.addRegions(), and RegionID.equals().

double getConversionTo ( Units  destUnits  ) 

Parameters:
destUnits 
Returns:
the number of destination Units that fit into this Unit. Alternatively, the number n that we would need to multiply the current value to in order to achieve the same length in the destination unit. For example, if we are one inch, and the destination is Points, then the number we need is 72, because we would have to multiply our value (1) by 72 to achieve 72 points, which is the same physical length.
Note:
we flipped the definition of this from Diamond's Edge.

Definition at line 108 of file Units.java.

References Units.getNumberOfUnitsInOneInch().

Referenced by CompoundRegion.addChild(), RegionGroup.addRegion(), GraphicsUtils.getPointsWithConvertedUnits(), Units.getValueIn(), RegionRenderer.renderToG2D(), PolygonRenderer.renderToG2D(), ImageRenderer.renderToG2D(), and SheetRenderer.renderToJPEG().

Units getCopy (  ) 

Returns a copy of this unit.

WARNING: If you have a unit that depends on other factors, you should override this method. This is particularly true for Screen Pixels and Printer Dots.

TODO (Implement override for Pixels and PrinterDots)

Returns:

Definition at line 120 of file Units.java.

References Units.getUnitsObjectOfSameLengthIn().

abstract double getNumberOfUnitsInOneInch (  )  [protected, pure virtual]

Returns:
how many of these units fit in one inch.

Implemented in Centimeters, Feet, Inches, Meters, Millimeters, PatternDots, Percentage, Pixels, Points, and PrinterDots.

Referenced by Units.getConversionTo(), and Percentage.getNumberOfUnitsInOneInch().

String getUnitName (  ) 

Returns:
Inches, Points, Pixels...

Definition at line 133 of file Units.java.

Referenced by Units.toString(), TextRegion.toString(), Region.toString(), PatternDots.toString(), ImageRegion.toString(), and CompoundRegion.toString().

Units getUnitsObjectOfSameLengthIn ( Units  destUnits  ) 

Gets a new Units object of the same type as destUnits, with the same physical length as this object.

Parameters:
destUnits 
Returns:

Definition at line 144 of file Units.java.

References Units.clone(), Units.getValueIn(), and Units.value.

Referenced by CompoundRegion.CompoundRegion(), Units.getCopy(), and RegionGroup.RegionGroup().

Units getUnitsObjectOfSameTypeWithValue ( double  val  ) 

Gets a new Units object of the same type as this unit, but with a new value.

Parameters:
val 
Returns:

Definition at line 156 of file Units.java.

References Units.clone(), and Units.value.

Referenced by Units.add(), Region.getHeight(), Region.getOriginX(), Region.getOriginY(), Region.getUnscaledBoundsHeight(), Region.getUnscaledBoundsWidth(), Region.getWidth(), Percentage.Percentage(), PolygonalRegion.PolygonalRegion(), and Units.subtract().

double getValue (  ) 

Returns:
the numerical value of this unit measure.

Definition at line 165 of file Units.java.

Referenced by Units.add(), CompoundRegion.addChild(), Percentage.getNumberOfUnitsInOneInch(), PatternPackage.getPatternCoordinateOfOriginOfFile(), PercentageCoordinates.getPercentageInXDirection(), PercentageCoordinates.getPercentageInYDirection(), StreamedPatternCoordinates.getXVal(), BatchedPatternCoordinates.getXVal(), StreamedPatternCoordinates.getYVal(), BatchedPatternCoordinates.getYVal(), GestureHandler.handleEvent(), RegionID.hashCode(), ImageRegion.ImageRegion(), Percentage.Percentage(), Region.Region(), TextRenderer.renderToG2D(), PolygonRenderer.renderToG2D(), PatternLocationToSheetLocationMapping.setPatternInformationOfRegion(), Units.subtract(), TextRegion.TextRegion(), TextRegion.toString(), Percentage.toString(), PatternDots.toString(), and CompoundRegion.toString().

double getValueIn ( Units  destUnits  ) 

Gets the value in a new unit.

For example, you have a Units object that represents 2 Inches. You want to see what the value will be in Points. getConversionTo(new Points()) will return 72. 2 * 72 is 144.

Parameters:
destUnits 
Returns:

Definition at line 178 of file Units.java.

References Units.getConversionTo().

Referenced by Units.add(), CompoundRegion.addChild(), RegionGroup.addRegion(), Units.equals(), Units.getUnitsObjectOfSameLengthIn(), Units.getValueInCentimeters(), Units.getValueInInches(), Units.getValueInMillimeters(), Units.getValueInPatternDots(), Units.getValueInPixels(), Units.getValueInPoints(), ImageRegion.ImageRegion(), Region.Region(), SheetRenderer.renderToJPEG(), InkRenderer.renderToJPEG(), Units.subtract(), and TextRegion.TextRegion().

double getValueInCentimeters (  ) 

Returns:

Definition at line 185 of file Units.java.

References Units.getValueIn().

double getValueInInches (  ) 

This is a CONVENIENCE method.

Yes, Yes... it's probably poor programming style to have the Units class be aware of its subclass (Inches). However, it makes code a lot more readable. Plus, if you implement your own Units class, you can use the generic method getValueIn(Units).

Returns:
the double value of this unit, converted to Inches.

Definition at line 197 of file Units.java.

References Units.getValueIn().

Referenced by RegionGroup.getXOffsetInInches(), RegionGroup.getYOffsetInInches(), FlowPaperLayout.layout(), FlowPaperLayout.layoutRegionGroups(), and Units.toInches().

double getValueInMillimeters (  ) 

Returns:

Definition at line 204 of file Units.java.

References Units.getValueIn().

double getValueInPatternDots (  ) 

CONVENIENCE method for converting this unit to PatternDots.

Returns:

Definition at line 213 of file Units.java.

References Units.getValueIn().

Referenced by TiledPatternGenerator.displayTilingInformation(), FlexiblePatternCoordinateConverter.FlexiblePatternCoordinateConverter(), TiledPatternGenerator.getPattern(), InkCollector.handleEvent(), PatternPackage.readPatternFromFile(), and InkCollector.setNotifyDistance().

double getValueInPixels (  ) 

CONVENIENCE method for converting to Pixels.

This uses the DEFAULT pixelsPerInch as specified by the configuration xml file. Unfortunately, Java cannot detect this value yet.

Returns:
the value after converting to pixels.

Definition at line 223 of file Units.java.

References Units.getValueIn().

Referenced by HandwritingRecognizer.handleEvent(), and Units.toPixels().

double getValueInPoints (  ) 

CONVENIENCE method for converting this unit to Points.

Returns:

Definition at line 232 of file Units.java.

References Units.getValueIn().

Referenced by PDFPatternGenerator.renderPattern(), TextRenderer.renderToG2D(), SheetRenderer.renderToG2D(), PDFSheetRenderer.renderToG2D(), CompoundRenderer.renderToG2D(), SheetRenderer.renderToPDF(), SheetRenderer.renderToPDFContentLayers(), and Units.toPoints().

static Units subtract ( Units  a,
Units  b 
) [static]

Parameters:
a 
b 
Returns:
a Unit object of type a representing a-b

Definition at line 36 of file Units.java.

References Units.getUnitsObjectOfSameTypeWithValue(), Units.getValue(), and Units.getValueIn().

Inches toInches (  ) 

Get an Inches object representing the same physical length.

Returns:

Definition at line 241 of file Units.java.

References Units.getValueInInches().

Pixels toPixels (  ) 

Returns:

Definition at line 249 of file Units.java.

References Units.getValueInPixels().

Points toPoints (  ) 

Get a Points object representing the same physical length.

Returns:

Definition at line 258 of file Units.java.

References Units.getValueInPoints().

String toString (  ) 

See also:
java.lang.Object.toString()

Reimplemented in PatternDots, and Percentage.

Definition at line 265 of file Units.java.

References Units.getUnitName().

Referenced by PercentageCoordinates.toString(), and Coordinates.toString().


Member Data Documentation

final double POINTS_PER_INCH = 72 [static]

Java handles everything in 1/72nd of an inch (1 point).

We should do the same to be compatible.

Definition at line 20 of file Units.java.


The documentation for this class was generated from the following file:
Generated on Sat Apr 14 18:21:45 2007 for R3 Paper Toolkit by  doxygen 1.4.7