Package bluej.extensions2
Class BlueJ
- java.lang.Object
-
- bluej.extensions2.BlueJ
-
public final class BlueJ extends java.lang.Object
A proxy object which provides services to BlueJ extensions. From this class an extension can obtain the projects and packages which BlueJ is currently displayng and the classes and objects they contain. Fields and methods of these objects can be inspected and invoked using an API based on Java's reflection API. Every effort has been made to retain the logic of the Reflection API and to provide methods that behave in a very similar way.BlueJ | +---- BProject | +---- BPackage | +--------- BClass | | +- BObject + BConstructor | | | +- BObject | +---- BMethod | | | +- BObject | +---- BField
Attempts to invoke methods on a BlueJ object made by an extension after itsterminate()
method has been called will result in an (unchecked)ExtensionUnloadedException
being thrown.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addApplicationListener(ApplicationListener listener)
Registers a listener for application events.void
addClassListener(ClassListener listener)
Registers a listener for class events.void
addCompileListener(CompileListener listener)
Registers a listener for compile events.void
addExtensionEventListener(ExtensionEventListener listener)
Registers a listener for all the events generated by BlueJ.void
addExternalFileLaunchers(java.util.List<ExternalFileLauncher> launchers)
Appends a list of ExternalFileLauncher objects in BlueJ's list of external file launchers.void
addInvocationFinishedListener(InvocationFinishedListener listener)
Registers a listener for invocation finished events.void
addPackageListener(PackageListener listener)
Registers a listener for package events.java.lang.String
getBlueJPropertyString(java.lang.String property, java.lang.String def)
Returns a property from BlueJ's properties.BPackage
getCurrentPackage()
Returns the current package.javafx.stage.Stage
getCurrentWindow()
Returns the current JavaFX Stage being displayed.java.lang.String
getDataCollectionUniqueID()
Returns the data-collection user ID.java.lang.String
getExtensionPropertyString(java.lang.String property, java.lang.String def)
Returns a property associated with this extension from the standard BlueJ property repository.java.lang.String
getLabel(java.lang.String key)
Returns the language-dependent label with the given key.MenuGenerator
getMenuGenerator()
Returns the currently registered menu generatorBProject[]
getOpenProjects()
Returns all currently open projects.PreferenceGenerator
getPreferenceGenerator()
Returns the currently registered preference generator.java.io.File
getSystemLibDir()
Returns the path of the<BLUEJ_HOME>/lib
system directory.java.io.File
getUserConfigDir()
Returns the path of the user configuration directory.BProject
newProject(java.io.File directory)
Creates a new BlueJ project.BProject
openProject(java.io.File directory)
Opens a BlueJ project.void
removeApplicationListener(ApplicationListener listener)
Removes the listener specified listener so that it no longer receives application events.void
removeClassListener(ClassListener listener)
Removes the specified class listener so no that it no longer receives class events.void
removeCompileListener(CompileListener listener)
Removes the specified listener so that it no longer receives compile events.void
removeExtensionEventListener(ExtensionEventListener listener)
Removes the specified listener so that it no longer receives events.void
removeInvocationFinishedListener(InvocationFinishedListener listener)
Removes the specified listener so no that it no longer receives invocation finished events.void
removePackageListener(PackageListener listener)
Removes the specified listener so that it no longer receives package events.void
setExtensionPropertyString(java.lang.String property, java.lang.String value)
Sets a property associated with this extension into the standard BlueJ property repository.void
setMenuGenerator(MenuGenerator menuGen)
Installs a new menu generator for this extension.void
setPreferenceGenerator(PreferenceGenerator prefGen)
Installs a new preference panel for this extension.void
setScopeHighlightStrength(int strength)
Sets the scope highlighting strength across all Java editors.
-
-
-
Method Detail
-
openProject
public final BProject openProject(java.io.File directory)
Opens a BlueJ project.- Parameters:
directory
- location where the project is stored.- Returns:
- A
BProject
that wraps the newly opened project, ornull
if it cannot be opened.
-
newProject
public BProject newProject(java.io.File directory)
Creates a new BlueJ project.- Parameters:
directory
- location where the project will be stored, it must be writable.- Returns:
- A
BProject
object wrapping the newly created project if successful,null
otherwise.
-
getOpenProjects
public BProject[] getOpenProjects()
Returns all currently open projects.- Returns:
- An array of
BProject
objects representing opened projects, empty array if no project are opened.
-
getCurrentPackage
public BPackage getCurrentPackage()
Returns the current package. The current package is the one that is currently selected by the user interface.- Returns:
- A
BPackage
object wrapping the current package,null
if there is no currently open package.
-
getCurrentWindow
public javafx.stage.Stage getCurrentWindow()
Returns the current JavaFX Stage being displayed. Can be used (e.g.) as a "parent" frame for positioning modal dialogs. If there is a package currently open, it's probably better to use itsBPackage.getWindow()
method to provide better placement.- Returns:
- A
Stage
object representing the current JavaFX Stage object
-
setMenuGenerator
public void setMenuGenerator(MenuGenerator menuGen)
Installs a new menu generator for this extension.- Parameters:
menuGen
- a newMenuGenerator
,null
to delete a previously installed menu.
-
getMenuGenerator
public MenuGenerator getMenuGenerator()
Returns the currently registered menu generator
-
setPreferenceGenerator
public void setPreferenceGenerator(PreferenceGenerator prefGen)
Installs a new preference panel for this extension.- Parameters:
prefGen
- a class instance that implements thePreferenceGenerator
interface,null
to delete a previously installed preference panel.
-
getPreferenceGenerator
public PreferenceGenerator getPreferenceGenerator()
Returns the currently registered preference generator.
-
addExternalFileLaunchers
public final void addExternalFileLaunchers(java.util.List<ExternalFileLauncher> launchers)
Appends a list of ExternalFileLauncher objects in BlueJ's list of external file launchers. This method must be called withinExtension.startup(BlueJ)
for BlueJ to be able to retrieve the launcher(s). Calling it anywhere else will produce no effect in BlueJ. Adding launchers will not replace previously added launchers by the extension. Note that for a same external file type, the last extension loaded by BlueJ will overwrite a previously register launcher. Therefore, there is no guarantee that this extension's launcher will not be overwritten by another extension..- Parameters:
launchers
- a list ofExternalFileLauncher
to be registered in BlueJ.
-
getSystemLibDir
public java.io.File getSystemLibDir()
Returns the path of the<BLUEJ_HOME>/lib
system directory. This can be used to locate system-wide configuration files. A file can then be located within this directory.
-
getUserConfigDir
public java.io.File getUserConfigDir()
Returns the path of the user configuration directory. This can be used to locate user dependent information. A file can then be located within this directory.
-
getDataCollectionUniqueID
public java.lang.String getDataCollectionUniqueID()
Returns the data-collection user ID. Used by extensions that aim to augment the BlueJ data collection project.- Returns:
- the user ID, as read from the properties file.
-
getBlueJPropertyString
public java.lang.String getBlueJPropertyString(java.lang.String property, java.lang.String def)
Returns a property from BlueJ's properties.- Parameters:
property
- the name of the required global propertydef
- the default value to use if the property cannot be found.- Returns:
- The requested property's value, or the default value if the property is not currently set.
-
getExtensionPropertyString
public java.lang.String getExtensionPropertyString(java.lang.String property, java.lang.String def)
Returns a property associated with this extension from the standard BlueJ property repository. Extensions must usesetExtensionPropertyString(String, String)
to write any property that should be stored.- Parameters:
property
- the name of the required global property.def
- the default value to use if the property cannot be found.- Returns:
- The value of that property, or the default value if the property is not currently set.
-
setExtensionPropertyString
public void setExtensionPropertyString(java.lang.String property, java.lang.String value)
Sets a property associated with this extension into the standard BlueJ property repository. The property name does not need to be fully qualified since a prefix will be prepended to it.- Parameters:
property
- the name of the required global propertyvalue
- the required value of that property (or null to remove the property)
-
getLabel
public java.lang.String getLabel(java.lang.String key)
Returns the language-dependent label with the given key. The search order is to look first in the extension'slabel
files and if the requested label is not found in the BlueJ systemlabel
files. Extensions' labels are stored in a Property format and must be jarred together with the extension. The path searched is equivalent to the bluej/lib/[language] style used for the BlueJ system labels. E.g. to create a set of labels which can be used by English, Italian and German users of an extension, the following files would need to be present in the extension's Jar file:lib/english/label lib/italian/label lib/german/label
The files namedlabel
would contain the actual label key/value pairs.- Parameters:
key
- the name of the required label- Returns:
- The label value.
-
addExtensionEventListener
public void addExtensionEventListener(ExtensionEventListener listener)
Registers a listener for all the events generated by BlueJ.- Parameters:
listener
- anExtensionEventListener
object to register.
-
removeExtensionEventListener
public void removeExtensionEventListener(ExtensionEventListener listener)
Removes the specified listener so that it no longer receives events.- Parameters:
listener
- anExtensionEventListener
object to unregister.
-
addApplicationListener
public void addApplicationListener(ApplicationListener listener)
Registers a listener for application events.- Parameters:
listener
- anApplicationListener
object to register.
-
removeApplicationListener
public void removeApplicationListener(ApplicationListener listener)
Removes the listener specified listener so that it no longer receives application events.- Parameters:
listener
- anApplicationListener
object to unregister.
-
addPackageListener
public void addPackageListener(PackageListener listener)
Registers a listener for package events.- Parameters:
listener
- anPackageListener
object to register.
-
removePackageListener
public void removePackageListener(PackageListener listener)
Removes the specified listener so that it no longer receives package events.- Parameters:
listener
- anPackageListener
object to unregister.
-
addCompileListener
public void addCompileListener(CompileListener listener)
Registers a listener for compile events.- Parameters:
listener
- anCompileListener
object to register.
-
removeCompileListener
public void removeCompileListener(CompileListener listener)
Removes the specified listener so that it no longer receives compile events.- Parameters:
listener
- anCompileListener
object to unregister.
-
addInvocationFinishedListener
public void addInvocationFinishedListener(InvocationFinishedListener listener)
Registers a listener for invocation finished events.- Parameters:
listener
- anInvocationFinishedListener
object to register.
-
removeInvocationFinishedListener
public void removeInvocationFinishedListener(InvocationFinishedListener listener)
Removes the specified listener so no that it no longer receives invocation finished events.- Parameters:
listener
- anInvocationFinishedListener
object to unregister.
-
addClassListener
public void addClassListener(ClassListener listener)
Registers a listener for class events.- Parameters:
listener
- anClassListener
object to register.
-
removeClassListener
public void removeClassListener(ClassListener listener)
Removes the specified class listener so no that it no longer receives class events.- Parameters:
listener
- anClassListener
object to unregister.
-
setScopeHighlightStrength
public void setScopeHighlightStrength(int strength)
Sets the scope highlighting strength across all Java editors. This is how opaque or transparent the coloured boxes are that appear for classes, methods, control flow constructs, etc. *- Parameters:
strength
- The highlighting strength: 0 means off, 20 means full, and then it's a sliding scale inbetween.- Since:
- Extension API 3.2 (BlueJ 5.0.2)
-
-