|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gishur.x2.core.XObject
A generic planar object. A concrete planar object should represent some sort of a planar primitive like point, line, polygon.
An XObject instance would occupy only two bytes for storing an object state.
Every bit of the state variable represents one state; three bits are reserved
for the internal states STATE_MUTABLE
, STATE_DIRTY
and
STATE_LOCKED
, the other 5 bits are free for specific states of the
subclasses. One can check states through checkState(short)
and set and clear
non-internal states using setState(short)
and clearState(short)
.
Planar object could treated as constant or modifyable. Per default planar
objects are constant, represented by not setting the STATE_MUTABLE
state. To ensure, that this semantic of (im)mutability is valid, every subclass
should call modify()
before changing its geometric data. If planar
objects are mutable, the dirty state is set when modify()
is called.
If a planar object is locked through lock()
, it prevents other threads
modifying its geometric data (through modify()
) until unlock()
removes that lock. All this state changes should be called recursiv for all
contained XObjects (e.g. for all points of a polygon). This is assured by the
methods lock()
, unlock()
, clearDirty()
, makeMutable()
and makeImmutable()
through getXObjectMembers()
.
All planar objects should implement transform
enabling affine transformations. XObject provides some shortcut methods like
scale(gishur.x2.core.XPoint, double, double)
, rotate(gishur.x2.core.XPoint, double)
and translate
for special affine transformations
Field Summary | |
static short |
RESERVED_STATE_MAX_MASK
State mask constant used for internal states. |
static short |
STATE_DIRTY
Dirty State. |
static short |
STATE_LOCKED
Locked State. |
static short |
STATE_MUTABLE
Mutable State. |
Constructor Summary | |
XObject()
|
Method Summary | |
boolean |
checkState(short state)
Checks if the given state is set. |
boolean |
checkStateCleared(short state)
Checks if the given state is cleared; that means every bit of the given state is cleared. |
void |
clearDirty()
Clears the dirty state. |
protected void |
clearState(short state)
Clears a given state. |
java.lang.Object |
clone()
Creates a new object of the same class as this object. |
XObject |
copy()
This method creates a clone of this object instance like clone with a little difference: if this is immutable, the clone won't be
till the first modification. |
boolean |
dirty()
Checks, if this XObject is dirty. |
XObject |
getMutable()
This method returns either this XObject or a temporary mutable
clone of this XObject, depending on its mutability.
|
java.lang.Object |
getOldXObject()
Returns corresponding old gishur.x-object. |
protected abstract XObject[] |
getXObjectMembers()
This method should return all XObject members that contain geometric information. |
XObject |
inverseTransform(double m00,
double m01,
double m02,
double m10,
double m11,
double m12)
Inverse transforms this XObject by the given affine
transformation matrix. |
void |
lock()
Sets the write-lock on this XObject. |
boolean |
locked()
Returns true, if the XObject is locked. |
protected void |
makeImmutable()
Makes this object immutable. |
protected void |
makeMutable()
Makes this object mutable. |
protected void |
modify()
This method should only be called from this XObject, if
its instance variables should be modified. |
boolean |
mutable()
Checks, if this XObject is mutable. |
void |
restoreMutability()
Restores the mutability information to the information of the original of this clone. |
XObject |
rotate(XPoint center,
double angle)
Rotates this XObject around the rotation center
center by angle . |
XObject |
scale(XPoint center,
double xscale,
double yscale)
Scales this XObject with xscale and
yscale scale factors and with center point
center . |
protected void |
setState(short state)
Sets a given state. |
protected short |
state()
Returns the complete state of this XObject. |
protected short |
state(short state)
Returns the state for the given state constant. |
java.lang.String |
toString_complete()
Returns a more detailed string representation of the object than toString() . |
java.lang.String |
toString_state()
Returns a String representation of the internal XObject state. |
java.lang.String |
toString()
Returns a string representation of the object. |
XObject |
transform(AffineTransformation t)
Transforms this XObject by the given affine
transformation matrix. |
abstract XObject |
transform(double m00,
double m01,
double m02,
double m10,
double m11,
double m12)
Transforms this XObject by the given affine
transformation matrix. |
XObject |
translate(double dx,
double dy)
Translates this XObject by the given Vector
(dx,dy) . |
XObject |
translate(XPoint v)
Translates this XObject by the given Vector
v . |
void |
unlock()
Removes the write-lock on this XObject. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final short STATE_MUTABLE
public static final short STATE_DIRTY
clearDirty()
.public static final short STATE_LOCKED
public static final short RESERVED_STATE_MAX_MASK
Constructor Detail |
public XObject()
Method Detail |
public final boolean checkState(short state)
state
- state to verifypublic final boolean checkStateCleared(short state)
state
- state to verifyprotected final short state()
this
XObject.protected final short state(short state)
protected final void setState(short state)
state
must use other bits than
RESERVED_STATE_MAX_MASK
, otherwise these bits will be
ignored.state
- state to setprotected final void clearState(short state)
state
must use other bits than
RESERVED_STATE_MAX_MASK
, otherwise these bits will be
ignored.state
- state to clearpublic boolean mutable()
STATE_MUTABLE
is set)protected void makeMutable()
this
Object
can modify its coordinates (and some other geometric
information). This must be assured by every subclass of XObject
itself. makeMutable()
will not be called
for XObject members.
makeMutable()
may be overriden with public modifier to
make it accessible for all classes, but should finally call this
method implementation.protected void makeImmutable()
this
Object
cannot modify its coordinates (and some other geometric
information). This must be assured by every subclass of XObject
itself. makeImmutable()
will not be called
for XObject members.
makeImmutable()
may be overriden with public modifier to
make it accessible for all classes, but should finally call this
method implementation.public final boolean dirty()
STATE_DIRTY
is set)public final void clearDirty()
getXObjectMembers()
.public final boolean locked()
STATE_LOCKED
is set)public final void lock()
this
XObject. That means any modifying
method should block until the write lock is removed.
Propagation to all contained XObjects is assured through getXObjectMembers()
.unlock()
public final void unlock()
this
XObject. That means all
waiting modifying methods wakeup.
Propagation to all contained XObjects is assured through getXObjectMembers()
.unlock()
protected final void modify()
this
XObject, if
its instance variables should be modified. If it is immutable, then
an GeomException
will be thrown, otherwise it waits, till
there is no lock set and set the dirty state.
There must be exactly one call of modify before a modification!GeomException
- if XObject is immutableprotected abstract XObject[] getXObjectMembers()
makeMutable()
, makeImmutable()
,
clearDirty()
, lock()
and unlock()
. To make this
work there must not occur circular dependencies.null
if none).public abstract XObject transform(double m00, double m01, double m02, double m10, double m11, double m12)
this
XObject by the given affine
transformation matrix.m00,m01,m02
- first row of the transformation matrixm10,m11,m12
- second row of the transformation matrixthis
, only if it is
mutable, otherwise a new XObject represeting the transformed object).public XObject inverseTransform(double m00, double m01, double m02, double m10, double m11, double m12)
this
XObject by the given affine
transformation matrix.m00,m01,m02
- first row of the transformation matrixm10,m11,m12
- second row of the transformation matrixthis
, only if it is
mutable, otherwise a new XObject represeting the transformed object).public XObject transform(AffineTransformation t)
this
XObject by the given affine
transformation matrix.t
- the transformation matrixthis
, only if it is
mutable)public XObject scale(XPoint center, double xscale, double yscale)
this
XObject with xscale
and
yscale
scale factors and with center point
center
.center
- immutable scaling center pointxscale
- scale factor for x-axisyscale
- scale factor for y-axisthis
, only if it is
mutable)public XObject rotate(XPoint center, double angle)
this
XObject around the rotation center
center
by angle
.center
- rotation centerangle
- rotation anglethis
, only if it is
mutable)public XObject translate(double dx, double dy)
this
XObject by the given Vector
(dx,dy)
.(dx,dy)
- translation vectorthis
, only if it is
mutable)public XObject translate(XPoint v)
this
XObject by the given Vector
v
.(dx,dy)
- translation vectorthis
, only if it is
mutable)public java.lang.Object clone()
clone
in interface Cloneable
clone
in class java.lang.Object
OutOfMemoryError
- if there is not enough memory.Cloneable
public XObject copy()
this
is immutable, the clone won't be
till the first modification. This is usefull if you like to create a modified
version of an object instance and you don't know, if this object is mutable.
With copy
you can assure, there will be created a new instance;
you can write code as this:
XObject a=...; XObject b=a.copy().translate(x,y);If
a
is mutable, copy
assures that a new instance
is created and translate(double, double)
works on that copy. If a
is
immutable, copy
creates a new instance of a
and
lets modify translate(double, double)
this instance exactly one time.this
object, that is modifyable at least one
time (depending on the immutable-flag of this
).public XObject getMutable()
this
XObject or a temporary mutable
clone of this
XObject, depending on its mutability.
If this
XObject is immutable, a clone will be created and returned
that is mutable until a call to restoreMutability()
. This gives
one the possibility to write code like this without knowing something
about the mutability of the used XObject:
XObject a=...; a=getMutable(); // get a mutable version of a a.transform(...); // change a ... (can be more transformations) a.restoreMutability(); // restore the old mutability information of the original
this
or a mutable clone.copy()
,
#restorMutability
public void restoreMutability()
this
is a normal mutable
(or immutable) XObject, nothing happens.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString_complete()
toString()
.public java.lang.String toString_state()
public java.lang.Object getOldXObject()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |