Пример #1
0
  public void createPopupMenu() {
    popupMenu = new JPopupMenu();
    JMenuItem menuItem = null;
    JMenu subMenu = null;
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Message", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sendMessage(currentJIDStatus);
          }
        });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Chat", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            sendChat(currentJIDStatus);
          }
        });
    popupMenu.add(menuItem);
    subMenu = new JMenu(I18N.gettext("main.main.rostermenu.Subscriptions"));
    menuItem = new JMenuItem(I18N.gettext("main.main.rostermenu.Subscribe_from"));
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Subscribe_from", menuItem);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            backend.send(new Presence(currentJIDStatus.getJID(), "subscribe"));
          }
        });
    subMenu.add(menuItem);
    menuItem = new JMenuItem(I18N.gettext("main.main.rostermenu.Unsubscribe_from"));
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Unsubscribe_from", menuItem);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            backend.send(new Presence(currentJIDStatus.getJID(), "unsubscribe"));
          }
        });
    subMenu.add(menuItem);
    popupMenu.add(subMenu);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Remove", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JID to = currentJIDStatus.getJID();
            if (JOptionPane.showConfirmDialog(
                    main,
                    MessageFormat.format(
                        I18N.gettext("main.popup.Really_remove_{0}_from_all_groups_?"),
                        new Object[] {new String(to.toString())}),
                    I18N.gettext("main.main.rostermenu.Remove"),
                    JOptionPane.YES_NO_OPTION)
                == JOptionPane.YES_OPTION) {
              // backend.remove(currentJIDStatus.getJID());
              IQXRoster roster = new IQXRoster(new RosterItem(to, null, "remove", null, null));
              backend.send(new InfoQuery("set", roster));
            }
          }
        });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Rename", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String nick =
                JOptionPane.showInputDialog(
                    main,
                    MessageFormat.format(
                        I18N.gettext("main.popup.Rename_{0}_to:"),
                        new Object[] {new String(currentJIDStatus.getNick())}));
            if (nick == null) return;
            IQXRoster roster =
                new IQXRoster(
                    new RosterItem(
                        currentJIDStatus.getJID(),
                        nick,
                        null,
                        null,
                        currentJIDStatus.getGroupsCopy()));
            backend.send(new InfoQuery("set", roster));
          }
        });
    popupMenu.add(menuItem);
    subMenu = new JMenu();
    I18N.setTextAndMnemonic("main.main.rostermenu.Group", subMenu);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Change_Group", menuItem, true);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new GroupDialog(currentGroup, currentJIDStatus, backend).show();
          }
        });
    subMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Add_to_Group", menuItem, true);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new GroupDialog(currentJIDStatus, backend).show();
          }
        });
    subMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Remove_from_group", menuItem, true);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JID to = currentJIDStatus.getJID();
            if (currentJIDStatus.groupCount() == 1) {
              if (JOptionPane.showConfirmDialog(
                      main,
                      MessageFormat.format(
                          I18N.gettext("main.popup.{0}_is_in_the_last_group,_remove_completely?"),
                          new Object[] {new String(to.toString())}),
                      I18N.gettext("main.main.rostermenu.Remove"),
                      JOptionPane.YES_NO_OPTION)
                  == JOptionPane.YES_OPTION) {
                IQXRoster roster = new IQXRoster(new RosterItem(to, null, "remove", null, null));
                backend.send(new InfoQuery("set", roster));
              }
            } else {
              nu.fw.jeti.util.StringArray groups = currentJIDStatus.getGroupsCopy();
              groups.remove(currentGroup);
              IQXRoster roster =
                  new IQXRoster(new RosterItem(to, currentJIDStatus.getNick(), null, null, groups));
              backend.send(new InfoQuery("set", roster));
            }
          }
        });
    subMenu.add(menuItem);
    popupMenu.add(subMenu);
    if (onlineTree) {
      menuItem = new JMenuItem();
      I18N.setTextAndMnemonic("main.main.rostermenu.Local_Time", menuItem, true);
      menuItem.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              backend.send(new InfoQuery(currentJIDStatus.getCompleteJID(), "get", new IQTime()));
            }
          });
      popupMenu.add(menuItem);
    }
    if (!onlineTree) {
      menuItem = new JMenuItem();
      I18N.setTextAndMnemonic("main.main.rostermenu.Last_Seen", menuItem, true);
      menuItem.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              backend.send(new InfoQuery(currentJIDStatus.getJID(), "get", new IQLast()));
            }
          });
      popupMenu.add(menuItem);
    }
    if (onlineTree) {
      menuItem = new JMenuItem();
      I18N.setTextAndMnemonic("main.main.rostermenu.Local_Version", menuItem, true);
      menuItem.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              backend.send(
                  new InfoQuery(currentJIDStatus.getCompleteJID(), "get", new IQVersion()));
            }
          });
      popupMenu.add(menuItem);
    }
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Invisible", menuItem);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            backend.send(new Presence(currentJIDStatus.getJID(), "invisible"));
          }
        });
    popupMenu.add(menuItem);
    if (menuItems != null) {
      for (Iterator i = menuItems.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        JMenuItem item = new JMenuItem((String) entry.getKey());
        final RosterMenuListener listener = (RosterMenuListener) entry.getValue();
        item.addActionListener(
            new java.awt.event.ActionListener() {
              public void actionPerformed(ActionEvent e) {
                listener.actionPerformed(currentJIDStatus, currentJIDStatusGroup2);
              }
            });
        popupMenu.add(item);
      }
    }
  }
