com.borland.primetime.editor
Class EditorPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.text.JTextComponent
                          |
                          +--javax.swing.JEditorPane
                                |
                                +--com.borland.primetime.editor.EditorPane
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, javax.swing.Scrollable, java.io.Serializable

public class EditorPane
extends javax.swing.JEditorPane
implements java.awt.event.FocusListener, java.beans.PropertyChangeListener

This is the editor component for the PrimeTime framework. The EditorPane is the focused component when the user is typing into the editor, thus it is responsible for sending keys to the current keymap. In addition, the EditorPane also does some undo management, as well as providing a facility for emphasizing particular lines through a highlight mark and temporary mark facility.

The EditorPane uses an EditorDocument class as the model, and an EditorView class as the view (to do the actual rendering of the text).

Through this component, other systems can call the editor APIs to manipulate the text contained in this component.

See Also:
EditorPane, EditorDocument, Serialized Form

Inner Class Summary
static class EditorPane.HighlightMark
          This is the highlight mark, placed on a line within the editor (through the document) to emphasize that line.
 
Inner classes inherited from class javax.swing.JEditorPane
javax.swing.JEditorPane.AccessibleJEditorPane, javax.swing.JEditorPane.AccessibleJEditorPaneHTML, javax.swing.JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Inner classes inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static int CENTER_ALWAYS
          Used in gotoLine and gotoOffset.
static int CENTER_IF_NEAR_EDGE
          Used in gotoLine and gotoOffset.
static int CENTER_IF_OFFSCREEN
          Used in gotoLine and gotoOffset.
static int CENTER_NEVER
          Deprecated. Use ONSCREEN instead.
protected  java.lang.ref.WeakReference editorRef
          A weak reference is needed in LineMark objects for instance.
protected  int fontHeight
           
protected  java.awt.FontMetrics fontMetrics
           
protected  int fontWidth
           
protected  EditorPane.HighlightMark highlightMark
          The highlight mark usually used for the temporary mark.
 ModalKeymap.ModeStateInfo keymapStateInfo
          This member records information specific to a particular keymap, including state info.
protected  javax.swing.Action lastAction
          This member records the last Action object executed on this editor instance.
static int LINE_PADDING
           
static int NOT_OUT_OF_BOUNDS
          Used in gotoLine and gotoOffset.
static int ONETHIRD_ALWAYS
          Used in gotoLine and gotoOffset.
static int ONETHIRD_IF_NEAR_EDGE
          Used in gotoLine and gotoOffset.
static int ONETHIRD_IF_OFFSCREEN
          Used in gotoLine and gotoOffset.
static int ONSCREEN
          Used in gotoLine and gotoOffset.
protected  boolean popupEnabled
          The flag that remembers if there is a current popup in the editor.
 boolean processedKeyPressed
          Flag to indicate if the KeyPressed event has been processed after a key is entered.
protected  LineMark temporaryMark
          The temporary mark used to highlight lines when entries in the structure pane are choosen.
protected static ToolTipProvider toolTipProvider
          The editor will delegate to this object when it is asked for ToolTipText
static int TWOTHIRD_ALWAYS
          Used in gotoLine and gotoOffset.
static int TWOTHIRD_IF_NEAR_EDGE
          Used in gotoLine and gotoOffset.
static int TWOTHIRD_IF_OFFSCREEN
          Used in gotoLine and gotoOffset.
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
EditorPane()
          Constructs a new EditorPane.
 
