Package nz.ac.waikato.cms.gui.core
Class AbstractChooserPanel<T>
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
nz.ac.waikato.cms.gui.core.BasePanel
nz.ac.waikato.cms.gui.core.AbstractChooserPanel<T>
- Type Parameters:
T- the type of object to handle
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
- Direct Known Subclasses:
DirectoryChooserPanel,FileChooserPanel,FontChooserPanel
A panel that contains a text field with the current choice and a
button for bringing up a dialog offering the choice.
- Version:
- $Revision: 15192 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for editors that can customize the popup menu.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JButtonthe button for bringing up the chooser dialog.protected HashSet<ChangeListener>listeners that listen to changes of the selected value.protected booleanwhether the chooser is editable.protected booleanwhether inline editing is enabled.protected JLabelthe prefix label.protected JLabela spacer for the prefix label.protected JPanelthe panel for the button(s).protected JPanelthe panel for the prefix.protected AbstractChooserPanel.PopupMenuCustomizeroptional customizer of the popup.protected AbstractChooserPanelthe panel itself.protected JTextFieldthe text field.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInitializes the panel with no value. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener for connect/disconnect events to the internal list.voidchoose()Lets the user choose and updates the current value if choosing was successful.voidcleanUp()Cleans up data structures, frees up memory.protected voidCopies the current settings to the clipboard.protected abstract TdoChoose()Performs the actual choosing of an object.voidFires a change event to all subscribed listeners that the value has changed.protected abstract TfromString(String value) Converts the string representation into its object representation.Returns the current value.protected StringThe string that is used by default.protected JPopupMenuReturns a popup menu when right-clicking on the edit field.Returns the currently set customizer.Returns the current text of the prefix label.Returns the prefix label.protected intReturns the number of columns in the selection text field.protected StringReturns the current string from the clipboard.intReturns the number of columns of the text field.voidLets the text component grab the focus.booleanhasValue()Checks whether the value of text field is different from the default value, i.e., a proper value.protected voidinitGUI()Initializes the GUI elements.protected voidInitializes the members.booleanReturns whether the chooser is editable or read-only.booleanReturns whether inline editing is enabled, i.e., editing without having to bring up the chooser.voidmoveChooseButton(boolean left) Moves the "..." button to either the left or right.protected voidNotifies all listeners with the given event.protected voidPastes the string representation from the clipboard.voidRemoves a listener for connect/disconnect events from the internal list.booleansetCurrent(T value) Sets the current value.voidSets the default value.voidsetEditable(boolean value) Sets whether the chooser is editable or read-only.voidsetEnabled(boolean enabled) Sets the enabled state of the panel.voidsetInlineEditingEnabled(boolean value) Sets whether inline editing is enabled, i.e., editing without bringing up chooser.voidSets the customizer.voidSets the text for the prefix label.voidsetTextColumns(int value) Sets the number of columns for the text field.voidsetToolTipText(String text) Sets the tool tip, displayed when hovering with the mouse.protected abstract StringConverts the value into its string representation.protected voidUpdates the preferred size of the panel.Methods inherited from class nz.ac.waikato.cms.gui.core.BasePanel
finishInitMethods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods 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, transferFocusDownCycle, validate, validateTreeMethods 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, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
m_Self
the panel itself. -
m_TextSelection
the text field. -
m_PanelPrefix
the panel for the prefix. -
m_LabelPrefix
the prefix label. -
m_LabelPrefixSpacer
a spacer for the prefix label. -
m_PanelButtons
the panel for the button(s). -
m_ButtonSelection
the button for bringing up the chooser dialog. -
m_ChangeListeners
listeners that listen to changes of the selected value. -
m_PopupMenuCustomizer
optional customizer of the popup. -
m_Editable
protected boolean m_Editablewhether the chooser is editable. -
m_InlineEditingEnabled
protected boolean m_InlineEditingEnabledwhether inline editing is enabled.
-
-
Constructor Details
-
AbstractChooserPanel
protected AbstractChooserPanel()Initializes the panel with no value.
-
-
Method Details
-
initialize
protected void initialize()Initializes the members.- Overrides:
initializein classBasePanel
-
initGUI
protected void initGUI()Initializes the GUI elements. -
getSelectionColumns
protected int getSelectionColumns()Returns the number of columns in the selection text field.- Returns:
- the number of columns
-
setPrefix
Sets the text for the prefix label. Mnemonics can be indicated by a preceding underscore "_".- Parameters:
value- the text to display- See Also:
-
getPrefix
Returns the current text of the prefix label.- Returns:
- the text currently being displayed
-
getPrefixLabel
Returns the prefix label.- Returns:
- the label
-
getDefaultString
The string that is used by default. E.g., if a "null" value is provided.- Returns:
- the default string
-
setDefault
public void setDefault()Sets the default value. -
toString
Converts the value into its string representation.- Parameters:
value- the value to convert- Returns:
- the generated string
-
setCurrent
Sets the current value.- Parameters:
value- the value to use, can be null- Returns:
- if successfully set
-
fireCurrentValueChanged
public void fireCurrentValueChanged()Fires a change event to all subscribed listeners that the value has changed. -
fromString
Converts the string representation into its object representation.- Parameters:
value- the string value to convert- Returns:
- the generated object
-
getCurrent
Returns the current value.- Returns:
- the current value
-
copyToClipboard
protected void copyToClipboard()Copies the current settings to the clipboard. -
getStringFromClipboard
Returns the current string from the clipboard.- Returns:
- the string, null if not available
-
pasteFromClipboard
protected void pasteFromClipboard()Pastes the string representation from the clipboard. -
addChangeListener
Adds a listener for connect/disconnect events to the internal list.- Parameters:
l- the listener to add
-
removeChangeListener
Removes a listener for connect/disconnect events from the internal list.- Parameters:
l- the listener to remove
-
notifyChangeListeners
Notifies all listeners with the given event.- Parameters:
e- the event to send to the listeners
-
setEnabled
public void setEnabled(boolean enabled) Sets the enabled state of the panel.- Overrides:
setEnabledin classJComponent- Parameters:
enabled- if true then the sub-elements will be enabled
-
setEditable
public void setEditable(boolean value) Sets whether the chooser is editable or read-only.- Parameters:
value- if true then the user can change the value
-
isEditable
public boolean isEditable()Returns whether the chooser is editable or read-only.- Returns:
- true if the user can change the value
-
setInlineEditingEnabled
public void setInlineEditingEnabled(boolean value) Sets whether inline editing is enabled, i.e., editing without bringing up chooser.- Parameters:
value- true if inlined editing enabled
-
isInlineEditingEnabled
public boolean isInlineEditingEnabled()Returns whether inline editing is enabled, i.e., editing without having to bring up the chooser.- Returns:
- true if inline editing enabled
-
setToolTipText
Sets the tool tip, displayed when hovering with the mouse.- Overrides:
setToolTipTextin classJComponent- Parameters:
text- the text, null to turn off
-
doChoose
Performs the actual choosing of an object.- Returns:
- the chosen object or null if none chosen
-
choose
public void choose()Lets the user choose and updates the current value if choosing was successful. -
hasValue
public boolean hasValue()Checks whether the value of text field is different from the default value, i.e., a proper value.- Returns:
- true if a proper value is available
-
updatePreferredSize
protected void updatePreferredSize()Updates the preferred size of the panel. -
setTextColumns
public void setTextColumns(int value) Sets the number of columns for the text field.- Parameters:
value- the number of columns (>0)
-
getTextColumns
public int getTextColumns()Returns the number of columns of the text field.- Returns:
- the number of columns (>0)
-
grabFocus
public void grabFocus()Lets the text component grab the focus.- Overrides:
grabFocusin classJComponent
-
getPopupMenu
Returns a popup menu when right-clicking on the edit field.- Returns:
- the menu, null if non available
-
setPopupMenuCustomizer
Sets the customizer. Use null do disable.- Parameters:
value- the customizer, or null to disable
-
getPopupMenuCustomizer
Returns the currently set customizer.- Returns:
- the customizer, or null if none set
-
moveChooseButton
public void moveChooseButton(boolean left) Moves the "..." button to either the left or right.- Parameters:
left- if true the button gets moved to the left, otherwise to the right
-
cleanUp
public void cleanUp()Cleans up data structures, frees up memory.
Default implementation does nothing.
-