com.hfg.graphics.units.Resolution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.graphics.units;
import com.hfg.units.Quantity;
public class Resolution
{
private Float mDots;
private ResolutionUnit mUnit;
private static ResolutionUnit sDefaultUnit = ResolutionUnit.DPI;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//--------------------------------------------------------------------------
public Resolution(int inNumDots)
{
this(inNumDots, sDefaultUnit);
}
//--------------------------------------------------------------------------
public Resolution(float inNumDots, ResolutionUnit inUnit)
{
mDots = inNumDots;
mUnit = inUnit;
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//--------------------------------------------------------------------------
@Override
public String toString()
{
return mDots + " " + mUnit;
}
//--------------------------------------------------------------------------
public float floatValue()
{
return mDots;
}
//--------------------------------------------------------------------------
public int intValue()
{
return mDots.intValue();
}
//--------------------------------------------------------------------------
public Resolution convertTo(ResolutionUnit inUnit)
{
Resolution value;
if (inUnit.equals(mUnit))
{
value = this;
}
else
{
float dots = mDots / (new Quantity(1, mUnit.getLengthUnit()).convertTo(inUnit.getLengthUnit()).floatValue());
// Round to 1 decimal place and create a new Resolution object
value = new Resolution(Float.parseFloat(String.format("%.1f", dots)), inUnit);
}
return value;
}
}