GeoSoft API

no.geosoft.cc.graphics
Class GObject

Object
  extended byGObject
All Implemented Interfaces:
GStyleListener
Direct Known Subclasses:
GScene

public class GObject
extends Object
implements GStyleListener

Class representing a graphical object. The representation is by actual geometry (GSegments) or in terms of sub objects (or both).

Typically GObject is extended and its draw() method is overloaded:

    public class ClientGraphicsObject extends GObject
    {
        public ClientGraphicsObject()
        {
           // Prepare the graphics object here, i.e. add the
           // GSegments and sub-GObjects it consists of, and
           // set rendering style (GStyle) on the elements
           // and add annotations (GText) and images (GImage).
        }

        public void draw()
        {
           // Set geometry for all containing GSegments.
        }
    }
 
A top level GObject is inserted into the scene like this:
    GScene scene = new GScene (window);
 
    GObject object = new ClientGraphicsObject();
    scene.add (object);
 

Author:
GeoSoft

Field Summary
static int ANNOTATION_INVISIBLE
           
static int ANNOTATION_VISIBLE
           
static int DATA_INVISIBLE
           
static int DATA_VISIBLE
           
static int INVISIBLE
           
static int SYMBOLS_INVISIBLE
           
static int SYMBOLS_VISIBLE
           
static int VISIBLE
           
static int WIDGETS_INVISIBLE
           
static int WIDGETS_VISIBLE
           
 
Constructor Summary
GObject()
          Create a new unnamed graphic object.
GObject(String name)
          Create a graphical object with specified name.
 
Method Summary
 void add(GObject child)
          Add child object to this object.
 void add(GObject child, int position)
          Add a sub object to this graphics object.
 void addSegment(GSegment segment)
          Add a new segment to this object.
 int back()
          Return the position code for back.
 int backward()
          Return position code for "backward".
 int behind(GObject child)
          Return the position code for the position behind the specified child node.
 void draw()
          This method should be overloaded for graphics objects with drawable elements (GSegments).
 GObject find(int x, int y)
          Return front-most object intersecting the specfied point.
 GObject find(int x0, int y0, int x1, int y1)
          Return front-most object intersecting the specfied rectangle.
 GObject find(Object userData)
          Find sub object based on user data tag.
 GObject find(String name)
          Find a child object with specified name.
 List findAll(int x, int y)
          Find all objects intersecting a specified point.
 List findAll(int x0, int y0, int x1, int y1)
          Find all objects intersecting a specified rectangle.
 List findAllInside(int x0, int y0, int x1, int y1)
          Find all objects inside a specified rectangle.
 GObject findInside(int x0, int y0, int x1, int y1)
          Find front-most object that are inside the specified rectangle.
 GSegment findSegment(int x, int y)
          Return the first segment found that intersects the specified point.
 GSegment findSegment(int x0, int y0, int x1, int y1)
          Return the first segment found that intersects the specified rectangle Search this node, and all sub nodes.
 GSegment findSegment(Object userData)
          Find a segment with specified user data.
 GSegment findSegmentInside(int x0, int y0, int x1, int y1)
          Return the first segment found that are completely inside the specified rectangle.
 List findSegments(int x, int y)
          Return all segments that intersects with the specified point.
 List findSegments(int x0, int y0, int x1, int y1)
          Return all segments that intersects the specified rectangle.
 List findSegmentsInside(int x0, int y0, int x1, int y1)
          Return all segments that are completely inside of the specified rectangle.
 int forward()
          Return position code for "forward".
 int front()
          Return the position code for front.
 GObject getChild(int position)
          Return the child object at specified position.
 List getChildren()
          Return all children objects of this GObject.
 String getName()
          Return name of this graphic object.
 int getNChildren()
          Return number of children of this graphic object.
 int getNSegments()
          Return number of segments in this GObject.
 GObject getObjectBehind()
          Return the sibling object immediately behind this object.
 GObject getObjectInFront()
          Return the sibling object in the immediate front of this object.
 GObject getParent()
          Return parent GObject of this object.
 GScene getScene()
          Return scene of this graphic object.
 GSegment getSegment()
          Return first segment of this graphic object.
 GSegment getSegment(int segmentNo)
          Return the n'th segment of this object.
 List getSegments()
          Return all segments of this graphic object.
 GStyle getStyle()
          Return style of this object.
 GTransformer getTransformer()
          Conveience method for getting the transformation object of the scene of this object.
 Object getUserData()
          Return user data of this graphics object.
 int getVisibility()
          Return the current visibility mask for this object.
 GWindow getWindow()
          Return the window of this graphic object.
 int inFrontOf(GObject child)
          Return the position code for the position in front of the specified child node.
 boolean isInBack()
          Return true if this object is behind all its siblings.
 boolean isInFront()
          Return true if this object is in front of all its siblings.
 void redraw()
          Force a redraw of this object.
 void refresh()
          Convenience method for refreshing the window canvas.
 void remove()
          Unlink self from parent child list.
 void remove(GObject child)
          Remove child from child list.
 void removeAll()
          Remove all children objects.
 void removeSegment(GSegment segment)
          Remove the specified segment from this GObject.
 void removeSegment(int segmentNo)
          Remove specified segment from this GObject.
 void removeSegments()
          Remove all segments from this GObject.
 void removeSegments(int from)
          Remove sequence of segments from this object.
 void removeSegments(int from, int to)
          Remove sequence of segments from this object.
 void reposition(GObject child, int position)
          Reposition specified child object.
 void setName(String name)
          Set name of this graphic object.
 void setStyle(GStyle style)
          Set new style for this object.
 void setUserData(Object userData)
          Set user data of this graphics object.
 void setVisibility(int visibilityMask)
          Change the visibility for this object.
 void styleChanged(GStyle style)
          Called when the style of this object is changed.
 void toBack()
          Move this object to the behind its siblings in its parent object.
 void toFront()
          Move this object to the front of its siblings in its parent object.
 String toString()
          Return a string representation of this object.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATA_VISIBLE

