public final class EditorContextDispatcher extends Object
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.
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.Modifier and Type | Field and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
Set<String> |
getMIMETypesOnCurrentLine()
Get a list of MIME types of languages found on the current line.
|
Set<String> |
getMIMETypesOnLine(Line line)
Get a list of MIME types of languages found on a line.
|
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.
|
public static final String PROP_FILE
public static final String PROP_EDITOR
public static EditorContextDispatcher getDefault()
public FileObject getCurrentFile()
null
when there is no active file.public String getCurrentURLAsString()
public JEditorPane getCurrentEditor()
JEditorPane
of currently edited file.JEditorPane
or
null
when there is no currently edited file.public int getCurrentLineNumber()
-1
when there is no current editor.public Line getCurrentLine()
null
when there is no current editor.public Set<String> getMIMETypesOnCurrentLine()
public Set<String> getMIMETypesOnLine(Line line)
line
- The line to search for the MIME types.public FileObject getMostRecentFile()
null
when there was no recent
active file.public String getMostRecentURLAsString()
public JEditorPane getMostRecentEditor()
public int getMostRecentLineNumber()
-1
when there was no recent active editor.public Line getMostRecentLine()
null
when there was no recent active editor.public void addPropertyChangeListener(PropertyChangeListener l)
EditorContextDispatcher.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
instead, if possible, for performance reasons.l
- The PropertyChangeListenerpublic void removePropertyChangeListener(PropertyChangeListener l)
l
- The PropertyChangeListenerpublic void addPropertyChangeListener(String MIMEType, PropertyChangeListener l)
MIMEType
- The MIME type to report changes forl
- The PropertyChangeListener