Extension SDK 10.1.2

oracle.javatools.editor
Class BasicEditorPane

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.text.JTextComponent
                  extended byjavax.swing.JEditorPane
                      extended byoracle.javatools.editor.BasicEditorPane
All Implemented Interfaces:
javax.accessibility.Accessible, ActionInvoker, java.awt.dnd.Autoscroll, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, javax.swing.Scrollable, java.io.Serializable

public class BasicEditorPane
extends javax.swing.JEditorPane
implements ActionInvoker, java.awt.dnd.Autoscroll, java.beans.PropertyChangeListener

A BasicEditorPane is an extension of the JEditorPane to provide more flexible syntax and background highlighting functionality at a reduced memory and performance footprint. It can be used anywhere a JEditorPane instance can be used. Clients are strongly encouraged to call dispose() when the the editor pane is no longer needed, but this is not an absolute requirement. This allows us to clean up as well as notify editor plugins that the editor is no longer being used.

Undo Support:

The editor framework provides some support for naming edits, grouping together similar edits, and undo of navigation. When making a change to the document using insertString() or remove(), or through the editor using replaceSelection(), cut(), or paste(), you can specify a name for the edit by creating an EditDescriptor for the edit, and passing it to BasicEditorPane.beginEdit(EditDescriptor). Additionally, you can use it for grouping together a group of edits as a single undoable unit by placing your edits between a call to BasicEditorPane.beginEdit(EditDescriptor) and BasicEditorPane.endEdit(EditDescriptor).

The edit name which you specify through the EditDescriptor is made available through the UndoableEdit using getPresentationName(). This allows you to name your edits like "Add Button", or "Add Field" so that it better describes the edit operation the Undo or Redo applies to.

Built-in actions have pre-defined names used for the EditDescriptor already. Additionally, the editor provides automatic support for merging simple edits. Currently, the simple edit consists of a key-typed insert (insert mode), a key-typed replace (overwrite mode), delete next (Delete key), or delete previous (Backspace key). These simple edits may be merged with other consecutive simple edits of the same type. That means two inserts in a row will be automatically merged if merging for key-typed inserts is enabled, and the merge count allowed is set to greater than two. Look in EditorProperties for the properties to set to enable merging of simple edits, and for setting the merge count.

The editor also provides support for undoing navigation (without associated document changes) using beginNavigation() and endNavigation(). Client code which causes a navigation in the editor (such as "Go to Line", or "Find") should always wrap their navigation commands with calls to beginNavigation() and endNavigation. The current default for the editor is to generate undo events for navigation, though this can be disabled with the appropriate property in EditorProperties. If the editor is set to not generate undos for navigation, the beginNavigation() and endNavigation() will just be NOP calls.

As with the Swing text framework, the UndoableEditListener should be attached to the document (BasicDocument). Undo edits (including navigation) will be delivered through the document. Highlight Support:

For highlight support, refer to the documentation for the HighlightLayer class.

Underline Support:

For underline support, refer to the documentation for the UnderlineLayer class.

Tooltip Support:

For tooltip support, refer to the documentation for the TooltipProvider interface.

Popup Support:

For popup (context) menu support, refer to the documentation for the PopupManager interface.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JEditorPane
javax.swing.JEditorPane.AccessibleJEditorPane, javax.swing.JEditorPane.AccessibleJEditorPaneHTML, javax.swing.JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Nested classes inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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
BasicEditorPane()
          Creates a new instance of a BasicEditorPane.
 
Method Summary
 void addActionHookInvoker(ActionHookInvoker invoker)
          Adds an ActionHookInvoker to the list so that it has a chance to override the default action temporarily.
 void addActionPostInvoker(ActionPostInvoker invoker)
          Adds an ActionPostInvoker to the list so that it gets notified of successfully completed actions just after the fact.
 void addCharacterTypedListener(CharacterTypedListener listener)
          Adds a character typed listener to the list so that it can receive notifications of characters typed into this editor pane.
 void addFeedbackManager(FeedbackManager manager)
          Installs the given FeedbackManager for displaying feedback messages to the user for this editor pane.
 void addPopupManager(PopupManager manager)
          Installs the given PopupManager for managing popup menus for this editor pane.
 void addToolTipProvider(ToolTipProvider provider)
          Installs the given ToolTipProvider for providing tooltips for the editor pane.
 void autoscroll(java.awt.Point location)
          Notify the Component to autoscroll.
 void beginEdit(EditDescriptor editDescriptor)
          Marks the start of an Undoable edit applied through this editor.
 void beginNavigation()
          Marks the start of a navigation through this editor.
 boolean canCopy()
          Fetches whether a copy operation can be performed by calling copy().
 boolean canCut()
          Fetches whether a cut operation can be performed by calling cut().
 boolean canPaste()
          Fetches whether the paste operation can be performed by calling paste().
 void copy()
          Transfers the currently selected range in the associated text model to the system clipboard, leaving the contents in the text model.
