chemaxon.struc.graphics
Class MTextBox

java.lang.Object
  extended bychemaxon.struc.MObject
      extended bychemaxon.struc.graphics.MPolyline
          extended bychemaxon.struc.graphics.MRectangle
              extended bychemaxon.struc.graphics.MTextBox
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class MTextBox
extends MRectangle

Text box object.

Since:
Marvin 3.3, 10/20/2003
Version:
4.1, 04/28/2006
Author:
Peter Csizmadia
See Also:
Serialized Form

Field Summary
 
Fields inherited from class chemaxon.struc.graphics.MRectangle
P_CENTER, P_E, P_N, P_NE, P_NW, P_S, P_SE, P_SW, P_W, T_NOROT
 
Fields inherited from class chemaxon.struc.graphics.MPolyline
ARROW_BACK_FLAG, ARROW_HALF_LEFT, ARROW_HALF_MASK, ARROW_HALF_RIGHT, CLOSED_FLAG, DEFAULT_THICKNESS, HEAD, TAIL, THICKNESS_SET_FLAG
 
Fields inherited from class chemaxon.struc.MObject
PAINT_ANTIALIAS, PAINT_FOCUSED, TRANSFORM_DISTORT
 
Constructor Summary
  MTextBox()
          Contructs an empty text box.
protected MTextBox(MTextBox t)
          Copy constructor.
 
