org.tigris.gef.presentation
Class FigText

java.lang.Object
  extended by org.tigris.gef.presentation.Fig
      extended by org.tigris.gef.presentation.FigText
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, PopupGenerator

public class FigText
extends Fig
implements java.awt.event.KeyListener, java.awt.event.MouseListener

This class handles painting and editing text Fig's in a LayerDiagram. Needs-More-Work: should eventually allow styled text editing, ... someday...

See Also:
Serialized Form

Field Summary
static int JUSTIFY_CENTER
           
static int JUSTIFY_LEFT
          Constants to specify text justification.
static int JUSTIFY_RIGHT
           
static int MIN_TEXT_WIDTH
          Minimum size of a FigText object.
 
Fields inherited from class org.tigris.gef.presentation.Fig
_allowsSaving, _context, _dashes, _dashPeriod, _dashStyle, _filled, _h, _w, _x, _y, an, annotationOwner, annotationStatus, BORDER, MIN_SIZE
 
Constructor Summary
FigText(int x, int y, int w, int h)
          Construct a new FigText with the given position and size
FigText(int x, int y, int w, int h, boolean expandOnly)
          Construct a new FigText with the given position, size, and attributes.
FigText(int x, int y, int w, int h, java.awt.Color textColor, java.awt.Font font)
           
FigText(int x, int y, int w, int h, java.awt.Color textColor, java.lang.String familyName, int fontSize)
           
FigText(int x, int y, int w, int h, java.awt.Color textColor, java.lang.String familyName, int fontSize, boolean expandOnly)
          Construct a new FigText with the given position, size, color, string, font, and font size.
 
Method Summary
 void append(char c)
          Append a character to the current String .
 void append(java.lang.String s)
          Append the given String to the current String.
 void calcBounds()
          Compute the overall width and height of the FigText object based on the font, font size, and current text.
 void deleteLastChar()
          Delete the last char from the current string.
 java.lang.String deleteLastCharFromString(java.lang.String s)
          Remove the last char from the current string line and return the new string.
protected  void drawString(java.awt.Graphics graphics, java.lang.String curLine, int xPos, int yPos)
          Draws the given string starting at the given position.
 boolean getAllowsTab()
           
 boolean getBold()
           
 int getBotMargin()
           
 boolean getEditable()
           
 boolean getExpandOnly()
           
 java.awt.Font getFont()
           
 java.lang.String getFontFamily()
          USED BY PGML.tee
 int getFontSize()
          USED BY PGML.tee
 boolean getItalic()
           
 int getJustification()
           
 java.lang.String getJustificationByName()
          Reply a string that indicates how the text is justified: Left, Center, or Right.
 int getLeftMargin()
           
 int getLineSpacing()
           
 int getMinimumHeight()
           
 java.awt.Dimension getMinimumSize()
          Returns the minimum size of the Fig.
 boolean getMultiLine()
           
 int getRightMargin()
           
 java.lang.String getText()
          Get the String held by this FigText.
 int getTextBounds(java.awt.Graphics graphics)
           
 java.awt.Color getTextColor()
           
 java.lang.Class getTextEditorClass()
           
 java.awt.Color getTextFillColor()
           
 boolean getTextFilled()
           
 int getTopMargin()
           
 boolean getUnderline()
           
 boolean hit(java.awt.Rectangle r)
          Muse clicks are handled differentlty that the defi]ault Fig behavior so that it is easier to select text that is not filled.
