GeoSoft API

no.geosoft.cc.graphics
Class GSegment

Object
  extended byGSegment
All Implemented Interfaces:
GStyleListener

public class GSegment
extends Object
implements GStyleListener

Class for holding a polyline. GSegments are contained by GObjects. They can have its own rendering style (GStyle) or inherit style from its parent GObject if not specified.

Example usage:

    public class Box extends GObject
    {
       private double    x0_, y0_, width_, height_;
       private GSegment  border_;

       public Box (double x0, double y0, double width, double height)
       {
          // Store the abstract representation of the box
          x0_     = x0;
          y0_     = y0;
          width_  = width;
          height_ = height;

          // Prepare the graphics representation of the box
          border_ = new GSegment();
          addSegment (border_);
       }

       public void draw()
       {
          // Complete the graphics representation of the box
          double[] xy = new double {x0_,          y0_,
                                    x0_ + width_, y0_,
                                    x0_ + width_, y0_ + height_,
                                    x0_,          y0_ + height_,
                                    x0_,          y0}
          border_.setGeometry (xy);
       }
    }
 
A typical GObject will have many GSegments and sub-GObjects. Some of these can be created in the constructor while others may need to be created within the draw method as they depend ont external factors such as zoom etc.

For efficiency, G does not store world coordinates internally but converts these to device coordinates in the rendering step. It is therfore essential that geometry is provided in the draw() method which is called by G on retransformations (zoom/resize etc.).

Author:
GeoSoft

Constructor Summary
GSegment()
          Create a GSegment.
 
Method Summary
 void addComponent(GComponent component)
          Add a AWT component to this segment.
 void addImage(GImage image)
          Add an image to this segment.
 void addText(GText text)
          Add a text element to this segment.
 Collection getComponents()
          Return all AWT components of this segment.
 Collection getImages()
          Return all images associated with this segment.
 GObject getOwner()
          Return the owner GObject of this GSegment.
 GStyle getStyle()
          Return style for this segment.
 GText getText()
          Return the first text element of this segment.
 List getTexts()
          Return all text elements of this segment.
 Object getUserData()
          Return user data of this GSegment.
 GImage getVertexImage()
          Return the image that is to be associated with all vertices of this GSegment.
 void removeComponents()
          Remove all AWT components from this GSegment.
 void removeImages()
          Remove all images from this GSegment.
 void removeText()
          Remove all text elements set on this segment.
 void setComponent(GComponent component)
          Set component of this segment.
 void setGeometry(double[] xyz)
          Set polyline world coordinate geometry.
 void setGeometry(double[] x, double[] y)
          Set polyline world coordinate geometry.
 void setGeometry(double[] x, double[] y, double[] z)
          Set polyline world coordinate geometry.
 void setGeometry(double x, double y)
          Set single point world coordinate geometry.
 void setGeometry(double x, double y, double z)
          Set single point world coordinate geometry.
 void setGeometry(double x0, double y0, double x1, double y1)
          Set two point (line) world coordinate geometry.
 void setGeometry(double x0, double y0, double z0, double x1, double y1, double z1)
          Set two point (line) world coordinate geometry.
 void setGeometry(int[] xy)
          Set polyline device coordinate geometry.
 void setGeometry(int[] x, int[] y)
          Set polyline device coordinate geometry.
 void setGeometry(int x, int y)
          Set single point device coordinate geometry.
 void setGeometry(int x0, int y0, int x1, int y1)
          Set two point (line) device coordinate geometry.
 void setGeometryXy(double[] xy)
          Set polyline world coordinate geometry.
 void setImage(GImage image)
          Set image of this segment.
 void setStyle(GStyle style)
          Set new style for this segment.
 void setText(GText text)
          Set text element of this segment.
 void setUserData(Object userData)
          Set user data of this GSegment.
 void setVertexImage(GImage image)
          Set image to associate with every vertex of this GSegment.
 void styleChanged(GStyle style)
          Called when the style of this object is changed.
 void translate(int dx, int dy)
          Translate this segment in device.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GSegment

public GSegment()
Create a GSegment.

Method Detail

getOwner

public GObject getOwner()
Return the owner GObject of this GSegment. If the GSegment has not been added to a GObject, owner is null.

Returns:
GObject owner of this GSegment, or null if not attacted to one.

setUserData

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

Parameters:
userData - User data of this GSegment.

getUserData

public Object getUserData()
Return user data of this GSegment.

Returns:
User data of this GSegment.

setGeometry

public void setGeometry(int x,
                        int y)
Set single point device coordinate geometry.

Parameters:
x - X coordinate.
y - Y coordinate.

setGeometry

public void setGeometry(int x0,
                        int y0,
                        int x1,
                        int y1)
Set two point (line) device coordinate geometry.

