JIDE 3.5.15

com.jidesoft.editor
Class CodeEditor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.jidesoft.editor.CodeEditor
All Implemented Interfaces:
CaretListener, LineBreak, SelectionListener, FindResultIntepreter, ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener

public class CodeEditor
extends JComponent
implements SelectionListener, CaretListener, PropertyChangeListener, FindResultIntepreter, LineBreak

CodeEditor is a text component for source code viewing and editing.

It contains CodeEditorPainter as its major area to display/edit the code. If you want to add mouse listener, please make sure you invoke yourCodeEditor.getPainter().addMouseListener(). Same rule applies to mouse motion listeners and key listeners.

On the left of the major edit area, it's margin area panel, you could invoke getMarginArea() to get the panel and add new margin area to it. By default, we added RowNumberMargin to the left, you could add other margin components to that area if you want to customize it to have something like break point, bookmark, etc. You could invoke setLineNumberVisible(boolean) to make the default line number margin invisible.

Each CodeEditor could define a single MarkerArea. It's not part of the CodeEditor. However, usually you would layout it on the right of the major edit area and the vertical scroll bar. With the help of MarkerArea, you would be able to add some parse information to that area to indicate wrong input or warning information. Please check out PhpSyntaxParsingDemo for the detail implementations.

To help searching inside the CodeEditor, CodeEditor provides two solutions. One is integrated FindAndReplace which could be triggered with CTRL+F. That will provide REGEX searching or normal wildcard searching options. Another searching option is the uninstallable CodeEditorSearchable. You could find the detail implementation at CodeEditorDemo

Please invoke getHighlighter() to highlight some part of your target documents if necessary.

Sometimes, the customers may need to collapse several parts of code to help reviewing or editing. In this case, you may utilize getFoldingModel() and invoke FoldingModel.addFoldingSpan(int, int, String) to add the folding spans. As long as you define your folding spans with initial index, CodeEditor will update the indices appropriately based on the recent character inputs. You could leverage CodeFoldingMargin to help your customer gain a better sense of where the code folding is. Please be noted that, so far if you allow tabs in your document, this feature would behave incorrectly. We will fix this issue in later releases.

Please invoke setTokenMarker(com.jidesoft.editor.tokenmarker.TokenMarker) to set your customized token marker. JIDE provided several default TokenMakers for your quick use.

Please invoke getInputHandler() to get the InputHandler instance. If you want to change the default key combinations, you would need access that class.

In normal cases, please just invoke setText(String) to feed CodeEditor the string to review or edit. Please invoke getText() to get current string in the memory after editing to output. However, if you are reviewing or editing a large document and worry about the memory, please invoke setFileName(String) )} to feed CodeEditor with strings from the input stream. In this case, CodeEditor will utilize LazyLoadDocument to load the file page by page to save the memory. You would need invoke exportToOutputStream(java.io.OutputStream) to output the string after editing. If you do have a large file, please try not to invoke getText(). Otherwise, it may cause heap memory used up.

Author:
Slava Pestov, JIDE Software, Inc.
See Also:
Serialized Form

Nested Class Summary
static class CodeEditor.DefaultUIResourceHighlighter
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  CaretModel _caretModel
           
protected  boolean _caretVisible
           
protected static List<Transferable> _clipboards
           
protected  CodeEditorSettings _defaultSettings
           
protected  SyntaxDocument _document
           
protected  com.jidesoft.editor.CodeEditor.DocumentHandler _documentHandler
           
protected  boolean _editable
           
protected  int _firstLine
           
protected  int _horizontalOffset
           
protected  JScrollBar _horizontalScrollBar
           
 Timer _inspectionTimer
           
 RowNumberMargin _lineNumberMargin
           
protected  DefaultCodeEditorSettings _localSettings
           
protected  int _magicCaret
          Magic caret in X.
 MarginArea _marginArea
           
protected  boolean _overwrite
           
protected  CodeEditorPainter _painter
           
protected  boolean _scrollBarsInitialized
           
 Searchable _searchable
           
protected  SelectionModel _selectionModel
           
protected  CodeEditorSettings _settings
           
protected  UndoableEditListener _undoableEditListener
           
protected  JScrollBar _verticalScrollBar
           
protected  int _visibleLines
           
protected  boolean biasLeft
           
protected static String BOTTOM
           
protected  int bracketLine
          Model line of the bracket.
protected  int bracketPosition
          Model column of the bracket.
protected static Timer caretTimer
          Deprecated. no longer use static field to start one timer for all CodeEditors. Each CodeEditor manages its own timer.
protected static String CENTER
           
protected static CodeEditor focusedComponent
          Deprecated. no longer use static field to track the CodeEditor that has focus.
protected static String LEFT
           
static String LEFT_OF_SCROLLBAR
          Adding components with this name to the text area will place them left of the horizontal scroll bar.
 Segment lineSegment
           
static String PROPERTY_COLUMN_SELECTION_ENABLED
           
static String PROPERTY_EDITABLE
           
static String PROPERTY_FIRST_LINE
           
static String PROPERTY_LINE_BREAK_STYLE
           
static String PROPERTY_MAX_NUMBER_OF_CLIPBOARDS
           
static String PROPERTY_OVERWRITE_ENABLED
           
static String PROPERTY_REPLACE_TAB_WITH_SPACE
           
static String PROPERTY_TAB_SIZE
           
static String PROPERTY_VISIBLE_LINES
           
protected static String RIGHT
           
static String SMART_HOME_END_PROPERTY
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.jidesoft.editor.LineBreak
CR, LF, LINE_BREAK_CODE_EDITOR, LINE_BREAK_MAC, LINE_BREAK_MIXED, LINE_BREAK_PC, LINE_BREAK_UNIX, LINE_BREAK_UNKNOWN, STRING_CR, STRING_CR_LF, STRING_LF
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CodeEditor()
          Creates a new CodeEditor with the default settings.
CodeEditor(DefaultSettings defaults)
          Creates a new CodeEditor with the specified settings.
 
Method Summary
 int _offsetToX(int offset)
          Converts an offset in a document into an x co-ordinate.
 int _offsetToX(int line, int offset)
          Deprecated. replaced by _offsetToX(int)
 void addCodeInspector(CodeInspector inspector)
           
 void addColumnGuide(ColumnGuide guide)
          Adds a column guide and repaint the code editor.
 void addNotify()
           
protected  void adjustColumnSelectionModelOnCaretMoving(boolean select)
          Adjusts the column seletion model to false when the caret is moving without selection.
 void append(String text)
           
 void backspaceChar()
          Deletes a char before the caret if there is no selection.
 void backspaceWord()
          Deletes from current caret to the start of the word if the caret is not at the start of the word or to the start of the previous word if the caret is currently at the start of the word.
 void blinkCaret()
          Blinks the caret.
 void blockComments()
          Comments the selected text using block comments.
 void caretUpdated(CaretEvent e)
          This method will be called whenever caret position changes.
static void clearClipboards()
          Clears clipboards memory.
 void clipboardCopy()
          Places the selected text into the clipboard.
 void clipboardCut()
          Deletes the selected text from the text area and places it into the clipboard.
 void clipboardMove(int offset)
          Moves the selected text to the offset.
 void clipboardPaste()
          Inserts the clipboard contents into the document.
 void collapseAll()
          Collapses all expanded spans.
 void collapseFolding()
          Collapses the expanded span if any.
 int columnToX(int column)
          Deprecated. as this method doesn't consider the actual font it is used so when the font is not fix-width, this method will return the wrong result. The correct one to use is columnToX(int, int) which takes the line index.
 int columnToX(int line, int column)
          Converts from the column to x position (in pixels).
 void commentLine()
           
 void commentLine(int line)
           
 void configureStyledLabel(StyledLabel styledLabel, Object userObject)
          Configure the styled label to display the find result.
protected  ClipboardOwner createClipboardOwner()
          Create ClipboardOwner instance.
protected  CodeEditorPainter createCodeEditorPainter(CodeEditor editor)
           
protected  TransferHandler createDefaultTransferHandler()
          Creates the default TransferHandler.
protected  Highlighter createHighlighter()
          Creates the object to use for adding highlights.
protected  LazyLoadDocument createLazyLoadDocument()
          Creates the LazyLoadDocument instance.
protected  OutputStreamWriter createOutputStreamWriter(OutputStream outputStream)
           
 JComponent createOverlay()
           
protected  DocumentEvent createReplaceAllDocumentEvent()
          Creates the DocumentEvent for replace all.
protected  JScrollBar createScrollBar(int orientation)
          Creates the scroll bars used by the CodeEditor.
protected  Searchable createSearchable(CodeEditor editor)
          Creates a Searchable for the CodeEditor.
protected  SelectionModel createSelectionModel()
          Create selection model for CodeEditor.
protected  void customizeDialog(StandardDialog dialog)
          Customizes the dialog to be visible.
protected  void customizeDialogData(StandardDialog dialog)
          Customizes the dialog to be pack.
 void deleteChar()
          Deletes a char at the caret if there is no selection.
 void deleteLine()
          Deletes the entire line including line break associated with the line.
 void deleteWord()
          Deletes from current caret to the start of the next word.
 void discardAllEdits()
           
 void dispose()
          Disposes the CodeEditor.
protected  void documentChanged(DocumentEvent evt)
           
 void duplicateSelection()
          Inserts the selected text to the start of the current selection.
 void escape()
          Clears the selection if any.
 void expandAll()
          Expands all folded spans.
 void expandFolding()
          Expands the folded span if any.