protected  javax.swing.text.EditorKit createDefaultEditorKit()
          Creates the default editor kit for when the component is first created.
 HighlightLayer createHighlightLayer()
          Creates a new highlight layer that can be used for highlighting text in this editor pane.
 UnderlineLayer createUnderlineLayer()
          Creates a new underline layer that can be used for underlining text in this editor pane.
 void cut()
          Transfers the currently selected range in the associated text model to the system clipboard, removing the contents from the model.
protected  void deinstallAllPlugins()
          Utility routine to deinstall all plugins.
protected  void deinstallKeyboardSupport()
          Support routine to deinitialize the keyboard support for this editor pane instance.
 void deinstallPlugin(EditorPlugin plugin)
          This deinstalls an editor plugin from the editor.
 void destroyHighlightLayer(HighlightLayer layer)
          Destroys a highlight layer that is no longer needed.
 void destroyUnderlineLayer(UnderlineLayer layer)
          Destroys a underline layer that is no longer needed.
 void dispose()
          Instructs this editor pane that it is no longer needed, and that it can clear up resources and references.
 void endEdit()
          Marks the end of an Undoable edit applied through this editor.
 void endNavigation()
          Marks the end of a navigation through this editor.
protected  void ensureVisibleAndCentered(int location)
           
protected  void ensureVisibleAndCentered(java.awt.Rectangle positionRect)
          Utility routine to ensure that the given position is visible vertically and horizontally.
protected  void ensureVisibleAndCentered(java.awt.Rectangle positionRect, boolean force)
          Utility routine to ensure that the given position is visible vertically and horizontally.
protected  void finalize()
          Finalizer to clean up the editor in case it was not disposed of properly.
protected  void fireCharacterTypedEvent(int offset, char charTyped)
          Utility routine used to notify listeners that a character was typed.
 ActionInvoker getActionInvoker()
          Fetches the action invoker to use to execute some particular action.
 java.awt.Insets getAutoscrollInsets()
          This method returns the Insets describing the autoscrolling region or border relative to the geometry of the implementing Component.
 boolean getBooleanProperty(java.lang.String key)
          Fetch the boolean property stored by the given key.
 FeedbackManager getFeedbackManager()
          Fetches the current installed FeedbackManager.
 FontHelper getFontHelper()
          Convenience method for getting the current font helper.
 javax.swing.text.Highlighter getHighlighter()
          Fetches the object responsible for making highlights.
protected  java.util.Iterator getHighlightLayers()
          Fetches an iterator to access the highlight layers associated with this editor pane.
 HighlightRegistry getHighlightRegistry()
          Fetch the global highlight registry used for all editor panes.
 int getIntegerProperty(java.lang.String key)
          Fetch the integer property stored by the given key.
 int getLineCount()
          Fetches the number of lines in this TextBuffer.
 int getLineEndOffset(int line)
          Given a specified line, returns the offset from the beginning of a TextBuffer that the line ends at.
 int getLineFromOffset(int offset)
          Given an offset from the beginning of the underlying TextBuffer, fetches the line number containing that offset using a Forward bias.
 int getLineStartOffset(int line)
          Given a specified line, returns the offset from the beginning of the TextBuffer for the start of the line.
 PopupManager getPopupManager()
          Fetches the current installed PopupManager.
 java.lang.Object getProperty(java.lang.String key)
          Get the property associated with the given key.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation.
 StyleRegistry getStyleRegistry()
          Fetch the global style registry used for all editor panes.
 ToolTipProvider getToolTipProvider()
          Fetches the current installed ToolTipProvider.
 java.lang.String getToolTipText()
          Returns the tooltip string that has been set with setToolTipText().
 java.lang.String getToolTipText(java.awt.event.MouseEvent event)
          Returns the string to be used as the tooltip for event.
