Class NumRangeSelector
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.text.JTextComponent
-
- javax.swing.JTextField
-
- com.jstatcom.component.IValTextField
-
- com.jstatcom.component.NumRangeSelector
-
- All Implemented Interfaces:
- java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable, javax.swing.SwingConstants
public final class NumRangeSelector extends IValTextField
This component allows to input a range specified by two komma separated numbers that is automatically checked according to an overallNumberRangeobject. The overall range to validate against can be specified by constants.Example text input would be
1, 100. Only real numbers are allowed, +/- Infinity or NaN are always invalid. This component always assumes that the range type of the selected range isCLOSED, even if a different range was set via thesetNumberRangemethod. ThereforegetNumberRangealways returns aCLOSEDrange. The overall range does not have this restriction imposed.Usage Note:
If the number format type is set toNumberFormatTypes.DEFAULT, then the precision set for this selector defines, how displayed numbers are rounded. Any additional precision is lost, after a number was selected. If, for example, onlyintnumbers should be possible, the precision can be set to 0, which is also the default. The resulting number is then stored as adoublethat is equal to anint.
If the number format type is set toNumberFormatTypes.SCIENTIFIC, then the precision is used only for the display. No rounding is performed and a precision of 0 does not mean that values are equal to anint.This class fires a "numberRange" property change, if a new number range was set.
- See Also:
NumberRange, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor and Description NumRangeSelector()Default constructor initializes overall range to (-Infinity,+Infinity) and sets the displayed range to value to1, 100.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description NumberFormatTypesgetNumberFormatType()Gets the current number format type.NumberRangegetNumberRange()Gets the currently displayed number range.NumberRangegetOverallNumberRange()Gets the overall range that the range input is checked against.java.lang.StringgetOverallRangeExpr()Gets the current overall number range displayed as a string, for example[1,100] or ("lowerBound_p", 20].intgetPrecision()Gets the precision for the displayed numbers.voidhandleError(java.lang.String msg)Error handling routine if validation failed.voidsetNumberFormatType(NumberFormatTypes newNumberFormatType)Sets the current number format type.voidsetNumberRange(NumberRange newRange)Sets the currently displayed number range with checking whether it conforms to the specified overall range.voidsetOverallNumberRange(NumberRange newNumberRange)Sets the overall range that the range input is checked against.voidsetOverallRangeExpr(java.lang.String expr)Sets the range to be checked against by specifying a string of the form["(", "["] lowerBound "," upperBound + ["]", ")"], wherelowerbound/upperBoundare either a number or a symbolname, for example[lowerBound_p, upperBound_p] or (0, upperBound_x] or [1,10].voidsetPrecision(int newPrecision)Sets number of digits right to decimal point.voidsetRangeBounds(java.lang.String expr)Sets the currently selected range by specifying a string with lower bound and upper bound seperated by a komma, for example1, 100.java.lang.StringvalidateInput()Validates input against the specified range whenever necessary.-
Methods inherited from class com.jstatcom.component.IValTextField
addNotify, isEditing, setTextCarefully
-
Methods inherited from class javax.swing.JTextField
addActionListener, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset
-
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Constructor Detail
-
NumRangeSelector
public NumRangeSelector()
Default constructor initializes overall range to (-Infinity,+Infinity) and sets the displayed range to value to1, 100.
-
-
Method Detail
-
getNumberFormatType
public NumberFormatTypes getNumberFormatType()
Gets the current number format type.- Returns:
- the format type in use
-
getNumberRange
public NumberRange getNumberRange()
Gets the currently displayed number range. This range is always of typeCLOSEDan can never have +/- Infinity bounds.- Returns:
- the (closed) selected number range
-
getOverallNumberRange
public NumberRange getOverallNumberRange()
Gets the overall range that the range input is checked against.- Returns:
- current overall number range
-
getOverallRangeExpr
public java.lang.String getOverallRangeExpr()
Gets the current overall number range displayed as a string, for example[1,100] or ("lowerBound_p", 20].- Returns:
- string representation of overall number range
-
getPrecision
public int getPrecision()
Gets the precision for the displayed numbers.- Returns:
- number count right to the decimal point
-
handleError
public void handleError(java.lang.String msg)
Error handling routine if validation failed. Displays error message and sets back number value to the last valid one..- Overrides:
handleErrorin classIValTextField- Parameters:
msg- an error message
-
setNumberFormatType
public void setNumberFormatType(NumberFormatTypes newNumberFormatType)
Sets the current number format type.- Parameters:
newNumberFormatType- format type to use
-
setNumberRange
public void setNumberRange(NumberRange newRange)
Sets the currently displayed number range with checking whether it conforms to the specified overall range. The number range is always set to range typeCLOSED, even ifnewRangehas a different type. This is possible, because any legal range can also be a closed range. Be aware that +/- Infinity is not allowed for the selected range bounds. This method fires a "numberRange" property change with the old value and the changed value, if a new number range was set.- Parameters:
newRange- the new selected number range- Throws:
java.lang.IllegalArgumentException- ifnewRangeis not enclosed in overall range
-
setOverallNumberRange
public void setOverallNumberRange(NumberRange newNumberRange)
Sets the overall range that the range input is checked against. The currently displayed range is automatically validated against the new overall range. If the current range is not valid, it automatically set to a legal value withinnewNumberRange.- Parameters:
newNumberRange- the overall number range for validation, ifnullthen a range of (-Infinity,+Infinity) is set.
-
setOverallRangeExpr
public void setOverallRangeExpr(java.lang.String expr)
Sets the range to be checked against by specifying a string of the form["(", "["] lowerBound "," upperBound + ["]", ")"], wherelowerbound/upperBoundare either a number or a symbolname, for example[lowerBound_p, upperBound_p] or (0, upperBound_x] or [1,10].If the range is specified without symbol names, it is set immediately. If the range depends on symbols to be loaded from a symbol table, this is postponed to the next
FOCUS_GAINEDevent. In the meantime, the default non-validating(-Infinity,Infinity)range is used.- Parameters:
expr- the expression to be parsed- Throws:
java.lang.IllegalArgumentException- ifexpr == nullor if it cannot be parsed to a valid range
-
setPrecision
public void setPrecision(int newPrecision)
Sets number of digits right to decimal point.- Parameters:
newPrecision- new number precision- Throws:
java.lang.IllegalArgumentException- ifnewPrecision < 0
-
setRangeBounds
public void setRangeBounds(java.lang.String expr)
Sets the currently selected range by specifying a string with lower bound and upper bound seperated by a komma, for example1, 100. Symbol names are not allowed for the bounds but have to be specified separately by the respective accessor methods.- Parameters:
expr- string containing komma separated bounds- Throws:
java.lang.IllegalArgumentException- if bounds are not enclosed in overall range or expr could not be parsed to a valid range of typeCLOSED
-
validateInput
public java.lang.String validateInput()
Validates input against the specified range whenever necessary. This method is invoked by the superclass and does not need to be called manually.- Specified by:
validateInputin classIValTextField- Returns:
nullif ok, an error message otherwise
-
-
DMelt 3.0 © DataMelt by jWork.ORG