jfig.objects
Class FigCompound

java.lang.Object
  extended byjfig.objects.FigBaseobject
      extended byjfig.objects.FigCompound
All Implemented Interfaces:
FigDrawable, FigObject
Direct Known Subclasses:
FigWrapper, HorizontalBarGraph, ProbeSymbol, Symbol

public class FigCompound
extends FigBaseobject

FIG compound (group) object.

The graphics editor 'compound' object, kind of a group object. A compound object contains references to other objects, it's members. Typical editor manipulations like move() are passed to all the compound's members in turn.

To break a compound, the editor should call getMembers() to retrieve the array with the compound object's member objects, insert these objects into its own (the editors) object-list, and finally delete the compound. There is no obvious way to do this with a member function of FigCompound, unless we make all data structures of the editor transparent (but we won't want this).


Field Summary
(package private)  FigObjectList members
           
 
Fields inherited from class jfig.objects.FigBaseobject
attribs, bbox, comment, debug, painter, printer, sc_bbox, sc_bbox_timestamp, selected, showPoints, syncRedrawFlag, timestamp, trafo, visible, x, y
 
Constructor Summary
FigCompound()
          Basic FigCompound constructor.
 
Method Summary
 void addMember(FigObject obj)
          add an object to this compound.
 boolean canRotate(double angle_in_rad)
           
 void changeLayerRecursively(FigAttribs new_attribs)
           
 FigObject copy()
          The copy() method for a compound object.
 boolean deleteAllMembers()
           
 boolean deleteMember(FigObject obj)
          Try to delete an object from this compound.
 void fastAddMember(FigObject obj)
          add an object to this compound, but don't update the bounding box.
 FigObjectList getMembers()
          return the list with all member objects of this compound.
 boolean isMember(FigObject testobj)
          check whether the given object is a member of this compound.
 double minDistanceEuclid(java.awt.Point wp)
          return a distance measure (in world coords units) between point wp and this compound which is useful for object selection.
 void mirrorX(int mirror_x, int mirror_y)
          mirrorX: we just call mirrorX() for each object in this compound and finally update our bounding-box.
 void mirrorY(int mirror_x, int mirror_y)
          mirrorY: we just call mirrorY() for each object in this compound and finally update our bounding-box.
 void move(int dx, int dy)
          The move() method calls the move() method for each member.
 void paint(java.awt.Graphics g)
          paint(): Again, we just call paint() for each member of this component.
 void paint(java.awt.Graphics g, FigBbox bbox)
          paint( Graphics g, FigBbox bbox ): Check all members of this compound whether they are visible or not.
 void paintInverse(java.awt.Graphics g)
           
 void paintSave(java.awt.Graphics g, FigTrafo2D trafo)
           
 void rebuild()
          rebuild this compound: call rebuild() recursively on all member objects
 void rotate(java.awt.Point anchor, double angle_in_rad)
          rotate this compound: we simple call rotate to all compound member objects in turn, and finally update the compound bbox data.
 void scale(java.awt.Point origin, double factor_x, double factor_y)
          scale(): scale all our members in turn, the recalculate the bounding box
 void setObjectPainter(ObjectPainter painter)
          set a new ObjectPainter for all objects in this compound
 void setTrafo(FigTrafo2D trafo)
          set a new transformation for this compound.
 void setVisible(boolean visible)
          set the visible attribute for all members of this FigCompound
 java.lang.String toString()
          debug object information
 void update_bbox()
          calculate a new bounding box for this compound object.
 void update(FigAttribs parent_attribs)
          update(): Call update() for all members of this compound and update its layer.
 
Methods inherited from class jfig.objects.FigBaseobject
appendPoint, build_sc_bbox, clonePoints, deletePoint, deselect, get_sc_bbox, getAttributes, getBbox, getComment, getLayer, getMovePointNeighbors, getNearestPoint, getNeighborPoints, getPoints, getPosition, getSyncRedrawFlag, getText, getTimestamp, getTrafo, initialize, insertPoint, isClosed, isSelected, isShowPoints, isVisible, isVisible, keyPressed, manhattan, message, minDistance, movePoint, numPoints, paint, reset_debug, select, set_debug, setAttributes, setComment, setConsole, setPoints, setSyncRedrawFlag, setText, showPoints, supportsPointOps, updateAttributes, writeAsResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

members

FigObjectList members
Constructor Detail

FigCompound

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

Method Detail

addMember

public void addMember(FigObject obj)
add an object to this compound. To get the redrawing right, the new member is inserted at the position in the members list corresponding to its layer. Deeper layers (999) are drawn first, layer (0) is drawn last.

The editor that calls addMember(obj) should probably delete obj from its own objectList.

Parameters:
obj - The editor object to add to this compound.

fastAddMember