Method Summary
 int calcCaretPosition(int lineNumber, int column)
          Calculcate the caret position for a particular line and column of the the document.
 boolean canRedo()
          Check to see if we can redo in this editor.
 boolean canUndo()
          Check to see if we can undo in this editor.
 void clearHighlight()
          Clear the highlight.
 void clearTemporaryMark()
          Clear the temporary mark.
 void deleteNextChar()
          This method deletes the character immediately after the caret.
 void deletePrevChar()
          This method deletes the character immediately before the caret.
 void endUndoGroup()
          End the active undo group.
 void endUndoSegment()
          End the active undo segment.
 void focusGained(java.awt.event.FocusEvent e)
          Called when this editor gains focus.
 void focusLost(java.awt.event.FocusEvent e)
          Called when this editor loses focus.
 int getColumnNumber(int p0)
          Get the 1-based column number containing a particular position in the document.
 int getFontHeight()
          Return the height of the current font.
 java.awt.FontMetrics getFontMetrics()
          Return the FontMetrics of the current font.
 int getFontWidth()
          Return the width of the current font.
 ModalKeymap.ModeStateInfo getKeymapStateInfo()
          Get the state info object associated with this editor instance.
 javax.swing.Action getLastAction()
          Get the last action executed in this editor pane.
 int getLineCount()
          Get the number of lines in the document.
 int getLineNumber(int p0)
          Get the 1-based line number containing a particular position in the document.
 java.awt.Dimension getPreferredSize()
          Gets the preferred size of this component.
 java.lang.ref.WeakReference getReference()
          For other objects that want a weak reference link to the editor pane.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Override this method so that vertical block scrolling will scroll one page at a time (determined by fontHeight), and that horizontal scrolling will scroll by the visible horizontal width.
 boolean getScrollableTracksViewportWidth()
          Return false here to allow horizontal scrolling.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Override this method so that vertical unit scrolling will scroll one line at a time (determined by fontHeight), and that horizontal scrolling will scroll by 10% of the visible horizontal width.
 java.lang.String getTextLine(int lineNumber)
          Get the text contained in a particular line in the document.
 java.lang.String getToolTipText(java.awt.event.MouseEvent e)
          Get the text which should be displayed in a tooltip.
 int getTopLine()
          Get the number of the line at the top of the editor viewport.
 void gotoLine(int lineNumber)
          Go to a particular line in the document.
 void gotoLine(int lineNumber, boolean highlight)
          Go to a particular line in the document.
 void gotoLine(int lineNumber, boolean highlight, int centerPolicy)
          Go to a particular line in the document.
 void gotoOffset(int p0)
          Go to a particular offset within the document.
 void gotoOffset(int p0, boolean highlight)
          Go to a particular offset within the document.
 void gotoOffset(int p0, boolean highlight, int centerPolicy)
          Go to a particular offset within the document.
 void gotoOffset(int p0, boolean highlight, int centerPolicy, int topHiddenLine, int bottomHiddenLine)
          Specialized version of gotoOffset(...) which will try to avoid a certain region on the screen as defined by the topHiddenLine and bottomHiddenLine parameters.
 void gotoPosition(int line, int column)
          Go to a particular line and column position within the document.
 void gotoPosition(int line, int column, boolean highlight)
          Go to a particular line and column position within the document.
 void gotoPosition(int line, int column, boolean highlight, int centerPolicy)
          Go to a particular line and column position within the document.
 void insertAt(int lineNumber, int column, java.lang.String text)
          This is a convenience method to insert text at a particular position in the document.
 void insertAt(int p0, java.lang.String text)
          This is a convenience method to insert text at a particular position in the document.
 void insertChar(java.lang.String content)
          This method inserts the text in content (usually a single character) immediately after the caret.
 boolean isPopupEnabled()
          See if we can bring up a popup window in the editor's current state.
 void overwriteChar(java.lang.String content)
          This method deletes the character immediately after the caret, replacing it with the text in content (usually a single character).
 void paste()
          Transfers the contents of the system clipboard into the associated text model.
protected  void positionCaret(int point, int mark)
          Position the caret point and mark.
 void propertyChange(java.beans.PropertyChangeEvent e)
          This function is called by the EditorManager when a property has changed.
 void redo()
          Cause a redo in this editor.
 void redo(boolean checkPosition)
          Cause a redo in this editor.
static void registerToolTipProvider(ToolTipProvider provider)
          Register a tooltip provider for all editors to use.
 void release()
           
 void repaintLine(int lineNumber)
          Repaints a particular line of the document.
 void replaceSelection(java.lang.String content)
          This method replaces the current selection with the text in content.
 void selectCharacters(int numChars)
          This is a convenience method used to select a number of characters from the current caret offset.
 void setCaret(javax.swing.text.Caret c)
          Set a new Caret for this EditorPane.
 void setCaretPosition(int lineNumber, int column)
          Set the caret to a particular line and column within the document.
 void setFont(java.awt.Font f)
          Sets the font of this component.
 void setHighlight(int lineNumber)
          Set the highlight to a particular line number.
 void setLastAction(javax.swing.Action action)
          Set the last action executed in this editor pane.
 void setPopupEnabled(boolean enabled)
          Set the editor to enable or disable popup windows.
 void setTemporaryMark(int lineNumber, LineMark mark)
          Set a temporary mark on a particular line number.
 void setTopLine(int lineNumber)
          Set the indicated line number to be the first line visible in the in the editor viewport.
 void startUndoGroup()
          Start an undo group.
 void startUndoSegment(int type)
          Start an undo segment.
 void undo()
          Cause an undo in this editor.
 void undo(boolean checkPosition)
          Cause an undo in this editor.
 void updateColors()
          Update the colors using the default style context supplied by the editor manager.
 void updateColors(javax.swing.text.StyleContext context)
          Update the colors using the supplied style context.
 void updateUI()
          This method is overridden to reset the keymap and colors after the UI is changed.
 
Methods inherited from class javax.swing.JEditorPane
addHyperlinkListener, createDefaultEditorKit, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getPage, getScrollableTracksViewportHeight, getStream, getText, getUIClassID, isFocusCycleRoot, isManagingFocus, paramString, processComponentKeyEvent, processKeyEvent, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKit, setEditorKitForContentType, setPage, setPage, setText
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretPosition, getDisabledTextColor, getDocument, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getPreferredScrollableViewportSize, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getUI, isEditable, isFocusTraversable, loadKeymap, modelToView, moveCaretPosition, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, select, selectAll, setCaretColor, setCaretPosition, setDisabledTextColor, setDocument, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isLightweightComponent, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processFocusEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

toolTipProvider

protected static ToolTipProvider toolTipProvider
The editor will delegate to this object when it is asked for ToolTipText

highlightMark

protected EditorPane.HighlightMark highlightMark
The highlight mark usually used for the temporary mark.

temporaryMark

protected LineMark temporaryMark
The temporary mark used to highlight lines when entries in the structure pane are choosen.

processedKeyPressed

public boolean processedKeyPressed
Flag to indicate if the KeyPressed event has been processed after a key is entered.

popupEnabled

protected boolean popupEnabled
The flag that remembers if there is a current popup in the editor. If this flag is true, it is safe to bring up a popup.

fontMetrics

protected java.awt.FontMetrics fontMetrics

fontWidth

protected int fontWidth

fontHeight

protected int fontHeight

keymapStateInfo

public ModalKeymap.ModeStateInfo keymapStateInfo
This member records information specific to a particular keymap, including state info.
See Also:
ModalKeymap

lastAction

protected javax.swing.Action lastAction
This member records the last Action object executed on this editor instance.

editorRef

protected java.lang.ref.WeakReference editorRef
A weak reference is needed in LineMark objects for instance.

CENTER_ALWAYS

public static final int CENTER_ALWAYS
Used in gotoLine and gotoOffset. Will position the relevant line at the center of the screen.

CENTER_IF_NEAR_EDGE

public static final int CENTER_IF_NEAR_EDGE
Used in gotoLine and gotoOffset. Will position the relevant line at the center of the screen if that line would otherwise be close to the top or the bottom of the screen.

CENTER_IF_OFFSCREEN

public static final int CENTER_IF_OFFSCREEN
Used in gotoLine and gotoOffset. Will position the relevant line at the center of the screen if that line would otherwise be off the screen.

CENTER_NEVER

public static final int CENTER_NEVER
Deprecated. Use ONSCREEN instead.

Used in gotoLine and gotoOffset. Will position the relevant line on the screen if that line would otherwise be off the screen. if the line would be above the current screen, the line is moved to the top of the screen. if the line would be below the current screen, the line is moved to the bottom of the screen.

ONSCREEN

