Package chemaxon.struc.graphics
Class MTextDocument
- java.lang.Object
-
- chemaxon.struc.graphics.MTextDocument
-
- All Implemented Interfaces:
Externalizable
,Serializable
@PublicAPI public class MTextDocument extends Object implements Externalizable
Text document consisting of sections with different attributes.- Since:
- Marvin 4.1, 09/29/2005
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MTextDocument.Portion
Selected text.static class
MTextDocument.Section
Plain text section with uniform attributes.
-
Constructor Summary
Constructors Constructor Description MTextDocument()
Constructs an empty document.MTextDocument(MTextDocument d)
Copy constructor.MTextDocument(String s)
Constructs a document from the specified string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(String s, MTextAttributes attr)
Append text to end of document.char
charAt(int i)
Gets a character of the document.boolean
endsWith(char c)
Tests whether the document ends with the specified character.int
findScriptLastSectionIndex(int from, int subl)
Finds the end of a subscript or superscript.MFont
getAttrFont(MTextAttributes attr)
Gets the font for the specified attribute object.MTextAttributes
getAttributes(int start, int len, int set0)
Gets attributes of the text of len length from start that are supposed to be set even if their values are "default".MFont
getDefaultFont()
Gets the default font.String
getPlainText()
Gets the document as plain text.MTextDocument.Portion
getPortion(int start, int end)
Gets a portion of the document.int
getScriptCount(int i1, int subl)
Gets the number of subscripts or superscripts on the last normal character.MTextDocument.Section
getSection(int k)
Gets a section of the document.int
getSectionCount()
Gets the number of sections in the document.int
getSectionIndexOfCharAt(int i)
Gets the section index of a character.double
getSectionShiftY(int k)
Gets the y shift of a section.MTextDocument
getSubDocument(int start, int end)
void
insert(int i, MTextDocument src)
void
insert(int i, String s, MTextAttributes attr)
Inserts a string.boolean
isFontDefaultInRange(int start, int len)
Tests whether the default font is used in the specified range.boolean
isFontRegularInRange(int start, int len)
Tests whether the default font is used in the specified range.int
length()
Gets the length of the document.void
readExternal(ObjectInput in)
Restores the document.void
readFromString(String str)
Reads the document from a string.void
remove(int start, int len)
Deletes a substring in the document.void
replace(int start, int len, String s)
Replaces a substring in the document.MFont
reuseFont(String name, int style, double size)
void
setAttributes(int start, int len, MTextAttributes attr)
Sets attributes of selected text.void
setDefaultFont(MFont font)
Sets the default font.void
setPlainText(String s)
Sets the document as plain text.String
substring(int start)
Gets a substring of the document.String
substring(int start, int end)
Gets a substring of the document.String
toString()
Gets the string representation of the document.void
updateSubLevel(double[] sublevX, double x, int k)
void
writeExternal(ObjectOutput out)
Saves the document.
-
-
-
Constructor Detail
-
MTextDocument
public MTextDocument()
Constructs an empty document.
-
MTextDocument
public MTextDocument(String s)
Constructs a document from the specified string.- Parameters:
s
- the string
-
MTextDocument
public MTextDocument(MTextDocument d)
Copy constructor.- Parameters:
d
- the document to copy
-
-
Method Detail
-
getPlainText
public final String getPlainText()
Gets the document as plain text.- Returns:
- the text
-
setPlainText
public void setPlainText(String s)
Sets the document as plain text.- Parameters:
s
- the text
-
length
public final int length()
Gets the length of the document.- Returns:
- the length
-
charAt
public final char charAt(int i)
Gets a character of the document.- Returns:
- the character
-
endsWith
public boolean endsWith(char c)
Tests whether the document ends with the specified character.- Parameters:
c
- the character- Returns:
- true if c is the last character, false otherwise
-
substring
public final String substring(int start)
Gets a substring of the document.- Parameters:
start
- index of first character- Returns:
- the substring
-
substring
public final String substring(int start, int end)
Gets a substring of the document.- Parameters:
start
- index of first characterend
- index of last character + 1- Returns:
- the substring
-
getSubDocument
public MTextDocument getSubDocument(int start, int end)
-
remove
public final void remove(int start, int len)
Deletes a substring in the document.- Parameters:
start
- index of first character to deletelen
- number of characters to delete
-
append
public final void append(String s, MTextAttributes attr)
Append text to end of document.- Parameters:
s
- text to addattr
- section attributes or null
-
insert
public final void insert(int i, MTextDocument src)
-
insert
public final void insert(int i, String s, MTextAttributes attr)
Inserts a string.- Parameters:
i
- character indexs
- string to insertattr
- text attributes or null
-
replace
public final void replace(int start, int len, String s)
Replaces a substring in the document.- Parameters:
start
- index of first character to deletelen
- number of characters to replaces
- substitution
-
getAttributes
public final MTextAttributes getAttributes(int start, int len, int set0)
Gets attributes of the text of len length from start that are supposed to be set even if their values are "default".- Parameters:
start
- position of first characterlen
- number of charactersset0
- the set of attributes that are supposed to be set even if their values are "default"- Returns:
- the attributes and the flags
-
isFontDefaultInRange
public final boolean isFontDefaultInRange(int start, int len)
Tests whether the default font is used in the specified range.- Returns:
- true if only the default font is used, false otherwise
-
isFontRegularInRange
public final boolean isFontRegularInRange(int start, int len)
Tests whether the default font is used in the specified range.- Returns:
- true if only the default font is used, false otherwise
-
setAttributes
public final void setAttributes(int start, int len, MTextAttributes attr)
Sets attributes of selected text.- Parameters:
start
- position of first characterlen
- number of charactersattr
- the attributes- 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
-
getPortion
public final MTextDocument.Portion getPortion(int start, int end)
Gets a portion of the document.- Parameters:
start
- position of first characterend
- position of last character + 1- Returns:
- the portion
-
getDefaultFont
public MFont getDefaultFont()
Gets the default font.- Returns:
- the font
-
setDefaultFont
public void setDefaultFont(MFont font)
Sets the default font.- Parameters:
font
- the font
-
getSectionCount
public final int getSectionCount()
Gets the number of sections in the document.- Returns:
- the number of sections
-
getSectionIndexOfCharAt
public final int getSectionIndexOfCharAt(int i)
Gets the section index of a character.- Parameters:
i
- character position- Returns:
- the section index
-
getSection
public final MTextDocument.Section getSection(int k)
Gets a section of the document.- Parameters:
k
- section number- Returns:
- the section
-
getSectionShiftY
public final double getSectionShiftY(int k)
Gets the y shift of a section.- Parameters:
k
- the section number- Returns:
- the shift
-
findScriptLastSectionIndex
public final int findScriptLastSectionIndex(int from, int subl)
Finds the end of a subscript or superscript.- Parameters:
from
- the first section indexsubl
- the script level to query, +1 (superscript) or -1 (subscript)- Returns:
- the index of the last section containing this subscript or superscript
- Since:
- Marvin 4.1, 02/25/2006
-
getScriptCount
public final int getScriptCount(int i1, int subl)
Gets the number of subscripts or superscripts on the last normal character.- Parameters:
i1
- the positionsubl
- the script level to query, +1 (superscript) or -1 (subscript)- Returns:
- the number of subscripts or superscripts
- Since:
- Marvin 4.1, 02/25/2006
-
getAttrFont
public MFont getAttrFont(MTextAttributes attr)
Gets the font for the specified attribute object.- Returns:
- the font
-
toString
public String toString()
Gets the string representation of the document.
-
readFromString
public void readFromString(String str) throws IllegalArgumentException
Reads the document from a string.- Parameters:
str
- the string- Throws:
IllegalArgumentException
-
updateSubLevel
public void updateSubLevel(double[] sublevX, double x, int k)
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
Restores the document.- Specified by:
readExternal
in interfaceExternalizable
- Parameters:
in
- the stream to read data from in order to restore the object- Throws:
IOException
- if I/O errors occurClassNotFoundException
- If the class for an object being restored cannot be found.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
Saves the document.- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- the stream to write the object to- Throws:
IOException
- Includes any I/O exceptions that may occur
-
-