Package org.opensourcephysics.display
Class TextLine
java.lang.Object
org.opensourcephysics.display.TextLine
- Direct Known Subclasses:
DrawableTextLine
TextLine is designed to bundle together all the information required
to draw short Strings with subscripts and superscripts.
TextLine was modified by W. Christian to add Greek characters using TeX notation.
- Author:
- Leigh Brookshaw
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Format to use when parsing a doubleprotected int
The ascent using the current fontprotected Color
Background Colorstatic final int
Center the Text over the pointprotected Color
Text colorprotected int
The descent using the current fontprotected Font
Font to use for textprotected String
The logical name of the font to useprotected int
The font sizeprotected int
The font styleprotected int
The height using the current font ie ascent+descent+leadingprotected int
Text justification.protected int
The leading using the current fontstatic final int
Position the Text to the Left of the pointprotected Graphics
Local graphics context.protected Vector<org.opensourcephysics.display.TextState>
The parsed string.protected int
The maximum ascent using the current fontprotected int
The maximum descent using the current fontprotected boolean
Has the string been parsed! This only needs to be done once unless the font is altered.static final int
Position the Text to the Right of the pointstatic final int
Format to use when parsing a doubleprotected double
Decrease in size of successive script levelsprotected double
Subscript offsetprotected double
Superscript offsetprotected String
The text to displayprotected AffineTransform
protected int
The width of the text using the current Font -
Constructor Summary
ConstructorsConstructorDescriptionTextLine()
Instantiate the classInstantiate the classInstantiate the class.Instantiate the classInstantiate the classInstantiate the class -
Method Summary
Modifier and TypeMethodDescriptionint
Create a New Textline object copying the state of the existing object into the new one.void
Copy the state of the parsed Textline into the existing object.protected void
drawRotatedText
(double theta, double x, double y, Graphics g) void
Parse the text then draw it without any rotation.void
Parse the text then draw it.protected void
drawTextImageRotated
(ImageObserver panel, Graphics g, double theta, double x, double y) Paint the font onto and image, and then paint that using a transform onto the actual graphic.int
getColor()
int
getFont()
int
int
int
int
int
int
int
Returns the bounding box for this string.getText()
int
boolean
isNull()
static double
log10
(double x) boolean
parseDouble
(double d) Parse a double value.boolean
parseDouble
(double d, int p) Parse a double value.boolean
parseDouble
(double d, int n, int p, int f) Parse a double valuevoid
parse the text.void
Set the Background Color to use with the classvoid
Set the Color to use with the classvoid
Set the Font to use with the classvoid
Set the Logical font name of the current fontvoid
setFontSize
(int i) Set the Font size of the current fontvoid
setFontStyle
(int i) Set the Font style of the current fontvoid
setJustification
(int i) Set the Justification to use with the classvoid
Set the String to use with the class
-
Field Details
-
CENTER
public static final int CENTERCenter the Text over the point- See Also:
-
LEFT
public static final int LEFTPosition the Text to the Left of the point- See Also:
-
RIGHT
public static final int RIGHTPosition the Text to the Right of the point- See Also:
-
SCIENTIFIC
public static final int SCIENTIFICFormat to use when parsing a double- See Also:
-
ALGEBRAIC
public static final int ALGEBRAICFormat to use when parsing a double- See Also:
-
script_fraction
protected double script_fractionDecrease in size of successive script levels -
sup_offset
protected double sup_offsetSuperscript offset -
sub_offset
protected double sub_offsetSubscript offset -
font
Font to use for text -
color
Text color -
background
Background Color -
text
The text to display -
fontname
The logical name of the font to use -
fontsize
protected int fontsizeThe font size -
fontstyle
protected int fontstyleThe font style -
justification
protected int justificationText justification. Either CENTER, LEFT or RIGHT -
width
protected int widthThe width of the text using the current Font -
ascent
protected int ascentThe ascent using the current font -
maxAscent
protected int maxAscentThe maximum ascent using the current font -
descent
protected int descentThe descent using the current font -
maxDescent
protected int maxDescentThe maximum descent using the current font -
height
protected int heightThe height using the current font ie ascent+descent+leading -
leading
protected int leadingThe leading using the current font -
parse
protected boolean parseHas the string been parsed! This only needs to be done once unless the font is altered. -
lg
Local graphics context. -
list
The parsed string. Each element in the vector represents a change of context in the string ie font change and offset. -
trTL
-
-
Constructor Details
-
TextLine
public TextLine()Instantiate the class -
TextLine
Instantiate the class.- Parameters:
s
- String to parse.
-
TextLine
Instantiate the class- Parameters:
s
- String to parse.f
- Font to use.
-
TextLine
Instantiate the class- Parameters:
s
- String to parse.f
- Font to use.c
- Color to usej
- Justification
-
TextLine
Instantiate the class- Parameters:
s
- String to parse.c
- Color to use
-
TextLine
Instantiate the class- Parameters:
f
- Font to use.c
- Color to usej
- Justification
-
-
Method Details
-
copyState
Create a New Textline object copying the state of the existing object into the new one. The state of the class is the color, font, and justification ie everything but the string. -
copyState
Copy the state of the parsed Textline into the existing object.- Parameters:
t
- The TextLine to get the state information from.
-
setFont
Set the Font to use with the class- Parameters:
f
- Font
-
setText
Set the String to use with the class- Parameters:
s
- String
-
setColor
Set the Color to use with the class- Parameters:
c
- Color
-
setBackground
Set the Background Color to use with the class- Parameters:
c
- Color
-
setJustification
public void setJustification(int i) Set the Justification to use with the class- Parameters:
i
- Justification
-
getFont
- Returns:
- the font the class is using
-
getText
- Returns:
- the String the class is using.
-
getColor
- Returns:
- the Color the class is using.
-
getBackground
- Returns:
- the Background Color the class is using.
-
getJustification
public int getJustification()- Returns:
- the Justification the class is using.
-
getFM
- Parameters:
g
- Graphics context.- Returns:
- the Fontmetrics the class is using.
-
charWidth
- Parameters:
g
- Graphics context.ch
- The character.- Returns:
- the width of the character.
-
getStringBounds
Returns the bounding box for this string.- Parameters:
g
- Graphics- Returns:
- Rectangle2D
-
getWidth
- Parameters:
g
- Graphics context.- Returns:
- the width of the parsed text.
-
getHeight
- Parameters:
g
- Graphics context.- Returns:
- the height of the parsed text.
-
getAscent
- Parameters:
g
- Graphics context.- Returns:
- the ascent of the parsed text.
-
getMaxAscent
- Parameters:
g
- Graphics context.- Returns:
- the maximum ascent of the parsed text.
-
getDescent
- Parameters:
g
- Graphics context.- Returns:
- the descent of the parsed text.
-
getMaxDescent
- Parameters:
g
- Graphics context.- Returns:
- the maximum descent of the parsed text.
-
getLeading
- Parameters:
g
- Graphics context.- Returns:
- the leading of the parsed text.
-
parseText
parse the text. When the text is parsed the width, height, leading are all calculated. The text will only be truly parsed if the graphics context has changed or the text has changed or the font has changed. Otherwise nothing is done when this method is called.- Parameters:
g
- Graphics context.
-
isNull
public boolean isNull()- Returns:
- true if the text has never been set or is null
-
drawText
Parse the text then draw it.- Parameters:
g
- Graphics contextx
- pixel position of the texty
- pixel position of the textj
- justification of the text
-
drawText
Parse the text then draw it without any rotation.- Parameters:
g
- Graphics contextx
- pixel position of the texty
- pixel position of the text
-
drawRotatedText
-
drawTextImageRotated
protected void drawTextImageRotated(ImageObserver panel, Graphics g, double theta, double x, double y) Paint the font onto and image, and then paint that using a transform onto the actual graphic.- Parameters:
panel
-g
-theta
-x
-y
-
-
getFontName
- Returns:
- Logical font name of the set font
-
getFontStyle
public int getFontStyle()- Returns:
- Style of the set font
-
getFontSize
public int getFontSize()- Returns:
- Size of the set font
-
setFontName
Set the Logical font name of the current font- Parameters:
s
- Logical font name.
-
setFontStyle
public void setFontStyle(int i) Set the Font style of the current font- Parameters:
i
- Font style.
-
setFontSize
public void setFontSize(int i) Set the Font size of the current font- Parameters:
i
- Font size.
-
getScriptFont
- Parameters:
f
- Font- Returns:
- The script font version of the parsed font using the script_fraction variable.
-
parseDouble
public boolean parseDouble(double d) Parse a double value. Precision is 6 figures, with 7 significant figures.- Parameters:
d
- double to parse return true if the parse was successful
-
parseDouble
public boolean parseDouble(double d, int p) Parse a double value. Number of significant figures is 1 greater than the precision.- Parameters:
d
- double to parsep
- precision of the number return true if the parse was successful
-
parseDouble
public boolean parseDouble(double d, int n, int p, int f) Parse a double value- Parameters:
d
- double to parsen
- number of significant figuresp
- precision of the numberf
- format of the number scientific, algebraic etc. return true if the parse was successful
-
log10
- Parameters:
x
- a double value- Returns:
- The log10
- Throws:
ArithmeticException
-