Пример #1
0
  public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() instanceof JMenuItem) {
      JMenuItem src = (JMenuItem) ae.getSource();

      if (src.getName().equals("exit")) {
        cleanExit();
        return;
      }

      runPlugin(src.getName());
    } else runPlugin(MAIN_INTERFACE);
  }
  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());
      }
    }
  }
Пример #3
0
  /**
   * Handles the <tt>ActionEvent</tt> when one of the menu items is selected.
   *
   * @param e the <tt>ActionEvent</tt> that notified us
   */
  public void actionPerformed(ActionEvent e) {
    JMenuItem menuItem = (JMenuItem) e.getSource();
    String itemText = menuItem.getName();

    if (itemText.equalsIgnoreCase("myChatRooms")) {
      ChatRoomTableDialog.showChatRoomTableDialog();
    } else if (itemText.equals("history")) {
      HistoryWindow history;

      HistoryWindowManager historyWindowManager =
          GuiActivator.getUIService().getHistoryWindowManager();

      ChatPanel chatPanel = this.parentWindow.getCurrentChatPanel();
      ChatSession chatSession = chatPanel.getChatSession();

      if (historyWindowManager.containsHistoryWindowForContact(chatSession.getDescriptor())) {
        history = historyWindowManager.getHistoryWindowForContact(chatSession.getDescriptor());

        if (history.getState() == JFrame.ICONIFIED) history.setState(JFrame.NORMAL);

        history.toFront();
      } else {
        history = new HistoryWindow(chatPanel.getChatSession().getDescriptor());

        history.setVisible(true);

        historyWindowManager.addHistoryWindowForContact(chatSession.getDescriptor(), history);
      }
    } else if (itemText.equalsIgnoreCase("close")) {
      this.parentWindow.setVisible(false);
      this.parentWindow.dispose();
    }
  }
 private JMenuItem getWithName(JMenu menu, String name) {
   int numOfItems = menu.getItemCount();
   JMenuItem menuItem = null;
   for (int i = 0; i < numOfItems; i++) {
     JMenuItem item = menu.getItem(i);
     if (item == null) {
       continue;
     }
     if (item.getName() == null) {
       continue;
     }
     if (item.getName().equals(name)) {
       menuItem = item;
       i = numOfItems;
     }
   }
   return menuItem;
 }
Пример #5
0
 /**
  * Finds the insert position of the given <code>command</command> within the <code>popupMenu</code>.
  *
  * @param popupMenu The popup menu.
  * @param command The command to insert.
  * @param manager The command manager.
  */
 public static int findMenuInsertPosition(
     final JPopupMenu popupMenu, final Command command, final CommandManager manager) {
   int pbi = popupMenu.getComponentCount();
   String placeBefore = command.getPlaceBefore();
   if (placeBefore != null) {
     pbi = UIUtils.findMenuItemPosition(popupMenu, placeBefore);
   }
   int pai = -1;
   String placeAfter = command.getPlaceAfter();
   if (placeAfter != null) {
     pai = UIUtils.findMenuItemPosition(popupMenu, placeAfter) + 1;
   }
   final int componentCount = popupMenu.getComponentCount();
   for (int i = 0; i < componentCount; i++) {
     final Component component = popupMenu.getComponent(i);
     if (!(component instanceof JMenuItem)) {
       continue;
     }
     final JMenuItem item = (JMenuItem) component;
     final String name = item.getName();
     final Command menuCommand = manager.getCommand(name);
     if (menuCommand == null) {
       continue;
     }
     placeBefore = menuCommand.getPlaceBefore();
     if (command.getCommandID().equals(placeBefore)) {
       if (pbi > i) {
         pbi = i + 1;
       }
     }
     placeAfter = menuCommand.getPlaceAfter();
     if (command.getCommandID().equals(placeAfter)) {
       if (pai < i) {
         pai = i;
       }
     }
   }
   int insertPos = -1;
   if (pbi >= pai) {
     insertPos = pai;
   }
   if (insertPos == -1) {
     insertPos = popupMenu.getComponentCount();
   }
   return insertPos;
 }
  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());
    }
  }
