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 SummaryNested ClassesModifier and TypeClassDescriptionclassA class to act as text selection.Nested classes/interfaces inherited from class javax.swing.JComponentJComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.ContainerContainer.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyNested classes/interfaces inherited from interface com.inductiveautomation.rm.base.RMTypesRMTypes.Align, RMTypes.AlignX, RMTypes.AlignYNested classes/interfaces inherited from interface com.inductiveautomation.snap.text.TextTypesTextTypes.TabType
- 
Field SummaryFields inherited from class javax.swing.JComponentlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface com.inductiveautomation.snap.text.TextTypesTEXT_CHAR_SPACING, TEXT_COLOR, TEXT_FONT, TEXT_FORMAT, TEXT_LINK, TEXT_OUTLINE, TEXT_SCRIPTING, TEXT_UNDERLINE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected doubleReturns the height needed to display all characters.protected doubleReturns the width needed to display all characters.charcharAt(int anIndex) Returns the individual character at given index.voidcopy()Copies the current selection onto the clipboard.protected TextCreates a new 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 doUpdateSel) Deletes the given range of chars.voidDeletes the character before of the insertion point.voidDeletes the character after of the insertion point.voidDeletes the characters from the insertion point to the end of the line.Returns the alignment for current selection.intgetCharIndex(double anX, double aY) Returns the char index for given point in text coordinate space.intgetCharIndex(Point2D aPoint) Returns the char index for given point in text coordinate space.doubleReturns 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.intReturns the number of lines.getLineFor(int anIndex) Returns the line for the given character index or last line if at end.floatReturns the line gap for current selection.floatReturns the maximum line height for a line of text (even if font size would dictate higher).floatReturns the min line height for current selection.Returns the last line.floatReturns 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.intReturns the character index of the last explicitly selected char (confined to the bounds of the selection).Returns the selection color.intReturns the character index of the end of the text selection.Returns the path for the current selection.intReturns the number of chars in the selection.intReturns 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 ObjectReturns a selection object for undoer.voidHides the cursor.booleanReturns whether the selection is empty.booleanReturns whether current selection is underlined.protected voidkeyPressed(KeyEvent anEvent) Called when a key is pressed.protected voidkeyReleased(KeyEvent anEvent) Called when a key is released.protected voidCalled when a key is typed.intlength()Returns the number of characters in the text string.protected voidmouseDragged(MouseEvent anEvent) Handles mouse dragged.protected voidmousePressed(MouseEvent anEvent) Handles mouse pressed.protected voidmouseReleased(MouseEvent anEvent) Handles mouse released.protected voidpaintBackground(Graphics2D aGraphics) Paints background.voidOverrides JComponent to paint text editor text.protected voidpaintLine(Graphics2D aGraphics, TextLine aLine, double anX, double aY) Paints a TextLine.protected voidpaintText(Graphics2D aGraphics) Paints text area lines.protected voidpaintTextSelection(Graphics2D aGraphics) Paints text selection.protected voidpaintToken(Graphics2D aGraphics, TextToken aToken, double anX, double aY) Paints a TextToken.voidpaste()Pasts the current clipboard data over the current selection.protected voidprocessComponentKeyEvent(KeyEvent anEvent) Overrides JComponent to forward to keyPressed(), keyReleased(), keyTyped().protected voidOverride to show hidden cursor.protected voidprocessMouseEvent(MouseEvent anEvent) Overrides JComponent method to forward mouse pressed/released to text editor.protected voidprocessMouseMotionEvent(MouseEvent anEvent) Overrides JComponent method to forward mouse drags to text editor.voidpropertyChange(PropertyChangeEvent anEvent) Called when characters where added, updated or deleted.booleanredo()Called to redo the last undo operation in the editor.voidReplaces the current selection with the given string.voidReplaces the current selection with the given string.voidSelects all the characters in the text editor.voidselectBackward(boolean isShiftDown) Moves the selection index backward a character (or if a range is selected, moves to beginning of range).voidMoves the selection index down a line, trying preserve distance from beginning of line.voidselectForward(boolean isShiftDown) Moves the selection index forward a character (or if a range is selected, moves to end of range).voidMoves the insertion point to next newline or text end.voidMoves the insertion point to the beginning of line.voidselectUp()Moves the selection index up a line, trying to preserve distance from beginning of line.voidsetAlignX(RMTypes.AlignX anAlignX) Sets the alignment for current selection.voidsetBounds(int x, int y, int w, int h) Overrides JComponent method to update TextEditor.Text bounds.voidsetCharSpacing(float aValue) Returns the character spacing of the current selection or cursor.voidSets the color of the current selection or cursor.voidSet AWT Font for current selection.voidsetInputAttribute(String aKey, Object aValue) Sets the attributes that are applied to current selection or newly typed chars.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.voidSets the text margins.protected voidsetRenderingHints(Graphics2D aGraphics) Sets rendering hints for text render.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.voidSet the source for TextComponent text.voidSet text string of text editor.voidSets current selection to subscript.voidSets current selection to superscript.voidSets the text that is to be edited.voidsetTextFont(SnapFont aFont) Sets the font of the current selection or cursor.protected voidSets the Text.Rect from text area.voidsetUnderlined(boolean aFlag) Sets whether current selection is underlined.voidShows the cursor.subSequence(int aStart, int anEnd) Returns a newCharSequencethat is a subsequence of this sequence.booleanundo()Called to undo the last edit operation in the editor.protected voidAdds a property change to undoer.voidSaves changes to undoer.Methods inherited from class javax.swing.JComponentaddAncestorListener, 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, updateUIMethods inherited from class java.awt.Containeradd, 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, validateTreeMethods inherited from class java.awt.Componentaction, 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, transferFocusUpCycleMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequencechars, codePoints, isEmpty, toString
- 
Constructor Details- 
TextComponentpublic TextComponent()Creates a new TextComponent.
 
