Back to index

moin  1.9.0~rc2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
CH.ifa.draw.figures.TextFigure Class Reference

A text figure. More...

Inheritance diagram for CH.ifa.draw.figures.TextFigure:
Inheritance graph
[legend]
Collaboration diagram for CH.ifa.draw.figures.TextFigure:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TextFigure ()
void moveBy (int x, int y)
void basicDisplayBox (Point newOrigin, Point newCorner)
Rectangle displayBox ()
Rectangle textDisplayBox ()
boolean readOnly ()
 Tests whether this figure is read only.
void setReadOnly (boolean isReadOnly)
 Sets the read only status of the text figure.
Font getFont ()
 Gets the font.
void setFont (Font newFont)
 Sets the font.
void changed ()
 Updates the location whenever the figure changes itself.
Object getAttribute (String name)
 A text figure understands the "FontSize", "FontStyle", "FontName" and "TextAlign" attributes.
void setAttribute (String name, Object value)
 A text figure understands the "FontSize", "FontStyle", "FontName" and "Align" attributes.
String getText ()
 Gets the text shown by the text figure.
void setText (String newText)
 Sets the text shown by the text figure.
boolean acceptsTyping ()
 Tests whether the figure accepts typing.
void drawBackground (Graphics g)
 Draws the background of the figure.
void drawFrame (Graphics g)
 Draws the frame of the figure.
int overlayColumns ()
 Gets the number of columns to be overlaid when the figure is edited.
int overlayRows ()
 Gets the number of rows to be overlaid when the figure is edited.
Vector handles ()
void write (StorableOutput dw)
void read (StorableInput dr) throws IOException
void connect (Figure figure)
void figureChanged (FigureChangeEvent e)
void figureRemoved (FigureChangeEvent e)
void figureRequestRemove (FigureChangeEvent e)
void figureInvalidated (FigureChangeEvent e)
void figureRequestUpdate (FigureChangeEvent e)
void release ()
void disconnect ()
 Disconnects the text figure.
void draw (Graphics g, boolean showGuides)
 Draws the figure in the given graphics.
Color getFillColor ()
 Gets the fill color of a figure.
Color getFrameColor ()
 Gets the frame color of a figure.
Object defaultAttribute (String name)
String getMap ()

Static Public Member Functions

static Font createCurrentFont ()
 Creates the current font to be used for new text figures.
static void setCurrentFontName (String name)
 Sets the current font name.
static void setCurrentFontSize (int size)
 Sets the current font size.
static void setCurrentFontStyle (int style)
 Sets the current font style.
static Object getDefaultAttribute (String name)
 Gets a the default value for a named attribute.

Protected Member Functions

void basicMoveBy (int x, int y)
void updateLocation ()
 Updates the location relative to the connected figure.

Private Member Functions

Dimension textExtent ()
void markDirty ()
Dimension getRowsAndColumns (String text)
void readObject (ObjectInputStream s) throws ClassNotFoundException, IOException

Private Attributes

int fOriginX
int fOriginY
transient boolean fSizeIsDirty = true
transient int fWidth
transient int fHeight
String fText
Font fFont
boolean fIsReadOnly
int fAlign
Figure fObservedFigure = null
OffsetLocator fLocator = null
int textFigureSerializedDataVersion = 1

Static Private Attributes

static final int TEXTALIGN_LEFT = 0
static final int TEXTALIGN_CENTRE = 1
static final int TEXTALIGN_RIGHT = 2
static String fgCurrentFontName = "Helvetica"
static int fgCurrentFontSize = 12
static int fgCurrentFontStyle = Font.PLAIN
static final long serialVersionUID = 4599820785949456124L

Detailed Description

A text figure.

See also:
TextTool

Definition at line 20 of file TextFigure.java.


Constructor & Destructor Documentation

Definition at line 54 of file TextFigure.java.

                        {
        fOriginX = 0;
        fOriginY = 0;
        fFont = createCurrentFont();
        setAttribute("FillColor", ColorMap.getColorMap().color("None"));
       fAlign = TEXTALIGN_LEFT;
        fText = new String("");
        fSizeIsDirty = true;
    }

Here is the call graph for this function:


Member Function Documentation

Tests whether the figure accepts typing.

Definition at line 211 of file TextFigure.java.

                                   {
        return !fIsReadOnly;
    }