protected  boolean isStartEditingKey(java.awt.event.KeyEvent ke)
           
 void keyPressed(java.awt.event.KeyEvent ke)
          This method handles backspace and enter.
 void keyReleased(java.awt.event.KeyEvent ke)
          Not used, does nothing.
 void keyTyped(java.awt.event.KeyEvent ke)
          When the user presses a key when a FigText is selected, that key should be added to the current string, or if the key was backspace, the last character is removed.
 void mouseClicked(java.awt.event.MouseEvent me)
           
 void mouseEntered(java.awt.event.MouseEvent me)
           
 void mouseExited(java.awt.event.MouseEvent me)
           
 void mousePressed(java.awt.event.MouseEvent me)
           
 void mouseReleased(java.awt.event.MouseEvent me)
           
 boolean OK()
          Check the class invariant to make sure that this FigText is in a valid state.
 void paint(java.awt.Graphics g)
          Paint the FigText.
 void setAllowsTab(boolean b)
           
 void setBold(boolean b)
           
 void setBotMargin(int m)
           
 void setEditable(boolean e)
           
 void setExpandOnly(boolean b)
           
 void setFont(java.awt.Font f)
           
 void setFontFamily(java.lang.String familyName)
          USED BY PGML.tee
 void setFontSize(int size)
          USED BY PGML.tee
 void setItalic(boolean b)
           
 void setJustification(int align)
           
 void setJustificationByName(java.lang.String justifyString)
          Set the text justification given one of these strings: Left, Center, or Right.
 void setLeftMargin(int m)
           
 void setLineSpacing(int s)
           
 void setMultiLine(boolean b)
           
 void setRightMargin(int m)
           
 void setText(java.lang.String s)
          Sets the given string to the current string of this fig.
 void setText(java.lang.String str, java.awt.Graphics graphics)
          Set the give string to be the current string of this fig.
 void setTextColor(java.awt.Color c)
           
 void setTextEditorClass(java.lang.Class editorClass)
           
 void setTextFillColor(java.awt.Color c)
           
 void setTextFilled(boolean b)
           
 void setTopMargin(int m)
           
 void setUnderline(boolean b)
           
 FigTextEditor startTextEditor(java.awt.event.InputEvent ie)
           
 void stuffMinimumSize(java.awt.Dimension d)
           
 
Methods inherited from class org.tigris.gef.presentation.Fig
addAnnotation, addPoint, addPropertyChangeListener, align, center, classNameAndBounds, cleanUp, clone, connectionPoint, contains, contains, contains, countCornersContained, createDrag, damage, deleteFromModel, drawDashedLine, drawDashedPerimeter, endTrans, firePropChange, firePropChange, firePropChange, getAnnotationOwner, getAnnotationStrategy, getBounds, getBounds, getClosestPoint, getContext, getDashed, getDashed01, getDashedString, getEnclosedFigs, getEnclosingFig, getFillColor, getFilled, getFilled01, getFirstPoint, getGravityPoints, getGroup, getHalfHeight, getHalfWidth, getHandleBox, getHeight, getId, getLastPoint, getLayer, getLineColor, getLineWidth, getLocation, getLocked, getNumPoints, getOwner, getPerimeterLength, getPoint, getPoints, getPopUpActions, getPreferredSize, getPrivateData, getResource, getSingle, getSize, getTipString, getTrapRect, getUseTrapRect, getVisState, getWidth, getX, getXs, getY, getYs, hasFillColor, hasLineColor, initAnnotations, insertPoint, intersects, intersectsPerimeter, isAnnotation, isCopyable, isCutable, isLowerRightResizable, isMovable, isReshapable, isResizable, isRotatable, isSelected, isVisible, makeSelection, pointAlongPerimeter, postLoad, postSave, preSave, print, propertyChange, redraw, removeAnnotation, removeAnnotation, removeFromDiagram, removePoint, removePropertyChangeListener, reorder, routingRect, savingAllowed, setAnnotationOwner, setAnnotationStatus, setAnnotationStrategy, setBounds, setBounds, setCenter, setContext, setDashed, setDashedString, setEnclosingFig, setFillColor, setFilled, setGroup, setHandleBox, setHeight, setLayer, setLineColor, setLineWidth, setLocation, setLocation, setLocked, setMovable, setNumPoints, setOwner, setPoint, setPoint, setPoint, setPoint, setPoints, setPrivateData, setResizable, setResource, setSavingAllowed, setSingle, setSize, setSize, setVisible, setVisState, setWidth, setX, setXs, setY, setYs, stuffBounds, stuffPointAlongPerimeter, translate, translateAnnotations, unsetAnnotationOwner, updateAnnotationPositions, updateVisState, within
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JUSTIFY_LEFT