Method Summary
 void addAttributeKeys(java.util.Vector v)
          Adds the attribute names to the specified vector.
 void addCdataAttributeKeys(java.util.Vector v)
          Adds attribute names to the specified vector.
 void addChar(char c)
          Adds a character to the text.
 void addString(java.lang.String s)
          Adds a string to the text.
 java.lang.Object clone()
          Creates a clone.
 void cursorDown(boolean select)
          Move the cursor down.
 void cursorUp(boolean select)
          Moves the cursor up.
 void deleteChar()
          Removes the character under the cursor.
 void deleteCharBackward()
          Removes the character before the cursor (backspace).
 int determinePosition(DPoint3 p, boolean allowExternalPoints)
           
 java.lang.String getAttribute(java.lang.String s)
          Gets the value of an attribute.
 MFont getBaseFont()
          Gets the base font.
 java.lang.String getBaseFontFamily()
          Gets the base font family.
 int getBaseFontStyle()
          Gets the base font style.
 java.awt.Color getCurrentForeground()
          Gets the current color.
 int getCurrentScriptCount(int subl)
          Gets the number of subscripts or superscripts on the last normal character.
 int getCurrentSubLevel()
          Gets the current subscript/superscript level.
 MTextAttributes getCurrentTextAttributes(int set0)
          Gets the common attributes of the selected text or attributes for the next character to be typed.
 int getCursorPos()
          Gets the cursor position.
 double getFontScale()
          Gets the font scaling factor.
 int getPreviousNormalTextSectionIndex()
          Gets the index of the last `normal' text section before the current subscript/superscript section.
 java.lang.String getSelectedString()
          Gets the selected substring.
 int getSelectionEndPos()
          Gets the selection's end position.
 int getSelectionStartPos()
          Gets the selection's start position.
 java.lang.String getText()
          Gets the text stored.
 MTextDocument getTextDocument()
          Gets the text document.
 boolean hasBackground()
          A text box has a background always.
 boolean hasColor()
          A text box has a text color.
 boolean hasFace()
          Is it 2 dimensional?
 boolean hasRichText()
          Tests whether the document is rich text.
 boolean hasSelection()
          Checks the existence of the selection.
 boolean isCurrentFontDefault()
          Tests whether the default font is used.
 boolean isCurrentFontRegular()
          Tests whether the current font is regular.
 boolean isEmpty()
          A text box is empty if the string contains only whitespace.
 void paint(java.awt.Graphics g, CTransform3D t0, int f, java.awt.Color c, java.awt.Color selc, java.awt.Color focusc)
          Paints the object.
 void setAttribute(java.lang.String s, java.lang.String v)
          Sets the value of an attribute.
 void setAutoSize(boolean v)
          Turns on/off automatic size calculation.
 void setBaseFontFamily(java.lang.String name)
          Sets the base font family.
 void setBaseFontStyle(int style)
          Sets the base font style.
 void setCurrentFont(MFont ft, int setflags)
          Sets font for selected text or the next character to be typed.
 void setCurrentForeground(java.awt.Color c)
          Sets color for selected text or the next character to be typed.
 void setCurrentTextAttributes(MTextAttributes attr)
          Sets the attributes for the selected text or the next character to be typed.
 void setCursorPos(int i, boolean select)
          Sets the cursor position.
 void setFontScale(double scale)
          Sets the font scaling factor.
 void setPoints(MPoint[] p)
          Sets the points.
 void setSelected(boolean v)
          Selects or unselects the text box.
 void setText(java.lang.String s)
          Sets the text.
 void transform(CTransform3D t, int opts, CTransform3D trot)
          Transforms all points and scales the font size.
 void unselectContents()
          Unselects text.
 
Methods inherited from class chemaxon.struc.graphics.MRectangle
calcCenter, convertTransform, distanceFrom, fixRectanglePointClones, getClipObject, getPointRef, getPointRefCount, getTCenter, getTOption, removeChild, setCorners, setTCenter, setTOption, transformTo2D
 
Methods inherited from class chemaxon.struc.graphics.MPolyline
checkValidity, containsAtom, copyProperties, finishCloning, fixMidPointClones, getArcAngle, getArcCenter, getArcRadius, getArrowFlags, getArrowLength, getArrowWidth, getFlags, getMidPointLocation, getPoint, getPointCount, getPoints, getSkip, getThickness, hasLineColor, hasOutline, isArrow, isThicknessSet, replaceAtom, setArcAngle, setArrow, setArrowFlags, setArrowLength, setArrowWidth, setFlags, setSkip, setThickness
 
Methods inherited from class chemaxon.struc.MObject
addNotify, distanceFrom, getBackground, getColor, getLineColor, isChildOf, isInternalSelectable, isSelectableNow, isSelected, isTransformable, makeColor, removeNotify, setBackground, setColor, setLineColor, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MTextBox

public MTextBox()
Contructs an empty text box.


MTextBox

protected MTextBox(MTextBox t)
Copy constructor.

Parameters:
t - the original text box
Method Detail

clone

public java.lang.Object clone()
Description copied from class: MObject
Creates a clone.

Overrides:
clone in class MRectangle

getTextDocument

public MTextDocument getTextDocument()
Gets the text document.

Returns:
the text
Since:
Marvin 4.1, 09/30/2005

getText

public java.lang.String getText()
Gets the text stored.

Returns:
the text

setText

public void setText(java.lang.String s)
Sets the text.

Parameters:
s - the text
Since:
Marvin 3.5, 07/14/2004

getBaseFont

public final MFont getBaseFont()
Gets the base font.

Returns:
the base font
Since:
Marvin 4.1, 11/11/2005

getBaseFontFamily

public final java.lang.String getBaseFontFamily()
Gets the base font family.

Returns:
the font family name
Since:
Marvin 4.1, 11/11/2005

setBaseFontFamily

public final void setBaseFontFamily(java.lang.String name)
Sets the base font family.

Parameters:
name - the font family name
Since:
Marvin 4.1, 11/11/2005

getBaseFontStyle

public final int getBaseFontStyle()
Gets the base font style.

Returns:
the font style
Since:
Marvin 4.1, 11/11/2005

setBaseFontStyle

public final void setBaseFontStyle(int style)
Sets the base font style.

Parameters:
style - the font style
Since:
Marvin 4.1, 11/11/2005

getFontScale

public final double getFontScale()
Gets the font scaling factor.

Returns:
the font scale
Since:
Marvin 4.1, 11/11/2005

setFontScale

public final void setFontScale(double scale)
Sets the font scaling factor.

Parameters:
scale - the font scale
Since:
Marvin 4.1, 11/11/2005

setAutoSize

public void setAutoSize(boolean v)
Turns on/off automatic size calculation.

Parameters:
v - turn on (true) or off (false)

isEmpty

public boolean isEmpty()
A text box is empty if the string contains only whitespace.

Overrides:
isEmpty in class MPolyline
Returns:
true if empty, false otherwise

hasRichText

public boolean hasRichText()
Tests whether the document is rich text.

Returns:
true if the text is rich, false otherwise
Since:
Marvin 4.1, 11/11/2005

addAttributeKeys

public void addAttributeKeys(java.util.Vector v)
Adds the attribute names to the specified vector. CDATA attributes are not added.

Overrides:
addAttributeKeys in class MRectangle
Parameters:
v - the vector

addCdataAttributeKeys

public void addCdataAttributeKeys(java.util.Vector v)
Adds attribute names to the specified vector. Only CDATA attributes are added.

Overrides:
addCdataAttributeKeys in class MObject
Parameters:
v - the vector

getAttribute

public java.lang.String getAttribute(java.lang.String s)
Gets the value of an attribute.
Supported attributes:

Overrides:
getAttribute in class MRectangle
Parameters:
s - the attribute name
Returns:
the value or null

setAttribute

public void setAttribute(java.lang.String s,
                         java.lang.String v)
Sets the value of an attribute.
Supported attributes:

Overrides:
setAttribute in class MRectangle
Parameters:
s - the attribute name
v - the attribute value

hasSelection

public boolean hasSelection()
Checks the existence of the selection.

Returns:
true if selection exists, false otherwise

getSelectedString

public java.lang.String getSelectedString()
Gets the selected substring.

Returns:
the selection if it exists, null otherwise

deleteCharBackward

public void deleteCharBackward()
Removes the character before the cursor (backspace).


deleteChar

public void deleteChar()
Removes the character under the cursor.


addChar

public void addChar(char c)
Adds a character to the text.

Parameters:
c - the character

addString

public void addString(java.lang.String s)
Adds a string to the text.

Parameters:
s - the string

getCursorPos

public int getCursorPos()
Gets the cursor position.

Returns:
the position

setCursorPos

public void setCursorPos(int i,
                         boolean select)
Sets the cursor position.

Parameters:
i - the new position
select - select text while moving the cursor

getPreviousNormalTextSectionIndex

public final int getPreviousNormalTextSectionIndex()
Gets the index of the last `normal' text section before the current subscript/superscript section. `Normal' means that the absolute value of the subscript/superscript level must be smaller than in the current cursor position.

