Package bluej.extensions2
Class BPackage
- java.lang.Object
-
- bluej.extensions2.BPackage
-
public class BPackage extends java.lang.Object
A 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 void
compile(boolean waitCompileEnd)
Compiles all modified files of this package.void
compileAll(boolean waitCompileEnd)
Compiles all files of this package.BClass
getBClass(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.File
getDir()
Returns the directory where this package is stored.java.lang.String
getName()
Returns the name of the package.BObject
getObject(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.BProject
getProject()
Returns the package's project.javafx.stage.Stage
getWindow()
Returns the package window.BClass
newClass(java.lang.String className)
Creates a new Java class with the given name.BClass
newClass(java.lang.String className, SourceType sourceType)
Creates a new class with the given name for the given type.void
reload()
Reloads the entire package.void
remove()
Removes this package from BlueJ, including the underlying files.void
scheduleCompilation(boolean immediate)
Schedules a compilation of the package.java.lang.String
toString()
Returns a string representation of the package object
-
-
-
Method Detail
-
remove
public void remove() throws ProjectNotOpenException, PackageNotFoundException
Removes 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
BProject
object wrapping the package's project. - Throws:
ProjectNotOpenException
- if the project has been closed by the user.
-
getName
public java.lang.String getName() throws ProjectNotOpenException, PackageNotFoundException
Returns 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, PackageNotFoundException
Reloads the entire package. This is used (e.g.) when a new.java
file 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
BClass
object 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
- theSourceType
objecet describing the type of the class, eitherSourceType.Java
orSourceType.Stride
.- Returns:
- A
BClass
object 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, PackageNotFoundException
Returns the package window. This can be used (e.g.) as the "parent" frame for positioning modal dialogues.- Returns:
- A
Stage
object 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
BClass
object wrapping the class targeted withname
,null
if 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
BClass
objects 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
BObject
object wrapping the object targered byinstanceName
,null
if 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
BObject
objects 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, CompilationNotStartedException
Compiles all modified files of this package. A single CompileEvent with all modified files listed will be generated.- Parameters:
waitCompileEnd
-true
waits 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, CompilationNotStartedException
Compiles all files of this package. A single CompileEvent with all compiled files listed will be generated.- Parameters:
waitCompileEnd
-true
waits 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
BClass
objects 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
BObject
objects 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, PackageNotFoundException
Returns the directory where this package is stored.- Returns:
- A
File
object 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:
toString
in classjava.lang.Object
-
scheduleCompilation
public void scheduleCompilation(boolean immediate) throws ProjectNotOpenException, PackageNotFoundException
Schedules 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 recentscheduleCompilation
call. 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
-
-