- 
- 
Method Details- 
setSourceSet the source for TextComponent text.
- 
getTextReturns the text that is being edited.
- 
setTextSets the text that is to be edited.
- 
createTextCreates a new Text.
- 
lengthpublic int length()Returns the number of characters in the text string.- Specified by:
- lengthin interface- CharSequence
 
- 
charAtpublic char charAt(int anIndex) Returns the individual character at given index.- Specified by:
- charAtin interface- CharSequence
 
- 
subSequenceReturns a newCharSequencethat is a subsequence of this sequence.- Specified by:
- subSequencein interface- CharSequence
 
- 
getStringReturns the plain string of the text being edited.
- 
setStringSet text string of text editor.
- 
getLineCountpublic int getLineCount()Returns the number of lines.
- 
getLineReturns the individual line at given index.
- 
getLineLastReturns the last line.
- 
getLineAtReturns the line for the given character index.
- 
getLineForReturns the line for the given character index or last line if at end.
- 
getTokenAtReturns the token for given character index.
- 
getCharIndexReturns the char index for given point in text coordinate space.
- 
getCharIndexpublic int getCharIndex(double anX, double aY) Returns the char index for given point in text coordinate space.
- 
getMarginReturns the text margins.
- 
setMarginSets the text margins.
- 
isSelEmptypublic boolean isSelEmpty()Returns whether the selection is empty.
- 
getSelSizepublic int getSelSize()Returns the number of chars in the selection.
- 
getSelStartpublic int getSelStart()Returns the character index of the start of the text selection.
- 
getSelEndpublic int getSelEnd()Returns the character index of the end of the text selection.
- 
getSelAnchorpublic int getSelAnchor()Returns the character index of the last explicitly selected char (confined to the bounds of the selection).
- 
getSelReturns the selection.
- 
setSelpublic void setSel(int newStartEnd) Sets the character index of the text cursor.
- 
setSelpublic void setSel(int aStart, int anEnd) Sets the character index of the start and end of the text selection.
- 
setSelpublic void setSel(int aStart, int anEnd, int anAnchor) Sets the character index of the start and end of the text selection.
- 
selectAllpublic void selectAll()Selects all the characters in the text editor.
- 
selectForwardpublic void selectForward(boolean isShiftDown) Moves the selection index forward a character (or if a range is selected, moves to end of range).
- 
selectBackwardpublic void selectBackward(boolean isShiftDown) Moves the selection index backward a character (or if a range is selected, moves to beginning of range).
- 
selectUppublic void selectUp()Moves the selection index up a line, trying to preserve distance from beginning of line.
- 
selectDownpublic void selectDown()Moves the selection index down a line, trying preserve distance from beginning of line.
- 
selectLineStartpublic void selectLineStart()Moves the insertion point to the beginning of line.
- 
selectLineEndpublic void selectLineEnd()Moves the insertion point to next newline or text end.
- 
replaceReplaces the current selection with the given string.
- 
replaceReplaces the current selection with the given string.
- 
deletepublic void delete()Deletes the current selection.
- 
deletepublic void delete(int aStart, int anEnd, boolean doUpdateSel) Deletes the given range of chars.
- 
deleteBackwardpublic void deleteBackward()Deletes the character before of the insertion point.
- 
deleteForwardpublic void deleteForward()Deletes the character after of the insertion point.
- 
deleteToLineEndpublic void deleteToLineEnd()Deletes the characters from the insertion point to the end of the line.
- 
getInputStyleReturns the TextStyle applied to any input characters.
- 
setInputAttributeSets the attributes that are applied to current selection or newly typed chars.
- 
getInputLineReturns the line for the current selection start index.
- 
getColorReturns the color of the current selection or cursor.
- 
setColorSets the color of the current selection or cursor.
- 
getTextFontReturns the font of the current selection or cursor.
- 
setTextFontSets the font of the current selection or cursor.
- 
setFontSet AWT Font for current selection.- Overrides:
- setFontin class- JComponent
 
