jfig.objects
Class FigText

java.lang.Object
  extended byjfig.objects.FigBaseobject
      extended byjfig.objects.FigText
All Implemented Interfaces:
FigDrawable, FigObject
Direct Known Subclasses:
Label

public class FigText
extends FigBaseobject

FIG text object with Unicode and restricted math support. Instances of this class are used to represent FIG text objects, each with a single line of text. Attributes include one of the fonts defined in the FIG format, with an optional mapping to different TrueType fonts on your system. The default settings of jfig.gui.FontCache substitute the Postscript fonts with the standard fonts of JDK 1.2+, namely Serif, SansSerif, and Monospaced, which usually map to the Lucida fonts. A text may be left, center, or right aligned, and can be rotated around its base point.

Notes:

Implementation notes: For historical reasons, FigText is derived from FigBaseobject. However, this is currently no longer really useful and should probably be changed to slightly reduce text object overhead. Also, selection of overlapping rotated text objects can be a mess. This should be fixed with a better implementaton if minDistance().


Field Summary
(package private)  java.awt.Polygon border
           
(package private)  java.awt.FontMetrics fm
           
(package private)  FigRenderer renderer
           
(package private)  boolean showCursorFlag
           
(package private)  java.lang.String str
           
(package private)  int textCursorIndex
           
 
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
FigText()
          Basic FigBaseobject constructor.
FigText(java.awt.Point pos, java.lang.String s, FigAttribs attribs, FigTrafo2D trafo)
          Advanced constructor
 
Method Summary
 boolean canRotate(double angle_in_rad)
          xfig allows to rotate text objects to any angle
 FigObject copy()
          build a copy of this FigText object.
 void createRenderer()
           
 java.awt.Point[] getPoints()
          return a list of all Points of this objects.
 java.lang.String getText()
          Get the current text string
 int getTextCursorIndex()
           
 int initializeCursor(int x, int y)
          initialize the current text cursor from the given screen-coordinates.
 boolean isShowCursor()
           
 void keyPressed(java.awt.event.KeyEvent evt)
          handleKeyDown(): move the textCursor, append or insert a character right from the textCursor, delete the character right from the text cursor (or the last character).
 double minDistance_OLD(java.awt.Point wp)
          return the minimum distance of any points (edges,corners) of this object and the Point wp.
 double minDistance(java.awt.Point wp)
          returns the minimum distance of this text object to the target point.
 double minDistanceEuclid(java.awt.Point wp)
          returns the euclidean distance of the target point to this text object.
 void mirrorX(int mirror_x, int mirror_y)
          method stub for the mirrorX() method
 void mirrorY(int mirror_x, int mirror_y)
          mirrorY(): we do not actually put the text upside down, but we do set a new basepoint.
 void move(int dx, int dy)
          the move() method for a FigText
 void moveCursorTo(int index)
          move the (abstract) cursor to position index in our text string.
 void paint(java.awt.Graphics g)
          paint(): draw the String str at position (x,y).
 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 rotate(java.awt.Point anchor, double angle)
          rotate this text.
 void scale(java.awt.Point origin, double factor_x, double factor_y)
          scale this text object.
 void setColor(java.awt.Color c)
           
 void setCursor(int x, int y)
          set the text cursor at the character near the position (x,y) in screen-coordinates.
 void setFont(int fig_font_index)
          set the font for this text objects from the FIG 3.2 font index.
 void setFontSize(int pt)
          set the size (in pt units) for this text object
 void setPoints(java.awt.Point[] pp)
          set PointList (if any), world-coordinates.
 void setText(java.lang.String str)
          Set the text string
 void setTextAlignment(int mode)
          set the text alignment for this text object
 void setTrafo(FigTrafo2D trafo)
          Set a new transformation
 void showCursor(boolean flag)
          showCursor(): activate or hide the textCursor
static java.lang.String symbol_recode(java.lang.String s)
          hack to handle xfig/FIG symbol font: we use Times font, and recode the string to use the Unicode chars corresponding to the necessary greek and math chars...
 java.lang.String toString()
          debug object information
 void update_bbox()
          update the bounding box of this text object including base point, selected font, and rotation.
 void update(FigAttribs new_attribs)
          update(): get the new text attribs and recalculate the bbox.
 
Methods inherited from class jfig.objects.FigBaseobject
appendPoint, build_sc_bbox, clonePoints, deletePoint, deselect, get_sc_bbox, getAttributes, getBbox, getComment, getLayer, getMovePointNeighbors, getNearestPoint, getNeighborPoints, getPosition, getSyncRedrawFlag, getTimestamp, getTrafo, initialize, insertPoint, isClosed, isSelected, isShowPoints, isVisible, isVisible, manhattan, message, movePoint, numPoints, reset_debug, select, set_debug, setAttributes, setComment, setConsole, setObjectPainter, setSyncRedrawFlag, setVisible, showPoints, supportsPointOps, updateAttributes, writeAsResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

textCursorIndex

int textCursorIndex

showCursorFlag

boolean showCursorFlag

str

java.lang.String str

fm

