Package ca.cgjennings.ui.textedit
Class CodeEditorBase
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- ca.cgjennings.ui.textedit.CodeEditorBase
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible
- Direct Known Subclasses:
UILibraryHelper.CodeArea
public class CodeEditorBase extends javax.swing.JPanelThis is the base class for all code editing controls.- Since:
- 3.4
- Author:
- Chris Jennings
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCodeEditorBase.PopupMenuBuilderInterface implemented by code editor users to create custom popup menus.static classCodeEditorBase.ResultThe result of a search or replace operation.-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
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
-
-
Constructor Summary
Constructors Constructor Description CodeEditorBase()Creates a new code editor control.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCaretListener(javax.swing.event.CaretListener listener)voidaddDocumentListener(javax.swing.event.DocumentListener listener)voidaddFocusListener(java.awt.event.FocusListener listener)voidaddKeyBinding(java.lang.String keyStroke, java.awt.event.ActionListener action)Add a key binding to trigger an editor action.voidaddKeyBinding(java.lang.String keyStroke, java.lang.Runnable action)Add a key binding using a string description of the key.voidaddKeyBinding(java.lang.String keyStroke, java.lang.String action)Add a key binding to trigger an editor action.voidaddKeyBinding(java.lang.String keyStroke, javax.swing.Action action)Add a key binding to trigger an editor action.voidaddKeyBinding(javax.swing.KeyStroke ks, java.awt.event.ActionListener action)Add a key binding to trigger an editor action.voidaddKeyBinding(javax.swing.KeyStroke keyStroke, java.lang.Runnable action)Add a key binding to trigger an editor action.voidaddKeyBinding(javax.swing.KeyStroke ks, java.lang.String action)Add a key binding to trigger an editor action.voidaddKeyBinding(javax.swing.KeyStroke ks, javax.swing.Action action)Add a key binding to trigger an editor action.protected voidaddKeyBindings()voidbeginCompoundEdit()Begins a sequence of zero or more document edits that will be treated as a single action when undoing and redoing.CodeEditorBase.ResultbeginSearch(java.lang.String pattern, boolean matchCase, boolean wholeWord, boolean regexp, boolean wrap)Begins a search of the document.booleancanPerformAction(java.lang.String actionName)booleancanRedo()Returns whether there is an undone edit can currently be redone.booleancanUndo()Returns whether there are edits that can be undone.voidclearUndoHistory()Clears the undo history, making undo impossible until another edit occurs.voidendCompoundEdit()Ends a previously started compound edit operation.voidendSearch()Ends the current search, if any.CodeEditorBase.ResultfindNext(boolean forward)Searches for the next match of the current search.AbbreviationTablegetAbbreviationTable()Returns the current abbreviation table for this editor.javax.swing.ActiongetAction(java.lang.String actionName)Returns a named editor action.javax.swing.Action[]getActions()intgetCaretLine()Returns the line number of the text insertion caret.intgetCaretOffsetFromLineStart()Returns the offset of the text insertion caret from the start of its line.intgetCaretPosition()Returns the position of the text insertion caret for the text component.CodeSupportgetCodeSupport()Returns the currently installed code support.CodeTypegetCodeType()Returns the code type used for syntax highlighting and related features.javax.swing.text.DocumentgetDocument()Returns the edited document.java.io.FilegetFile()Returns the file associated with this editor, if any.intgetFirstDisplayedLine()Returns the line number of the line at the top of the view.java.awt.FontgetFont()intgetLength()Returns the document length, in characters.intgetLineCount()Returns the number of lines in the document.intgetLineEndOffset(int line)Returns the document offset at which the specified line ends.intgetLineLength(int line)Returns the length of the specified line.intgetLineOfOffset(int offset)Returns the zero-based line number of the specified document offset.intgetLineStartOffset(int line)Returns the document offset at which the specified line begins.java.lang.StringgetLineText()Returns the text of the current line, that is, the line containing the caret.java.lang.StringgetLineText(int line)Returns the text of the specified line.intgetMarkPosition()Returns the position of the mark for the text component.CodeEditorBase.PopupMenuBuildergetPopupMenuBuilder()Returns the popup menu builder, which can customize the popup menu before it is displayed.java.lang.String[]getSelectedLineText(boolean doNotIncludeLineIfCaretAtStart)Returns the selected lines as an array of strings.java.lang.StringgetSelectedText()Returns the currently selected text.intgetSelectionEnd()Returns the selected text's end position.intgetSelectionEndLine()Returns the line of the selection end.intgetSelectionStart()Returns the selected text's start position.intgetSelectionStartLine()Returns the line of the selection start.java.lang.StringgetText()Returns the contents of the editor.java.lang.StringgetText(int start, int length)Returns the text of the specified document region.java.lang.StringgetTextRange(int start, int end)Returns the text of the document region specified by two offsets.booleanhasSelection()Returns true if the editor currently has a selection.voidinsert(java.lang.String text, int offset)Inserts the specified text at the given offset.booleanisCodeFoldingEnabled()Returns whether or not code folding is enabled for supported code types.booleanisContentFeedbackVisible()Sets whether feedback on the document content is visible.booleanisEditable()Returns whether this editor is editable.booleanisNumberLineVisible()Returns whether line numbers are shown.booleanisWhitespaceVisible()Returns whether white space should be visible.static javax.swing.KeyStrokeparseKeyStroke(java.lang.String keyStroke)Converts a string to a single key stroke.booleanperformAction(java.lang.String actionName)voidredo()Redoes the most recently undone edit.voidremoveCaretListener(javax.swing.event.CaretListener listener)voidremoveDocumentListener(javax.swing.event.DocumentListener listener)voidremoveFocusListener(java.awt.event.FocusListener listener)CodeEditorBase.ResultreplaceAll(java.lang.String replacement)Replaces all occurrences of the current search.CodeEditorBase.ResultreplaceNext(boolean forward, java.lang.String replacement)Replaces the next match of the current search.voidreplaceRange(java.lang.String text, int start, int end)Replaces the specified text range with new text.voidreplaceSelection(java.lang.String text)Replaces the selection with new text.voidrequestFocus()booleanrequestFocus(boolean temporary)voidrequestFocus(java.awt.event.FocusEvent.Cause cause)booleanrequestFocusInWindow()booleanrequestFocusInWindow(java.awt.event.FocusEvent.Cause cause)voidscrollToLine(int line)Scroll the editor view to display the specified line.voidscrollToOffset(int offset)Scroll the editor view to display the specified offset.voidselect(int start, int end)Sets the current selection range.voidselectAll()Selects the entire document.voidsetAbbreviationTable(AbbreviationTable table)Sets the abbreviation table for this editor, replacing any default table determined by the code type.voidsetCaretLine(int line)Moves the caret to the start of the specified line.voidsetCaretPosition(int offset)Sets the position of the text insertion caret for the text component.voidsetCodeFoldingEnabled(boolean enable)Sets whether or not code folding is enabled for supported code types.voidsetCodeSupport(CodeSupport support)Installs code editing support.voidsetCodeType(CodeType type)Changes the code type used for syntax highlighting and enables any additional support features that are available for the language.voidsetCodeType(CodeType type, boolean enableAdvancedFeatures)Changes the code type used for syntax highlighting.voidsetContentFeedbackVisible(boolean visible)Sets whether feedback on the document content, such as icons marking rows with errors, is visible.voidsetEditable(boolean editable)Sets whether this editor should be editable.voidsetFile(java.io.File file)Associates the contents of the editor with a file.voidsetFont(java.awt.Font font)voidsetInitialText(java.lang.String text)Sets the initial contents of the editor.voidsetMarkPosition(int offset)Sets the position of the mark for the text component.voidsetNumberLineVisible(boolean visible)Sets whether line numbers are shown.voidsetPopupMenuBuilder(CodeEditorBase.PopupMenuBuilder pmb)Sets a popup menu builder, which can customize the popup menu before it is displayed.voidsetSelectedLineText(java.lang.String[] lines)Replaces the selection with the lines in the provided array.voidsetSelectedText(java.lang.String text)Replaces the selection with the specified text, selecting the new text.voidsetText(java.lang.String text)Sets the contents of the editor.voidsetWhitespaceVisible(boolean visible)Sets whether white space should be visible.voidtype(javax.swing.KeyStroke keyStroke)Simulates pressing the specified key in the editor.voidundo()Undoes the most recent edit.-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, 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
-
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, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, 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, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Method Detail
-
addKeyBindings
protected void addKeyBindings()
-
requestFocus
public void requestFocus()
- Overrides:
requestFocusin classjavax.swing.JComponent
-
requestFocus
public void requestFocus(java.awt.event.FocusEvent.Cause cause)
- Overrides:
requestFocusin classjava.awt.Component
-
requestFocus
public boolean requestFocus(boolean temporary)
- Overrides:
requestFocusin classjavax.swing.JComponent
-
requestFocusInWindow
public boolean requestFocusInWindow()
- Overrides:
requestFocusInWindowin classjavax.swing.JComponent
-
requestFocusInWindow
public boolean requestFocusInWindow(java.awt.event.FocusEvent.Cause cause)
- Overrides:
requestFocusInWindowin classjava.awt.Component
-
addDocumentListener
public final void addDocumentListener(javax.swing.event.DocumentListener listener)
-
removeDocumentListener
public final void removeDocumentListener(javax.swing.event.DocumentListener listener)
-
addCaretListener
public final void addCaretListener(javax.swing.event.CaretListener listener)
-
removeCaretListener
public final void removeCaretListener(javax.swing.event.CaretListener listener)
-
addFocusListener
public final void addFocusListener(java.awt.event.FocusListener listener)
- Overrides:
addFocusListenerin classjava.awt.Component
-
removeFocusListener
public final void removeFocusListener(java.awt.event.FocusListener listener)
- Overrides:
removeFocusListenerin classjava.awt.Component
-
getFont
public java.awt.Font getFont()
- Specified by:
getFontin interfacejava.awt.MenuContainer- Overrides:
getFontin classjava.awt.Component
-
setFont
public void setFont(java.awt.Font font)
- Overrides:
setFontin classjavax.swing.JComponent
-
getAction
public javax.swing.Action getAction(java.lang.String actionName)
Returns a named editor action.- Parameters:
actionName- the name of the action to return- Returns:
- the action matching the name, or null
-
getActions
public javax.swing.Action[] getActions()
-
canPerformAction
public boolean canPerformAction(java.lang.String actionName)
-
performAction
public boolean performAction(java.lang.String actionName)
-
setAbbreviationTable
public void setAbbreviationTable(AbbreviationTable table)
Sets the abbreviation table for this editor, replacing any default table determined by the code type.- Parameters:
table- the new table, or null to disable abbreviations
-
getAbbreviationTable
public AbbreviationTable getAbbreviationTable()
Returns the current abbreviation table for this editor.- Returns:
- the current table, or null if none is set
-
getDocument
public final javax.swing.text.Document getDocument()
Returns the edited document.- Returns:
- the document object
-
addKeyBinding
public void addKeyBinding(java.lang.String keyStroke, java.lang.Runnable action)Add a key binding using a string description of the key.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the action to perform
-
addKeyBinding
public void addKeyBinding(javax.swing.KeyStroke keyStroke, java.lang.Runnable action)Add a key binding to trigger an editor action.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the action to perform
-
addKeyBinding
public void addKeyBinding(java.lang.String keyStroke, java.awt.event.ActionListener action)Add a key binding to trigger an editor action.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the action to perform
-
addKeyBinding
public void addKeyBinding(javax.swing.KeyStroke ks, java.awt.event.ActionListener action)Add a key binding to trigger an editor action.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the action to perform
-
addKeyBinding
public void addKeyBinding(java.lang.String keyStroke, javax.swing.Action action)Add a key binding to trigger an editor action.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the action to perform
-
addKeyBinding
public void addKeyBinding(javax.swing.KeyStroke ks, javax.swing.Action action)Add a key binding to trigger an editor action.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the action to perform
-
addKeyBinding
public void addKeyBinding(java.lang.String keyStroke, java.lang.String action)Add a key binding to trigger an editor action.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the name of the action to perform, which must be in the action map
-
addKeyBinding
public void addKeyBinding(javax.swing.KeyStroke ks, java.lang.String action)Add a key binding to trigger an editor action.- Parameters:
keyStroke- the key stroke that should trigger the actionaction- the name of the action to perform, which must be in the action map
-
setCodeType
public void setCodeType(CodeType type)
Changes the code type used for syntax highlighting and enables any additional support features that are available for the language.- Parameters:
type- the new type of code being edited; if null,PLAINtype is used
-
setCodeType
public void setCodeType(CodeType type, boolean enableAdvancedFeatures)
Changes the code type used for syntax highlighting. If advanced editing features are requested, the editor may also install additional features such as code completion and syntax checking, where supported. Otherwise, only basic syntax highlighting is provided.- Parameters:
type- the new type of code being edited; if null,PLAINtype is usedenableAdvancedFeatures- if true, enables additional high-level language support where available; if false, provides only basic syntax highlighting support
-
getCodeType
public CodeType getCodeType()
Returns the code type used for syntax highlighting and related features.- Returns:
- the type of code being edited
-
setCodeSupport
public final void setCodeSupport(CodeSupport support)
Installs code editing support. A default support package is installed by setting the code type, but this can be used to install custom support.- Parameters:
support- the code support to apply to the editor
-
getCodeSupport
public final CodeSupport getCodeSupport()
Returns the currently installed code support.- Returns:
- the installed code support
-
setFile
public void setFile(java.io.File file)
Associates the contents of the editor with a file. The editor itself does not use this information, but an attached code support may use this information to offer advanced editing support.- Parameters:
file- the new, or null to remove any prior association
-
getFile
public java.io.File getFile()
Returns the file associated with this editor, if any.- Returns:
- the associated file, or null
-
setEditable
public void setEditable(boolean editable)
Sets whether this editor should be editable. If false, the editor is read-only.- Parameters:
editable- whether to allow modifications to the document
-
isEditable
public boolean isEditable()
Returns whether this editor is editable. If false, the editor is read-only.- Returns:
- whether the editor allows modifications
-
setInitialText
public void setInitialText(java.lang.String text)
Sets the initial contents of the editor. This treats the text as if it were the initial content of a new editor (for example, as if editing a newly opened file). It is similar to callingsetText(java.lang.String)except that the caret is moved to the start of the document and the undo history is cleared.- Parameters:
text- the text to set
-
setText
public void setText(java.lang.String text)
Sets the contents of the editor.- Parameters:
text- the new text to edit
-
getText
public java.lang.String getText()
Returns the contents of the editor.- Returns:
- the edited text
-
getText
public java.lang.String getText(int start, int length)Returns the text of the specified document region.- Parameters:
start- the start offsetlength- the length of the desired region- Returns:
- the text in the specified range
-
getTextRange
public java.lang.String getTextRange(int start, int end)Returns the text of the document region specified by two offsets.- Parameters:
start- the start offsetend- the end offset- Returns:
- the text between the two offsets, inclusive
-
getLineText
public java.lang.String getLineText(int line)
Returns the text of the specified line.- Parameters:
line- the zero-based line- Returns:
- the line text
-
getLineText
public java.lang.String getLineText()
Returns the text of the current line, that is, the line containing the caret.- Returns:
- the line text
-
getLineLength
public int getLineLength(int line)
Returns the length of the specified line.- Parameters:
line- the zero-based line number- Returns:
- the line length in characters
-
getSelectedText
public java.lang.String getSelectedText()
Returns the currently selected text.- Returns:
- the current selection, or an empty string if there is none
-
setSelectedText
public void setSelectedText(java.lang.String text)
Replaces the selection with the specified text, selecting the new text.- Parameters:
text- the text to insert
-
getSelectedLineText
public java.lang.String[] getSelectedLineText(boolean doNotIncludeLineIfCaretAtStart)
Returns the selected lines as an array of strings.- Parameters:
doNotIncludeLineIfCaretAtStart- if the selection ends at offset 0 within a line (i.e., it immediately follows a newline), then the line that includes the selection end will not be included- Returns:
- an array of strings, where each string is one line of the selection
-
setSelectedLineText
public void setSelectedLineText(java.lang.String[] lines)
Replaces the selection with the lines in the provided array.- Parameters:
lines- the lines of text, one per line per element
-
insert
public void insert(java.lang.String text, int offset)Inserts the specified text at the given offset.- Parameters:
text- the text to insertoffset- the document offset
-
replaceSelection
public void replaceSelection(java.lang.String text)
Replaces the selection with new text. If there is no selection, inserts text at the caret position.- Parameters:
text- the text to insert
-
replaceRange
public void replaceRange(java.lang.String text, int start, int end)Replaces the specified text range with new text.- Parameters:
text- the text to insertstart- the start offset of the range to replaceend- the end offset of the range to replace
-
getLength
public int getLength()
Returns the document length, in characters.- Returns:
- the number of characters in the document
-
getSelectionStart
public int getSelectionStart()
Returns the selected text's start position. Returns 0 for an empty document, or the value of dot if no selection.- Returns:
- the selection start offset
-
getSelectionEnd
public int getSelectionEnd()
Returns the selected text's end position. Returns 0 if the document is empty, or the value of dot if there is no selection.- Returns:
- the selection end offset
-
getSelectionStartLine
public int getSelectionStartLine()
Returns the line of the selection start.- Returns:
- the selection start line
-
getSelectionEndLine
public int getSelectionEndLine()
Returns the line of the selection end.- Returns:
- the selection end line
-
select
public void select(int start, int end)Sets the current selection range. If the start and end are the same, any current selection will be cleared.- Parameters:
start- the start offsetend- the end offset
-
selectAll
public void selectAll()
Selects the entire document.
-
hasSelection
public boolean hasSelection()
Returns true if the editor currently has a selection.
-
beginCompoundEdit
public void beginCompoundEdit()
Begins a sequence of zero or more document edits that will be treated as a single action when undoing and redoing. This should always be used in atry-finallyblock with thefinallyclause callingendCompoundEdit().
-
endCompoundEdit
public void endCompoundEdit()
Ends a previously started compound edit operation.
-
canUndo
public boolean canUndo()
Returns whether there are edits that can be undone.
-
undo
public void undo()
Undoes the most recent edit.
-
canRedo
public boolean canRedo()
Returns whether there is an undone edit can currently be redone.
-
redo
public void redo()
Redoes the most recently undone edit.
-
clearUndoHistory
public void clearUndoHistory()
Clears the undo history, making undo impossible until another edit occurs.
-
getLineCount
public int getLineCount()
Returns the number of lines in the document.
-
getLineOfOffset
public int getLineOfOffset(int offset)
Returns the zero-based line number of the specified document offset.- Parameters:
offset- the offset from the document start- Returns:
- the line number containing that offset
-
getLineStartOffset
public int getLineStartOffset(int line)
Returns the document offset at which the specified line begins.- Parameters:
line- the zero-based line number- Returns:
- the line start offset
-
getLineEndOffset
public int getLineEndOffset(int line)
Returns the document offset at which the specified line ends.- Parameters:
line- the zero-based line number- Returns:
- the line end offset
-
getCaretPosition
public int getCaretPosition()
Returns the position of the text insertion caret for the text component.- Returns:
- the position of the text insertion caret for the text component ≥ 0
-
setCaretPosition
public void setCaretPosition(int offset)
Sets the position of the text insertion caret for the text component.- Parameters:
offset- the new caret position, from 0 to the document length
-
getMarkPosition
public int getMarkPosition()
Returns the position of the mark for the text component. This is the end of the selection that is opposite the caret.- Returns:
- the position of the mark for the text component ≥ 0
-
setMarkPosition
public void setMarkPosition(int offset)
Sets the position of the mark for the text component.- Parameters:
offset- the position of the mark for the text component ≥ 0
-
getCaretLine
public int getCaretLine()
Returns the line number of the text insertion caret.- Returns:
- the line number ≥ 0
-
setCaretLine
public void setCaretLine(int line)
Moves the caret to the start of the specified line.- Parameters:
line- the zero-based line number
-
getCaretOffsetFromLineStart
public int getCaretOffsetFromLineStart()
Returns the offset of the text insertion caret from the start of its line.- Returns:
- the offset of the text insertion caret from the line start offset ≥ 0
-
getFirstDisplayedLine
public int getFirstDisplayedLine()
Returns the line number of the line at the top of the view.- Returns:
- the first visible line ≥ 0
-
scrollToLine
public void scrollToLine(int line)
Scroll the editor view to display the specified line.- Parameters:
line- the line number ≥ 0
-
scrollToOffset
public void scrollToOffset(int offset)
Scroll the editor view to display the specified offset.- Parameters:
offset- the offset to scroll into view
-
setWhitespaceVisible
public void setWhitespaceVisible(boolean visible)
Sets whether white space should be visible.- Parameters:
visible- if true, white space is rendered as symbols- See Also:
isWhitespaceVisible()
-
isWhitespaceVisible
public boolean isWhitespaceVisible()
Returns whether white space should be visible.- Returns:
- true if white space is rendered as symbols
- See Also:
setWhitespaceVisible(boolean)
-
setNumberLineVisible
public void setNumberLineVisible(boolean visible)
Sets whether line numbers are shown.- Parameters:
visible- if true, lines are numbered- See Also:
isNumberLineVisible()
-
isNumberLineVisible
public boolean isNumberLineVisible()
Returns whether line numbers are shown.- Returns:
- true if lines are numbered
- See Also:
setNumberLineVisible(boolean)
-
setContentFeedbackVisible
public void setContentFeedbackVisible(boolean visible)
Sets whether feedback on the document content, such as icons marking rows with errors, is visible.- Parameters:
visible- if true, feedback will be visible- See Also:
isContentFeedbackVisible()
-
isContentFeedbackVisible
public boolean isContentFeedbackVisible()
Sets whether feedback on the document content is visible.- Returns:
- true if feedback is visible
- See Also:
setContentFeedbackVisible(boolean)
-
setCodeFoldingEnabled
public void setCodeFoldingEnabled(boolean enable)
Sets whether or not code folding is enabled for supported code types.- Parameters:
enable- if true, code blocks can be hidden by clicking the fold control in the margin- See Also:
isCodeFoldingEnabled()
-
isCodeFoldingEnabled
public boolean isCodeFoldingEnabled()
Returns whether or not code folding is enabled for supported code types.- Returns:
- true if code blocks can be hidden by clicking the fold control in the margin
- See Also:
setCodeFoldingEnabled(boolean)
-
setPopupMenuBuilder
public void setPopupMenuBuilder(CodeEditorBase.PopupMenuBuilder pmb)
Sets a popup menu builder, which can customize the popup menu before it is displayed.- Parameters:
pmb- the menu builder to set, or null to use a default menu
-
getPopupMenuBuilder
public CodeEditorBase.PopupMenuBuilder getPopupMenuBuilder()
Returns the popup menu builder, which can customize the popup menu before it is displayed.- Returns:
- the menu builder, or null if none is set
-
type
public void type(javax.swing.KeyStroke keyStroke)
Simulates pressing the specified key in the editor.- Parameters:
keyStroke- the non-null key to simulate
-
beginSearch
public CodeEditorBase.Result beginSearch(java.lang.String pattern, boolean matchCase, boolean wholeWord, boolean regexp, boolean wrap)
Begins a search of the document. When a new search is started or the parameters of an ongoing search are changed, this will restart searching from the current position, selecting the initial match if any. In this case, the method will return aCodeEditorBase.Resultthat describes the initial match (or no match if none occurs). If this is called with the same parameters as an ongoing search, null is returned and no initial search is performed. (A return value of null does not, therefore, mean that there are no matches.)- Parameters:
pattern- the pattern to search formatchCase- true if the search should be case sensitivewholeWord- true to match only whole wordsregexp- true if the pattern is a regular expressionwrap- true if the search should wrap around the document start or end
-
findNext
public CodeEditorBase.Result findNext(boolean forward)
Searches for the next match of the current search.- Parameters:
forward- if true, searches forward through the document; else backward- Returns:
- the result of the search operation
-
replaceNext
public CodeEditorBase.Result replaceNext(boolean forward, java.lang.String replacement)
Replaces the next match of the current search.- Parameters:
forward- if true, searches forward through the document; else backwardreplacement- the string to replace the next match with- Returns:
- the result of the search operation
-
replaceAll
public CodeEditorBase.Result replaceAll(java.lang.String replacement)
Replaces all occurrences of the current search.- Parameters:
replacement- the string to replace all occurrences with- Returns:
- the result of the search operation
-
endSearch
public void endSearch()
Ends the current search, if any.
-
parseKeyStroke
public static javax.swing.KeyStroke parseKeyStroke(java.lang.String keyStroke)
Converts a string to a single key stroke. The string may use one of two formats: the verbose format use by theKeyStrokeclass, or a compact format that requires less typing. The compact format uses the form[modifiers*+]key. Here,modifiersrepresents a sequence of one or more modifier keys. Each modifier is represented by a single letter:PPlatform-specific menu accelerator key (Control on most platforms; Command on OS X) MMeta (Command) CControl AAlt SShift GAltGr (not recommended for shortcut keys) Examples:
HOME
ctrl X
ctrl alt DELETE
C+X
CA+DELETE- Parameters:
keyStroke- the string description of the key stroke, in one of the two supported formats- Returns:
- a
KeyStrokefor the string description, ornull
-
-