Parameters:
x0 - X coordinate of first end point.
y0 - Y coordinate of first end point.
x1 - X coordinate of second end point.
y1 - Y coordinate of second end point.

setGeometry

public void setGeometry(int[] x,
                        int[] y)
Set polyline device coordinate geometry.

Parameters:
x - X coordinates.
y - Y coordinates.

setGeometry

public void setGeometry(int[] xy)
Set polyline device coordinate geometry.

Parameters:
xy - Polyline geometry [x,y,x,y,...]. null can be specified to indicate that the present geometry should be removed.

setGeometry

public void setGeometry(double x,
                        double y,
                        double z)
Set single point world coordinate geometry.

Parameters:
x - X coordinate.
y - Y coordinate.
z - Z coordinate.

setGeometry

public void setGeometry(double x,
                        double y)
Set single point world coordinate geometry. Ignore Z coordinate (set to 0.0).

Parameters:
x - X coordinate.
y - Y coordinate.

setGeometry

public void setGeometry(double x0,
                        double y0,
                        double z0,
                        double x1,
                        double y1,
                        double z1)
Set two point (line) world coordinate geometry.

Parameters:
x0 - X coordinate of first end point.
y0 - Y coordinate of first end point.
z0 - Z coordinate of first end point.
x1 - X coordinate of second end point.
y1 - Y coordinate of second end point.
z1 - Z coordinate of second end point.

setGeometry

public void setGeometry(double x0,
                        double y0,
                        double x1,
                        double y1)
Set two point (line) world coordinate geometry. Ignore Z coordinate (set to 0.0).

Parameters:
x0 - X coordinate of first end point.
y0 - Y coordinate of first end point.
x1 - X coordinate of second end point.
y1 - Y coordinate of second end point.

setGeometry

public void setGeometry(double[] x,
                        double[] y,
                        double[] z)
Set polyline world coordinate geometry. TODO: Look at the implementation


setGeometry

public void setGeometry(double[] x,
                        double[] y)
Set polyline world coordinate geometry. Ignore Z coordinate (interpret all as 0.0).

Parameters:
x - X coordinates.
y - Y coordinates.

setGeometry

public void setGeometry(double[] xyz)
Set polyline world coordinate geometry.

Parameters:
xyz - Polyline geometry [x,y,z,x,y,z,...].

setGeometryXy

public void setGeometryXy(double[] xy)
Set polyline world coordinate geometry. Ignore Z coordinate (set to 0.0).

Parameters:
xy - Polyline geometry [x,y,x,y,...].

translate

public void translate(int dx,
                      int dy)
Translate this segment in device.

Parameters:
dx - Translation in x direction.
dy - Translation in Y direction.

setStyle

public void setStyle(GStyle style)
Set new style for this segment. Style elements not explicitly set within this GStyle object are inherited from parent objects. Default style is null, i.e. all style elements are inherited from parent.

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

getStyle

public GStyle getStyle()
Return style for this segment. 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 GSegment as specified with setStyle(), (or null if no style has been provided).

addText

public void addText(GText text)
Add a text element to this segment.

Text elements without line position hint will be associated with the n'th segment coordinate according to the number of texts added.

Parameters:
text - Text element to add.

setText

public void setText(GText text)
Set text element of this segment. Replaces all current text elements of this segment.

Parameters:
text - Text element to set.

getTexts

public List getTexts()
Return all text elements of this segment.

Returns:
All text elements of this segment (or null if none).

getText

public GText getText()
Return the first text element of this segment. Convenient when caller knows that there are exactly one text element.

Returns:
First text elements of this segment (or null if none).

removeText

public void removeText()
Remove all text elements set on this segment.


addImage

public void addImage(GImage image)
Add an image to this segment.

Parameters:
image - Image to add.

setImage

public void setImage(GImage image)
Set image of this segment. All current images are removed.

Parameters:
image - Image to set.

getImages

public Collection getImages()
Return all images associated with this segment.

Returns:
All images associated with this segment.

removeImages

public void removeImages()
Remove all images from this GSegment.


setVertexImage

public void setVertexImage(GImage image)
Set image to associate with every vertex of this GSegment.

Parameters:
image - Image to decorate every vertex of this polyline (or null to turn off this feature).

getVertexImage

public GImage getVertexImage()
Return the image that is to be associated with all vertices of this GSegment. Return null if none is specified.

Returns:
Image that decorates every vertex of this GSegment (or null if not specified).

addComponent

public void addComponent(GComponent component)
Add a AWT component to this segment.

Parameters:
component - Component to add.

setComponent

public void setComponent(GComponent component)
Set component of this segment. All current components are removed.

Parameters:
component - Component to set.

getComponents

public Collection getComponents()
Return all AWT components of this segment.

Returns:
All components of this segment.

removeComponents

public void removeComponents()
Remove all AWT components from this GSegment.


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.

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no