protected  int exportText(String in, StringBuffer out)
          Converts text with LINE_BREAK_CODE_EDITOR as line break to the line break style on this code editor.
 boolean exportToOutputStream(OutputStream outputStream)
          Exports the contents inside the CodeEditor to an output stream.
 void find()
          Shows a find dialog to let the customer input searching text then search the text in the document or the current selected text.
 void findNext()
          Looks for the next match in the document or the current selected text.
 void findPrevious()
          Looks for the previous match in the document or the current selected text.
 int getAnchorSelectionOffset()
          Gets the anchor offset of the selection.
 Color getBracketHighlightColor()
          Returns the bracket highlight color.
 int getBracketLine()
           
 int getBracketPosition()
           
 Color getCaretColor()
          Returns the caret color.
 Point getCaretLocation()
           
 Point getCaretLocationOnScreen()
           
 CaretModel getCaretModel()
           
 int getCaretPosition()
           
 CodeInspector getCodeInspector(int i)
           
 int getCodeInspectorCount()
           
 CodeInspector[] getCodeInspectors()
           
 ColumnGuide[] getColumnGuides()
          Gets all the column guides.
 Dimension getContentSize()
           
 int getCorrespondingColumn(int column, int oldLine, int newLine)
          Get corresponding column in the new line which visually in the same column of the column in the old line.
 int getCurrentIndentForLine(int lineIndex, int[] whitespaceChars)
          Returns the line's current leading indent.
 String getCurrentWord()
           
 String getCurrentWord(String noWordDelimiters)
           
 int[] getCurrentWordBounds()
           
 int[] getCurrentWordBounds(String nonwordDelimiters)
           
 int getDefaultLineBreakStyle()
          Gets the default line break style.
 SyntaxDocument getDocument()
          Returns the document this text area is editing.
 int getDocumentLength()
          Returns the length of the document.
 boolean getDragEnabled()
          Gets the value of the dragEnabled property.
 int getElectricScroll()
          Returns the number of lines from the top and button of the text area that are always visible.
 String getFileName()
          Get the full path to the file that the CodeEditor is currently editing.
 FindAndReplace getFindAndReplace()
           
 int getFirstLine()
          Returns the first line displayed at the text area's origin.
 Highlighter getFixedHighlighter()
          Fetches the object responsible for making fixed highlights that can only be changed through code.
 boolean getFocusCycleRoot()
           
 boolean getFocusTraversalKeysEnabled()
           
 FoldingModel getFoldingModel()
           
 Highlighter getHighlighter()
          Fetches the object responsible for making highlights.
 int getHorizontalOffset()
          Returns the horizontal offset of drawn lines.
 JScrollBar getHorizontalScrollBar()
          Gets the horizontal scroll bar used by CodeEditor.
 int getHorizontalScrollBarPolicy()
          Get the horizontal scroll bar policy.
 InputHandler getInputHandler()
          Returns the input handler.
 InputMethodRequests getInputMethodRequests()
           
 int getLeadSelectionOffset()
          Gets the lead offset of the selection.
 String getLeftWordPart()
           
 String getLeftWordPart(String nonwordDelimiters)
           
 int getLineBreakStyle()
           
 int getLineCount()
          Returns the number of lines in the document.
 int getLineEndOffset(int line)
          Returns the end offset of the specified line.
 int getLineHeight()
           
 Color getLineHighlightColor()
          Returns the line highlight color.
 int getLineLength(int line)
          Gets the length of the specified line.
 int getLineNumber(int offset)
          Returns the line containing the specified offset.
 RowNumberMargin getLineNumberMargin()
           
 int getLineStartOffset(int line)
          Returns the start offset of the specified line.
 int getLineStartOffsetNoSpace(int line)
          Returns the start offset of the specified line exclude the spaces.
 String getLineText(int lineIndex)
          Returns the text on the specified line.
 boolean getLineText(int lineIndex, Segment segment)
          Copies the text on the specified line into a segment.
 int getMagicCaretPosition()
          Returns the `magic' caret position.
 MarginArea getMarginArea()
           
 MarkerArea getMarkerArea()
           
 MarkerModel getMarkerModel()
           
 int getMarkPosition()
          Returns the mark position.
 int getMaxNumberOfClipboards()
           
 CodeEditorPainter getPainter()
          Get CodeEditorPainter instance.
 String getRawText()
          Returns the entire text of this text area.
 String getResourceString(String key)
          Gets the resource string used by CodeEditor.
 Searchable getSearchable()
           
 String getSelectedText()
           
 Color getSelectionColor()
          Returns the selection color.
 int getSelectionEnd()
           
 int getSelectionEnd(int line)
          Gets the offset where the selection ends on the specified line.
 int getSelectionEndLine()
           
 SelectionModel getSelectionModel()
           
 int getSelectionStart()
          Gets the selection start offset on the entire document.
 int getSelectionStart(int line)
          Gets the offset where the selection starts on the specified line.
 int getSelectionStartLine()
          Gets the selection start line.
 Color getSpecialCharactersColor()
          Returns the special characters such as space, tab and end of line color.
 SyntaxStyleSchema getStyles()
          Returns the syntax styles used to paint colorized text.
 int getTabSize()
           
 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.
 TransferHandler getTransferHandler()
           
 JScrollBar getVerticalScrollBar()
          Gets the vertical scroll bar used by CodeEditor.
 int getVerticalScrollBarPolicy()
          Get the vertical scroll bar policy.
 int getVisibleLines()
           
 int getVisualLineCount()
           
 void gotoEndOfLine()
           
 void gotoLine(int line)
          Go to the model line.
 void gotoLineAtView(int line)
          Go to the view line.
 void gotoOffset(int offset)
          Go to the offset.
protected  int importText(String in, StringBuffer out)
          Converts the text with any line break style to LINE_BREAK_CODE_EDITOR style (LF only).
 void indentLine(int line)
           
 boolean indentLine(int lineIndex, boolean decrease)
           
 void indentLinesBetween(int startLine, int endLine)
           
 void indentSelectedLines()
           
 void indentSelection()
          Indents all selected lines no matter if the selection is a line selection or not if there is a selection.
 void initializeDefaultSettings(DefaultSettings defaults)
          setPainter must be called first
 void insertBreak()
          Deletes current selected text if any then inserts a line break.
 void insertChar(String str)
          Inserts the string into the document.
 void inspectCode()
          Triggers CodeInspectors added to this CodeEditor to inspect the code.
 void inspectCode(DocumentEvent event)
          Triggers CodeInspectors added to this CodeEditor to inspect the code.
protected  List<ColumnGuide> internalGetColumnGuides()
          Gets all the column guides.
 boolean isAdjustColumnSelectionOnMouseEvent()
          Gets the flag indicating if the column selection mode should be automatically adjusted on mouse dragging.
 boolean isAutoInspecting()
          Check if autoInspecting is on.
 boolean isBlink()
          Gets the flag indicating if the caret currently is blinking.
 boolean isBlockCaret()
          Checks if the block caret is used.
 boolean isBracketHighlightVisible()
          Checks if the bracket highlight is visible.
 boolean isCaretBlinks()
          Returns true if the caret is blinking, false otherwise.
 boolean isCaretVisible()
          Returns true if the caret is visible, false otherwise.
 boolean isChangePromptDialogPosition()
          Gets the flag indicating if prompt dialog position should be changed to show current selected text.
protected  boolean isColumnSelectionMode(MouseEvent evt)
          Checks if the mouse event indicates a ColumnSelectionModel.
 boolean isContentVisible()
          Get the flag indicating if the content should be visible right now.
 boolean isCopyVisibleTextOnly()
          Gets the flag indicating if only visible text should be copied to clipboard or dragged.
 boolean isDelayContentsOnLoading()
          Get the flag indicating if the contents in the code editor should be hidden while the page need to be loaded.
 boolean isEditable()
          Returns true if this text area is editable, false otherwise.
 boolean isIndentOnPasting()
          Gets the flag indicating if the pasted multiple-line text should respect the indent of the previous line.
 boolean isLineBreakStyleMixed()
           
 boolean isLineHighlightVisible()
          Checks if the line highlight is visible.
 boolean isLineNumberVisible()
           
 boolean isManagingFocus()
          Returns if this component can be traversed by pressing the Tab key.
 boolean isOverwriteEnabled()
           
 boolean isPaintInvalid()
          Get the paint invalid flag.
 boolean isReplaceTabWithSpace()
           
 boolean isSelectionRectangular()
           
 boolean isShowToolTipOverMarkedText()
          Get the flag indicating if the tooltip should be displayed while the mouse hover on a marked text.
 boolean isSkipsEmptyLinesOnLineComments()
          Gets the flag indicating if the line comment action should skip the empty lines.
 boolean isSpecialCharactersVisible()
          Get the flag indicating if the special characters are visible.
 boolean isTabAlignment()
          Get the flag indicating TAB key is to alignment or just add fixed number of spaces.
 boolean isVirtualSpaceAllowed()
           
 void joinLines()
          Joins all selected lines by deleting line breaks and the empty spaces leading the lines.
 void lineComments()
          Comments all selected lines using line comments no matter if the selection is a line selection or not if there is a selection.
 int lineToY(int line)
          Converts a line index to y coordinate.
 void loadActionMap()
          Loads the default actions to the ActionMap so that other tools can look up the action map to find out the actions.
 int modelPositionToOffset(CaretPosition p)
           
 Rectangle modelToView(int offset)
           
 Rectangle modelToView(int startOffset, int endOffset)
           
 int modelToViewLine(int line)
           
 CaretPosition modelToViewPosition(CaretPosition p)
          Get view position from model position.
 void moveToDocumentEnd(boolean select)
          Moves the caret to the end of the document.
 void moveToDocumentStart(boolean select)
          Moves the caret to the start of the document.
 void moveToLineEnd(boolean select)
          Moves the caret to the end of the line where the caret resides.
 void moveToLineStart(boolean select)
          Moves the caret to the start of the line where the caret resides.
 void moveToNextChar(boolean select)
          Moves the caret to the next column if isVirtualSpaceAllowed() is true.
 void moveToNextLine(boolean select)
          Moves the caret to the next line.
 void moveToNextPage(boolean select)
          Moves the caret to the next page.
 void moveToNextWord(boolean select)
          Moves caret to the the word start of the next word.
 void moveToNextWord(boolean select, boolean toWordStart)
          If toWordStart is false, moves caret to the the word end of the current word if the caret is not on the end of the current word or to the word end of the next word if the caret is on the end of the current word.
 void moveToPreviousChar(boolean select)
          Moves the caret to the previous column or stay at column 0 if isVirtualSpaceAllowed() is true.
 void moveToPreviousLine(boolean select)
          Moves the caret to the previous line.
 void moveToPreviousPage(boolean select)
          Moves the caret to the previous page.
 void moveToPreviousWord(boolean select)
          Moves caret to the the word start of the current word if the caret is not on the start of the current word or to the word start of the previous word if the caret is on the start of the current word.
 void moveToPreviousWord(boolean select, boolean toWordEnd)
          If toWordEnd is false, moves caret to the the word start of the current word if the caret is not on the start of the current word or to the word start of the previous word if the caret is on the start of the current word.
 int offsetToLine(int offset)
          Deprecated. replaced by offsetToViewPosition(int)
 CaretPosition offsetToModelPosition(int offset)
           
 CaretPosition offsetToViewPosition(int offset)
           
 int offsetToX(int offset)
          Converts an offset in a document into an x co-ordinate.
 int offsetToX(int line, int offset)
          Deprecated. replaced by offsetToX(int)
 void overwriteSetSelectedText(String str)
          Similar to setSelectedText(), but overwrite the appropriate number of characters if overwrite mode is enabled.
protected  void pageLoadFailedHandling(PageLoadEvent e)
          The action to take while page loading process is failed.
 void pasteWithDialog()
          Shows a dialog so that the customer could choose text from the clipboard contents to paste.
 void pauseBlink()
          Pauses the blink and set caret to display.
 void processKeyEvent(KeyEvent evt)
          Forwards key events directly to the input handler.
 void promptGotoLine()
          Shows a dialog so that the customer could input a line number then jump to the line.
 void promptGotoLineAtView()
           
 void promptGotoOffset()
           
 void propertyChange(PropertyChangeEvent evt)
           
 void quickSearch(String searchingText)
          Shows a Searchable popup to start searching quickly.
protected  Dimension recalculateContentSize()
           
 void recalculateVisibleLines()
          Recalculates the number of visible lines.
 void redo()
          Redo the last action (if possible).
 void removeAllColumnGuides()
          Removes all column guides that were added before and repaint the code editor.
 void removeCodeInspector(CodeInspector inspector)
           
 void removeColumnGuide(ColumnGuide guide)
          Removes a column guide and repaint the code editor.
 void removeNotify()
           
 void repaint()
           
 void repaint(long tm)
           
 void repaint(long tm, int x, int y, int width, int height)
           
 void replace()
          Shows a find and replace dialog to let the customer input searching text then search the text in the document or the current selected text.
protected  void resetContentSize()
           
 void scrollDownPage()
          Scrolls down by one page.
 boolean scrollTo(CaretPosition position)
          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.
 boolean scrollToViewPosition(CaretPosition vp)
          Ensures that the specified line and offset is visible by scrolling the text area if necessary.
protected  boolean scrollToViewPosition(CaretPosition vp, CaretPosition anotherVp)
          Ensures that the specified line and offset is visible by scrolling the text area if necessary.
 void scrollUpPage()
          Scrolls up by one page.
 void select(int caret)
          Sets the caret position.
 void select(int start, int end)
          Selects from the start offset to the end offset.
 void select(int start, int end, boolean scroll)
          Selects from the start offset to the end offset.
 void selectAll()
          Selects all text in the document.
 void selectBlock()
          Selects the code block surrounding the caret.
 void selectionChanged(SelectionEvent e)
          Called when selection changed.
 void selectLine(int line)
          Select the model line.
 void selectLines(int start, int end)
          Select the model lines.
 void selectNone()
          Moves the mark to the caret position.
 void selectToMatchingBracket()
          Selects the block between the closest pair of brackets which contains current caret.
 void selectWord()
          Selects the word in current caret position.
 void selectWord(String noWordSep)
           
 void setAdjustColumnSelectionOnMouseEvent(boolean adjustColumnSelectionOnMouseEvent)
          Sets the flag indicating if the column selection mode should be automatically adjusted on mouse dragging.
 void setAutoInspecting(boolean autoInspecting)
          Sets autoInspecting option.
 void setBlink(boolean blink)
          Sets the flag indicating if the caret currently is blinking.
 void setBlockCaret(boolean blockCaret)
          Sets if the caret should be drawn as a block, false otherwise.
 void setBracketHighlightColor(Color bracketHighlightColor)
          Sets the bracket highlight color.
 void setBracketHighlightVisible(boolean bracketHighlight)
          Enables or disables bracket highlighting.
 void setCaretBlinks(boolean caretBlinks)
          Toggles caret blinking.
 void setCaretColor(Color caretColor)
          Sets the caret color.
 void setCaretPosition(int offset)
           
 void setCaretVisible(boolean caretVisible)
          Sets if the caret should be visible.
 void setChangePromptDialogPosition(boolean changePromptDialogPosition)
          Sets the flag indicating if prompt dialog position should be changed to show current selected text.
 void setContentVisible(boolean contentVisible)
          Set the flag indicating if the content should be visible right now.
 void setCopyVisibleTextOnly(boolean copyVisibleTextOnly)
          Sets the flag indicating if only visible text should be copied to clipboard or dragged.
 void setDelayContentsOnLoading(boolean delayContentsOnLoading)
          Set the flag indicating if the contents in the code editor should be hidden while the page need to be loaded.
 void setDocument(SyntaxDocument document)
          Sets the document this text area is editing.
 void setDragEnabled(boolean b)
          Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component.
 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 setFileName(String pathToFile)
          Set the full path to a local file on the CodeEditor.
 void setFirstLine(int firstLine)
          Sets the line displayed at the text area's origin without updating the scroll bars.
 void setFixedHighlighter(Highlighter h)
          Sets the fixed highlighter to be used.
 void setFoldingModel(FoldingModel foldingModel)
           
 void setFont(Font font)
           
 void setHighlighter(Highlighter h)
          Sets the highlighter to be used.
 void setHorizontalOffset(int horizontalOffset)
          Sets the horizontal offset of drawn lines.
 void setHorizontalScrollBarPolicy(int horizontalScrollBarPolicy)
          Set the horizontal scroll bar policy.
 void setIndentOnPasting(boolean indentOnPasting)
          Sets the flag indicating if the pasted multiple-line text should respect the indent of the previous line.
 void setInputHandler(InputHandler inputHandler)
          Sets the input handler.
 void setLineBreakStyle(int lineBreakStyle)
           
 void setLineHighlight(boolean lineHighlight)
          Enables or disables current line highlighting.
 void setLineHighlightColor(Color lineHighlightColor)
          Sets the line highlight color.
 void setLineNumberVisible(boolean visible)
           
 void setLineText(int lineIndex, String text)
          Sets the text on the specified line.
 void setMagicCaretPosition(int magicCaret)
          Sets the `magic' caret position.
 void setMarginArea(MarginArea marginArea)
           
 void setMarkerArea(MarkerArea markerArea)
           
 void setMarkerModel(MarkerModel markerModel)
           
 void setMaxNumberOfClipboards(int maxNumberOfClipboards)
           
 boolean setOrigin(int firstLine, int horizontalOffset)
          A fast way of changing both the first line and horizontal offset.
 void setOverlayVisible(boolean visible)
           
 void setOverwriteEnabled(boolean overwrite)
          Sets if overwrite mode should be enabled.
 void setPaintInvalid(boolean paintInvalid)
          Sets if invalid lines are to be painted as red tildes.
 void setRawText(String text)
          Sets the content of the code editor.
 void setReplaceTabWithSpace(boolean replaceTabWithSpace)
           
 void setSelectedText(String selectedText)
          Replaces the selection with the specified text.
 void setSelectionColor(Color selectionColor)
          Sets the selection color.
 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 setShowToolTipOverMarkedText(boolean showToolTipOverMarkedText)
          Set the flag indicating if tooltip should be displayed while the mouse hover on a marked text.
 void setSkipsEmptyLinesOnLineComments(boolean skipsEmptyLinesOnLineComments)
          Sets the flag indicating if the line comment action should skip the empty lines.
 void setSpecialCharactersColor(Color specialCharactersColor)
          Sets the special characters such as space, tab and end of line color.
 void setSpecialCharactersVisible(boolean visible)
          Sets if special characters such as space, tab and end of line are to be drawn.
 void setStyles(SyntaxStyleSchema styles)
          Sets the syntax styles used to paint colorized text.
 void setTabAlignment(boolean tabAlignment)
          Set the flag indicating TAB key is to alignment or just add fixed number of spaces.
 void setTabSize(int tabSize)
           
 void setText(String text)
          Sets the entire text of this CodeEditor.
 void setTokenMarker(TokenMarker tokenMarker)
          Sets the document's token marker.
 void setVerticalScrollBarPolicy(int verticalScrollBarPolicy)
          Set the vertical scroll bar policy.
 void setVirtualSpaceAllowed(boolean virtualSpaceAllowed)
           
 void showMessage(String message)
           
 void splitLine()
          Deletes current selected text if any then inserts a line break.
 void startNewLine()
          Inserts a line break after the end of the line where the caret is.
 void stopInspectCode()
          Interrupts the inspection, if it is inspecting.
 void surroundSelection(String prefix, String postfix)
          Surrounds the selected text with prefix and postfix.
 void swap()
          Swaps the left and right component.
 void toggleCase()
          Toggles the case when typing an alphabetic char.
 void toggleFoldingSelection()
          If there is no folding and has selection, the selected text will be folded and shown as "...".
 void toggleOverwrite()
          Toggles the editing mode between overwrite and insert.
 void undo()
          Undo the last action (if possible).
 void unindentSelection()
          Indents all selected lines no matter if the selection is a line selection or not if there is a selection.
