Package uk.ac.gda.client
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
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 ClassesModifier and TypeClassDescriptionstatic interfaceNumberAndUnitsComposite.UnitSelectionChangedListener<Q extends javax.measure.Quantity<Q>> -
Field Summary
Fields inherited from class org.eclipse.swt.widgets.Composite
embeddedHandleFields inherited from class org.eclipse.swt.widgets.Widget
handle -
Constructor Summary
ConstructorsConstructorDescriptionNumberAndUnitsComposite(org.eclipse.swt.widgets.Composite parent, int style, javax.measure.Unit<Q> modelUnit) Constructor for the case where only one unit is permittedNumberAndUnitsComposite(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 unitNumberAndUnitsComposite(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 newNumberAndUnitsComposite. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddModifyListener(org.eclipse.swt.events.ModifyListener listener) voidGets the value set in local properties in decimal format If it is not set, the default decimal format is used insteadjavax.measure.Unit<Q> getUnit()doublegetValue()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 objectvoidvoidvoidsetValue(double value) Sets the value shown by this UI element.toString()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, setTabListMethods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBarMethods 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, updateMethods 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
-
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 permittedFor 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 unitFor 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 newNumberAndUnitsComposite.- Parameters:
parent- parent compositestyle- SWT stylemodelUnit- Units of the model to which the composite is boundvalidUnits- Units that the user can choose for this valueinitialUnit- Units to be selected when the combo box is first displayed
-
-
Method Details
-
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
-
getUnit
-
addUnitSelectionChangedListener
public void addUnitSelectionChangedListener(NumberAndUnitsComposite.UnitSelectionChangedListener<Q> listener) -
addModifyListener
public void addModifyListener(org.eclipse.swt.events.ModifyListener listener) -
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
- Overrides:
toStringin classorg.eclipse.swt.widgets.Composite
-