protected  java.util.Iterator getUnderlineLayers()
          Fetches an iterator to access the underline layers associated with this editor pane.
 UnderlineRegistry getUnderlineRegistry()
          Fetch the global underline registry used for all editor panes.
 boolean hasSelection()
          Fetches whether there is currently a selection in the editor.
protected  void installBuiltInPlugins()
          Utility routine to install known, built-in plugins.
protected  void installKeyboardSupport()
          Support routine to initialize the keyboard support for this editor pane instance.
 void installPlugin(EditorPlugin plugin)
          This installs an editor plugin into the editor.
 void invokeAction(java.lang.String actionKey)
          Invokes the Action corresponding to the given actionKey.
protected  boolean isCutCopyLineEnabled()
          Checks whether Cut/Copy on current line with no selection is enabled.
 boolean isProtected()
          Fetches whether the editor's content is protected or not - this may be used by clients to indicate that the document is some sort of protected content, and that changes cannot be made directly through the editor, but through other wizards or dialogs instead.
 void moveCaretPosition(int position)
          Moves the caret to a new position, leaving behind a mark defined by the last time setCaretPosition was called.
 void moveCaretPositionCenter(int position)
          Moves the caret to a new position, leaving behind a mark defined by the last time setCaretPosition was called.
 void paste()
          Transfers the contents of the system clipboard into the associated text model.
 void propertyChange(java.beans.PropertyChangeEvent event)
          This method gets called when a bound property is changed.
 void putBooleanProperty(java.lang.String key, boolean value)
          Sets the boolean property and value in the property table.
 void putIntegerProperty(java.lang.String key, int value)
          Sets the integer property and value in the property table.
 void putProperty(java.lang.String key, java.lang.Object value)
          Store the property associated with the given key.
 void removeActionHookInvoker(ActionHookInvoker invoker)
          Removes an ActionHookInvoker from our list.
 void removeActionPostInvoker(ActionPostInvoker invoker)
          Removes an ActionPostInvoker from our list.
 void removeCharacterTypedListener(CharacterTypedListener listener)
          Removes a character typed listener from the list so that it no longer receives notifications.
 void removeFeedbackManager(FeedbackManager manager)
          Deinstalls the given FeedbackManager that was previously installed for handling feedback messages for this editor pane.
 void removePopupManager(PopupManager manager)
          Deinstalls the given PopupManager that was previously installed for managing popup menus for the editor pane.
 void removeToolTipProvider(ToolTipProvider provider)
          Deinstalls the given ToolTipProvider that was previously installed for getting tooltip info for the editor pane.
 void replaceSelection(java.lang.String content)
          Replaces the currently selected content with the new content represented by the given String.
 void select(int selectionStart, int selectionEnd)
          Selects the text found between the specified start and end locations.
 void selectAll()
          Selects all the text in the TextComponent.
 void setBaseFont(java.lang.String fontFamily, int fontSize)
          Set the base font of this editor pane independently from the global base font.
 void setCaretPosition(int position)
          Sets the position of the text insertion caret for the TextComponent.
 void setCaretPositionCenter(int position)
          Sets the position of the text insertion caret for the TextComponent.
 void setDocument(javax.swing.text.Document doc)
          Associates the editor with the text document.
 void setEditable(boolean editable)
          Sets the specified boolean to indicate whether or not this TextComponent should be editable.
 void setFont(java.awt.Font font)
          We override the setFont implementation, as the font handling in the editor framework is different.
 void setHighlighter(javax.swing.text.Highlighter h)
          Sets the highlighter to be used.
 void setHighlightRegistry(HighlightRegistry registry)
          Replace the global highlight registry used for all editor panes.
 void setLanguageSupport(java.lang.String fileName)
          Sets the LanguageSupport for editing the type of content indicated by the specified filename.
 void setProtected(boolean makeProtected)
          Sets the editor in protected mode or not.
 void setStyleRegistry(StyleRegistry registry)
          Replace the global style registry used for all editor panes.
 void setToolTipText(java.lang.String text)
          Registers the text to display in a tool tip.
 void setUnderlineRegistry(UnderlineRegistry registry)
          Replace the global underline registry used for all editor panes.
 void unselect()
          Unselects the current text selection (if any), but leaves the caret where it is.
 void updateUI()
          Reloads the pluggable UI.
