gishur.gui2
Class DrawObject

java.lang.Object
  |
  +--gishur.gui2.DrawAtom
        |
        +--gishur.gui2.DrawObject
Direct Known Subclasses:
DisplayGroup, DisplayObject, InputHandler

public abstract class DrawObject
extends DrawAtom

Extends the DrawAtom by screen positions.

Version:
2.0
Author:
Thomas Wolf

Fields inherited from class gishur.gui2.DrawAtom
BLOCK_REPAINT, MARK_RECALC, MARK_REPAINT, MARK_SIZE, REPAINT, UNBLOCK_REPAINT, USER_STATES_FIRST, USER_STATES_MASK
 
Constructor Summary
protected DrawObject(java.lang.String property_prefix)
          Constructs a new DisplayObject which uses the given prefix for all properties.
 
Method Summary
protected  void addDrawDependency(DrawObject drw)
          Deprecated.  
protected  void addPainter(Painter p)
          Adds the given Painter at the end of the current painter list.
protected  void blockRepaint()
          Blocks all repaint() calls at this drawing hierachy.
 boolean checkState(int state)
          Checks if the given state is set.
 boolean checkStateCleared(int state)
          Checks if the given state is cleared; that means every bit of the given state is cleared.
protected  DrawObject child()
          Returns the first group element of the group.
protected  void clear()
          Removes all member DrawObjects from this DrawAtom.
 void clearCache()
          Clears the property-cache at this DrawObject and at all members.
 void clearState(int state)
          Clears a given state.
protected  DrawDependency dependency()
          Returns the DrawDependency of this DrawObject.
 boolean dirty()
          Returns true, if the object is currently marked as dirty.
protected  void disableEvents(int events_to_disable)
          Disables the events defined by the specified event mask parameter from being delivered to this DrawObject.
protected  void draw(java.awt.Graphics g, RenderContext context)
          Draws this DrawAtom to the given Graphics g.
protected  void draw(java.awt.Graphics g, RenderContext context, PropertyStatusReader properties)
          Draws this DrawAtom to the given Graphics.
protected  void enableEvents(int events_to_enable)
          Enables the events defined by the specified event mask parameter to be delivered to this DrawObject.
protected  void ensureRecalculate(RenderContext context)
          This method could be used, to ensure recalculation of the DrawObject.
protected  Painter findPainter(java.lang.String name)
          Returns the first stored Painter with the given name.
protected  Painter firstPainter()
          Returns the first Painter in the painter list.
protected  boolean fullscreen()
          Returns true, if this DrawObject needs the full screen as bounds.
 void hide()
          Hides the DrawAtom (visible()()==false).
 void hide(boolean update)
          Hides the DrawAtom (visible()()==false).
protected  void insert(DrawObject p, DrawObject drw)
          Inserts the DrawObject drw in the group before p.
 byte levelMask()
          Returns the level mask (a combination of levels, that are displayed by this DrawObject).
 byte levelUsed()
          Returns a level mask of levels, that are used by this DrawObject).
 java.lang.String locate(int x, int y)
          Locates the point (x,y).
 void makeDirty()
          Marks this DrawAtom for repainting (and recalculating) and starts the recalculation/repainting system immediately.
 void makeDirty(boolean update)
          Marks this DrawAtom for repainting (and recalculating).
protected  DrawObject next()
          Returns the next DrawObject in the group or null if it is the last group element.
protected  DrawObject next(DrawObject drw)
          Returns the next DrawObject of the given DrawObject, if this is direct parent of the given DrawObject or null if it is the last group element.
protected  Painter nextPainter(Painter p)
          Returns the next Painter of the given Painter p in the painter list.
protected  DrawObject parent()
          Returns the parent group of this DrawObject.
protected  void prepeareRenderContext(RenderContext context)
          Prepeares the RenderContext before recalulation or drawing via a call to recalculate(gishur.gui2.RenderContext, gishur.gui2.PropertyStatusReader)/draw(Graphics,RenderContext).
protected  DrawObject prev()
          Returns the previous DrawObject in the group or null if it is the first group element.
protected  DrawObject prev(DrawObject drw)
          Returns the previous DrawObject of the given DrawObject, if this is direct parent of the given DrawObject or null if it is the first group element.
protected  void processDrawEvent(DrawEvent e)
          Processes DrawEvents occuring on this DrawObject.
protected  void processEvent(java.awt.AWTEvent e)
          Processes events delivered to this DrawObject.
 PropertyStatusReader propertyReader()
          The PropertyStatusReader that should be used for reading properties.
protected  void recalculate(RenderContext context)
          Forces the DrawAtom to recalculate its representation.