public static final int ONSCREEN
Used in gotoLine and gotoOffset. Will position the relevant line on the screen if that line would otherwise be off the screen. if the line would be above the current screen, the line is moved to the top of the screen. if the line would be below the current screen, the line is moved to the bottom of the screen.

ONETHIRD_ALWAYS

public static final int ONETHIRD_ALWAYS
Used in gotoLine and gotoOffset. Will position the relevant line one third of a screen from the top.

ONETHIRD_IF_NEAR_EDGE

public static final int ONETHIRD_IF_NEAR_EDGE
Used in gotoLine and gotoOffset. Will position the relevant line one third of a screen from the top if that line would otherwise be close to the top or the bottom of the screen.

ONETHIRD_IF_OFFSCREEN

public static final int ONETHIRD_IF_OFFSCREEN
Used in gotoLine and gotoOffset. Will position the relevant line one third of a screen from the top, if that line would otherwise be off the screen.

TWOTHIRD_ALWAYS

public static final int TWOTHIRD_ALWAYS
Used in gotoLine and gotoOffset. Will position the relevant line two third of a screen from the top.

TWOTHIRD_IF_NEAR_EDGE

public static final int TWOTHIRD_IF_NEAR_EDGE
Used in gotoLine and gotoOffset. Will position the relevant line two third of a screen from the top if that line would otherwise be close to the top or the bottom of the screen.

TWOTHIRD_IF_OFFSCREEN

public static final int TWOTHIRD_IF_OFFSCREEN
Used in gotoLine and gotoOffset. Will position the relevant line two third of a screen from the top, if that line would otherwise be off the screen.

NOT_OUT_OF_BOUNDS

public static final int NOT_OUT_OF_BOUNDS
Used in gotoLine and gotoOffset. Will position the relevant line on the screen taking into account that a range of lines is out of bounds. if the line is on the screen and not in the out of bounds region, only the highlight is moved if necessary. if the line is either not on the screen, or in the out of bounds region, the line is displayed in the larger of the two region that are above and below the out of bounds region. if the line is displayed in the top region, it is displayed PADDING lines from the top. if the line is displayed in the bottom region, it is displayed PADDING lines from the out of bounds region.
See Also:
gotoOffset

LINE_PADDING

public static int LINE_PADDING
Constructor Detail

EditorPane

public EditorPane()
Constructs a new EditorPane. Among other things, this is the time that the appropriate state info object is created.
Method Detail

setLastAction

public void setLastAction(javax.swing.Action action)
Set the last action executed in this editor pane. This is mostly used internally by the keymaps.
Parameters:
action - the last action executed.

getLastAction

public javax.swing.Action getLastAction()
Get the last action executed in this editor pane.
Returns:
the last executed action.

release

public void release()

updateUI

public void updateUI()
This method is overridden to reset the keymap and colors after the UI is changed.
Overrides:
updateUI in class javax.swing.text.JTextComponent
See Also:
JComponent.updateUI()

updateColors

public void updateColors()
Update the colors using the default style context supplied by the editor manager.

updateColors

public void updateColors(javax.swing.text.StyleContext context)
Update the colors using the supplied style context.
Parameters:
context - the new style context used for colors.

setCaret

public void setCaret(javax.swing.text.Caret c)
Set a new Caret for this EditorPane. if a caret is already installed for this editor, we'll preserve the selection points so we can restore them in the new caret.
Overrides:
setCaret in class javax.swing.text.JTextComponent
Parameters:
c - the new Caret to set.

setFont

public void setFont(java.awt.Font f)
Sets the font of this component. We override this so that we can track specific things about the current font.
Overrides:
setFont in class javax.swing.JComponent
Parameters:
f - The font to become this component's font.
See Also:
Component.getFont()

getFontHeight

public int getFontHeight()
Return the height of the current font.
Returns:
the height of the current font.

getFontWidth

public int getFontWidth()
Return the width of the current font. This actually returns the width of the space character, ' ', because this is assumed to be a fixed pitch font (where each character is the same width).
Returns:
the width of the current font.

getFontMetrics

