public class UnitConverter
extends de.infinityloop.util.Units
Modifier and Type | Field and Description |
---|---|
static int |
kDefaultPrecision |
Constructor and Description |
---|
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 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
|
Modifier and Type | Method and Description |
---|---|
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.
|
public static final int kDefaultPrecision
public UnitConverter()
public UnitConverter(double rV, int rU)
rV
- the valuerU
- its unitpublic 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 unitpublic 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 conversionspublic 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 decimalspublic double convert(double src, int srcUnit, int destUnit)
src
- source valuesrcUnit
- source unitdestUnit
- destination unitpublic double convert(java.lang.String srcString, int destUnit)
srcString
- the source value stringdestUnit
- the unit to convert topublic 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 havepublic static java.lang.String precisionString(double d, int prec)
d
- the value to convert to a stringprec
- the decimal precision (number of decimals)