|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.values.ValuesEditorAdapter
com.ccg.values.ValuesEditorBean
public class ValuesEditorBean
A 'generic' ValuesEditor implementation for
bean style object.
The ValuesEditorBean provides a full working implementation of a
ValuesEditor for ANY bean style. Currently, it
provides editable fields for the following pairs of methods:
The following TYPES are supported:
You can control the appearance and behavior through a optional resource file (this is yet to be defined).
The following example defines a simple email bean (having name and email address properties), it also includes a main() method (and one supporting class) such that when you compile and run it, you will end up with a full graphical editor allowing you to add, delete, and modify a collection of objects stored on disk:
import com.ccg.values.*;
public class Email {
//----------------------------------------------------------------
// Construct a ValuesConfigBean with a default constructor so we can
// make use of ValuesConfigModel.
//----------------------------------------------------------------
public static class ValuesConfigEmail extends ValuesConfigBean {
public ValuesConfigEmail() { super(Email.class); }
}
public static void main(String[] args) {
// Create model for bean we want to edit
ValuesConfigModel vcm = new ValuesConfigModel();
vcm.setValuesConfigClass(ValuesConfigEmail.class);
// Construct a full editor (user will
// be able to add, delete, and change
// a collection of Email entries)
ValuesConfigEditor vce = new ValuesConfigEditor();
vce.setModel(vcm);
vce.setEditor(new ValuesEditorBean(Email.class));
vce.setButtons(ValuesConfigEditor.ALL_BUTTONS);
vce.showDialog("Email List",true);
System.exit(0);
}
public Email() { _Name=_Email="unknown"; }
public String getName() { return _Name; }
public void setName(String name) { if (name != null) _Name = name; }
public String getEmail() { return _Email; }
public void setEmail(String email) { if (email != null) _Email = email; }
public String toString() { return _Name+" <"+_Email+'>'; }
private String _Name;
private String _Email;
}
It actually took less code to create a full GUI than the email
example shown in the ValuesConfigBean class. When you
compile and run the above, you should see a GUI editor similar to
whats shown below:
This class provides a static main(java.lang.String[]) method which allows
one to look at the editor created for any particular bean. It only
shows the panel used to edit the contents of the bean for testing
purposes (it doesn't providea a ValuesConfig
implementation, and as such, you won't be to load/save/modify
persistent instances of your bean class). However, this means you
can try it out to see the default editor you would see for any bean
style class. Try the following, and you should see an editor for
many of the fields in a JButton object:
[pkb@salsa swing]$ java com.ccg.values.ValuesEditorBean javax.swing.JButton [pkb@salsa swing]$
ValuesConfigBean| Field Summary | |
|---|---|
(package private) Class |
_Class
|
(package private) JComponent |
_Component
|
(package private) JComponent[] |
_Fields
|
(package private) Method[] |
_GetMethods
|
(package private) Method[] |
_SetMethods
|
| Fields inherited from interface com.ccg.values.ValuesHolder |
|---|
HAS_FROM, HAS_TO, HAS_TO_FROM |
| Constructor Summary | |
|---|---|
ValuesEditorBean(Class c)
Default constructor for the ValuesEditorBean class. |
|
| Method Summary | |
|---|---|
Object |
createObjectInstance()
Creates a new instance of a object (with default values set) which the editor is designed to work with. |
void |
fromObject(Object o)
Transfer values from a object into this "value holder". |
JComponent |
getComponent()
Get the Swing component which the user sees. |
Class |
getObjectClass()
Get the Class which the "values holder" is
designed to work with. |
void |
init(Lookup props)
Set the properties to be used when constructing the visual component. |
static void |
main(String[] args)
Main entry point into the applications. |
void |
toObject(Object o)
Transfer values from this "value holder" into a object. |
String |
toString()
Get a simple string representation of the object. |
void |
validate()
Verify that all of the user input fields are valid. |
| Methods inherited from class com.ccg.values.ValuesEditorAdapter |
|---|
addChangeListener, checkArgument, fireChangeEvent, getCapabilities, getProxyChangeListener, getProxyDocumentListener, getProxyInputMethodListener, getProxyItemListener, getProxyListDataListener, getProxyTableModelListener, removeChangeListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
Class _Class
JComponent _Component
Method[] _SetMethods
Method[] _GetMethods
JComponent[] _Fields
| Constructor Detail |
|---|
public ValuesEditorBean(Class c)
ValuesEditorBean class.
c - Class which the editor should be used on - must not be null,
and must have a public default constructor.| Method Detail |
|---|
public static void main(String[] args)
This method was stubbed in by default. You will want to either delete it entirely, or modify it to do something more useful.
args - Array of command line arguments.public String toString()
toString in class Objectpublic Class getObjectClass()
Class which the "values holder" is
designed to work with.
This method returns the Class which the "values
holder" is designed to work with. All objects which are passed to
the toObject or fromObject
methods MUST be instances of this class.
public void toObject(Object o)
throws IllegalStateException,
IllegalArgumentException,
UnsupportedOperationException,
NullPointerException
This method transfers all of the values held into the object passed. It transfers ALL values if successful. It transfers ZERO values if a exception is thrown.
NullPointerException - If you pass null.
IllegalArgumentException - If the object passed is not the proper type.
IllegalStateException - If the "values holder" isn't in the proper state to do the
transfer.
UnsupportedOperationException - If the "value holder" doesn't implement the setting of values
in the associated objects.fromObject(java.lang.Object)
public void fromObject(Object o)
throws IllegalStateException,
IllegalArgumentException,
UnsupportedOperationException,
NullPointerException
This method transfers all of the values of interest from the object passed into this "value holder". It transfers ALL values if successful. It transfers ZERO values if a exception is thrown.
NullPointerException - If you pass null.
IllegalArgumentException - If the object passed is not the proper type.
IllegalStateException - If the object isn't in the proper state to do the
transfer into this "values holder".
UnsupportedOperationException - If the "value holder" doesn't implement the getting of values
from associated objects.toObject(java.lang.Object)
public void validate()
throws IllegalStateException
After allowing the user to modify the fields, it is often
desirable to "validate" what the user has entered. This method
checks the data entered by the user. If any of the user
information looks bad, it throws an IllegalStateException.
IllegalStateException - If any of the user input fields have invalid values contained
which the user needs to fix prior to a commit.ValuesHolder.toObject(java.lang.Object)
public JComponent getComponent()
throws IllegalStateException
All classes which implement this interface need to be able to create a GUI editor.
The first invocation triggers the "creation" of the component.
Multiple invocations will return a reference to the same component as returned by the first invocation.
IllegalStateException - If the object was not properly initialized.public Object createObjectInstance()
This is method should ALWAYS be implemented when possible and
is a requirement for the ValuesEditor
implementation to be used in "factories".
createObjectInstance in interface ValuesEditorcreateObjectInstance in class ValuesEditorAdapterfromObject or toObject implementation. Never returns null.public void init(Lookup props)
Implementations may optionally implement this method (it doesn't need to do anything). It allows one to pass a set of properties which the implementation may optionally use when constructing its visual component.
The properties recognized (if any) are implementation dependent. Typically these properties include custom labels, tooltips, format rules, etc.
If this method is invoked (it is not required), it must
be invoked prior to the invocation of the getComponent method (otherwise it would be too
late now wouldn't it).
init in interface ValuesEditorinit in class ValuesEditorAdapterprops - Set of properties (implementation dependent) to initialize
object with (must not be null).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||