void CH.ifa.draw.figures.TextFigure.basicDisplayBox ( Point  newOrigin,
Point  newCorner 
) [inline]

Definition at line 77 of file TextFigure.java.

                                                                  {
        fOriginX = newOrigin.x;
        fOriginY = newOrigin.y;
    }
void CH.ifa.draw.figures.TextFigure.basicMoveBy ( int  x,
int  y 
) [inline, protected]

Definition at line 72 of file TextFigure.java.

                                             {
        fOriginX += x;
        fOriginY += y;
    }

Here is the caller graph for this function:

Updates the location whenever the figure changes itself.

Definition at line 125 of file TextFigure.java.

                          {
        super.changed();
        updateLocation();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.figures.TextFigure.connect ( Figure  figure) [inline]

Definition at line 343 of file TextFigure.java.

                                       {
        if (fObservedFigure != null)
            fObservedFigure.removeFigureChangeListener(this);

        fObservedFigure = figure;
        fLocator = new OffsetLocator(figure.connectedTextLocator(this));
        fObservedFigure.addFigureChangeListener(this);
        setAttribute("observed.figure", fObservedFigure);
        updateLocation();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static Font CH.ifa.draw.figures.TextFigure.createCurrentFont ( ) [inline, static]

Creates the current font to be used for new text figures.

Definition at line 405 of file TextFigure.java.

Here is the caller graph for this function:

Object CH.ifa.draw.figures.AttributeFigure.defaultAttribute ( String  name) [inline, inherited]

Definition at line 135 of file AttributeFigure.java.

                                                {
       return getDefaultAttribute(name);
    }

Here is the call graph for this function:

Disconnects the text figure.

Definition at line 394 of file TextFigure.java.

                             {
        fObservedFigure.removeFigureChangeListener(this);
        fObservedFigure = null;
        fLocator = null;
        setAttribute("observed.figure", null);
    }

Here is the call graph for this function:

Definition at line 82 of file TextFigure.java.

                                  {
        Dimension extent = textExtent();
        return new Rectangle(fOriginX, fOriginY, extent.width, extent.height);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.figures.AttributeFigure.draw ( Graphics  g,
boolean  showGuides 
) [inline, inherited]

Draws the figure in the given graphics.

Draw is a template method calling drawBackground followed by drawFrame.

Definition at line 48 of file AttributeFigure.java.

                                                     {
        Color fill = getFillColor();
        if (!ColorMap.getColorMap().isTransparent(fill)) {
            g.setColor(fill);
            drawBackground(g);
        }
        Color frame = getFrameColor();
        if (!ColorMap.getColorMap().isTransparent(frame)) {
            g.setColor(frame);
            drawFrame(g);
        }
       if (showGuides) {
           drawURL(g);
       }
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.TextFigure.drawBackground ( Graphics  g) [inline]

Draws the background of the figure.

See also:
draw

Reimplemented from CH.ifa.draw.figures.AttributeFigure.

Definition at line 215 of file TextFigure.java.

                                           {
        Rectangle r = displayBox();
        g.fillRect(r.x, r.y, r.width, r.height);
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.TextFigure.drawFrame ( Graphics  g) [inline]

Draws the frame of the figure.

See also:
draw

Reimplemented from CH.ifa.draw.figures.AttributeFigure.

Definition at line 220 of file TextFigure.java.

                                      {
        g.setFont(fFont);
        g.setColor((Color) getAttribute("TextColor"));
        FontMetrics metrics = g.getFontMetrics(fFont);
       StringTokenizer st = new StringTokenizer(fText, "\n");
       Dimension d = textExtent();
       
       int orgy = fOriginY;
       while (st.hasMoreTokens()) {
           String t = st.nextToken();
           int xpos = fOriginX;
           if (fAlign == TEXTALIGN_RIGHT) {
              xpos += d.width - metrics.stringWidth(t);
           } else if (fAlign == TEXTALIGN_CENTRE) {
              xpos += (d.width - metrics.stringWidth(t)) / 2;
           }
           g.drawString(t, xpos, orgy + metrics.getAscent());
           orgy += metrics.getHeight();
       }
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.TextFigure.figureChanged ( FigureChangeEvent  e) [inline]

Definition at line 354 of file TextFigure.java.

Here is the call graph for this function:

void CH.ifa.draw.figures.TextFigure.figureInvalidated ( FigureChangeEvent  e) [inline]

Definition at line 364 of file TextFigure.java.

{}
void CH.ifa.draw.figures.TextFigure.figureRemoved ( FigureChangeEvent  e) [inline]

Definition at line 358 of file TextFigure.java.

                                                   {
        if (listener() != null)
            listener().figureRequestRemove(new FigureChangeEvent(this));
    }
void CH.ifa.draw.figures.TextFigure.figureRequestRemove ( FigureChangeEvent  e) [inline]

Definition at line 363 of file TextFigure.java.

{}
void CH.ifa.draw.figures.TextFigure.figureRequestUpdate ( FigureChangeEvent  e) [inline]

Definition at line 365 of file TextFigure.java.

{}
Object CH.ifa.draw.figures.TextFigure.getAttribute ( String  name) [inline]

A text figure understands the "FontSize", "FontStyle", "FontName" and "TextAlign" attributes.

Definition at line 134 of file TextFigure.java.

                                            {
        Font font = getFont();
        if (name.equals("FontSize"))
            return new Integer(font.getSize());
        if (name.equals("FontStyle"))
            return new Integer(font.getStyle());
        if (name.equals("FontName"))
            return font.getName();
       if (name.equals("TextAlign")) {
           switch (fAlign) {
           default: return "Left";
           case TEXTALIGN_CENTRE: return "Centre";
           case TEXTALIGN_RIGHT: return "Right";
           }
       }
        return super.getAttribute(name);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static Object CH.ifa.draw.figures.AttributeFigure.getDefaultAttribute ( String  name) [inline, static, inherited]

Gets a the default value for a named attribute.

See also:
getAttribute

Definition at line 129 of file AttributeFigure.java.

                                                          {
        if (fgDefaultAttributes == null)
            initializeAttributes();
        return fgDefaultAttributes.get(name);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Color CH.ifa.draw.figures.AttributeFigure.getFillColor ( ) [inline, inherited]

Gets the fill color of a figure.

This is a convenience method.

See also:
getAttribute

Definition at line 97 of file AttributeFigure.java.

                                {
        return (Color) getAttribute("FillColor");
    }

Here is the caller graph for this function:

Gets the font.

Definition at line 108 of file TextFigure.java.

                          {
        return fFont;
    }

Here is the caller graph for this function:

Gets the frame color of a figure.

This is a convenience method.

See also:
getAttribute

Definition at line 106 of file AttributeFigure.java.

                                 {
        return (Color) getAttribute("FrameColor");
    }

Here is the caller graph for this function:

String CH.ifa.draw.figures.AttributeFigure.getMap ( ) [inline, inherited]
Dimension CH.ifa.draw.figures.TextFigure.getRowsAndColumns ( String  text) [inline, private]

Definition at line 265 of file TextFigure.java.

                                                     {
       int rows = 0;
       int cols = 0;
       StringTokenizer st = new StringTokenizer(fText, "\n");
       while (st.hasMoreTokens()) {
           String t = st.nextToken();
           if (t.length() > cols)
              cols = t.length();
           rows++;
       }
       return new Dimension(cols, rows);
    }

Here is the caller graph for this function:

Gets the text shown by the text figure.

Definition at line 192 of file TextFigure.java.

                            {
        return fText;
    }

Here is the caller graph for this function:

Definition at line 294 of file TextFigure.java.

                            {
        Vector handles = new Vector();
        handles.addElement(new NullHandle(this, RelativeLocator.northWest()));
        handles.addElement(new NullHandle(this, RelativeLocator.northEast()));
        handles.addElement(new NullHandle(this, RelativeLocator.southEast()));
        handles.addElement(new FontSizeHandle(this, RelativeLocator.southWest()));
        return handles;
    }
void CH.ifa.draw.figures.TextFigure.markDirty ( ) [inline, private]

Definition at line 261 of file TextFigure.java.

                             {
        fSizeIsDirty = true;
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.TextFigure.moveBy ( int  x,
int  y 
) [inline]

Definition at line 64 of file TextFigure.java.

                                     {
        willChange();
        basicMoveBy(x, y);
        if (fLocator != null)
            fLocator.moveBy(x, y);
        changed();
    }

Here is the call graph for this function:

Gets the number of columns to be overlaid when the figure is edited.

Reimplemented in CH.ifa.draw.figures.NumberTextFigure.

Definition at line 281 of file TextFigure.java.

                                {
       Dimension d = getRowsAndColumns(getText());
        return d.width < 20 ? 20 : d.width;
    }

Here is the call graph for this function:

Gets the number of rows to be overlaid when the figure is edited.

Reimplemented in CH.ifa.draw.figures.NumberTextFigure.

Definition at line 289 of file TextFigure.java.

                             {
       Dimension d = getRowsAndColumns(getText());
        return d.height < 5 ? 5 : d.height;
    }

Here is the call graph for this function:

void CH.ifa.draw.figures.TextFigure.read ( StorableInput  dr) throws IOException [inline]

Definition at line 316 of file TextFigure.java.

                                                          {
        super.read(dr);
        markDirty();
        fOriginX = dr.readInt();
        fOriginY = dr.readInt();
        fText = dr.readString();
        fFont = new Font(dr.readString(), dr.readInt(), dr.readInt());
        fIsReadOnly = dr.readBoolean();

        fObservedFigure = (Figure)dr.readStorable();
        if (fObservedFigure != null) {
            setAttribute("observed.figure", fObservedFigure);
            fObservedFigure.addFigureChangeListener(this);
        }
        fLocator = (OffsetLocator)dr.readStorable();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.figures.TextFigure.readObject ( ObjectInputStream  s) throws ClassNotFoundException, IOException [inline, private]

Definition at line 333 of file TextFigure.java.

                                                   {

        s.defaultReadObject();

        if (fObservedFigure != null)
            fObservedFigure.addFigureChangeListener(this);
        markDirty();
    }

Here is the call graph for this function:

Tests whether this figure is read only.

Definition at line 94 of file TextFigure.java.

                              {
        return fIsReadOnly;
    }

Definition at line 385 of file TextFigure.java.

                          {
        super.release();
        if (fObservedFigure != null)
            fObservedFigure.removeFigureChangeListener(this);
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.TextFigure.setAttribute ( String  name,
Object  value 
) [inline]

A text figure understands the "FontSize", "FontStyle", "FontName" and "Align" attributes.

Definition at line 156 of file TextFigure.java.

                                                        {
        Font font = getFont();
        if (name.equals("FontSize")) {
            Integer s = (Integer)value;
            setFont(new Font(font.getName(), font.getStyle(), s.intValue()) );
        }
        else if (name.equals("FontStyle")) {
            Integer s = (Integer)value;
            int style = font.getStyle();
            if (s.intValue() == Font.PLAIN)
                style = font.PLAIN;
            else
                style = style ^ s.intValue();
            setFont(new Font(font.getName(), style, font.getSize()) );
        }
        else if (name.equals("FontName")) {
            String n = (String)value;
            setFont(new Font(n, font.getStyle(), font.getSize()) );
        }
       else if (name.equals("TextAlign")) {
            String n = (String)value;
           if (n.equals("Centre"))
              fAlign = TEXTALIGN_CENTRE;
           else if (n.equals("Right"))
              fAlign = TEXTALIGN_RIGHT;
           else
              fAlign = TEXTALIGN_LEFT;
            changed();
       }
        else
            super.setAttribute(name, value);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static void CH.ifa.draw.figures.TextFigure.setCurrentFontName ( String  name) [inline, static]

Sets the current font name.

Definition at line 412 of file TextFigure.java.

                                                       {
        fgCurrentFontName = name;
    }
static void CH.ifa.draw.figures.TextFigure.setCurrentFontSize ( int  size) [inline, static]

Sets the current font size.

Definition at line 419 of file TextFigure.java.

Here is the call graph for this function:

static void CH.ifa.draw.figures.TextFigure.setCurrentFontStyle ( int  style) [inline, static]

Sets the current font style.

Definition at line 426 of file TextFigure.java.

                                                      {
        fgCurrentFontStyle = style;
    }
void CH.ifa.draw.figures.TextFigure.setFont ( Font  newFont) [inline]

Sets the font.

Definition at line 115 of file TextFigure.java.

                                      {
        willChange();
        fFont = newFont;
        markDirty();
        changed();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.figures.TextFigure.setReadOnly ( boolean  isReadOnly) [inline]

Sets the read only status of the text figure.

Definition at line 101 of file TextFigure.java.

                                                {
        fIsReadOnly = isReadOnly;
    }
void CH.ifa.draw.figures.TextFigure.setText ( String  newText) [inline]

Sets the text shown by the text figure.

Definition at line 199 of file TextFigure.java.

                                        {
        if (!newText.equals(fText)) {
            willChange();
            fText = new String(newText);
            markDirty();
            changed();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 87 of file TextFigure.java.

                                      {
        return displayBox();
    }

Here is the call graph for this function:

Dimension CH.ifa.draw.figures.TextFigure.textExtent ( ) [inline, private]

Definition at line 241 of file TextFigure.java.

                                   {
        if (!fSizeIsDirty)
            return new Dimension(fWidth, fHeight);
        FontMetrics metrics =
           Toolkit.getDefaultToolkit().getFontMetrics(fFont);
       fWidth = 0;
       fHeight = 0;
       StringTokenizer st = new StringTokenizer(fText, "\n");
       while (st.hasMoreTokens()) {
           String t = st.nextToken();
           fHeight += metrics.getHeight();
           int w = metrics.stringWidth(t);
           if (w > fWidth)
              fWidth = w;
       }

        fSizeIsDirty = false;
        return new Dimension(fWidth, fHeight);
    }

Here is the caller graph for this function:

void CH.ifa.draw.figures.TextFigure.updateLocation ( ) [inline, protected]

Updates the location relative to the connected figure.

The TextFigure is centered around the located point.

Definition at line 371 of file TextFigure.java.

                                    {
        if (fLocator != null) {
            Point p = fLocator.locate(fObservedFigure);
            p.x -= size().width/2 + fOriginX;
            p.y -= size().height/2 + fOriginY;

            if (p.x != 0 || p.y != 0) {
                willChange();
                basicMoveBy(p.x, p.y);
                changed();
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.figures.TextFigure.write ( StorableOutput  dw) [inline]

Definition at line 303 of file TextFigure.java.

                                         {
        super.write(dw);
        dw.writeInt(fOriginX);
        dw.writeInt(fOriginY);
        dw.writeString(fText);
        dw.writeString(fFont.getName());
        dw.writeInt(fFont.getStyle());
        dw.writeInt(fFont.getSize());
        dw.writeBoolean(fIsReadOnly);
        dw.writeStorable(fObservedFigure);
        dw.writeStorable(fLocator);
    }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 35 of file TextFigure.java.

Definition at line 33 of file TextFigure.java.

String CH.ifa.draw.figures.TextFigure.fgCurrentFontName = "Helvetica" [static, private]

Definition at line 44 of file TextFigure.java.

Definition at line 45 of file TextFigure.java.

int CH.ifa.draw.figures.TextFigure.fgCurrentFontStyle = Font.PLAIN [static, private]

Definition at line 46 of file TextFigure.java.

transient int CH.ifa.draw.figures.TextFigure.fHeight [private]

Definition at line 30 of file TextFigure.java.

Definition at line 34 of file TextFigure.java.

OffsetLocator CH.ifa.draw.figures.TextFigure.fLocator = null [private]

Definition at line 42 of file TextFigure.java.

Definition at line 41 of file TextFigure.java.

Definition at line 24 of file TextFigure.java.

Definition at line 25 of file TextFigure.java.

transient boolean CH.ifa.draw.figures.TextFigure.fSizeIsDirty = true [private]

Definition at line 28 of file TextFigure.java.

Definition at line 32 of file TextFigure.java.

transient int CH.ifa.draw.figures.TextFigure.fWidth [private]

Definition at line 29 of file TextFigure.java.

final long CH.ifa.draw.figures.TextFigure.serialVersionUID = 4599820785949456124L [static, private]

Reimplemented from CH.ifa.draw.figures.AttributeFigure.

Reimplemented in CH.ifa.draw.figures.NumberTextFigure.

Definition at line 51 of file TextFigure.java.

final int CH.ifa.draw.figures.TextFigure.TEXTALIGN_CENTRE = 1 [static, private]

Definition at line 38 of file TextFigure.java.

final int CH.ifa.draw.figures.TextFigure.TEXTALIGN_LEFT = 0 [static, private]

Definition at line 37 of file TextFigure.java.

final int CH.ifa.draw.figures.TextFigure.TEXTALIGN_RIGHT = 2 [static, private]

Definition at line 39 of file TextFigure.java.

Definition at line 52 of file TextFigure.java.


The documentation for this class was generated from the following file: