uci.gef
Class FigText

java.lang.Object
  |
  +--uci.gef.Fig
        |
        +--uci.gef.FigText

public class FigText
extends Fig
implements KeyListener, 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
protected  boolean _allowsTab
           
protected  int _botMargin
           
protected  String _curText
          The current string to display.
protected  boolean _editable
          True if the text should be editable.
protected  boolean _expandOnly
          True if the FigText can only grow in size, never shrink.
protected  FontMetrics _fm
           
protected  Font _font
          Font info.
protected  int _justification
          Text justification can be JUSTIFY_LEFT, JUSTIFY_RIGHT, or JUSTIFY_CENTER.
protected  int _leftMargin
           
protected  int _lineHeight
           
protected  int _lineSpacing
          Extra spacing between lines.
protected  boolean _multiLine
          True if more than one line of text is allow.
protected  int _rightMargin
           
protected  Color _textColor
          Color of the actual text characters.
protected  Color _textFillColor
          Color to be drawn behind the actual text characters.
protected  boolean _textFilled
          True if the area behind individual characters is to be filled with TextColor.
protected  int _topMargin
          Internal margins between the text and the edge of the rectangle.
protected  boolean _underline
          True if the text should be underlined.
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 uci.gef.Fig
_dashes, _fillColor, _filled, _group, _h, _layer, _lineColor, _lineWidth, _locked, _w, _x, _y, BORDER, DASH_ARRAYS, DASHED_CHOICES, MIN_SIZE
 
Constructor Summary
FigText(int x, int y, int w, int h)
          Construct a new FigText with the given position, size, and attributes.