protected  void updateBracketHighlight(int newCaretPosition)
           
 void updateScrollBars()
          Updates the state of the scroll bars.
 int viewToModelLine(int line)
           
 CaretPosition viewToModelPosition(CaretPosition p)
          Get model position from view position.
 int xToColumn(int x)
          Deprecated. as this method doesn't consider the actual font it is used so when the font is not fix-width, this method will return the wrong result. The correct one to use is xToColumn(int, int) which takes the line index.
 int xToColumn(int viewLine, int x)
          Converts from x position (in pixels) to column.
 int xToOffset(int viewLine, int x)
          Converts an x co-ordinate to an offset within a document.
 int xyToOffset(int x, int y)
          Converts a point to an offset in the document.
 int yToLine(int y)
          Converts a y co-ordinate to a line index.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT_OF_SCROLLBAR

public static String LEFT_OF_SCROLLBAR
Adding components with this name to the text area will place them left of the horizontal scroll bar.


PROPERTY_OVERWRITE_ENABLED

public static final String PROPERTY_OVERWRITE_ENABLED
See Also:
Constant Field Values

PROPERTY_FIRST_LINE

public static final String PROPERTY_FIRST_LINE
See Also:
Constant Field Values

PROPERTY_VISIBLE_LINES

public static final String PROPERTY_VISIBLE_LINES
See Also:
Constant Field Values

PROPERTY_COLUMN_SELECTION_ENABLED

public static final String PROPERTY_COLUMN_SELECTION_ENABLED
See Also:
Constant Field Values

_marginArea

public MarginArea _marginArea

_lineNumberMargin

public RowNumberMargin _lineNumberMargin

_clipboards

protected static List<Transferable> _clipboards

_searchable

public Searchable _searchable

_inspectionTimer

public Timer _inspectionTimer

_defaultSettings

protected CodeEditorSettings _defaultSettings

_localSettings

protected DefaultCodeEditorSettings _localSettings

PROPERTY_EDITABLE

public static final String PROPERTY_EDITABLE
See Also:
Constant Field Values

CENTER

protected static String CENTER

RIGHT

protected static String RIGHT

LEFT

protected static String LEFT

BOTTOM

protected static String BOTTOM

focusedComponent

@Deprecated
protected static CodeEditor focusedComponent
Deprecated. no longer use static field to track the CodeEditor that has focus.

caretTimer

@Deprecated
protected static Timer caretTimer
Deprecated. no longer use static field to start one timer for all CodeEditors. Each CodeEditor manages its own timer.

_painter

protected CodeEditorPainter _painter

_caretVisible

protected boolean _caretVisible

_editable

protected boolean _editable

_settings

protected CodeEditorSettings _settings

_firstLine

protected int _firstLine

_visibleLines

protected int _visibleLines

_horizontalOffset

protected int _horizontalOffset

_verticalScrollBar

protected JScrollBar _verticalScrollBar

_horizontalScrollBar

protected JScrollBar _horizontalScrollBar

_scrollBarsInitialized

protected boolean _scrollBarsInitialized

_document

protected SyntaxDocument _document

_documentHandler

protected com.jidesoft.editor.CodeEditor.DocumentHandler _documentHandler

_undoableEditListener

protected UndoableEditListener _undoableEditListener

lineSegment

public Segment lineSegment

biasLeft

protected boolean biasLeft

bracketPosition

