public class PsObject extends java.lang.Object implements PsUpdateIf, java.lang.Cloneable, java.io.Serializable
PsUpdateIf
may have PsObject as super class unless it is a panel, dialog etc. which are derived
from PsPanel
and PsDialog
.
Subclasses must call the init()
method in each constructor, and each init()
method must call super.init()
at first. The following layout may be used:
public class myClass extends mySuperClass public myClass() { ... // create all instance variables if (getClass() == myClass.class) init(); } public void init() { super.init(); ... // initialization of instance variables, allows to use init() as reset() }This ensures that the init() method of superclasses is called. Otherwise even the init() methods of the superclasses will not be called. The init() method should be written such that it can be used to reset the current instance. Therefore, all creation of instance variables should be placed in the constructor, as far as possible.
Each instance of PsObject may have an associated info panel as interactive inspector.
Most information in the panel is interactively modifiable. The class name of an
info panel may follow a special naming convention: "name of main class"+"_IP". This convention
allows the method getInfoPanel()
of PsObject to find this class
automatically if it is in the same java package as the main class. For example,
jv.geom.PgPointSet.java and jv.geom.PgPointSet_IP.java are a pair of base class and info
panel.
If a class does not have an own inspector class then the inspector of its superclass is used. Each object may have several other inspectors with different filename extensions which are accessible via the menu of the control window.
Each instance of PsObject has a unique default name of the form 'object_NUMBER' where
NUMBER is a unique integer number counting the number of created instances.
The name should be changed using method setName(String)
since it
is used e.g. as header of the inspector panel, and in debug output as a unique reference
to the object.
The tag variable may be used locally in methods or projects. They have no global influence, and a user cannot rely on the value once a method is left.
Since JavaView 1.74, we get the Class object that describes any Java type using the new class literal syntax. A class literal is simply the name of a type (a class name or a primitive type name) followed by a period and the class keyword. For example:
Class o = PsObject.class; Class i = int.class; Class v = java.util.Vector.class;Prior to JavaView 1.74 we used the Java 1.0 style, where we got the Class object from the name of a data type using the forName() class method of Class.
Modifier and Type | Field and Description |
---|---|
static int |
HAS_BOUNDARY_PANEL
Tag object as having a texture panel.
|
static int |
HAS_CONFIG_PANEL
Tag object as having a control panel.
|
static int |
HAS_INFO_PANEL
Tag object as having an inspector panel.
|
static int |
HAS_LABEL_PANEL
Tag object as having a font panel.
|
static int |
HAS_MATERIAL_PANEL
Tag object as having a material panel.
|
static int |
HAS_TEXTURE_PANEL
Tag object as having a texture panel.
|
static int |
HAS_VECTOR_PANEL
Tag object as having a vector field panel.
|
static java.lang.String |
INSPECTOR_INFO
Deprecated.
use PsPanel.INFO instead
|
static java.lang.String |
INSPECTOR_INFO_EXT
Deprecated.
use PsPanel.INFO_EXT instead
|
static int |
IS_DELETED
Tag object as been deleted, applications should not continue to access its data.
|
static int |
IS_FIXED
Tag object as been fixed, applications should not modify its data.
|
static int |
IS_FOCUSSED
Tag object as being within the focus of a device, and further
action might pick or select this object.
|
static int |
IS_PICKED
Tag object as being temporarily picked in a device and interactively
modified.
|
static int |
IS_SELECTED
Tag object as been selected, applications may use this tag.
|
static int |
IS_USED
Tag object as been used, applications may use this tag.
|
static int |
NUM_TAGS
Number of available tags to describe state of object.
|
Constructor and Description |
---|
PsObject()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addInspector(java.lang.String name,
PsPanel panel)
Register a new inspector, and set current object as parent of panel.
|
boolean |
addUpdateListener(PsUpdateIf listener)
Register a new update listener.
|
PsPanel |
assureInspector(java.lang.String name,
java.lang.String ext)
Get a certain panel - if it does not exist then try to allocate it.
|
void |
clearTag(int aBit)
Unset tag of object.
|
java.lang.Object |
clone()
Duplicate geometry by recursively cloning all instance variables
except inspector panels and lists of registered listeners.
|
static PsObject[] |
clone(PsObject[] src)
Duplicate array and all entries by recursively cloning all instance variables
except inspector panels and lists of registered listeners.
|
static PsObject[][] |
clone(PsObject[][] src)
Duplicate array and all entries by recursively cloning all instance variables
except inspector panels and lists of registered listeners.
|
void |
copy(PsObject object)
Copy the content of data instance variables from argument object to
this object.
|
PsUpdateIf |
getFather()
Get unique parent of an object.
|
PsPanel |
getInfoPanel()
Get info panel, or if panel does not exist then try to allocate it.
|
PsPanel |
getInspector(java.lang.String name)
Get a registered inspector panel.
|
java.lang.String |
getName()
Get name identifying the object.
|
static int |
getNumObjects()
Get number of allocated instances of PsObject and its subclasses.
|
java.lang.String |
getSymbol()
Get symbol, i.e. shortcut name, which identifies this object in equations.
|
boolean |
hasInspector(java.lang.String name)
Check for a registered inspector panel by name.
|
boolean |
hasTag(int aBit)
Check whether tag of object is set.
|
boolean |
hasUpdateListener(PsUpdateIf listener)
Check whether an instance is a registered listener.
|
void |
init()
If instance has missing name then assign default name 'Object_NUMBER' where
number is the total number of already created instances.
|
static boolean |
instanceOf(java.lang.Object obj,
java.lang.Class cl)
Method checks if an object extends a given class or one of its superclasses.
|
boolean |
instanceOf(java.lang.String className)
Deprecated.
use "if (getClass() == PsObject.class)" instead
|
PsPanel |
newInspector(java.lang.String ext)
Create and register a new inspector panel of this class,
and set current object as parent of inspector panel.
|
PsPanel |
newInspector(java.lang.String name,
java.lang.String ext)
Create and register a new inspector panel of this class,
and set current object as parent of inspector panel.
|
boolean |
removeInspector(PsPanel panel)
Remove a registered inspector panel from list of registered inspectors.
|
boolean |
removeInspector(java.lang.String name)
Remove a registered inspector panel from list of registered inspectors.
|
boolean |
removeUpdateListener(PsUpdateIf listener)
Remove a registered listener from list of registered listeners.
|
void |
setName(java.lang.String name)
Set name identifying the object.
|
void |
setParent(PsUpdateIf aParent)
Set parent to receive update methods.
|
void |
setSymbol(java.lang.String symbol)
Set symbol, i.e. shortcut name, which identifies this object in equations.
|
void |
setTag(int aBit)
Set tag of object.
|
java.lang.String |
toString()
Create a multi-line string representation
with detailed information about all instance variables.
|
boolean |
update(java.lang.Object event)
Update all inspector panels, send update to all registered update listeners
and finally update parent.
|
boolean |
updatePanels(java.lang.Object event)
Partial update method to synchronize all registered inspector panels.
|
public static final int NUM_TAGS
setTag(int)
,
Constant Field Valuespublic static final int IS_USED
setTag(int)
,
Constant Field Valuespublic static final int IS_SELECTED
setTag(int)
,
Constant Field Valuespublic static final int IS_DELETED
setTag(int)
,
Constant Field Valuespublic static final int IS_FIXED
setTag(int)
,
Constant Field Valuespublic static final int IS_PICKED
setTag(int)
,
Constant Field Valuespublic static final int IS_FOCUSSED
setTag(int)
,
Constant Field Valuespublic static final int HAS_INFO_PANEL
setTag(int)
,
Constant Field Valuespublic static final int HAS_MATERIAL_PANEL
setTag(int)
,
Constant Field Valuespublic static final int HAS_BOUNDARY_PANEL
setTag(int)
,
Constant Field Valuespublic static final int HAS_TEXTURE_PANEL
setTag(int)
,
Constant Field Valuespublic static final int HAS_VECTOR_PANEL
setTag(int)
,
Constant Field Valuespublic static final int HAS_LABEL_PANEL
setTag(int)
,
Constant Field Valuespublic static final int HAS_CONFIG_PANEL
setTag(int)
,
Constant Field Valuespublic static final java.lang.String INSPECTOR_INFO_EXT
public static final java.lang.String INSPECTOR_INFO
public PsObject()
public void init()
public java.lang.String toString()
PsDebug.message(object.toString())
to print information
to console. This method is usually extended by subclasses with further information.toString
in class java.lang.Object
public static PsObject[][] clone(PsObject[][] src)
null
.copy(PsObject)
public static PsObject[] clone(PsObject[] src)
null
.copy(PsObject)
public java.lang.Object clone()
null
.clone
in class java.lang.Object
copy(PsObject)
public static int getNumObjects()
public void copy(PsObject object)
Instance variables like parent and listeners are not copied.
clone()
public boolean update(java.lang.Object event)
Central update method of this object. Must be overwritten if this class receives unknown events, say, from new children. Any subclass must class invoke super.update(event) on all events it does handle itself.
update
in interface PsUpdateIf
event
- carries a lot of informationsetParent(PsUpdateIf)
,
getFather()
,
addUpdateListener(PsUpdateIf)
public boolean updatePanels(java.lang.Object event)
PuDouble
which automatically and instantaneously
synchronize their panels whenever, say, their value has changed.
This is in contrast to heavier classes b which only synchronize their panels
on a call b.update(panel of b) or b.update(b).
Method does nothing if list of panels does not exist. Method issues a warning if event is a panel but the panel is not registered as inspector.
Usually, application classes do not call this method but use
update(Object)
.
event
- Either this object or a registered panel.update(Object)
,
addInspector(String, PsPanel)
public boolean addUpdateListener(PsUpdateIf listener)
listener
- Listener to registerfalse
if listener already registered.hasUpdateListener(PsUpdateIf)
,
removeUpdateListener(PsUpdateIf)
public boolean hasUpdateListener(PsUpdateIf listener)
listener
- Listener to be checkedtrue
if registered listener found.addUpdateListener(PsUpdateIf)
,
removeUpdateListener(PsUpdateIf)
public boolean removeUpdateListener(PsUpdateIf listener)
listener
- Registered listenerfalse
if listener is not registered.addUpdateListener(PsUpdateIf)
,
hasUpdateListener(PsUpdateIf)
public PsUpdateIf getFather()
getParent()
to its classes.getFather
in interface PsUpdateIf
PsUpdateIf
,
update(Object)
,
setParent(PsUpdateIf)
public void setParent(PsUpdateIf aParent)
setParent
in interface PsUpdateIf
aParent
- will receive events which this
does not handlePsUpdateIf
,
update(Object)
,
getFather()
public java.lang.String getName()
getName
in interface PsUpdateIf
public void setName(java.lang.String name)
public java.lang.String getSymbol()
public void setSymbol(java.lang.String symbol)
public void clearTag(int aBit)
PsObject
.public boolean hasTag(int aBit)
PsObject
.public void setTag(int aBit)
PsObject
.public final boolean instanceOf(java.lang.String className)
false
.
This method is different from Java operator instanceof
which
is true even if current instance is subclass of class 'className'.className
- name of class without package identifiersinstanceOf(Object, Class)
public static boolean instanceOf(java.lang.Object obj, java.lang.Class cl)
obj
- object to testcl
- class or interfaceinstanceOf(String)
public boolean addInspector(java.lang.String name, PsPanel panel)
This method invokes the two methods PsPanel.setParent(PsUpdateIf)
and PsPanel.update(Object)
to register this class as
parent of the panel:
setParent(this) update(this)
name
- any name except one of the reserved inspector namespanel
- panel to be registeredfalse
if same name already exists.getInspector(String)
,
hasInspector(String)
,
newInspector(String)
,
removeInspector(PsPanel)
,
removeInspector(String)
public PsPanel newInspector(java.lang.String name, java.lang.String ext)
The parameter name
specifies the string under
which the inspector is registered in the list of inspectors
of this class.
Any name of an inspector panels is possible except the string PsPanel.INFO,
PsPanel.MATERIAL which are reserved for JavaView internal panels.
The extension string allows this method to reconstruct the file name of the inspector panel from the name of this class. For example, if the name of this class is 'jvx.geom.Torus' then the name of the inspector panel must be 'jvx.geom.Torus_myExt' if the parameter extension is 'myExt'.
This method calls addInspector(String, PsPanel)
.
name
- any name except one of the reserved inspector namesext
- suffix to name of base classaddInspector(String, PsPanel)
,
getInspector(String)
,
hasInspector(String)
,
newInspector(String)
,
removeInspector(PsPanel)
,
removeInspector(String)
public PsPanel newInspector(java.lang.String ext)
The extension string allows this method to reconstruct the file name of the inspector panel from the name of this class. For example, if the name of this class is 'jvx.geom.Torus' then the name of the inspector panel must be 'jvx.geom.Torus_myExt' if the parameter extension is 'myExt'.
The name, under which this panel is registered as inspector of
this object, is unique and automatically chosen. Currently,
this name is unavailable to the outside. Use
newInspector(String, String)
if the name is important.
This method calls newInspector(String, String)
.
ext
- suffix to name of base classaddInspector(String, PsPanel)
,
getInspector(String)
,
hasInspector(String)
,
newInspector(String, String)
,
removeInspector(PsPanel)
,
removeInspector(String)
public PsPanel getInspector(java.lang.String name)
name
- Name of inspector to be receivednull
if not found.addInspector(String, PsPanel)
,
hasInspector(String)
,
newInspector(String)
,
newInspector(String, String)
,
removeInspector(String)
public boolean hasInspector(java.lang.String name)
name
- Name of inspector to be checkedtrue
if registered inspector found.addInspector(String, PsPanel)
,
getInspector(String)
,
newInspector(String)
,
newInspector(String, String)
,
removeInspector(String)
,
removeInspector(PsPanel)
public boolean removeInspector(java.lang.String name)
name
- Name of inspector to be removedfalse
if inspector does not exists.addInspector(String, PsPanel)
,
getInspector(String)
,
hasInspector(String)
,
newInspector(String)
,
newInspector(String, String)
,
removeInspector(PsPanel)
public boolean removeInspector(PsPanel panel)
panel
- Panel to be removedfalse
if inspector does not exists.addInspector(String, PsPanel)
,
getInspector(String)
,
hasInspector(String)
,
newInspector(String)
,
newInspector(String, String)
,
removeInspector(String)
public PsPanel assureInspector(java.lang.String name, java.lang.String ext)
Class name of info panel must consist of the name of the class to be inspected and '_IP' as suffix. In this case the panel is automatically found.
Method is a shortcut to avoid checking, creating, and adding the panel to the inspector list.
name
- name of panelext
- suffix to name of base classaddInspector(String, PsPanel)
,
getInspector(String)
,
hasInspector(String)
,
newInspector(String)
,
newInspector(String, String)
,
removeInspector(PsPanel)
,
removeInspector(String)
public PsPanel getInfoPanel()
Class name of info panel must consist of the name of the class to be inspected and '_IP' as suffix. In this case the panel is automatically found.
Method is a shortcut to avoid checking, creating, and adding the panel
to the inspector list. But note, obtaining an inspector with this
method provides always the same panel instance, that is, this panel
should only be used within a single other container, for example.
If more panels are needed the create panels with different names
using assureInspector(String, String)
.
addInspector(String, PsPanel)
,
getInspector(String)
,
hasInspector(String)
,
newInspector(String)
,
newInspector(String, String)
,
removeInspector(String)
"