public static final int DATA_VISIBLE
See Also:
Constant Field Values

ANNOTATION_VISIBLE

public static final int ANNOTATION_VISIBLE
See Also:
Constant Field Values

SYMBOLS_VISIBLE

public static final int SYMBOLS_VISIBLE
See Also:
Constant Field Values

WIDGETS_VISIBLE

public static final int WIDGETS_VISIBLE
See Also:
Constant Field Values

VISIBLE

public static final int VISIBLE
See Also:
Constant Field Values

DATA_INVISIBLE

public static final int DATA_INVISIBLE
See Also:
Constant Field Values

ANNOTATION_INVISIBLE

public static final int ANNOTATION_INVISIBLE
See Also:
Constant Field Values

SYMBOLS_INVISIBLE

public static final int SYMBOLS_INVISIBLE
See Also:
Constant Field Values

WIDGETS_INVISIBLE

public static final int WIDGETS_INVISIBLE
See Also:
Constant Field Values

INVISIBLE

public static final int INVISIBLE
See Also:
Constant Field Values
Constructor Detail

GObject

public GObject(String name)
Create a graphical object with specified name.

Parameters:
name - Name of object.

GObject

public GObject()
Create a new unnamed graphic object.

Method Detail

getName

public String getName()
Return name of this graphic object.

Returns:
Name of this graphic object.

setName

public void setName(String name)
Set name of this graphic object.

Parameters:
name - New name of this graphic object.

getScene

public GScene getScene()
Return scene of this graphic object. The scene defines the world-to-device transformation.

Returns:
Scene of this graphic object (or null if the object is not attached to a scene).

getTransformer

public GTransformer getTransformer()
Conveience method for getting the transformation object of the scene of this object.

Returns:
Transformation object for this graphic object (or null if the object is not attached to a scene).

getWindow

public GWindow getWindow()
Return the window of this graphic object.

Returns:
Window of this graphic object (or null if this object is not attached to a window).

getSegments

public List getSegments()
Return all segments of this graphic object.

