verinec.gui.configurator.nodeeditor
Class EditorTextField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextField
                      extended by verinec.gui.configurator.nodeeditor.EditorTextField
All Implemented Interfaces:
ActionListener, FocusListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, Scrollable, SwingConstants, IEditorComponent
Direct Known Subclasses:
EditorMultiTextField

public class EditorTextField
extends JTextField
implements FocusListener, ActionListener, IEditorComponent

The EditorTextField is a "Leaf" class in the Composite design pattern, it accepts user input, verifies it and assures coherence when treating the XML.

For an explication of the structural organisation of EditorTextFields see the documentation of the IEditorComponent.

The color code for the field works in the following way: An unmodified field is black. If the value is changed and happens to be the same value as before the modification, it stays black. If a value is entered which fails the verification, the field turns red. If the value is correct but differs from the previous value, it turns green, and the value is written to the underlying XML.

Author:
Damian Vogel
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTextField
JTextField.AccessibleJTextField
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  boolean attributeIsNecessary
          Stores whether an XML attribute can be removed or not, it will have an asterik next to its name to visualize its property of being necessary.
protected  String attributeName
          The Name of the XML attribute in which the value is stored.
protected  String childName
          Only used for EditorMultiTextField; is the name of the XML Elements which contain the multiple values.
protected  String concatenator
          Only used for EditorMultiTextField; Is an InputValidator class field that states the optimal separator and therefore is used to concatenate strings
protected  boolean containsNameForPanel
          Is true if the XML element type is "Hostname" or "Name"
protected  Color green
          The default GREEN color was not really readable, so this is the color for valid inputs.
protected  String inputValidatorMessage
          Is an InputValidator class field (Regular expression) that serves as InputValidator pattern; Depending on the pattern a ToolTip string is attributed.
protected  JLabel label
          The label; is stored as an instance field and will be displayed next to the field.
protected  Logger logger
          Debugging.
protected  NodeEditor nodeEditor
          Links to the NodeEditor instance in order to call the NodeEditor.setFocusTextField() and register itself.
protected  Element parentNode
          A link to the XML Element which contains the XML attribute.
protected  String previousInputValue
          If the value of a field is changed, its original value is stored in this variable.
protected  String separator
          Only used for EditorMultiTextField; Contains the InputValidator class field (Regular expression) that states the possible separators.
 
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
EditorTextField(String attributeName, Element parentNode, NodeEditor nodeEditor, String inputValidatorMessage, int fieldSize, boolean attributeIsNecessary, String labelString)
          A field can have different properties according to the Parameter values given on creation.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Checks the input.
protected  boolean attributeRemove(Element element, String attribute)
          Wrapper for the jdom function org.jdom.Element.removeAttribute.
 void checkInput()
          This is where the value of a field is verified.
 void discard()
          Resets all the changed values (i.e. all the colored fields).
 void discardRed()
          Resets all the wrong values (i.e. all the red fields).
protected  String elementRead(Element element, String attribute)
          Wrapper for the jdom function org.jdom.Element.elementRead.
protected  Element elementWrite(Element element, String attribute, String value)
          Wrapper for the jdom function org.jdom.Element.setAttribute.
 void focusGained(FocusEvent e)
          Once the field gets focus, it registers itself in the NodeEditor class as "the field having focus" by calling the setFocusTextField() function.
 void focusLost(FocusEvent e)
          The FocusLostEvent occurs if the Tab key is hit or the focus is transfered using the mouse.
 JLabel getLabel()
          Return the label to prompt for this field.
 void save()
          Saves the current value of the field.
 boolean update()
          Checks if there have been changes in the fields.
 
Methods inherited from class javax.swing.JTextField
addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, 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, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, 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, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, 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

attributeName

protected String attributeName
The Name of the XML attribute in which the value is stored.


previousInputValue

protected String previousInputValue
If the value of a field is changed, its original value is stored in this variable.


nodeEditor

protected NodeEditor nodeEditor
Links to the NodeEditor instance in order to call the NodeEditor.setFocusTextField() and register itself. (See also the focusGained() function)


inputValidatorMessage

protected String inputValidatorMessage
Is an InputValidator class field (Regular expression) that serves as InputValidator pattern; Depending on the pattern a ToolTip string is attributed.


parentNode

protected Element parentNode
A link to the XML Element which contains the XML attribute.


attributeIsNecessary

protected boolean attributeIsNecessary
Stores whether an XML attribute can be removed or not, it will have an asterik next to its name to visualize its property of being necessary.


label

protected JLabel label
The label; is stored as an instance field and will be displayed next to the field.