protected int bracketPosition
Model column of the bracket.


bracketLine

protected int bracketLine
Model line of the bracket.


_magicCaret

protected int _magicCaret
Magic caret in X.


_overwrite

protected boolean _overwrite

_caretModel

protected CaretModel _caretModel

_selectionModel

protected SelectionModel _selectionModel

PROPERTY_TAB_SIZE

public static final String PROPERTY_TAB_SIZE
See Also:
Constant Field Values

PROPERTY_REPLACE_TAB_WITH_SPACE

public static final String PROPERTY_REPLACE_TAB_WITH_SPACE
See Also:
Constant Field Values

PROPERTY_LINE_BREAK_STYLE

public static final String PROPERTY_LINE_BREAK_STYLE
See Also:
Constant Field Values

PROPERTY_MAX_NUMBER_OF_CLIPBOARDS

public static final String PROPERTY_MAX_NUMBER_OF_CLIPBOARDS
See Also:
Constant Field Values

SMART_HOME_END_PROPERTY

public static final String SMART_HOME_END_PROPERTY
See Also:
Constant Field Values
Constructor Detail

CodeEditor

public CodeEditor()
Creates a new CodeEditor with the default settings.


CodeEditor

public CodeEditor(DefaultSettings defaults)
Creates a new CodeEditor with the specified settings.

Parameters:
defaults - The default settings
Method Detail

createSearchable

protected Searchable createSearchable(CodeEditor editor)
Creates a Searchable for the CodeEditor.

Parameters:
editor - the CodeEditor.
Returns:
a Searchable for CodeEditor.

swap

public void swap()
Swaps the left and right component. By default, we have MarginArea on the left hand side and vertical scrollbar on the right hand side. This swap method will swap the two components and put MarginArea to the right side and the vertical scroll bar to the left side.


createCodeEditorPainter

protected CodeEditorPainter createCodeEditorPainter(CodeEditor editor)

createDefaultTransferHandler

protected TransferHandler createDefaultTransferHandler()
Creates the default TransferHandler.

Returns:
the created TransferHandler instance.
Since:
3.4.7

createScrollBar

protected JScrollBar createScrollBar(int orientation)
Creates the scroll bars used by the CodeEditor. There are two of them - one vertical and the other horizontal.

Parameters:
orientation - the orientation of the scroll bar.
Returns:
the scroll bar.

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

getTransferHandler

public TransferHandler getTransferHandler()
Overrides:
getTransferHandler in class JComponent

getStyles

public final SyntaxStyleSchema getStyles()
Returns the syntax styles used to paint colorized text. Entry n will be used to paint tokens with id = n.

Returns:
return the syntax styles.
See Also:
Token

setStyles

public final void setStyles(SyntaxStyleSchema styles)
Sets the syntax styles used to paint colorized text. Entry n will be used to paint tokens with id = n.

Parameters:
styles - The syntax styles
See Also:
Token

getCaretColor

public final Color getCaretColor()
Returns the caret color.

Returns:
the caret color.

setCaretColor

public final void setCaretColor(Color caretColor)
Sets the caret color.

Parameters:
caretColor - The caret color

getSelectionColor

public final Color getSelectionColor()
Returns the selection color.

Returns:
the selection color.

setSelectionColor

public final void setSelectionColor(Color selectionColor)
Sets the selection color.

Parameters:
selectionColor - The selection color

getLineHighlightColor

public final Color getLineHighlightColor()
Returns the line highlight color.

Returns:
the line highlight color.

setLineHighlightColor

public final void setLineHighlightColor(Color lineHighlightColor)
Sets the line highlight color.

Parameters:
lineHighlightColor - The line highlight color

isLineHighlightVisible

public final boolean isLineHighlightVisible()
Checks if the line highlight is visible.

Returns:
true if line highlight is enabled, false otherwise.

setLineHighlight

public final void setLineHighlight(boolean lineHighlight)
Enables or disables current line highlighting.

Parameters:
lineHighlight - True if current line highlight should be enabled, false otherwise

getBracketHighlightColor

public final Color getBracketHighlightColor()
Returns the bracket highlight color.

Returns:
the bracket highlight color.

setBracketHighlightColor

public final void setBracketHighlightColor(Color bracketHighlightColor)
Sets the bracket highlight color.

Parameters:
bracketHighlightColor - The bracket highlight color

isBracketHighlightVisible

public final boolean isBracketHighlightVisible()
Checks if the bracket highlight is visible.

Returns:
true if bracket highlighting is enabled, false otherwise. When bracket highlighting is enabled, the bracket matching the one before the caret (if any) is highlighted.

setBracketHighlightVisible

public final void setBracketHighlightVisible(boolean bracketHighlight)
Enables or disables bracket highlighting. When bracket highlighting is enabled, the bracket matching the one before the caret (if any) is highlighted.

Parameters:
bracketHighlight - True if bracket highlighting should be enabled, false otherwise

isBlockCaret

public final boolean isBlockCaret()
Checks if the block caret is used. By default the caret is drawn as one vertical line. If the flag returns true, a block will be used as caret.

Returns:
true if the caret should be drawn as a block, false otherwise.

setBlockCaret

public final void setBlockCaret(boolean blockCaret)
Sets if the caret should be drawn as a block, false otherwise.

Parameters:
blockCaret - True if the caret should be drawn as a block, false otherwise.

isCaretBlinks

public final boolean isCaretBlinks()
Returns true if the caret is blinking, false otherwise.

Returns:
true if the caret should blink. Otherwise false.

setCaretBlinks

public void setCaretBlinks(boolean caretBlinks)
Toggles caret blinking.

Parameters:
caretBlinks - True if the caret should blink, false otherwise

getSpecialCharactersColor

public final Color getSpecialCharactersColor()
Returns the special characters such as space, tab and end of line color.

Returns:
the color of special characters.

setSpecialCharactersColor

public final void setSpecialCharactersColor(Color specialCharactersColor)
Sets the special characters such as space, tab and end of line color.

Parameters:
specialCharactersColor - The EOL marker color

isSpecialCharactersVisible

public final boolean isSpecialCharactersVisible()
Get the flag indicating if the special characters are visible.

Returns:
true if special characters such as space, tab and end of line are drawn, false otherwise.

setSpecialCharactersVisible

public final void setSpecialCharactersVisible(boolean visible)
Sets if special characters such as space, tab and end of line are to be drawn.

Parameters:
visible - True if special characters such as space, tab and end of line should be drawn, false otherwise

isPaintInvalid

public boolean isPaintInvalid()
Get the paint invalid flag.

Returns:
true if invalid lines are painted as red tildes (~). Otherwise false.

setPaintInvalid

public void setPaintInvalid(boolean paintInvalid)
Sets if invalid lines are to be painted as red tildes.

Parameters:
paintInvalid - True if invalid lines should be drawn, false otherwise

isVirtualSpaceAllowed

public boolean isVirtualSpaceAllowed()

setVirtualSpaceAllowed

public void setVirtualSpaceAllowed(boolean virtualSpaceAllowed)

getMarkerArea

public MarkerArea getMarkerArea()

setMarkerArea

public void setMarkerArea(MarkerArea markerArea)

initializeDefaultSettings

public void initializeDefaultSettings(DefaultSettings defaults)
setPainter must be called first

Parameters:
defaults - the default settings

addCodeInspector

public void addCodeInspector(CodeInspector inspector)

removeCodeInspector

public void removeCodeInspector(CodeInspector inspector)

getCodeInspectors

public CodeInspector[] getCodeInspectors()

getCodeInspectorCount

public int getCodeInspectorCount()

getCodeInspector

public CodeInspector getCodeInspector(int i)

isAutoInspecting

public boolean isAutoInspecting()
Check if autoInspecting is on. If it is on, the inspection will be triggered automatically when document changes.

Returns:
the true if autoInspecting is on. Other returns false.

setAutoInspecting

public void setAutoInspecting(boolean autoInspecting)
Sets autoInspecting option. If it is on, the inspection will be triggered automatically when document changes.

Parameters:
autoInspecting - true to turn autoInspecting on. False to turn it off.

stopInspectCode

public void stopInspectCode()
Interrupts the inspection, if it is inspecting.


inspectCode

public void inspectCode()
Triggers CodeInspectors added to this CodeEditor to inspect the code.


inspectCode

public void inspectCode(DocumentEvent event)
Triggers CodeInspectors added to this CodeEditor to inspect the code.

Parameters:
event - the DocumentEvent. It's up to CodeInspector if it will look at the DocumentEvent to do incremental inspection.

getLineHeight

public int getLineHeight()

isManagingFocus

public final boolean isManagingFocus()
Returns if this component can be traversed by pressing the Tab key. This returns false.

Overrides:
isManagingFocus in class JComponent

getPainter

public final CodeEditorPainter getPainter()
Get CodeEditorPainter instance.

Returns:
the object responsible for painting this text area.

getInputHandler

public final InputHandler getInputHandler()
Returns the input handler.

Returns:
the input handler.

setInputHandler

public void setInputHandler(InputHandler inputHandler)
Sets the input handler.

Parameters:
inputHandler - The new input handler

isCaretVisible

public final boolean isCaretVisible()
Returns true if the caret is visible, false otherwise.

Returns:
true if caret is visible. Otherwise false.

setCaretVisible

public void setCaretVisible(boolean caretVisible)
Sets if the caret should be visible.

Parameters:
caretVisible - True if the caret should be visible, false otherwise

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.

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

Parameters:
electricScroll - The number of lines always visible from the top or bottom

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 first line displayed at the text area's origin.

Returns:
the first 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.

Parameters:
firstLine - the first view line to display.

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.

Returns:
the horizontal offset.

setHorizontalOffset

public void setHorizontalOffset(int horizontalOffset)
Sets the horizontal offset of drawn lines. This can be used to implement horizontal scrolling.

Parameters:
horizontalOffset - offset The new horizontal offset

setOrigin

public boolean setOrigin(int firstLine,
                         int horizontalOffset)
A fast way of changing both the first line and horizontal offset.

Parameters:
firstLine - The new first line
horizontalOffset - The new horizontal offset
Returns:
True if any of the values were changed, false otherwise

scrollToCaret

public boolean scrollToCaret()
Ensures that the caret is visible by scrolling the text area if necessary.

Returns:
True if scrolling was actually performed, false if the caret was already visible

scrollTo

public boolean scrollTo(CaretPosition position)
Ensures that the specified line and offset is visible by scrolling the text area if necessary.

Parameters:
position - the caret model position
Returns:
True if scrolling was actually performed, false if the line and offset was already visible

scrollToViewPosition

public boolean scrollToViewPosition(CaretPosition vp)
Ensures that the specified line and offset is visible by scrolling the text area if necessary.

Parameters:
vp - the caret view position
Returns:
True if scrolling was actually performed, false if the line and offset was already visible

scrollToViewPosition

protected boolean scrollToViewPosition(CaretPosition vp,
                                       CaretPosition anotherVp)
Ensures that the specified line and offset is visible by scrolling the text area if necessary.

