Class UnitValue

java.lang.Object
com.codename1.ui.layouts.mig.UnitValue

public final class UnitValue extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    An operation indicating a addition of two sub units.
    static final int
    A unit indicating alignment.
    static final int
    A unit indicating botton size.
    static final int
    A unit indicating centimeters.
    static final int
    An operation indicating a division of two sub units.
    static final int
    A unit indicating inches.
    static final int
    A unit indicating label alignment.
    static final int
    A unit indicating linking to height.
    static final int
    A unit indicating linking to width.
    static final int
    A unit indicating linking to x.
    static final int
    A unit indicating linking to x2.
    static final int
    A unit indicating linking to x position on screen.
    static final int
    A unit indicating linking to y.
    static final int
    A unit indicating linking to y2.
    static final int
    A unit indicating linking to y position on screen.
    static final int
    A unit indicating a lookup.
    static final int
    A unit indicating logical horizontal pixels.
    static final int
    A unit indicating logical vertical pixels.
    static final int
    An operation indicating the maximum of two sub units
    static final int
    A unit indicating maximum size.
    static final int
    An operation indicating the middle value of two sub units
    static final int
    An operation indicating the minimum of two sub units
    static final int
    A unit indicating minimum size.
    static final int
    A unit indicating millimeters.
    static final int
    An operation indicating a multiplication of two sub units.
    static final int
    A unit indicating percent.
    static final int
    A unit indicating pixels.
    static final int
    A unit indicating preferred size.
    static final int
    A unit indicating points.
    static final int
    A unit indicating screen percentage width.
    static final int
    A unit indicating screen percentage height.
    static final int
    An operation indicating a static value.
    static final int
    An operation indicating a subtraction of two sub units
  • Constructor Summary

    Constructors
    Constructor
    Description
    UnitValue(float value)
     
    UnitValue(float value, int unit, String createString)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Adds a global unit converter that can convert from some unit to pixels.
    boolean
    Indicates whether some other object is "equal to" this one.
    Returns the creation string for this object.
    static int
    Returns the current default unit.
    static UnitConverter[]
    Returns the global converters currently registered.
    int
     
    int
    getPixels(float refValue, ContainerWrapper parent, ComponentWrapper comp)
    Returns the size in pixels rounded.
    float
    getPixelsExact(float refValue, ContainerWrapper parent, ComponentWrapper comp)
    Returns the size in pixels.
     
    int
     
     
    float
     
    int
    Returns a hash code value for the object.
    boolean
     
    static boolean
    Removed the converter.
    static void
    setDefaultUnit(int unit)
    Sets the default unit.
    Returns a string representation of the object.

    Methods inherited from class Object

    clone, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • STATIC

      public static final int STATIC
      An operation indicating a static value.
      See Also:
    • ADD

      public static final int ADD
      An operation indicating a addition of two sub units.
      See Also:
    • SUB

      public static final int SUB
      An operation indicating a subtraction of two sub units
      See Also:
    • MUL

      public static final int MUL
      An operation indicating a multiplication of two sub units.
      See Also:
    • DIV

      public static final int DIV
      An operation indicating a division of two sub units.
      See Also:
    • MIN

      public static final int MIN
      An operation indicating the minimum of two sub units
      See Also:
    • MAX

      public static final int MAX
      An operation indicating the maximum of two sub units
      See Also:
    • MID

      public static final int MID
      An operation indicating the middle value of two sub units
      See Also:
    • PIXEL

      public static final int PIXEL
      A unit indicating pixels.
      See Also:
    • LPX

      public static final int LPX
      A unit indicating logical horizontal pixels.
      See Also:
    • LPY

      public static final int LPY
      A unit indicating logical vertical pixels.
      See Also:
    • MM

      public static final int MM
      A unit indicating millimeters.
      See Also:
    • CM

      public static final int CM
      A unit indicating centimeters.
      See Also:
    • INCH

      public static final int INCH
      A unit indicating inches.
      See Also:
    • PERCENT

      public static final int PERCENT
      A unit indicating percent.
      See Also:
    • PT

      public static final int PT
      A unit indicating points.
      See Also:
    • SPX

      public static final int SPX
      A unit indicating screen percentage width.
      See Also:
    • SPY

      public static final int SPY
      A unit indicating screen percentage height.
      See Also:
    • ALIGN

      public static final int ALIGN
      A unit indicating alignment.
      See Also:
    • MIN_SIZE

      public static final int MIN_SIZE
      A unit indicating minimum size.
      See Also:
    • PREF_SIZE

      public static final int PREF_SIZE
      A unit indicating preferred size.
      See Also:
    • MAX_SIZE

      public static final int MAX_SIZE
      A unit indicating maximum size.
      See Also:
    • BUTTON

      public static final int BUTTON
      A unit indicating botton size.
      See Also:
    • LOOKUP

      public static final int LOOKUP
      A unit indicating a lookup.
      See Also:
    • LABEL_ALIGN

      public static final int LABEL_ALIGN
      A unit indicating label alignment.
      See Also:
  • Constructor Details

    • UnitValue

      public UnitValue(float value)
    • UnitValue

      public UnitValue(float value, int unit, String createString)
  • Method Details

    • addGlobalUnitConverter

      public static void addGlobalUnitConverter(UnitConverter conv)

      Adds a global unit converter that can convert from some unit to pixels.

      This converter will be asked before the platform converter so the values for it (e.g. "related" and "unrelated") can be overridden. It is however not possible to override the built in ones (e.g. "mm", "pixel" or "lp").

      Parameters
      • conv: The converter. Not null.
    • removeGlobalUnitConverter

      public static boolean removeGlobalUnitConverter(UnitConverter unit)

      Removed the converter.

      Parameters
      • unit: The converter.
      Returns

      If there was a converter found and thus removed.

    • getGlobalUnitConverters

      public static UnitConverter[] getGlobalUnitConverters()

      Returns the global converters currently registered. The platform converter will not be in this list.

      Returns

      The converters. Never null.

    • getDefaultUnit

      public static int getDefaultUnit()

      Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".

      Returns

      The current default unit.

      Deprecated

      Use PlatformDefaults#getDefaultHorizontalUnit() and PlatformDefaults#getDefaultVerticalUnit() instead.

      See also
      • #PIXEL

      • #LPX

    • setDefaultUnit

      public static void setDefaultUnit(int unit)

      Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".

      Parameters
      • unit: The new default unit.
      Deprecated

      Use PlatformDefaults#setDefaultHorizontalUnit(int) and PlatformDefaults#setDefaultVerticalUnit(int) instead.

      See also
      • #PIXEL

      • #LPX

    • getPixels

      public int getPixels(float refValue, ContainerWrapper parent, ComponentWrapper comp)

      Returns the size in pixels rounded.

      Parameters
      • refValue: The reference value. Normally the size of the parent. For unit #ALIGN the current size of the component should be sent in.

      • parent: @param parent The parent. May be null for testing the validity of the value, but should normally not and are not required to return any usable value if null.

      • comp: @param comp The component, if any, that the value is for. Might be null if the value is not connected to any component.

      Returns

      The size in pixels.

    • getPixelsExact

      public float getPixelsExact(float refValue, ContainerWrapper parent, ComponentWrapper comp)

      Returns the size in pixels.

      Parameters
      • refValue: The reference value. Normally the size of the parent. For unit #ALIGN the current size of the component should be sent in.

      • parent: @param parent The parent. May be null for testing the validity of the value, but should normally not and are not required to return any usable value if null.

      • comp: @param comp The component, if any, that the value is for. Might be null if the value is not connected to any component.

      Returns

      The size in pixels.

    • getSubUnits

      public UnitValue[] getSubUnits()
    • getUnit

      public int getUnit()
    • getUnitString

      public String getUnitString()
    • getOperation

      public int getOperation()
    • getValue

      public float getValue()
    • isHorizontal

      public boolean isHorizontal()
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object
    • getConstraintString

      public String getConstraintString()

      Returns the creation string for this object. Note that boolean) must be set to true for the creation strings to be stored.

      Returns

      The constraint string or null if none is registered.

    • hashCode

      public int hashCode()
      Description copied from class: Object
      Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Description copied from class: Object
      Indicates whether some other object is "equal to" this one. The equals method implements an equivalence relation: It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified. For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).
      Overrides:
      equals in class Object