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
Nested ClassesModifier and TypeClassDescriptionclassSelected text.static classPlain text section with uniform attributes. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty document.Copy constructor.Constructs a document from the specified string. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidappend(String s, MTextAttributes attr) Append text to end of document.final charcharAt(int i) Gets a character of the document.booleanendsWith(char c) Tests whether the document ends with the specified character.final intfindScriptLastSectionIndex(int from, int subl) Finds the end of a subscript or superscript.getAttrFont(MTextAttributes attr) Gets the font for the specified attribute object.final MTextAttributesgetAttributes(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 StringGets the document as plain text, with no formatting and escaping.final MTextDocument.PortiongetPortion(int start, int end) Gets a portion of the document.final intgetScriptCount(int i1, int subl) Gets the number of subscripts or superscripts on the last normal character.final MTextDocument.SectiongetSection(int k) Gets a section of the document.final intGets the number of sections in the document.final intgetSectionIndexOfCharAt(int i) Gets the section index of a character.final doublegetSectionShiftY(int k) Gets the y shift of a section.getSubDocument(int start, int end) final voidinsert(int i, MTextDocument src) final voidinsert(int i, String s, MTextAttributes attr) Inserts a string.final booleanisFontDefaultInRange(int start, int len) Deprecated, for removal: This API element is subject to removal in a future version.final booleanisFontRegularInRange(int start, int len) Deprecated, for removal: This API element is subject to removal in a future version.final intlength()Gets the length of the document.voidRestores the document.voidreadFromString(String str) Reads the document content from a string.final voidremove(int start, int len) Deletes a substring in the document.final voidReplaces a substring in the document.final voidsetAttributes(int start, int len, MTextAttributes attr) Sets attributes of selected text.voidsetDefaultFont(MFont font) Sets the default font.voidSets the document as plain text.final Stringsubstring(int start) Gets a substring of the document.final Stringsubstring(int start, int end) Gets a substring of the document.toString()Gets the string representation of the document.voidupdateSubLevel(double[] sublevX, double x, int k) voidSaves 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, with no formatting and escaping.- 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 content from a string. Content can have formatting, but already should be unescaped:- when method is called from CMLImport, value is already unescaped, this method relies on it during parsing
- TODO: the method is called from other non-import places where the input still may have escaping- Parameters:
str- the string- Throws:
IllegalArgumentException
-
reuseFont
-
updateSubLevel
public void updateSubLevel(double[] sublevX, double x, int k) -
readExternal
Restores the document.- Specified by:
readExternalin 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:
writeExternalin interfaceExternalizable- Parameters:
out- the stream to write the object to- Throws:
IOException- Includes any I/O exceptions that may occur
-