Parameters:
vp - the caret view position
anotherVp - another caret view position. non-null value means this view position is better to be considered on scrolling
Returns:
True if scrolling was actually performed, false if the line and offset was already visible
Since:
3.3.2

createReplaceAllDocumentEvent

protected DocumentEvent createReplaceAllDocumentEvent()
Creates the DocumentEvent for replace all. It is invoked only once after replacing all is finished.

Returns:
a DocumentEvent.
Since:
3.5.7

lineToY

public int lineToY(int line)
Converts a line index to y coordinate.

Parameters:
line - the view line index
Returns:
the y coordinate of the line.

yToLine

public int yToLine(int y)
Converts a y co-ordinate to a line index.

The meaning of the return value is changed since 2.10.2. Right now it returns view line instead of model line. Please invoke xyToOffset() to get the offset first, then invoke offsetToModelPosition() to get the model line.

Parameters:
y - The y coordinate
Returns:
the view line index at the y coordinate.

offsetToX

public final int offsetToX(int offset)
Converts an offset in a document into an x co-ordinate. This is a slow version that can be used any time.

Parameters:
offset - the offset in a document
Returns:
the X to start painting the offset.

offsetToX

@Deprecated
public final int offsetToX(int line,
                                      int offset)
Deprecated. replaced by offsetToX(int)

Converts an offset in a line into an x co-ordinate. This is a slow version that can be used any time.

Parameters:
line - The line
offset - The model offset, from the start of the line
Returns:
the X to start painting the offset.

_offsetToX

@Deprecated
public int _offsetToX(int line,
                                 int offset)
Deprecated. replaced by _offsetToX(int)

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.

Parameters:
line - The line
offset - The offset, from the start of the line
Returns:
the X to start painting the offset.

_offsetToX

public int _offsetToX(int offset)
Converts an offset in a document 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.

Parameters:
offset - The offset, from the start of the line
Returns:
the X to start painting the offset.

xToColumn

public int xToColumn(int x)
Deprecated. as this method doesn't consider the actual font it is used so when the font is not fix-width, this method will return the wrong result. The correct one to use is xToColumn(int, int) which takes the line index.

Converts from x position (in pixels) to column. Because we only support fix-width font, this method has nothing to do with the actual text. All it does is to use the char width to divide the x position. It does consider the horizontal scroll bar position when calculating.

Parameters:
x - the x position in pixels. The x position is not counted from the line beginning but from the first visible pixel because of the scroll bar.
Returns:
the column

xToColumn

public int xToColumn(int viewLine,
                     int x)
Converts from x position (in pixels) to column. The difference between this method and xToOffset is this method will consider the virtual spaces after the line end. For example, if line 0 has 10 characters, each character needs 6 pixels, xToOffset(0, 66) will return 10 but xToColumn(0, 66) will return 11.

The meaning of the input parameter is changed to view line since 2.10.2. If you ever invoked this method before, please re-check and make sure you will invoke this method with view line index instead of model line index.

Parameters:
viewLine - the view line index
x - the x position in pixels
Returns:
the view column

columnToX

@Deprecated
public int columnToX(int column)
Deprecated. as this method doesn't consider the actual font it is used so when the font is not fix-width, this method will return the wrong result. The correct one to use is columnToX(int, int) which takes the line index.

Converts from the column to x position (in pixels). Because we only support fix-width font, this method has nothing to do with the actual text. All it does is to use the char width to multiple the column. It does consider the horizontal scroll bar position when calculating.

Parameters:
column - the column
Returns:
the x position.

columnToX

public int columnToX(int line,
                     int column)
Converts from the column to x position (in pixels). The x position is not counted from the line beginning but from the first visible pixel because of the scroll bar. The different between this method and the offsetToX method is this method will consider the virtual spaces after the line end. For example, if line 0 has 10 characters, each character needs 6 pixels, offsetToX(0, 11) will return 60 but columnToX(0, 11) will return 66.

Parameters:
line - the view line index
column - the view column
Returns:
the x position. The x position is not counted from the line beginning but from the first visible pixel because of the scroll bar

xToOffset

public int xToOffset(int viewLine,
                     int x)
Converts an x co-ordinate to an offset within a document.

In previous releases earlier than 2.10.2, the definition of the first parameter and the return value are different. If you ever invoked this method explicitly, please use the following code to replace the original implementation. int viewLine = modelToViewLine(modelLine); int offsetInDocument = xToOffset(viewLine, x); int offsetInLine = offsetInDocument - getLineStartOffset(modelLine);

Parameters:
viewLine - the view line
x - The x co-ordinate
Returns:
the offset within the document.

xyToOffset

public int xyToOffset(int x,
                      int y)
Converts a point to an offset in the document.

Parameters:
x - The x co-ordinate of the point
y - The y co-ordinate of the point
Returns:
the offset in the document at the x and y coordinates.

getDocument

public final SyntaxDocument getDocument()
Returns the document this text area is editing.

Returns:
the document.

setDocument

public void setDocument(SyntaxDocument document)
Sets the document this text area is editing.

Parameters:
document - The document

getTokenMarker

public final TokenMarker getTokenMarker()
Returns the document's token marker. Equivalent to calling getDocument().getTokenMarker().

Returns:
the token marker.

setTokenMarker

public final void setTokenMarker(TokenMarker tokenMarker)
Sets the document's token marker. Equivalent to calling getDocument().setTokenMarker().

Parameters:
tokenMarker - The token marker

getDocumentLength

public final int getDocumentLength()
Returns the length of the document. Equivalent to calling getDocument().getLength().

Returns:
the document length.

getLineCount

public final int getLineCount()
Returns the number of lines in the document.

Returns:
the number of lines in the document.

getVisualLineCount

public int getVisualLineCount()

getLineNumber

public final int getLineNumber(int offset)
Returns the line containing the specified offset.

Parameters:
offset - The offset
Returns:
the line number of the offset.

getLineStartOffset

public int getLineStartOffset(int line)
Returns the start offset of the specified line.

Parameters:
line - The line
Returns:
The start offset of the specified line, or -1 if the line is invalid

getLineStartOffsetNoSpace

public int getLineStartOffsetNoSpace(int line)
Returns the start offset of the specified line exclude the spaces.

Parameters:
line - The line
Returns:
The start offset of the specified line, or -1 if the line is invalid

getLineEndOffset

public int getLineEndOffset(int line)
Returns the end offset of the specified line.

Parameters:
line - The line
Returns:
The end offset of the specified line, or -1 if the line is invalid.

getLineLength

public int getLineLength(int line)
Gets the length of the specified line.

Parameters:
line - the line
Returns:
the length of the specified line.

getText

public String getText()
Returns the entire text of this text area.

Returns:
the text with the line break style as specified on this code editor.

setText

public void setText(String text)
Sets the entire text of this CodeEditor.

Please note, the text can have any kind of line breaks. Internally, we will use importText(String, StringBuffer) to convert. If you know your text doesn't have any inconsistency in the line breaks, you can use setRawText(String) to avoid the unnecessary conversion. Otherwise we will try to import the first 1000 (of course only if the text length is less than 1000) to see what the line style is.

Parameters:
text - the new text.

append

public void append(String text)

getText

public final String getText(int start,
                            int len)
Returns the specified substring of the document.

Parameters:
start - The start offset
len - The length of the substring
Returns:
The substring, or null if the offsets are invalid

getText

public final void getText(int start,
                          int len,
                          Segment segment)
Copies the specified substring of the document into a segment. If the offsets are invalid, the segment will contain a null string.

Parameters:
start - The start offset
len - The length of the substring
segment - The segment

exportText

protected int exportText(String in,
                         StringBuffer out)
Converts text with LINE_BREAK_CODE_EDITOR as line break to the line break style on this code editor.

Parameters:
in - the text with LINE_BREAK_CODE_EDITOR as line break.
out - the text using the line break style set on the code editor as line break.
Returns:
the line break style used in the input string.

importText

protected int importText(String in,
                         StringBuffer out)
Converts the text with any line break style to LINE_BREAK_CODE_EDITOR style (LF only).

Parameters:
in - the text with any line break style.
out - the text with LINE_BREAK_CODE_EDITOR as line break style.
Returns:
the line break style used in the input string.

getRawText

public String getRawText()
Returns the entire text of this text area. Please note, the text will use LF as line break. If you want the proper line break according to the line break style on this code editor, use exportText(String, StringBuffer))} instead.

Returns:
the entire text of this text area.

setRawText

public void setRawText(String text)
Sets the content of the code editor. Different from setText(String), this method assumes the line break used in the text is LF only. If you are not sure about this, you should use setText(String) instead.

Parameters:
text - the raw text.

getLineText

public final String getLineText(int lineIndex)
Returns the text on the specified line.

Parameters:
lineIndex - The line
Returns:
The text, or null if the line is invalid

getLineText

public final boolean getLineText(int lineIndex,
                                 Segment segment)
Copies the text on the specified line into a segment. If the line is invalid, the segment will contain a null string.

Parameters:
lineIndex - The line
segment - the segment
Returns:
true if getLineText succeed. Otherwise returns false.

setLineText

public final void setLineText(int lineIndex,
                              String text)
Sets the text on the specified line.

Parameters:
lineIndex - the line index
text - the text

getSelectionStart

public final int getSelectionStart()
Gets the selection start offset on the entire document.

Returns:
the selection start offset.

getSelectionStart

public int getSelectionStart(int line)
Gets the offset where the selection starts on the specified line.

Parameters:
line - the specified line
Returns:
the offset where the selection starts on the specified line.

getSelectionStartLine

public final int getSelectionStartLine()
Gets the selection start line.

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.

Parameters:
selectionStart - The selection start
See Also:
select(int, int)

surroundSelection

public final void surroundSelection(String prefix,
                                    String postfix)
Surrounds the selected text with prefix and postfix.

Parameters:
prefix - String
postfix - String

selectWord

public void selectWord()
Selects the word in current caret position.


selectWord

public void selectWord(String noWordSep)

getCurrentWordBounds

public int[] getCurrentWordBounds()

getLeftWordPart

public String getLeftWordPart()

getLeftWordPart

public String getLeftWordPart(String nonwordDelimiters)

getCurrentWordBounds

public int[] getCurrentWordBounds(String nonwordDelimiters)

getCurrentWord

public String getCurrentWord()

getCurrentWord

public String getCurrentWord(String noWordDelimiters)

selectToMatchingBracket

public void selectToMatchingBracket()
Selects the block between the closest pair of brackets which contains current caret.


selectBlock

public void selectBlock()
Selects the code block surrounding the caret.


gotoEndOfLine

public void gotoEndOfLine()

commentLine

public void commentLine(int line)

commentLine

public void commentLine()

indentSelectedLines

public void indentSelectedLines()

indentLinesBetween

public void indentLinesBetween(int startLine,
                               int endLine)

indentLine

public void indentLine(int line)

selectLine

public void selectLine(int line)
Select the model line.

Parameters:
line - the model line index

selectLines

