org.netbeans.spi.debugger.ui/1 2.27.1

org.netbeans.spi.debugger.ui
Class EditorContextDispatcher

java.lang.Object
  extended by org.netbeans.spi.debugger.ui.EditorContextDispatcher

public final class EditorContextDispatcher
extends Object

Dispatcher of context-related events and provider of active elements in the IDE.

This class tracks the changes of the selected file and active editor and re-fires the changes to registered listeners. The listeners can register based on a MIME type of files which they are interested in. This prevents from unnecessary activity of debugging actions when the context is switched among unrelated files.

The EditorContextDispatcher provides convenient access to currently selected elements and recently selected elements in the GUI.

Typical usage:

Attach a listener based on file MIME type. The usage of WeakListeners is preferred, unless the listener can be removed explicitely.
  EditorContextDispatcher.getDefault().addPropertyChangeListener("<MIME type>",
              WeakListeners.propertyChange(dispatchListener, EditorContextDispatcher.getDefault()));
 
Then use getCurrent*() methods to find the currently selected elements in the IDE. If recently selected elements are desired, use getMostRecent*() methods. They provide current elements if available, or elements that were current the last time.

Since:
2.13

Field Summary
static String PROP_EDITOR
          Name of property fired when the current editor changes.
static String PROP_FILE
          Name of property fired when the current file changes.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Add a PropertyChangeListener to this context dispatcher.
 void addPropertyChangeListener(String MIMEType, PropertyChangeListener l)
          Add a PropertyChangeListener to this context dispatcher to be notified about changes of files with a specified MIME type.
 JEditorPane getCurrentEditor()
          Get the JEditorPane of currently edited file.
 FileObject getCurrentFile()
          Get the current active file.
 Line getCurrentLine()
          Get the line of the caret in the current editor.
 int getCurrentLineNumber()
          Get the line number of the caret in the current editor.
 String getCurrentURLAsString()
          Get the String representation of URL of the current active file.
static EditorContextDispatcher getDefault()
          Get the default instance of EditorContextDispatcher.
 JEditorPane getMostRecentEditor()
           
 FileObject getMostRecentFile()
          Get the most recent active file.
 Line getMostRecentLine()
          Get the line of the caret in the most recent editor.
 int getMostRecentLineNumber()
          Get the line number of the caret in the most recent editor.
 String getMostRecentURLAsString()
          Get the String representation of URL of the most recent active file.
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove a PropertyChangeListener from this context dispatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_FILE

public static final String PROP_FILE
Name of property fired when the current file changes.

See Also:
Constant Field Values

PROP_EDITOR

public static final String PROP_EDITOR
Name of property fired when the current editor changes.

See Also:
Constant Field Values
Method Detail

getDefault

public static EditorContextDispatcher getDefault()
Get the default instance of EditorContextDispatcher.

Returns:
The EditorContextDispatcher

getCurrentFile

public FileObject getCurrentFile()
Get the current active file.

Returns:
The current file or null when there is no active file.

getCurrentURLAsString

public String getCurrentURLAsString()
Get the String representation of URL of the current active file.

Returns:
The String representation of URL of the current active file or an empty String when there is no active file.

getCurrentEditor

public JEditorPane getCurrentEditor()
Get the JEditorPane of currently edited file.

Returns:
The current JEditorPane or null when there is no currently edited file.

getCurrentLineNumber

public int getCurrentLineNumber()
Get the line number of the caret in the current editor.

Returns:
the line number or -1 when there is no current editor.

getCurrentLine

public Line getCurrentLine()
Get the line of the caret in the current editor.

Returns:
the line or null when there is no current editor.

getMostRecentFile

public FileObject getMostRecentFile()
Get the most recent active file. This returns the active file if there's one, or a file, that was most recently active.

Returns:
The most recent file or null when there was no recent active file.

getMostRecentURLAsString

public String getMostRecentURLAsString()
Get the String representation of URL of the most recent active file.

Returns:
The String representation of URL of the most recent file or an empty String when there was no recent active file.

getMostRecentEditor

public JEditorPane getMostRecentEditor()

getMostRecentLineNumber

public int getMostRecentLineNumber()
Get the line number of the caret in the most recent editor. This returns the current line number in the current editor if there's one, or a line number of the caret in the editor, that was most recently active.

Returns:
the line number or -1 when there was no recent active editor.

getMostRecentLine

public Line getMostRecentLine()
Get the line of the caret in the most recent editor. This returns the current line in the current editor if there's one, or a line of the caret in the editor, that was most recently active.

Returns:
the line or null when there was no recent active editor.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Add a PropertyChangeListener to this context dispatcher. It's strongly suggested to use addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) instead, if possible, for performance reasons.

Parameters:
l - The PropertyChangeListener

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Remove a PropertyChangeListener from this context dispatcher.

Parameters:
l - The PropertyChangeListener

addPropertyChangeListener

public void addPropertyChangeListener(String MIMEType,
                                      PropertyChangeListener l)
Add a PropertyChangeListener to this context dispatcher to be notified about changes of files with a specified MIME type.

Parameters:
MIMEType - The MIME type to report changes for
l - The PropertyChangeListener

org.netbeans.spi.debugger.ui/1 2.27.1

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.