|
|||||||||
| Home >> All >> org >> gjt >> sp >> jedit >> [ textarea overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.gjt.sp.jedit.textarea
Class JEditTextArea

java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
org.gjt.sp.jedit.textarea.JEditTextArea
- All Implemented Interfaces:
- java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
- public class JEditTextArea
- extends javax.swing.JComponent
jEdit's text area component. It is more suited for editing program source code than JEditorPane, because it drops the unnecessary features (images, variable-width lines, and so on) and adds a whole bunch of useful goodies such as:
- More flexible key binding scheme
- Supports macro recorders
- Rectangular selection
- Bracket highlighting
- Syntax highlighting
- Command repetition
- Block caret can be enabled
To use it in your app, treat it like any other component, for example:
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"
+ "}");
- Version:
- $Id: JEditTextArea.java,v 1.10 2003/06/30 17:31:08 blaisorblade Exp $
| Nested Class Summary | |
(package private) class |
JEditTextArea.AdjustHandler
|
(package private) static class |
JEditTextArea.CaretBlinker
|
(package private) class |
JEditTextArea.CaretUndo
|
(package private) class |
JEditTextArea.ComponentHandler
|
(package private) class |
JEditTextArea.DocumentHandler
|
(package private) class |
JEditTextArea.DragHandler
|
(package private) class |
JEditTextArea.FocusHandler
|
(package private) class |
JEditTextArea.MouseHandler
|
(package private) class |
JEditTextArea.MutableCaretEvent
|
(package private) class |
JEditTextArea.ScrollLayout
|
| Nested classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Fields inherited from class javax.swing.JComponent |
accessibleContext, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Container |
|
| Fields inherited from class java.awt.Component |
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 |
| Constructor Summary | |
JEditTextArea(org.jext.JextFrame view)
Creates a new JEditTextArea with the default settings. |
|
JEditTextArea(org.jext.JextFrame view,
TextAreaDefaults defaults)
Creates a new JEditTextArea with the specified settings. |
|
| Method Summary | |
void |
addCaretListener(javax.swing.event.CaretListener listener)
Adds a caret change listener to this text area. |
void |
addNotify()
Called by the AWT when this component is added to a parent. |
void |
appendCopy()
|
void |
appendCut()
|
void |
blinkCaret()
Blinks the caret. |
void |
copy()
Places the selected text into the clipboard. |
void |
cut()
Deletes the selected text from the text area and places it into the clipboard. |
protected void |
documentChanged(javax.swing.event.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. |
org.gjt.sp.jedit.syntax.SyntaxDocument |
getDocument()
Returns the document this text area is editing. |
int |
getDocumentLength()
Returns the length of the document. |
int |
getElectricScroll()
Returns the number of lines from the top and button of the text area that are always visible. |
int |
getFirstLine()
Returns the line displayed at the text area's origin. |
boolean |
getFocusTraversalKeysEnabled()
Check whether or not focus traversal keys are enabled on this Component. |
Gutter |
getGutter()
Returns the gutter to the left of the text area or null if the gutter is disabled |
int |
getHorizontalOffset()
Returns the horizontal offset of drawn lines. |
InputHandler |
getInputHandler()
|
int |
getLineCount()
Returns the number of lines in the document. |
int |
getLineEndOffset(int line)
Returns the end offset of the specified line. |
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. |
java.lang.String |
getLineText(int lineIndex)
Returns the text on the specified line. |
void |
getLineText(int lineIndex,
javax.swing.text.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. |
java.awt.Dimension |
getMinimumSize()
Returns 0,0 for split pane compatibility. |
TextAreaPainter |
getPainter()
Returns the object responsible for painting this text area. |
javax.swing.JPopupMenu |
getRightClickPopup()
Returns the right click popup menu. |
java.lang.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 |
getShadowCaretLine()
|
int |
getShadowCaretPosition()
|
java.awt.Component |
getStatus()
Returns the status bar component (which was added with a name of LEFT_OF_SCROLLBAR). |
java.lang.String |
getText()
Returns the entire text of this text area. |
java.lang.String |
getText(int start,
int len)
Returns the specified substring of the document. |
void |
getText(int start,
int len,
javax.swing.text.Segment segment)
Copies the specified substring of the document into a segment. |
org.gjt.sp.jedit.syntax.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(java.lang.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. |
protected void |
processKeyEvent(java.awt.event.KeyEvent evt)
Override the default key dispatch system from Component to hook into the swing javax.swing.InputMap / javax.swing.ActionMap system. |
void |
recalculateVisibleLines()
Recalculates the number of visible lines. |
void |
removeCaretListener(javax.swing.event.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. |
boolean |
scrollTo(int line,
int offset)
Ensures that the specified line and offset is visible by scrolling the text area if necessary. |
boolean |
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(org.gjt.sp.jedit.syntax.SyntaxDocument document)
Sets the document this text area is editing. |
void |
setEditable(boolean editable)
Sets if this component is editable. |
void |
setElectricScroll(int electricScroll)
Sets the number of lines from the top and bottom of the text area that are always visible |
void |
setFirstLine(int firstLine)
Sets the line displayed at the text area's origin without updating the scroll bars. |
void |
setHorizontalOffset(int horizontalOffset)
Sets the horizontal offset of drawn lines. |
void |
setMagicCaretPosition(int magicCaret)
Sets the `magic' caret position. |
void |
setOneClick(org.jext.OneClickAction oneClick)
|
void |
setOneClick(org.jext.OneClickAction oneClick,
java.awt.event.ActionEvent oneClickEvent)
|
boolean |
setOrigin(int firstLine,
int horizontalOffset)
A fast way of changing both the first line and horizontal offset. |
void |
setOverwriteEnabled(boolean overwrite)
Sets if overwrite mode should be enabled. |
void |
setRightClickPopup(javax.swing.JPopupMenu popup)
Sets the right click popup menu. |
void |
setSelectedText(java.lang.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 |
setShadowCaretPosition(int offset)
|
void |
setText(java.lang.String text)
Sets the entire text of this text area. |
void |
setTokenMarker(org.gjt.sp.jedit.syntax.TokenMarker tokenMarker)
Sets the document's token marker. |
protected void |
updateBracketHighlight(int newCaretPosition)
|
(package private) void |
updateMaxHorizontalScrollWidth()
|
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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
view
private org.jext.JextFrame view
LEFT_OF_SCROLLBAR
public static java.lang.String LEFT_OF_SCROLLBAR
- Adding components with this name to the text area will place
them left of the horizontal scroll bar. In jEdit, the status
bar is added this way.
lineSegment
javax.swing.text.Segment lineSegment
CENTER
protected static java.lang.String CENTER
RIGHT
protected static java.lang.String RIGHT
LEFT
protected static java.lang.String LEFT
BOTTOM
protected static java.lang.String BOTTOM
focusedComponent
protected static JEditTextArea focusedComponent
caretTimer
protected static javax.swing.Timer caretTimer
painter
protected TextAreaPainter painter
gutter
protected Gutter gutter
popup
protected javax.swing.JPopupMenu popup
listenerList
protected javax.swing.event.EventListenerList listenerList
caretEvent
protected JEditTextArea.MutableCaretEvent caretEvent
caretBlinks
protected boolean caretBlinks
caretVisible
protected boolean caretVisible
blink
protected boolean blink
editable
protected boolean editable
maxHorizontalScrollWidth
protected int maxHorizontalScrollWidth
firstLine
protected int firstLine
visibleLines
protected int visibleLines
electricScroll
protected int electricScroll
horizontalOffset
protected int horizontalOffset
vertical
protected javax.swing.JScrollBar vertical
horizontal
protected javax.swing.JScrollBar horizontal
scrollBarsInitialized
protected boolean scrollBarsInitialized
inputHandler
protected InputHandler inputHandler
document
protected org.gjt.sp.jedit.syntax.SyntaxDocument document
documentHandler
protected JEditTextArea.DocumentHandler documentHandler
documentHandlerInstalled
protected boolean documentHandlerInstalled
selectionStart
protected int selectionStart
selectionStartLine
protected int selectionStartLine
selectionEnd
protected int selectionEnd
selectionEndLine
protected int selectionEndLine
biasLeft
protected boolean biasLeft
bracketPosition
protected int bracketPosition
bracketLine
protected int bracketLine
magicCaret
protected int magicCaret
overwrite
protected boolean overwrite
rectSelect
protected boolean rectSelect
clickCount
private int clickCount
oneClickEvent
protected java.awt.event.ActionEvent oneClickEvent
oneClick
public org.jext.OneClickAction oneClick
dragText
private boolean dragText
dragCursor
private boolean dragCursor
dragControlDown
private boolean dragControlDown
shadowCaretLine
private int shadowCaretLine
shadowCaretOffset
private int shadowCaretOffset
| Constructor Detail |
JEditTextArea
public JEditTextArea(org.jext.JextFrame view)
- Creates a new JEditTextArea with the default settings.
JEditTextArea
public JEditTextArea(org.jext.JextFrame view, TextAreaDefaults defaults)
- Creates a new JEditTextArea with the specified settings.
| Method Detail |
getFocusTraversalKeysEnabled
public boolean getFocusTraversalKeysEnabled()
- Description copied from class:
java.awt.Component - Check whether or not focus traversal keys are enabled on this
Component. If they are, then the keyboard focus manager consumes
and acts on key press and release events that trigger focus
traversal, and discards the corresponding key typed events. If
focus traversal keys are disabled, then all key events that would
otherwise trigger focus traversal are sent to this Component.
getInputHandler
public InputHandler getInputHandler()
isManagingFocus
public final boolean isManagingFocus()
- Returns if this component can be traversed by pressing
the Tab key. This returns false.
getMinimumSize
public final java.awt.Dimension getMinimumSize()
- Returns 0,0 for split pane compatibility.
getPainter
public final TextAreaPainter getPainter()
- Returns the object responsible for painting this text area.
getGutter
public final Gutter getGutter()
- Returns the gutter to the left of the text area or null if the gutter
is disabled
isCaretBlinkEnabled
public final boolean isCaretBlinkEnabled()
- Returns true if the caret is blinking, false otherwise.
setCaretBlinkEnabled
public void setCaretBlinkEnabled(boolean caretBlinks)
- Toggles caret blinking.
isCaretVisible
public final boolean isCaretVisible()
- Returns true if the caret is visible, false otherwise.
setCaretVisible
public void setCaretVisible(boolean caretVisible)
- Sets if the caret should be visible.
blinkCaret
public final void blinkCaret()
- Blinks the caret.
getElectricScroll
public final int getElectricScroll()
- Returns the number of lines from the top and button of the
text area that are always visible.
setElectricScroll
public final void setElectricScroll(int electricScroll)
- Sets the number of lines from the top and bottom of the text
area that are always visible
updateScrollBars
public void updateScrollBars()
- Updates the state of the scroll bars. This should be called
if the number of lines in the document changes, or when the
size of the text are changes.
getFirstLine
public final int getFirstLine()
- Returns the line displayed at the text area's origin.
setFirstLine
public void setFirstLine(int firstLine)
- Sets the line displayed at the text area's origin without
updating the scroll bars.
getVisibleLines
public final int getVisibleLines()
- Returns the number of lines visible in this text area.
recalculateVisibleLines
public final void recalculateVisibleLines()
- Recalculates the number of visible lines. This should not
be called directly.
updateMaxHorizontalScrollWidth
void updateMaxHorizontalScrollWidth()
getHorizontalOffset
public final int getHorizontalOffset()
- Returns the horizontal offset of drawn lines.
setHorizontalOffset
public void setHorizontalOffset(int horizontalOffset)
- Sets the horizontal offset of drawn lines. This can be used to
implement horizontal scrolling.
setOrigin
public boolean setOrigin(int firstLine,
int horizontalOffset)
- A fast way of changing both the first line and horizontal
offset.
scrollToCaret
public boolean scrollToCaret()
- Ensures that the caret is visible by scrolling the text area if
necessary.
scrollTo
public boolean scrollTo(int line,
int offset)
- Ensures that the specified line and offset is visible by scrolling
the text area if necessary.
lineToY
public int lineToY(int line)
- Converts a line index to a y co-ordinate.
yToLine
public int yToLine(int y)
- Converts a y co-ordinate to a line index.
offsetToX
public int offsetToX(int line,
int offset)
- Converts an offset in a line into an x co-ordinate.
xToOffset
public int xToOffset(int line,
int x)
- Converts an x co-ordinate to an offset within a line.
xyToOffset
public int xyToOffset(int x,
int y)
- Converts a point to an offset, from the start of the text.
getDocument
public final org.gjt.sp.jedit.syntax.SyntaxDocument getDocument()
- Returns the document this text area is editing.
setDocument
public void setDocument(org.gjt.sp.jedit.syntax.SyntaxDocument document)
- Sets the document this text area is editing.
getTokenMarker
public final org.gjt.sp.jedit.syntax.TokenMarker getTokenMarker()
- Returns the document's token marker. Equivalent to calling
getDocument().getTokenMarker().
setTokenMarker
public final void setTokenMarker(org.gjt.sp.jedit.syntax.TokenMarker tokenMarker)
- Sets the document's token marker. Equivalent to caling
getDocument().setTokenMarker().
getDocumentLength
public final int getDocumentLength()
- Returns the length of the document. Equivalent to calling
getDocument().getLength().
getLineCount
public final int getLineCount()
- Returns the number of lines in the document.
getLineOfOffset
public final int getLineOfOffset(int offset)
- Returns the line containing the specified offset.
getLineStartOffset
public int getLineStartOffset(int line)
- Returns the start offset of the specified line.
getLineEndOffset
public int getLineEndOffset(int line)
- Returns the end offset of the specified line.
getLineLength
public int getLineLength(int line)
- Returns the length of the specified line.
getText
public java.lang.String getText()
- Returns the entire text of this text area.
setText
public void setText(java.lang.String text)
- Sets the entire text of this text area.
getText
public final java.lang.String getText(int start, int len)
- Returns the specified substring of the document.
getText
public final void getText(int start,
int len,
javax.swing.text.Segment segment)
- Copies the specified substring of the document into a segment.
If the offsets are invalid, the segment will contain a null string.
getLineText
public final java.lang.String getLineText(int lineIndex)
- Returns the text on the specified line.
getLineText
public final void getLineText(int lineIndex,
javax.swing.text.Segment segment)
- Copies the text on the specified line into a segment. If the line
is invalid, the segment will contain a null string.
getSelectionStart
public final int getSelectionStart()
- Returns the selection start offset.
getSelectionStart
public int getSelectionStart(int line)
- Returns the offset where the selection starts on the specified
line.
getSelectionStartLine
public final int getSelectionStartLine()
- Returns the selection start line.
setSelectionStart
public final void setSelectionStart(int selectionStart)
- Sets the selection start. The new selection will be the new
selection start and the old selection end.
getSelectionEnd
public final int getSelectionEnd()
- Returns the selection end offset.
getSelectionEnd
public int getSelectionEnd(int line)
- Returns the offset where the selection ends on the specified
line.
getSelectionEndLine
public final int getSelectionEndLine()
- Returns the selection end line.
setSelectionEnd
public final void setSelectionEnd(int selectionEnd)
- Sets the selection end. The new selection will be the old
selection start and the bew selection end.
getCaretPosition
public final int getCaretPosition()
- Returns the caret position. This will either be the selection
start or the selection end, depending on which direction the
selection was made in.
getCaretLine
public final int getCaretLine()
- Returns the caret line.
getMarkPosition
public final int getMarkPosition()
- Returns the mark position. This will be the opposite selection
bound to the caret position.
getMarkLine
public final int getMarkLine()
- Returns the mark line.
setCaretPosition
public final void setCaretPosition(int caret)
- Sets the caret position. The new selection will consist of the
JAVADOC