com.gridsystems.config.tools.swing
Class PopupTextField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.gridsystems.config.tools.swing.PopupTextField
All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible
Direct Known Subclasses:
FileChooserField

public abstract class PopupTextField
extends javax.swing.JPanel
implements java.awt.event.FocusListener

Abstract class for fields that get its contents from a popup component. Implementations of this class should define a graphic component that will display in a popup windows. The openPopup() method must be able to launch this popup window. If the popup is modalless, this method must also call postCheckChange() once the data manipulation has finished. The default implementation works if the value managed by the component is the String shown at the text field. In any other case, the methods setValue() and getValue() should be implemented to discern between the value and its String representation. IMPORTANT: getValue() should return a copy of the object if it can be modified from outside (the original implementation returns String, that are inmutable). Changes are detected at the method hasChanged() from comparing the values stored before and after a possible modification (at the private fields previousValue and newValue). These values are set by the calls to preCheckChanges() and postCheckChanges(). postCheckChanges() also calls the hasChangedMethod() and, if it returns true, launches a PropertyChanged event reporting the change. Finally, the implementation of FocusListener only reacts to focus events originated by the text field. Objects from this class and its implementations should not be added as focus listeners of any component.

Author:
SJM
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PopupTextField()
          Default constructor.
 
Method Summary
 void discard()
          Sets the previous value as the current one.
 void focusGained(java.awt.event.FocusEvent focusEvent)
          Receives an event of focus gained.
 void focusLost(java.awt.event.FocusEvent focusEvent)
          Receives an event of focus lost.
 java.lang.String getButtonText()
          Gets the text to display at the button.
 java.lang.String getPropertyName()
          Gets the property name of the component.
 java.lang.Object getValue()
          Returns the value stored by the component.
 boolean hasChanged()
          Tells if the value of the component has changed.
 boolean isFieldEditable()
          Gets if the field can be modified by the user or not.
protected abstract  void openPopup()
          Opens a popup to ask the user for data.
 void postCheckChanges()
          Checks for changes in the value and, in that case, fires an event.
 void preCheckChanges()
          Stores the value of the component value to check for future changes.
 void setButtonText(java.lang.String buttonText)
          Sets the text to display at the button.
 void setEnabled(boolean enabled)
          
 void setFieldEditable(boolean textEditable)
          Sets if the field can be modified by the user or not.
 void setValue(java.lang.Object value)
          Sets the value managed by the component.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, 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, addInputMethodListener, 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, getInputMethodRequests, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, 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
 

Constructor Detail

PopupTextField

public PopupTextField()
Default constructor. Default constructor. It should be called for every constructor of the implementations of this abstract class.

Method Detail

setEnabled

public void setEnabled(boolean enabled)

Overrides:
setEnabled in class javax.swing.JComponent

getValue

public java.lang.Object getValue()
Returns the value stored by the component. Returns the value managed by the component. The default implementation just returns the String displayed at the text field; reimplement this method if the value shown is not the same than the actual value. This is the value used to check for changes in hasChanged();

Returns:
an Object with the value managed by the component.
See Also:
hasChanged()

setValue

public void setValue(java.lang.Object value)
Sets the value managed by the component.

The default implementation just sets the text of the text field to the result of doing toString to value(or the empty String if value is null). Reimplement this method if the value shown is not the same than the actual value. This is the value used to check for changes in hasChanged();

Parameters:
value - The value to set
See Also:
hasChanged()

getPropertyName

public final java.lang.String getPropertyName()
Gets the property name of the component. Gets the property name of the component. The only use of the property name is as a parameter when firing an event of property change. The default value is ""; but as BasePanel#watch(PopupTextField) just ignores the property name, it usually does not need to be changed. This method is provided for the case that more sophisticated PropertyChangeListener are added to the list of listeners of this object.

Returns:
a String with the property name of the component.

setButtonText

public final void setButtonText(java.lang.String buttonText)
Sets the text to display at the button.

Parameters:
buttonText - a String with the new text to display at the button.

getButtonText

public final java.lang.String getButtonText()
Gets the text to display at the button.

Returns:
a String with the text displayed at the button.

setFieldEditable

public final void setFieldEditable(boolean textEditable)
Sets if the field can be modified by the user or not.

Parameters:
textEditable - a boolean that is true if and only if the user should be able to edit the text field.

isFieldEditable

public final boolean isFieldEditable()
Gets if the field can be modified by the user or not.

Returns:
a boolean that is true if and only if the user can edit the text field.

preCheckChanges

public final void preCheckChanges()
Stores the value of the component value to check for future changes. Stores the current value of the component value to check for changes. This method should be called before every possible ocassion in which the value managed by the component could be modified. In the default implementation, it is before opening the popup or when the text field gets the focus. The checks are made in the postCheckChanges method.

See Also:
postCheckChanges()

postCheckChanges

public final void postCheckChanges()
Checks for changes in the value and, in that case, fires an event. Checks for changes in the value managed by the component. The check is made calling the hasChanged() method. If a change is detected, a PropertyChanged event reporting this is fired. This method should be called after every possible ocassion in which the value managed by the component could have been modified. In the default implementation, it is after calling openPopup() or when the text field loses the focus.


discard

public final void discard()
Sets the previous value as the current one.


openPopup

protected abstract void openPopup()
Opens a popup to ask the user for data. Opens a popup with the UI specific for the data type. Once this method returns, the old and new values of the component will be checked. If the popup is not modal (the method returns before the popup has been closed), the popup must call the postCheckChange() method after changing the value managed by the component.


hasChanged

public boolean hasChanged()
Tells if the value of the component has changed. Tells if the value of the component has changed. This must be done by comparing the previousValue and newValue set by preCheckChanges() and postCheckChanges(). The default implementation returns true if and only if both objects are null or if the equals() method of them returns false.

Returns:
a boolean that is true if the previous and new values are not the same.
See Also:
preCheckChanges(), postCheckChanges()

focusGained

public final void focusGained(java.awt.event.FocusEvent focusEvent)
Receives an event of focus gained. Receives an event of focus gained. This method will only react to focus events originated by the text field of the component, and does it by storing its current value for later comparisons of changes.

Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
focusEvent - the FocusEvent with the information of what has happened.
See Also:
preCheckChanges()

focusLost

public final void focusLost(java.awt.event.FocusEvent focusEvent)
Receives an event of focus lost. Receives an event of focus lost. This method will only react to focus events originated by the text field of the component, and does it by storing checking for changes in its value.

Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
focusEvent - the FocusEvent with the information of what has happened.
See Also:
postCheckChanges()


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.