|
|||||||||
| Home >> All >> jsource >> [ gui overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
jsource.gui
Class JSEditor

java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
jsource.gui.JSEditor
- All Implemented Interfaces:
- java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
- public class JSEditor
- extends javax.swing.JComponent
JSEditor is JSource's text editing 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
| Nested Class Summary | |
(package private) class |
JSEditor.AdjustHandler
|
(package private) static class |
JSEditor.CaretBlinker
|
(package private) class |
JSEditor.CaretUndo
|
(package private) class |
JSEditor.ComponentHandler
|
(package private) class |
JSEditor.DocumentHandler
|
(package private) class |
JSEditor.DragHandler
|
(package private) class |
JSEditor.FocusHandler
|
(package private) class |
JSEditor.MouseHandler
|
(package private) class |
JSEditor.MutableCaretEvent
|
(package private) class |
JSEditor.ScrollLayout
Custom Layout manager |
| 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 | |
JSEditor(MainFrame main)
Creates a new JSEditor with the default settings. |
|
JSEditor(TextAreaDefaults defaults,
MainFrame main)
Creates a new JSEditor with the specified settings. |
|
| Method Summary | |
int |
_offsetToX(int line,
int offset)
Converts an offset in a line into an x co-ordinate. |
void |
addCaretListener(javax.swing.event.CaretListener listener)
Adds a caret change listener to this text area. |
void |
append(java.lang.String str)
Appends the given text to the end of the document. |
void |
blinkCaret()
Blinks the caret. |
void |
clearBreakpoints()
|
void |
comment()
Comments the selected lines. |
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. |
jsource.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 bottom of the text area that are always visible. |
int |
getFirstLine()
Returns the line displayed at the text area's origin. |
Gutter |
getGutter()
Get the Gutter of this JSEditor |
int |
getHorizontalOffset()
Returns the horizontal offset of drawn lines. |
jsource.syntax.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 |
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. |
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. |
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. |
jsource.syntax.tokenmarker.TokenMarker |
getTokenMarker()
Returns the document's token marker. |
int |
getVisibleLines()
Returns the number of lines visible in this text area. |
void |
indent()
Indents the selected lines. |
void |
insert(java.lang.String str)
Inserts the given text after the current caret position. |
boolean |
isBreakpoint(int line)
|
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 |
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. |
void |
processKeyEvent(java.awt.event.KeyEvent evt)
Forwards key events directly to the input handler. |
void |
recalculateVisibleLines()
Recalculates the number of visible lines. |
boolean |
redo()
Redoes the most recently undone edit. |
void |
removeBreakpoint(int line)
|
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 |
setBreakpoint(int line)
|
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(jsource.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 |
setIndent(int indent)
Sets a new indent length. |
void |
setInputHandler(jsource.syntax.InputHandler inputHandler)
Sets the input handler. |
void |
setMagicCaretPosition(int magicCaret)
Sets the `magic' caret position. |
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 |
setText(java.lang.String text)
Sets the entire text of this text area. |
void |
setTokenMarker(jsource.syntax.tokenmarker.TokenMarker tokenMarker)
Sets the document's token marker. |
void |
uncomment()
Uncomments the selected lines. |
boolean |
undo()
Undoes the most recent edit. |
void |
update(java.awt.Graphics g)
Overrides update for smoother repainting. |
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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
CENTER
private static java.lang.String CENTER
RIGHT
private static java.lang.String RIGHT
BOTTOM
private static java.lang.String BOTTOM
LEFT
private static java.lang.String LEFT
focusedComponent
private static JSEditor focusedComponent
caretTimer
private static javax.swing.Timer caretTimer
refreshTimer
private static javax.swing.Timer refreshTimer
painter
private TextAreaPainter painter
main
private MainFrame main
popup
private javax.swing.JPopupMenu popup
listenerList
private javax.swing.event.EventListenerList listenerList
caretEvent
private JSEditor.MutableCaretEvent caretEvent
mGutter
private Gutter mGutter
mBreakPts
private java.util.HashSet mBreakPts
caretBlinks
private boolean caretBlinks
caretVisible
private boolean caretVisible
blink
private boolean blink
editable
private boolean editable
firstLine
private int firstLine
visibleLines
private int visibleLines
electricScroll
private int electricScroll
horizontalOffset
private int horizontalOffset
vertical
private javax.swing.JScrollBar vertical
horizontal
private javax.swing.JScrollBar horizontal
scrollBarsInitialized
private boolean scrollBarsInitialized
inputHandler
private jsource.syntax.InputHandler inputHandler
document
private jsource.syntax.SyntaxDocument document
documentHandler
private JSEditor.DocumentHandler documentHandler
lineSegment
private javax.swing.text.Segment lineSegment
selectionStart
private int selectionStart
selectionStartLine
private int selectionStartLine
selectionEnd
private int selectionEnd
selectionEndLine
private int selectionEndLine
biasLeft
private boolean biasLeft
bracketPosition
private int bracketPosition
bracketLine
private int bracketLine
magicCaret
private int magicCaret
overwrite
private boolean overwrite
rectSelect
private boolean rectSelect
modifiedSinceSave
public boolean modifiedSinceSave
indent
private boolean indent
tab
private java.lang.String tab
lineSep
private java.lang.String lineSep
| Constructor Detail |
JSEditor
public JSEditor(MainFrame main)
- Creates a new JSEditor with the default settings.
JSEditor
public JSEditor(TextAreaDefaults defaults, MainFrame main)
- Creates a new JSEditor with the specified settings.
| Method Detail |
update
public void update(java.awt.Graphics g)
- Overrides
updatefor smoother repainting. Implemented 01/02/03
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.
append
public void append(java.lang.String str)
- Appends the given text to the end of the document.
insert
public void insert(java.lang.String str)
- Inserts the given text after the current caret position.
getPainter
public final TextAreaPainter getPainter()
- Returns the object responsible for painting this text area.
getInputHandler
public final jsource.syntax.InputHandler getInputHandler()
- Returns the input handler.
setInputHandler
public void setInputHandler(jsource.syntax.InputHandler inputHandler)
- Sets the input handler.
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 bottom 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 area 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.
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 final int offsetToX(int line,
int offset)
- Converts an offset in a line into an x co-ordinate. This is a
slow version that can be used any time.
_offsetToX
public int _offsetToX(int line,
int offset)
- Converts an offset in a line into an x co-ordinate. This is a
fast version that should only be used if no changes were made
to the text since the last repaint.
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 jsource.syntax.SyntaxDocument getDocument()
- Returns the document this text area is editing.
setDocument
public void setDocument(jsource.syntax.SyntaxDocument document)
- Sets the document this text area is editing.
setIndent
public void setIndent(int indent)
- Sets a new indent length.
getTokenMarker
public final jsource.syntax.tokenmarker.TokenMarker getTokenMarker()
- Returns the document's token marker. Equivalent to calling
getDocument().getTokenMarker().
setTokenMarker
public final void setTokenMarker(jsource.syntax.tokenmarker.TokenMarker tokenMarker)
- Sets the document's token marker. Equivalent to caling
getDocument().setTokenMarker().
getDocumentLength
public int getDocumentLength()
- Returns the length of the document. Equivalent to calling
getDocument().getLength().
getLineCount
public 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 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 java.lang.String getLineText(int lineIndex)
- Returns the text on the specified line.
getLineText
public 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
caret position only (hence no text will be selected)
selectAll
public final void selectAll()
- Selects all text in the document.
selectNone
public final void selectNone()
- Moves the mark to the caret position.
select
public void select(int start,
int end)
- Selects from the start offset to the end offset. This is the
general selection method used by all other selecting methods.
The caret position will be start if start < end, and end
if end > start.
getSelectedText
public final java.lang.String getSelectedText()
- Returns the selected text, or null if no selection is active.
setSelectedText
public void setSelectedText(java.lang.String selectedText)
- Replaces the selection with the specified text.
isEditable
public final boolean isEditable()
- Returns true if this text area is editable, false otherwise.
setEditable
public final void setEditable(boolean editable)
- Sets if this component is editable.
getRightClickPopup
public final javax.swing.JPopupMenu getRightClickPopup()
- Returns the right click popup menu.
setRightClickPopup
public final void setRightClickPopup(javax.swing.JPopupMenu popup)
- Sets the right click popup menu.
getMagicCaretPosition
public final int getMagicCaretPosition()
- Returns the `magic' caret position. This can be used to preserve
the column position when moving up and down lines.
setMagicCaretPosition
public final void setMagicCaretPosition(int magicCaret)
- Sets the `magic' caret position. This can be used to preserve
the column position when moving up and down lines.
overwriteSetSelectedText
public void overwriteSetSelectedText(java.lang.String str)
- Similar to
setSelectedText(), but overstrikes the appropriate number of characters if overwrite mode is enabled.
isOverwriteEnabled
public final boolean isOverwriteEnabled()
- Returns true if overwrite mode is enabled, false otherwise.
setOverwriteEnabled
public final void setOverwriteEnabled(boolean overwrite)
- Sets if overwrite mode should be enabled.
isSelectionRectangular
public final boolean isSelectionRectangular()
- Returns true if the selection is rectangular, false otherwise.
setSelectionRectangular
public final void setSelectionRectangular(boolean rectSelect)
- Sets if the selection should be rectangular.
getBracketPosition
public final int getBracketPosition()
- Returns the position of the highlighted bracket (the bracket
matching the one before the caret)
getBracketLine
public final int getBracketLine()
- Returns the line of the highlighted bracket (the bracket
matching the one before the caret)
addCaretListener
public final void addCaretListener(javax.swing.event.CaretListener listener)
- Adds a caret change listener to this text area.
removeCaretListener
public final void removeCaretListener(javax.swing.event.CaretListener listener)
- Removes a caret change listener from this text area.
cut
public void cut()
- Deletes the selected text from the text area and places it
into the clipboard.
copy
public void copy()
- Places the selected text into the clipboard.
paste
public void paste()
- Inserts the clipboard contents into the text.
undo
public boolean undo()
- Undoes the most recent edit. Returns true if the undo was successful.
redo
public boolean redo()
- Redoes the most recently undone edit. Returns true if the redo was successful.
indent
public void indent()
- Indents the selected lines.
comment
public void comment()
- Comments the selected lines.
uncomment
public void uncomment()
- Uncomments the selected lines.
JAVADOC