public void fastAddMember(FigObject obj)
add an object to this compound, but don't update the bounding box. This function is provided to allow for faster FIG 3.1 file parsing.


deleteMember

public boolean deleteMember(FigObject obj)
Try to delete an object from this compound. Return true if the object was on the members list and could be deleted, return false if the object was not on the members list.


deleteAllMembers

public boolean deleteAllMembers()

isMember

public boolean isMember(FigObject testobj)
check whether the given object is a member of this compound.


update_bbox

public void update_bbox()
calculate a new bounding box for this compound object. It suffices to calculate the union of the bounding boxes of all member objects.

This method is public to allow the FIG3.1 parser efficient parsing of (possibly nested) compound objects.

See Also:
FigParser

getMembers

public FigObjectList getMembers()
return the list with all member objects of this compound.


move

public void move(int dx,
                 int dy)
The move() method calls the move() method for each member.

Specified by:
move in interface FigObject
Overrides:
move in class FigBaseobject

mirrorX

public void mirrorX(int mirror_x,
                    int mirror_y)
mirrorX: we just call mirrorX() for each object in this compound and finally update our bounding-box.

Specified by:
mirrorX in interface FigObject
Overrides:
mirrorX in class FigBaseobject

mirrorY

public void mirrorY(int mirror_x,
                    int mirror_y)
mirrorY: we just call mirrorY() for each object in this compound and finally update our bounding-box.

Specified by:
mirrorY in interface FigObject
Overrides:
mirrorY in class FigBaseobject

scale

public void scale(java.awt.Point origin,
                  double factor_x,
                  double factor_y)
scale(): scale all our members in turn, the recalculate the bounding box

Specified by:
scale in interface FigObject
Overrides:
scale in class FigBaseobject

update

public void update(FigAttribs parent_attribs)
update(): Call update() for all members of this compound and update its layer. Note that we don't have to check the layers of the member objects: either no layers are changed, or all members will have the same drawing layer after the update()...

Specified by:
update in interface FigObject
Overrides:
update in class FigBaseobject

rebuild

public void rebuild()
rebuild this compound: call rebuild() recursively on all member objects

Specified by:
rebuild in interface FigObject
Overrides:
rebuild in class FigBaseobject

changeLayerRecursively

public void changeLayerRecursively(FigAttribs new_attribs)

copy

public FigObject copy()
The copy() method for a compound object. We first create a new compound object. Then we create copies of all members of this compound and add them to the new one. Finally we return the new compound.

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

Specified by:
copy in interface FigObject
Overrides:
copy in class FigBaseobject

setTrafo

public void setTrafo(FigTrafo2D trafo)
set a new transformation for this compound. Note that we also need to recursively set the new transformation for all objects in this compound.

Specified by:
setTrafo in interface FigObject
Overrides:
setTrafo in class FigBaseobject

setVisible

public void setVisible(boolean visible)
set the visible attribute for all members of this FigCompound

Specified by:
setVisible in interface FigObject
Overrides:
setVisible in class FigBaseobject

setObjectPainter

public void setObjectPainter(ObjectPainter painter)
set a new ObjectPainter for all objects in this compound

Specified by:
setObjectPainter in interface FigObject
Overrides:
setObjectPainter in class FigBaseobject

paint

public void paint(java.awt.Graphics g)
paint(): Again, we just call paint() for each member of this component.

Note that this method() may be very inefficient, because all members of the component are paint()ed, whether they are visible or not. Typically you should call the improved variant paint( Graphics, FigBbox bbox ) below.

Specified by:
paint in interface FigObject
Overrides:
paint in class FigBaseobject

paintSave

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

paintInverse

public void paintInverse(java.awt.Graphics g)

canRotate

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

rotate

public void rotate(java.awt.Point anchor,
                   double angle_in_rad)
            throws java.lang.Exception
rotate this compound: we simple call rotate to all compound member objects in turn, and finally update the compound bbox data.

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

paint

public void paint(java.awt.Graphics g,
                  FigBbox bbox)
paint( Graphics g, FigBbox bbox ): Check all members of this compound whether they are visible or not. If yes, paint() the member. The simple checks whether the objects are visible and the check for nested compounds are much faster than the unnecessary construction and transformation of all objects.


minDistanceEuclid

public double minDistanceEuclid(java.awt.Point wp)
return a distance measure (in world coords units) between point wp and this compound which is useful for object selection. On the outside of this rectangle, we just use the manhattan distance to the nearest corner. However, when wp lies inside the rectangle, this is not what the user expects. Therefore, we return the minimum value of the manhattan corner distance and 0.4 snap-grid value from the current object transformation.

Specified by:
minDistanceEuclid in interface FigObject
Overrides:
minDistanceEuclid in class FigBaseobject

toString

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

Specified by:
toString in interface FigObject
Overrides:
toString in class FigBaseobject