|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.infinityloop.util.Units
de.infinityloop.util.UnitConverter
public class UnitConverter
Unit converter class Converts between several units like cm, mm, twips, pt, inches etc.
| Field Summary | |
|---|---|
static int |
kDefaultPrecision
|
| Fields inherited from class de.infinityloop.util.Units |
|---|
CM, DEG, EM, EMU, EX, GRAD, HP, IN, kDefault, kSame, M, MM, PC, PECENT, PT, PX, RAD, TW |
| Constructor Summary | |
|---|---|
UnitConverter()
Default constructor |
|
UnitConverter(double dpi)
Construct with at the same time setting the dpi value for conversions |
|
UnitConverter(double rV,
int rU)
Constructor with at the same time setting the reference value and unit for relative conversions like em, ex, or percentages. |
|
UnitConverter(double rV,
int rU,
double fsV,
int fsU)
Constructor with at the same time setting the reference values for percentages and font size |
|
UnitConverter(java.lang.String reference,
java.lang.String fontsize)
Constructor with at the same time setting the reference values for percentages and font size |
|
| Method Summary | |
|---|---|
double |
convert(double src,
int srcUnit,
int destUnit)
Converts a value from one unit to another. |
double |
convert(java.lang.String srcString,
int destUnit)
Converts a value from one unit to another. |
java.lang.String |
convertString(double src,
int srcUnit,
int destUnit,
int prec)
Converts a value from one unit to another. |
double |
getDPI()
Returns the currently set global DPI value used for calculating conversions |
static double |
getNumber(java.lang.String srcString)
Returns only the numerical part of the value, i.e. this trims the extension and converts to a double. |
static java.lang.String |
precisionString(double d,
int prec)
Convert the passed floating point value to a string representation with the specified number of decimals. |
void |
setDPI(double dpi)
|
void |
setPrecision(int decs)
Sets the precision to be used for all following conversions. |
| Methods inherited from class de.infinityloop.util.Units |
|---|
getUnit, getUnitId, getUnitString, isRelativeUnit |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int kDefaultPrecision
| Constructor Detail |
|---|
public UnitConverter()
public UnitConverter(double rV,
int rU)
rV - the valuerU - its unit
public UnitConverter(double rV,
int rU,
double fsV,
int fsU)
rV - the percentage reference valuerU - the percentage reference value unitfsV - the current font size reference valuefsU - the current font size reference value unit
public UnitConverter(java.lang.String reference,
java.lang.String fontsize)
reference - the percentage reference valuefontsize - the current font size reference valuepublic UnitConverter(double dpi)
dpi - the dpi value to use in px conversions| Method Detail |
|---|
public void setDPI(double dpi)
dpi - sets the DPI value to use in subsequent calculationspublic double getDPI()
public void setPrecision(int decs)
decs - the number of decimals
public double convert(double src,
int srcUnit,
int destUnit)
src - source valuesrcUnit - source unitdestUnit - destination unit
public double convert(java.lang.String srcString,
int destUnit)
srcString - the source value stringdestUnit - the unit to convert to
public static double getNumber(java.lang.String srcString)
srcString - the value specification, e.g. "1em" or "2.54mm"
public java.lang.String convertString(double src,
int srcUnit,
int destUnit,
int prec)
src - the source valuesrcUnit - the unit the source value is indestUnit - the unit to convert toprec - the precision the resulting string should have
public static java.lang.String precisionString(double d,
int prec)
d - the value to convert to a stringprec - the decimal precision (number of decimals)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||