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 class
GenericObjectEditor.GOEPanel
Handles the GUI side of editing values.static interface
GenericObjectEditor.PostProcessObjectHandler
Interface for post-processing the object after selecting it, but before setting it.
-
Field Summary
Fields Modifier and Type Field Description static String
ACTION_CMD_CANCEL
the action command for Cancel.static String
ACTION_CMD_OK
the action command for OK.static String
ACTION_CMD_OPEN
the action command for Open.static String
ACTION_CMD_REDO
the action command for Redo.static String
ACTION_CMD_SAVE
the action command for Save.static String
ACTION_CMD_UNDO
the action command for Undo.static int
APPROVE_OPTION
constant for dialog approval.static int
CANCEL_OPTION
constant for dialog cancellation.protected static Logger
LOGGER
for logging.protected boolean
m_canChangeClassInDialog
whether the class can be changed.protected Class
m_ClassType
The Class of objects being edited.protected JPanel
m_CustomPanel
the custom panel provided by this editor.protected BaseButton
m_CustomPanelChooseButton
the button for choosing a different class in the custom panel.protected BaseButton
m_CustomPanelFavoriteButton
the button for showing the favorites menu in the custom panel.protected Object
m_DefaultValue
the default value.protected Boolean
m_DefaultValueDetermined
whether a default value has been determined.protected GenericObjectEditor.GOEPanel
m_EditorComponent
The GUI component for editing values, created when needed.protected boolean
m_Enabled
True if the GUI component is needed.protected AbstractItemFilter
m_Filter
the class filter in use.protected int
m_MinimumChars
the minimum number of characters before triggering search events.protected Object
m_Object
The object being configured.protected List<String>
m_ObjectNames
The model containing the list of names to select from.protected PropertyPanel
m_ObjectPropertyPanel
The property panel created for the objects.protected GenericObjectEditor.PostProcessObjectHandler
m_PostProcessObjectHandler
for post-processing objects.protected Class[]
m_ProposedClasses
the proposed classes.protected int
m_Result
whether the dialog was cancelled or ok'ed.protected PropertyChangeSupport
m_Support
Handles property change notification.protected Undo
m_Undo
the undo manager.protected UserMode
m_UserMode
the user mode to use.static boolean
SHOW_CHOOSE_CLASS_BUTTON
whether 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 void
addPropertyChangeListener(PropertyChangeListener l)
Adds a PropertyChangeListener who will be notified of value changes.protected boolean
checkClassType(Object obj)
Checks and, if possible, sets the class type for the given object.protected void
classSelected(String className)
Called when the user selects an class type to change to.void
clearLogMessage()
Removes the message and hides the panel.void
copyLogMessage()
Copies the message to the clipboard.protected BaseButton
createChooseClassButton()
Creates a button that when clicked will enable the user to change the class of the object being edited.protected BaseButton
createFavoriteButton()
Creates a button brings up the favorites popup menu.protected Object
determineDefaultValue()
Determines the default value.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 buttons are visible.boolean
getCanChangeClassInDialog()
Returns whether the user can change the class in the dialog.BasePopupMenu
getChooseClassPopupMenu()
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.Class
getClassType()
Returns the currently set class.Component
getCustomEditor()
Returns the array editing component.JPanel
getCustomPanel()
Gets the custom panel used for editing the object.AbstractItemFilter
getFilter()
Returns the current filter.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.String
getLogMessage()
Returns the current log message.int
getMinimumChars()
Returns the minimum number of characters that the user needs to enter before triggering a search event.GenericObjectEditor.PostProcessObjectHandler
getPostProcessObjectHandler()
Returns the handler for post-processing objects after they have been selected but before updating the UI.Class[]
getProposedClasses()
Returns the proposed classes.int
getResult()
Returns whether the dialog got cancelled or approved.String[]
getTags()
Returns null as we don't support getting values as tags.Undo
getUndo()
Returns the current undo manager, can be null.boolean
getUpdateSize()
Returns whether to update the size.UserMode
getUserMode()
Returns the user mode to use for displaying the properties.Object
getValue()
Gets the current Object.boolean
hasLogMessage()
Returns whether a message is currently being displayed.boolean
isPaintable()
Returns true to indicate that we can paint a representation of the Object.boolean
isReadOnly()
Returns whether the dialog is read-only.boolean
isUndoSupported()
Returns whether an Undo manager is currently available.void
log(Level level, String msg)
For logging messages.void
log(Level level, String msg, Throwable t)
For logging messages.void
paintValue(Graphics gfx, Rectangle box)
Paints a representation of the current Object.void
removePropertyChangeListener(PropertyChangeListener l)
Removes a PropertyChangeListener.void
setAsText(String text)
Returns null as we don't support getting/setting values as text.void
setButtonsVisible(boolean value)
Sets whether to display the buttons.void
setCanChangeClassInDialog(boolean value)
Sets whether the user can change the class in the dialog.void
setClassType(Class type)
Sets the class of values that can be edited.void
setDefaultValue()
Sets the current object to be the default, taken as the first item in the chooser.void
setEnabled(boolean newVal)
Sets whether the editor is "enabled", meaning that the current values will be painted.void
setFilter(AbstractItemFilter value)
Sets the filter to use for filtering the display.void
setMinimumChars(int value)
Sets the minimum number of characters that the user needs to enter before triggering a search event.protected void
setObject(Object obj)
Sets the current Object.void
setPostProcessObjectHandler(GenericObjectEditor.PostProcessObjectHandler value)
Sets the handler for post-processing objects after they have been selected but before updating the UI.void
setProposedClasses(Class[] value)
Sets the proposed classes.void
setProposedClasses(Object[] value)
Sets the proposed classes based on the provided objects.void
setReadOnly(boolean value)
Sets whether the dialog is read-only.void
setUndo(Undo value)
Sets the undo manager to use, can be null if no undo-support wanted.void
setUpdateSize(boolean value)
Sets whether to update the size.void
setUserMode(UserMode value)
Sets the user mode to use for displaying the properties.void
setValue(Object o)
Sets the current Object.boolean
supportsCustomEditor()
Returns true because we do support a custom editor.protected void
updateObjectNames()
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_canChangeClassInDialog
is 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:
setValue
in 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:
getValue
in interfacePropertyEditor
- Returns:
- the current Object
-
setUserMode
public void setUserMode(UserMode value)
Sets the user mode to use for displaying the properties.- Specified by:
setUserMode
in interfaceUserModeSupporter
- Parameters:
value
- the mode
-
getUserMode
public UserMode getUserMode()
Returns the user mode to use for displaying the properties.- Specified by:
getUserMode
in 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:
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 Object.- Specified by:
isPaintable
in interfacePropertyEditor
- Returns:
- always true
-
paintValue
public void paintValue(Graphics gfx, Rectangle box)
Paints a representation of the current Object.- 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:
- 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:
addPropertyChangeListener
in interfacePropertyEditor
- Parameters:
l
- a value of type 'PropertyChangeListener'
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Removes a PropertyChangeListener.- Specified by:
removePropertyChangeListener
in interfacePropertyEditor
- Parameters:
l
- a value of type 'PropertyChangeListener'
-
getCustomPanel
public JPanel getCustomPanel()
Gets the custom panel used for editing the object.- Specified by:
getCustomPanel
in 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:
setUndo
in interfaceUndoHandler
- Parameters:
value
- the undo manager to use
-
getUndo
public Undo getUndo()
Returns the current undo manager, can be null.- Specified by:
getUndo
in interfaceUndoHandler
- Returns:
- the undo manager, if any
-
isUndoSupported
public boolean isUndoSupported()
Returns whether an Undo manager is currently available.- Specified by:
isUndoSupported
in 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
-
-