protected abstract  void recalculate(RenderContext context, PropertyStatusReader properties)
          Forces the DrawObject to recalculate its representation.
protected  void remove(DrawObject drw)
          Removes the given DrawObject from this group.
protected  void removeDrawDependency(DrawObject drw)
          Deprecated.  
 void repaint()
          Starts the recalculation/repainting system immediately.
 ScreenTransformation screenTransformation()
          Returns the valid ScreenTransformation for this DrawObject.
protected  boolean setFullscreen(boolean fullscreen)
          Marks or clears this DrawObject as a fullscreen DrawObject.
protected  boolean setPaintBeforeMembers(boolean paintbefore)
          Defines the paint order of this DrawObject and its members.
protected  void setScreenTransformation(ScreenTransformation transform)
          Sets the screen transformation for this DrawObject.
 void setState(int state)
          Sets a given state.
 void show()
          Shows the DrawAtom (visible()()==true).
 void show(boolean update)
          Shows the DrawAtom (visible()()==true).
 int state()
          Returns the complete state of this object.
 int state(int state)
          Returns the state for the given state constant.
protected  void unblockRepaint()
          Unblocks repaint() calls and repaints all dirty objects.
protected  void unblockRepaint(boolean recalc_all)
          Unblocks repaint() calls and repaints all (dirty) objects.
 boolean visible()
          Returns true, if the DrawAtom is visible.
 
Methods inherited from class gishur.gui2.DrawAtom
addProperties, collectHits, dispatchEvent, displayManager, drawComponent, getBounds, getLocalProperty, getProperty, getProperty, getRequiredProperty, preprocessEvent, processMessage, properties, removeProperty, sendEvent, sendMessage, setBounds, setPropertiesTo, setProperty, setProperty, setProperty, setProperty, toString, toString, toStringDetail, toTreeString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DrawObject

protected DrawObject(java.lang.String property_prefix)
Constructs a new DisplayObject which uses the given prefix for all properties.
Parameters:
property_prefix - the prefix string used for all read properties
Method Detail

propertyReader

public PropertyStatusReader propertyReader()
The PropertyStatusReader that should be used for reading properties.
Returns:
PropertyStatusReader for reading properties.

firstPainter

protected final Painter firstPainter()
Returns the first Painter in the painter list.
Returns:
the first Painter in the painter list.

nextPainter

protected final Painter nextPainter(Painter p)
Returns the next Painter of the given Painter p in the painter list.
Parameters:
p - the Painter which successor will be returned.
Returns:
the successor of the given Painter

findPainter

protected Painter findPainter(java.lang.String name)
Returns the first stored Painter with the given name.
Parameters:
name - the name to search for
Returns:
the first Painter with the given name

addPainter

protected final void addPainter(Painter p)
Adds the given Painter at the end of the current painter list.
Parameters:
p - the Painter to add

levelMask

public byte levelMask()
Returns the level mask (a combination of levels, that are displayed by this DrawObject).
Returns:
level mask

levelUsed

public byte levelUsed()
Returns a level mask of levels, that are used by this DrawObject).
Returns:
used level mask

recalculate

protected abstract void recalculate(RenderContext context,
                                    PropertyStatusReader properties)
Forces the DrawObject to recalculate its representation. This method will only be called, if it became dirty via a call to the makeDirty(boolean) method or something has happened, that causes all DrawAtoms to recalculate their representation. This method should only be called by the render system.
Parameters:
context - the RenderContext to use
properties - the PropertyStatusReader to use for reading properties

draw

protected void draw(java.awt.Graphics g,
                    RenderContext context,
                    PropertyStatusReader properties)
Draws this DrawAtom to the given Graphics. The default implementation of this method calls the Painter.draw(java.awt.Graphics, gishur.gui2.RenderContext, gishur.gui2.PropertyStatusReader, byte) methods of the stored Painters for all used levels. This method should only be called by the render system.
Parameters:
g - Graphics for drawing
context - the RenderContext to use
properties - the PropertyStatusReader to use for
Throws:
DrawException - if invalid call to this method

recalculate

protected final void recalculate(RenderContext context)
Forces the DrawAtom to recalculate its representation. This method will only be called, if it became dirty via a call to the makeDirty(boolean) method or something has happened, that causes all DrawAtoms to recalculate their representation. This method should only be called by the render system.
Overrides:
recalculate in class DrawAtom
Parameters:
context - the RenderContext to use

ensureRecalculate

protected void ensureRecalculate(RenderContext context)
This method could be used, to ensure recalculation of the DrawObject. This may be useful, if another DrawObject needs the representation of this DrawObject in order to be calculated correctly. To enable access to this method from outside overwrite the method (by calling this implementation) to put it to the same package.
Parameters:
context - must be a valid RenderContext

