public class JEditTextArea extends JComponent implements Scrollable
JEditTextArea ta = new JEditTextArea(); ta.setTokenMarker( new JavaTokenMarker() ); ta.setText( "public class Test {\n" + " public static void main(String[] args) {\n" + " System.out.println(\"Hello World\");\n" + " }\n" + "}" );
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected boolean |
biasLeft |
protected boolean |
blink |
protected static String |
BOTTOM |
protected int |
bracketLine |
protected int |
bracketPosition |
protected boolean |
caretBlinks |
protected org.syntax.jedit.JEditTextArea.MutableCaretEvent |
caretEvent |
protected static Timer |
caretTimer |
protected boolean |
caretVisible |
protected static String |
CENTER |
protected SyntaxDocument |
document |
protected org.syntax.jedit.JEditTextArea.DocumentHandler |
documentHandler |
protected boolean |
editable |
protected int |
firstLine |
protected static WeakReference<JEditTextArea> |
focusedComponentRef |
protected InputHandler |
inputHandler |
static String |
LEFT_OF_SCROLLBAR
Adding components with this name to the text area will place them left of
the horizontal scroll bar.
|
protected Segment |
lineSegment |
protected EventListenerList |
listenerList |
protected int |
magicCaret |
protected boolean |
overwrite |
protected TextAreaPainter |
painter |
protected JPopupMenu |
popup |
protected boolean |
rectSelect |
protected static String |
RIGHT |
protected boolean |
scrollBarsInitialized |
protected int |
selectionEnd |
protected int |
selectionEndLine |
protected int |
selectionStart |
protected int |
selectionStartLine |
protected int |
visibleLines |
TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JEditTextArea()
Creates a new JEditTextArea with the default settings.
|
JEditTextArea(TextAreaDefaults defaults)
Creates a new JEditTextArea with the specified settings.
|
Modifier and Type | Method and Description |
---|---|
int |
_offsetToX(int line,
int offset)
Converts an offset in a line into an x co-ordinate.
|
void |
addCaretListener(CaretListener listener)
Adds a caret change listener to this text area.
|
void |
addNotify() |
void |
blinkCaret()
Blinks the caret.
|
void |
copy()
Places the selected text into the clipboard.
|
protected TextAreaPainter |
createPainter(TextAreaDefaults defaults)
Allow subclasses to override.
|
void |
cut()
Deletes the selected text from the text area and places it into the
clipboard.
|
protected void |
documentChanged(DocumentEvent evt) |
protected void |
fireCaretEvent() |
int |
getBracketLine()
Returns the line of the highlighted bracket (the bracket matching the one
before the caret)
|
int |
getBracketPosition()
Returns the position of the highlighted bracket (the bracket matching the
one before the caret)
|
int |
getCaretLine()
Returns the caret line.
|
int |
getCaretPosition()
Returns the caret position.
|
SyntaxDocument |
getDocument()
Returns the document this text area is editing.
|
int |
getDocumentLength()
Returns the length of the document.
|
int |
getFirstLine()
Returns the line displayed at the text area's origin.
|
InputHandler |
getInputHandler()
Returns the input handler.
|
int |
getLineCount()
Returns the number of lines in the document.
|
int |
getLineEndOffset(int line)
Returns the end offset of the specified line.
|
int |
getLineHeight() |
int |
getLineLength(int line)
Returns the length of the specified line.
|
int |
getLineOfOffset(int offset)
Returns the line containing the specified offset.
|
int |
getLineStartOffset(int line)
Returns the start offset of the specified line.
|
String |
getLineText(int lineIndex)
Returns the text on the specified line.
|
void |
getLineText(int lineIndex,
Segment segment)
Copies the text on the specified line into a segment.
|
int |
getMagicCaretPosition()
Returns the `magic' caret position.
|
int |
getMarkLine()
Returns the mark line.
|
int |
getMarkPosition()
Returns the mark position.
|
Dimension |
getMaximumSize() |
int |
getMaxLineLength() |
Dimension |
getMinimumSize() |
TextAreaPainter |
getPainter()
Returns the object responsible for painting this text area.
|
Dimension |
getPreferredScrollableViewportSize() |
Dimension |
getPreferredSize() |
JPopupMenu |
getRightClickPopup()
Returns the right click popup menu.
|
int |
getScrollableBlockIncrement(Rectangle arg0,
int arg1,
int arg2) |
boolean |
getScrollableTracksViewportHeight() |
boolean |
getScrollableTracksViewportWidth() |
int |
getScrollableUnitIncrement(Rectangle arg0,
int arg1,
int arg2) |
String |
getSelectedText()
Returns the selected text, or null if no selection is active.
|
int |
getSelectionEnd()
Returns the selection end offset.
|
int |
getSelectionEnd(int line)
Returns the offset where the selection ends on the specified line.
|
int |
getSelectionEndLine()
Returns the selection end line.
|
int |
getSelectionStart()
Returns the selection start offset.
|
int |
getSelectionStart(int line)
Returns the offset where the selection starts on the specified line.
|
int |
getSelectionStartLine()
Returns the selection start line.
|
int |
getTabExpandedLineLength(int line)
Returns the length of the specified line.
|
String |
getText()
Returns the entire text of this text area.
|
String |
getText(int start,
int len)
Returns the specified substring of the document.
|
void |
getText(int start,
int len,
Segment segment)
Copies the specified substring of the document into a segment.
|
TokenMarker |
getTokenMarker()
Returns the document's token marker.
|
int |
getVisibleLines()
Returns the number of lines visible in this text area.
|
boolean |
isCaretBlinkEnabled()
Returns true if the caret is blinking, false otherwise.
|
boolean |
isCaretVisible()
Returns true if the caret is visible, false otherwise.
|
boolean |
isEditable()
Returns true if this text area is editable, false otherwise.
|
boolean |
isManagingFocus()
Returns if this component can be traversed by pressing the Tab key.
|
boolean |
isOverwriteEnabled()
Returns true if overwrite mode is enabled, false otherwise.
|
boolean |
isSelectionRectangular()
Returns true if the selection is rectangular, false otherwise.
|
int |
lineToY(int line)
Converts a line index to a y co-ordinate.
|
int |
offsetToX(int line,
int offset)
Converts an offset in a line into an x co-ordinate.
|
void |
overwriteSetSelectedText(String str)
Similar to
setSelectedText() , but overstrikes the appropriate
number of characters if overwrite mode is enabled. |
void |
paste()
Inserts the clipboard contents into the text.
|
int |
pointToOffset(Point pt) |
void |
processKeyEvent(KeyEvent evt)
Forwards key events directly to the input handler.
|
void |
recalculateVisibleLines()
Recalculates the number of visible lines.
|
void |
removeCaretListener(CaretListener listener)
Removes a caret change listener from this text area.
|
void |
removeNotify()
Called by the AWT when this component is removed from it's parent.
|
void |
scrollTo(int line,
int offset)
Ensures that the specified line and offset is visible by scrolling the
text area if necessary.
|
void |
scrollToCaret()
Ensures that the caret is visible by scrolling the text area if necessary.
|
void |
select(int start,
int end)
Selects from the start offset to the end offset.
|
void |
selectAll()
Selects all text in the document.
|
void |
selectNone()
Moves the mark to the caret position.
|
void |
setCaretBlinkEnabled(boolean caretBlinks)
Toggles caret blinking.
|
void |
setCaretPosition(int caret)
Sets the caret position.
|
void |
setCaretVisible(boolean caretVisible)
Sets if the caret should be visible.
|
void |
setDocument(SyntaxDocument document)
Sets the document this text area is editing.
|
void |
setEditable(boolean editable)
Sets if this component is editable.
|
void |
setFirstLine(int firstLine)
Sets the line displayed at the text area's origin without updating the
scroll bars.
|
void |
setInputHandler(InputHandler inputHandler)
Sets the input handler.
|
void |
setMagicCaretPosition(int magicCaret)
Sets the `magic' caret position.
|
void |
setOverwriteEnabled(boolean overwrite)
Sets if overwrite mode should be enabled.
|
void |
setRightClickPopup(JPopupMenu popup)
Sets the right click popup menu.
|
void |
setSelectedText(String selectedText)
Replaces the selection with the specified text.
|
void |
setSelectionEnd(int selectionEnd)
Sets the selection end.
|
void |
setSelectionRectangular(boolean rectSelect)
Sets if the selection should be rectangular.
|
void |
setSelectionStart(int selectionStart)
Sets the selection start.
|
void |
setText(String text)
Sets the entire text of this text area.
|
void |
setTokenMarker(TokenMarker tokenMarker)
Sets the document's token marker.
|
protected void |
updateBracketHighlight(int newCaretPosition) |
void |
updateScrollBars()
Updates the state of the scroll bars.
|
int |
xToOffset(int line,
int x)
Converts an x co-ordinate to an offset within a line.
|
int |
xyToOffset(int x,
int y)
Converts a point to an offset, from the start of the text.
|
int |
yToLine(int y)
Converts a y co-ordinate to a line index.
|
addAncestorListener, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
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
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, getPeer, 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, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final String LEFT_OF_SCROLLBAR
protected static final String CENTER
protected static final String RIGHT
protected static final String BOTTOM
protected static WeakReference<JEditTextArea> focusedComponentRef
protected static final Timer caretTimer
protected TextAreaPainter painter
protected JPopupMenu popup
protected EventListenerList listenerList
protected org.syntax.jedit.JEditTextArea.MutableCaretEvent caretEvent
protected boolean caretBlinks
protected boolean caretVisible
protected boolean blink
protected boolean editable
protected int firstLine
protected int visibleLines
protected boolean scrollBarsInitialized
protected InputHandler inputHandler
protected SyntaxDocument document
protected org.syntax.jedit.JEditTextArea.DocumentHandler documentHandler
protected Segment lineSegment
protected int selectionStart
protected int selectionStartLine
protected int selectionEnd
protected int selectionEndLine
protected boolean biasLeft
protected int bracketPosition
protected int bracketLine
protected int magicCaret
protected boolean overwrite
protected boolean rectSelect
public JEditTextArea()
public JEditTextArea(TextAreaDefaults defaults)
defaults
- The default settingsprotected TextAreaPainter createPainter(TextAreaDefaults defaults)
defaults
- public final boolean isManagingFocus()
isManagingFocus
in class JComponent
public final TextAreaPainter getPainter()
public final InputHandler getInputHandler()
public void setInputHandler(InputHandler inputHandler)
inputHandler
- The new input handlerpublic final boolean isCaretBlinkEnabled()
public void setCaretBlinkEnabled(boolean caretBlinks)
caretBlinks
- True if the caret should blink, false otherwisepublic final boolean isCaretVisible()
public void setCaretVisible(boolean caretVisible)
caretVisible
- True if the caret should be visible, false otherwisepublic final void blinkCaret()
public void updateScrollBars()
public final int getFirstLine()
public void setFirstLine(int firstLine)
public final int getVisibleLines()
public final void recalculateVisibleLines()
public void scrollToCaret()
public void scrollTo(int line, int offset)
line
- The line to scroll tooffset
- The offset in the line to scroll topublic int lineToY(int line)
line
- The linepublic int getLineHeight()
public int yToLine(int y)
y
- The y co-ordinatepublic final int offsetToX(int line, int offset)
line
- The lineoffset
- The offset, from the start of the linepublic int _offsetToX(int line, int offset)
line
- The lineoffset
- The offset, from the start of the linepublic int xToOffset(int line, int x)
line
- The linex
- The x co-ordinatepublic int xyToOffset(int x, int y)
x
- The x co-ordinate of the pointy
- The y co-ordinate of the pointpublic int pointToOffset(Point pt)
public final SyntaxDocument getDocument()
public void setDocument(SyntaxDocument document)
document
- The documentpublic final TokenMarker getTokenMarker()
getDocument().getTokenMarker()
.public final void setTokenMarker(TokenMarker tokenMarker)
getDocument().setTokenMarker()
.tokenMarker
- The token markerpublic final int getDocumentLength()
getDocument().getLength()
.public final int getLineCount()
public final int getLineOfOffset(int offset)
offset
- The offsetpublic int getLineStartOffset(int line)
line
- The linepublic int getLineEndOffset(int line)
line
- The linepublic int getTabExpandedLineLength(int line)
line
- The linepublic int getLineLength(int line)
line
- The linepublic String getText()
public void setText(String text)
public final String getText(int start, int len)
start
- The start offsetlen
- The length of the substringpublic final void getText(int start, int len, Segment segment)
start
- The start offsetlen
- The length of the substringsegment
- The segmentpublic final String getLineText(int lineIndex)
lineIndex
- The linepublic final void getLineText(int lineIndex, Segment segment)
lineIndex
- The linepublic final int getSelectionStart()
public int getSelectionStart(int line)
public final int getSelectionStartLine()
public final void setSelectionStart(int selectionStart)
selectionStart
- The selection startselect(int, int)
public final int getSelectionEnd()
public int getSelectionEnd(int line)
public final int getSelectionEndLine()
public final void setSelectionEnd(int selectionEnd)
selectionEnd
- The selection endselect(int, int)
public final int getCaretPosition()
public final int getCaretLine()
public final int getMarkPosition()
getCaretPosition()
public final int getMarkLine()
public final void setCaretPosition(int caret)
caret
- The caret positionselect(int, int)
public final void selectAll()
public final void selectNone()
public void select(int start, int end)
start
- The start offsetend
- The end offsetpublic final String getSelectedText()
public void setSelectedText(String selectedText)
selectedText
- The replacement text for the selectionpublic final boolean isEditable()
public void setEditable(boolean editable)
editable
- True if this text area should be editable, false otherwisepublic final JPopupMenu getRightClickPopup()
public final void setRightClickPopup(JPopupMenu popup)
popup
- The popuppublic final int getMagicCaretPosition()
public final void setMagicCaretPosition(int magicCaret)
magicCaret
- The magic caret positionpublic void overwriteSetSelectedText(String str)
setSelectedText()
, but overstrikes the appropriate
number of characters if overwrite mode is enabled.str
- The stringsetSelectedText(String)
,
isOverwriteEnabled()
public final boolean isOverwriteEnabled()
public final void setOverwriteEnabled(boolean overwrite)
overwrite
- True if overwrite mode should be enabled, false otherwise.public final boolean isSelectionRectangular()
public final void setSelectionRectangular(boolean rectSelect)
overwrite
- True if the selection should be rectangular, false otherwise.public final int getBracketPosition()
public final int getBracketLine()
public final void addCaretListener(CaretListener listener)
listener
- The listenerpublic final void removeCaretListener(CaretListener listener)
listener
- The listenerpublic void cut()
public void copy()
public void paste()
public void removeNotify()
removeNotify
in class JComponent
public void addNotify()
addNotify
in class JComponent
public void processKeyEvent(KeyEvent evt)
processKeyEvent
in class JComponent
protected void fireCaretEvent()
protected void updateBracketHighlight(int newCaretPosition)
protected void documentChanged(DocumentEvent evt)
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
public Dimension getMaximumSize()
getMaximumSize
in class JComponent
public Dimension getMinimumSize()
getMinimumSize
in class JComponent
public int getMaxLineLength()
public Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize
in interface Scrollable
public int getScrollableBlockIncrement(Rectangle arg0, int arg1, int arg2)
getScrollableBlockIncrement
in interface Scrollable
public boolean getScrollableTracksViewportHeight()
getScrollableTracksViewportHeight
in interface Scrollable
public boolean getScrollableTracksViewportWidth()
getScrollableTracksViewportWidth
in interface Scrollable
public int getScrollableUnitIncrement(Rectangle arg0, int arg1, int arg2)
getScrollableUnitIncrement
in interface Scrollable
Copyright © 2019. All Rights Reserved.