jfig.objects
Class FigRectangle

java.lang.Object
  extended byjfig.objects.FigBaseobject
      extended byjfig.objects.FigRectangle
All Implemented Interfaces:
FigDrawable, FigObject
Direct Known Subclasses:
BboxRectangle, FigImage, FsmRenderer, PortSymbol, Rectangle

public class FigRectangle
extends FigBaseobject

FIG rectangle objects, optionally with rounded corners.

A rectangle object for the graphics editor. The reference point is the top left corner.


Field Summary
protected  int pixel_width
           
protected  int radius
           
protected  FigRenderer renderer
           
protected  boolean use_rounded_corners
           
 
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
FigRectangle()
          default constructor: 1inch square below the origin, layer 10
FigRectangle(FigBbox bbox, int layer)
          Basic constructor from bbox object.
FigRectangle(int x1, int y1, int x2, int y2, boolean use_rounded_corners, FigAttribs attribs, FigTrafo2D trafo)
          constructor with full parameter set.
FigRectangle(int x1, int y1, int x2, int y2, int layer)
          Basic rectangle constructor from (x1,y1) to (x2,y2) on (layer).
 
Method Summary
 void appendPoint(java.awt.Point wp)
          No, we cannot append, insert, or delete a Point in a rectangle.
 boolean canRotate(double angle_in_rad)
           
 FigObject copy()
          make a copy of this object and return the reference to the copy.
 void createRenderer()
           
 java.awt.Point deletePoint(java.awt.Point wp)
          delete the Point with specified coords from our Point list.
 java.awt.Point[] getMovePointNeighbors(java.awt.Point wp)
          getMovePointNeighbors( Point wp ): find the nearest Point of the rectangle and return an array with the opposite corner, to allow the main editor correct rubberbanding.
 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()
          getPoints(): get bbox coordinates for this rectangle
 void insertPoint(java.awt.Point wp, java.awt.Point wpnew)
          insert a Point wp into our Point list after Point wprev.
 boolean isClosed()
          return true if this object is 'closed' (polygon vs.
 boolean isRounded()
           
 double minDistance(java.awt.Point wp)
          return distance (currently Manhattan-distance) of the rectangle corners to the reference point wp.
 double minDistanceEuclid(java.awt.Point wp)
          return a distance measure (in world coords units) between point wp and this rectangle which is useful for object selection.
 void mirrorX(int mirror_x, int mirror_y)
          mirrorX(): implemented as a move( dx, 0 ).
 void mirrorY(int mirror_x, int mirror_y)
          mirrorY(): implemented as a move( 0, dy ).
 void move(int dx, int dy)
          move() this rectangle.
 void movePoint(java.awt.Point wp, java.awt.Point wpnew)
          move the Point wp to position wpnew.
 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()
          as we store our coordinates directly as the bounding box coords, we have nothing to do here except to tell our renderer.
 void setAttributes(FigAttribs attribs)
          set new object attributes and regenerate Java2D drawing stuff
 void setFillColor(java.awt.Color c)
          set a new fill color
 void setFillStyle(int shade_or_pattern)
          set the fill style to one of the predefined FIG values, where -1 implies NO_FILL, a value between 0..40 selects the corresponding shade/tint, and values >= 41 select one of the FIG fill patterns.
 void setLayer(int _layer)
          set the layer (depth) for this polyline; the FIG format allows values in the range [1..1000] with 1 being the topmost layer.
 void setLineColor(java.awt.Color c)
          set a new line color
 void setLineStyle(int fig_line_style)
          set the line style to one of the predefined FIG styles, e.g.
 void setLineWidth(int fig_line_width)
          set the line width to one of the predefined FIG widths, e.g.
 void setPoints(java.awt.Point[] wcp)
          setPoints(): Set new bbox coordinates for this rectangle.
 boolean supportsPointOps()
          yes, we support the point operations (actually, only movePoint).
 java.lang.String toString()
          toString() for debug purposes.
 void update(FigAttribs new_attribs)
          update(): Set the new rectangle attributes: lineColor, lineStyle, fillColor, fillStyle, ...
 
Methods inherited from class jfig.objects.FigBaseobject
build_sc_bbox, clonePoints, deselect, get_sc_bbox, getAttributes, getBbox, getComment, getLayer, getPosition, getSyncRedrawFlag, getText, getTimestamp, getTrafo, initialize, isSelected, isShowPoints, isVisible, isVisible, keyPressed, manhattan, message, numPoints, reset_debug, rotate, scale, select, set_debug, setComment, setConsole, setObjectPainter, setSyncRedrawFlag, setText, setTrafo, setVisible, showPoints, updateAttributes, writeAsResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

renderer

protected FigRenderer renderer

use_rounded_corners

protected boolean use_rounded_corners

radius

protected int radius

pixel_width

protected int pixel_width
Constructor Detail

FigRectangle

public FigRectangle()
default constructor: 1inch square below the origin, layer 10


FigRectangle

public FigRectangle(int x1,
                    int y1,
                    int x2,
                    int y2,
                    int layer)
Basic rectangle constructor from (x1,y1) to (x2,y2) on (layer). Color is black, no fill.


FigRectangle

public FigRectangle(FigBbox bbox,
                    int layer)
Basic constructor from bbox object.


FigRectangle

public FigRectangle(int x1,
                    int y1,
                    int x2,
                    int y2,
                    boolean use_rounded_corners,
                    FigAttribs attribs,
                    FigTrafo2D trafo)
constructor with full parameter set.

Method Detail

createRenderer

public void createRenderer()

rebuild

public void rebuild()
as we store our coordinates directly as the bounding box coords, we have nothing to do here except to tell our renderer.

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

setAttributes

public void setAttributes(FigAttribs attribs)
set new object attributes and regenerate Java2D drawing stuff

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

setLayer

public void setLayer(int _layer)
set the layer (depth) for this polyline; the FIG format allows values in the range [1..1000] with 1 being the topmost layer. Note that changing the layer attribute DOES NOT AUTOMATICALLY re-sort the objectlist of the editor/viewer that this object belongs to. Therefore, you might want to do something like this: polyline.setLayer( newLayer ); editor.removeFromObjectList( polyline ); editor.insertIntoObjectList( polyline );


setLineColor

public void setLineColor(java.awt.Color c)
set a new line color


setLineWidth

public void setLineWidth(int fig_line_width)
set the line width to one of the predefined FIG widths, e.g. setLineWidth( FigAttribs.LINE_WIDTH_1 )


setLineStyle

public void setLineStyle(int fig_line_style)
set the line style to one of the predefined FIG styles, e.g. setLineStyle( FigAttribs.DASHED_LINE )


setFillColor

public void setFillColor(java.awt.Color c)
set a new fill color


setFillStyle

public void setFillStyle(int shade_or_pattern)
set the fill style to one of the predefined FIG values, where -1 implies NO_FILL, a value between 0..40 selects the corresponding shade/tint, and values >= 41 select one of the FIG fill patterns.


isRounded

public boolean isRounded()

getPoints

public java.awt.Point[] getPoints()
getPoints(): get bbox coordinates for this rectangle

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

setPoints

public void setPoints(java.awt.Point[] wcp)
setPoints(): Set new bbox coordinates for this rectangle.

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

update

public void update(FigAttribs new_attribs)
update(): Set the new rectangle attributes: lineColor, lineStyle, fillColor, fillStyle, ...

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

copy

public FigObject copy()
make a copy of this object and return the reference to the copy.

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

move

public void move(int dx,
                 int dy)
move() this rectangle.

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

mirrorX

public void mirrorX(int mirror_x,
                    int mirror_y)
mirrorX(): implemented as a move( dx, 0 ).

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

mirrorY

public void mirrorY(int mirror_x,
                    int mirror_y)
mirrorY(): implemented as a move( 0, dy ).

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

canRotate

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

supportsPointOps

public boolean supportsPointOps()
yes, we support the point operations (actually, only movePoint).

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

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
Overrides:
isClosed in class FigBaseobject

appendPoint

public void appendPoint(java.awt.Point wp)
No, we cannot append, insert, or delete a Point in a rectangle. Therefore, these functions just return without doing anything.

(To support these operations, we might convert the FigRectangle automatically into a polygon. But currently I don't want this.)

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

deletePoint

public java.awt.Point deletePoint(java.awt.Point wp)
Description copied from class: FigBaseobject
delete the Point with specified coords from our Point list.

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

insertPoint

public void insertPoint(java.awt.Point wp,
                        java.awt.Point wpnew)
Description copied from class: FigBaseobject
insert a Point wp into our Point list after Point wprev.

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

getMovePointNeighbors

public java.awt.Point[] getMovePointNeighbors(java.awt.Point wp)
getMovePointNeighbors( Point wp ): find the nearest Point of the rectangle and return an array with the opposite corner, to allow the main editor correct rubberbanding.

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

movePoint

public void movePoint(java.awt.Point wp,
                      java.awt.Point wpnew)
move the Point wp to position wpnew. Note that this method will search and move the rectangle corner nearest to wp, independent of the actual distance.

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

getNearestPoint

public java.awt.Point getNearestPoint(java.awt.Point wp)
Description copied from class: FigBaseobject
return the point of this object nearest to Point wp, if any.

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

getNeighborPoints

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

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

minDistance

public double minDistance(java.awt.Point wp)
return distance (currently Manhattan-distance) of the rectangle corners to the reference point wp. A point inside the rectangle may have a large distance from this rectangle.

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

minDistanceEuclid

public double minDistanceEuclid(java.awt.Point wp)
return a distance measure (in world coords units) between point wp and this rectangle 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 the 0.4*snap-grid value from the current object transformation.

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

paint

public void paint(java.awt.Graphics g)
Description copied from class: FigBaseobject
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
Overrides:
paint in class FigBaseobject

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
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

toString

public java.lang.String toString()
toString() for debug purposes.

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