Returns:
the section index or -1
Since:
Marvin 4.1, 10/08/2005

getCurrentSubLevel

public final int getCurrentSubLevel()
Gets the current subscript/superscript level.

Returns:
the attributes
Since:
Marvin 4.1, 10/08/2005

getCurrentScriptCount

public final int getCurrentScriptCount(int subl)
Gets the number of subscripts or superscripts on the last normal character.

Parameters:
subl - the script level to query, +1 (superscript) or -1 (subscript)
Returns:
the number of subscripts or superscripts
Since:
Marvin 4.1, 02/25/2006

getCurrentTextAttributes

public final MTextAttributes getCurrentTextAttributes(int set0)
Gets the common attributes of the selected text or attributes for the next character to be typed.

Parameters:
set0 - the set of attributes that are supposed to be set even if their values are "default"
Returns:
the attributes
Since:
Marvin 4.1, 10/06/2005
See Also:
MTextAttributes.A_SUBLEVEL, MTextAttributes.A_FOREGROUND, MTextAttributes.A_FONT, MTextAttributes.A_FONTFAMILY, MTextAttributes.A_FONTSIZE, MTextAttributes.A_BOLD, MTextAttributes.A_ITALIC, MTextAttributes.A_SCALE, MTextAttributes.A_DX, MTextAttributes.A_DY

setCurrentTextAttributes

