jfig.objects
Class FigBaseobject

java.lang.Object
  extended byjfig.objects.FigBaseobject
All Implemented Interfaces:
FigDrawable, FigObject
Direct Known Subclasses:
FigCompound, FigEllipse, FigRectangle, FigText, FigTrigger

public class FigBaseobject
extends java.lang.Object
implements FigObject

a stub graphics object, suitable for subclassing.

The basic graphics editor object. This implements the full object interface with stub methods and should be subclassed to implement the behaviour for actual objects (polyline, rectangle, text, etc.) version 0.7 13.02.00 added rotate version 0.6 07.04.99 added syncRedrawFlag version 0.5 14.06.97 added isVisible, ObjectPainter for animated objects version 0.4 11.04.96 (added Point functions: insert/append/...) version 0.3 28.03.96 version 0.2 17.03.96


Field Summary
protected  FigAttribs attribs
           
protected  FigBbox bbox
           
protected  java.lang.String comment
           
protected  boolean debug
           
 ObjectPainter painter
           
protected static ConsoleMessage printer
           
protected  FigBbox sc_bbox
           
protected  long sc_bbox_timestamp
           
protected  boolean selected
           
protected  boolean showPoints
           
protected  boolean syncRedrawFlag
           
protected  long timestamp
           
protected  FigTrafo2D trafo
           
protected  boolean visible
           
protected  int x
           
protected  int y
           
 
Constructor Summary
FigBaseobject()
          Basic FigBaseobject constructor.
FigBaseobject(FigTrafo2D trafo)
          Basic FigBaseobject constructor.
 
Method Summary
 void appendPoint(java.awt.Point wp)
          append a Point to our Point list.
 void build_sc_bbox()
           
 boolean canRotate(double angle_in_rad)
           