protected  boolean useDefaultKeyHandling()
          Fetches whether the default use of the multi-key handler should be used.
protected  void validateVisibleRect(java.awt.Rectangle visibleRect)
          Utility method to ensure that the visible rectangle does not go beyond the edges of the editor view.
 
Methods inherited from class javax.swing.JEditorPane
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, getUIClassID, paramString, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKit, setEditorKitForContentType, setPage, setPage, setText
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getUI, isEditable, loadKeymap, modelToView, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, setCaret, setCaretColor, setComponentOrientation, setDisabledTextColor, setDragEnabled, setFocusAccelerator, setKeymap, setMargin, setNavigationFilter, 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, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicEditorPane

public BasicEditorPane()
Creates a new instance of a BasicEditorPane. Note, it is strongly encouraged that clients that use the BasicEditorPane call dispose() when it is no longer necessary.

See Also:
dispose()
Method Detail

setLanguageSupport

public void setLanguageSupport(java.lang.String fileName)
Sets the LanguageSupport for editing the type of content indicated by the specified filename.

Parameters:
fileName - the name of the file

beginEdit

public void beginEdit(EditDescriptor editDescriptor)
Marks the start of an Undoable edit applied through this editor. This instructs the editor to record its caret information into the undoable edit so that when the edit is undone or redone, the caret position is restored appropriately.

Parameters:
editDescriptor - the edit descriptor describes this edit, such as providing a human-readable name

endEdit

public void endEdit()
Marks the end of an Undoable edit applied through this editor.


beginNavigation

public void beginNavigation()
Marks the start of a navigation through this editor. If navigation is marked as undoable, then this instructs the editor to generate the start of an Undo event.


endNavigation

public void endNavigation()
Marks the end of a navigation through this editor. If navigation is marked as undoable, then this instructs the editor to generate the end of an Undo event.


unselect

public void unselect()
Unselects the current text selection (if any), but leaves the caret where it is.


setCaretPositionCenter

public void setCaretPositionCenter(int position)
Sets the position of the text insertion caret for the TextComponent. This works the same way as setCaretPosition() except that if the new caret position is offscreen, it recenters the new position vertically into the center of the parent view port.

Parameters:
position - the position

moveCaretPositionCenter

public void moveCaretPositionCenter(int position)
Moves the caret to a new position, leaving behind a mark defined by the last time setCaretPosition was called. This is similar to setCaretPositionCenter in that if the new position is offscreen, it recenters the new position vertically into the center of the parent view port.

Parameters:
position - the position

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalizer to clean up the editor in case it was not disposed of properly.

Throws:
java.lang.Throwable

dispose

public void dispose()
Instructs this editor pane that it is no longer needed, and that it can clear up resources and references. This is strongly encouraged so that the editor can clean up its resources and deinstall all editor plugins properly.


isProtected

public boolean isProtected()
Fetches whether the editor's content is protected or not - this may be used by clients to indicate that the document is some sort of protected content, and that changes cannot be made directly through the editor, but through other wizards or dialogs instead. From a user's point of view, this is equivalent to making something read-only, except that the status bar will show "Protected" when it is protected, or "Read Only" when it is read only.

Returns:
whether the editor is in protected mode or not

setProtected

public void setProtected(boolean makeProtected)
Sets the editor in protected mode or not.

Parameters:
makeProtected - true to set the editor in protected mode

isCutCopyLineEnabled

protected boolean isCutCopyLineEnabled()
Checks whether Cut/Copy on current line with no selection is enabled.

Returns:
true if cut or copy on current line with no selection is enabled.

canCut

public boolean canCut()
Fetches whether a cut operation can be performed by calling cut(). This checks to make sure the editor is editable, and that there is a selection to cut.

Returns:
whether the cut() operation can be performed

canCopy

public boolean canCopy()
Fetches whether a copy operation can be performed by calling copy(). This checks to make that there is a selection currently in the editor to copy.

Returns:
whether the copy() operation can be performed

canPaste

public boolean canPaste()
Fetches whether the paste operation can be performed by calling paste(). This checks to make sure that the editor is editable, but does not check if the contents are pasteable as that can be an expensive operation.

Returns:
whether the paste() operation can be performed

hasSelection