public void setCurrentTextAttributes(MTextAttributes attr)
Sets the attributes for the selected text or the next character to be typed.

Parameters:
attr - the text attributes
Since:
Marvin 4.1, 10/06/2005
See Also:
MTextAttributes.A_SUBLEVEL, MTextAttributes.A_FOREGROUND, MTextAttributes.A_FONT, MTextAttributes.A_FONTFAMILY, MTextAttributes.A_FONTSIZE, MTextAttributes.A_BOLD, MTextAttributes.A_ITALIC, MTextAttributes.A_SCALE, MTextAttributes.A_DX, MTextAttributes.A_DX, MTextAttributes.A_DY

isCurrentFontDefault

public final boolean isCurrentFontDefault()
Tests whether the default font is used.

Returns:
true if only the default font is used, false otherwise
Since:
Marvin 4.1, 01/11/2006

isCurrentFontRegular

public final boolean isCurrentFontRegular()
Tests whether the current font is regular.

Returns:
true if the font is regular, false otherwise
Since:
Marvin 4.1, 01/11/2006

getCurrentForeground

public final java.awt.Color getCurrentForeground()
Gets the current color.

Returns:
the color
Since:
Marvin 4.1, 01/18/2006

setCurrentForeground

public final void setCurrentForeground(java.awt.Color c)
Sets color for selected text or the next character to be typed.

Parameters:
c - the color
Since:
Marvin 4.1, 10/08/2005

setCurrentFont

public final void setCurrentFont(MFont ft,
                                 int setflags)
Sets font for selected text or the next character to be typed.

Parameters:
ft - the font or null
setflags - font attributes to set
Since:
Marvin 4.1, 10/08/2005
See Also:
MTextAttributes.A_FONT, MTextAttributes.A_FONTFAMILY, MTextAttributes.A_FONTSIZE, MTextAttributes.A_BOLD, MTextAttributes.A_ITALIC

cursorUp

public void cursorUp(boolean select)
Moves the cursor up.

Parameters:
select - select text while moving the cursor

cursorDown

public void cursorDown(boolean select)
Move the cursor down.

Parameters:
select - select text while moving the cursor

getSelectionStartPos

public int getSelectionStartPos()
Gets the selection's start position.

Returns:
the start index

getSelectionEndPos

public int getSelectionEndPos()
Gets the selection's end position.

Returns:
the end index

setPoints

public void setPoints(MPoint[] p)
Sets the points.

Overrides:
setPoints in class MPolyline
Parameters:
p - the points

hasColor

public boolean hasColor()
A text box has a text color.

Overrides:
hasColor in class MPolyline
Returns:
true

hasBackground

public boolean hasBackground()
A text box has a background always.

Overrides:
hasBackground in class MPolyline
Returns:
true if closed

hasFace

public boolean hasFace()
Is it 2 dimensional?

Overrides:
hasFace in class MPolyline
Returns:
true always

transform

public void transform(CTransform3D t,
                      int opts,
                      CTransform3D trot)
Transforms all points and scales the font size.

Overrides:
transform in class MRectangle
Parameters:
t - the transformation matrix
opts - transform options or 0
trot - the viewing transformation or null
Since:
Marvin 4.1, 04/28/2006

paint

public void paint(java.awt.Graphics g,
                  CTransform3D t0,
                  int f,
                  java.awt.Color c,
                  java.awt.Color selc,
                  java.awt.Color focusc)
Paints the object.

Overrides:
paint in class MRectangle
Parameters:
g - the graphics context
t0 - the transformation matrix
f - flags
c - the color to use or null
selc - the selection color
focusc - the focus color

setSelected

public void setSelected(boolean v)
Selects or unselects the text box.

Overrides:
setSelected in class MObject
Parameters:
v - true to select, false to unselect

unselectContents

public void unselectContents()
Unselects text.

Overrides:
unselectContents in class MPolyline

determinePosition

public int determinePosition(DPoint3 p,
                             boolean allowExternalPoints)