Пример #7
0
 private static Command[] getCommands(
     final JPopupMenu popupMenu, final CommandManager manager, final Command command) {
   final List<Command> commands = new ArrayList<Command>();
   final int count = popupMenu.getComponentCount();
   for (int i = 0; i < count; i++) {
     final Component component = popupMenu.getComponent(i);
     if (!(component instanceof JMenuItem)) {
       continue;
     }
     final JMenuItem item = (JMenuItem) component;
     final String name = item.getName();
     final Command menuCommand = manager.getCommand(name);
     if (menuCommand != null) {
       commands.add(menuCommand);
     }
   }
   commands.add(command);
   return commands.toArray(new Command[commands.size()]);
 }
  /**
   * Handles the <tt>ActionEvent</tt>. Determines which menu item was selected and makes the
   * appropriate operations.
   *
   * @param e the event.
   */
  public void actionPerformed(ActionEvent e) {
    JMenuItem menuItem = (JMenuItem) e.getSource();
    String itemName = menuItem.getName();

    ConferenceChatManager conferenceManager =
        GuiActivator.getUIService().getConferenceChatManager();

    if (itemName.equals("removeChatRoom")) {
      conferenceManager.removeChatRoom(chatRoomWrapper);
    } else if (itemName.equals("leaveChatRoom")) {
      conferenceManager.leaveChatRoom(chatRoomWrapper);
    } else if (itemName.equals("joinChatRoom")) {
      conferenceManager.joinChatRoom(chatRoomWrapper);
    } else if (itemName.equals("openChatRoom")) {
      if (chatRoomWrapper.getChatRoom() != null) {
        if (!chatRoomWrapper.getChatRoom().isJoined()) {
          conferenceManager.joinChatRoom(chatRoomWrapper);
        }
      } else {
        // this is not a server persistent room we must create it
        // and join
        chatRoomWrapper =
            GuiActivator.getUIService()
                .getConferenceChatManager()
                .createChatRoom(
                    chatRoomWrapper.getChatRoomName(),
                    chatRoomWrapper.getParentProvider().getProtocolProvider(),
                    new ArrayList<String>(),
                    "",
                    true,
                    true);
      }

      ChatWindowManager chatWindowManager = GuiActivator.getUIService().getChatWindowManager();
      ChatPanel chatPanel = chatWindowManager.getMultiChat(chatRoomWrapper, true);

      chatWindowManager.openChat(chatPanel, true);
    } else if (itemName.equals("joinAsChatRoom")) {
      ChatRoomAuthenticationWindow authWindow = new ChatRoomAuthenticationWindow(chatRoomWrapper);

      authWindow.setVisible(true);
    }
  }
 private void activateMenu(ActionEvent event) {
   int width = 0;
   int height = 0;
   MinesweeperModel newModel = null;
   JMenuItem jMenuItem = (JMenuItem) event.getSource();
   String nameJMenuItem = jMenuItem.getName();
   if (nameJMenuItem.equals("Новичок")) {
     model = new MinesweeperModel(8, 8, 10);
     width = 400;
     height = 400;
   }
   if (nameJMenuItem.equals("Любитель")) {
     model = new MinesweeperModel(16, 16, 40);
     width = 600;
     height = 500;
   }
   if (nameJMenuItem.equals("Профессионал")) {
     model = new MinesweeperModel(16, 30, 99);
     width = 800;
     height = 800;
   }
   setSize(width, height);
   createNewField();
 }
 private void assertNameAndText(JMenuItem menuItem, String name, String text) {
   Assert.assertEquals("Name of menu item is " + name, name, menuItem.getName());
   Assert.assertEquals("Text of menu item is " + text, text, menuItem.getText());
 }
Пример #11
0
 /** Get the recent file for the menu item */
 private File getRecentFile(ActionEvent e) {
   JMenuItem menuItem = (JMenuItem) e.getSource();
   // Get the preference for the recent files
   return new File(getRecentFile(Integer.parseInt(menuItem.getName())));
 }
