|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gishur.gui2.Painter
This class is the basic class for all painters. A Painter
is a small
piece of a DisplayObject
, such as a point, a line or other primitives.
The concept of painters makes it easier to write complicated DisplayObject
plus the bonus to have small reusable components. For instance once written a
painter that represents a point, it can be used to draw endpoints of line segments
or points of polygon, even it may be used to draw points of graphs.
A DisplayObject
that uses Painters
, will not need to know
the exact type of the painter it uses - for instance it's only interested to
display a point, no matter how the drawed point looks like. There are conventions
that must be met by a particular Painter
, but these are only a few - the
Painter
should make use of the paramters given by the DisplayObject
.
Painters
are strongly connected to Styles
. A
Style
is a factory for a special type of {link Painter Painters}. In
addition the Style
can store global informations for all
Painters
produced by this Style
. A Painter
can
gain access to its Style
using the style()
method.
In order to write own Styles
and Painters
, simply
create two classes based upon Style
/Painter
and overwrite the
abstract
methods. In the case of a Painter
these are
recalculate(...)
and draw(...)
.
recalculate(...)
is used to 'format' the Painter
.
This method should initialize the local variables using the given local
informations and the proprties. The draw(...)
should efficiently
draw this
Painter
. Make this methods fast! Avoid creation
of objects! A Painter
itself will be reused. The Style
caches unused
instances.
To use Painters
by a DisplayObject
, simply call the
createPainter(...)
method of its Style
, than reshape it using
its reshape(...)
method and add it to the DisplayObject
via
DrawObject.addPainter(gishur.gui2.Painter)
.
Every Painter
has got a name
and a subtype prefix string.
The name is used to identify the Painter
for activation and element
transformation. The subtype prefix is used by a PropertyStatusReader
for reading properties correctly.
Properties Summary | |||
Key | Value Type | Default value | Meaning |
visible | java.lang.Boolean | true |
The visibility of this Painter |
locateable | java.lang.Boolean | true |
Specifies, if this Painter
is locateable (by the mouse). Unvisible Painters
may still be locateable.
|
alignment | Alignment |
Alignment#LEFT_TOP_ALIGNMENT |
The alignment of this Painter .
(Read by the align -methods. |
Style
Field Summary | |
static byte |
LEVEL_0
Level attribute: Level 0 |
static byte |
LEVEL_1
Level attribute: Level 1 |
static byte |
LEVEL_2
Level attribute: Level 2 (default) |
static byte |
LEVEL_3
Level attribute: Level 3 |
static byte |
LEVEL_ALL
Level attribute: all levels |
static byte |
LEVEL_BITS_USED
The number of bits used by levels. |
static byte |
LEVEL_DEFAULT
Level attribute: default level ( == ) |
static byte |
LEVEL_FIRST
Level attribute: first level |
static byte |
LEVEL_LAST
Level attribute: last level |
static int |
LOCATEABLE
Painter is locateable. |
static int |
VISIBLE
Painter is visible. |
Constructor Summary | |
Painter()
|
Method Summary | |
protected void |
addBounds(int x,
int y)
Adds the given point to this Painters bounds. |
protected void |
addBounds(int x,
int y,
int width,
int height)
Adds the given rectangular area to this
Painters bounds. |
void |
alignTo(DrawObject source,
PropertyStatusReader prop,
Alignment default_align)
Aligns this Painter at the given DrawObject .
|
void |
alignTo(int x,
int y,
PropertyStatusReader prop,
Alignment default_align)
Aligns this Painter relatively to the given point.
|
java.awt.Point |
calculateDockingPoint(int x,
int y)
Calculates a docking point, that means a point on the outline of the Painter , that lies nearest to the given point.
|
boolean |
contains(int x,
int y)
Returns true , if the specified point hits the Painter .
|
protected abstract void |
draw(java.awt.Graphics g,
RenderContext context,
PropertyStatusReader prop,
byte level)
Draws the specified level of this Painter using the
given Graphics object and RenderContext for drawing,
and the given PropertyStatusReader for reading properties. |
protected java.awt.Point |
getAlignmentPoint(java.awt.Point p,
byte h_align,
byte v_align)
Returns an alignment point for the given alignment values. |
protected java.awt.Point |
getRelativeAlignmentPoint(java.awt.Point p,
byte h_align,
byte v_align)
Returns an alignment point for the given alignment values relatively to the upper left corner of this Painters bounding box.
|
int |
height()
Returns the height of this Painters bounds. |
boolean |
isOnLevel(byte level)
Returns true , if the Painter uses a level
of the given level mask. |
byte |
level()
Returns the level mask, this Painter uses. |
boolean |
locateable()
Returns true , if this Painter is
locateable via contains(int, int) , otherwise false . |
java.lang.String |
name()
Returns the name of the Painter . |
Shape |
outline()
Returns the stored outline shape. |
protected abstract void |
recalculate(RenderContext context,
PropertyStatusReader prop,
Parameters param)
Recalculates this Painter using the given RenderContext ,
PropertyStatusReader , local point information and other parameters. |
void |
reshape(RenderContext context,
Parameters param)
Calls the recalculate(gishur.gui2.RenderContext, gishur.gui2.PropertyStatusReader, gishur.core.Parameters) method. |
protected void |
setBounds(int x,
int y,
int width,
int height)
Sets the drawing bounds for this Painter . |
protected void |
setBounds(java.awt.Rectangle r)
Sets the drawing bounds for this Painter . |
protected void |
setLevel(byte level)
Sets the level mask, this Painter uses. |
void |
setLocation(int x,
int y)
Sets the location of this Painter . |
void |
setName(java.lang.String name)
Sets the name of the element. |
protected void |
setOutline(Shape outline)
Sets the outline shape. |
void |
setSubTypePrefix(java.lang.String prefix)
Sets the subtype prefix that this Painter should use for
reading properties. |
Style |
style()
Returns the connected Style of this Painter
(that is the Style that created this object via
its Style.createPainter(java.lang.String, java.lang.String, gishur.gui2.PropertyStatusReader) method). |
boolean |
visible()
Returns true , if this Painter is
visible, otherwise false . |
int |
width()
Returns the width of this Painters bounds. |
int |
x()
Returns the x-coordinate of the upper left corner of this
Painters bounds. |
int |
y()
Returns the y-coordinate of the upper left corner of this
Painters bounds. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int VISIBLE
Painter
is visible.public static final int LOCATEABLE
Painter
is locateable.public static final byte LEVEL_0
public static final byte LEVEL_1
public static final byte LEVEL_2
public static final byte LEVEL_3
public static final byte LEVEL_ALL
public static final byte LEVEL_DEFAULT
==LEVEL_2
)public static final byte LEVEL_FIRST
public static final byte LEVEL_LAST
public static final byte LEVEL_BITS_USED
Constructor Detail |
public Painter()
Method Detail |
public void setSubTypePrefix(java.lang.String prefix)
Painter
should use for
reading properties.prefix
- the new subtype prefix for reading properties
(must not be null
)public void setName(java.lang.String name)
name
- the name of the element (must not be null
)public java.lang.String name()
Painter
.Painter
.protected abstract void recalculate(RenderContext context, PropertyStatusReader prop, Parameters param)
this
Painter
using the given RenderContext
,
PropertyStatusReader
, local point information and other parameters.context
- the RenderContext
to useprop
- the PropertyStatusReader
to use for reading propertiesparam
- a Parameters
-object for location and other parameters parsed
by the DisplayObject
, that uses this
Painter
.protected abstract void draw(java.awt.Graphics g, RenderContext context, PropertyStatusReader prop, byte level)
this
Painter
using the
given Graphics
object and RenderContext
for drawing,
and the given PropertyStatusReader
for reading properties.g
- the Graphics
to draw oncontext
- the RenderContext
to useprop
- the PropertyStatusReader
to use for reading propertieslevel
- the level to drawpublic final void reshape(RenderContext context, Parameters param)
recalculate(gishur.gui2.RenderContext, gishur.gui2.PropertyStatusReader, gishur.core.Parameters)
method. This method looks for the visible and
locateable properties itself.protected final void setBounds(int x, int y, int width, int height)
this
Painter
.x,y
- upper left corner of the drawing boundswidth,height
- width and height of the drawing boundsprotected final void setBounds(java.awt.Rectangle r)
this
Painter
.r
- the bounds rectangleprotected final void addBounds(int x, int y, int width, int height)
this
Painters
bounds.x,y
- upper left corner of the areawidth,height
- width and height of the areaprotected final void addBounds(int x, int y)
this
Painters
bounds.x,y
- the pointprotected java.awt.Point getRelativeAlignmentPoint(java.awt.Point p, byte h_align, byte v_align)
this
Painters
bounding box.
The default implementation calls
Alignment.getReferencePoint}-method. Overwrite this method to select other
reference points.p
- a Point
object where to store the calculated point or
null
.h_align
- an alignment value
(-128==Alignment.LEFT
≤0==Alignment.CENTER
≤127==Alignment.RIGHT
)
for the horizontal alignmentv_align
- an alignment value
(-128==Alignment.TOP
≤0==Alignment.CENTER
≤127==Alignment.BOTTOM
)
for the vertical alignmentprotected final java.awt.Point getAlignmentPoint(java.awt.Point p, byte h_align, byte v_align)
getRelativeAlignmentPoint(java.awt.Point, byte, byte)
.p
- a Point
object where to store the calculated point or
null
.h_align
- an alignment value
(-128==Alignment.LEFT
≤0==Alignment.CENTER
≤127==Alignment.RIGHT
)
for the horizontal alignmentv_align
- an alignment value
(-128==Alignment.TOP
≤0==Alignment.CENTER
≤127==Alignment.BOTTOM
)
for the vertical alignmentpublic void setLocation(int x, int y)
this
Painter
. This method translates
the bounding box and the outline of this
Painter
.x,y
- new positionpublic final void alignTo(DrawObject source, PropertyStatusReader prop, Alignment default_align)
this
Painter
at the given DrawObject
.
The method reads the alignment-property via the given PropertyStatusReader
.source
- the DrawObject
to use to alignmentprop
- PropertyStatusReader
for reading propertiesdefault_align
- the default Alignment
public final void alignTo(int x, int y, PropertyStatusReader prop, Alignment default_align)
this
Painter
relatively to the given point.
The method reads the alignment-property via the given PropertyStatusReader
.x,y
- the position to align relatively toprop
- PropertyStatusReader
for reading propertiesdefault_align
- the default Alignment
public final boolean visible()
true
, if this
Painter
is
visible, otherwise false
.true
, if visiblepublic final boolean locateable()
true
, if this
Painter
is
locateable via contains(int, int)
, otherwise false
.true
, if locateablepublic final Shape outline()
protected final void setOutline(Shape outline)
contains(int, int)
in order to decide, if
a given point (usually the mouse position) hits this
Painter
or not.outline
- the outline shapepublic java.awt.Point calculateDockingPoint(int x, int y)
Painter
, that lies nearest to the given point.
The default implementation returns the center point of the outline
shape. This is not a real docking-point! Overwrite this method in
order to return correct docking points.x,y
- point, where to come from for docking (outside the
Painter
).public final byte level()
this
Painter
uses.this
Painter
uses.protected final void setLevel(byte level)
this
Painter
uses.level
- the new level mask of this
Painter
.public final boolean isOnLevel(byte level)
true
, if the Painter
uses a level
of the given level mask.level
- the level mask to testtrue
, if a levelof the level mask is usedpublic final int x()
this
Painters
bounds.public final int y()
this
Painters
bounds.public final int width()
this
Painters
bounds.public final int height()
this
Painters
bounds.public boolean contains(int x, int y)
true
, if the specified point hits the Painter
.
This method should return false
, if the painter is not
locateable (see locateable()
).
This method returns true
, if the point lies inside the specified
painter bounds (see setBounds(int, int, int, int)
) and if it lies in the outline shape
(see setOutline(gishur.gui2.Shape)
) (If no outline shape is defined, true
will be returned, if it lies in the bounds).true
, if the specified point hits the Painter
.public final Style style()
Style
of this
Painter
(that is the Style
that created this
object via
its Style.createPainter(java.lang.String, java.lang.String, gishur.gui2.PropertyStatusReader)
method).Style
of this
Painter
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |