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. Based on weka.gui.GenericArrayEditor- Author:
- Len Trigg ([email protected])
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classGenericArrayEditor.EditorListCellRendererThis 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 LoggerLOGGERfor logging.protected AbstractBaseActionm_ActionRestorethe restore action.protected AbstractBaseActionm_ActionSortAscthe sort (asc) action.protected AbstractBaseActionm_ActionSortDescthe sort (desc) action.protected Set<ChangeListener>m_ArrayChangeListenersthe change listeners (get notified whenever items get added/removed/updated).protected BaseButtonWithDropDownMenum_ButtonActionsMore actions.protected BaseButtonm_ButtonAddClick to add the current object configuration to the array.protected BaseButtonm_ButtonAddMultipleClick to add multiple objects to the array.protected BaseButtonm_ButtonCancelClick to cancel the dialog.protected BaseButtonm_ButtonCopyClick to copy the currently selected object in array into the edit field.protected BaseButtonm_ButtonDownClick this to move the selected array value(s) one down.protected BaseButtonm_ButtonEditClick this to edit the selected array value.protected BaseButtonm_ButtonOKClick to OK the dialog.protected BaseButtonm_ButtonRemoveClick this to delete the selected array values.protected BaseButtonm_ButtonRemoveAllClick this to delete all the array values.protected BaseButtonm_ButtonSetFavoritesClick to set favorites.protected BaseButtonm_ButtonUpClick this to move the selected array value(s) one up.protected booleanm_CanSortwhether the objects implement comparable.protected GenericObjectEditorDialogm_DialogThe currently displayed property dialog, if any.protected Classm_ElementClassThe class of objects allowed in the array.protected PropertyEditorm_ElementEditorThe property editor for the class we are editing.protected BaseListWithButtonsm_ElementListThe list component displaying current values.protected booleanm_IsPrimitivewhether the objects are wrapped with BaseObject.protected JLabelm_LabelThe label for when we can't edit that type.protected DefaultListModel<Object>m_ListModelThe defaultlistmodel holding our data.protected DefaultListModel<Object>m_ListModelBackupThe defaultlistmodel holding the backup of our data.protected ListDataListenerm_ModelListenerthe listener for model updates.protected booleanm_Modifiedwhether the content got modified.protected booleanm_OkAlwaysEnabledwhether the OK button is always enabled.protected JPanelm_PanelDialogButtonsthe panel for the buttons.protected PropertyChangeSupportm_SupportHandles property change notification.protected Componentm_Viewthe view in use.protected WindowAdapterm_WindowAdapterto catch the event when the user is closing the dialog via the "X".static StringNONEif 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 voidaddArrayChangeListener(ChangeListener l)Adds the change listener.voidaddCancelListener(ActionListener a)This is used to hook an action listener to the cancel button.booleanaddMultipleObjects()If the element editor implementsMultiSelectionEditora dialog is popped up to enter multiple objects.booleanaddMultipleObjects(Object[] objects)Adds multiple objects.booleanaddObject(Object object)Adds the object to the list.voidaddOkListener(ActionListener a)This is used to hook an action listener to the ok button.voidaddPropertyChangeListener(PropertyChangeListener l)Adds a PropertyChangeListener who will be notified of value changes.protected voidapply()Accepts the array.protected voidclose()Closes and disposes the window the GOE belongs to, if possible.protected JPopupMenucreateListPopupMenu(MouseEvent e)Creates the right-click popup for the list.protected booleaneditSelectedObject()Edits the selected object.voidfirePropertyChange()Fires a property change event.StringgetAsText()Returns null as we don't support getting/setting values as text.booleangetButtonsVisible()Returns whether the OK/Cancel/action buttons are visible.ComponentgetCustomEditor()Returns the array editing component.PropertyEditorgetElementEditor()Returns the element editor in use.StringgetJavaInitializationString()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.ObjectgetValue()Gets the current object array.protected voidinitGUI()For initializing the GUI.protected voidinitialize()Initializes the members.booleanisOkAlwaysEnabled()Returns whether the OK button is always enabled, not just when array was modified.booleanisPaintable()Returns true to indicate that we can paint a representation of the string array.protected voidnotifyArrayChangeListeners()Notifies all change listeners that the array elements have changed.voidpaintValue(Graphics gfx, Rectangle box)Paints a representation of the current classifier.voidremoveAllObjects()Removes all elements.voidremoveArrayChangeListener(ChangeListener l)Removes the change listener.voidremoveCancelListener(ActionListener a)This is used to remove an action listener from the cancel button.voidremoveOkListener(ActionListener a)This is used to remove an action listener from the ok button.voidremovePropertyChangeListener(PropertyChangeListener l)Removes a PropertyChangeListener.protected voidremoveSelectedObjects()Removes all currently selected objects.protected voidrestore()Restores the values to the original ones.voidsetAsText(String text)Returns null as we don't support getting/setting values as text.voidsetButtonsVisible(boolean value)Sets the visibility state of the OK/Cancel/action buttons.voidsetFavorites()Opens the favorites menu and replaces the current array elements when applying a favorite.voidsetOkAlwaysEnabled(boolean value)Sets whether the OK button is always enabled, not just when array was modified.voidsetValue(Object o)Sets the current object array.protected voidsort(boolean ascending)Sorts the values.booleansupportsCustomEditor()Returns true because we do support a custom editor.protected voidupdateButtons()Sets the correct enabled/disabled state of the buttons.protected voidupdateEditorType(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:
initializein 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
-
createListPopupMenu
protected JPopupMenu createListPopupMenu(MouseEvent e)
Creates the right-click popup for the list.- Parameters:
e- the triggering event
-
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:
setValuein interfacePropertyEditor- Parameters:
o- an object that must be an array.
-
getValue
public Object getValue()
Gets the current object array.- Specified by:
getValuein 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:
getJavaInitializationStringin 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:
isPaintablein interfacePropertyEditor- Returns:
- always true
-
paintValue
public void paintValue(Graphics gfx, Rectangle box)
Paints a representation of the current classifier.- Specified by:
paintValuein 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:
getAsTextin interfacePropertyEditor- Returns:
- always null
-
setAsText
public void setAsText(String text)
Returns null as we don't support getting/setting values as text.- Specified by:
setAsTextin 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:
getTagsin interfacePropertyEditor- Returns:
- always null
-
supportsCustomEditor
public boolean supportsCustomEditor()
Returns true because we do support a custom editor.- Specified by:
supportsCustomEditorin interfacePropertyEditor- Returns:
- always true
-
getCustomEditor
public Component getCustomEditor()
Returns the array editing component.- Specified by:
getCustomEditorin interfacePropertyEditor- Returns:
- itself
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener l)
Adds a PropertyChangeListener who will be notified of value changes.- Specified by:
addPropertyChangeListenerin interfacePropertyEditor- Overrides:
addPropertyChangeListenerin classContainer- Parameters:
l- a value of type 'PropertyChangeListener'
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Removes a PropertyChangeListener.- Specified by:
removePropertyChangeListenerin interfacePropertyEditor- Overrides:
removePropertyChangeListenerin 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 implementsMultiSelectionEditora 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.
-
-