public java.awt.FontMetrics getFontMetrics()
Return the FontMetrics of the current font.
Returns:
the font metrics of the current font.

getKeymapStateInfo

public ModalKeymap.ModeStateInfo getKeymapStateInfo()
Get the state info object associated with this editor instance.
Returns:
the current state info object.
See Also:
ModalKeymap#ModeStateInfo

isPopupEnabled

public boolean isPopupEnabled()
See if we can bring up a popup window in the editor's current state.
Returns:
if true, it is safe to bring up a popup window.

setPopupEnabled

public void setPopupEnabled(boolean enabled)
Set the editor to enable or disable popup windows. Note that this is simply a marker flag that should be used by codeInsight and other such windows. When a system is going to bring up a popup window, that system should set this flag to false, so that *other* systems do not bring up popup windows, and so that the system in question doesn't bring itself up twice (unless the programmer really knows what he's doing).

It is also very important that any system which uses this flag resets it to the correct value when the system is finished, so that other systems can come up.

Parameters:
enabled - Set to false if nobody else should bring up a popup window, otherwise set to true.

startUndoGroup

public void startUndoGroup()
Start an undo group. Subsequent edits are automatically added to the active undo group until endUndoGroup is called. This method passes the state of the caret to the UndoManager so that it can be restored if this undo group is undone.
See Also:
endUndoGroup()

endUndoGroup

public void endUndoGroup()
End the active undo group. This method passes the state of the caret to the UndoManager so that it can be restored if this undo group is redone.
See Also:
startUndoGroup()

startUndoSegment

public void startUndoSegment(int type)
Start an undo segment. Subsequent edits of the same type are automatically added to the active undo segment until endUndoSegment is called. This method passes the state of the caret to the UndoManager so that it can be restored if this undo group is undone.
Parameters:
type - The type of modification this undoSegment will contain. Valid types are:
  • JBUndoManager.INSERT
  • JBUndoManager.OVERWRITE
  • JBUndoManager.REMOVE
See Also:
endUndoSegment()

endUndoSegment

public void endUndoSegment()
End the active undo segment. This method passes the state of the caret to the UndoManager so that it can be restored if this undo group is redone.
See Also:
startUndoSegment(int)

canUndo

public boolean canUndo()
Check to see if we can undo in this editor.
Returns:
true if undo's are possible, false otherwise.
See Also:
undo(), JBUndoManager

canRedo

public boolean canRedo()
Check to see if we can redo in this editor.
Returns:
true if redo's are possible, false otherwise.
See Also:
undo(), JBUndoManager

undo

public void undo()
Cause an undo in this editor.

This method checks the caret positioning after the appropriate edit in the UndoManager. If the caret is not currently in that position, it is moved to that position. If it is already in that position, then the appropriate edit is undone.

See Also:
redo(), JBUndoManager

undo

public void undo(boolean checkPosition)
Cause an undo in this editor.

Parameters:
checkPosition - If true, this method checks the caret positioning after the appropriate edit in the UndoManager. if the caret is not currently in that position, it is moved to that position. if it is already in that position, then the appropriate edit is undone.
See Also:
redo(), JBUndoManager

redo

public void redo()
Cause a redo in this editor.

This method checks the caret positioning before the appropriate edit in the UndoManager. if the caret is not currently in that position, it is moved to that position. if it is already in that position, then the appropriate edit is redone.

See Also:
undo(), JBUndoManager

redo

public void redo(boolean checkPosition)
Cause a redo in this editor.

Parameters:
checkPosition - if true, this method checks the caret positioning after the appropriate edit in the UndoManager. if the caret is not currently in that position, it is moved to that position. if it is already in that position, then the appropriate edit is redone.
See Also:
redo(), JBUndoManager

positionCaret

protected void positionCaret(int point,
                             int mark)
Position the caret point and mark.
Parameters:
point - The offset at which to position the caret dot. if this value is -1, the caret is not moved.
mark - The offset at which to position the caret mark. if this value is -1, no mark is placed.

insertChar

public void insertChar(java.lang.String content)
                throws javax.swing.text.BadLocationException
