Package adams.gui.goe
Class GenericArrayEditor
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.goe.GenericArrayEditor
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,PropertyEditor
,Serializable
,Accessible
public class GenericArrayEditor extends BasePanel implements PropertyEditor
A PropertyEditor for arrays of objects that themselves have property editors.- Author:
- Len Trigg (trigg@cs.waikato.ac.nz)
- See Also:
GenericArrayEditor
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
GenericArrayEditor.EditorListCellRenderer
This class handles the creation of list cell renderers from the property editors.-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected static Logger
LOGGER
for logging.protected AbstractBaseAction
m_ActionRestore
the restore action.protected AbstractBaseAction
m_ActionSortAsc
the sort (asc) action.protected AbstractBaseAction
m_ActionSortDesc
the sort (desc) action.protected Set<ChangeListener>
m_ArrayChangeListeners
the change listeners (get notified whenever items get added/removed/updated).protected BaseButtonWithDropDownMenu
m_ButtonActions
More actions.protected BaseButton
m_ButtonAdd
Click to add the current object configuration to the array.protected BaseButton
m_ButtonAddMultiple
Click to add multiple objects to the array.protected BaseButton
m_ButtonCancel
Click to cancel the dialog.protected BaseButton
m_ButtonCopy
Click to copy the currently selected object in array into the edit field.protected BaseButton
m_ButtonDown
Click this to move the selected array value(s) one down.protected BaseButton
m_ButtonEdit
Click this to edit the selected array value.protected BaseButton
m_ButtonOK
Click to OK the dialog.protected BaseButton
m_ButtonRemove
Click this to delete the selected array values.protected BaseButton
m_ButtonRemoveAll
Click this to delete all the array values.protected BaseButton
m_ButtonSetFavorites
Click to set favorites.protected BaseButton
m_ButtonUp
Click this to move the selected array value(s) one up.protected boolean
m_CanSort
whether the objects implement comparable.protected GenericObjectEditorDialog
m_Dialog
The currently displayed property dialog, if any.protected Class
m_ElementClass
The class of objects allowed in the array.protected PropertyEditor
m_ElementEditor
The property editor for the class we are editing.protected BaseListWithButtons
m_ElementList
The list component displaying current values.protected boolean
m_IsPrimitive
whether the objects are wrapped with BaseObject.protected JLabel
m_Label
The label for when we can't edit that type.protected DefaultListModel<Object>
m_ListModel
The defaultlistmodel holding our data.protected DefaultListModel<Object>
m_ListModelBackup
The defaultlistmodel holding the backup of our data.protected ListDataListener
m_ModelListener
the listener for model updates.protected boolean
m_Modified
whether the content got modified.protected boolean
m_OkAlwaysEnabled
whether the OK button is always enabled.protected JPanel
m_PanelDialogButtons
the panel for the buttons.protected PropertyChangeSupport
m_Support
Handles property change notification.protected Component
m_View
the view in use.protected WindowAdapter
m_WindowAdapter
to catch the event when the user is closing the dialog via the "X".static String
NONE
if there are no elements in the list.-
Fields inherited from class adams.gui.core.BasePanel
m_FileChooser
-
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_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, 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
Constructors Constructor Description GenericArrayEditor()
Sets up the array editor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addArrayChangeListener(ChangeListener l)
Adds the change listener.void
addCancelListener(ActionListener a)
This is used to hook an action listener to the cancel button.boolean
addMultipleObjects()
If the element editor implementsMultiSelectionEditor
a dialog is popped up to enter multiple objects.boolean
addMultipleObjects(Object[] objects)
Adds multiple objects.boolean
addObject(Object object)
Adds the object to the list.void
addOkListener(ActionListener a)
This is used to hook an action listener to the ok button.void
addPropertyChangeListener(PropertyChangeListener l)
Adds a PropertyChangeListener who will be notified of value changes.protected void
apply()
Accepts the array.protected void
close()
Closes and disposes the window the GOE belongs to, if possible.protected boolean
editSelectedObject()
Edits the selected object.void
firePropertyChange()
Fires a property change event.String
getAsText()
Returns null as we don't support getting/setting values as text.boolean
getButtonsVisible()
Returns whether the OK/Cancel/action buttons are visible.Component
getCustomEditor()
Returns the array editing component.PropertyEditor
getElementEditor()
Returns the element editor in use.String
getJavaInitializationString()
Supposedly returns an initialization string to create a classifier identical to the current one, including it's state, but this doesn't appear possible given that the initialization string isn't supposed to contain multiple statements.String[]
getTags()
Returns null as we don't support getting values as tags.Object
getValue()
Gets the current object array.protected void
initGUI()
For initializing the GUI.protected void
initialize()
Initializes the members.boolean
isOkAlwaysEnabled()
Returns whether the OK button is always enabled, not just when array was modified.boolean
isPaintable()
Returns true to indicate that we can paint a representation of the string array.protected void
notifyArrayChangeListeners()
Notifies all change listeners that the array elements have changed.void
paintValue(Graphics gfx, Rectangle box)
Paints a representation of the current classifier.void
removeAllObjects()
Removes all elements.void
removeArrayChangeListener(ChangeListener l)
Removes the change listener.void
removeCancelListener(ActionListener a)
This is used to remove an action listener from the cancel button.void
removeOkListener(ActionListener a)
This is used to remove an action listener from the ok button.void
removePropertyChangeListener(PropertyChangeListener l)
Removes a PropertyChangeListener.protected void
removeSelectedObjects()
Removes all currently selected objects.protected void
restore()
Restores the values to the original ones.void
setAsText(String text)
Returns null as we don't support getting/setting values as text.void
setButtonsVisible(boolean value)
Sets the visibility state of the OK/Cancel/action buttons.void
setFavorites()
Opens the favorites menu and replaces the current array elements when applying a favorite.void
setOkAlwaysEnabled(boolean value)
Sets whether the OK button is always enabled, not just when array was modified.void
setValue(Object o)
Sets the current object array.protected void
sort(boolean ascending)
Sorts the values.boolean
supportsCustomEditor()
Returns true because we do support a custom editor.protected void
updateButtons()
Sets the correct enabled/disabled state of the buttons.protected void
updateEditorType(Object o)
Updates the type of object being edited, so attempts to find an appropriate propertyeditor.-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, finishInit, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, main, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
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, 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, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, 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, 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, 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 Detail
-
NONE
public static final String NONE
if there are no elements in the list.- See Also:
- Constant Field Values
-
LOGGER
protected static Logger LOGGER
for logging.
-
m_Support
protected PropertyChangeSupport m_Support
Handles property change notification.
-
m_Label
protected JLabel m_Label
The label for when we can't edit that type.
-
m_ElementList
protected BaseListWithButtons m_ElementList
The list component displaying current values.
-
m_ElementClass
protected Class m_ElementClass
The class of objects allowed in the array.
-
m_ListModel
protected DefaultListModel<Object> m_ListModel
The defaultlistmodel holding our data.
-
m_ListModelBackup
protected DefaultListModel<Object> m_ListModelBackup
The defaultlistmodel holding the backup of our data.
-
m_ElementEditor
protected PropertyEditor m_ElementEditor
The property editor for the class we are editing.
-
m_IsPrimitive
protected boolean m_IsPrimitive
whether the objects are wrapped with BaseObject.
-
m_CanSort
protected boolean m_CanSort
whether the objects implement comparable.
-
m_ButtonRemove
protected BaseButton m_ButtonRemove
Click this to delete the selected array values.
-
m_ButtonRemoveAll
protected BaseButton m_ButtonRemoveAll
Click this to delete all the array values.
-
m_ButtonEdit
protected BaseButton m_ButtonEdit
Click this to edit the selected array value.
-
m_ButtonUp
protected BaseButton m_ButtonUp
Click this to move the selected array value(s) one up.
-
m_ButtonDown
protected BaseButton m_ButtonDown
Click this to move the selected array value(s) one down.
-
m_ButtonAdd
protected BaseButton m_ButtonAdd
Click to add the current object configuration to the array.
-
m_ButtonAddMultiple
protected BaseButton m_ButtonAddMultiple
Click to add multiple objects to the array.
-
m_ButtonSetFavorites
protected BaseButton m_ButtonSetFavorites
Click to set favorites.
-
m_ButtonCopy
protected BaseButton m_ButtonCopy
Click to copy the currently selected object in array into the edit field.
-
m_ButtonOK
protected BaseButton m_ButtonOK
Click to OK the dialog.
-
m_ButtonCancel
protected BaseButton m_ButtonCancel
Click to cancel the dialog.
-
m_ButtonActions
protected BaseButtonWithDropDownMenu m_ButtonActions
More actions.
-
m_ActionRestore
protected AbstractBaseAction m_ActionRestore
the restore action.
-
m_ActionSortAsc
protected AbstractBaseAction m_ActionSortAsc
the sort (asc) action.
-
m_ActionSortDesc
protected AbstractBaseAction m_ActionSortDesc
the sort (desc) action.
-
m_PanelDialogButtons
protected JPanel m_PanelDialogButtons
the panel for the buttons.
-
m_Dialog
protected GenericObjectEditorDialog m_Dialog
The currently displayed property dialog, if any.
-
m_WindowAdapter
protected WindowAdapter m_WindowAdapter
to catch the event when the user is closing the dialog via the "X".
-
m_Modified
protected boolean m_Modified
whether the content got modified.
-
m_OkAlwaysEnabled
protected boolean m_OkAlwaysEnabled
whether the OK button is always enabled.
-
m_View
protected Component m_View
the view in use.
-
m_ArrayChangeListeners
protected Set<ChangeListener> m_ArrayChangeListeners
the change listeners (get notified whenever items get added/removed/updated).
-
m_ModelListener
protected ListDataListener m_ModelListener
the listener for model updates.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classBasePanel
-
close
protected void close()
Closes and disposes the window the GOE belongs to, if possible.
-
updateButtons
protected void updateButtons()
Sets the correct enabled/disabled state of the buttons.
-
apply
protected void apply()
Accepts the array.
-
restore
protected void restore()
Restores the values to the original ones.
-
sort
protected void sort(boolean ascending)
Sorts the values.- Parameters:
ascending
- if true, sorting is done ascending, otherwise descending
-
updateEditorType
protected void updateEditorType(Object o)
Updates the type of object being edited, so attempts to find an appropriate propertyeditor.- Parameters:
o
- a value of type 'Object'
-
setValue
public void setValue(Object o)
Sets the current object array.- Specified by:
setValue
in interfacePropertyEditor
- Parameters:
o
- an object that must be an array.
-
getValue
public Object getValue()
Gets the current object array.- Specified by:
getValue
in interfacePropertyEditor
- Returns:
- the current object array
-
getElementEditor
public PropertyEditor getElementEditor()
Returns the element editor in use.- Returns:
- the editor, null if not available
-
getJavaInitializationString
public String getJavaInitializationString()
Supposedly returns an initialization string to create a classifier identical to the current one, including it's state, but this doesn't appear possible given that the initialization string isn't supposed to contain multiple statements.- Specified by:
getJavaInitializationString
in interfacePropertyEditor
- Returns:
- the java source code initialisation string
-
isPaintable
public boolean isPaintable()
Returns true to indicate that we can paint a representation of the string array.- Specified by:
isPaintable
in interfacePropertyEditor
- Returns:
- always true
-
paintValue
public void paintValue(Graphics gfx, Rectangle box)
Paints a representation of the current classifier.- Specified by:
paintValue
in interfacePropertyEditor
- Parameters:
gfx
- the graphics context to usebox
- the area we are allowed to paint into
-
getAsText
public String getAsText()
Returns null as we don't support getting/setting values as text.- Specified by:
getAsText
in interfacePropertyEditor
- Returns:
- always null
-
setAsText
public void setAsText(String text)
Returns null as we don't support getting/setting values as text.- Specified by:
setAsText
in interfacePropertyEditor
- Parameters:
text
- the text value- Throws:
IllegalArgumentException
- as we don't support getting/setting values as text.
-
getTags
public String[] getTags()
Returns null as we don't support getting values as tags.- Specified by:
getTags
in interfacePropertyEditor
- Returns:
- always null
-
supportsCustomEditor
public boolean supportsCustomEditor()
Returns true because we do support a custom editor.- Specified by:
supportsCustomEditor
in interfacePropertyEditor
- Returns:
- always true
-
getCustomEditor
public Component getCustomEditor()
Returns the array editing component.- Specified by:
getCustomEditor
in interfacePropertyEditor
- Returns:
- itself
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener l)
Adds a PropertyChangeListener who will be notified of value changes.- Specified by:
addPropertyChangeListener
in interfacePropertyEditor
- Overrides:
addPropertyChangeListener
in classContainer
- Parameters:
l
- a value of type 'PropertyChangeListener'
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Removes a PropertyChangeListener.- Specified by:
removePropertyChangeListener
in interfacePropertyEditor
- Overrides:
removePropertyChangeListener
in classComponent
- Parameters:
l
- a value of type 'PropertyChangeListener'
-
addOkListener
public void addOkListener(ActionListener a)
This is used to hook an action listener to the ok button.- Parameters:
a
- The action listener.
-
addCancelListener
public void addCancelListener(ActionListener a)
This is used to hook an action listener to the cancel button.- Parameters:
a
- The action listener.
-
removeOkListener
public void removeOkListener(ActionListener a)
This is used to remove an action listener from the ok button.- Parameters:
a
- The action listener
-
removeCancelListener
public void removeCancelListener(ActionListener a)
This is used to remove an action listener from the cancel button.- Parameters:
a
- The action listener
-
addObject
public boolean addObject(Object object)
Adds the object to the list.- Parameters:
object
- the object to add- Returns:
- true if successfully added
-
addMultipleObjects
public boolean addMultipleObjects()
If the element editor implementsMultiSelectionEditor
a dialog is popped up to enter multiple objects.- Returns:
- true if a dialog was popped up and all objects added successfully
-
addMultipleObjects
public boolean addMultipleObjects(Object[] objects)
Adds multiple objects.- Parameters:
objects
- the objects to add- Returns:
- true if all objects were added successfully
-
setFavorites
public void setFavorites()
Opens the favorites menu and replaces the current array elements when applying a favorite.
-
removeAllObjects
public void removeAllObjects()
Removes all elements.
-
removeSelectedObjects
protected void removeSelectedObjects()
Removes all currently selected objects.
-
editSelectedObject
protected boolean editSelectedObject()
Edits the selected object.- Returns:
- true is successfully edited
-
firePropertyChange
public void firePropertyChange()
Fires a property change event.- See Also:
m_Support
-
setOkAlwaysEnabled
public void setOkAlwaysEnabled(boolean value)
Sets whether the OK button is always enabled, not just when array was modified.- Parameters:
value
- true if to always enable
-
isOkAlwaysEnabled
public boolean isOkAlwaysEnabled()
Returns whether the OK button is always enabled, not just when array was modified.- Returns:
- true if always enabled
-
setButtonsVisible
public void setButtonsVisible(boolean value)
Sets the visibility state of the OK/Cancel/action buttons.- Parameters:
value
- whether to show them or hide them
-
getButtonsVisible
public boolean getButtonsVisible()
Returns whether the OK/Cancel/action buttons are visible.- Returns:
- true if visible
-
addArrayChangeListener
public void addArrayChangeListener(ChangeListener l)
Adds the change listener. Gets notified whenever the array elements change.- Parameters:
l
- the listener to add
-
removeArrayChangeListener
public void removeArrayChangeListener(ChangeListener l)
Removes the change listener.- Parameters:
l
- the listener to remove
-
notifyArrayChangeListeners
protected void notifyArrayChangeListeners()
Notifies all change listeners that the array elements have changed.
-
-