public void selectLines(int start,
                        int end)
Select the model lines.

Parameters:
start - the start model line index
end - the end model line index

getSelectionEnd

public final int getSelectionEnd()
Returns:
the selection end offset.

getSelectionEnd

public int getSelectionEnd(int line)
Gets the offset where the selection ends on the specified line.

Parameters:
line - the specified 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 new selection end.

Parameters:
selectionEnd - The selection end
See Also:
select(int, int)

getLeadSelectionOffset

public int getLeadSelectionOffset()
Gets the lead offset of the selection. If the selection model has no selection, it will return the caret offset in CaretModel. If it has selection and the caret offset is at the selection end, it will return the selection start. In all other cases, the selection end will be returned.

Returns:
the lead selection offset.

getAnchorSelectionOffset

public int getAnchorSelectionOffset()
Gets the anchor offset of the selection. If the selection model has no selection, it will return the caret offset in CaretModel. If it has selection and the caret offset is at the selection start, it will return the selection end. In all other cases, the selection start will be returned.

Returns:
the lead selection offset.

getMarkPosition

public final int getMarkPosition()
Returns the mark position. This will be the opposite selection bound to the caret position.

Returns:
the mark position.

select

public final void select(int caret)
Sets the caret position. The new selection will consist of the caret position only (hence no text will be selected)

Parameters:
caret - The caret position
See Also:
select(int, int)

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.

By default, this method will scroll to make caret visible only if the code editor has focus.

Parameters:
start - The start offset
end - The end offset

select

public void select(int start,
                   int end,
                   boolean scroll)
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. This method can scroll the caret visible depending on the value of the scroll parameter.

Parameters:
start - The start offset
end - The end offset
scroll - true or false. True to scroll the caret visible after selecting the text.

getSelectedText

public final String getSelectedText()
Returns:
the selected text, or null if no selection is active.

setSelectedText

public void setSelectedText(String selectedText)
Replaces the selection with the specified text.

Parameters:
selectedText - The replacement text for the selection

isEditable

public final boolean isEditable()
Returns true if this text area is editable, false otherwise.

Returns:
true if the CodeEditor is editable.

setEditable

public final void setEditable(boolean editable)
Sets if this component is editable.

Parameters:
editable - True if this text area should be editable, false otherwise

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.

Returns:
the magic caret position.

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.

Parameters:
magicCaret - The magic caret position

overwriteSetSelectedText

public void overwriteSetSelectedText(String str)
Similar to setSelectedText(), but overwrite the appropriate number of characters if overwrite mode is enabled.

Parameters:
str - The string
See Also:
setSelectedText(String), isOverwriteEnabled()

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.

Parameters:
overwrite - True if overwrite mode should be enabled, false otherwise.

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.

Parameters:
rectSelect - True if the selection should be rectangular, false otherwise.

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)

undo

public void undo()
Undo the last action (if possible).


redo

public void redo()
Redo the last action (if possible).


addNotify

public void addNotify()
Overrides:
addNotify in class JComponent

removeNotify

public void removeNotify()
Overrides:
removeNotify in class JComponent

processKeyEvent

public void processKeyEvent(KeyEvent evt)
Forwards key events directly to the input handler. This is slightly faster than using a KeyListener because some Swing overhead is avoided.

Overrides:
processKeyEvent in class JComponent

updateBracketHighlight

protected void updateBracketHighlight(int newCaretPosition)

documentChanged

protected void documentChanged(DocumentEvent evt)

isBlink

public boolean isBlink()
Gets the flag indicating if the caret currently is blinking.

Returns:
true if the caret is blinking. Otherwise false.
Since:
3.3.7

setBlink

public void setBlink(boolean blink)
Sets the flag indicating if the caret currently is blinking.

Parameters:
blink - the flag
Since:
3.3.7

pauseBlink

public void pauseBlink()
Pauses the blink and set caret to display. Please make sure that you will invoke blinkCaret() to restart the caret blinking.


isTabAlignment

public boolean isTabAlignment()
Get the flag indicating TAB key is to alignment or just add fixed number of spaces.

This flag will only take effect when isReplaceTabWithSpace() returns true.

The default value of this flag is false to keep original behavior. If you want to make tab align the column, please set this flag to true.

Returns:
the flag.

setTabAlignment

public void setTabAlignment(boolean tabAlignment)
Set the flag indicating TAB key is to alignment or just add fixed number of spaces.

Parameters:
tabAlignment - the flag
See Also:
isTabAlignment()

getHorizontalScrollBarPolicy

public int getHorizontalScrollBarPolicy()
Get the horizontal scroll bar policy.

The return value could be ScrollPane.SCROLLBARS_ALWAYS, ScrollPane.SCROLLBARS_AS_NEEDED or ScrollPane.SCROLLBARS_NEVER. By default the value is ScrollPane.SCROLLBARS_ALWAYS for backward compatibility.

Returns:
the policy.

setHorizontalScrollBarPolicy

public void setHorizontalScrollBarPolicy(int horizontalScrollBarPolicy)
Set the horizontal scroll bar policy.

Parameters:
horizontalScrollBarPolicy - the policy.
See Also:
getHorizontalScrollBarPolicy()

getVerticalScrollBarPolicy

public int getVerticalScrollBarPolicy()
Get the vertical scroll bar policy.

The return value could be ScrollPane.SCROLLBARS_ALWAYS, ScrollPane.SCROLLBARS_AS_NEEDED or ScrollPane.SCROLLBARS_NEVER. By default the value is ScrollPane.SCROLLBARS_ALWAYS for backward compatibility.

Returns:
the policy.

setVerticalScrollBarPolicy

public void setVerticalScrollBarPolicy(int verticalScrollBarPolicy)
Set the vertical scroll bar policy.

Parameters:
verticalScrollBarPolicy - the policy.
See Also:
getVerticalScrollBarPolicy()

isShowToolTipOverMarkedText

public boolean isShowToolTipOverMarkedText()
Get the flag indicating if the tooltip should be displayed while the mouse hover on a marked text.

By default, the flag is false. You could set it to true to display the tooltip for the offsets defined in marker model.

Returns:
true if tooltip should be displayed. Otherwise false.
See Also:
getMarkerModel()

setShowToolTipOverMarkedText

public void setShowToolTipOverMarkedText(boolean showToolTipOverMarkedText)
Set the flag indicating if tooltip should be displayed while the mouse hover on a marked text.

Parameters:
showToolTipOverMarkedText - the flag
See Also:
isShowToolTipOverMarkedText()

getFileName

public String getFileName()
Get the full path to the file that the CodeEditor is currently editing.

Returns:
the file name.

setFileName

public void setFileName(String pathToFile)
Set the full path to a local file on the CodeEditor. Unless setText(String) where the content of the file is loaded fully into memory, CodeEditor will load the file using lazy-loading.

Parameters:
pathToFile - the full path to a local file.

createLazyLoadDocument

protected LazyLoadDocument createLazyLoadDocument()
Creates the LazyLoadDocument instance.

Returns:
the LazyLoadDocument instance.

exportToOutputStream

public boolean exportToOutputStream(OutputStream outputStream)
                             throws IOException,
                                    BadLocationException
Exports the contents inside the CodeEditor to an output stream.

Please be noted that, the contents can not be saved to the same file as getFileName()

Parameters:
outputStream - the output stream
Returns:
true if exporting successfully. Otherwise false.
Throws:
IOException - if there is any I/O issue.
BadLocationException - if there is any document reading issue.

createOutputStreamWriter

protected OutputStreamWriter createOutputStreamWriter(OutputStream outputStream)

isContentVisible

public boolean isContentVisible()
Get the flag indicating if the content should be visible right now.

Returns:
true if the content should be visible. Otherwise false.
See Also:
setContentVisible(boolean)

setContentVisible

public void setContentVisible(boolean contentVisible)
Set the flag indicating if the content should be visible right now.

By default, the flag is true to paint contents. In some scenarios, for example, dragging scroll bars in a extremely large file, setting this flag to false will speed up the dragging process.

Parameters:
contentVisible - the flag

isDelayContentsOnLoading

public boolean isDelayContentsOnLoading()
Get the flag indicating if the contents in the code editor should be hidden while the page need to be loaded.

Returns:
true if the contents need to be hidden. Otherwise false.
See Also:
setDelayContentsOnLoading(boolean)

setDelayContentsOnLoading

public void setDelayContentsOnLoading(boolean delayContentsOnLoading)
Set the flag indicating if the contents in the code editor should be hidden while the page need to be loaded.

By default, the flag is false to leave contents visible. However, if you don't like to see the obvious slowness on huge files on dragging the thumb in the vertical scroll bar, please set this flag to true.

Parameters:
delayContentsOnLoading - the flag

isChangePromptDialogPosition

public boolean isChangePromptDialogPosition()
Gets the flag indicating if prompt dialog position should be changed to show current selected text.

Returns:
true if prompt dialog position to be changed. Otherwise false.
See Also:
setChangePromptDialogPosition(boolean)

setChangePromptDialogPosition

public void setChangePromptDialogPosition(boolean changePromptDialogPosition)
Sets the flag indicating if prompt dialog position should be changed to show current selected text.

By default, this flag is false. The prompt dialog will not change its position on searching, which helps the client to click "replace" continuously. Target CodeEditor will be scrolled to show current selection.

You could change this flag to true to switch to the behavior before 2.11.1.

Parameters:
changePromptDialogPosition - the flag

isIndentOnPasting

public boolean isIndentOnPasting()
Gets the flag indicating if the pasted multiple-line text should respect the indent of the previous line.

Returns:
true if indent to be respected. Otherwise false.
See Also:
setIndentOnPasting(boolean)

setIndentOnPasting

public void setIndentOnPasting(boolean indentOnPasting)
Sets the flag indicating if the pasted multiple-line text should respect the indent of the previous line.

By default, the flag is true.

Parameters:
indentOnPasting - the flag

isCopyVisibleTextOnly

public boolean isCopyVisibleTextOnly()
Gets the flag indicating if only visible text should be copied to clipboard or dragged.

Returns:
true if only visible text should be copied. Otherwise false.
Since:
3.4.1
See Also:
setCopyVisibleTextOnly(boolean)

setCopyVisibleTextOnly

public void setCopyVisibleTextOnly(boolean copyVisibleTextOnly)
Sets the flag indicating if only visible text should be copied to clipboard or dragged.

The default value is false to keep the behavior backward compatibility.

Parameters:
copyVisibleTextOnly - the flag
Since:
3.4.1

isSkipsEmptyLinesOnLineComments

public boolean isSkipsEmptyLinesOnLineComments()
Gets the flag indicating if the line comment action should skip the empty lines.

Returns:
true if the empty lines should be skipped. Otherwise false.
Since:
3.4.3
See Also:
setSkipsEmptyLinesOnLineComments(boolean)

setSkipsEmptyLinesOnLineComments

public void setSkipsEmptyLinesOnLineComments(boolean skipsEmptyLinesOnLineComments)
Sets the flag indicating if the line comment action should skip the empty lines.