This method inserts the text in content (usually a single character) immediately after the caret. After this operation, the caret is located after the newly inserted text.
Parameters:
content - A string consisting of the new content to insert. Null or an empty string here removes the character after the caret.

deleteNextChar

public void deleteNextChar()
                    throws javax.swing.text.BadLocationException
This method deletes the character immediately after the caret.

deletePrevChar

public void deletePrevChar()
                    throws javax.swing.text.BadLocationException
This method deletes the character immediately before the caret.

overwriteChar

public void overwriteChar(java.lang.String content)
                   throws javax.swing.text.BadLocationException
This method deletes the character immediately after the caret, replacing it with the text in content (usually a single character). After this operation, the caret is located after the newly inserted text.
Parameters:
content - A string consisting of the new content to insert. Null or an empty string here removes the character after the caret.

replaceSelection

public void replaceSelection(java.lang.String content)
This method replaces the current selection with the text in content.

This method should only be used when doing a non-trivial change, or when being called from within an undo group. This is because this method creates an undo group so that the removal of the current selection, and the insertion of the new text are treated as a unit. Since an undo group is used, these operations cannot be coalesced.

if a "primitive" operation is being performed, use deleteNextChar, deletePrevChar, overwriteChar, or insertChar.

Overrides:
replaceSelection in class javax.swing.JEditorPane
Parameters:
content - A string consisting of the new content to insert. Null or an empty string here simply deletes the existing selection.
See Also:
deleteNextChar(), #deletePreChar, overwriteChar(java.lang.String), insertChar(java.lang.String)

paste

public void paste()
Transfers the contents of the system clipboard into the associated text model. if there is a selection in the associated view, it is replaced with the contents of the clipboard. if there is no selection, the clipboard contents are inserted in front of the current insert position in the associated view. if the clipboard is empty, does nothing.

The one additional thing this method does is ensures that the pasted text uses linefeed characters as line separators.

Overrides:
paste in class javax.swing.text.JTextComponent
See Also:
replaceSelection(java.lang.String)

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred size of this component. This is overridden so that we have a constant preferred width of 1028 characters, which eliminates the performance problems we see when we're trying to expand the width of the editor dynamically.
Overrides:
getPreferredSize in class javax.swing.JEditorPane
Returns:
A dimension object indicating this component's preferred size.
See Also:
Component.getPreferredSize()

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Override this method so that vertical unit scrolling will scroll one line at a time (determined by fontHeight), and that horizontal scrolling will scroll by 10% of the visible horizontal width.
Overrides:
getScrollableUnitIncrement in class javax.swing.text.JTextComponent
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "unit" increment for scrolling in the specified direction
See Also:
Scrollable.getScrollableUnitIncrement(java.awt.Rectangle, int, int)

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Override this method so that vertical block scrolling will scroll one page at a time (determined by fontHeight), and that horizontal scrolling will scroll by the visible horizontal width. The horizontal scrolling is written so that the the view always scrolls in whole multiples of one line height, so that lines do not appear to "crawl" up and down the screen as the user pages up and down.
Overrides:
getScrollableBlockIncrement in class javax.swing.text.JTextComponent
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "block" increment for scrolling in the specified direction.
See Also:
Scrollable.getScrollableBlockIncrement(java.awt.Rectangle, int, int)

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Return false here to allow horizontal scrolling.
Overrides:
getScrollableTracksViewportWidth in class javax.swing.JEditorPane
Returns:
True if a viewport should force the Scrollables width to match its own.
See Also:
Scrollable.getScrollableTracksViewportWidth()

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Called when this editor gains focus. Here we notify EditorAction that the focused editor has changed so that any EditorActions which are invoked will have the correct target.
Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
e - the event that triggered this call.

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Called when this editor loses focus. Here we do nothing because we may lose focus for a number of reasons. if the actual target for an EditorAction should change, it will be handled by either the new editor which gets focus, or by another component acting as a BrowserListener.
Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
e - the event that triggered this call

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
This function is called by the EditorManager when a property has changed. Any option that deals with the editor pane will be handled here.
Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
e - the event describing the property that changed.

setTemporaryMark

public void setTemporaryMark(int lineNumber,
                             LineMark mark)
Set a temporary mark on a particular line number. A temporary mark is "temporary" because it will go away as soon as the editor gets focus. It's primarily used to draw the users attention to a particular line in the editor when the editor is being driven from an external source.

There can only be one temporary mark per editor, so this method has the side effect of removing the previous temporary mark. This function also guarantees that the temporary mark is only visible in this editor instance by calling LineMark.setEditorReference(this), and when this linemark is removed later on, LineMark.setEditorReference(null) will be called to disassociate the linemark from the editor.

Parameters:
lineNumber - the 1-based line number where the temporary mark should be placed.
mark - The LineMark to use as the temporary mark.

setHighlight

public void setHighlight(int lineNumber)
Set the highlight to a particular line number. There can only be one highlighted line per document, so this method has the side effect of removing the previous highlighted line.
Parameters:
lineNumber - the 1-based line number that should be highlighted.

clearHighlight

public void clearHighlight()
Clear the highlight.

clearTemporaryMark

public void clearTemporaryMark()
Clear the temporary mark.

repaintLine

public void repaintLine(int lineNumber)
Repaints a particular line of the document.
Parameters:
lineNumber - the line number to repaint.

getLineCount

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

gotoOffset

public void gotoOffset(int p0,
                       boolean highlight,
                       int centerPolicy)
Go to a particular offset within the document.

NOTE: The gotoOffset(...) methods are generally used when driving the editor from an outside source. if you simply wish to position the caret within an EditorAction, you should probably use setCaretPosition().

Parameters:
p0 - The offset to go to.
highlight - True if the editor should highlight the line.
center - True if the editor should center on the line containing the offset. if false, the editor will simply ensure that the line is within the viewport.

gotoOffset

public void gotoOffset(int p0,
                       boolean highlight,
                       int centerPolicy,
                       int topHiddenLine,
                       int bottomHiddenLine)
Specialized version of gotoOffset(...) which will try to avoid a certain region on the screen as defined by the topHiddenLine and bottomHiddenLine parameters. NOTE: The gotoOffset(...) methods are generally used when driving the editor from an outside source. if you simply wish to position the caret within an EditorAction, you should probably use setCaretPosition().
Parameters:
p0 - The offset to go to.
highlight - True if the editor should highlight the line.
centerPolicy - True if the editor should center on the line containing the offset. if false, the editor will simply ensure that the line is within the viewport.
topHiddenLine - The top line of the area that should be avoided.
bottomHiddenLine - The bottom line of the area that should be avoided.

gotoOffset

public void gotoOffset(int p0,
                       boolean highlight)
Go to a particular offset within the document. This will put the line on which the offset occurs a little above the center of the screen.

NOTE: The gotoOffset(...) methods are generally used when driving the editor from an outside source. if you simply wish to position the caret within an EditorAction, you should probably use setCaretPosition().

Parameters:
p0 - The offset to go to.
highlight - True if the editor should highlight the line.

gotoOffset

public void gotoOffset(int p0)
Go to a particular offset within the document. This will put the line on which the offset occurs a little above the center of the screen.

NOTE: The gotoOffset(...) methods are generally used when driving the editor from an outside source. if you simply wish to position the caret within an EditorAction, you should probably use setCaretPosition().

Parameters:
p0 - The offset to go to.

gotoLine

public void gotoLine(int lineNumber,
                     boolean highlight,
                     int centerPolicy)
Go to a particular line in the document.
Parameters:
lineNumber - the 1-based line number to go to
highlight - True if the editor should highlight the line.
center - True if the editor should center on the line in question. If false, the editor will simply ensure that the line is within the viewport.

gotoLine

public void gotoLine(int lineNumber,
                     boolean highlight)
Go to a particular line in the document. This will put the line a little above the center of the screen.
Parameters:
lineNumber - the line number to go to
highlight - True if the editor should highlight the line.

gotoLine

public void gotoLine(int lineNumber)
Go to a particular line in the document. This will highlight the line and put it a little above the center of the screen.
Parameters:
lineNumber - the line number to go to

