예제 #1
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Opens a project.
   *
   * @param directory Where the project is stored.
   * @return the BProject that describes the newly opened project or null if it cannot be opened.
   */
  public final BProject openProject(File directory) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    // Yes somebody may just call it with null, for fun..
    if (directory == null) return null;

    Project openProj = Project.openProject(directory.getAbsolutePath(), null);
    if (openProj == null) return null;

    // a hack, since bluej does not handle "opening" of projects correctly.
    // this code should really be into openProject or it should not be possible to open
    // a project is the initial package name is not there.
    Package pkg = openProj.getCachedPackage(openProj.getInitialPackageName());
    if (pkg == null) return null;

    // I make a new identifier out of this
    Identifier aProject = new Identifier(openProj, pkg);

    // This will make the frame if not already there. should not be needed...
    try {
      aProject.getPackageFrame();
    } catch (ExtensionException exc) {
    }

    // Note: the previous Identifier is not used here.
    return openProj.getBProject();
  }
예제 #2
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Creates a new BlueJ project.
   *
   * @param directory where you want the project be placed, it must be writable.
   * @param projectType the type of project, such as ME or SE.
   * @return the newly created BProject if successful, null otherwise.
   */
  public BProject newProject(File directory, int projectType) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    String pathString = directory.getAbsolutePath();
    if (!pathString.endsWith(File.separator)) pathString += File.separator;

    if (!Project.createNewProject(pathString, projectType == ME_PROJECT)) return null;

    return openProject(directory);
  }
예제 #3
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Returns the language-dependent label with the given key. The search order is to look first in
   * the extension's <code>label</code> files and if the requested label is not found in the BlueJ
   * system <code>label</code> 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:
   *
   * <pre>
   * lib/english/label
   * lib/italian/label
   * lib/german/label
   * </pre>
   *
   * The files named <code>label</code> would contain the actual label key/value pairs.
   *
   * @param key Description of the Parameter
   * @return The label value
   */
  public String getLabel(String key) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    // If there are no label for this extension I can only return the system ones.
    if (localLabels == null) return Config.getString(key, key);

    // In theory there are label for this extension let me try to get them
    String aLabel = localLabels.getProperty(key, null);

    // Found what I wanted, job done.
    if (aLabel != null) return aLabel;

    // ok, the only hope is to get it from the system
    return Config.getString(key, key);
  }
예제 #4
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();
  }
예제 #5
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Returns all currently open projects. Returns an empty array if no projects are open.
   *
   * @return The openProjects value
   */
  public BProject[] getOpenProjects() {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    Collection projects = Project.getProjects();
    BProject[] result = new BProject[projects.size()];

    Iterator iter;
    int index;
    for (iter = projects.iterator(), index = 0; iter.hasNext(); index++) {
      Project prj = (Project) iter.next();
      result[index] = prj.getBProject();
    }

    return result;
  }
예제 #6
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * 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.
   *
   * @param property The name of the required global property
   * @param value the required value of that property.
   */
  public void setExtensionPropertyString(String property, String value) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    String thisKey = myWrapper.getSettingsString(property);
    Config.putPropString(thisKey, value);
  }
예제 #7
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Return a property associated with this extension from the standard BlueJ property repository.
   * You must use the setExtensionPropertyString to write any property that you want stored. You can
   * then come back and retrieve it using this function.
   *
   * @param property The name of the required global property.
   * @param def The default value to use if the property cannot be found.
   * @return the value of that property.
   */
  public String getExtensionPropertyString(String property, String def) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    String thisKey = myWrapper.getSettingsString(property);
    return Config.getPropString(thisKey, def);
  }
예제 #8
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Returns a property from BlueJ's properties, or the given default value if the property is not
   * currently set.
   *
   * @param property The name of the required global property
   * @param def The default value to use if the property cannot be found.
   * @return the value of the property.
   */
  public String getBlueJPropertyString(String property, String def) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    return Config.getPropString(property, def);
  }
예제 #9
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Returns the path of the user configuration directory. This can be used to locate user dependent
   * information. Having the directory you can then locate a file within it.
   *
   * @return The userConfigDir value
   */
  public File getUserConfigDir() {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    return Config.getUserConfigDir();
  }
예제 #10
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Returns the path of the <code>&lt;BLUEJ_HOME&gt;/lib</code> system directory. This can be used
   * to locate systemwide configuration files. Having the directory you can then locate a file
   * within it.
   *
   * @return The systemLibDir value
   */
  public File getSystemLibDir() {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    return Config.getBlueJLibDir();
  }
예제 #11
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Install a new preference panel for this extension. If you want to delete a previously installed
   * preference panel, then set it to null
   *
   * @param prefGen a class instance that implements the PreferenceGenerator interface.
   */
  public void setPreferenceGenerator(PreferenceGenerator prefGen) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    currentPrefGen = prefGen;
    prefManager.panelRevalidate();
  }
예제 #12
0
파일: BlueJ.java 프로젝트: tordf/Greenfoot
  /**
   * Install a new menu generator for this extension. If you want to delete a previously installed
   * menu, then set it to null
   *
   * @param menuGen The new menuGenerator value
   */
  public void setMenuGenerator(MenuGenerator menuGen) {
    if (!myWrapper.isValid()) throw new ExtensionUnloadedException();

    currentMenuGen = menuGen;
  }
예제 #13
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();
  }