public boolean hasSelection()
Fetches whether there is currently a selection in the editor.

Returns:
whether there is a selection in the editor

getFontHelper

public FontHelper getFontHelper()
Convenience method for getting the current font helper.

Returns:
the current FontHelper instance

setBaseFont

public void setBaseFont(java.lang.String fontFamily,
                        int fontSize)
Set the base font of this editor pane independently from the global base font. Note that changes to the global base font will override this custom font set in this editor.

Parameters:
fontFamily - the font family of the base font
fontSize - the font size of the base font

getStyleRegistry

public StyleRegistry getStyleRegistry()
Fetch the global style registry used for all editor panes.

Returns:
the global style registry

setStyleRegistry

public void setStyleRegistry(StyleRegistry registry)
Replace the global style registry used for all editor panes.

Parameters:
registry - the new registry to use

getHighlightRegistry

public HighlightRegistry getHighlightRegistry()
Fetch the global highlight registry used for all editor panes.

Returns:
the global highlight registry

setHighlightRegistry

public void setHighlightRegistry(HighlightRegistry registry)
Replace the global highlight registry used for all editor panes.

Parameters:
registry - the new registry to use

getUnderlineRegistry

public UnderlineRegistry getUnderlineRegistry()
Fetch the global underline registry used for all editor panes.

Returns:
the global underline registry

setUnderlineRegistry

public void setUnderlineRegistry(UnderlineRegistry registry)
Replace the global underline registry used for all editor panes.

Parameters:
registry - the new registry to use

setFont

public void setFont(java.awt.Font font)
We override the setFont implementation, as the font handling in the editor framework is different. Since this editor is capable of rendering different styles for the same font, and since we are using global fonts from our properties, we ignore the normal Swing/AWT set font mechanism. To change the base font of this editor by itself, use BasicEditorPane.setBaseFont(). To change the global base font of the editor framework, use EditorProperties.setBaseFont().

Parameters:
font - the font to set

setEditable

public void setEditable(boolean editable)
Sets the specified boolean to indicate whether or not this TextComponent should be editable. A PropertyChange event ("editable") is fired when the state is changed. We override this to track whether the clients have made the editor read only through this, so that if the editor's protected or the text buffer's read only mode changes, we can still honor user's programmatic changes

Parameters:
editable - the boolean to be set

createDefaultEditorKit

protected javax.swing.text.EditorKit createDefaultEditorKit()
Creates the default editor kit for when the component is first created.

Returns:
the editor kit

updateUI

public void updateUI()
Reloads the pluggable UI. Override this here as we have our own custom UI that takes care of locking the document properly.


setDocument

public void setDocument(javax.swing.text.Document doc)
Associates the editor with the text document. We override this to do proper reference cleanup.

Parameters:
doc - the new document

cut

public void cut()
Transfers the currently selected range in the associated text model to the system clipboard, removing the contents from the model. The current selection is reset. Does nothing for null selections. We override the default behavior to generate undo's with caret information.


copy

public void copy()
Transfers the currently selected range in the associated text model to the system clipboard, leaving the contents in the text model. The current selection is remains intact. Does nothing for null selections.


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. We override the default behavior to generate undo's with caret information.

See Also:
replaceSelection(java.lang.String)

replaceSelection

public void replaceSelection(java.lang.String content)
Replaces the currently selected content with the new content represented by the given String. We override the implementation of JTextComponent so that the whole replace can be a single undoable operation.

Parameters:
content - the new content to replace the current selection

selectAll

public void selectAll()
Selects all the text in the TextComponent. Does nothing on a null or empty document. We override the default implementation so that the cursor is placed at the beginning instead of the end. This is so that it doesn't scroll to the end on a select all.


select

public void select(int selectionStart,
                   int selectionEnd)
Selects the text found between the specified start and end locations.

Parameters:
selectionStart - the start position of the text >= 0
selectionEnd - the end position of the text >= 0
See Also:
setCaretPosition(int), moveCaretPosition(int)

getHighlighter

public javax.swing.text.Highlighter getHighlighter()
Fetches the object responsible for making highlights. Highlighting is now done through HighlightLayers instead of through the Swing text highlighters.

Returns:
the highlighter

setHighlighter

public void setHighlighter(javax.swing.text.Highlighter h)
Sets the highlighter to be used. Highlighting is now done through HighlightLayers instead of through the Swing text highlighters.

