|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.text.JTextComponent javax.swing.JTextField com.cosylab.gui.components.ResizableTextField com.cosylab.gui.components.NumberField
public class NumberField
Descendant of ResizableTextField
which only allows input of
numbers. Double and long number formats are supported through number
document classes DobuleDocument
and LongDocument
,
both descedents of AbstractNumberDocument
, while display
format is controlled using com.cosylab.util.PrintfFormat
string parser. The number field operates in two modes. When in focus mode,
the user can type in numbers that are recognized by the set number document
of the number field. When the user presses the Enter key or the
component goes out of focus the typed value is checked for range using the
set minimum and maximum allowed values. Than the new value is displayed
using the com.cosylab.util.PrinfFormat
with the set format
string. Value stored by the number field can be accessed through getter and
setter methods in both double
or long
or even
generic Number
type.
ResizableTextField
,
AbstractNumberDocument
,
PrintfFormat
,
Serialized FormNested Class Summary | |
---|---|
protected class |
NumberField.NumberActionAdapter
Listens for action events and handles the focus change. |
protected class |
NumberField.NumberDocumentAdapter
Listens for document events and handles the value property change. |
protected class |
NumberField.NumberFocusAdapter
Listens for focus events sets the appropriate display mode. |
protected class |
NumberField.NumberKeyAdapter
An implementation of KeyAdapter responsible for losing focus when the ESC key is pressed. |
protected class |
NumberField.TiltHandler
An extension of Timer used for periodic tilting of the Wheelswitch. |
Nested classes/interfaces inherited from class com.cosylab.gui.components.ResizableTextField |
---|
ResizableTextField.ResizableComponentAdapter, ResizableTextField.ResizableKeyAdapter |
Nested classes/interfaces inherited from class javax.swing.JTextField |
---|
javax.swing.JTextField.AccessibleJTextField |
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 |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
static int |
ENTER_AT_CLICKED
Enter policy - enter at clicked position. |
static int |
ENTER_AT_END
Enter policy - enter at the end of existing value. |
static int |
ENTER_AT_START
Enter policy - enter at the beginning of existing value. |
static java.lang.String |
ENTER_POLICY
Enter policy name tag. |
static int |
ENTER_SELECTED
Enter policy - |
static java.lang.String |
NUMBER_TYPE
Number type property name tag. |
static int |
SET_AS_TYPED
Setting policy - value set as typed. |
static int |
SET_ON_APPLY
Setting policy - value set on apply. |
static int |
SET_ON_EXIT
Setting policy - value set when focus is lost. |
static java.lang.String |
SETTING_POLICY
Setting policy name tag. |
static java.lang.String |
VALUE
Value property name tag. |
Fields inherited from class javax.swing.JTextField |
---|
notifyAction |
Fields inherited from class javax.swing.text.JTextComponent |
---|
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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 |
Fields inherited from interface javax.swing.SwingConstants |
---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
NumberField()
Default constructor for NumberField creates number field with zero value. |
|
NumberField(java.lang.Number newValue)
Constructs a new NumberField with value. |
|
NumberField(java.lang.Number newValue,
java.lang.String newFormat)
Constructs a new NumberField with specified value and PrintfFormat format string. |
Method Summary | |
---|---|
void |
addSetListener(SetListener l)
Adds a SetListener to the list of listeners receiving events when sets are performed on this Numberfield. |
java.lang.Number |
castNumber(java.lang.Number number)
Converts provided number to Number instance whose class
matches current number type. |
static java.lang.String |
createDefaultFormat(java.lang.Class<? extends java.lang.Number> numberType)
Returns safe default format for type. |
static java.lang.String |
createDefaultFormat(java.lang.Class<? extends java.lang.Number> numberType,
java.lang.String format)
Converts format string to default safe format for appropriate number type. |
protected void |
fireSetPerformed()
|
double |
getDoubleValue()
Returns the value of type doubleValue |
javax.swing.border.Border |
getEditBorder()
Returns the edit border. |
int |
getEnterPolicy()
Returns the current enter policy. |
java.lang.String |
getFormat()
Returns the diplay format |
long |
getLongValue()
Returns the value of type longValue |
java.lang.Number |
getMaximum()
Returns the maximum value allowed by this NumberField. |
java.lang.Number |
getMinimum()
Returns the minimum value allowed by this NumberField. |
java.awt.Color |
getNormalColor()
|
NumberDescriptor |
getNumberDescriptor()
Returns descriptor object, to which visualization of number as strring is dlegated. |
java.lang.Class<? extends java.lang.Number> |
getNumberType()
Returns the number format |
java.awt.Color |
getOutOfBoundsColor()
|
int |
getSettingPolicy()
Returns the currently used seting policy by this Numberfield |
javax.swing.border.Border |
getStaticBorder()
Returns the static border. |
java.lang.Number |
getValue()
Returns generic representation of the value using the Number class. |
java.awt.Color |
getWarningColor()
|
boolean |
isTiltingEnabled()
Returns whether the component should indicate value out of bounds condition by visually tilting its border. |
boolean |
isWarnOutOfBounds()
Returns the warnOutOfBounds. |
static void |
main(java.lang.String[] args)
For testing and demonstration purposes. |
protected void |
paintComponent(java.awt.Graphics g)
This method hes been overriden to implement the feature of enhanced anti-aliasing paint of the text field. |
void |
removeSetListener(SetListener l)
Removes a SetListener from the list of listeners receiving events when sets are performed on this Numberfield. |
void |
setDoubleValue(double newValue)
Sets the value of type doubleValue to be displayed. |
void |
setEditBorder(javax.swing.border.Border border)
Sets the edit border. |
void |
setEnterPolicy(int policy)
Sets the enter policy. |
void |
setFormat(java.lang.String newFormat)
Sets the display format. |
void |
setLongValue(long newValue)
Sets the value of type long to be displayed. |
void |
setMaximum(java.lang.Number newMaximum)
Sets the maximum allowed value that can be entered in this NumberField. |
void |
setMinimum(java.lang.Number newMinimum)
Sets the minimum allowed value that can be entered in this NumberField. |
void |
setNormalColor(java.awt.Color normalColor)
|
void |
setNumberDescriptor(NumberDescriptor numberDescriptor)
When this is set with non-null value, this NumberField uses this descriptor to convert Number to string and back. |
void |
setNumberType(java.lang.Class<? extends java.lang.Number> newNumberFormat)
Sets the number format. |
void |
setOutOfBoundsColor(java.awt.Color outOfBoundsColor)
|
void |
setSettingPolicy(int newPolicy)
Sets the setting policy of thi Numberdisplayer. |
void |
setStaticBorder(javax.swing.border.Border border)
Sets the static border. |
void |
setTiltingEnabled(boolean b)
Sets the tilitng enabled property. |
void |
setValue(java.lang.Number newValue)
Sets the numeric value for this component. |
void |
setWarningColor(java.awt.Color warningColor)
|
void |
setWarnOutOfBounds(boolean b)
Sets the value of warnOutOfBounds flag. |
Methods inherited from class com.cosylab.gui.components.ResizableTextField |
---|
getMinimumSize, getPreferredSize, isEnhanced, isResizable, resize, setEnhanced, setFont, setMargin, setMinimumSize, setPreferredSize, setResizable, setText |
Methods inherited from class javax.swing.JTextField |
---|
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setHorizontalAlignment, setScrollOffset |
Methods inherited from class javax.swing.text.JTextComponent |
---|
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, 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, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, hide, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, 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, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String SETTING_POLICY
public static final int SET_AS_TYPED
public static final int SET_ON_APPLY
public static final int SET_ON_EXIT
public static final java.lang.String ENTER_POLICY
public static final int ENTER_AT_CLICKED
public static final int ENTER_SELECTED
public static final int ENTER_AT_END
public static final int ENTER_AT_START
public static final java.lang.String VALUE
public static final java.lang.String NUMBER_TYPE
Constructor Detail |
---|
public NumberField(java.lang.Number newValue, java.lang.String newFormat)
newValue
- initial value (null not permitted)newFormat
- initial format (null not permitted)
java.lang.IllegalArgumentException
- if value or format is nullpublic NumberField(java.lang.Number newValue)
newValue
- initial valuepublic NumberField()
Method Detail |
---|
public static java.lang.String createDefaultFormat(java.lang.Class<? extends java.lang.Number> numberType, java.lang.String format)
numberType
- number type for which format is createdformat
- old format to be used as reference
java.lang.NullPointerException
- if type is nullpublic static java.lang.String createDefaultFormat(java.lang.Class<? extends java.lang.Number> numberType)
numberType
- number type
java.lang.NullPointerException
- if type is nullpublic void setDoubleValue(double newValue)
doubleValue
to be displayed.
newValue
- public double getDoubleValue()
doubleValue
public void setEditBorder(javax.swing.border.Border border)
border
- new edit borderpublic javax.swing.border.Border getEditBorder()
public void setEnterPolicy(int policy)
ENTER_AT_CLICKED
number will be entered at the
place where the user clickedENTER_AT_END
number will be appended to the existing
valueENTER_AT_START
number will be prepended to the
existing valueENTER_SELECTED
number will overwrite the existing
value
policy
- new policypublic int getEnterPolicy()
public void setFormat(java.lang.String newFormat)
newFormat
- java.lang.String
java.lang.IllegalArgumentException
- DOCUMENT ME!PrintfFormat
public java.lang.String getFormat()
public void setLongValue(long newValue)
long
to be displayed.
newValue
- public long getLongValue()
longValue
public void setMaximum(java.lang.Number newMaximum)
newMaximum
- Numberpublic java.lang.Number getMaximum()
public void setMinimum(java.lang.Number newMinimum)
newMinimum
- Numberpublic java.lang.Number getMinimum()
public void setNumberType(java.lang.Class<? extends java.lang.Number> newNumberFormat) throws java.lang.IllegalArgumentException
Long.class
of
Double.class
.
newNumberFormat
-
java.lang.IllegalArgumentException
public java.lang.Class<? extends java.lang.Number> getNumberType()
public void setSettingPolicy(int newPolicy)
newPolicy
-
java.lang.IllegalArgumentException
- DOCUMENT ME!public int getSettingPolicy()
public void setStaticBorder(javax.swing.border.Border border)
border
- new static borderpublic javax.swing.border.Border getStaticBorder()
public void setTiltingEnabled(boolean b)
b
- whether the component should tilt when value is out of bounds.public boolean isTiltingEnabled()
public void setWarnOutOfBounds(boolean b)
b
- whether this component should change background color if value
is out of bounds.public void setValue(java.lang.Number newValue)
newValue
- Numberpublic java.lang.Number getValue()
Number
class.
public void addSetListener(SetListener l)
l
- listener to be added.public void removeSetListener(SetListener l)
l
- listener to be removed.protected void fireSetPerformed()
protected void paintComponent(java.awt.Graphics g)
ResizableTextField
paintComponent
in class ResizableTextField
g
- GraphicsJComponent.paintComponent(Graphics)
public NumberDescriptor getNumberDescriptor()
public void setNumberDescriptor(NumberDescriptor numberDescriptor)
numberDescriptor
- new Number visualization, can be
null
public java.lang.Number castNumber(java.lang.Number number)
Number
instance whose class
matches current number type.
number
- number to be cast to current number type
public java.awt.Color getNormalColor()
public void setNormalColor(java.awt.Color normalColor)
normalColor
- The normalColor to set.public java.awt.Color getOutOfBoundsColor()
public void setOutOfBoundsColor(java.awt.Color outOfBoundsColor)
outOfBoundsColor
- The outOfBoundsColor to set.public java.awt.Color getWarningColor()
public void setWarningColor(java.awt.Color warningColor)
warningColor
- The warningColor to set.public boolean isWarnOutOfBounds()
public static void main(java.lang.String[] args)
args
- String[]
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |