|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectjApp.Changeable
jApp.Variable
public class Variable
This class provides a way to create named variables that are persitently
stored into a Document.
Variables are run-time objects that as such are not persitent. Instead they are explicitly created and named at run-time. The name is used in storing/retrieving the values of the variables from the Document file and the run-time object is used to refer to the value. This makes it possible to add named variables to documents in a non-fragile way, as new variables can be easily introduced as the application develops. When a Document is loaded from a file, the names are used to find the correct run-time variable into which the value is loaded. For variables that do not exist in a Document file, the variable retains the default value passed to its constructor. Note that Document does not remove variable values during save/load even if they values have not been associated with variable, which makes the system also downwards compatible.
Variables are usually created either in Document or ModalDialog
initializers/constructors and associated with a document by calling
Document.addVariable(String,Variable).
The objects that are used as Variable values need to implement
Serializable interface.
If variable values are changed while a Modal dialog is visible on the screen, the old values for the variables are saved for restoring, in case the user 'Cancel's the dialog. This happens automatically. Note that this value store/restore is done directly on variable values, so if the object that is the variable value is changed then there is no way the system can no about this and thus cannot save/restore the value. So this mechanism works best for conceptually immutable objects like String's and base type wrappers, like Integer's.
Variables maintain a list of ChangeListener objects that are notified
whenever the value of the object changes. This makes it very easy and bug
free to associate widgets with variables. For example if a check box is
created and associated with a varible by calling one of the
createCheckBox methods of PartFactory, then whenever
the value of that variable changes the check box will correctly reflect the
state of the variable and the value of that variable can be changed by
clicking that checkbox.
public class ExampleDialog extends ModalDialog
{
private ExampleDocument document;
....
private DoubleVariable exampleVariable;
....
public ExampleDialog(ExampleDocument doc) {
super(null, "Dialog Title");
document = doc;
<b>document.addVariable("EXAMPLE_VARIABLE",exampleVariable = new Variable(defaultValue));</b>
....
Typically the dialog object is created in an initialzer of the document member that is used to refer to the dialog:
public class ExampleDocumentsh
extends Document {
public ExampleDialog exampleDialog = new ExampleDialog(this);
Document| Field Summary | |
|---|---|
protected java.lang.Object |
m_Value
|
| Fields inherited from interface jApp.ValueInterface |
|---|
VALUE_VALID |
| Constructor Summary | |
|---|---|
Variable()
Constructs a variable with the initial (default) value of null |
|
Variable(java.lang.Object value)
Constructs a variable with the given default value. |
|
| Method Summary | |
|---|---|
boolean |
booleanValue()
Casts the value of the variable to boolean and returns the
boolean value. |
double |
doubleValue()
Casts the value of the variable to Number and returns the
long value. |
java.lang.Object |
getValue()
|
int |
intValue()
Casts the value of the variable to Number and returns the
int value. |
boolean |
isEnabled()
|
long |
longValue()
Casts the value of the variable to Number and returns the
long value. |
int |
numberOfValues()
|
static void |
readVariables(java.io.ObjectInputStream stream,
java.util.Hashtable variables)
Reads in variable values from a stream. |
void |
setEnabled(boolean e)
|
void |
setValue(java.lang.Object value)
|
void |
showAlertDialog(int cause,
Unit unit)
Provided so that derived classes can provide their own specic alert dialogs in case an attempt is made to set the variable to an unacceptable value. |
java.lang.String |
stringValue()
Converts the value of the variable to String by calling the
Object.toString() method. |
int |
validate(java.lang.Object value)
Validates the value and returns a constant describing the result |
boolean |
valueEquals(java.lang.Object value)
Compares the equality of the variables value. |
static void |
writeVariables(java.io.ObjectOutputStream stream,
java.util.Hashtable variables)
Writes variable values to a stream. |
| Methods inherited from class jApp.Changeable |
|---|
addChangeListener, fireChangeEvent, removeChangeListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface jApp.ValueInterface |
|---|
addChangeListener, removeChangeListener |
| Field Detail |
|---|
protected java.lang.Object m_Value
| Constructor Detail |
|---|
public Variable()
null
public Variable(java.lang.Object value)
value - the devault value.| Method Detail |
|---|
public static void writeVariables(java.io.ObjectOutputStream stream,
java.util.Hashtable variables)
throws java.lang.Exception
Document class objects to store variable values, but has been
made public because it is conceivable that it has other uses. This method
presumes that the keys of the hashtable are the names of the variables
String and the values are the variables.
stream - the stream to store the values to.variables - a hashtable containing name/variable pairs.
java.lang.Exception
public static void readVariables(java.io.ObjectInputStream stream,
java.util.Hashtable variables)
throws java.lang.Exception
Document class objects to store variable values, but has been
made public because it is conceivable that it has other uses. This method
presumes that the keys of the hashtable are the names of the variables
String and the values are the variables.
stream - the stream to read the values from.variables - a hashtable of name/variable pairs.
java.lang.Exceptionpublic boolean valueEquals(java.lang.Object value)
value - the value to compare to the varible value.
equalpublic boolean booleanValue()
boolean and returns the
boolean value.
boolean value of the variable.public int intValue()
Number and returns the
int value.
int value of the variable.public long longValue()
Number and returns the
long value.
long value of the variable.public java.lang.String stringValue()
String by calling the
Object.toString() method.
String value of the variable.public double doubleValue()
Number and returns the
long value.
double value of the variable.
public void showAlertDialog(int cause,
Unit unit)
showAlertDialog in interface ValueInterfaceunit - the unit in which to express the variable value or the value
range.public int validate(java.lang.Object value)
validate in interface ValueInterfacevalue - the value to validate
ValueInterface.VALUE_VALIDpublic void setValue(java.lang.Object value)
setValue in interface ValueInterfacepublic java.lang.Object getValue()
getValue in interface ValueInterfacepublic void setEnabled(boolean e)
public boolean isEnabled()
isEnabled in interface ValueInterfacepublic int numberOfValues()
numberOfValues in interface ValueInterface
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||