All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.graphics.units.Resolution Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
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;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy