bluej.extensions
Class BPackage

java.lang.Object
  extended by bluej.extensions.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
 void compile(boolean waitCompileEnd)
          Compile all modified files of this package.
 void compileAll(boolean waitCompileEnd)
          Compile 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.awt.Frame getFrame()
          Returns the package frame.
 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.
 BClass newClass(java.lang.String className)
          Creates a new Class with the given name.
 void reload()
          Reloads the entire package.
 void remove()
          Removes this package from BlueJ, including the underlying files.
 java.lang.String toString()
          Returns a string representation of the package object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.

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 Class with the given name. The class name must not be a fully qualified name, and the .java file must already 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.
MissingJavaFileException - if the .java file for the new class does not exist.

getFrame

public java.awt.Frame getFrame()
                        throws ProjectNotOpenException,
                               PackageNotFoundException
Returns the package frame. This can be used (e.g.) as the "parent" frame for positioning modal dialogues.

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. Returns null if the class name does not exist. Note the naming inconsistency, which avoids a clash with java.lang.Object.getClass()

Parameters:
name - the simple name of the required 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.

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.

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:
the object, or 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.

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
Compile 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
Compile 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.

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.

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.

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 class java.lang.Object


BlueJ homepage