By default, the value is false to keep backward compatibility.

Parameters:
skipsEmptyLinesOnLineComments - the flag
Since:
3.4.3

pageLoadFailedHandling

protected void pageLoadFailedHandling(PageLoadEvent e)
The action to take while page loading process is failed. In most cases, it's caused by memory used up.

By default, it do nothing. You could override this method to release memory from other parts of your application.

Parameters:
e - the page load event.

getFocusTraversalKeysEnabled

public boolean getFocusTraversalKeysEnabled()
Overrides:
getFocusTraversalKeysEnabled in class Component

getFocusCycleRoot

public boolean getFocusCycleRoot()

isColumnSelectionMode

protected boolean isColumnSelectionMode(MouseEvent evt)
Checks if the mouse event indicates a ColumnSelectionModel.

By default, it returns true if the ALT_MASK is on. You could change it to the code below to switch back to the old behavior earlier than 3.3.0.

 return (evt.getModifiers() & InputEvent.CTRL_MASK) != 0;
 

Parameters:
evt - the mouse event
Returns:
true if the mouse event indicates a ColumnSelectionMode. Otherwise false.
Since:
3.3.0

scrollUpPage

public void scrollUpPage()
Scrolls up by one page.


scrollDownPage

public void scrollDownPage()
Scrolls down by one page.


getMarginArea

public MarginArea getMarginArea()

setMarginArea

public void setMarginArea(MarginArea marginArea)

setLineNumberVisible

public void setLineNumberVisible(boolean visible)

isLineNumberVisible

public boolean isLineNumberVisible()

getLineNumberMargin

public RowNumberMargin getLineNumberMargin()

getCaretModel

public CaretModel getCaretModel()

getSelectionModel

public SelectionModel getSelectionModel()

selectionChanged

public void selectionChanged(SelectionEvent e)
Description copied from interface: SelectionListener
Called when selection changed.

Specified by:
selectionChanged in interface SelectionListener

createClipboardOwner

protected ClipboardOwner createClipboardOwner()
Create ClipboardOwner instance.

Returns:
the ClipboardOwner instance.

caretUpdated

public void caretUpdated(CaretEvent e)
Description copied from interface: CaretListener
This method will be called whenever caret position changes.

Specified by:
caretUpdated in interface CaretListener
Parameters:
e - the CaretEvent.

createSelectionModel

protected SelectionModel createSelectionModel()
Create selection model for CodeEditor. The default implementation is new DefaultSelectionModel(this). You can override this method to create your selection model.

Returns:
a DefaultSelectionModel instance.

viewToModelPosition

public CaretPosition viewToModelPosition(CaretPosition p)
Get model position from view position.

If there is no folding span those two positions should be the same.

If there are folding spans, find the closest folded span to get the relative position.

If it's on the folded descriptions, use the model position of the first offset of the folded span.

Parameters:
p - the view position.
Returns:
the model position.

modelToViewPosition

public CaretPosition modelToViewPosition(CaretPosition p)
Get view position from model position.

If there is no folding span those two positions should be the same.

If there are folding spans, find the closest folded span to get the relative position.

If it's inside a folded span, use the view position of the first offset of the folded span.

Parameters:
p - the model position.
Returns:
the view position.

offsetToModelPosition

public CaretPosition offsetToModelPosition(int offset)

offsetToViewPosition

public CaretPosition offsetToViewPosition(int offset)

modelPositionToOffset

public int modelPositionToOffset(CaretPosition p)

offsetToLine

@Deprecated
public int offsetToLine(int offset)
Deprecated. replaced by offsetToViewPosition(int)

Converts the offset as in the Document to the view line in the editor.

The return value is changed to mean view line instead of model line since 2.10.2. If you ever invoked this method before and intended to get model line. Please use getLineNumber(int) instead.

Parameters:
offset - the offset in the document
Returns:
the view line number contains the character at that offset.

getTabSize

public int getTabSize()

setTabSize

public void setTabSize(int tabSize)

isReplaceTabWithSpace

public boolean isReplaceTabWithSpace()

setReplaceTabWithSpace

public void setReplaceTabWithSpace(boolean replaceTabWithSpace)

getDefaultLineBreakStyle

public int getDefaultLineBreakStyle()
Gets the default line break style. If you are on Windows or MacOSX, LINE_BREAK_PC will be returned. If you are on Mac classic, LINE_BREAK_MAC will be returned. if you are on UNIX, LINE_BREAK_UNIX will be returned. Otherwise, we will return LINE_BREAK_PC as the default one.

Returns:
the default line break depending on the platform.

getLineBreakStyle

public int getLineBreakStyle()

isLineBreakStyleMixed

public boolean isLineBreakStyleMixed()

setLineBreakStyle

public void setLineBreakStyle(int lineBreakStyle)

discardAllEdits

public void discardAllEdits()

promptGotoLine

public void promptGotoLine()
Shows a dialog so that the customer could input a line number then jump to the line.


promptGotoLineAtView

public void promptGotoLineAtView()

promptGotoOffset

public void promptGotoOffset()

gotoLine

public void gotoLine(int line)
Go to the model line.

Parameters:
line - the model line index

gotoLineAtView

public void gotoLineAtView(int line)
Go to the view line.

Parameters:
line - the view line index

gotoOffset

public void gotoOffset(int offset)
Go to the offset.

Parameters:
offset - the offset in the document

getMarkerModel

public MarkerModel getMarkerModel()

setMarkerModel

public void setMarkerModel(MarkerModel markerModel)

getMaxNumberOfClipboards

public int getMaxNumberOfClipboards()

setMaxNumberOfClipboards

public void setMaxNumberOfClipboards(int maxNumberOfClipboards)

setDragEnabled

public void setDragEnabled(boolean b)
Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component. The transferHandler property needs to be set to a non-null value for the drag to do anything. The default value of the dragEnabledfalse.

When automatic drag handling is enabled, most look and feels begin a drag-and-drop operation whenever the user presses the mouse button over a selection and then moves the mouse a few pixels. Setting this property to true can therefore have a subtle effect on how selections behave.

Some look and feels might not support automatic drag and drop; they will ignore this property. You can work around such look and feels by modifying the component to directly call the exportAsDrag method of a TransferHandler.

Parameters:
b - the value to set the dragEnabled property to
Throws:
HeadlessException - if b is true and GraphicsEnvironment.isHeadless() returns true
See Also:
GraphicsEnvironment.isHeadless(), getDragEnabled(), JComponent.setTransferHandler(javax.swing.TransferHandler), TransferHandler

getDragEnabled

public boolean getDragEnabled()
Gets the value of the dragEnabled property.

Returns:
the value of the dragEnabled property
See Also:
setDragEnabled(boolean)

setFont

public void setFont(Font font)
Overrides:
setFont in class JComponent

getSearchable

public Searchable getSearchable()

getFindAndReplace

public FindAndReplace getFindAndReplace()

getCaretLocation

public Point getCaretLocation()

getCaretLocationOnScreen

public Point getCaretLocationOnScreen()

showMessage

public void showMessage(String message)

find

public void find()
Shows a find dialog to let the customer input searching text then search the text in the document or the current selected text.


findNext

public void findNext()
Looks for the next match in the document or the current selected text.


findPrevious

public void findPrevious()
Looks for the previous match in the document or the current selected text.


replace

public void replace()
Shows a find and replace dialog to let the customer input searching text then search the text in the document or the current selected text.


quickSearch

public void quickSearch(String searchingText)
Shows a Searchable popup to start searching quickly.

Parameters:
searchingText - the searching text

moveToLineEnd

public void moveToLineEnd(boolean select)
Moves the caret to the end of the line where the caret resides. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not

moveToLineStart

public void moveToLineStart(boolean select)
Moves the caret to the start of the line where the caret resides. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not

moveToDocumentStart

public void moveToDocumentStart(boolean select)
Moves the caret to the start of the document. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not

moveToDocumentEnd

public void moveToDocumentEnd(boolean select)
Moves the caret to the end of the document. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not

moveToNextChar

public void moveToNextChar(boolean select)
Moves the caret to the next column if isVirtualSpaceAllowed() is true. Otherwise moves the caret to the next char excluding line breaks. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not
See Also:
isVirtualSpaceAllowed()

moveToNextLine

public void moveToNextLine(boolean select)
Moves the caret to the next line. The column may change if isVirtualSpaceAllowed() is false. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not
See Also:
isVirtualSpaceAllowed()

moveToNextPage

public void moveToNextPage(boolean select)
Moves the caret to the next page. The column may change if isVirtualSpaceAllowed() is false. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not
See Also:
isVirtualSpaceAllowed()

moveToNextWord

public void moveToNextWord(boolean select)
Moves caret to the the word start of the next word. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the text between current caret and new caret should be selected.

moveToNextWord

public void moveToNextWord(boolean select,
                           boolean toWordStart)
If toWordStart is false, moves caret to the the word end of the current word if the caret is not on the end of the current word or to the word end of the next word if the caret is on the end of the current word.

If toWordStart is true, moves caret to the the word start of the next word.

Parameters:
select - the flag indicating if the text between current caret and new caret should be selected
toWordStart - the flag indicating if the caret should be put at the start of the word

moveToPreviousChar

public void moveToPreviousChar(boolean select)
Moves the caret to the previous column or stay at column 0 if isVirtualSpaceAllowed() is true. Otherwise moves the caret to the previous char excluding line breaks. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not
See Also:
isVirtualSpaceAllowed()

moveToPreviousLine

public void moveToPreviousLine(boolean select)
Moves the caret to the previous line. The column may change if isVirtualSpaceAllowed() is false. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not
See Also:
isVirtualSpaceAllowed()

moveToPreviousPage

public void moveToPreviousPage(boolean select)
Moves the caret to the previous page. The column may change if isVirtualSpaceAllowed() is false. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the caret moving will extend selection or not
See Also:
isVirtualSpaceAllowed()

moveToPreviousWord

public void moveToPreviousWord(boolean select)
Moves caret to the the word start of the current word if the caret is not on the start of the current word or to the word start of the previous word if the caret is on the start of the current word. Extends the selection if the select parameter is true.

Parameters:
select - the flag indicating if the text between current caret and new caret should be selected.

moveToPreviousWord

public void moveToPreviousWord(boolean select,
                               boolean toWordEnd)
If toWordEnd is false, moves caret to the the word start of the current word if the caret is not on the start of the current word or to the word start of the previous word if the caret is on the start of the current word.

If toWordEnd is true, moves caret to the the word end of the previous word.

Parameters:
select - the flag indicating if the text between current caret and new caret should be selected.
toWordEnd - the flag indicating if the caret should be put at the end of the word

adjustColumnSelectionModelOnCaretMoving

protected void adjustColumnSelectionModelOnCaretMoving(boolean select)
Adjusts the column seletion model to false when the caret is moving without selection.

Parameters:
select - if this caret moving causes a new selection
Since:
3.4.2

toggleOverwrite

public void toggleOverwrite()
Toggles the editing mode between overwrite and insert. The caret will change accordingly.


