Package chemaxon.struc.graphics
Class MTextDocument
java.lang.Object
chemaxon.struc.graphics.MTextDocument
- All Implemented Interfaces:
Externalizable
,Serializable
Text document consisting of sections with different attributes.
- Since:
- Marvin 4.1, 09/29/2005
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Selected text.static class
Plain text section with uniform attributes. -
Constructor Summary
ConstructorDescriptionConstructs an empty document.Copy constructor.Constructs a document from the specified string. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
append
(String s, MTextAttributes attr) Append text to end of document.final char
charAt
(int i) Gets a character of the document.boolean
endsWith
(char c) Tests whether the document ends with the specified character.final int
findScriptLastSectionIndex
(int from, int subl) Finds the end of a subscript or superscript.getAttrFont
(MTextAttributes attr) Gets the font for the specified attribute object.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".Gets the default font.final String
Gets the document as plain text.final MTextDocument.Portion
getPortion
(int start, int end) Gets a portion of the document.final int
getScriptCount
(int i1, int subl) Gets the number of subscripts or superscripts on the last normal character.final MTextDocument.Section
getSection
(int k) Gets a section of the document.final int
Gets the number of sections in the document.final int
getSectionIndexOfCharAt
(int i) Gets the section index of a character.final double
getSectionShiftY
(int k) Gets the y shift of a section.getSubDocument
(int start, int end) final void
insert
(int i, MTextDocument src) final void
insert
(int i, String s, MTextAttributes attr) Inserts a string.final boolean
isFontDefaultInRange
(int start, int len) Deprecated, for removal: This API element is subject to removal in a future version.final boolean
isFontRegularInRange
(int start, int len) Deprecated, for removal: This API element is subject to removal in a future version.final int
length()
Gets the length of the document.void
Restores the document.void
readFromString
(String str) Reads the document from a string.final void
remove
(int start, int len) Deletes a substring in the document.final void
Replaces a substring in the document.final void
setAttributes
(int start, int len, MTextAttributes attr) Sets attributes of selected text.void
setDefaultFont
(MFont font) Sets the default font.void
Sets the document as plain text.final String
substring
(int start) Gets a substring of the document.final String
substring
(int start, int end) Gets a substring of the document.toString()
Gets the string representation of the document.void
updateSubLevel
(double[] sublevX, double x, int k) void
Saves the document.
-
Constructor Details
-
MTextDocument
public MTextDocument()Constructs an empty document. -
MTextDocument
Constructs a document from the specified string.- Parameters:
s
- the string
-
MTextDocument
Copy constructor.- Parameters:
d
- the document to copy
-
-
Method Details
-
getPlainText
Gets the document as plain text.- Returns:
- the text
-
setPlainText
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
Gets a substring of the document.- Parameters:
start
- index of first character- Returns:
- the substring
-
substring
Gets a substring of the document.- Parameters:
start
- index of first characterend
- index of last character + 1- Returns:
- the substring
-
getSubDocument
-
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
Append text to end of document.- Parameters:
s
- text to addattr
- section attributes or null
-
insert
-
insert
Inserts a string.- Parameters:
i
- character indexs
- string to insertattr
- text attributes or null
-
replace
Replaces a substring in the document.- Parameters:
start
- index of first character to deletelen
- number of characters to replaces
- substitution
-
getAttributes
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
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public final boolean isFontDefaultInRange(int start, int len) Deprecated, for removal: This API element is subject to removal in a future version.Tests whether the default font is used in the specified range.- Returns:
- true if only the default font is used, false otherwise
-
isFontRegularInRange
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public final boolean isFontRegularInRange(int start, int len) Deprecated, for removal: This API element is subject to removal in a future version.Tests whether the default font is used in the specified range.- Returns:
- true if only the default font is used, false otherwise
-
setAttributes
Sets attributes of selected text.- Parameters:
start
- position of first characterlen
- number of charactersattr
- the attributes- See Also:
-
getPortion
Gets a portion of the document.- Parameters:
start
- position of first characterend
- position of last character + 1- Returns:
- the portion
-
getDefaultFont
Gets the default font.- Returns:
- the font
-
setDefaultFont
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
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
Gets the font for the specified attribute object.- Returns:
- the font
-
toString
Gets the string representation of the document. -
readFromString
Reads the document from a string.- Parameters:
str
- the string- Throws:
IllegalArgumentException
-
reuseFont
-
updateSubLevel
public void updateSubLevel(double[] sublevX, double x, int k) -
readExternal
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
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
-