gotoPosition

public void gotoPosition(int line,
                         int column,
                         boolean highlight,
                         int centerPolicy)
Go to a particular line and column position within the document.
Parameters:
line - The 1-based line number to go to.
column - The 1-based column number to go to.
highlight - True if the editor should highlight the line.
center - True if the editor should center on the line containing the position in question. if false, the editor will simply ensure that the line is within the viewport.

gotoPosition

public void gotoPosition(int line,
                         int column,
                         boolean highlight)
Go to a particular line and column position within the document. This will put the line in which the position occurs a little above the center of the screen, and the line will be highlighted if wanted.
Parameters:
line - The 1-based line number to go to.
column - The 1-based column number to go to.
highlight - True if the editor should highlight the line.

gotoPosition

public void gotoPosition(int line,
                         int column)
Go to a particular line and column position within the document. This will put the line in which the position occurs a little above the center of the screen.
Parameters:
line - The 1-based line number to go to.
column - The 1-based column number to go to.

getLineNumber

public int getLineNumber(int p0)
Get the 1-based line number containing a particular position in the document.
Parameters:
p0 - the position for which to return the line number.
Returns:
the 1-based line number containing the position p0.

getColumnNumber

public int getColumnNumber(int p0)
Get the 1-based column number containing a particular position in the document.
Parameters:
p0 - the position for which to return the column number.
Returns:
the 1-based column number containing the position p0.

getTextLine

public java.lang.String getTextLine(int lineNumber)
Get the text contained in a particular line in the document.
Parameters:
lineNumber - the 1-based linenumber for which to retrieve the text.
Returns:
the text contained on the indicated line. if lineNumber is out of the range of the document, this method returns null.

insertAt

public void insertAt(int p0,
                     java.lang.String text)
This is a convenience method to insert text at a particular position in the document.
Parameters:
p0 - The position in which to insert the text.
text - The text to insert at position p0.

insertAt

public void insertAt(int lineNumber,
                     int column,
                     java.lang.String text)
This is a convenience method to insert text at a particular position in the document.
Parameters:
line - The line number on which to insert the text. This parameter is 1-based.
column - The column number on which to insert the text. This parameter is 1-based.
text - The text to insert.

setCaretPosition

public void setCaretPosition(int lineNumber,
                             int column)
Set the caret to a particular line and column within the document. if the line is past the last line in the document, the caret is placed on the last line. if the column is past the last column on the indicated line, the caret is placed in the last column.
Parameters:
line - The line number on which to position the caret. This parameter is 1-based.
column - The column number on which to position the caret. This parameter is 1-based.

calcCaretPosition

public int calcCaretPosition(int lineNumber,
                             int column)
Calculcate the caret position for a particular line and column of the the document.
Parameters:
line - The line number for which to calculate the position. This parameter is 1-based. if this is out of the document's range, it is treated as either the first or last line of the document.
column - The column number for which to calculate the position. This parameter is 1-based. if this is out of the line's range, it is treated as the first column of the line.
Returns:
the offset corresponding to the line and column passed.

selectCharacters

public void selectCharacters(int numChars)
This is a convenience method used to select a number of characters from the current caret offset. Any previous selection is unselected by this operation.
Parameters:
numChars - the number of characters to select from the current caret offset.

getTopLine

public int getTopLine()
Get the number of the line at the top of the editor viewport.
Returns:
Number of the line at the top of the editor viewport or 0 in case of failure.

setTopLine

public void setTopLine(int lineNumber)
Set the indicated line number to be the first line visible in the in the editor viewport.
Parameters:
lineNumber - the 1-based lineNumber to make the first visible line.

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
Get the text which should be displayed in a tooltip.
Overrides:
getToolTipText in class javax.swing.JComponent

registerToolTipProvider

public static void registerToolTipProvider(ToolTipProvider provider)
Register a tooltip provider for all editors to use.

getReference

public java.lang.ref.WeakReference getReference()
For other objects that want a weak reference link to the editor pane.
Returns:
A weakReference to this editor pane.