java.awt.FontMetrics fm

renderer

FigRenderer renderer

border

java.awt.Polygon border
Constructor Detail

FigText

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


FigText

public FigText(java.awt.Point pos,
               java.lang.String s,
               FigAttribs attribs,
               FigTrafo2D trafo)
Advanced constructor

Method Detail

createRenderer

public void createRenderer()

isShowCursor

public boolean isShowCursor()

getTextCursorIndex

public int getTextCursorIndex()

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

update_bbox

public void update_bbox()
update the bounding box of this text object including base point, selected font, and rotation.


paint

public void paint(java.awt.Graphics g)
paint(): draw the String str at position (x,y). This method checks whether the editor viewport transformation has changed and recalculates the string screen coords if necessary.

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

showCursor

public void showCursor(boolean flag)
showCursor(): activate or hide the textCursor


setCursor

public void setCursor(int x,
                      int y)
set the text cursor at the character near the position (x,y) in screen-coordinates. We get the right position by converting (x,y) into a radius from the text base point, correct for text alignment and rotation, and then searching through the string.


initializeCursor

public int initializeCursor(int x,
                            int y)
initialize the current text cursor from the given screen-coordinates.


moveCursorTo

public void moveCursorTo(int index)
move the (abstract) cursor to position index in our text string.


move

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

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

copy

public FigObject copy()
build a copy of this FigText object.

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

canRotate

public boolean canRotate(double angle_in_rad)
xfig allows to rotate text objects to any angle

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

rotate

public void rotate(java.awt.Point anchor,
                   double angle)
rotate this text. This actually only requires to update the fig_angle field in our attributes. The angle is measured in radians.

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

scale

public void scale(java.awt.Point origin,
                  double factor_x,
                  double factor_y)
scale this text object. This modifies the base position of this text object. Unless the SetupManager property "jfig.scaleFontsize" is "false", we also scale the font size corresponding to the factor_x value.

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

mirrorX

public void mirrorX(int mirror_x,
                    int mirror_y)
Description copied from class: FigBaseobject
method stub for the mirrorX() method

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

mirrorY

public void mirrorY(int mirror_x,
                    int mirror_y)
mirrorY(): we do not actually put the text upside down, but we do set a new basepoint.

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

update

public void update(FigAttribs new_attribs)
update(): get the new text attribs and recalculate the bbox.

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

minDistance_OLD

public double minDistance_OLD(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.

To allow easy selection of text objects, this method uses the following algorithm. If Point wp is outside of the bounding box of this text object, we return the actual minimum (Manhattan) distance to the text object, see class jfig.objects.FigBbox for details. However, if wp lies inside the text object, we return a value of one grid snap distance, in order not to hide other objects lying under/near the text object.


minDistance

public double minDistance(java.awt.Point wp)
returns the minimum distance of this text object to the target point.

To allow easy selection of text objects, this method uses the following algorithm: If Point wp is the base point (origin) of this text, we return 0. If Point wp lies outside of the (axis-parallel) bounding box of this text object, we return Double.MAX_VALUE. If wp lies inside the bounding box, we use a more elaborate, rotation-aware calculation, and return a value of 0.9*snap, where snap is the current object canvas setting of its magnetic grid. This magical value ensures that the text object can be selected but will not hide other objects with vertices nearer to wp.

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

minDistanceEuclid

public double minDistanceEuclid(java.awt.Point wp)
returns the euclidean distance of the target point to this text object.

However, in the context of jfig it does not really make sense to do the full calculation here. Instead, we simply dispatch to minDistance(wp), whose return value should be ok for most uses.

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

getPoints

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

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

setPoints

public void setPoints(java.awt.Point[] pp)
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
Overrides:
setPoints in class FigBaseobject

getText

public java.lang.String getText()
Get the current text string

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

setText

public void setText(java.lang.String str)
Set the text string

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

setTrafo

public void setTrafo(FigTrafo2D trafo)
Set a new transformation

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

setFont

public void setFont(int fig_font_index)
set the font for this text objects from the FIG 3.2 font index. This method does no range check on the fig_font_index parameter.


setFontSize

public void setFontSize(int pt)
set the size (in pt units) for this text object


setTextAlignment

public void setTextAlignment(int mode)
set the text alignment for this text object

See Also:
for possible values

setColor

public void setColor(java.awt.Color c)

keyPressed

public void keyPressed(java.awt.event.KeyEvent evt)
handleKeyDown(): move the textCursor, append or insert a character right from the textCursor, delete the character right from the text cursor (or the last character).

This method contains a hack to correct a problem with compose characters under Solaris, because Solaris/JDK 1.1.x won't react to the 'COMPOSE' key on the Sun keyboard. Therefore, it will interpret the keys ALT+a, ALT+A, ALT+u, ALT+U, ALT+o, ALT+O, and ALT+s as the corresponding German Umlauts.

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

symbol_recode

public static java.lang.String symbol_recode(java.lang.String s)
hack to handle xfig/FIG symbol font: we use Times font, and recode the string to use the Unicode chars corresponding to the necessary greek and math chars...


toString

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

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