public static final int JUSTIFY_LEFT
Constants to specify text justification.

See Also:
Constant Field Values

JUSTIFY_RIGHT

public static final int JUSTIFY_RIGHT
See Also:
Constant Field Values

JUSTIFY_CENTER

public static final int JUSTIFY_CENTER
See Also:
Constant Field Values

MIN_TEXT_WIDTH

public static final int MIN_TEXT_WIDTH
Minimum size of a FigText object.

See Also:
Constant Field Values
Constructor Detail

FigText

public FigText(int x,
               int y,
               int w,
               int h,
               java.awt.Color textColor,
               java.lang.String familyName,
               int fontSize,
               boolean expandOnly)
Construct a new FigText with the given position, size, color, string, font, and font size. Text string is initially empty and centered.


FigText

public FigText(int x,
               int y,
               int w,
               int h,
               java.awt.Color textColor,
               java.lang.String familyName,
               int fontSize)

FigText

public FigText(int x,
               int y,
               int w,
               int h,
               java.awt.Color textColor,
               java.awt.Font font)

FigText

public FigText(int x,
               int y,
               int w,
               int h)
Construct a new FigText with the given position and size


FigText

public FigText(int x,
               int y,
               int w,
               int h,
               boolean expandOnly)
Construct a new FigText with the given position, size, and attributes.

Method Detail

OK

public boolean OK()
Check the class invariant to make sure that this FigText is in a valid state. Useful for debugging.

Overrides:
OK in class Fig

getJustificationByName

public java.lang.String getJustificationByName()
Reply a string that indicates how the text is justified: Left, Center, or Right.


setJustificationByName

public void setJustificationByName(java.lang.String justifyString)
Set the text justification given one of these strings: Left, Center, or Right.


getTextColor

public java.awt.Color getTextColor()

setTextColor

public void setTextColor(java.awt.Color c)

getTextFillColor

public java.awt.Color getTextFillColor()

setTextFillColor

public void setTextFillColor(java.awt.Color c)

getTextFilled

public boolean getTextFilled()

setTextFilled

public void setTextFilled(boolean b)

getEditable

public boolean getEditable()

setEditable

public void setEditable(boolean e)

getUnderline

public boolean getUnderline()

setUnderline

public void setUnderline(boolean b)

getJustification

public int getJustification()

setJustification

public void setJustification(int align)

getLineSpacing

public int getLineSpacing()

setLineSpacing

public void setLineSpacing(int s)

getTopMargin

public int getTopMargin()

setTopMargin

public void setTopMargin(int m)

getBotMargin

public int getBotMargin()

setBotMargin

public void setBotMargin(int m)

getLeftMargin

public int getLeftMargin()

setLeftMargin

public void setLeftMargin(int m)

getRightMargin

public int getRightMargin()

setRightMargin

public void setRightMargin(int m)

getExpandOnly

public boolean getExpandOnly()

setExpandOnly

public void setExpandOnly(boolean b)

getFont

public java.awt.Font getFont()

setFont

public void setFont(java.awt.Font f)

getFontFamily

public java.lang.String getFontFamily()
USED BY PGML.tee


setFontFamily

public void setFontFamily(java.lang.String familyName)
USED BY PGML.tee


getFontSize

public int getFontSize()
USED BY PGML.tee


setFontSize

public void setFontSize(int size)
USED BY PGML.tee


getItalic

public boolean getItalic()

setItalic

public void setItalic(boolean b)

getBold

public boolean getBold()

setBold

public void setBold(boolean b)

setMultiLine

public void setMultiLine(boolean b)

