Package bluej.extensions2
Class BPackage
- java.lang.Object
-
- bluej.extensions2.BPackage
-
public class BPackage extends java.lang.ObjectA wrapper for a single package of a BlueJ project. This represents an open package, and functions relating to that package.- Author:
- Clive Miller, University of Kent at Canterbury, 2002, Damiano Bolla, University of Kent at Canterbury, 2003
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcompile(boolean waitCompileEnd)Compiles all modified files of this package.voidcompileAll(boolean waitCompileEnd)Compiles all files of this package.BClassgetBClass(java.lang.String name)Returns the class with the given name in this package.BClass[]getClasses()Returns an array containing all the classes in this package.BClass[]getCurrentClasses()Returns the currently selected classes in this Package.BObject[]getCurrentObjects()Returns the currently selected objects in the object bench.java.io.FilegetDir()Returns the directory where this package is stored.java.lang.StringgetName()Returns the name of the package.BObjectgetObject(java.lang.String instanceName)Returns a wrapper for the object with the given name on BlueJ's object bench.BObject[]getObjects()Returns an array of all the Objects on the object bench.BProjectgetProject()Returns the package's project.javafx.stage.StagegetWindow()Returns the package window.BClassnewClass(java.lang.String className)Creates a new Java class with the given name.BClassnewClass(java.lang.String className, SourceType sourceType)Creates a new class with the given name for the given type.voidreload()Reloads the entire package.voidremove()Removes this package from BlueJ, including the underlying files.voidscheduleCompilation(boolean immediate)Schedules a compilation of the package.java.lang.StringtoString()Returns a string representation of the package object
-
-
-
Method Detail
-
remove
public void remove() throws ProjectNotOpenException, PackageNotFoundExceptionRemoves this package from BlueJ, including the underlying files.- Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
getProject
public BProject getProject() throws ProjectNotOpenException
Returns the package's project.- Returns:
- A
BProjectobject wrapping the package's project. - Throws:
ProjectNotOpenException- if the project has been closed by the user.
-
getName
public java.lang.String getName() throws ProjectNotOpenException, PackageNotFoundExceptionReturns the name of the package. Returns an empty string if no package name has been set.- Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
reload
public void reload() throws ProjectNotOpenException, PackageNotFoundExceptionReloads the entire package. This is used (e.g.) when a new.javafile has been added to the package.- Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
newClass
public BClass newClass(java.lang.String className) throws ProjectNotOpenException, PackageNotFoundException, MissingJavaFileException
Creates a new Java class with the given name. The class name must not be a fully qualified name, and the .java file must already exist.- Parameters:
className- the fully qualified name of the class to create.- Returns:
- A
BClassobject wrapping the created class. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.MissingJavaFileException- if the .java file for the new class does not exist.
-
newClass
public BClass newClass(java.lang.String className, SourceType sourceType) throws ProjectNotOpenException, PackageNotFoundException, MissingJavaFileException
Creates a new class with the given name for the given type. The class name must not be a fully qualified name, and the .java or .stride file must already exist.- Parameters:
className- the fully qualified name of the class to create.sourceType- theSourceTypeobjecet describing the type of the class, eitherSourceType.JavaorSourceType.Stride.- Returns:
- A
BClassobject wrapping the created class. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.MissingJavaFileException- if the .java file for the new class does not exist.
-
getWindow
public javafx.stage.Stage getWindow() throws ProjectNotOpenException, PackageNotFoundExceptionReturns the package window. This can be used (e.g.) as the "parent" frame for positioning modal dialogues.- Returns:
- A
Stageobject representing the window of the package wrapped by this BPackage. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
getBClass
public BClass getBClass(java.lang.String name) throws ProjectNotOpenException, PackageNotFoundException
Returns the class with the given name in this package. Note the naming inconsistency, which avoids a clash withjava.lang.Object.getClass()- Parameters:
name- the simple name of the required class.- Returns:
- A
BClassobject wrapping the class targeted withname,nullif the class name does not exist. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
getClasses
public BClass[] getClasses() throws ProjectNotOpenException, PackageNotFoundException
Returns an array containing all the classes in this package. If there are no classes an empty array will be returned.- Returns:
- An array of
BClassobjects wrapping the classes contained in this package. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
getObject
public BObject getObject(java.lang.String instanceName) throws ProjectNotOpenException, PackageNotFoundException
Returns a wrapper for the object with the given name on BlueJ's object bench.- Parameters:
instanceName- the name of the object as shown on the object bench.- Returns:
- A
BObjectobject wrapping the object targered byinstanceName,nullif no such object exists. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
getObjects
public BObject[] getObjects() throws ProjectNotOpenException, PackageNotFoundException
Returns an array of all the Objects on the object bench. The array will be empty if no objects are on the bench.- Returns:
- An array of
BObjectobjects wrapping the objects contained in the object bench. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
compile
public void compile(boolean waitCompileEnd) throws ProjectNotOpenException, PackageNotFoundException, CompilationNotStartedExceptionCompiles all modified files of this package. A single CompileEvent with all modified files listed will be generated.- Parameters:
waitCompileEnd-truewaits for the compilation to be finished.- Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.CompilationNotStartedException- if BlueJ is currently executing Java code.
-
compileAll
public void compileAll(boolean waitCompileEnd) throws ProjectNotOpenException, PackageNotFoundException, CompilationNotStartedExceptionCompiles all files of this package. A single CompileEvent with all compiled files listed will be generated.- Parameters:
waitCompileEnd-truewaits for the compilation to be finished.- Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.CompilationNotStartedException- if BlueJ is currently executing Java code.
-
getCurrentClasses
public BClass[] getCurrentClasses() throws ProjectNotOpenException, PackageNotFoundException
Returns the currently selected classes in this Package. If no class is selected an empty array is returned.- Returns:
- An array of
BClassobjects wrapping the classes selected in this package. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
getCurrentObjects
public BObject[] getCurrentObjects() throws ProjectNotOpenException, PackageNotFoundException
Returns the currently selected objects in the object bench. If no object is selected an empty array is returned.- Returns:
- An array of
BObjectobjects wrapping the objects selected in the object bench. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
getDir
public java.io.File getDir() throws ProjectNotOpenException, PackageNotFoundExceptionReturns the directory where this package is stored.- Returns:
- A
Fileobject representing the directory where this package is stored. - Throws:
ProjectNotOpenException- if the project this package is part of has been closed by the user.PackageNotFoundException- if the package has been deleted by the user.
-
toString
public java.lang.String toString()
Returns a string representation of the package object- Overrides:
toStringin classjava.lang.Object
-
scheduleCompilation
public void scheduleCompilation(boolean immediate) throws ProjectNotOpenException, PackageNotFoundExceptionSchedules a compilation of the package.- Parameters:
immediate- iftrue, compile now. Otherwise, wait for the default time (currently 1 second) then perform a compilation. Any other compilation requests from extensions or internally (e.g. due to code editing) will reset the timer to 1 second again, so the compilation will always occur 1 second after the call to the most recentscheduleCompilationcall. e.g. if this method is called every 900ms, compilation will never occur.- Throws:
ProjectNotOpenException- if the project has been closed by the userPackageNotFoundException- if the package has been deleted
-
-