splitLine

public void splitLine()
Deletes current selected text if any then inserts a line break. It will also add empty spaces following the white spaces in the previous line. The caret will stay in the end of the current line.


insertBreak

public void insertBreak()
Deletes current selected text if any then inserts a line break. It will also add empty spaces following the white spaces in the previous line. The caret will be put in the first non-space character or the end of the new line.


startNewLine

public void startNewLine()
Inserts a line break after the end of the line where the caret is. It will also add empty spaces following the white spaces in the previous line. Just clears selection and leaves the selected text no touch if there is any selection. The caret will be put in the first non-space character or the end of the new line.


indentSelection

public void indentSelection()
Indents all selected lines no matter if the selection is a line selection or not if there is a selection. If there is no selection, a tab or several white spaces will be inserted at the caret position.

See Also:
isReplaceTabWithSpace(), getTabSize()

unindentSelection

public void unindentSelection()
Indents all selected lines no matter if the selection is a line selection or not if there is a selection. If there is no selection, the line where the caret resides will be unindented.


indentLine

public boolean indentLine(int lineIndex,
                          boolean decrease)

getCurrentIndentForLine

public int getCurrentIndentForLine(int lineIndex,
                                   int[] whitespaceChars)
Returns the line's current leading indent.

Parameters:
lineIndex - The line number
whitespaceChars - If this is non-null, the number of whitespace characters is stored at the 0 index
Returns:
the current indent.

insertChar

public void insertChar(String str)
Inserts the string into the document. Deletes the selected text first if there is a selection.

Parameters:
str - the string to insert

joinLines

public void joinLines()
Joins all selected lines by deleting line breaks and the empty spaces leading the lines. If there is no selection, the line where the caret resides and the next line will be joined. The current selection should be kept and the caret will be moved to where the last join happens.


toggleCase

public void toggleCase()
Toggles the case when typing an alphabetic char.


duplicateSelection

public void duplicateSelection()
Inserts the selected text to the start of the current selection. Keeps the current selection and the current caret position. If there is no selection, the current line will be duplicated.


backspaceChar

public void backspaceChar()
Deletes a char before the caret if there is no selection. If there is a selection, delete all selected texts.


backspaceWord

public void backspaceWord()
Deletes from current caret to the start of the word if the caret is not at the start of the word or to the start of the previous word if the caret is currently at the start of the word.


deleteChar

public void deleteChar()
Deletes a char at the caret if there is no selection. If there is a selection, delete all selected texts.


deleteWord

public void deleteWord()
Deletes from current caret to the start of the next word.


deleteLine

public void deleteLine()
Deletes the entire line including line break associated with the line.


clipboardCut

public void clipboardCut()
Deletes the selected text from the text area and places it into the clipboard. If there is no selection, the current line where the caret resides will be selected and deleted and placed into the clipboard.


clipboardMove

public void clipboardMove(int offset)
Moves the selected text to the offset.

Parameters:
offset - the offset

clipboardCopy

public void clipboardCopy()
Places the selected text into the clipboard. If there is no selection, selects the current line then places the selected line into the clipboard.


clipboardPaste

public void clipboardPaste()
Inserts the clipboard contents into the document. Deletes current selected text first if there is any.


pasteWithDialog

public void pasteWithDialog()
Shows a dialog so that the customer could choose text from the clipboard contents to paste.


lineComments

public void lineComments()
Comments all selected lines using line comments no matter if the selection is a line selection or not if there is a selection. If there is no selection, the line where the caret resides will be commented.

It works only if you use LanguageSpec's configureCodeEditor to configure a CodeEditor. Otherwise it doesn't know what line comment string to use.


blockComments

public void blockComments()
Comments the selected text using block comments. It works only if you use LanguageSpec's configureCodeEditor to configure a CodeEditor. Otherwise it doesn't know what block comment string to use.


getFoldingModel

public FoldingModel getFoldingModel()

setFoldingModel

public void setFoldingModel(FoldingModel foldingModel)

expandFolding

public void expandFolding()
Expands the folded span if any.


collapseFolding

public void collapseFolding()
Collapses the expanded span if any.


expandAll

public void expandAll()
Expands all folded spans.


collapseAll

public void collapseAll()
Collapses all expanded spans.


toggleFoldingSelection

public void toggleFoldingSelection()
If there is no folding and has selection, the selected text will be folded and shown as "...". If the entire folded texts are selected, the folding will be removed. If there is no folding and no selection, do nothing.


modelToViewLine

public int modelToViewLine(int line)

viewToModelLine

public int viewToModelLine(int line)

repaint

public void repaint()
Overrides:
repaint in class Component

repaint

public void repaint(long tm)
Overrides:
repaint in class Component

getContentSize

public Dimension getContentSize()

recalculateContentSize

protected Dimension recalculateContentSize()

resetContentSize

protected void resetContentSize()

configureStyledLabel

public void configureStyledLabel(StyledLabel styledLabel,
                                 Object userObject)
Description copied from interface: FindResultIntepreter
Configure the styled label to display the find result.

Specified by:
configureStyledLabel in interface FindResultIntepreter

getResourceString

public String getResourceString(String key)
Gets the resource string used by CodeEditor.

Parameters:
key - the resource key
Returns:
the localized resource string.

modelToView

public Rectangle modelToView(int offset)
                      throws BadLocationException
Throws:
BadLocationException

modelToView

public Rectangle modelToView(int startOffset,
                             int endOffset)
                      throws BadLocationException,
                             IllegalArgumentException
Parameters:
startOffset - the start offset
endOffset - the end offset
Returns:
the view rectangle from the start offset to the end offset.
Throws:
BadLocationException - if the startOffset or endOffset is out of the boundary of the document.
IllegalArgumentException - if the startOffset and endOffset is not in the same visible line.

getHighlighter

public Highlighter getHighlighter()
Fetches the object responsible for making highlights.

Returns:
the highlighter

setHighlighter

public void setHighlighter(Highlighter h)
Sets the highlighter to be used. By default this will be set by the UI that gets installed. This can be changed to a custom highlighter if desired. The highlighter can be set to null to disable it. A PropertyChange event ("highlighter") is fired when a new highlighter is installed.

Parameters:
h - the highlighter
See Also:
getHighlighter()

getFixedHighlighter

public Highlighter getFixedHighlighter()
Fetches the object responsible for making fixed highlights that can only be changed through code.

Returns:
the highlighter

setFixedHighlighter

public void setFixedHighlighter(Highlighter h)
Sets the fixed highlighter to be used. Different from regular highlighter which can be set using setHighlighter method, the fixed highlighter can only be changed by code. So while the regular highlighter can be cleared when the users press escape key, the fixed highlighter will stay.

Parameters:
h - the highlighter
See Also:
getHighlighter()

createHighlighter

protected Highlighter createHighlighter()
Creates the object to use for adding highlights. By default an instance of DefaultUIResourceHighlighter is created. This method can be redefined to provide something else that implements the Highlighter interface or a subclass of DefaultHighlighter.

Returns:
the highlighter

getColumnGuides

public ColumnGuide[] getColumnGuides()
Gets all the column guides. Please note, the actual instances of the column guides used by code editor will be in the returned array. You can call setter to change the column guides. However it will not take affect until the code editor is repainted.

Returns:
the column guides.

internalGetColumnGuides

protected List<ColumnGuide> internalGetColumnGuides()
Gets all the column guides.

Returns:
all the column guides.

addColumnGuide

public void addColumnGuide(ColumnGuide guide)
Adds a column guide and repaint the code editor.

Parameters:
guide - the column guide

removeColumnGuide

public void removeColumnGuide(ColumnGuide guide)
Removes a column guide and repaint the code editor.

Parameters:
guide - the column guide

removeAllColumnGuides

public void removeAllColumnGuides()
Removes all column guides that were added before and repaint the code editor.


escape

public void escape()
Clears the selection if any. If there is no selection, clears any highlights. If there is no selection and highlights, does nothing.


loadActionMap

public void loadActionMap()
Loads the default actions to the ActionMap so that other tools can look up the action map to find out the actions. The actions we loaded are "copy", "cut", "paste", "delete", "undo", "redo", and "selectAll".


setCaretPosition

public void setCaretPosition(int offset)

getCaretPosition

public int getCaretPosition()

getVerticalScrollBar

public JScrollBar getVerticalScrollBar()
Gets the vertical scroll bar used by CodeEditor.

Returns:
the vertical scroll bar.

getHorizontalScrollBar

public JScrollBar getHorizontalScrollBar()
Gets the horizontal scroll bar used by CodeEditor.

Returns:
the horizontal scroll bar.

getCorrespondingColumn

public int getCorrespondingColumn(int column,
                                  int oldLine,
                                  int newLine)
Get corresponding column in the new line which visually in the same column of the column in the old line.

Parameters:
column - the column in the old line
oldLine - the old line
newLine - the new line
Returns:
the column in the new line.

getInputMethodRequests

public InputMethodRequests getInputMethodRequests()
Overrides:
getInputMethodRequests in class Component

setOverlayVisible

public void setOverlayVisible(boolean visible)

createOverlay

public JComponent createOverlay()

repaint

public void repaint(long tm,
                    int x,
                    int y,
                    int width,
                    int height)
Overrides:
repaint in class JComponent

customizeDialog

protected void customizeDialog(StandardDialog dialog)
Customizes the dialog to be visible. Those dialog include ClipboardsDialog and FindAndReplaceDialog.

You could try to customize its location or size before it is visible.

Parameters:
dialog - the dialog to be customized.

customizeDialogData

protected void customizeDialogData(StandardDialog dialog)
Customizes the dialog to be pack. Those dialog include ClipboardsDialog and FindAndReplaceDialog.

You could try to customize its data model before the panel inside it is actually created.

Parameters:
dialog - the dialog to be customized.
Since:
3.5.9

clearClipboards

public static void clearClipboards()
Clears clipboards memory.


isAdjustColumnSelectionOnMouseEvent

public boolean isAdjustColumnSelectionOnMouseEvent()
Gets the flag indicating if the column selection mode should be automatically adjusted on mouse dragging.

Returns:
true if the mode should be adjusted. Otherwise false.
See Also:
setAdjustColumnSelectionOnMouseEvent(boolean)

setAdjustColumnSelectionOnMouseEvent

public void setAdjustColumnSelectionOnMouseEvent(boolean adjustColumnSelectionOnMouseEvent)
Sets the flag indicating if the column selection mode should be automatically adjusted on mouse dragging.

By default, the flag is true. You could disable this flag to let your explicit setting always takes effective.

Parameters:
adjustColumnSelectionOnMouseEvent - the flag

dispose

public void dispose()
Disposes the CodeEditor.

If you have one document for multiple CodeEditor instances, you will need invoke this method to release the memory when you want to remove a CodeEditor while keeping other CodeEditors in working.

By default, it will invoke getMarkerArea().dispose() and setDocument(null) to release the memory.

Since:
3.4.6

JIDE 3.5.15