Пример #1
0
  /**
   * 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
  /**
   * 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
  /**
   * 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
  /**
   * 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
  /**
   * 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
  /**
   * Constructor for a BlueJ proxy object. See the ExtensionBridge class
   *
   * @param aWrapper Description of the Parameter
   * @param aPrefManager Description of the Parameter
   */
  BlueJ(ExtensionWrapper aWrapper, ExtensionPrefManager aPrefManager) {
    myWrapper = aWrapper;
    prefManager = aPrefManager;

    eventListeners = new ArrayList();
    applicationListeners = new ArrayList();
    packageListeners = new ArrayList();
    compileListeners = new ArrayList();
    invocationListeners = new ArrayList();
    classListeners = new ArrayList();

    /* I do NOT want lazy initialization otherwise I may try to load it
     * may times just because I cannof find anything.
     * Or having state variables to know I I did load it but had nothing found
     */
    localLabels = myWrapper.getLabelProperties();
  }
Пример #7
0
  /**
   * 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);
  }
Пример #8
0
  /**
   * 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);
  }
Пример #9
0
  /**
   * 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);
  }
Пример #10
0
  /**
   * 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();
  }
Пример #11
0
  /**
   * 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();
  }
Пример #12
0
  /**
   * 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();
  }
Пример #13
0
  /**
   * 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;
  }
Пример #14
0
  /**
   * 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();
  }