static java.awt.Point[] clonePoints(java.awt.Point[] points)
           
 FigObject copy()
          method stub for the copy() method.
 java.awt.Point deletePoint(java.awt.Point wp)
          delete the Point with specified coords from our Point list.
 void deselect()
          mehtod stub for the deselect() mehtod
 FigBbox get_sc_bbox()
          get object bounding box (in screen coordinates at current transformation)
 FigAttribs getAttributes()
          get object attributes
 FigBbox getBbox()
          get bounding box (in world coordinates)
 java.lang.String getComment()
          get the comment for this object (may be null).
 int getLayer()
          get layer
 java.awt.Point[] getMovePointNeighbors(java.awt.Point wp)
          get the neighbor Points for a move point operation
 java.awt.Point getNearestPoint(java.awt.Point wp)
          return the point of this object nearest to Point wp, if any.
 java.awt.Point[] getNeighborPoints(java.awt.Point wp)
          get the two neighbor Points for the specified Point wp from our Point list.
 java.awt.Point[] getPoints()
          return a list of all Points of this objects.
 java.awt.Point getPosition()
          get object (reference point) position
 boolean getSyncRedrawFlag()
          is a sync redraw pending on this object?
 java.lang.String getText()
          get the object's text: no text in a baseobject
 long getTimestamp()
          return the timestamp of this object (it's creation/modification time).
 FigTrafo2D getTrafo()
          get transformation
 boolean initialize(java.lang.String s)
          a dummy function to initialize a FigObject from a String resource.
 void insertPoint(java.awt.Point wp, java.awt.Point wprev)
          insert a Point wp into our Point list after Point wprev.
 boolean isClosed()
          return true if this object is 'closed' (polygon vs.
 boolean isSelected()
          get current selection status
 boolean isShowPoints()
           
 boolean isVisible()
          check whether this Object is currently visible.
 boolean isVisible(FigBbox viewport)
          check whether this object is visible inside the given viewport (using world coordinates)
 void keyPressed(java.awt.event.KeyEvent e)
          basic reaction to keyDown events: none.
static int manhattan(java.awt.Point p, java.awt.Point q)
           
 void message(java.lang.String msg)
           
 double minDistance(java.awt.Point wp)
          return the minimum distance of any points (edges,corners) of this object and the Point wp.
 double minDistanceEuclid(java.awt.Point wp)
          return a high-precision value of the minimum distance between point wp and this object.
 void mirrorX(int x, int y)
          method stub for the mirrorX() method
 void mirrorY(int x, int y)
          method stub for the mirrorY() method
 void move(int dx, int dy)
          method stub for the move() method
 void movePoint(java.awt.Point wp, java.awt.Point wpnew)
          move a Point from position wp to new position wpnew
 int numPoints()
          get number of Points in this object
 void paint(java.awt.Graphics g)
          paint() this object.
 void paint(java.awt.Graphics g, FigTrafo2D trafo)
          paint this object using the specified transformation and Graphics g
 void paintSave(java.awt.Graphics g, FigTrafo2D trafo)
           
 void rebuild()
          rebuild (=re-initialize) this object given its current points, attributes, transformation, and the global Java2D enable status.
 void reset_debug()
          reset debug flag
 void rotate(java.awt.Point anchor, double angle_in_rad)
          rotate: this contains a reference implementation suitable for most object subclasses.
 void scale(java.awt.Point origin, double factor_x, double factor_y)
          scale the object.
 void select()
          method stub for the select() method.
 void set_debug()
          set debug flag
 void setAttributes(FigAttribs attribs)
          set object attributes
 void setComment(java.lang.String s)
          set a comment for this object.
 void setConsole(ConsoleMessage _printer)
           
 void setObjectPainter(ObjectPainter canvas)
          set the ObjectPainter responsible for drawing this FigBaseobject
 void setPoints(java.awt.Point[] wcp)
          set PointList (if any), world-coordinates.
 void setSyncRedrawFlag(boolean b)
          set or reset whether this objects needs a sync redraw
 void setText(java.lang.String s)
          set the object's text: ignored by a baseobject
 void setTrafo(FigTrafo2D trafo)
          set transformation
 void setVisible(boolean v)
          set this Object to be visible or not
 void showPoints()
          method stub for the showPoints() method.
 boolean supportsPointOps()
          this object does not provide useful Point list operations.
 java.lang.String toString()
          debug object information
 void update(FigAttribs parent_attribs)
          method stub for update() method
 void updateAttributes(java.lang.String s)
           
 void writeAsResource(java.io.PrintWriter ps)
          default implementation of 'writeAsResource'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

attribs

protected FigAttribs attribs

trafo

protected FigTrafo2D trafo

x

protected int x

y

protected int y

bbox

protected FigBbox bbox

sc_bbox

protected FigBbox sc_bbox

sc_bbox_timestamp

protected long sc_bbox_timestamp

debug

protected boolean debug

selected

protected boolean selected

showPoints

protected boolean showPoints

syncRedrawFlag

protected boolean syncRedrawFlag

timestamp

protected long timestamp

comment

protected java.lang.String comment

visible

protected boolean visible

painter

public ObjectPainter painter

printer

protected static ConsoleMessage printer
Constructor Detail

FigBaseobject

public FigBaseobject()
Basic FigBaseobject constructor. Defaults are position (0,0), layer 0 and bounding box (0,0,0,0).


FigBaseobject

public FigBaseobject(FigTrafo2D trafo)
Basic FigBaseobject constructor. Defaults are position (0,0), layer 0 and bounding box (0,0,0,0).

Method Detail

initialize

public boolean initialize(java.lang.String s)
a dummy function to initialize a FigObject from a String resource. The method returns true once all required data has been read.

Specified by:
initialize in interface FigObject

setObjectPainter

public void setObjectPainter(ObjectPainter canvas)
set the ObjectPainter responsible for drawing this FigBaseobject

Specified by:
setObjectPainter in interface FigObject

setVisible

public void setVisible(boolean v)
set this Object to be visible or not

Specified by:
setVisible in interface FigObject

isVisible

public boolean isVisible()
check whether this Object is currently visible.

Specified by:
isVisible in interface FigObject

getAttributes

public FigAttribs getAttributes()
get object attributes

Specified by:
getAttributes in interface FigObject

setAttributes

public void setAttributes(FigAttribs attribs)
set object attributes

Specified by:
setAttributes in interface FigObject

updateAttributes

public void updateAttributes(java.lang.String s)
Specified by:
updateAttributes in interface FigObject

setTrafo

public void setTrafo(FigTrafo2D trafo)
set transformation

Specified by:
setTrafo in interface FigObject

getTrafo

public FigTrafo2D getTrafo()
get transformation

Specified by:
getTrafo in interface FigObject

getLayer

public int getLayer()
get layer

Specified by:
getLayer in interface FigObject

getPosition

public java.awt.Point getPosition()
get object (reference point) position

Specified by:
getPosition in interface FigObject

getBbox

public FigBbox getBbox()
get bounding box (in world coordinates)

Specified by:
getBbox in interface FigObject

set_debug

public void set_debug()
set debug flag

Specified by:
set_debug in interface FigObject

reset_debug

public void reset_debug()
reset debug flag

Specified by:
reset_debug in interface FigObject

move

public void move(int dx,
                 int dy)
method stub for the move() method

Specified by:
move in interface FigObject

mirrorX

public void mirrorX(int x,
                    int y)
method stub for the mirrorX() method

Specified by:
mirrorX in interface FigObject

mirrorY

public void mirrorY(int x,
                    int y)
method stub for the mirrorY() method

Specified by:
mirrorY in interface FigObject

scale

public void scale(java.awt.Point origin,
                  double factor_x,
                  double factor_y)
scale the object. We modify all object points corresponding to the given scale factors in x and y directions, with the "origin" point remaining fixed.

We also modify the line width, line dash length, and arrow size corresponding to the factor_x value, unless the SetupManager property "jfig.scaleLineWidth" is "false".

Specified by:
scale in interface FigObject

rotate

public void rotate(java.awt.Point anchor,
                   double angle_in_rad)
            throws java.lang.Exception
rotate: this contains a reference implementation suitable for most object subclasses. We first check whether the object supports rotation by the specified angle via calling canRotate(). If rotation is not supported, we throw an Exception( "rotation not supported" ). Otherwise, we call getPoints(), rotate them, and put them back into the object by calling setPoints().

Specified by:
rotate in interface FigObject
Throws:
java.lang.Exception

canRotate

public boolean canRotate(double angle_in_rad)
Specified by:
canRotate in interface FigObject

update

public void update(FigAttribs parent_attribs)
method stub for update() method

Specified by:
update in interface FigObject
Parameters:
parent_attribs - The current editor FigAttribs object.

rebuild

public void rebuild()
Description copied from interface: FigObject
rebuild (=re-initialize) this object given its current points, attributes, transformation, and the global Java2D enable status. This is a potentially expensive but sometimes necessary operation.

Specified by:
rebuild in interface FigObject

copy

public FigObject copy()
method stub for the copy() method. The copy method clones its object and return the reference to it.

To get the xfig copy behaviour, the editor may combine copy() with a subsequent move().

Specified by:
copy in interface FigObject

isSelected

public boolean isSelected()
Description copied from interface: FigObject
get current selection status

Specified by:
isSelected in interface FigObject

showPoints

public void showPoints()
Description copied from interface: FigObject
method stub for the showPoints() method. The object will paint() its control points (e.g. the bbox for a rectangle, origin and radius for a circle, the control points for a spline). Similar to xfig, these points should be marked with small rectangles. showPoints() is deactivated again by calling deselect().

Specified by:
showPoints in interface FigObject

isShowPoints

public boolean isShowPoints()

select

public void select()
Description copied from interface: FigObject
method stub for the select() method. Similar to xfig, a selected object will paint its control points with small filled rectangles. select() is deactivated again by calling deselect().

Specified by:
select in interface FigObject

deselect

public void deselect()
Description copied from interface: FigObject
mehtod stub for the deselect() mehtod

Specified by:
deselect in interface FigObject

getSyncRedrawFlag

public boolean getSyncRedrawFlag()
is a sync redraw pending on this object?

Specified by:
getSyncRedrawFlag in interface FigDrawable

setSyncRedrawFlag

public void setSyncRedrawFlag(boolean b)
set or reset whether this objects needs a sync redraw

Specified by:
setSyncRedrawFlag in interface FigDrawable

supportsPointOps

public boolean supportsPointOps()
this object does not provide useful Point list operations. A polyline object should implement all of these functions.

Specified by:
supportsPointOps in interface FigObject

numPoints

public int numPoints()
Description copied from interface: FigObject
get number of Points in this object

Specified by:
numPoints in interface FigObject

isClosed

public boolean isClosed()
Description copied from interface: FigObject
return true if this object is 'closed' (polygon vs. polyline, etc)

Specified by:
isClosed in interface FigObject

getPoints

public java.awt.Point[] getPoints()
return a list of all Points of this objects. No Points in a FigBaseobject.

Specified by:
getPoints in interface FigObject

setPoints

public void setPoints(java.awt.Point[] wcp)
Description copied from interface: FigObject
set PointList (if any), world-coordinates. This function should be used by input file parsers to speed up the construction of polylines, polygons, or splines with many points.

Specified by:
setPoints in interface FigObject

clonePoints

public static java.awt.Point[] clonePoints(java.awt.Point[] points)

appendPoint

public void appendPoint(java.awt.Point wp)
append a Point to our Point list. No Points in a FigBaseobject.

Specified by:
appendPoint in interface FigObject

movePoint

public void movePoint(java.awt.Point wp,
                      java.awt.Point wpnew)
move a Point from position wp to new position wpnew

Specified by:
movePoint in interface FigObject

insertPoint

public void insertPoint(java.awt.Point wp,
                        java.awt.Point wprev)
insert a Point wp into our Point list after Point wprev.

Specified by:
insertPoint in interface FigObject

deletePoint

public java.awt.Point deletePoint(java.awt.Point wp)
delete the Point with specified coords from our Point list.

Specified by:
deletePoint in interface FigObject

getNearestPoint

public java.awt.Point getNearestPoint(java.awt.Point wp)
return the point of this object nearest to Point wp, if any.

Specified by:
getNearestPoint in interface FigObject

manhattan

public static int manhattan(java.awt.Point p,
                            java.awt.Point q)

getNeighborPoints

public java.awt.Point[] getNeighborPoints(java.awt.Point wp)
get the two neighbor Points for the specified Point wp from our Point list.

Specified by:
getNeighborPoints in interface FigObject

getMovePointNeighbors

public java.awt.Point[] getMovePointNeighbors(java.awt.Point wp)
Description copied from interface: FigObject
get the neighbor Points for a move point operation

Specified by:
getMovePointNeighbors in interface FigObject

minDistance

public double minDistance(java.awt.Point wp)
return the minimum distance of any points (edges,corners) of this object and the Point wp. Coordinates are world-coordinates, the distance is therefore given as a multiple of 2400 dpi. The default implementation dispatches to FigBbox.minDistanceInside(), which calculates the distance based on a Manhattan geometry and provides reasonable behaviour for rectangle-like objects. This method needs to be overridden for polylines and other objects.

Specified by:
minDistance in interface FigObject

minDistanceEuclid

public double minDistanceEuclid(java.awt.Point wp)
return a high-precision value of the minimum distance between point wp and this object. The trivial default implementation dispatches to minDistance() and needs to be overridden in derived classes.

Specified by:
minDistanceEuclid in interface FigObject

getText

public java.lang.String getText()
get the object's text: no text in a baseobject

Specified by:
getText in interface FigObject

setText

public void setText(java.lang.String s)
set the object's text: ignored by a baseobject

Specified by:
setText in interface FigObject

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
basic reaction to keyDown events: none. Probably needs to be overridden by a text object.

Specified by:
keyPressed in interface FigObject

getTimestamp

public long getTimestamp()
return the timestamp of this object (it's creation/modification time).


build_sc_bbox

public void build_sc_bbox()

get_sc_bbox

public FigBbox get_sc_bbox()
get object bounding box (in screen coordinates at current transformation)

Specified by:
get_sc_bbox in interface FigObject

paint

public void paint(java.awt.Graphics g)
paint() this object. This function currently handles drawing the bounding box corners with emply rectangles for (showPoint) and with filled rectangles for (selected). Subclasses can therefore directly call this method to implement drawing of (showPoints) and (selected) objects.

Specified by:
paint in interface FigObject

paint

public void paint(java.awt.Graphics g,
                  FigTrafo2D trafo)
Description copied from interface: FigDrawable
paint this object using the specified transformation and Graphics g

Specified by:
paint in interface FigObject

paintSave

public void paintSave(java.awt.Graphics g,
                      FigTrafo2D trafo)
Specified by:
paintSave in interface FigObject

isVisible

public boolean isVisible(FigBbox viewport)
check whether this object is visible inside the given viewport (using world coordinates)

Specified by:
isVisible in interface FigObject

message

public void message(java.lang.String msg)

setConsole

public void setConsole(ConsoleMessage _printer)

writeAsResource

public void writeAsResource(java.io.PrintWriter ps)
default implementation of 'writeAsResource'. This will write a nearly xfig-compatible version of all basic FigObjects.

Specified by:
writeAsResource in interface FigObject

getComment

public java.lang.String getComment()
Description copied from interface: FigObject
get the comment for this object (may be null).

Specified by:
getComment in interface FigObject

setComment

public void setComment(java.lang.String s)
Description copied from interface: FigObject
set a comment for this object.

Specified by:
setComment in interface FigObject

toString

public java.lang.String toString()
debug object information

Specified by:
toString in interface FigObject