separator

protected String separator
Only used for EditorMultiTextField; Contains the InputValidator class field (Regular expression) that states the possible separators.


concatenator

protected String concatenator
Only used for EditorMultiTextField; Is an InputValidator class field that states the optimal separator and therefore is used to concatenate strings


childName

protected String childName
Only used for EditorMultiTextField; is the name of the XML Elements which contain the multiple values.


green

protected Color green
The default GREEN color was not really readable, so this is the color for valid inputs.


containsNameForPanel

protected boolean containsNameForPanel
Is true if the XML element type is "Hostname" or "Name"


logger

protected Logger logger
Debugging.

Constructor Detail

EditorTextField

public EditorTextField(String attributeName,
                       Element parentNode,
                       NodeEditor nodeEditor,
                       String inputValidatorMessage,
                       int fieldSize,
                       boolean attributeIsNecessary,
                       String labelString)
A field can have different properties according to the Parameter values given on creation. See the Field summary for detailed information about the different parameters.

Parameters:
attributeName -
parentNode -
nodeEditor -
inputValidatorMessage -
fieldSize - Number of columns for the field. (Currently uniform, constant in EditFieldsPanel).
attributeIsNecessary -
labelString -
Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
Checks the input.

Specified by:
actionPerformed in interface ActionListener
Parameters:
e - The action event.

focusGained

public void focusGained(FocusEvent e)
Once the field gets focus, it registers itself in the NodeEditor class as "the field having focus" by calling the setFocusTextField() function. This is necessary because the FocusLostEvent is not triggered if the component gets unselected in the DrawPanel, and a modified input might be lost. (cf the focusLost() function)

Specified by:
focusGained in interface FocusListener
Parameters:
e - The event.

focusLost

public void focusLost(FocusEvent e)
The FocusLostEvent occurs if the Tab key is hit or the focus is transfered using the mouse. The Effect is the same as with the ActionPerformedEvent; the data is validated and according to the result the field changes its color. Additionally, it unregisters in the NodeEditor class. (cf the focusGained() function)

Specified by:
focusLost in interface FocusListener
Parameters:
e - The event.

checkInput

public void checkInput()
This is where the value of a field is verified. If the value is empty, the Attribute is removed. Except the Attribute is necessary, then it is reset to its previous value (which obviously was correct). If it is not empty, it is verified using the InputValidator.go() function. According to the result of the verification, the color of the field changes to black, green or red.


update

public boolean update()
Checks if there have been changes in the fields.

Specified by:
update in interface IEditorComponent
Returns:
If there is nothing changed, false is returned. If there are changed values, (i.e. green or red fields) true is returned.

save

public void save()
Saves the current value of the field.

Specified by:
save in interface IEditorComponent

discard

public void discard()
Resets all the changed values (i.e. all the colored fields). The target value (the value which will be in the field after this function executed) is stored in the variable previousInputValue.

Specified by:
discard in interface IEditorComponent

discardRed

public void discardRed()
Resets all the wrong values (i.e. all the red fields). The target value (the value which will be in the field after this function executed) is stored in the Attribute itself.

Specified by:
discardRed in interface IEditorComponent

getLabel

public JLabel getLabel()
Return the label to prompt for this field.

Returns:
The label to display next to the field.

elementWrite

protected Element elementWrite(Element element,
                               String attribute,
                               String value)
Wrapper for the jdom function org.jdom.Element.setAttribute. Wrapping this function facilitates the implementation of the EditorMultiTextField where all the functionality of this class can be kept and only jdom access functions have to be rewritten. If we set a node name, we also repaint the graphical view of the network.

Parameters:
element - The element to set its attribute.
attribute - The attribute to set.
value - The value to set the attribute to.
Returns:
The modified element.

attributeRemove

protected boolean attributeRemove(Element element,
                                  String attribute)
Wrapper for the jdom function org.jdom.Element.removeAttribute. Wrapping this function facilitates the implementation of the EditorMultiTextField where all the functionality of this class can be kept and only jdom access functions have to be rewritten.

Parameters:
element - The element to modify.
attribute - The attribute name to remove.
Returns:
Whether removing the attribute was successful.

elementRead

protected String elementRead(Element element,
                             String attribute)
Wrapper for the jdom function org.jdom.Element.elementRead. Wrapping this function facilitates the implementation of the EditorMultiTextField where all the functionality of this class can be kept and only jdom access functions have to be rewritten.

Parameters:
element - The element to read from.
attribute - The attribute name to read.
Returns:
The value of the attribute.

Copyright © 2005 Verinec, DIUF