コード例 #1
0
  public void testCreatesTheItemShopMenu() {
    ItemShop building = new ItemShop();
    building.stockItems(Item.BLOCKABALL, Item.HEALVIAL);
    JMenu menu = _constructor.createBuildingMenu(building, null);

    Assert.assertNotNull(menu);
    Assert.assertEquals(building.getName(), menu.getName());
    Assert.assertEquals(building.getName(), menu.getText());
    Assert.assertEquals(2, menu.getItemCount());
    for (int i = 0; i < menu.getItemCount(); i++) {
      JMenuItem menuItem = menu.getItem(i);
      Action action = menuItem.getAction();
      Assert.assertNotNull(action);
      Assert.assertEquals(ItemAction.class, action.getClass());

      String name = menuItem.getName();
      if (name.equals(Item.BLOCKABALL.toString())) {
        Assert.assertEquals(Item.BLOCKABALL.getWellFormattedString(), menuItem.getText());
      } else if (name.equals(Item.HEALVIAL.toString())) {
        Assert.assertEquals(Item.HEALVIAL.getWellFormattedString(), menuItem.getText());
      } else {
        Assert.fail("Name: " + name + " Text: " + menuItem.getText());
      }
    }
  }
コード例 #2
0
  public Integer getOrder() {
    getComponent()
        .getDocument()
        .getTransactionManager()
        .readAccess(
            new Runnable() {
              public void run() {
                targetComponent = new WeakReference<DesignComponent>(getTargetComponent());
              }
            });

    if (targetComponent == null)
      throw new IllegalStateException(getComponent() + " has no target component"); // NOI18N

    Collection<? extends ActionsPresenter> presenters =
        targetComponent.get().getPresenters(ActionsPresenter.class);

    for (ActionsPresenter presenter : presenters) {
      List<Action> pa = presenter.getActions();
      for (Action action : pa) {
        if (action == null) continue;

        if (actionToInherit == action.getClass()) {
          return presenter.getOrder();
        }
      }
    }

    return null;
  }
コード例 #3
0
ファイル: ServiceView4.java プロジェクト: brianm6/javatoolbox
  public void enforce() {

    logger_.error("xx", new Throwable("looky"));

    Set transitions = actions_.keySet();

    logger_.debug("Machine state = " + machine_.getState());

    for (Iterator i = transitions.iterator(); i.hasNext(); ) {
      ServiceTransition t = (ServiceTransition) i.next();
      logger_.debug("Transition = " + t);
      logger_.debug("Can trans  = " + machine_.canTransition(t));
      Action action = (Action) actions_.get(t);
      logger_.debug("Action clas= " + action.getClass().getName());

      action.setEnabled(machine_.canTransition(t));
    }

    //        for (Iterator i = ServiceTransition.iterator(); i.hasNext(); ) {
    //            ServiceTransition t = (ServiceTransition) i.next();
    //            Action action = (Action) actions_.get(t);
    //            action.setEnabled(machine_.canTransition(t));
    //
    //            // action = startAction
    //            // state = started
    //            // transition = initialize
    //
    //        }
  }
コード例 #4
0
ファイル: ToolbarPreferences.java プロジェクト: windu2b/josm
 /** @return The parameter (for better chaining) */
 public Action register(Action action) {
   String toolbar = (String) action.getValue("toolbar");
   if (toolbar == null) {
     System.out.println(
         tr("Registered toolbar action without name: {0}", action.getClass().getName()));
   } else {
     Action r = regactions.get(toolbar);
     if (r != null) {
       System.out.println(
           tr(
               "Registered toolbar action {0} overwritten: {1} gets {2}",
               toolbar, r.getClass().getName(), action.getClass().getName()));
     }
   }
   regactions.put(toolbar, action);
   return action;
 }
コード例 #5
0
ファイル: GUIUtilities.java プロジェクト: blickly/ptii
 /**
  * Add icons to an action. This method is used to associate icons with the different states:
  * unselected, rollover, rollover selected, selected etc.
  *
  * @param action The action to which the icons are added.
  * @param iconRoles A matrix of Strings, where each element consists of two Strings, the absolute
  *     URL of the icon and the key that represents the role of the icon. The keys are usually
  *     static fields from this class, such as {@link #LARGE_ICON}, {@link #ROLLOVER_ICON}, {@link
  *     #ROLLOVER_SELECTED_ICON} or {@link #SELECTED_ICON}.
  */
 public static void addIcons(Action action, String[][] iconRoles) {
   for (int i = 0; i < iconRoles.length; i++) {
     URL img = action.getClass().getResource(iconRoles[i][0]);
     if (img != null) {
       ImageIcon icon = new ImageIcon(img);
       action.putValue(iconRoles[i][1], icon);
     }
   }
 }