Returns:
All segments of this object (or null if none).

getSegment

public GSegment getSegment()
Return first segment of this graphic object. Convenient if the caller knows that it contains exactly one segment.

Returns:
First segment of this graphics object (or null if none).

getVisibility

public int getVisibility()
Return the current visibility mask for this object.

Returns:
Current visibility of this object.
See Also:
setVisibility(int)

setUserData

public void setUserData(Object userData)
Set user data of this graphics object.

Parameters:
userData - User data of this graphics object.

getUserData

public Object getUserData()
Return user data of this graphics object.

Returns:
User data of this graphics object.

find

public GObject find(Object userData)
Find sub object based on user data tag. Search from this (included) and in entire sub tree, depth first.

Parameters:
userData - User data of child to find.
Returns:
Requested object (or null if not found).

findSegment

public GSegment findSegment(Object userData)
Find a segment with specified user data. Start search in this node.

Parameters:
userData - User data of requested segment.
Returns:
Segment (or null if not found).

add

public void add(GObject child,
                int position)
Add a sub object to this graphics object. Use as: Add is performed on a parent node, adding child to self.

Parameters:
child - Object to add
position - Position to add to

add

public void add(GObject child)
Add child object to this object. Add to front (on screen).

Parameters:
child - Child to add.

toFront

public void toFront()
Move this object to the front of its siblings in its parent object. If doesn't have a parent, this method has no effect. This is a convenience shorthand of getParent().reposition (this, getParent().front());


toBack

public void toBack()
Move this object to the behind its siblings in its parent object. If doesn't have a parent, this method has no effect. This is a convenience shorthand of getParent().reposition (this, getParent().back());


reposition

public void reposition(GObject child,
                       int position)
Reposition specified child object. Use as:

Parameters:
child - Child object to be repositioned.
position - New position of child.

behind

public int behind(GObject child)
Return the position code for the position behind the specified child node.

Parameters:
child - Child node.
Returns:
Position for "behind" child.
See Also:
reposition(GObject,int)

inFrontOf

public int inFrontOf(GObject child)
Return the position code for the position in front of the specified child node.

Parameters:
child - Child node.
Returns:
Position for "in front of" child.
See Also:
reposition(GObject,int)

front

public int front()
Return the position code for front.

Returns:
Position code for "front".
See Also:
reposition(GObject,int)

back

public int back()
Return the position code for back.

Returns:
Position code for "back".
See Also:
reposition(GObject,int)

forward

public int forward()
Return position code for "forward".

Returns:
Position code for "forward".
See Also:
reposition(GObject,int)

backward

public int backward()
Return position code for "backward".

Returns:
Position code for "backward".
See Also:
reposition(GObject,int)

getChildren

public List getChildren()
Return all children objects of this GObject.

Returns:
All children objects of this GObject.

getNChildren

public int getNChildren()
Return number of children of this graphic object.

Returns:
Number of children of this GObject.

find

public GObject find(String name)
Find a child object with specified name. Search entire sub tree from this node, depth first.

Parameters:
name - Name of object to find.
Returns:
Requested object (or null if not found).

findSegments

public List findSegments(int x0,
                         int y0,
                         int x1,
                         int y1)
Return all segments that intersects the specified rectangle. Serach this node, and all sub nodes.

Parameters:
x0 - X coordinate of upper left corner of rectangle.
y0 - Y coordinate of upper left corner of rectangle.
x1 - X coordinate of lower right corner of rectangle.
y1 - Y coordinate of lower right corner of rectangle.
Returns:
List of segments intersecting the rectangle. If none do, an empty list is returned.

findSegmentsInside

public List findSegmentsInside(int x0,
                               int y0,
                               int x1,
                               int y1)
Return all segments that are completely inside of the specified rectangle. Serach this node, and all sub nodes.

Parameters:
x0 - X coordinate of upper left corner of rectangle.
y0 - Y coordinate of upper left corner of rectangle.
x1 - X coordinate of lower right corner of rectangle.
y1 - Y coordinate of lower right corner of rectangle.
Returns:
List of segments intersecting the rectangle. If none do, an empty list is returned.