Parameters:
h - the highlighter

setToolTipText

public void setToolTipText(java.lang.String text)
Registers the text to display in a tool tip. This method does not do anything as tool tips for the editor are done using the ToolTipProvider instead.

Parameters:
text - the text to display in a tool tip.

getToolTipText

public java.lang.String getToolTipText()
Returns the tooltip string that has been set with setToolTipText(). We currently do not provide tooltip information that does not correspond to a mouse event.

Returns:
the tooltip text

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent event)
Returns the string to be used as the tooltip for event. By default this returns any string set using setToolTipText(). If a component provides more extensive API to support differing tooltips at different locations, this method should be overridden.


getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation. Ideally, components should handle a partially exposed row or column by returning the distance required to completely expose the item.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable
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:
JScrollBar.setUnitIncrement(int)

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable
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:
JScrollBar.setBlockIncrement(int)

setCaretPosition

public void setCaretPosition(int position)
Sets the position of the text insertion caret for the TextComponent. We override the default behavior so that instead of throwing the exception (which most clients probably are not expecting), we just quietly move the caret to the closest valid offset.

Parameters:
position - the position

moveCaretPosition

public void moveCaretPosition(int position)
Moves the caret to a new position, leaving behind a mark defined by the last time setCaretPosition was called. This forms a selection. Again, we override the default behavior to make sure that the position is valid. If not, we move it to the closest valid offset.

Parameters:
position -

getAutoscrollInsets

public java.awt.Insets getAutoscrollInsets()
This method returns the Insets describing the autoscrolling region or border relative to the geometry of the implementing Component.

This value is read once by the DropTarget upon entry of the drag Cursor into the associated Component.

Specified by:
getAutoscrollInsets in interface java.awt.dnd.Autoscroll
Returns:
the Insets

autoscroll

public void autoscroll(java.awt.Point location)
Notify the Component to autoscroll.

Specified by:
autoscroll in interface java.awt.dnd.Autoscroll
Parameters:
location - the Point location that triggered this autoscroll.

validateVisibleRect

protected void validateVisibleRect(java.awt.Rectangle visibleRect)
Utility method to ensure that the visible rectangle does not go beyond the edges of the editor view.

Parameters:
visibleRect - the visible rect to validate

getProperty

public final java.lang.Object getProperty(java.lang.String key)
Get the property associated with the given key.

Parameters:
key - the property to get
Returns:
the property
See Also:
EditorProperties

putProperty

public final void putProperty(java.lang.String key,
                              java.lang.Object value)
Store the property associated with the given key.

Parameters:
key - the property to store
value - the value to store
See Also:
EditorProperties

getBooleanProperty

public boolean getBooleanProperty(java.lang.String key)
Fetch the boolean property stored by the given key. This may throw a ClassCastException if the property is not a boolean property

Parameters:
key - the property to get
Throws:
java.lang.ClassCastException - if the property is not a boolean property

putBooleanProperty

public void putBooleanProperty(java.lang.String key,
                               boolean value)
Sets the boolean property and value in the property table.

Parameters:
key - the property name
value - the property value

getIntegerProperty

public int getIntegerProperty(java.lang.String key)
Fetch the integer property stored by the given key. This may throw a ClassCastException if the property is not a integer property

Parameters:
key - the property to get
Throws:
java.lang.ClassCastException - if the property is not a integer property

putIntegerProperty

public void putIntegerProperty(java.lang.String key,
                               int value)
Sets the integer property and value in the property table.

Parameters:
key - the property name
value - the property value

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
This method gets called when a bound property is changed.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
event - A PropertyChangeEvent object describing the event source and the property that has changed.

getLineCount

public int getLineCount()
Fetches the number of lines in this TextBuffer. For example, a 5-line TextBuffer has lines 0 through 4.

Returns:
number of lines in TextBuffer

getLineFromOffset

public int getLineFromOffset(int offset)
Given an offset from the beginning of the underlying TextBuffer, fetches the line number containing that offset using a Forward bias. This means if line A starts with offset B, and previous line A-1 ends with offset B, getLineFromOffset(B) will return line A.

Returns:
the line containing an offset

getLineStartOffset

public int getLineStartOffset(int line)
Given a specified line, returns the offset from the beginning of the TextBuffer for the start of the line.

