Пример #1
0
  void jList1_valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) return;

    JList theList = (JList) e.getSource();
    if (!theList.isSelectionEmpty()) {
      registerJID = (JID) services.get(theList.getSelectedValue());
      if (registerJID != null)
        backend.send(new InfoQuery(registerJID, "get", backend.getIdentifier(), new IQRegister()));
    }
    theList.clearSelection();
  }
Пример #2
0
 public void discoveryInfoResult(JID jid, DiscoveryInfo item) {
   // DefaultListModel model = (DefaultListModel) jList1.getModel();
   numberOfServices--;
   System.out.println(numberOfServices);
   if (numberOfServices <= 0) setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   DefaultListModel model = (DefaultListModel) jList1.getModel();
   String name = item.getName();
   if (name != null && model.removeElement(jid.toStringNoResource())) {
     model.addElement(name);
   }
   if (item.hasFeatures()) {
     for (Iterator j = item.getFeatures(); j.hasNext(); ) {
       String namespace = (String) j.next();
       if (namespace.equals("jabber:iq:register")) {
         if (name != null) services.put(item.getName(), jid);
         else services.put(jid.toStringNoResource(), jid);
       }
       // else{} remove from services
     }
   }
 }
Пример #3
0
 public void discoveryItemResult(JID jid, DiscoveryItem item) {
   // System.out.println(browse);
   if (!item.hasItems())
     nu.fw.jeti.util.Popups.errorPopup(
         I18N.gettext("main.error.No_services"), I18N.gettext("main.error.Register_Services"));
   else {
     numberOfServices = 0;
     DefaultListModel model = (DefaultListModel) jList1.getModel();
     services.clear();
     model.clear();
     for (Iterator i = item.getItems(); i.hasNext(); ) {
       DiscoveryItem di = (DiscoveryItem) i.next();
       String name = di.getName();
       if (name == null) name = di.getJID().toStringNoResource();
       // put in services so errors do not prevent register
       services.put(name, di.getJID());
       model.addElement(name);
       backend.getInfo(di.getJID(), this);
       numberOfServices++;
     }
   }
   pack();
   setLocationRelativeTo(null);
 }
Пример #4
0
 public void removeFromMenu(String name) {
   if (menuItems == null) return;
   menuItems.remove(name);
   if (menuItems.isEmpty()) menuItems = null;
   if (popupMenu != null) createPopupMenu();
 }
Пример #5
0
 public void addToMenu(String name, RosterMenuListener listener) {
   if (menuItems == null) menuItems = new HashMap(10);
   menuItems.put(name, listener);
   if (popupMenu != null) createPopupMenu();
 }
Пример #6
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);
      }
    }
  }