Class NumberAndUnitsComposite<Q extends javax.measure.Quantity<Q>>

java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
uk.ac.gda.client.NumberAndUnitsComposite<Q>
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class NumberAndUnitsComposite<Q extends javax.measure.Quantity<Q>> extends org.eclipse.swt.widgets.Composite
A Composite for displaying a number with a unit.
The selection of units supported is configured in the constructor.
It supports JFace databinding via NumberUnitsWidgetProperty *

Generic parameter Q is the type of quantity this composite can be used to edit e.g. Energy, Length, Time

If the style READ_ONLY is not specified, the composite contains a text box with the numeric value (displayed in scientific format if appropriate) and a drop-down box to choose units:

It automatically converts the numeric value when the units are changed:

If the style READ_ONLY is specified, then a read-only label will be created to display the units instead of a drop-down box.

Styles:
READ_ONLY, NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED
Events:
(none)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields inherited from class org.eclipse.swt.widgets.Composite

    embeddedHandle

    Fields inherited from class org.eclipse.swt.widgets.Widget

    handle
  • Constructor Summary

    Constructors
    Constructor
    Description
    NumberAndUnitsComposite(org.eclipse.swt.widgets.Composite parent, int style, javax.measure.Unit<Q> modelUnit)
    Constructor for the case where only one unit is permitted
    NumberAndUnitsComposite(org.eclipse.swt.widgets.Composite parent, int style, javax.measure.Unit<Q> modelUnit, Set<javax.measure.Unit<Q>> validUnits)
    Constructor for the case where the initially-displayed unit is the same as the model unit
    NumberAndUnitsComposite(org.eclipse.swt.widgets.Composite parent, int style, javax.measure.Unit<Q> modelUnit, Set<javax.measure.Unit<Q>> validUnits, javax.measure.Unit<Q> initialUnit)
    General constructor to create a new NumberAndUnitsComposite.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addModifyListener(org.eclipse.swt.events.ModifyListener listener)
     
    void
     
    Gets the value set in local properties in decimal format If it is not set, the default decimal format is used instead
    javax.measure.Unit<Q>
     
    double
    Gets the value set in the UI in model units.
    javax.measure.Quantity<Q>
    Get the currently-displayed value in the form of a Quantity object
    void
     
    void
    setUnit(javax.measure.Unit<Q> unit)
     
    void
    setValue(double value)
    Sets the value shown by this UI element.
     

    Methods inherited from class org.eclipse.swt.widgets.Composite

    changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList

    Methods inherited from class org.eclipse.swt.widgets.Scrollable

    computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar

    Methods inherited from class org.eclipse.swt.widgets.Control

    addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update

    Methods inherited from class org.eclipse.swt.widgets.Widget

    addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • NumberAndUnitsComposite

      public NumberAndUnitsComposite(org.eclipse.swt.widgets.Composite parent, int style, javax.measure.Unit<Q> modelUnit)
      Constructor for the case where only one unit is permitted

      For parameters, see (@link NumberAndUnitsComposite(Composite, int, Unit, Set, Unit)

    • NumberAndUnitsComposite

      public NumberAndUnitsComposite(org.eclipse.swt.widgets.Composite parent, int style, javax.measure.Unit<Q> modelUnit, Set<javax.measure.Unit<Q>> validUnits)
      Constructor for the case where the initially-displayed unit is the same as the model unit

      For parameters, see (@link NumberAndUnitsComposite(Composite, int, Unit, Set, Unit)

    • NumberAndUnitsComposite

      public NumberAndUnitsComposite(org.eclipse.swt.widgets.Composite parent, int style, javax.measure.Unit<Q> modelUnit, Set<javax.measure.Unit<Q>> validUnits, javax.measure.Unit<Q> initialUnit)
      General constructor to create a new NumberAndUnitsComposite.
      Parameters:
      parent - parent composite
      style - SWT style
      modelUnit - Units of the model to which the composite is bound
      validUnits - Units that the user can choose for this value
      initialUnit - Units to be selected when the combo box is first displayed
  • Method Details

    • getValueAsQuantity

      public javax.measure.Quantity<Q> getValueAsQuantity()
      Get the currently-displayed value in the form of a Quantity object
      Returns:
      Current value as a quantity
    • getValue

      public double getValue()
      Gets the value set in the UI in model units. Called by the data binding to update the model with changes by the user in the UI
      Returns:
      the value in model units
    • setValue

      public void setValue(double value)
      Sets the value shown by this UI element. This is called by the data binding to update the UI with changes in the model. This should always be called in model units.
      Parameters:
      value - The value to set in model units
    • setUnit

      public void setUnit(javax.measure.Unit<Q> unit)
    • getUnit

      public javax.measure.Unit<Q> getUnit()
    • addUnitSelectionChangedListener

      public void addUnitSelectionChangedListener(NumberAndUnitsComposite.UnitSelectionChangedListener<Q> listener)
    • addModifyListener

      public void addModifyListener(org.eclipse.swt.events.ModifyListener listener)
    • getDecimalFormat

      public String getDecimalFormat()
      Gets the value set in local properties in decimal format If it is not set, the default decimal format is used instead
      Returns:
      the number of decimal places to display in the mapping GUI
    • setTextReadyOnly

      public void setTextReadyOnly()
    • toString

      public String toString()
      Overrides:
      toString in class org.eclipse.swt.widgets.Composite