コード例 #6
0
ファイル: ToolbarPreferences.java プロジェクト: windu2b/josm
 private void loadAction(DefaultMutableTreeNode node, MenuElement menu) {
   Object userObject = null;
   MenuElement menuElement = menu;
   if (menu.getSubElements().length > 0 && menu.getSubElements()[0] instanceof JPopupMenu) {
     menuElement = menu.getSubElements()[0];
   }
   for (MenuElement item : menuElement.getSubElements()) {
     if (item instanceof JMenuItem) {
       JMenuItem menuItem = ((JMenuItem) item);
       if (menuItem.getAction() != null) {
         Action action = menuItem.getAction();
         userObject = action;
         Object tb = action.getValue("toolbar");
         if (tb == null) {
           System.out.println(tr("Toolbar action without name: {0}", action.getClass().getName()));
           continue;
         } else if (!(tb instanceof String)) {
           if (!(tb instanceof Boolean) || (Boolean) tb) {
             System.out.println(tr("Strange toolbar value: {0}", action.getClass().getName()));
           }
           continue;
         } else {
           String toolbar = (String) tb;
           Action r = actions.get(toolbar);
           if (r != null && r != action && !toolbar.startsWith("imagery_")) {
             System.out.println(
                 tr(
                     "Toolbar action {0} overwritten: {1} gets {2}",
                     toolbar, r.getClass().getName(), action.getClass().getName()));
           }
           actions.put(toolbar, action);
         }
       } else {
         userObject = menuItem.getText();
       }
     }
     DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObject);
     node.add(newNode);
     loadAction(newNode, item);
   }
 }
コード例 #7
0
  public void testCreatesOutOfBattleMenu() {
    JMenu menu = _constructor.createOutOfBattleMenu();

    assertNameAndText(menu, "OutOfBattle", "Actions");

    Assert.assertEquals(5, menu.getItemCount());

    assertNameAndText(menu.getItem(0), "Blockamon", "Blockamon");
    assertNameAndText(menu.getItem(1), "Bag", "Bag");
    assertNameAndText(menu.getItem(2), "Money", "Money");
    JMenuItem saveMenuItem = menu.getItem(3);
    Action saveMenuAction = saveMenuItem.getAction();
    Assert.assertNotNull(saveMenuAction);
    Assert.assertEquals(saveMenuAction.getClass(), SaveAction.class);
    assertNameAndText(saveMenuItem, "Save", "Save");
    assertNameAndText(menu.getItem(4), "Load", "Load");
  }
コード例 #8
0
  public void testCreatesTheHealingCenterMenu() {
    Building building = new HealingCenter();
    JMenu menu = _constructor.createBuildingMenu(building, null);

    Assert.assertNotNull(menu);
    Assert.assertEquals(building.getName(), menu.getName());
    Assert.assertEquals(building.getName(), menu.getText());
    Assert.assertEquals(1, menu.getItemCount());
    for (int i = 0; i < menu.getItemCount(); i++) {
      JMenuItem menuItem = menu.getItem(i);
      Action action = menuItem.getAction();
      Assert.assertNotNull(action);
      Assert.assertEquals(HealAction.class, action.getClass());

      Assert.assertEquals("Heal", menuItem.getName());
      Assert.assertEquals("Heal", menuItem.getText());
    }
  }
コード例 #9
0
ファイル: ToolBar.java プロジェクト: ieugen/squirrel-sql
 /**
  * Retrieve an icon from the passed action for the specified key.
  *
  * @param action Action to retrieve icon from.
  * @param key Key that specified the icon.
  * @return The requested Icon or null.
  */
 protected Icon getIconFromAction(Action action, String key) {
   // Object obj = action.getValue(BaseAction.IBaseActionPropertyNames.ROLLOVER_ICON);
   Object obj = action.getValue(key);
   if (obj != null) {
     if (obj instanceof Icon) {
       return (Icon) obj;
     }
     StringBuffer msg = new StringBuffer();
     msg.append("Non icon object of type ")
         .append(obj.getClass().getName())
         .append(" was stored in an Action of type ")
         .append(action.getClass().getName())
         .append(" using the key ")
         .append(key)
         .append(".");
     s_log.error(msg.toString());
   }
   return null;
 }
コード例 #10
0
  public List<Action> getActions() {
    getComponent()
        .getDocument()
        .getTransactionManager()
        .readAccess(
            new Runnable() {
              public void run() {
                targetComponent = new WeakReference<DesignComponent>(getTargetComponent());
              }
            });

    if (targetComponent == null)
      throw new IllegalStateException(getComponent() + " has no target component"); // NOI18N

    // Action[] allActions = ActionsSupport.createActionsArray(targetComponent.get());

    List<Action> filteredActions = null;
    // Fix for IZ#143558 - NullPointerException at
    // org.netbeans.modules.vmd.model.actions.ActionsPresenterForwarder.getActions
    if (targetComponent.get() == null) {
      return Collections.emptyList();
    }
    Collection<? extends ActionsPresenter> presenters =
        targetComponent.get().getPresenters(ActionsPresenter.class);
    for (ActionsPresenter presenter : presenters) {
      List<Action> pa = presenter.getActions();
      for (Action action : pa) {
        if (action == null) continue;

        if (actionToInherit == action.getClass()) {
          if (filteredActions == null) filteredActions = new ArrayList<Action>();
          filteredActions.add(action);
        }
      }
    }
    return filteredActions;
  }