FigText(int x, int y, int w, int h, Color textColor, String familyName, int fontSize)
          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(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.
 String deleteLastCharFromString(String s)
          Remove the last char from the current string line and return the new string.
 boolean getAllowsTab()
           
 boolean getBold()
           
 int getBotMargin()
           
 boolean getEditable()
           
 boolean getExpandOnly()
           
 Font getFont()
           
 String getFontFamily()
           
 int getFontSize()
           
 boolean getItalic()
           
 int getJustification()
           
 String getJustificationByName()
          Reply a string that indicates how the text is justified: Left, Center, or Right.
 int getLeftMargin()
           
 int getLineSpacing()
           
 Dimension getMinimumSize()
           
 boolean getMultiLine()
           
 int getRightMargin()
           
 String getText()
          Get the String held by this FigText.
 Color getTextColor()
           
 Color getTextFillColor()
           
 boolean getTextFilled()
           
 int getTopMargin()
           
 boolean getUnderline()
           
 boolean hit(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 isNonStartEditingKey(KeyEvent ke)
           
 void keyPressed(KeyEvent ke)
          This method handles backspace and enter.
 void keyReleased(KeyEvent ke)
          Not used, does nothing.
 void keyTyped(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(MouseEvent me)
           
 void mouseEntered(MouseEvent me)
           
 void mouseExited(MouseEvent me)
           
 void mousePressed(MouseEvent me)
           
 void mouseReleased(MouseEvent me)
           
 boolean OK()
          Check the class invariant to make sure that this FigText is in a valid state.
 void paint(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(Font f)
           
 void setFontFamily(String familyName)
           
 void setFontSize(int size)
           
 void setItalic(boolean b)
           
 void setJustifciaionByName(String justifyString)
          Set the text justification given one of these strings: Left, Center, or Right.
 void setJustification(int align)
           
 void setLeftMargin(int m)
           
 void setLineSpacing(int s)
           
 void setMultiLine(boolean b)
           
 void setRightMargin(int m)
           
 void setText(String s)
          set the current String to be the given String.
 void setTextColor(Color c)
           
 void setTextFillColor(Color c)
           
 void setTextFilled(boolean b)
           
 void setTopMargin(int m)
           
 void setUnderline(boolean b)
           
 FigTextEditor startTextEditor(InputEvent ie)
           
 void stuffMinimumSize(Dimension d)
           
 
Methods inherited from class uci.gef.Fig
addPoint, addPropertyChangeListener, align, center, classNameAndBounds, cleanUp, clone, connectionPoint, contains, contains, contains, countCornersContained, createDrag, damage, delete, dispose, drawDashedLine, drawDashedPerimeter, endTrans, firePropChange, firePropChange, firePropChange, getBounds, getClosestPoint, getDashed, getDashed01, getDashedString, getEnclosedFigs, getEnclosingFig, getFillColor, getFilled, getFilled01, getFirstPoint, getGravityPoints, getGroup, getHalfHeight, getHalfWidth, getHeight, getId, getLastPoint, getLayer, getLineColor, getLineWidth, getLocation, getLocked, getNumPoints, getOwner, getPerimeterLength, getPoints, getPoints, getPopUpActions, getPreferedSize, getSize, getTipString, getTrapRect, getUseTrapRect, getWidth, getX, getXs, getY, getYs, insertPoint, intersects, isLowerRightResizable, isMovable, isReshapable, isResizable, isRotatable, makeSelection, pointAlongPerimeter, postLoad, postSave, preSave, print, propertyChange, removePoint, removePropertyChangeListener, reorder, routingRect, setBounds, setBounds, setDashed, setDashedString, setEnclosingFig, setFillColor, setFilled, setGroup, setHeight, setLayer, setLineColor, setLineWidth, setLocation, setLocation, setLocked, setNumPoints, setOwner, setPoints, setPoints, setPoints, setPoints, setPoints, setSize, setSize, setWidth, setX, setXs, setY, setYs, startTrans, stuffBounds, stuffPointAlongPerimeter, translate, 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.

JUSTIFY_RIGHT

public static final int JUSTIFY_RIGHT

JUSTIFY_CENTER

public static final int JUSTIFY_CENTER

MIN_TEXT_WIDTH

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

_font

protected Font _font
Font info.

_fm

protected transient FontMetrics _fm

_lineHeight

protected int _lineHeight

_textColor

protected Color _textColor
Color of the actual text characters.

_textFillColor

protected Color _textFillColor
Color to be drawn behind the actual text characters. Note that this will be a smaller area than the bounding box which is filled with FillColor.

_textFilled

protected boolean _textFilled
True if the area behind individual characters is to be filled with TextColor.

_editable

protected boolean _editable
True if the text should be editable. False for read-only.

_underline

protected boolean _underline
True if the text should be underlined. needs-more-work.

_multiLine

protected boolean _multiLine
True if more than one line of text is allow. If false, newline characters will be ignored. True by default.

_allowsTab

protected boolean _allowsTab

_lineSpacing

protected int _lineSpacing
Extra spacing between lines. Default is 0 pixels.

_topMargin

protected int _topMargin
Internal margins between the text and the edge of the rectangle.

_botMargin

protected int _botMargin

_leftMargin

protected int _leftMargin

_rightMargin

protected int _rightMargin

_expandOnly

protected boolean _expandOnly
True if the FigText can only grow in size, never shrink.

_justification

protected int _justification
Text justification can be JUSTIFY_LEFT, JUSTIFY_RIGHT, or JUSTIFY_CENTER.

_curText

protected String _curText
The current string to display.
Constructor Detail

FigText

public FigText(int x,
               int y,
               int w,
               int h,
               Color textColor,
               String familyName,
               int fontSize)
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)
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 String getJustificationByName()
Reply a string that indicates how the text is justified: Left, Center, or Right.

setJustifciaionByName

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

getTextColor

public Color getTextColor()

setTextColor

public void setTextColor(Color c)

getTextFillColor

public Color getTextFillColor()

setTextFillColor

public void setTextFillColor(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 Font getFont()

setFont

public void setFont(Font f)

getFontFamily

public String getFontFamily()

setFontFamily

public void setFontFamily(String familyName)

getFontSize

public int getFontSize()

setFontSize

public void setFontSize(int size)

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 String deleteLastCharFromString(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(String s)
Append the given String to the current String.

setText

public void setText(String s)
set the current String to be the given String.

getText

public String getText()
Get the String held by this FigText. Multi-line text is represented by newline characters embedded in the String.

paint

public void paint(Graphics g)
Paint the FigText.
Overrides:
paint in class Fig

hit

public boolean hit(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

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class Fig

stuffMinimumSize

public void stuffMinimumSize(Dimension d)

keyTyped

public void keyTyped(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 KeyListener

keyPressed

public void keyPressed(KeyEvent ke)
This method handles backspace and enter.
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent ke)
Not used, does nothing.
Specified by:
keyReleased in interface KeyListener

isNonStartEditingKey

protected boolean isNonStartEditingKey(KeyEvent ke)

mouseClicked

public void mouseClicked(MouseEvent me)
Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent me)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent me)
Specified by:
mouseReleased in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent me)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent me)
Specified by:
mouseExited in interface MouseListener

startTextEditor

public FigTextEditor startTextEditor(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