public interface EntryHandler
ConfigRegistry.EntryType.CUSTOM
.
When the GUI encounters an entry of type ConfigRegistry.EntryType.CUSTOM
(or a ConfigRegistry.EntryType.LIST
whose entry type is EntryType#CUSTOM
)
it should check the ConfigConstants.HANDLER
property to see
if there is a custom handler present. If so it is recommended for the
GUI to use this handler, since otherwise it will not be able to
properly handle the value(s) in this entry!
Usage of the EntryHandler
should be done as follows:
When the user attempts to modify a value, the setValue(Object)
method should be called with the current value as its argument.
isValueEditable()
determines if the value is allowed to be
modified by the user. A return value of false
indicates that the GUI should
take no further actions and simply ignore the user modification attempts. After that
invoking getComponent()
will return the Component
used by the EntryHandler
to lay out its own user interface. This
Component
would normally be wrapped into a Dialog
(either by using
Dialog
or JDialog
directly or by relying on one of the many
helper methods in JOptionPane
) and presented to the user. However if
the returned Component
is a JFileChooser
or JColorChooser
it should be directly displayed using its own showDialog()
method.
Another option is to place the returned Component
next to the components
used by the GUI to display the entry itself.
No matter which way of displaying was used, once the user has modified the value
the EntryHandler
's isValueValid()
method should
be called to check if the user input is valid and the modifications can be committed.
When the value is declared valid invoking getValue()
will commit
the modifications to the value object stored in the handler and the modified object
will then be returned. In most cases just invoking this method is enough, since
the handler itself holds the entrie's value and directly operates on it.
In addition to simply modify existing entries this interface presents a way
to create new objects usable as values for the type this EntryHandler
is
used for. By calling newEntry()
a blank new entry is created.
This comes in hand when the handler is used in the context of a EntryType#LIST
entry and the user wants to add a new object to the list. Instead of using
the currently selected value in the list (which may be null
) the GUI should
call EntryHandler#newEntry()
and pass the result to the EntryHandler#setValue(Object)
method and continue the way described above.
Modifier and Type | Method and Description |
---|---|
java.awt.Component |
getComponent() |
java.lang.Object |
getValue() |
boolean |
isValueEditable() |
boolean |
isValueValid() |
java.lang.Object |
newEntry() |
void |
setValue(java.lang.Object value) |