Class TextComponent
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.inductiveautomation.snap.swing.TextComponent
- All Implemented Interfaces:
RMTypes
,TextTypes
,ImageObserver
,MenuContainer
,PropertyChangeListener
,Serializable
,CharSequence
,EventListener
- Direct Known Subclasses:
TextArea
public class TextComponent
extends JComponent
implements PropertyChangeListener, TextTypes, CharSequence
A base class for using Snap Text in Swing.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
A class to act as text selection.Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Nested classes/interfaces inherited from interface com.inductiveautomation.rm.base.RMTypes
RMTypes.Align, RMTypes.AlignX, RMTypes.AlignY
Nested classes/interfaces inherited from interface com.inductiveautomation.snap.text.TextTypes
TextTypes.TabType
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface com.inductiveautomation.snap.text.TextTypes
TEXT_CHAR_SPACING, TEXT_COLOR, TEXT_FONT, TEXT_FORMAT, TEXT_LINK, TEXT_OUTLINE, TEXT_SCRIPTING, TEXT_UNDERLINE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected double
Returns the height needed to display all characters.protected double
Returns the width needed to display all characters.char
charAt
(int anIndex) Returns the individual character at given index.void
copy()
Copies the current selection onto the clipboard.protected Text
Creates a new Text.void
cut()
Copies the current selection onto the clip board, then deletes the current selection.void
delete()
Deletes the current selection.void
delete
(int aStart, int anEnd, boolean doUpdateSel) Deletes the given range of chars.void
Deletes the character before of the insertion point.void
Deletes the character after of the insertion point.void
Deletes the characters from the insertion point to the end of the line.Returns the alignment for current selection.int
getCharIndex
(double anX, double aY) Returns the char index for given point in text coordinate space.int
getCharIndex
(Point2D aPoint) Returns the char index for given point in text coordinate space.double
Returns the character spacing of the current selection or cursor.getColor()
Returns the color of the current selection or cursor.Returns the line for the current selection start index.Returns the TextStyle applied to any input characters.getLine
(int anIndex) Returns the individual line at given index.getLineAt
(int anIndex) Returns the line for the given character index.int
Returns the number of lines.getLineFor
(int anIndex) Returns the line for the given character index or last line if at end.float
Returns the line gap for current selection.float
Returns the maximum line height for a line of text (even if font size would dictate higher).float
Returns the min line height for current selection.Returns the last line.float
Returns the line spacing for current selection.Returns the text margins.getPathForChars
(int aStart, int anEnd) Returns a path for two char indexes - it will be a a simple box with extensions for first/last lines.Overrides JComponent method to declare preferred size to be text's preferred size.getSel()
Returns the selection.int
Returns the character index of the last explicitly selected char (confined to the bounds of the selection).Returns the selection color.int
Returns the character index of the end of the text selection.Returns the path for the current selection.int
Returns the number of chars in the selection.int
Returns the character index of the start of the text selection.Returns the plain string of the text being edited.getText()
Returns the text that is being edited.Returns the font of the current selection or cursor.getTokenAt
(int anIndex) Returns the token for given character index.Returns the undoer.protected Object
Returns a selection object for undoer.void
Hides the cursor.boolean
Returns whether the selection is empty.boolean
Returns whether current selection is underlined.protected void
keyPressed
(KeyEvent anEvent) Called when a key is pressed.protected void
keyReleased
(KeyEvent anEvent) Called when a key is released.protected void
Called when a key is typed.int
length()
Returns the number of characters in the text string.protected void
mouseDragged
(MouseEvent anEvent) Handles mouse dragged.protected void
mousePressed
(MouseEvent anEvent) Handles mouse pressed.protected void
mouseReleased
(MouseEvent anEvent) Handles mouse released.protected void
paintBackground
(Graphics2D aGraphics) Paints background.void
Overrides JComponent to paint text editor text.protected void
paintLine
(Graphics2D aGraphics, TextLine aLine, double anX, double aY) Paints a TextLine.protected void
paintText
(Graphics2D aGraphics) Paints text area lines.protected void
paintTextSelection
(Graphics2D aGraphics) Paints text selection.protected void
paintToken
(Graphics2D aGraphics, TextToken aToken, double anX, double aY) Paints a TextToken.void
paste()
Pasts the current clipboard data over the current selection.protected void
processComponentKeyEvent
(KeyEvent anEvent) Overrides JComponent to forward to keyPressed(), keyReleased(), keyTyped().protected void
Override to show hidden cursor.protected void
processMouseEvent
(MouseEvent anEvent) Overrides JComponent method to forward mouse pressed/released to text editor.protected void
processMouseMotionEvent
(MouseEvent anEvent) Overrides JComponent method to forward mouse drags to text editor.void
propertyChange
(PropertyChangeEvent anEvent) Called when characters where added, updated or deleted.boolean
redo()
Called to redo the last undo operation in the editor.void
Replaces the current selection with the given string.void
Replaces the current selection with the given string.void
Selects all the characters in the text editor.void
selectBackward
(boolean isShiftDown) Moves the selection index backward a character (or if a range is selected, moves to beginning of range).void
Moves the selection index down a line, trying preserve distance from beginning of line.void
selectForward
(boolean isShiftDown) Moves the selection index forward a character (or if a range is selected, moves to end of range).void
Moves the insertion point to next newline or text end.void
Moves the insertion point to the beginning of line.void
selectUp()
Moves the selection index up a line, trying to preserve distance from beginning of line.void
setAlignX
(RMTypes.AlignX anAlignX) Sets the alignment for current selection.void
setBounds
(int x, int y, int w, int h) Overrides JComponent method to update TextEditor.Text bounds.void
setCharSpacing
(float aValue) Returns the character spacing of the current selection or cursor.void
Sets the color of the current selection or cursor.void
Set AWT Font for current selection.void
setInputAttribute
(String aKey, Object aValue) Sets the attributes that are applied to current selection or newly typed chars.void
setLineGap
(float aHeight) Sets the line gap for current selection.void
setLineHeightMax
(float aHeight) Sets the maximum line height for a line of text (even if font size would dictate higher).void
setLineHeightMin
(float aHeight) Sets the min line height for current selection.void
setLineSpacing
(float aHeight) Sets the line spacing for current selection.void
Sets the text margins.protected void
setRenderingHints
(Graphics2D aGraphics) Sets rendering hints for text render.void
setSel
(int newStartEnd) Sets the character index of the text cursor.void
setSel
(int aStart, int anEnd) Sets the character index of the start and end of the text selection.void
setSel
(int aStart, int anEnd, int anAnchor) Sets the character index of the start and end of the text selection.void
Set the source for TextComponent text.void
Set text string of text editor.void
Sets current selection to subscript.void
Sets current selection to superscript.void
Sets the text that is to be edited.void
setTextFont
(SnapFont aFont) Sets the font of the current selection or cursor.protected void
Sets the Text.Rect from text area.void
setUnderlined
(boolean aFlag) Sets whether current selection is underlined.void
Shows the cursor.subSequence
(int aStart, int anEnd) Returns a newCharSequence
that is a subsequence of this sequence.boolean
undo()
Called to undo the last edit operation in the editor.protected void
Adds a property change to undoer.void
Saves changes to undoer.Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty, toString
-
Constructor Details
-
TextComponent
public TextComponent()Creates a new TextComponent.
-
-
Method Details
-
setSource
Set the source for TextComponent text. -
getText
Returns the text that is being edited. -
setText
Sets the text that is to be edited. -
createText
Creates a new Text. -
length
public int length()Returns the number of characters in the text string.- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int anIndex) Returns the individual character at given index.- Specified by:
charAt
in interfaceCharSequence
-
subSequence
Returns a newCharSequence
that is a subsequence of this sequence.- Specified by:
subSequence
in interfaceCharSequence
-
getString
Returns the plain string of the text being edited. -
setString
Set text string of text editor. -
getLineCount
public int getLineCount()Returns the number of lines. -
getLine
Returns the individual line at given index. -
getLineLast
Returns the last line. -
getLineAt
Returns the line for the given character index. -
getLineFor
Returns the line for the given character index or last line if at end. -
getTokenAt
Returns the token for given character index. -
getCharIndex
Returns the char index for given point in text coordinate space. -
getCharIndex
public int getCharIndex(double anX, double aY) Returns the char index for given point in text coordinate space. -
getMargin
Returns the text margins. -
setMargin
Sets the text margins. -
isSelEmpty
public boolean isSelEmpty()Returns whether the selection is empty. -
getSelSize
public int getSelSize()Returns the number of chars in the 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). -
getSel
Returns the 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. -
selectAll
public void selectAll()Selects all the characters in the text editor. -
selectForward
public void selectForward(boolean isShiftDown) Moves the selection index forward a character (or if a range is selected, moves to end of range). -
selectBackward
public void selectBackward(boolean isShiftDown) Moves the selection index backward a character (or if a range is selected, moves to beginning of range). -
selectUp
public void selectUp()Moves the selection index up a line, trying to preserve distance from beginning of line. -
selectDown
public void selectDown()Moves the selection index 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. -
replace
Replaces the current selection with the given string. -
replace
Replaces the current selection with the given string. -
delete
public void delete()Deletes the current selection. -
delete
public void delete(int aStart, int anEnd, boolean doUpdateSel) Deletes the given range of chars. -
deleteBackward
public void deleteBackward()Deletes the character before of the insertion point. -
deleteForward
public void deleteForward()Deletes the character after of the insertion point. -
deleteToLineEnd
public void deleteToLineEnd()Deletes the characters from the insertion point to the end of the line. -
getInputStyle
Returns the TextStyle applied to any input characters. -
setInputAttribute
Sets the attributes that are applied to current selection or newly typed chars. -
getInputLine
Returns the line for the current selection start index. -
getColor
Returns the color of the current selection or cursor. -
setColor
Sets the color of the current selection or cursor. -
getTextFont
Returns the font of the current selection or cursor. -
setTextFont
Sets the font of the current selection or cursor. -
setFont
Set AWT Font for current selection.- Overrides:
setFont
in classJComponent
-
isUnderlined
public boolean isUnderlined()Returns whether current selection is underlined. -
setUnderlined
public void setUnderlined(boolean aFlag) Sets whether current selection is underlined. -
setSuperscript
public void setSuperscript()Sets current selection to superscript. -
setSubscript
public void setSubscript()Sets current selection to subscript. -
getAlignX
Returns the alignment for current selection. -
setAlignX
Sets the alignment for current selection. -
getCharSpacing
public double 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). -
setBounds
public void setBounds(int x, int y, int w, int h) Overrides JComponent method to update TextEditor.Text bounds. -
getPreferredSize
Overrides JComponent method to declare preferred size to be text's preferred size.- Overrides:
getPreferredSize
in classJComponent
-
calcPrefWidth
protected double calcPrefWidth()Returns the width needed to display all characters. -
calcPrefHeight
protected double calcPrefHeight()Returns the height needed to display all characters. -
setTextRect
protected void setTextRect()Sets the Text.Rect from text area. -
getSelColor
Returns the selection color. -
paintComponent
Overrides JComponent to paint text editor text.- Overrides:
paintComponent
in classJComponent
-
paintBackground
Paints background. -
paintTextSelection
Paints text selection. -
paintText
Paints text area lines. -
paintLine
Paints a TextLine. -
paintToken
Paints a TextToken. -
setRenderingHints
Sets rendering hints for text render. -
getSelPath
Returns the path for the current selection. -
getPathForChars
Returns a path for two char indexes - it will be a a simple box with extensions for first/last lines. -
processMouseEvent
Overrides JComponent method to forward mouse pressed/released to text editor.- Overrides:
processMouseEvent
in classJComponent
-
processMouseMotionEvent
Overrides JComponent method to forward mouse drags to text editor.- Overrides:
processMouseMotionEvent
in classJComponent
-
mousePressed
Handles mouse pressed. -
mouseDragged
Handles mouse dragged. -
mouseReleased
Handles mouse released. -
processComponentKeyEvent
Overrides JComponent to forward to keyPressed(), keyReleased(), keyTyped().- Overrides:
processComponentKeyEvent
in classJComponent
-
keyTyped
Called when a key is typed. -
keyPressed
Called when a key is pressed. -
keyReleased
Called when a key is released. -
processFocusEvent
Override to show hidden cursor.- Overrides:
processFocusEvent
in classComponent
-
showCursor
public void showCursor()Shows the cursor. -
hideCursor
public void hideCursor()Hides the cursor. -
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
Returns the undoer. -
undo
public boolean undo()Called to undo the last edit operation in the editor. -
redo
public boolean redo()Called to redo the last undo operation in the editor. -
undoerAddPropertyChange
Adds a property change to undoer. -
undoerSaveChanges
public void undoerSaveChanges()Saves changes to undoer. -
getUndoSelection
Returns a selection object for undoer. -
propertyChange
Called when characters where added, updated or deleted.- Specified by:
propertyChange
in interfacePropertyChangeListener
-