Package adams.gui.goe
Class GenericObjectEditor
- java.lang.Object
-
- adams.gui.goe.GenericObjectEditor
-
- All Implemented Interfaces:
UserModeSupporter,UndoHandler,CustomPanelSupplier,PropertyEditor
public class GenericObjectEditor extends Object implements PropertyEditor, CustomPanelSupplier, UserModeSupporter, UndoHandler
A PropertyEditor for objects.- Author:
- Len Trigg ([email protected]), Xin Xu ([email protected]), Richard Kirkby ([email protected]), FracPete (fracpete at waikato dot ac dot nz)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classGenericObjectEditor.GOEPanelHandles the GUI side of editing values.static interfaceGenericObjectEditor.PostProcessObjectHandlerInterface for post-processing the object after selecting it, but before setting it.
-
Field Summary
Fields Modifier and Type Field Description static StringACTION_CMD_CANCELthe action command for Cancel.static StringACTION_CMD_OKthe action command for OK.static StringACTION_CMD_OPENthe action command for Open.static StringACTION_CMD_REDOthe action command for Redo.static StringACTION_CMD_SAVEthe action command for Save.static StringACTION_CMD_UNDOthe action command for Undo.static intAPPROVE_OPTIONconstant for dialog approval.static intCANCEL_OPTIONconstant for dialog cancellation.protected static LoggerLOGGERfor logging.protected booleanm_canChangeClassInDialogwhether the class can be changed.protected Classm_ClassTypeThe Class of objects being edited.protected JPanelm_CustomPanelthe custom panel provided by this editor.protected BaseButtonm_CustomPanelChooseButtonthe button for choosing a different class in the custom panel.protected BaseButtonm_CustomPanelFavoriteButtonthe button for showing the favorites menu in the custom panel.protected Objectm_DefaultValuethe default value.protected Booleanm_DefaultValueDeterminedwhether a default value has been determined.protected GenericObjectEditor.GOEPanelm_EditorComponentThe GUI component for editing values, created when needed.protected booleanm_EnabledTrue if the GUI component is needed.protected AbstractItemFilterm_Filterthe class filter in use.protected intm_MinimumCharsthe minimum number of characters before triggering search events.protected Objectm_ObjectThe object being configured.protected List<String>m_ObjectNamesThe model containing the list of names to select from.protected PropertyPanelm_ObjectPropertyPanelThe property panel created for the objects.protected GenericObjectEditor.PostProcessObjectHandlerm_PostProcessObjectHandlerfor post-processing objects.protected Class[]m_ProposedClassesthe proposed classes.protected intm_Resultwhether the dialog was cancelled or ok'ed.protected PropertyChangeSupportm_SupportHandles property change notification.protected Undom_Undothe undo manager.protected UserModem_UserModethe user mode to use.static booleanSHOW_CHOOSE_CLASS_BUTTONwhether to show the choose class button.
-
Constructor Summary
Constructors Constructor Description GenericObjectEditor()Default constructor.GenericObjectEditor(boolean canChangeClassInDialog)Constructor that allows specifying whether it is possible to change the class within the editor dialog.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(PropertyChangeListener l)Adds a PropertyChangeListener who will be notified of value changes.protected booleancheckClassType(Object obj)Checks and, if possible, sets the class type for the given object.protected voidclassSelected(String className)Called when the user selects an class type to change to.voidclearLogMessage()Removes the message and hides the panel.voidcopyLogMessage()Copies the message to the clipboard.protected BaseButtoncreateChooseClassButton()Creates a button that when clicked will enable the user to change the class of the object being edited.protected BaseButtoncreateFavoriteButton()Creates a button brings up the favorites popup menu.protected ObjectdetermineDefaultValue()Determines the default value.voidfirePropertyChange()Fires a property change event.StringgetAsText()Returns null as we don't support getting/setting values as text.booleangetButtonsVisible()Returns whether the buttons are visible.booleangetCanChangeClassInDialog()Returns whether the user can change the class in the dialog.BasePopupMenugetChooseClassPopupMenu()Returns a popup menu that allows the user to change the class of object.protected List<String>getClasses()Called when the class of object being edited changes.ClassgetClassType()Returns the currently set class.ComponentgetCustomEditor()Returns the array editing component.JPanelgetCustomPanel()Gets the custom panel used for editing the object.AbstractItemFiltergetFilter()Returns the current filter.StringgetJavaInitializationString()Supposedly returns an initialization string to create a Object 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.StringgetLogMessage()Returns the current log message.intgetMinimumChars()Returns the minimum number of characters that the user needs to enter before triggering a search event.GenericObjectEditor.PostProcessObjectHandlergetPostProcessObjectHandler()Returns the handler for post-processing objects after they have been selected but before updating the UI.Class[]getProposedClasses()Returns the proposed classes.intgetResult()Returns whether the dialog got cancelled or approved.String[]getTags()Returns null as we don't support getting values as tags.UndogetUndo()Returns the current undo manager, can be null.booleangetUpdateSize()Returns whether to update the size.UserModegetUserMode()Returns the user mode to use for displaying the properties.ObjectgetValue()Gets the current Object.booleanhasLogMessage()Returns whether a message is currently being displayed.booleanisPaintable()Returns true to indicate that we can paint a representation of the Object.booleanisReadOnly()Returns whether the dialog is read-only.booleanisUndoSupported()Returns whether an Undo manager is currently available.voidlog(Level level, String msg)For logging messages.voidlog(Level level, String msg, Throwable t)For logging messages.voidpaintValue(Graphics gfx, Rectangle box)Paints a representation of the current Object.voidremovePropertyChangeListener(PropertyChangeListener l)Removes a PropertyChangeListener.voidsetAsText(String text)Returns null as we don't support getting/setting values as text.voidsetButtonsVisible(boolean value)Sets whether to display the buttons.voidsetCanChangeClassInDialog(boolean value)Sets whether the user can change the class in the dialog.voidsetClassType(Class type)Sets the class of values that can be edited.voidsetDefaultValue()Sets the current object to be the default, taken as the first item in the chooser.voidsetEnabled(boolean newVal)Sets whether the editor is "enabled", meaning that the current values will be painted.voidsetFilter(AbstractItemFilter value)Sets the filter to use for filtering the display.voidsetMinimumChars(int value)Sets the minimum number of characters that the user needs to enter before triggering a search event.protected voidsetObject(Object obj)Sets the current Object.voidsetPostProcessObjectHandler(GenericObjectEditor.PostProcessObjectHandler value)Sets the handler for post-processing objects after they have been selected but before updating the UI.voidsetProposedClasses(Class[] value)Sets the proposed classes.voidsetProposedClasses(Object[] value)Sets the proposed classes based on the provided objects.voidsetReadOnly(boolean value)Sets whether the dialog is read-only.voidsetUndo(Undo value)Sets the undo manager to use, can be null if no undo-support wanted.voidsetUpdateSize(boolean value)Sets whether to update the size.voidsetUserMode(UserMode value)Sets the user mode to use for displaying the properties.voidsetValue(Object o)Sets the current Object.booleansupportsCustomEditor()Returns true because we do support a custom editor.protected voidupdateObjectNames()Updates the list of selectable object names, adding any new names to the list.
-
-
-
Field Detail
-
ACTION_CMD_OK
public static final String ACTION_CMD_OK
the action command for OK.- See Also:
- Constant Field Values
-
ACTION_CMD_CANCEL
public static final String ACTION_CMD_CANCEL
the action command for Cancel.- See Also:
- Constant Field Values
-
ACTION_CMD_OPEN
public static final String ACTION_CMD_OPEN
the action command for Open.- See Also:
- Constant Field Values
-
ACTION_CMD_SAVE
public static final String ACTION_CMD_SAVE
the action command for Save.- See Also:
- Constant Field Values
-
ACTION_CMD_UNDO
public static final String ACTION_CMD_UNDO
the action command for Undo.- See Also:
- Constant Field Values
-
ACTION_CMD_REDO
public static final String ACTION_CMD_REDO
the action command for Redo.- See Also:
- Constant Field Values
-
CANCEL_OPTION
public static final int CANCEL_OPTION
constant for dialog cancellation.- See Also:
- Constant Field Values
-
APPROVE_OPTION
public static final int APPROVE_OPTION
constant for dialog approval.- See Also:
- Constant Field Values
-
SHOW_CHOOSE_CLASS_BUTTON
public static boolean SHOW_CHOOSE_CLASS_BUTTON
whether to show the choose class button.
-
LOGGER
protected static Logger LOGGER
for logging.
-
m_Object
protected Object m_Object
The object being configured.
-
m_DefaultValue
protected Object m_DefaultValue
the default value.
-
m_DefaultValueDetermined
protected Boolean m_DefaultValueDetermined
whether a default value has been determined.
-
m_Support
protected PropertyChangeSupport m_Support
Handles property change notification.
-
m_ClassType
protected Class m_ClassType
The Class of objects being edited.
-
m_ObjectNames
protected List<String> m_ObjectNames
The model containing the list of names to select from.
-
m_EditorComponent
protected GenericObjectEditor.GOEPanel m_EditorComponent
The GUI component for editing values, created when needed.
-
m_Enabled
protected boolean m_Enabled
True if the GUI component is needed.
-
m_CustomPanel
protected JPanel m_CustomPanel
the custom panel provided by this editor.
-
m_CustomPanelChooseButton
protected BaseButton m_CustomPanelChooseButton
the button for choosing a different class in the custom panel.
-
m_CustomPanelFavoriteButton
protected BaseButton m_CustomPanelFavoriteButton
the button for showing the favorites menu in the custom panel.
-
m_ObjectPropertyPanel
protected PropertyPanel m_ObjectPropertyPanel
The property panel created for the objects.
-
m_canChangeClassInDialog
protected boolean m_canChangeClassInDialog
whether the class can be changed.
-
m_Filter
protected AbstractItemFilter m_Filter
the class filter in use.
-
m_MinimumChars
protected int m_MinimumChars
the minimum number of characters before triggering search events.
-
m_ProposedClasses
protected Class[] m_ProposedClasses
the proposed classes.
-
m_PostProcessObjectHandler
protected GenericObjectEditor.PostProcessObjectHandler m_PostProcessObjectHandler
for post-processing objects.
-
m_UserMode
protected UserMode m_UserMode
the user mode to use.
-
m_Undo
protected Undo m_Undo
the undo manager.
-
m_Result
protected int m_Result
whether the dialog was cancelled or ok'ed.
-
-
Constructor Detail
-
GenericObjectEditor
public GenericObjectEditor()
Default constructor.
-
GenericObjectEditor
public GenericObjectEditor(boolean canChangeClassInDialog)
Constructor that allows specifying whether it is possible to change the class within the editor dialog.- Parameters:
canChangeClassInDialog- whether the user can change the class
-
-
Method Detail
-
setCanChangeClassInDialog
public void setCanChangeClassInDialog(boolean value)
Sets whether the user can change the class in the dialog.- Parameters:
value- if true then the user can change the class
-
getCanChangeClassInDialog
public boolean getCanChangeClassInDialog()
Returns whether the user can change the class in the dialog.- Returns:
- true if the user can change the class
-
setReadOnly
public void setReadOnly(boolean value)
Sets whether the dialog is read-only.- Parameters:
value- if true then the dialog is read-only
-
isReadOnly
public boolean isReadOnly()
Returns whether the dialog is read-only.- Returns:
- true if the dialog is read-only
-
setFilter
public void setFilter(AbstractItemFilter value)
Sets the filter to use for filtering the display.- Parameters:
value- the filter, null if to disable filtering
-
getFilter
public AbstractItemFilter getFilter()
Returns the current filter.- Returns:
- the filter, null if none set
-
getClasses
protected List<String> getClasses()
Called when the class of object being edited changes.- Returns:
- the vector containing all the (sorted) classnames
-
updateObjectNames
protected void updateObjectNames()
Updates the list of selectable object names, adding any new names to the list.
-
setEnabled
public void setEnabled(boolean newVal)
Sets whether the editor is "enabled", meaning that the current values will be painted.- Parameters:
newVal- a value of type 'boolean'
-
setClassType
public void setClassType(Class type)
Sets the class of values that can be edited.- Parameters:
type- a value of type 'Class'
-
getClassType
public Class getClassType()
Returns the currently set class.- Returns:
- the current class
-
determineDefaultValue
protected Object determineDefaultValue()
Determines the default value.- Returns:
- the default value, null if none found or not possible to instantiate
-
checkClassType
protected boolean checkClassType(Object obj)
Checks and, if possible, sets the class type for the given object. If a class type is determined successfully,m_canChangeClassInDialogis enabled as well.
It is assumed that a missing class type is due to the fact that the GOE is called from another framework which doesn't know thatsetClassType(Class)needs to called in order to make it work properly.- Parameters:
obj- the object to (potentially) set the class type for
-
setDefaultValue
public void setDefaultValue()
Sets the current object to be the default, taken as the first item in the chooser.
-
setValue
public void setValue(Object o)
Sets the current Object. If the Object is in the Object chooser, this becomes the selected item (and added to the chooser if necessary).- Specified by:
setValuein interfacePropertyEditor- Parameters:
o- an object that must be a Object.
-
setObject
protected void setObject(Object obj)
Sets the current Object.- Parameters:
obj- a value of type 'Object'
-
getValue
public Object getValue()
Gets the current Object.- Specified by:
getValuein interfacePropertyEditor- Returns:
- the current Object
-
setUserMode
public void setUserMode(UserMode value)
Sets the user mode to use for displaying the properties.- Specified by:
setUserModein interfaceUserModeSupporter- Parameters:
value- the mode
-
getUserMode
public UserMode getUserMode()
Returns the user mode to use for displaying the properties.- Specified by:
getUserModein interfaceUserModeSupporter- Returns:
- the mode
-
getJavaInitializationString
public String getJavaInitializationString()
Supposedly returns an initialization string to create a Object 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 Object.- Specified by:
isPaintablein interfacePropertyEditor- Returns:
- always true
-
paintValue
public void paintValue(Graphics gfx, Rectangle box)
Paints a representation of the current Object.- 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:
- a value of type 'Component'
-
setMinimumChars
public void setMinimumChars(int value)
Sets the minimum number of characters that the user needs to enter before triggering a search event.- Parameters:
value- the minimum number of characters (>= 1)
-
getMinimumChars
public int getMinimumChars()
Returns the minimum number of characters that the user needs to enter before triggering a search event.- Returns:
- the minimum number of characters (>= 1)
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener l)
Adds a PropertyChangeListener who will be notified of value changes.- Specified by:
addPropertyChangeListenerin interfacePropertyEditor- Parameters:
l- a value of type 'PropertyChangeListener'
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Removes a PropertyChangeListener.- Specified by:
removePropertyChangeListenerin interfacePropertyEditor- Parameters:
l- a value of type 'PropertyChangeListener'
-
getCustomPanel
public JPanel getCustomPanel()
Gets the custom panel used for editing the object.- Specified by:
getCustomPanelin interfaceCustomPanelSupplier- Returns:
- the panel
-
createChooseClassButton
protected BaseButton createChooseClassButton()
Creates a button that when clicked will enable the user to change the class of the object being edited.- Returns:
- the choose button
-
createFavoriteButton
protected BaseButton createFavoriteButton()
Creates a button brings up the favorites popup menu.- Returns:
- the choose button
-
getChooseClassPopupMenu
public BasePopupMenu getChooseClassPopupMenu()
Returns a popup menu that allows the user to change the class of object.- Returns:
- a JPopupMenu that when shown will let the user choose the class
-
classSelected
protected void classSelected(String className)
Called when the user selects an class type to change to.- Parameters:
className- the name of the class that was selected
-
setProposedClasses
public void setProposedClasses(Object[] value)
Sets the proposed classes based on the provided objects. This call needs to happen before calling setValue(Object).- Parameters:
value- the proposed objects- See Also:
setProposedClasses(Class[])
-
setProposedClasses
public void setProposedClasses(Class[] value)
Sets the proposed classes. This call needs to happen before calling setValue(Object).- Parameters:
value- the proposed classes
-
getProposedClasses
public Class[] getProposedClasses()
Returns the proposed classes.- Returns:
- the proposed classes
-
firePropertyChange
public void firePropertyChange()
Fires a property change event.- See Also:
m_Support
-
setPostProcessObjectHandler
public void setPostProcessObjectHandler(GenericObjectEditor.PostProcessObjectHandler value)
Sets the handler for post-processing objects after they have been selected but before updating the UI.- Parameters:
value- the handler, null to remove
-
getPostProcessObjectHandler
public GenericObjectEditor.PostProcessObjectHandler getPostProcessObjectHandler()
Returns the handler for post-processing objects after they have been selected but before updating the UI.- Returns:
- the handler, null if none set
-
setUpdateSize
public void setUpdateSize(boolean value)
Sets whether to update the size.- Parameters:
value- true if to update
-
getUpdateSize
public boolean getUpdateSize()
Returns whether to update the size.- Returns:
- true if to update
-
setButtonsVisible
public void setButtonsVisible(boolean value)
Sets whether to display the buttons.- Parameters:
value- true if to display
-
getButtonsVisible
public boolean getButtonsVisible()
Returns whether the buttons are visible.- Returns:
- true if displayed
-
log
public void log(Level level, String msg)
For logging messages.- Parameters:
level- the logging levelmsg- the message
-
log
public void log(Level level, String msg, Throwable t)
For logging messages.- Parameters:
level- the logging levelmsg- the messaget- the optional exception (if one occurred), can be null
-
clearLogMessage
public void clearLogMessage()
Removes the message and hides the panel.
-
copyLogMessage
public void copyLogMessage()
Copies the message to the clipboard.
-
hasLogMessage
public boolean hasLogMessage()
Returns whether a message is currently being displayed.- Returns:
- true if message displayed
-
getLogMessage
public String getLogMessage()
Returns the current log message.- Returns:
- the log message, null if none displayed
-
setUndo
public void setUndo(Undo value)
Sets the undo manager to use, can be null if no undo-support wanted.- Specified by:
setUndoin interfaceUndoHandler- Parameters:
value- the undo manager to use
-
getUndo
public Undo getUndo()
Returns the current undo manager, can be null.- Specified by:
getUndoin interfaceUndoHandler- Returns:
- the undo manager, if any
-
isUndoSupported
public boolean isUndoSupported()
Returns whether an Undo manager is currently available.- Specified by:
isUndoSupportedin interfaceUndoHandler- Returns:
- true if an undo manager is set
-
getResult
public int getResult()
Returns whether the dialog got cancelled or approved.- Returns:
- the result
- See Also:
APPROVE_OPTION,CANCEL_OPTION
-
-