|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.values.ValuesConfigEditor
public class ValuesConfigEditor
Complete configuration/value editor for a ValuesEditor and
ValuesConfig implementation.
This class builds a working "configuration editor" for use with a
ValuesConfig and its corresponding ValuesEditor
implemenation. It provides an alternative to the ValuesFactoryTree.
It allows the user to do the following:
As the applications developer, you make use of this class in the following manner:
ValuesConfigModel which is to be associated with the
editor (this is used to allow the user to select between available
configuartions, create new configurations, etc).ValuesEditor which the user will interact with to view
and modify settings for individual configurations.Object which information is
loaded from and/or transferred to.getComponent yourself when
creating custom Swing components, or use the simple showDialog method to let the user interact.The following shows how simple this can be:
import com.ccg.values.*;
class Example {
public static void foo(ValuesConfig vc, ValuesEditor ve) {
ValuesConfigModel vcm = new ValuesConfigModel();
vcm.setValuesConfigClass(vc.getClass());
ValuesConfigEditor vce = new ValuesConfigEditor();
vce.setModel(vcm);
vce.setEditor(ve);
vce.setButtons(ValuesConfigEditor.ALL_BUTTONS);
vce.showDialog("Edit Config", true);
}
}
In addition, you can use this class as a test bed for any ValuesConfig/ValuesEditor implementation. For example,
lets assume that you created a com.glatmos.ld.QueryDA class and then
created a associated com.glatmos.ld.swing.QueryDAConfig (ValuesConfig
implementation) and com.glatmos.ld.swing.QueryDAEditor (ValuesEditor
implementation). You could use the following command line to verify that your
config/editor implementations behaved properly:
java com.ccg.values.ValuesConfigEditor \
com.glatmos.ld.swing.QueryDAConfig \
com.glatmos.ld.swing.QueryDAEditor
ValuesFactoryTree| Nested Class Summary | |
|---|---|
(package private) class |
ValuesConfigEditor.Listener
|
| Field Summary | |
|---|---|
static int |
ALL_BUTTONS
Bit flag indicating that ALL buttons should be made available. |
static int |
APPLY_BUTTON
Bit flag indicating that a "Apply" button should be made available. |
static String |
APPLY_NAME
The constant name associated with the Apply button. |
static int |
CANCEL_BUTTON
Bit flag indicating that a "Cancel" button should be made available. |
static String |
CANCEL_NAME
The constant name associated with the Cancel button. |
static int |
DELETE_BUTTON
Bit flag indicating that a "Delete" button should be made available. |
static String |
DELETE_NAME
The constant name associated with the Delete button. |
static int |
NEW_BUTTON
Bit flag indicating that a "New" button should be made available. |
static String |
NEW_NAME
The constant name associated with the New button. |
static int |
OK_BUTTON
Bit flag indicating that a "OK" button should be made available. |
static String |
OK_NAME
The constant name associated with the Ok button. |
static int |
REVERT_BUTTON
Bit flag indicating that a "Revert" button should be made available. |
static String |
REVERT_NAME
The constant name associated with the Revert button. |
| Constructor Summary | |
|---|---|
ValuesConfigEditor()
|
|
| Method Summary | |
|---|---|
void |
addActionListener(ActionListener al)
Allows one to monitor when buttons are pressed. |
int |
getButtons()
Get the buttons (if any) that will be/have been created for the component. |
JComponent |
getComponent()
Get the Swing component which the user interacts with to edit or view the configuration. |
ValuesEditor |
getEditor()
Get the ValuesEditor which the user uses to adjust
the values for a particular configuration. |
ValuesConfigModel |
getModel()
Get the ValuesConfigModel used to select config
choices from. |
Object |
getObject()
Get the object which the config and edit implementations work with. |
static void |
main(String[] args)
Main entry point into the application. |
void |
removeActionListener(ActionListener al)
|
void |
selectAndLoad(Object cfgname)
Specify the configuration you want loaded, selected and ready to edit. |
void |
setButtons(int val)
Set the buttons (if any) to be created for the component. |
void |
setEditor(ValuesEditor val)
Set the ValuesEditor which the user uses to adjust
the values for a particular configuration. |
void |
setModel(ValuesConfigModel val)
Set the ValuesConfigModel used to select config
choices from. |
void |
setObject(Object val)
Set the object which the config and edit implementations work with. |
int |
showDialog(String title,
boolean modal)
Show a dialog box which allows the user to interract. |
(package private) void |
updateButtons()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ALL_BUTTONS
This constant can be used when specifying what buttons you would like
created on the bottom of the component. If used, you will get ALL of the
available buttons (and their associated behaviors) added. This constant
is the bitwise OR of: OK_BUTTON,
CANCEL_BUTTON, APPLY_BUTTON,
REVERT_BUTTON,
DELETE_BUTTON, and NEW_BUTTON.
setButtons(int),
Constant Field Valuespublic static final int OK_BUTTON
This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Ok" button on the panel - the actual label may be different, but the component name will ALWAYS be "ok" (incase you trap the action handler).
setButtons(int),
Constant Field Valuespublic static final String OK_NAME
If you indicated that you wanted the Ok button available in your
component (had the OK_BUTTON bit flag set in a call to
#setButtons setButtons). You can use this constant name in your
registered {@link ActionListener ActionListener} to tell when the user
presses the Ok button. Here is a code fragment of how you might use this
in your action listener:
public void actionPerformed(ActionEvent ae) {
Component c = (Component) ae.getSource();
if (c.getName().equals(ValuesConfigEditor.OK_NAME)) {
System.err.println("You pressed Ok");
} else if (...
setButtons(int),
Constant Field Valuespublic static final int CANCEL_BUTTON
This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Cancel" button on the panel - the actual label may be different, but the component name will ALWAYS be "cancel" (incase you trap the action handler).
setButtons(int),
Constant Field Valuespublic static final String CANCEL_NAME
If you indicated that you wanted the Cancel button available in your
component (had the CANCEL_BUTTON bit flag set in a
call to #setButtons setButtons). You can use this constant name in
your registered {@link ActionListener ActionListener} to tell when the
user presses the Cancel button. Here is a code fragment of how you might
use this in your action listener:
public void actionPerformed(ActionEvent ae) {
Component c = (Component) ae.getSource();
if (c.getName().equals(ValuesConfigEditor.CANCEL_NAME)) {
System.err.println("You pressed Cancel");
} else if (...
setButtons(int),
Constant Field Valuespublic static final int APPLY_BUTTON
This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Apply" button on the panel - the actual label may be different, but the component name will ALWAYS be "apply" (incase you trap the action handler).
setButtons(int),
Constant Field Valuespublic static final String APPLY_NAME
If you indicated that you wanted the Apply button available in your
component (had the APPLY_BUTTON bit flag set in a
call to #setButtons setButtons). You can use this constant name in
your registered {@link ActionListener ActionListener} to tell when the
user presses the Apply button. Here is a code fragment of how you might
use this in your action listener:
public void actionPerformed(ActionEvent ae) {
Component c = (Component) ae.getSource();
if (c.getName().equals(ValuesConfigEditor.APPLY_NAME)) {
System.err.println("You pressed Apply");
} else if (...
setButtons(int),
Constant Field Valuespublic static final int REVERT_BUTTON
This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Revert" button on the panel - the actual label may be different, but the component name will ALWAYS be "revert" (incase you trap the action handler).
setButtons(int),
Constant Field Valuespublic static final String REVERT_NAME
If you indicated that you wanted the Revert button available in your
component (had the REVERT_BUTTON bit flag set in a
call to #setButtons setButtons). You can use this constant name in
your registered {@link ActionListener ActionListener} to tell when the
user presses the Revert button. Here is a code fragment of how you might
use this in your action listener:
public void actionPerformed(ActionEvent ae) {
Component c = (Component) ae.getSource();
if (c.getName().equals(ValuesConfigEditor.REVERT_NAME)) {
System.err.println("You pressed Revert");
} else if (...
setButtons(int),
Constant Field Valuespublic static final int NEW_BUTTON
This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "New" button on the panel - the actual label may be different, but the component name will ALWAYS be "new" (incase you trap the action handler).
setButtons(int),
Constant Field Valuespublic static final String NEW_NAME
If you indicated that you wanted the New button available in your
component (had the NEW_BUTTON bit flag set in a call
to #setButtons setButtons). You can use this constant name in your
registered {@link ActionListener ActionListener} to tell when the user
presses the New button. Here is a code fragment of how you might use this
in your action listener:
public void actionPerformed(ActionEvent ae) {
Component c = (Component) ae.getSource();
if (c.getName().equals(ValuesConfigEditor.NEW_NAME)) {
System.err.println("You pressed New");
} else if (...
setButtons(int),
Constant Field Valuespublic static final int DELETE_BUTTON
This bit flag can be used when specifying what buttons you would like created on the bottom of the component. If used, you will get a "Delete" button on the panel - the actual label may be different, but the component name will ALWAYS be "delete" (incase you trap the action handler).
setButtons(int),
Constant Field Valuespublic static final String DELETE_NAME
If you indicated that you wanted the Delete button available in your
component (had the DELETE_BUTTON bit flag set in a
call to #setButtons setButtons). You can use this constant name in
your registered {@link ActionListener ActionListener} to tell when the
user presses the Delete button. Here is a code fragment of how you might
use this in your action listener:
public void actionPerformed(ActionEvent ae) {
Component c = (Component) ae.getSource();
if (c.getName().equals(ValuesConfigEditor.DELETE_NAME)) {
System.err.println("You pressed Delete");
} else if (...
setButtons(int),
Constant Field Values| Constructor Detail |
|---|
public ValuesConfigEditor()
| Method Detail |
|---|
public void setEditor(ValuesEditor val)
ValuesEditor which the user uses to adjust
the values for a particular configuration.
val - New ValuesEditor value to assign - must not be null and can only be set
one time.getEditor()public ValuesEditor getEditor()
ValuesEditor which the user uses to adjust
the values for a particular configuration.
setEditor(com.ccg.values.ValuesEditor)public void setModel(ValuesConfigModel val)
ValuesConfigModel used to select config
choices from.
NOTE: You can only set this once - you'll trigger a IllegalStateException if you try to set this twice.
val - ValuesConfigModel to associate with editor (must not be null).getModel()public ValuesConfigModel getModel()
ValuesConfigModel used to select config
choices from.
setModel(com.ccg.values.ValuesConfigModel)public void setObject(Object val)
val - New Object value to assign - you can pass null to force the next
invocation of getObject to try and load a fresh copy.getObject()
public void selectAndLoad(Object cfgname)
throws ConfigException,
IOException
This method can be used once the model AND editor have been set (the component need not be realized yet - though it doesn't hurt if it is). When you invoke this method, the following occurs:
object.
cfgname - Name of configuration to load.
ConfigException - If there was a problem with the configuration.
IOException - If there was an underlying I/O problem trying to load the configuration.public Object getObject()
IllegalStateException - If we needed to construct a new instance and the associated
ValuesEditor was not yet set or not acceptable.setObject(java.lang.Object)public JComponent getComponent()
This method retrieves the Swing component the user interacts with to
edit/view the configuration(s). Before invoking this method, one should
set the properties for the editor (or be faced with a
IllegalStateException). At a minimum, you MUST set the
config model and the editor. Most
likely, you will also want to set what buttons should
be included (as none are include by default).
This method returns the same value on subsequent calls.
This method is typically only used if you need to build up a custom
component. Most developers will find that using the showDialog method is a simpler mechanism and will meet most needs.
IllegalStateException - If the object hasn't been properly initialized.showDialog(java.lang.String, boolean)public void setButtons(int val)
Note: it is illegal to attempt to change this if the component has
already been realized via getComponent or the
installation of action listeneners.
val - New int value to assign (set of bit flag constants).getButtons(),
ALL_BUTTONSpublic int getButtons()
setButtons(int)public void addActionListener(ActionListener al)
You can install any action listener here for the purpose of detecting when the user presses one of the standard buttons.
al - ActionListener to be installed - must not be null.public void removeActionListener(ActionListener al)
public int showDialog(String title,
boolean modal)
This method retrieves the GUI component and places
it into a dialog box and then shows the dialog box to the user (allowing
the user to edit the values contained).
This is probably the simplest means to make use of this class as it only
involves initializing the object and then invoking this method. Refer to
the getComponent documentation for what values MUST
be set prior to using this method.
title - Title for dialog box - must not be null.modal - true if you want a modal dialog, false if non-blocking (affects value of
return code).
CANCEL_BUTTON if user closed
dialog without "ok" or "apply", OK_BUTTON if user
closed dialog with "ok" button, APPLY_BUTTON if
user applied changes and then closed window with "cancel" method.public static void main(String[] args)
args - Array of command line arguments.void updateButtons()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||