コード例 #1
0
  /**
   * Adds this object on the object bench. If you pass null as instanceName the object will have a
   * predefined name. If the object is not a valid one nothing will happen.
   *
   * @param instanceName The name you want this object to have on the bench.
   * @throws ProjectNotOpenException if the project to which this object belongs has been closed by
   *     the user.
   * @throws PackageNotFoundException if the package to which this object belongs has been deleted
   *     by the user.
   */
  public void addToBench(String instanceName)
      throws ProjectNotOpenException, PackageNotFoundException {
    if (objectWrapper == null) {
      return;
    }

    // Not rational to add a null object, is it ?
    if (objectWrapper.getObject().isNullObject()) {
      return;
    }

    // If you want you may set the instance name here. Otherwise accept default
    if (instanceName != null) {
      objectWrapper.setName(instanceName);
    }

    // This should really always exists, no need to check
    Package aPackage = wrapperId.getBluejPackage();
    PkgMgrFrame aFrame = wrapperId.getPackageFrame();

    ObjectBench aBench = aFrame.getObjectBench();
    aBench.addObject(objectWrapper);

    // load the object into runtime scope
    aPackage
        .getDebugger()
        .addObject(aPackage.getId(), objectWrapper.getName(), objectWrapper.getObject());
  }
コード例 #2
0
  /**
   * Removes this object from the object bench. This will also remove it from the view of the object
   * bench. Once the object is removed from the bench it will not be available again.
   *
   * @throws ProjectNotOpenException if the project to which this object belongs has been closed by
   *     the user.
   * @throws PackageNotFoundException if the package to which this object belongs has been deleted
   *     by the user.
   */
  public void removeFromBench() throws ProjectNotOpenException, PackageNotFoundException {
    Package aPackage = wrapperId.getBluejPackage();
    PkgMgrFrame aFrame = wrapperId.getPackageFrame();

    ObjectBench aBench = aFrame.getObjectBench();
    aBench.removeObject(objectWrapper, aPackage.getId());

    objectWrapper = null;
  }
コード例 #3
0
ファイル: BlueJ.java プロジェクト: tordf/Greenfoot
  /**
   * Returns the currently selected package. The current package is the one that is currently
   * selected by the user interface. It can return null if there is no currently open package.
   *
   * @return The currentPackage value
   */
  public BPackage getCurrentPackage() {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    // This is here and NOT into a BProject since it depends on user interface.

    PkgMgrFrame pmf = PkgMgrFrame.getMostRecent();
    // If there is nothing at all open there is no Frame open...
    if (pmf == null) return null;

    Package pkg = pmf.getPackage();
    // The frame may be there BUT have no package.
    if (pkg == null) return null;

    return pkg.getBPackage();
  }
コード例 #4
0
ファイル: BlueJ.java プロジェクト: tordf/Greenfoot
  /**
   * Returns the current frame 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
   * its <code>getFrame()</code> method to provide better placement.
   *
   * @return The currentFrame value
   */
  public Frame getCurrentFrame() {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    return PkgMgrFrame.getMostRecent();
  }