Parameters:
line - a line in the TextBuffer
Returns:
the starting offset of the specified line

getLineEndOffset

public int getLineEndOffset(int line)
Given a specified line, returns the offset from the beginning of a TextBuffer that the line ends at.

Parameters:
line - a line in the TextBuffer

addActionHookInvoker

public void addActionHookInvoker(ActionHookInvoker invoker)
Adds an ActionHookInvoker to the list so that it has a chance to override the default action temporarily.

Parameters:
invoker - the invoker to add

removeActionHookInvoker

public void removeActionHookInvoker(ActionHookInvoker invoker)
Removes an ActionHookInvoker from our list.

Parameters:
invoker - the invoker to remove

addActionPostInvoker

public void addActionPostInvoker(ActionPostInvoker invoker)
Adds an ActionPostInvoker to the list so that it gets notified of successfully completed actions just after the fact.

Parameters:
invoker - the invoker to add

removeActionPostInvoker

public void removeActionPostInvoker(ActionPostInvoker invoker)
Removes an ActionPostInvoker from our list.

Parameters:
invoker - the invoker to remove

getActionInvoker

public ActionInvoker getActionInvoker()
Fetches the action invoker to use to execute some particular action.

Returns:
the action invoker

invokeAction

public void invokeAction(java.lang.String actionKey)
Invokes the Action corresponding to the given actionKey.

Specified by:
invokeAction in interface ActionInvoker
Parameters:
actionKey - the published key for the action

installPlugin

public void installPlugin(EditorPlugin plugin)
This installs an editor plugin into the editor. This will call the install() method of the plugin as well as add the plugin as a PropertyChangeListener of the editor to receive property change events.

Parameters:
plugin - the plugin to install

deinstallPlugin

public void deinstallPlugin(EditorPlugin plugin)
This deinstalls an editor plugin from the editor. This will call the deinstall() method of the plugin as well as remove the plugin from being a PropertyChangeListener of the editor.

Parameters:
plugin - the plugin to deinstall

installBuiltInPlugins

protected void installBuiltInPlugins()
Utility routine to install known, built-in plugins.


deinstallAllPlugins

protected void deinstallAllPlugins()
Utility routine to deinstall all plugins.


createHighlightLayer

public HighlightLayer createHighlightLayer()
Creates a new highlight layer that can be used for highlighting text in this editor pane. Make sure to remove the highlight layer when it is no longer needed (even if it contains no highlights) so that it can be released.

Returns:
a newly created HighlightLayer that can be used for adding highlights to this editor pane

destroyHighlightLayer

public void destroyHighlightLayer(HighlightLayer layer)
Destroys a highlight layer that is no longer needed. This will also remove all highlights in that layer from this editor pane.

Parameters:
layer - the highlight layer to remove

getHighlightLayers

protected java.util.Iterator getHighlightLayers()
Fetches an iterator to access the highlight layers associated with this editor pane. This is needed by the view renderers to get access to the highlight layers for rendering the highlights for this editor pane.

Returns:
an iterator for accessing the highlight layers

createUnderlineLayer

public UnderlineLayer createUnderlineLayer()
Creates a new underline layer that can be used for underlining text in this editor pane. Make sure to remove the underline layer when it is no longer needed (even if it contains no underlines) so that it can be released.

Returns:
a newly created UnderlineLayer that can be used for adding underlines to this editor pane

destroyUnderlineLayer

public void destroyUnderlineLayer(UnderlineLayer layer)
Destroys a underline layer that is no longer needed. This will also remove all underlines in that layer from this editor pane.

Parameters:
layer - the underline layer to remove

getUnderlineLayers

protected java.util.Iterator getUnderlineLayers()
Fetches an iterator to access the underline layers associated with this editor pane. This is needed by the view renderers to get access to the underline layers for rendering the underlines for this editor pane.

Returns:
an iterator for accessing the underline layers

addPopupManager

public void addPopupManager(PopupManager manager)
Installs the given PopupManager for managing popup menus for this editor pane. When the user requests a popup menu, usually by right-clicking in the editor content, the showPopup() method of the PopupManager will be called. Only one PopupManager can be installed at any given time (but this is not enforced programmatically at the current time.)

Parameters:
manager - the popup manager to install

removePopupManager

