Package com.inductiveautomation.rm.text
Class RMTextEditor
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMListenerList
-
- com.inductiveautomation.rm.base.RMObject
-
- com.inductiveautomation.rm.text.RMTextEditor
-
- All Implemented Interfaces:
RMPropertyChanger,RMTypes,RMTextTypes,java.beans.PropertyChangeListener,java.lang.CharSequence,java.lang.Cloneable,java.util.EventListener
- Direct Known Subclasses:
RMEditorTextEditor
public class RMTextEditor extends RMObject implements RMTextTypes, java.lang.CharSequence, java.beans.PropertyChangeListener
This class provides all of the event and drawing code necessary to edit text in the form of an RMXString (separated from an actual UI Component).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classRMTextEditor.TextSelectionA class to act as text selection.-
Nested classes/interfaces inherited from interface com.inductiveautomation.rm.text.RMTextTypes
RMTextTypes.TabType
-
Nested classes/interfaces inherited from interface com.inductiveautomation.rm.base.RMTypes
RMTypes.Align, RMTypes.AlignX, RMTypes.AlignY
-
-
Field Summary
Fields Modifier and Type Field Description static booleanisHyphenatingstatic booleanisSpellChecking-
Fields inherited from interface com.inductiveautomation.rm.text.RMTextTypes
TEXT_CHAR_SPACING, TEXT_COLOR, TEXT_EMBEDDED_SHAPE, TEXT_FONT, TEXT_FORMAT, TEXT_OUTLINE, TEXT_PARAGRAPH, TEXT_SCRIPTING, TEXT_UNDERLINE
-
-
Constructor Summary
Constructors Constructor Description RMTextEditor()Creates a plain text editor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description charcharAt(int anIndex)Returns the individual character at given index.voidcopy()Copies the current selection onto the clipboard.RMTextLayoutcreateLayout()Creates a configured text layout used to layout text.voidcut()Copies the current selection onto the clip board, then deletes the current selection.voiddelete()Deletes the current selection.voiddelete(int aStart, int anEnd, boolean doUpdateSelection)Deletes the given range of chars.voiddeleteForward()Deletes the character in front of the insertion point.voiddeleteToLineEnd()Deletes the characters from the insertion point to the end of the line.RMTypes.AlignXgetAlignmentX()Returns the alignment for current selection.java.awt.geom.Rectangle2DgetBounds()Returns the text editor bounds.intgetCharIndex(java.awt.geom.Point2D aPoint)Returns the char index for given point in text coordinate space.floatgetCharSpacing()Returns the character spacing of the current selection or cursor.RMColorgetColor()Returns the color of the current selection or cursor.RMFontgetFont()Returns the font of the current selection or cursor.doublegetFontScale()Returns the scale applied to text when editing.RMFormatgetFormat()Returns the format of the current selection or cursor.doublegetHeight()Returns the bounds height.floatgetHeightToFit()Returns the height needed to display all characters.RMParagraphgetInputParagraph()Returns the paragraph of the current selection or cursor position.RMTextStylegetInputStyle()Returns the text style applied to any input characters.RMTextLayoutgetLayout()Returns the configured text layout used to layout text.RMTextLinegetLine(int anIndex)Returns the individual line at given index.intgetLineCount()Returns the number of lines.RMTextLinegetLineForChar(int anIndex)Returns the line index for the given character index.floatgetLineGap()Returns the line gap for current selection.floatgetLineHeightMax()Returns the maximum line height for a line of text (even if font size would dictate higher).floatgetLineHeightMin()Returns the min line height for current selection.floatgetLineSpacing()Returns the line spacing for current selection.RMXString.OutlinegetOutline()Returns whether current selection is outlined.RMTextSelgetSel()Returns the text editor selection.RMTextSelgetSel(double p1x, double p1y, double p2x, double p2y)Returns the selected range that would result from the given two points.intgetSelAnchor()Returns the character index of the last explicitly selected char (confined to the bounds of the selection).intgetSelEnd()Returns the character index of the end of the text selection.java.awt.geom.GeneralPathgetSelPath()Returns the path for the current selection.intgetSelStart()Returns the character index of the start of the text selection.RMTextLinegetSelStartLine()Returns the line at selection start.java.awt.geom.GeneralPathgetSpellingPath()Returns a path for misspelled word underlining.java.lang.StringgetString()Returns the plain string of the xstring being edited.RMUndoergetUndoer()Returns the undoer.protected java.lang.ObjectgetUndoSelection()Returns a selection object for undoer.doublegetWidth()Returns the bounds width.floatgetWidthToFit()Returns the width needed to display all characters.doublegetX()Returns the bounds x.RMXStringgetXString()Returns the xstring that is being edited.doublegetY()Returns the bounds y.booleanisHyphenating()Returns whether editor tries to hyphenate wrapped words.booleanisSelEmpty()Returns whether the selection is empty.booleanisSpellChecking()Returns whether editor is doing check-as-you-type spelling.booleanisUnderlined()Returns whether current selection is underlined.voidkeyBackward(boolean isShiftDown)Moves the insertion point backward a character (or if a range is selected, moves to beginning of range).voidkeyDown(boolean shiftDown)Moves the insertion point down a line, trying preserve distance from beginning of line.voidkeyForward(boolean isShiftDown)Moves the insertion point forward a character (or if a range is selected, moves to end of range).protected voidkeyPressed(java.awt.event.KeyEvent anEvent)Handle keyPressed.protected voidkeyTyped(java.awt.event.KeyEvent anEvent)Handle keyTyped.voidkeyUp(boolean shiftDown)Moves the insertion point up a line, trying to preserve distance from beginning of line.intlength()Returns the number of characters in the text string.voidmouseDragged(java.awt.event.MouseEvent anEvent)Handles mouse dragged.voidmousePressed(java.awt.event.MouseEvent anEvent)Handles mouse pressed.voidmouseReleased(java.awt.event.MouseEvent anEvent)Handles mouse released.voidpaint(java.awt.Graphics2D g)Paints a given layout in a given graphics.voidpaste()Pasts the current clipboard data over the current selection.voidprocessKeyEvent(java.awt.event.KeyEvent anEvent)Handles key events.voidpropertyChange(java.beans.PropertyChangeEvent anEvent)Called when characters where added, updated or deleted.voidredo()Called to redo the last undo operation in the editor.voidrelayout()Tells editor to rebuild layout.voidreplace(RMXString anXString)Replaces the current selection with the given xstring.voidreplace(RMXString anXString, int aStart, int anEnd, boolean doUpdateSelection)Replaces the current selection with the given xstring.voidreplace(java.lang.String aString)Replaces the current selection with the given string.voidreplace(java.lang.String aString, int aStart, int anEnd, boolean doUpdateSelection)Replaces the current selection with the given string.voidreplace(java.lang.String aString, RMTextStyle aStyle, int aStart, int anEnd, boolean doUpdateSelection)Replaces the current selection with the given string.voidreplace(java.lang.String aString, java.util.Map theAttrs, int aStart, int anEnd, boolean doUpdateSelection)Replaces the current selection with the given string.voidselectAll()Selects all the characters in the text editor.voidselectLineEnd()Moves the insertion point to next newline or text end.voidselectLineStart()Moves the insertion point to the beginning of line.voidsetAlignmentX(RMTypes.AlignX anAlignmentX)Sets the alignment for current selection.voidsetBounds(double anX, double aY, double aWidth, double aHeight)Sets the text editor bounds.voidsetBounds(java.awt.geom.Rectangle2D aRect)Sets the text editor bounds.voidsetCharSpacing(float aValue)Returns the character spacing of the current selection or cursor.voidsetColor(RMColor color)Sets the color of the current selection or cursor.voidsetFont(RMFont font)Sets the font of the current selection or cursor.voidsetFontScale(double aScale)Sets the scale applied to text when editing.voidsetFormat(RMFormat aFormat)Sets the format of the current selection or cursor, after trying to expand the selection to encompass currently selected, @-sign delineated key.voidsetInputAttribute(java.lang.String aKey, java.lang.Object aValue)Sets the attributes that are applied to current selection or newly typed chars.voidsetInputParagraph(RMParagraph ps)Sets the paragraph of the current selection or cursor position.voidsetLineGap(float aHeight)Sets the line gap for current selection.voidsetLineHeightMax(float aHeight)Sets the maximum line height for a line of text (even if font size would dictate higher).voidsetLineHeightMin(float aHeight)Sets the min line height for current selection.voidsetLineSpacing(float aHeight)Sets the line spacing for current selection.voidsetOutline(RMXString.Outline anOutline)Sets whether current selection is outlined.voidsetSel(int newStartEnd)Sets the character index of the text cursor.voidsetSel(int aStart, int anEnd)Sets the character index of the start and end of the text selection.voidsetSel(int aStart, int anEnd, int anAnchor)Sets the character index of the start and end of the text selection.voidsetSubscript()Sets current selection to subscript.voidsetSuperscript()Sets current selection to superscript.voidsetUnderlined(boolean aFlag)Sets whether current selection is underlined.voidsetXString(RMXString aString)Sets the xstring that is to be edited.java.lang.CharSequencesubSequence(int aStart, int anEnd)Returns a newCharSequencethat is a subsequence of this sequence.voidundo()Called to undo the last edit operation in the editor.protected voidundoerAddPropertyChange(java.beans.PropertyChangeEvent anEvent)Adds a property change to undoer.protected voidundoerSaveChanges()Saves changes to undoer.-
Methods inherited from class com.inductiveautomation.rm.base.RMObject
addPropertyChangeListener, animUpdate, firePropertyChange, firePropertyChange, firePropertyChange, getPCEvent, removePropertyChangeListener, sendPropertyChange, toString
-
Methods inherited from class com.inductiveautomation.rm.base.RMListenerList
addListener, clone, getListener, getListenerCount, getListenerCount, getListenerList, getListeners, hasListeners, removeListener
-
-
-
-
Method Detail
-
getXString
public RMXString getXString()
Returns the xstring that is being edited.
-
setXString
public void setXString(RMXString aString)
Sets the xstring that is to be edited.
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Returns the text editor bounds.
-
setBounds
public void setBounds(java.awt.geom.Rectangle2D aRect)
Sets the text editor bounds.
-
setBounds
public void setBounds(double anX, double aY, double aWidth, double aHeight)Sets the text editor bounds.
-
getX
public double getX()
Returns the bounds x.
-
getY
public double getY()
Returns the bounds y.
-
getWidth
public double getWidth()
Returns the bounds width.
-
getHeight
public double getHeight()
Returns the bounds height.
-
length
public int length()
Returns the number of characters in the text string.- Specified by:
lengthin interfacejava.lang.CharSequence
-
charAt
public char charAt(int anIndex)
Returns the individual character at given index.- Specified by:
charAtin interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int aStart, int anEnd)Returns a newCharSequencethat is a subsequence of this sequence.- Specified by:
subSequencein interfacejava.lang.CharSequence
-
isSpellChecking
public boolean isSpellChecking()
Returns whether editor is doing check-as-you-type spelling.
-
isHyphenating
public boolean isHyphenating()
Returns whether editor tries to hyphenate wrapped words.
-
isSelEmpty
public boolean isSelEmpty()
Returns whether the selection is empty.
-
getSel
public RMTextSel getSel()
Returns the text editor selection.
-
setSel
public void setSel(int newStartEnd)
Sets the character index of the text cursor.
-
setSel
public void setSel(int aStart, int anEnd)Sets the character index of the start and end of the text selection.
-
setSel
public void setSel(int aStart, int anEnd, int anAnchor)Sets the character index of the start and end of the text selection.
-
getSelStart
public int getSelStart()
Returns the character index of the start of the text selection.
-
getSelEnd
public int getSelEnd()
Returns the character index of the end of the text selection.
-
getSelAnchor
public int getSelAnchor()
Returns the character index of the last explicitly selected char (confined to the bounds of the selection).
-
selectAll
public void selectAll()
Selects all the characters in the text editor.
-
getSel
public RMTextSel getSel(double p1x, double p1y, double p2x, double p2y)
Returns the selected range that would result from the given two points.
-
getLineCount
public int getLineCount()
Returns the number of lines.
-
getLine
public RMTextLine getLine(int anIndex)
Returns the individual line at given index.
-
getLineForChar
public RMTextLine getLineForChar(int anIndex)
Returns the line index for the given character index.
-
getSelStartLine
public RMTextLine getSelStartLine()
Returns the line at selection start.
-
getFontScale
public double getFontScale()
Returns the scale applied to text when editing.
-
setFontScale
public void setFontScale(double aScale)
Sets the scale applied to text when editing.
-
getLayout
public RMTextLayout getLayout()
Returns the configured text layout used to layout text.
-
createLayout
public RMTextLayout createLayout()
Creates a configured text layout used to layout text.
-
relayout
public void relayout()
Tells editor to rebuild layout.
-
getCharIndex
public int getCharIndex(java.awt.geom.Point2D aPoint)
Returns the char index for given point in text coordinate space.
-
getInputStyle
public RMTextStyle getInputStyle()
Returns the text style applied to any input characters.
-
setInputAttribute
public void setInputAttribute(java.lang.String aKey, java.lang.Object aValue)Sets the attributes that are applied to current selection or newly typed chars.
-
getInputParagraph
public RMParagraph getInputParagraph()
Returns the paragraph of the current selection or cursor position.
-
setInputParagraph
public void setInputParagraph(RMParagraph ps)
Sets the paragraph of the current selection or cursor position.
-
getString
public java.lang.String getString()
Returns the plain string of the xstring being edited.
-
getColor
public RMColor getColor()
Returns the color of the current selection or cursor.
-
setColor
public void setColor(RMColor color)
Sets the color of the current selection or cursor.
-
getFont
public RMFont getFont()
Returns the font of the current selection or cursor.
-
setFont
public void setFont(RMFont font)
Sets the font of the current selection or cursor.
-
getFormat
public RMFormat getFormat()
Returns the format of the current selection or cursor.
-
setFormat
public void setFormat(RMFormat aFormat)
Sets the format of the current selection or cursor, after trying to expand the selection to encompass currently selected, @-sign delineated key.
-
isUnderlined
public boolean isUnderlined()
Returns whether current selection is underlined.
-
setUnderlined
public void setUnderlined(boolean aFlag)
Sets whether current selection is underlined.
-
getOutline
public RMXString.Outline getOutline()
Returns whether current selection is outlined.
-
setOutline
public void setOutline(RMXString.Outline anOutline)
Sets whether current selection is outlined.
-
setSuperscript
public void setSuperscript()
Sets current selection to superscript.
-
setSubscript
public void setSubscript()
Sets current selection to subscript.
-
getAlignmentX
public RMTypes.AlignX getAlignmentX()
Returns the alignment for current selection.
-
setAlignmentX
public void setAlignmentX(RMTypes.AlignX anAlignmentX)
Sets the alignment for current selection.
-
getCharSpacing
public float getCharSpacing()
Returns the character spacing of the current selection or cursor.
-
setCharSpacing
public void setCharSpacing(float aValue)
Returns the character spacing of the current selection or cursor.
-
getLineSpacing
public float getLineSpacing()
Returns the line spacing for current selection.
-
setLineSpacing
public void setLineSpacing(float aHeight)
Sets the line spacing for current selection.
-
getLineGap
public float getLineGap()
Returns the line gap for current selection.
-
setLineGap
public void setLineGap(float aHeight)
Sets the line gap for current selection.
-
getLineHeightMin
public float getLineHeightMin()
Returns the min line height for current selection.
-
setLineHeightMin
public void setLineHeightMin(float aHeight)
Sets the min line height for current selection.
-
getLineHeightMax
public float getLineHeightMax()
Returns the maximum line height for a line of text (even if font size would dictate higher).
-
setLineHeightMax
public void setLineHeightMax(float aHeight)
Sets the maximum line height for a line of text (even if font size would dictate higher).
-
delete
public void delete()
Deletes the current selection.
-
delete
public void delete(int aStart, int anEnd, boolean doUpdateSelection)Deletes the given range of chars.
-
replace
public void replace(@Nonnull java.lang.String aString)Replaces the current selection with the given string.
-
replace
public void replace(java.lang.String aString, int aStart, int anEnd, boolean doUpdateSelection)Replaces the current selection with the given string.
-
replace
public void replace(@Nonnull java.lang.String aString, java.util.Map theAttrs, int aStart, int anEnd, boolean doUpdateSelection)Replaces the current selection with the given string.
-
replace
public void replace(@Nonnull java.lang.String aString, RMTextStyle aStyle, int aStart, int anEnd, boolean doUpdateSelection)Replaces the current selection with the given string.
-
replace
public void replace(RMXString anXString)
Replaces the current selection with the given xstring.
-
replace
public void replace(RMXString anXString, int aStart, int anEnd, boolean doUpdateSelection)
Replaces the current selection with the given xstring.
-
cut
public void cut()
Copies the current selection onto the clip board, then deletes the current selection.
-
copy
public void copy()
Copies the current selection onto the clipboard.
-
paste
public void paste()
Pasts the current clipboard data over the current selection.
-
getUndoer
public RMUndoer getUndoer()
Returns the undoer.
-
undo
public void undo()
Called to undo the last edit operation in the editor.
-
redo
public void redo()
Called to redo the last undo operation in the editor.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent anEvent)
Called when characters where added, updated or deleted.- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
undoerAddPropertyChange
protected void undoerAddPropertyChange(java.beans.PropertyChangeEvent anEvent)
Adds a property change to undoer.
-
undoerSaveChanges
protected void undoerSaveChanges()
Saves changes to undoer.
-
getUndoSelection
protected java.lang.Object getUndoSelection()
Returns a selection object for undoer.
-
keyForward
public void keyForward(boolean isShiftDown)
Moves the insertion point forward a character (or if a range is selected, moves to end of range).
-
keyBackward
public void keyBackward(boolean isShiftDown)
Moves the insertion point backward a character (or if a range is selected, moves to beginning of range).
-
keyUp
public void keyUp(boolean shiftDown)
Moves the insertion point up a line, trying to preserve distance from beginning of line.
-
keyDown
public void keyDown(boolean shiftDown)
Moves the insertion point down a line, trying preserve distance from beginning of line.
-
selectLineStart
public void selectLineStart()
Moves the insertion point to the beginning of line.
-
selectLineEnd
public void selectLineEnd()
Moves the insertion point to next newline or text end.
-
deleteForward
public void deleteForward()
Deletes the character in front of the insertion point.
-
deleteToLineEnd
public void deleteToLineEnd()
Deletes the characters from the insertion point to the end of the line.
-
getWidthToFit
public float getWidthToFit()
Returns the width needed to display all characters.
-
getHeightToFit
public float getHeightToFit()
Returns the height needed to display all characters.
-
processKeyEvent
public void processKeyEvent(java.awt.event.KeyEvent anEvent)
Handles key events.
-
keyPressed
protected void keyPressed(java.awt.event.KeyEvent anEvent)
Handle keyPressed.
-
keyTyped
protected void keyTyped(java.awt.event.KeyEvent anEvent)
Handle keyTyped.
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent anEvent)
Handles mouse pressed.
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent anEvent)
Handles mouse dragged.
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent anEvent)
Handles mouse released.
-
paint
public void paint(java.awt.Graphics2D g)
Paints a given layout in a given graphics.
-
getSelPath
public java.awt.geom.GeneralPath getSelPath()
Returns the path for the current selection.
-
getSpellingPath
public java.awt.geom.GeneralPath getSpellingPath()
Returns a path for misspelled word underlining.
-
-