draw

protected final void draw(java.awt.Graphics g,
                          RenderContext context)
Draws this DrawAtom to the given Graphics g. This method should only be called by the render system.
Overrides:
draw in class DrawAtom
Parameters:
g - Graphics for drawing
context - the RenderContext to use
Throws:
DrawException - if invalid call to this method

prepeareRenderContext

protected void prepeareRenderContext(RenderContext context)
Prepeares the RenderContext before recalulation or drawing via a call to recalculate(gishur.gui2.RenderContext, gishur.gui2.PropertyStatusReader)/draw(Graphics,RenderContext).
Overrides:
prepeareRenderContext in class DrawAtom
Parameters:
context - RenderContext to prepeare

locate

public java.lang.String locate(int x,
                               int y)
Locates the point (x,y). If the point lies outside of the DrawAtom's bounds null will be returned, otherwise a String value will be returned that identifies the part that hits the given point. In this implementation, the name of the Painter will be returned, that hits the given point.
Overrides:
locate in class DrawAtom
Parameters:
x,y - point to locate
Returns:
null for no hit, otherwise the name of the element that hits the point.

setScreenTransformation

protected void setScreenTransformation(ScreenTransformation transform)
Sets the screen transformation for this DrawObject. The transformation will be stored under the key "screen_transformation" in this DrawObjects properties list. To initialize the ScreenTransformation correctly, use this method instead of DrawAtom.setProperty(java.lang.String, java.lang.Object).
Parameters:
transform - the new ScreenTransformation

screenTransformation