- 
isUnderlinedpublic boolean isUnderlined()Returns whether current selection is underlined.
- 
setUnderlinedpublic void setUnderlined(boolean aFlag) Sets whether current selection is underlined.
- 
setSuperscriptpublic void setSuperscript()Sets current selection to superscript.
- 
setSubscriptpublic void setSubscript()Sets current selection to subscript.
- 
getAlignXReturns the alignment for current selection.
- 
setAlignXSets the alignment for current selection.
- 
getCharSpacingpublic double getCharSpacing()Returns the character spacing of the current selection or cursor.
- 
setCharSpacingpublic void setCharSpacing(float aValue) Returns the character spacing of the current selection or cursor.
- 
getLineSpacingpublic float getLineSpacing()Returns the line spacing for current selection.
- 
setLineSpacingpublic void setLineSpacing(float aHeight) Sets the line spacing for current selection.
- 
getLineGappublic float getLineGap()Returns the line gap for current selection.
- 
setLineGappublic void setLineGap(float aHeight) Sets the line gap for current selection.
- 
getLineHeightMinpublic float getLineHeightMin()Returns the min line height for current selection.
- 
setLineHeightMinpublic void setLineHeightMin(float aHeight) Sets the min line height for current selection.
- 
getLineHeightMaxpublic float getLineHeightMax()Returns the maximum line height for a line of text (even if font size would dictate higher).
- 
setLineHeightMaxpublic void setLineHeightMax(float aHeight) Sets the maximum line height for a line of text (even if font size would dictate higher).
- 
setBoundspublic void setBounds(int x, int y, int w, int h) Overrides JComponent method to update TextEditor.Text bounds.
- 
getPreferredSizeOverrides JComponent method to declare preferred size to be text's preferred size.- Overrides:
- getPreferredSizein class- JComponent
 
- 
calcPrefWidthprotected double calcPrefWidth()Returns the width needed to display all characters.
- 
calcPrefHeightprotected double calcPrefHeight()Returns the height needed to display all characters.
- 
setTextRectprotected void setTextRect()Sets the Text.Rect from text area.
- 
getSelColorReturns the selection color.
- 
paintComponentOverrides JComponent to paint text editor text.- Overrides:
- paintComponentin class- JComponent
 
- 
paintBackgroundPaints background.
- 
paintTextSelectionPaints text selection.
- 
paintTextPaints text area lines.
- 
paintLinePaints a TextLine.
- 
paintTokenPaints a TextToken.
- 
setRenderingHintsSets rendering hints for text render.
- 
getSelPathReturns the path for the current selection.
- 
getPathForCharsReturns a path for two char indexes - it will be a a simple box with extensions for first/last lines.
- 
processMouseEventOverrides JComponent method to forward mouse pressed/released to text editor.- Overrides:
- processMouseEventin class- JComponent
 
- 
processMouseMotionEventOverrides JComponent method to forward mouse drags to text editor.- Overrides:
- processMouseMotionEventin class- JComponent
 
- 
mousePressedHandles mouse pressed.
- 
mouseDraggedHandles mouse dragged.
- 
mouseReleasedHandles mouse released.
- 
processComponentKeyEventOverrides JComponent to forward to keyPressed(), keyReleased(), keyTyped().- Overrides:
- processComponentKeyEventin class- JComponent
 
- 
keyTypedCalled when a key is typed.
- 
keyPressedCalled when a key is pressed.
- 
keyReleasedCalled when a key is released.
- 
processFocusEventOverride to show hidden cursor.- Overrides:
- processFocusEventin class- Component
 
- 
showCursorpublic void showCursor()Shows the cursor.
- 
hideCursorpublic void hideCursor()Hides the cursor.
- 
cutpublic void cut()Copies the current selection onto the clip board, then deletes the current selection.
- 
copypublic void copy()Copies the current selection onto the clipboard.
- 
pastepublic void paste()Pasts the current clipboard data over the current selection.
- 
getUndoerReturns the undoer.
- 
undopublic boolean undo()Called to undo the last edit operation in the editor.
- 
redopublic boolean redo()Called to redo the last undo operation in the editor.
- 
undoerAddPropertyChangeAdds a property change to undoer.
- 
undoerSaveChangespublic void undoerSaveChanges()Saves changes to undoer.
- 
getUndoSelectionReturns a selection object for undoer.
- 
propertyChangeCalled when characters where added, updated or deleted.- Specified by:
- propertyChangein interface- PropertyChangeListener
 
 
-