findSegment

public GSegment findSegment(int x0,
                            int y0,
                            int x1,
                            int y1)
Return the first segment found that intersects the specified rectangle Search this node, and all sub nodes.

Parameters:
x0 - X coordinate of upper left corner of rectangle.
y0 - Y coordinate of upper left corner of rectangle.
x1 - X coordinate of lower right corner of rectangle.
y1 - Y coordinate of lower right corner of rectangle.
Returns:
A segment intersecting the rectangle (or null if none do).

findSegmentInside

public GSegment findSegmentInside(int x0,
                                  int y0,
                                  int x1,
                                  int y1)
Return the first segment found that are completely inside the specified rectangle. Search this node, and all sub nodes.

Parameters:
x0 - X coordinate of upper left corner of rectangle.
y0 - Y coordinate of upper left corner of rectangle.
x1 - X coordinate of lower right corner of rectangle.
y1 - Y coordinate of lower right corner of rectangle.
Returns:
A segment intersecting the rectangle (or null if none do).

findSegment

public GSegment findSegment(int x,
                            int y)
Return the first segment found that intersects the specified point. Search this node, and all sub nodes.

Parameters:
x - X coordinate of point to check.
y - Y coordinate of point to check.
Returns:
Front-most segment intersecting the point (or null if none do).

findSegments

public List findSegments(int x,
                         int y)
Return all segments that intersects with the specified point. Search this node, and all sub nodes.

Returns:
All segments intersecting the point. If none do, an empty list is returned.

find

public GObject find(int x0,
                    int y0,
                    int x1,
                    int y1)
Return front-most object intersecting the specfied rectangle.

Parameters:
x0 - X coordinate of upper left corner of rectangle.
y0 - Y coordinate of upper left corner of rectangle.
x1 - X coordinate of lower right corner of rectangle.
y1 - Y coordinate of lower right corner of rectangle.
Returns:
Front-most object intersecting the specified rectangle (or null if none do).

findInside

public GObject findInside(int x0,
                          int y0,
                          int x1,
                          int y1)
Find front-most object that are inside the specified rectangle.

Parameters:
x0 - X coordinate of upper left corner of rectangle.
y0 - Y coordinate of upper left corner of rectangle.
x1 - X coordinate of lower right corner of rectangle.
y1 - Y coordinate of lower right corner of rectangle.
Returns:
Front most child object that are fully inside the specified rectangle (or null if none are).

find

public GObject find(int x,
                    int y)
Return front-most object intersecting the specfied point.

Parameters:
x - X coordinate of point to check.
y - Y coordinate of point to check.
Returns:
Front-most object intersecting the point (or null if none do).

findAll

public List findAll(int x0,
                    int y0,
                    int x1,
                    int y1)
Find all objects intersecting a specified rectangle. Objects are returned with front most object on screen last in list. Seacrh is done in the subtree of this object (including this). If no objects intersects, an empty list is returned.

Parameters:
x0 - X coordinate of upper left corner of rectangle.
y0 - Y coordinate of upper left corner of rectangle.
x1 - X coordinate of lower right corner of rectangle.
y1 - Y coordinate of lower right corner of rectangle.
Returns:
All objects intersecting the specified rectangle.

findAllInside

public List findAllInside(int x0,
                          int y0,
                          int x1,
                          int y1)
Find all objects inside a specified rectangle. Objects are returned with front most object on screen last in list. Seacrh is done in the subtree of this object (including this). If no objects is inside, an empty list is returned.

Returns:
All objects intersecting the rectangle.

findAll

public List findAll(int x,
                    int y)
Find all objects intersecting a specified point. Objects are returned with front most object on screen last in list. Seacrh is done in the subtree of this object (including this). If no objects intersects, an empty list is returned.

Parameters:
x - X coordinate of point to check.
y - Y coordinate of point to check.
Returns:
All objects intersecting the specfied point.

remove

public void remove()
Unlink self from parent child list.


remove