public ScreenTransformation screenTransformation()
Returns the valid ScreenTransformation for this DrawObject. If no ScreenTransformation is set, an exception will be thrown.
Returns:
the ScreenTransformation for this DrawObject.
Throws:
{@link - DrawException} if property value ("screen_transformation" was not set.

processEvent

protected void processEvent(java.awt.AWTEvent e)
Processes events delivered to this DrawObject. By default this method calls the appropriate process<event type>Event method for the given class of event. A DrawObject generates DrawEvents according to the enabled event mask (see enableEvents(int)) - these generated events are processed to this method. The checking for enabled events will be done before the call of this method.
Parameters:
e - the event.
See Also:
processDrawEvent(gishur.gui2.event.DrawEvent)

processDrawEvent

protected void processDrawEvent(DrawEvent e)
Processes DrawEvents occuring on this DrawObject. This implementation of processDrawEvent delivers the event to the appropriate listener methods for DrawEvents, if this object implements some of them. So its enough to implement listeners and enable events to process DrawEvents occured at this DrawObject at the appropriate listener methods.

The supported listeners are:

Parameters:
e - DrawEvent to process

enableEvents

protected final void enableEvents(int events_to_enable)
Enables the events defined by the specified event mask parameter to be delivered to this DrawObject. The parameter should be OR-combined event masks. If you want to enable standard awt-events, use the maks defined by GishurEvent (starting with AWT_) instead of the event masks defined by AWTEvent. Do not use event id's as event masks - this will not work! All events defined by the Gishur package have an event mask part and an id part - so one should only use the mask part! This method only needs to be invoked by subclasses of DrawObject which desire to have the specified event types delivered to. processEvent(java.awt.AWTEvent).
Parameters:
events_to_enable - the event mask defining the event types.

disableEvents

protected final void disableEvents(int events_to_disable)
Disables the events defined by the specified event mask parameter from being delivered to this DrawObject.
Parameters:
events_to_disable - the event mask defining the event types.

next

protected DrawObject next(DrawObject drw)
Returns the next DrawObject of the given DrawObject, if this is direct parent of the given DrawObject or null if it is the last group element. This method 'jumps over' elements in the drawing hierachy, that are no DrawObjects.
Returns:
next DrawObject

next

protected DrawObject next()
Returns the next DrawObject in the group or null if it is the last group element. This method 'jumps over' elements in the drawing hierachy, that are no DrawObjects.
Returns:
next DrawObject

prev

protected DrawObject prev()
Returns the previous DrawObject in the group or null if it is the first group element. This method 'jumps over' elements in the drawing hierachy, that are no DrawObjects.
Returns:
previous DrawObject

prev

protected DrawObject prev(DrawObject drw)
Returns the previous DrawObject of the given DrawObject, if this is direct parent of the given DrawObject or null if it is the first group element. This method 'jumps over' elements in the drawing hierachy, that are no DrawObjects.
Returns:
next DrawObject

parent

protected DrawObject parent()
Returns the parent group of this DrawObject.
Returns:
parent

child

protected DrawObject child()
Returns the first group element of the group. This method 'jumps over' elements in the drawing hierachy, that are no DrawObjects.
Returns:
first child

insert

protected void insert(DrawObject p,
                      DrawObject drw)
Inserts the DrawObject drw in the group before p. The inserted DrawObject is unvisible by default.
Parameters:
p - group member to insert before or null to add at the end of the group
drw - DrawObject to insert

remove

protected void remove(DrawObject drw)
Removes the given DrawObject from this group. If the specified DrawObject has members, all members were removed first. Insertion of the DrawObject inserts only the DrawObject - without its members.
Parameters:
drw - DrawObject to remove

clear

protected void clear()
Removes all member DrawObjects from this DrawAtom.

dependency

protected DrawDependency dependency()
Returns the DrawDependency of this DrawObject.
Returns:
the DrawDependency of this DrawObject.

fullscreen

protected boolean fullscreen()
Returns true, if this DrawObject needs the full screen as bounds.
Returns:
true, if fullscreen DrawObject

setFullscreen

protected boolean setFullscreen(boolean fullscreen)
Marks or clears this DrawObject as a fullscreen DrawObject.
Parameters:
fullscreen - if true, object will use full screen otherwise its bounds are fixed
Returns:
old fullscreen state

setPaintBeforeMembers

protected boolean setPaintBeforeMembers(boolean paintbefore)
Defines the paint order of this DrawObject and its members.
Parameters:
paintbefore - if true: this DrawObject will be painted before its members.
Returns:
old value of paint before members.

addDrawDependency

protected void addDrawDependency(DrawObject drw)
Deprecated.  

Adds this DrawObject as draw-dependend by the given DrawObject.
Parameters:
drw - the DrawObject, from which this depends

removeDrawDependency

protected void removeDrawDependency(DrawObject drw)
Deprecated.  

Removes the draw-dependency of this DrawObject from the given this DrawObject.
Parameters:
drw - the DrawObject, from which this depends

dirty

public boolean dirty()
Returns true, if the object is currently marked as dirty.
Returns:
true, if object dirty

makeDirty

public final void makeDirty(boolean update)
Marks this DrawAtom for repainting (and recalculating). If update==true, the recalculation/repainting system will be started immediately.
Parameters:
update - if true, recalculation/repainting system starts

makeDirty

public final void makeDirty()
Marks this DrawAtom for repainting (and recalculating) and starts the recalculation/repainting system immediately.
Parameters:
recalc - if true, the DrawAtom will be recalculated, otherwise only repainted.

clearCache

public void clearCache()
Clears the property-cache at this DrawObject and at all members.

repaint

public final void repaint()
Starts the recalculation/repainting system immediately.

blockRepaint

protected void blockRepaint()
Blocks all repaint() calls at this drawing hierachy. Make shure to call unblockRepaint(boolean), that will ensure, that objects will be repainted. Blocking calls may be nested, but every call of blockRepaint() should be finished by a call of unblockRepaint(boolean).

unblockRepaint

protected void unblockRepaint(boolean recalc_all)
Unblocks repaint() calls and repaints all (dirty) objects.
Parameters:
repaint_all - if true a full repaint will be done.

unblockRepaint

protected void unblockRepaint()
Unblocks repaint() calls and repaints all dirty objects.

visible

public boolean visible()
Returns true, if the DrawAtom is visible.
Returns:
true, if visible

hide

public void hide(boolean update)
Hides the DrawAtom (visible()()==false).

hide

public void hide()
Hides the DrawAtom (visible()()==false).

show

public void show(boolean update)
Shows the DrawAtom (visible()()==true).

show

public void show()
Shows the DrawAtom (visible()()==true).

checkState

public final boolean checkState(int state)
Checks if the given state is set.
Parameters:
state - state to verify
Returns:
True, if state set, else false.

checkStateCleared

public final boolean checkStateCleared(int state)
Checks if the given state is cleared; that means every bit of the given state is cleared.
Parameters:
state - state to verify
Returns:
True, if state cleared, else false.

state

public final int state()
Returns the complete state of this object.
Returns:
State.

state

public final int state(int state)
Returns the state for the given state constant.
Returns:
State information.

setState

public final void setState(int state)
Sets a given state. state must only use bits of DrawAtom.USER_STATES_MASK, otherwise these bits will be ignored.
Parameters:
state - state to set

clearState

public final void clearState(int state)
Clears a given state. state must only use bits of DrawAtom.USER_STATES_MASK, otherwise these bits will be ignored.
Parameters:
state - state to clear