public void removePopupManager(PopupManager manager)
Deinstalls the given PopupManager that was previously installed for managing popup menus for the editor pane.

Parameters:
manager - the popup manager to de-install

getPopupManager

public PopupManager getPopupManager()
Fetches the current installed PopupManager. This is primarily used within the editor component, for example by the BasicCaret, to notify the appropriate PopupManager for handling events related to popup menus. This will return null if there is no popup manager installed.

Returns:
the currently installed PopupMenu

addToolTipProvider

public void addToolTipProvider(ToolTipProvider provider)
Installs the given ToolTipProvider for providing tooltips for the editor pane. When the user requests a tooltip (by moving the mouse over text in the editor and waiting), the getToolTipText() method of the ToolTipProvider will be called. Only one ToolTipProvider can be installed at any given time (but this is not enforced programmatically currently.)

Parameters:
provider - the tool tip provider to install

removeToolTipProvider

public void removeToolTipProvider(ToolTipProvider provider)
Deinstalls the given ToolTipProvider that was previously installed for getting tooltip info for the editor pane.

Parameters:
provider - the tooltip provider to de-install.

getToolTipProvider

public ToolTipProvider getToolTipProvider()
Fetches the current installed ToolTipProvider. This is primarily used within the editor component, for example when a tool tip needs to be popped up. This will return null if there is no popup manager installed.

Returns:
the currently installed ToolTipProvider

addFeedbackManager

public void addFeedbackManager(FeedbackManager manager)
Installs the given FeedbackManager for displaying feedback messages to the user for this editor pane. Only one FeedbackManager can be installed at any given time (this is not enforce programmatically however.)

Parameters:
manager - the feedback manager to install

removeFeedbackManager

public void removeFeedbackManager(FeedbackManager manager)
Deinstalls the given FeedbackManager that was previously installed for handling feedback messages for this editor pane.

Parameters:
manager - the feedback manager to de-install

getFeedbackManager

public FeedbackManager getFeedbackManager()
Fetches the current installed FeedbackManager. This is can be used for displaying feedback messages to the user associated with this editor pane. This will return null if there is no feedback manager installed.

Returns:
the currently installed FeedbackMenu

addCharacterTypedListener

public void addCharacterTypedListener(CharacterTypedListener listener)
Adds a character typed listener to the list so that it can receive notifications of characters typed into this editor pane.

Parameters:
listener - the listener to add

removeCharacterTypedListener

public void removeCharacterTypedListener(CharacterTypedListener listener)
Removes a character typed listener from the list so that it no longer receives notifications.

Parameters:
listener - the listener to remove

fireCharacterTypedEvent

protected void fireCharacterTypedEvent(int offset,
                                       char charTyped)
Utility routine used to notify listeners that a character was typed. This is protected so that it can be called by the DefaultKeyTypedAction rather than passing the listeners off to the action.

Parameters:
offset - the offset where the character was typed
charTyped - the character that was typed

useDefaultKeyHandling

protected boolean useDefaultKeyHandling()
Fetches whether the default use of the multi-key handler should be used. Subclasses can return false to override the key handling behavior.

Returns:
true to use the default key handling mechanism

installKeyboardSupport

protected void installKeyboardSupport()
Support routine to initialize the keyboard support for this editor pane instance. This can be overrided by subclasses to change the way keymap support is done within the editor.


deinstallKeyboardSupport

protected void deinstallKeyboardSupport()
Support routine to deinitialize the keyboard support for this editor pane instance. This can be overrided by subclasses to change the way keymap support is done within the editor.


ensureVisibleAndCentered

protected void ensureVisibleAndCentered(int location)

ensureVisibleAndCentered

protected void ensureVisibleAndCentered(java.awt.Rectangle positionRect)
Utility routine to ensure that the given position is visible vertically and horizontally. if the position is not entirely visible in either direction, the viewport is recentered in the to center it (vertically, horizontally, or both.)

Parameters:
positionRect - the rectangle to make sure if visible

ensureVisibleAndCentered

protected void ensureVisibleAndCentered(java.awt.Rectangle positionRect,
                                        boolean force)
Utility routine to ensure that the given position is visible vertically and horizontally. if the position is not entirely visible in either direction, the viewport is recentered in the to center it (vertically, horizontally, or both.)

Parameters:
positionRect - the rectangle to make sure if visible
force - whether to force centering

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.