public void remove(GObject child)
Remove child from child list.

Parameters:
child - Child object to remove.

removeAll

public void removeAll()
Remove all children objects.


getChild

public GObject getChild(int position)
Return the child object at specified position.

Parameters:
position - Position to return child of.
Returns:
Requested child (or null if non existing).

isInFront

public boolean isInFront()
Return true if this object is in front of all its siblings.

Returns:
True if this object is in fron of all siblings, false otherwise.

isInBack

public boolean isInBack()
Return true if this object is behind all its siblings.

Returns:
True if this object is behind all siblings, false otherwise.

getObjectInFront

public GObject getObjectInFront()
Return the sibling object in the immediate front of this object.

Returns:
The sibling object in the immediate front of this object (or null if this object is in front, or it is not attach to a parent).

getObjectBehind

public GObject getObjectBehind()
Return the sibling object immediately behind this object.

Returns:
The sibling object immediately behind this object (or null if this object is in back, or it is not attach to a parent).

addSegment

public void addSegment(GSegment segment)
Add a new segment to this object.

Parameters:
segment - Segment to add.

getSegment

public GSegment getSegment(int segmentNo)
Return the n'th segment of this object.

Parameters:
segmentNo - Segment number to return.
Returns:
N'th segment (or null if non existent).

getNSegments

public int getNSegments()
Return number of segments in this GObject.

Returns:
Number of segments in this GObject.

removeSegment

public void removeSegment(GSegment segment)
Remove the specified segment from this GObject.

Parameters:
segment - Segment to remove. If the specified segment is not a child of this GObject, this call has no effect.

removeSegment

public void removeSegment(int segmentNo)
Remove specified segment from this GObject.

Parameters:
segmentNo - Segment to remove. If the specified segment does not exist, this casll has no effect.

removeSegments

public void removeSegments()
Remove all segments from this GObject.


removeSegments

public void removeSegments(int from,
                           int to)
Remove sequence of segments from this object.

Parameters:
from - Starting segment
to - Ending segment (-1 indicates all).

removeSegments

public void removeSegments(int from)
Remove sequence of segments from this object. Remove all from specified start segment.

Parameters:
from - Starting segment

redraw

public void redraw()
Force a redraw of this object.

Normally this method is called automatically whenever needed (typically on retransformations). A client application may call this method explicitly if some external factor that influence the graphics has been changed. However, beware of the performance overhead of such an approach, and consider reorganizing the code so that model changes explictly affects the graphics elements.


setStyle

public void setStyle(GStyle style)
Set new style for this object. Style elements not explicitly set within this GStyle object are inherited from parent objects. Child objects with not explicit set style will inherit from this style object. A GObject does not need a style instance; in this case all style elements are inherited.

Parameters:
style - Style of this object (or null if the intent is to unset the current style).

getStyle

public GStyle getStyle()
Return style of this object. This is the style set by setStyle() and not necesserily the style as it appears on screen as unset style elements are inherited from parents.

Returns:
Style of this object as specified with setStyle(), (or null if no style has been provided).

setVisibility

public void setVisibility(int visibilityMask)
Change the visibility for this object.

NOTE: The present visibility is maintained, and the new flag is taken as an instruction for change. The instruction is an or'ed combination of:

The settings VISIBLE and INVISIBLE are conveniences compound for all visible and invisible settings respectively.

Parameters:
visibilityMask - Visibility instruction.

getParent

public GObject getParent()
Return parent GObject of this object.

Returns:
Parent of this object (or null if it doesn't have a parent).

refresh

public void refresh()
Convenience method for refreshing the window canvas. Equivalent to getWindow().refresh();.


draw

public void draw()
This method should be overloaded for graphics objects with drawable elements (GSegments). Intermediate nodes should leave the method empty.


styleChanged

public void styleChanged(GStyle style)
Called when the style of this object is changed.

Specified by:
styleChanged in interface GStyleListener
Parameters:
style - Style that has changed.

toString

public String toString()
Return a string representation of this object.

Returns:
String representation of this object.

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no