Пример #12
0
  /**
   * Handles the <tt>ActionEvent</tt>. Determines which menu item was selected and makes the
   * appropriate operations.
   *
   * @param e the event.
   */
  public void actionPerformed(ActionEvent e) {
    JMenuItem menuItem = (JMenuItem) e.getSource();
    String itemName = menuItem.getName();

    ConferenceChatManager conferenceManager =
        GuiActivator.getUIService().getConferenceChatManager();

    if (itemName.equals("removeChatRoom")) {
      conferenceManager.removeChatRoom(chatRoomWrapper);
    } else if (itemName.equals("leaveChatRoom")) {
      conferenceManager.leaveChatRoom(chatRoomWrapper);
    } else if (itemName.equals("joinChatRoom")) {
      String nickName = null;

      nickName =
          ConfigurationManager.getChatRoomProperty(
              chatRoomWrapper.getParentProvider().getProtocolProvider(),
              chatRoomWrapper.getChatRoomID(),
              "userNickName");
      if (nickName == null) nickName = getNickname();

      if (nickName != null) conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null);
      else conferenceManager.joinChatRoom(chatRoomWrapper);
    } else if (itemName.equals("openChatRoom")) {
      if (chatRoomWrapper.getChatRoom() != null) {
        if (!chatRoomWrapper.getChatRoom().isJoined()) {
          String nickName = null;

          nickName =
              ConfigurationManager.getChatRoomProperty(
                  chatRoomWrapper.getParentProvider().getProtocolProvider(),
                  chatRoomWrapper.getChatRoomID(),
                  "userNickName");
          if (nickName == null) nickName = getNickname();

          if (nickName != null) conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null);
          else conferenceManager.joinChatRoom(chatRoomWrapper);
        }
      } else {
        // this is not a server persistent room we must create it
        // and join
        chatRoomWrapper =
            GuiActivator.getUIService()
                .getConferenceChatManager()
                .createChatRoom(
                    chatRoomWrapper.getChatRoomName(),
                    chatRoomWrapper.getParentProvider().getProtocolProvider(),
                    new ArrayList<String>(),
                    "",
                    false,
                    true);

        String nickName = null;

        nickName =
            ConfigurationManager.getChatRoomProperty(
                chatRoomWrapper.getParentProvider().getProtocolProvider(),
                chatRoomWrapper.getChatRoomID(),
                "userNickName");

        if (nickName == null) nickName = getNickname();

        if (nickName != null) conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null);
        else conferenceManager.joinChatRoom(chatRoomWrapper);
      }

      ChatWindowManager chatWindowManager = GuiActivator.getUIService().getChatWindowManager();
      ChatPanel chatPanel = chatWindowManager.getMultiChat(chatRoomWrapper, true);

      chatWindowManager.openChat(chatPanel, true);
    } else if (itemName.equals("joinAsChatRoom")) {
      ChatRoomAuthenticationWindow authWindow = new ChatRoomAuthenticationWindow(chatRoomWrapper);

      authWindow.setVisible(true);
    } else if (itemName.equals("nickNameChatRoom")) {
      String nickName = null;

      nickName =
          ConfigurationManager.getChatRoomProperty(
              chatRoomWrapper.getParentProvider().getProtocolProvider(),
              chatRoomWrapper.getChatRoomID(),
              "userNickName");

      ChatOperationReasonDialog reasonDialog =
          new ChatOperationReasonDialog(
              GuiActivator.getResources().getI18NString("service.gui.CHANGE_NICKNAME"),
              GuiActivator.getResources().getI18NString("service.gui.CHANGE_NICKNAME_LABEL"));

      reasonDialog.setReasonFieldText(
          nickName == null
              ? chatRoomWrapper.getParentProvider().getProtocolProvider().getAccountID().getUserID()
              : nickName);

      int result = reasonDialog.showDialog();

      if (result == MessageDialog.OK_RETURN_CODE) {
        nickName = reasonDialog.getReason().trim();
      }

      ConfigurationManager.updateChatRoomProperty(
          chatRoomWrapper.getParentProvider().getProtocolProvider(),
          chatRoomWrapper.getChatRoomID(),
          "userNickName",
          nickName);
    }
  }