Extension SDK 10.1.2

oracle.javatools.editor
Class BasicAction

java.lang.Object
  extended byjavax.swing.AbstractAction
      extended byjavax.swing.text.TextAction
          extended byoracle.javatools.editor.BasicAction
All Implemented Interfaces:
javax.swing.Action, java.awt.event.ActionListener, java.lang.Cloneable, java.util.EventListener, java.io.Serializable
Direct Known Subclasses:
BasicEditorKit.BeepAction, BasicEditorKit.BlockIndentOutdentAction, BasicEditorKit.CopyAction, BasicEditorKit.CutAction, BasicEditorKit.DefaultKeyTypedAction, BasicEditorKit.DeleteLineAction, BasicEditorKit.DeleteNextCharAction, BasicEditorKit.DeleteNextWordAction, BasicEditorKit.DeletePrevCharAction, BasicEditorKit.DeletePreviousWordAction, BasicEditorKit.DeleteUntilEOLAction, BasicEditorKit.GotoMatchingBraceAction, BasicEditorKit.InsertBreakAction, BasicEditorKit.MacroRecorderAction, BasicEditorKit.NavigateAction, BasicEditorKit.NOPAction, BasicEditorKit.OpenLineAction, BasicEditorKit.PasteAction, BasicEditorKit.ReadOnlyAction, BasicEditorKit.RecenterLineAction, BasicEditorKit.ScrollLineDownAction, BasicEditorKit.ScrollLineUpAction, BasicEditorKit.ScrollPageDownAction, BasicEditorKit.ScrollPageUpAction, BasicEditorKit.SelectAllAction, BasicEditorKit.SelectLineAction, BasicEditorKit.SelectWordAction, BasicEditorKit.SetLocalTabSizeAction, BasicEditorKit.SortSelectedLines, BasicEditorKit.TabifyAction, BasicEditorKit.ToggleCommentsAction, BasicEditorKit.ToggleInsertModeAction, BasicEditorKit.TransposeCharsAction, BasicEditorKit.UnselectAction, BasicEditorKit.UntabifyAction, BasicEditorKit.WritableAction, EmacsAction

public abstract class BasicAction
extends javax.swing.text.TextAction

The BasicAction is an abstract class that all editor actions should extend from. This provides some utility routines that can be used by subclasses. The primary purpose of this class is to track the last action executed within the editor. This is needed as certain actions (particularly Emacs ones) depend on this information.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
BasicAction(java.lang.String actionName)
          Constructs this object with the appropriate action name.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          The operation to perform when this action is triggered.
abstract  void actionPerformed(java.awt.event.ActionEvent event, BasicEditorPane editor, BasicDocument document)
          The operation to perform when this action is triggered in a BasicEditorPane.
static void beep(BasicEditorPane editor)
          Utility routine which just emits a beep.
static java.lang.String buildIndent(boolean useTabs, int tabSize, int numColumns)
          Utility routine to build a String that can be used to indent a line by a certain size (not necessarily a single indent.) This is used for example if the document does use tab characters and the user indents the line - we may need to convert spaces to tabs to do the right thing.
static int getFontHeight(BasicEditorPane editor)
          Utility routine which fetches the height of the current font of the editor.
 BasicAction getLastAction(BasicEditorPane editor)
          Utility routine which retrieves the last action executed (prior to the current one.) If there was no previous action, null is returned.
static java.awt.Point getMagicCaretPosition(BasicEditorPane editor)
          Reads the magic caret position from the editor's caret, or if there is none, the current horizontal position of the cursor.
protected  java.lang.String getName()
          Utility routine to return the name of this action instance.
static SmartIndentProvider getSmartIndentProvider(BasicEditorPane editor, BasicDocument document)
          Fetch the SmartIndentProvider for the current document.
static java.lang.String getSpaces(int numSpaces)
          Get a String with the specified number of space characters
static java.lang.String getTab(boolean useTabs, int tabSize)
          Utility routine to fetch the tab or equivalent spaces to use.
static java.lang.String getTabs(int numTabs)
          Get a String with the specified number of tab characters
static int getTabSizeProperty(BasicEditorPane editor)
          Utility routine to fetch the tab stop size for the given editor.
static boolean getUseAutoIndentProperty(BasicEditorPane editor)
          Utility routine to fetch whether auto-indentation should be done for the given editor.
static boolean getUseTabsProperty(BasicEditorPane editor)
          Utility routine to fetch whether a tab character should be used for the given editor.
static java.awt.Rectangle getVisibleRect(BasicEditorPane editor)
          Utility routine to fetch the current visible rectangle of the editor.
static boolean isEditable(BasicEditorPane editor, boolean beepIfNotEditable)
          Utility routine which checks if the editor is editable, and beeps if it isn't (if requested.)
static void setMagicCaretPosition(BasicEditorPane editor, java.awt.Point magicPosition)
          Stores the magic caret position into the editor's caret.
static void showMessage(BasicEditorPane editor, java.lang.String message)
          Utility routine to show a feedback message in the editor.
static int skipLeadingIndent(TextBuffer textBuffer, int lineStart, int lineEnd)
          Utility routine to find the offset of the first character after the leading indent (if any), or -1 for an empty line or line containing only whitespace.
 
Methods inherited from class javax.swing.text.TextAction
augmentList, getFocusedComponent, getTextComponent
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicAction

public BasicAction(java.lang.String actionName)
Constructs this object with the appropriate action name.