getMultiLine

public boolean getMultiLine()

setAllowsTab

public void setAllowsTab(boolean b)

getAllowsTab

public boolean getAllowsTab()

deleteLastCharFromString

public java.lang.String deleteLastCharFromString(java.lang.String s)
Remove the last char from the current string line and return the new string. Called whenever the user hits the backspace key. Needs-More-Work: Very slow. This will eventually be replaced by full text editing... if there are any volunteers to do that...


deleteLastChar

public void deleteLastChar()
Delete the last char from the current string. Called whenever the user hits the backspace key


append

public void append(char c)
Append a character to the current String .


append

public void append(java.lang.String s)
Append the given String to the current String.


setText

public void setText(java.lang.String str,
                    java.awt.Graphics graphics)
Set the give string to be the current string of this fig. Update the current font and font metrics first.

Parameters:
str - String to be set at this object.
graphics - Graphics context for the operation.

setText

public void setText(java.lang.String s)
Sets the given string to the current string of this fig.

Parameters:
s -

getText

public java.lang.String getText()
Get the String held by this FigText. Multi-line text is represented by newline characters embedded in the String. USED BY PGML.tee


getTextEditorClass

public java.lang.Class getTextEditorClass()

setTextEditorClass

public void setTextEditorClass(java.lang.Class editorClass)

paint

public void paint(java.awt.Graphics g)
Paint the FigText. Distingusih between linewidth=1 and >1 If is equal 1, then paint a single rectangle Otherwise paint nested rectangles, whereas every rectangle is painted of 4 connecting lines.

Overrides:
paint in class Fig

drawString

protected void drawString(java.awt.Graphics graphics,
                          java.lang.String curLine,
                          int xPos,
                          int yPos)
Draws the given string starting at the given position. The position indicates the baseline of the text. This method enables subclasses of FigText to either change the displayed text or the starting position.

Parameters:
graphics - Graphic context for drawing the string.
curLine - The current text to be drawn.
xPos - X-Coordinate of the starting point.
yPos - Y-Coordinate of the starting point.

hit

public boolean hit(java.awt.Rectangle r)
Muse clicks are handled differentlty that the defi]ault Fig behavior so that it is easier to select text that is not filled. Needs-More-Work: should actually check the individual text rectangles.

Overrides:
hit in class Fig
Parameters:
r - the rectangular hit area
Returns:
true if the hit rectangle strikes this fig

getMinimumHeight

public int getMinimumHeight()

getTextBounds

public int getTextBounds(java.awt.Graphics graphics)

getMinimumSize

public java.awt.Dimension getMinimumSize()
Description copied from class: Fig
Returns the minimum size of the Fig. This is the smallest size that the user can make this Fig by dragging. You can ignore this and make Figs smaller programmitically if you must.

Overrides:
getMinimumSize in class Fig

stuffMinimumSize

public void stuffMinimumSize(java.awt.Dimension d)

keyTyped

public void keyTyped(java.awt.event.KeyEvent ke)
When the user presses a key when a FigText is selected, that key should be added to the current string, or if the key was backspace, the last character is removed. Needs-More-Work: Should also catch arrow keys and mouse clicks for full text editing... someday...

Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent ke)
This method handles backspace and enter.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent ke)
Not used, does nothing.

Specified by:
keyReleased in interface java.awt.event.KeyListener

isStartEditingKey

protected boolean isStartEditingKey(java.awt.event.KeyEvent ke)

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent me)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent me)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
Specified by:
mouseExited in interface java.awt.event.MouseListener

startTextEditor

public FigTextEditor startTextEditor(java.awt.event.InputEvent ie)

calcBounds

public void calcBounds()
Compute the overall width and height of the FigText object based on the font, font size, and current text. Needs-More-Work: Right now text objects can get larger when you type more, but they do not get smaller when you backspace.

Overrides:
calcBounds in class Fig
See Also:
calcBounds()