Пример #2
0
  private void createGroupPopupMenu() {
    groupPopupMenu = new JPopupMenu();
    JMenuItem menuItem = null;
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Remove", menuItem, true);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(
                    main,
                    MessageFormat.format(
                        I18N.gettext(
                            "main.popup.Really_remove_{0}?_All_JIDs_in_this_group_will_be_removed!"),
                        new Object[] {new String(currentGroup)}),
                    I18N.gettext("main.popup.Remove_Group"),
                    JOptionPane.YES_NO_OPTION)
                == JOptionPane.YES_OPTION) {
              for (Iterator i = currentJIDStatusGroup.iterator(); i.hasNext(); ) {
                PrimaryJIDStatus primary = (PrimaryJIDStatus) i.next();
                if (primary.hasMultiple()) {
                  for (Iterator j = primary.getOtherJidStatussen(); j.hasNext(); ) {
                    groupRemove((JIDStatus) j.next());
                  }
                }
                groupRemove(primary);
              }
            }
          }

          private void groupRemove(JIDStatus jidStatus) {
            JID to = jidStatus.getJID();
            if (jidStatus.groupCount() == 1) {
              if (JOptionPane.showConfirmDialog(
                      main,
                      MessageFormat.format(
                          I18N.gettext("main.popup.{0}_is_in_the_last_group,_remove_completely?"),
                          new Object[] {new String(to.toString())}),
                      I18N.gettext("main.main.rostermenu.Remove"),
                      JOptionPane.YES_NO_OPTION)
                  == JOptionPane.YES_OPTION) {
                IQXRoster roster = new IQXRoster(new RosterItem(to, null, "remove", null, null));
                backend.send(new InfoQuery("set", roster));
              }
            } else {
              StringArray groups = jidStatus.getGroupsCopy();
              groups.remove(currentGroup);
              IQXRoster roster =
                  new IQXRoster(new RosterItem(to, jidStatus.getNick(), null, null, groups));
              backend.send(new InfoQuery("set", roster));
            }
          }
        });
    groupPopupMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Rename", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String groupName =
                JOptionPane.showInputDialog(
                    main,
                    MessageFormat.format(
                        I18N.gettext("main.popup.Rename_{0}_to:"),
                        new Object[] {new String(currentGroup)}));
            if (groupName == null) return;
            for (Iterator i = currentJIDStatusGroup.iterator(); i.hasNext(); ) {
              PrimaryJIDStatus primary = (PrimaryJIDStatus) i.next();
              if (primary.hasMultiple()) {
                for (Iterator j = primary.getOtherJidStatussen(); j.hasNext(); ) {
                  renameGroup(groupName, (JIDStatus) j.next());
                }
              }
              renameGroup(groupName, primary);
            }
          }

          private void renameGroup(String groupName, JIDStatus jidStatus) {
            StringArray groups = jidStatus.getGroupsCopy();
            groups.remove(currentGroup);
            groups.add(groupName);
            IQXRoster roster =
                new IQXRoster(
                    new RosterItem(jidStatus.getJID(), jidStatus.getNick(), null, null, groups));
            backend.send(new InfoQuery("set", roster));
          }
        });
    groupPopupMenu.add(menuItem);
  }