Method Detail

actionPerformed

public abstract void actionPerformed(java.awt.event.ActionEvent event,
                                     BasicEditorPane editor,
                                     BasicDocument document)
The operation to perform when this action is triggered in a BasicEditorPane. Implementations should override this method. Implementations are guaranteed that the document read lock is held for the duration of this call.

Parameters:
event - the action event
editor - the editor this action was invoked in
document - the document associated with the editor

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
The operation to perform when this action is triggered.

Parameters:
event - the action event

getName

protected final java.lang.String getName()
Utility routine to return the name of this action instance.

Returns:
the name of this action

getLastAction

public final BasicAction getLastAction(BasicEditorPane editor)
Utility routine which retrieves the last action executed (prior to the current one.) If there was no previous action, null is returned.

Parameters:
editor - the editor to check the last action executed
Returns:
the instance of the last action, or null if there was no last action

getMagicCaretPosition

public static java.awt.Point getMagicCaretPosition(BasicEditorPane editor)
                                            throws javax.swing.text.BadLocationException
Reads the magic caret position from the editor's caret, or if there is none, the current horizontal position of the cursor.

Parameters:
editor - the editor in which the vertical navigation occurred
Returns:
the magic caret position to use
Throws:
javax.swing.text.BadLocationException - this is generally unexpected, and may signal something more serious

setMagicCaretPosition

public static void setMagicCaretPosition(BasicEditorPane editor,
                                         java.awt.Point magicPosition)
Stores the magic caret position into the editor's caret. The magic postion is the point returned from getMagicCaretPosition().

Parameters:
editor - the editor in which the vertical navigation occurred
magicPosition - the new magic caret position

isEditable

public static boolean isEditable(BasicEditorPane editor,
                                 boolean beepIfNotEditable)
Utility routine which checks if the editor is editable, and beeps if it isn't (if requested.)

Parameters:
editor - the editor pane to check editability
beepIfNotEditable - request a beep if the editor is not editable

beep

public static void beep(BasicEditorPane editor)
Utility routine which just emits a beep. The editor pane has to be passed in because the getDefaultTookit() stuff is deprecated.

Parameters:
editor - the editor pane

getFontHeight

public static int getFontHeight(BasicEditorPane editor)
Utility routine which fetches the height of the current font of the editor.

Parameters:
editor - the editor pane
Returns:
the height of the editor font

getVisibleRect

public static java.awt.Rectangle getVisibleRect(BasicEditorPane editor)
Utility routine to fetch the current visible rectangle of the editor.

Parameters:
editor - the editor pane
Returns:
the visible rectangle for the editor

showMessage

public static void showMessage(BasicEditorPane editor,
                               java.lang.String message)
Utility routine to show a feedback message in the editor.

Parameters:
editor - the editor to show the message for
message - the message to display

getTabSizeProperty

public static int getTabSizeProperty(BasicEditorPane editor)
Utility routine to fetch the tab stop size for the given editor.

Parameters:
editor - the editor pane
Returns:
the tab size property for the editor

getUseAutoIndentProperty

public static boolean getUseAutoIndentProperty(BasicEditorPane editor)
Utility routine to fetch whether auto-indentation should be done for the given editor.

Parameters:
editor - the editor pane
Returns:
whether to use auto-indentation for the editor

getSmartIndentProvider

public static SmartIndentProvider getSmartIndentProvider(BasicEditorPane editor,
                                                         BasicDocument document)
Fetch the SmartIndentProvider for the current document. If it is not available, or smart indentations are off, then return null.

Parameters:
editor - the editor pane
document - the document being edited

getUseTabsProperty

public static boolean getUseTabsProperty(BasicEditorPane editor)
Utility routine to fetch whether a tab character should be used for the given editor.

Parameters:
editor - the editor pane
Returns:
the use tabs property for the editor

getTab

public static java.lang.String getTab(boolean useTabs,
                                      int tabSize)
Utility routine to fetch the tab or equivalent spaces to use. This is just for convenience, i.e., to build a String with a certain number of spaces.

Parameters:
useTabs - whether to use a tab character
tabSize - the size of the tab stop (if using spaces)
Returns:
a String that can be used as the tab character

buildIndent

public static java.lang.String buildIndent(boolean useTabs,
                                           int tabSize,
                                           int numColumns)
Utility routine to build a String that can be used to indent a line by a certain size (not necessarily a single indent.) This is used for example if the document does use tab characters and the user indents the line - we may need to convert spaces to tabs to do the right thing.

Parameters:
useTabs - whether to use tab characters
tabSize - the size of a tab stop
numColumns - the width of the indent in number of columns

skipLeadingIndent

public static int skipLeadingIndent(TextBuffer textBuffer,
                                    int lineStart,
                                    int lineEnd)
Utility routine to find the offset of the first character after the leading indent (if any), or -1 for an empty line or line containing only whitespace.

Parameters:
textBuffer - the text buffer to use
lineStart - the start of the line
lineEnd - the end of the line

getSpaces

public static java.lang.String getSpaces(int numSpaces)
Get a String with the specified number of space characters

Parameters:
numSpaces - the number of space characters
Returns:
a String with the number of space characters requested

getTabs

public static java.lang.String getTabs(int numTabs)
Get a String with the specified number of tab characters

Parameters:
numTabs - the number of tab characters
Returns:
a String with the number of tab characters requested

Extension SDK

 

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