コード例 #1
0
ファイル: BlueJ.java プロジェクト: tordf/Greenfoot
  /** Post a notification of a menu going to be display */
  void postMenuItem(Object attachedObject, JMenuItem onThisItem) {
    if (currentMenuGen == null) return;

    if (attachedObject == null) {
      // Only BPackages can be null when a menu is invoked
      currentMenuGen.notifyPostToolsMenu(null, onThisItem);
      return;
    }

    if (attachedObject instanceof Package) {
      Package attachedPkg = (Package) attachedObject;
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg);
      currentMenuGen.notifyPostToolsMenu(new BPackage(anId), onThisItem);
    }

    if (attachedObject instanceof ClassTarget) {
      ClassTarget aTarget = (ClassTarget) attachedObject;
      String qualifiedClassName = aTarget.getQualifiedName();
      Package attachedPkg = aTarget.getPackage();
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg, qualifiedClassName);
      currentMenuGen.notifyPostClassMenu(new BClass(anId), onThisItem);
    }

    if (attachedObject instanceof ObjectWrapper) {
      ObjectWrapper aWrapper = (ObjectWrapper) attachedObject;
      currentMenuGen.notifyPostObjectMenu(new BObject(aWrapper), onThisItem);
    }
  }
コード例 #2
0
ファイル: BlueJ.java プロジェクト: tordf/Greenfoot
  /**
   * Calls the extension to get the right menu item. This is already wrapped for errors in the
   * caller. It is right for it to create a new wrapped object each time. We do not want extensions
   * to share objects. It is here since it can access all constructors directly.
   *
   * @param attachedObject Description of the Parameter
   * @return The menuItem value
   */
  JMenuItem getMenuItem(Object attachedObject) {
    if (currentMenuGen == null) return null;

    if (attachedObject == null) {
      JMenuItem anItem = currentMenuGen.getToolsMenuItem(null);
      if (anItem != null) return anItem;

      // Try to use the old deprecated method.
      return currentMenuGen.getMenuItem();
    }

    if (attachedObject instanceof Package) {
      Package attachedPkg = (Package) attachedObject;
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg);
      return currentMenuGen.getToolsMenuItem(new BPackage(anId));
    }

    if (attachedObject instanceof ClassTarget) {
      ClassTarget aTarget = (ClassTarget) attachedObject;
      String qualifiedClassName = aTarget.getQualifiedName();
      Package attachedPkg = aTarget.getPackage();
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg, qualifiedClassName);
      return currentMenuGen.getClassMenuItem(new BClass(anId));
    }

    if (attachedObject instanceof ObjectWrapper) {
      ObjectWrapper aWrapper = (ObjectWrapper) attachedObject;
      return currentMenuGen.getObjectMenuItem(new BObject(aWrapper));
    }

    return null;
  }