コード例 #1
0
ファイル: BroadcastDialog.java プロジェクト: kevintich/IM-1
  private void hideOfflineUsers() {

    int i = 0;
    if (OfflineUsers.isSelected()) {
      final ContactList contactList = SparkManager.getWorkspace().getContactList();
      i = 0;
      for (CheckNode node : nodes) {
        if (contactList.getContactItemByDisplayName(node.toString()).getPresence().getType()
            == Presence.Type.unavailable) {
          if (node.getParent() != null) {
            TreeNode parent = node.getParent();
            TreeNode[] path =
                ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
            ((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(node);
            checkTree.getTree().setSelectionPath(new TreePath(path));
            NodesGroups.add(new ArrayList<Object>());
            NodesGroups.get(i).add(parent);
            NodesGroups.get(i).add(node);
            i++;
          }
        }
      }
      for (int x = 0; x < groupNodes.size(); x++) {
        if (groupNodes.get(x).toString().equals(Res.getString("group.offline"))) {
          OfflineGroup = x;
          TreeNode parent = groupNodes.get(x).getParent();
          TreeNode[] path =
              ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
          ((DefaultTreeModel) checkTree.getTree().getModel())
              .removeNodeFromParent(groupNodes.get(x));
          checkTree.getTree().setSelectionPath(new TreePath(path));
        }
      }
    } else {
      i = 0;
      DefaultMutableTreeNode child = groupNodes.get(OfflineGroup);
      ((DefaultTreeModel) checkTree.getTree().getModel())
          .insertNodeInto(child, rosterNode, rosterNode.getChildCount());
      TreeNode[] path =
          ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(rosterNode);
      checkTree.getTree().expandPath(new TreePath(path));
      checkTree.expandTree();
      for (CheckNode node : nodes) {
        if (node.getParent() == null) {
          child = (CheckNode) NodesGroups.get(i).get(1);
          ((DefaultTreeModel) checkTree.getTree().getModel())
              .insertNodeInto(
                  child,
                  ((CheckNode) NodesGroups.get(i).get(0)),
                  ((CheckNode) NodesGroups.get(i).get(0)).getChildCount());
          path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(node);
          checkTree.getTree().expandPath(new TreePath(path));
          checkTree.expandTree();
          i++;
        }
      }
    }
  }
コード例 #2
0
ファイル: BroadcastDialog.java プロジェクト: kevintich/IM-1
  public BroadcastDialog() {
    setLayout(new GridBagLayout());
    rosterNode = new CheckNode(Res.getString("title.roster"));
    checkTree = new CheckTree(rosterNode);
    final ContactList contactList = SparkManager.getWorkspace().getContactList();

    // creates the List for the Online Users
    String groupName = Res.getString("status.online");
    CheckNode groupNode = new CheckNode(groupName);
    groupNodes.add(groupNode);
    rosterNode.add(groupNode);
    // ContactGroup groupp;
    for (ContactGroup group : contactList.getContactGroups())
      for (ContactItem item : group.getContactItems()) {
        if (item.isAvailable()) {
          CheckNode itemNode = new CheckNode(item.getDisplayName(), false, item.getIcon());
          itemNode.setAssociatedObject(item.getJID());
          groupNode.add(itemNode);
          nodes.add(itemNode);
        }
      }

    // Build out from Roster

    for (ContactGroup group : contactList.getContactGroups()) {
      groupName = group.getGroupName();
      if (!group.hasAvailableContacts()) {
        continue;
      }
      groupNode = new CheckNode(groupName);
      groupNodes.add(groupNode);
      rosterNode.add(groupNode);

      // Now add contact items from contact group.
      for (ContactItem item : group.getContactItems()) {
        CheckNode itemNode = new CheckNode(item.getDisplayName(), false, item.getIcon());
        itemNode.setAssociatedObject(item.getJID());
        groupNode.add(itemNode);
        nodes.add(itemNode);
      }

      final List<ContactItem> offlineContacts =
          new ArrayList<ContactItem>(group.getOfflineContacts());
      Collections.sort(offlineContacts, ContactList.ContactItemComparator);

      for (ContactItem item : offlineContacts) {
        CheckNode itemNode = new CheckNode(item.getDisplayName(), false, item.getIcon());
        itemNode.setAssociatedObject(item.getJID());
        groupNode.add(itemNode);
        nodes.add(itemNode);
      }
    }

    messageBox = new ChatInputEditor();
    normalMessageButton = new JRadioButton(Res.getString("message.normal"));
    JRadioButton alertMessageButton = new JRadioButton(Res.getString("message.alert.notify"));

    ButtonGroup group = new ButtonGroup();
    group.add(normalMessageButton);
    group.add(alertMessageButton);

    final JScrollPane pane = new JScrollPane(messageBox);
    pane.setBorder(
        BorderFactory.createTitledBorder(Res.getString("label.message").replace("&", "")));

    final JScrollPane treePane = new JScrollPane(checkTree);
    treePane.setBorder(
        BorderFactory.createTitledBorder(Res.getString("message.send.to.these.people")));
    treePane.getVerticalScrollBar().setBlockIncrement(200);
    treePane.getVerticalScrollBar().setUnitIncrement(20);
    // Add to UI
    add(
        pane,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.5,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
    add(
        normalMessageButton,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    add(
        alertMessageButton,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(2, 5, 2, 5),
            0,
            0));
    add(
        treePane,
        new GridBagConstraints(
            1,
            0,
            1,
            3,
            0.5,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(2, 5, 2, 5),
            0,
            0));
    add(
        OfflineUsers,
        new GridBagConstraints(
            1,
            3,
            1,
            0,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(2, 5, 2, 5),
            0,
            0));

    OfflineUsers.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            hideOfflineUsers();
          }
        });

    normalMessageButton.setSelected(true);
    checkTree.expandTree();

    // Iterate through selected users.
    for (ContactItem item : contactList.getSelectedUsers()) {
      for (CheckNode node : nodes) {
        if (node.getAssociatedObject().toString().equals(item.getJID())) {
          node.setSelected(true);
        }
      }
    }
  }
コード例 #3
0
  public void initialize() {
    // Listen for right-clicks on ContactItem
    final ContactList contactList = SparkManager.getWorkspace().getContactList();

    final Action listenAction =
        new AbstractAction() {
          private static final long serialVersionUID = 7705539667621148816L;

          public void actionPerformed(ActionEvent e) {

            for (ContactItem item : contactList.getSelectedUsers()) {
              String bareAddress = StringUtils.parseBareAddress(item.getJID());
              sparkContacts.add(bareAddress);
            }
          }
        };

    listenAction.putValue(Action.NAME, Res.getString("menuitem.alert.when.online"));
    listenAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ALARM_CLOCK));

    final Action removeAction =
        new AbstractAction() {
          private static final long serialVersionUID = -8726129089417116105L;

          public void actionPerformed(ActionEvent e) {

            for (ContactItem item : contactList.getSelectedUsers()) {
              String bareAddress = StringUtils.parseBareAddress(item.getJID());
              sparkContacts.remove(bareAddress);
            }
          }
        };

    removeAction.putValue(Action.NAME, Res.getString("menuitem.remove.alert.when.online"));
    removeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DELETE));

    contactList.addContextMenuListener(
        new ContextMenuListener() {
          public void poppingUp(Object object, JPopupMenu popup) {
            if (object instanceof ContactItem) {
              ContactItem item = (ContactItem) object;
              String bareAddress = StringUtils.parseBareAddress(item.getJID());
              if (!item.getPresence().isAvailable() || item.getPresence().isAway()) {
                if (sparkContacts.contains(bareAddress)) {
                  popup.add(removeAction);
                } else {
                  popup.add(listenAction);
                }
              }
            }
          }

          public void poppingDown(JPopupMenu popup) {}

          public boolean handleDefaultAction(MouseEvent e) {
            return false;
          }
        });

    // Check presence changes
    SparkManager.getConnection()
        .addPacketListener(
            new PacketListener() {
              public void processPacket(final Packet packet) {
                try {
                  EventQueue.invokeAndWait(
                      new Runnable() {
                        public void run() {
                          Presence presence = (Presence) packet;
                          if (!presence.isAvailable() || presence.isAway()) {
                            return;
                          }
                          String from = presence.getFrom();

                          ArrayList<String> removelater = new ArrayList<String>();

                          for (final String jid : sparkContacts) {
                            if (jid.equals(StringUtils.parseBareAddress(from))) {
                              removelater.add(jid);
                              // sparkContacts.remove(jid);

                              String nickname =
                                  SparkManager.getUserManager().getUserNicknameFromJID(jid);
                              String time = SparkManager.DATE_SECOND_FORMATTER.format(new Date());
                              String infoText =
                                  Res.getString(
                                      "message.user.now.available.to.chat", nickname, time);

                              if (localPref.getShowToasterPopup()) {
                                SparkToaster toaster = new SparkToaster();
                                toaster.setDisplayTime(5000);
                                toaster.setBorder(BorderFactory.createBevelBorder(0));

                                toaster.setToasterHeight(150);
                                toaster.setToasterWidth(200);

                                toaster.setTitle(nickname);
                                toaster.showToaster(null, infoText);

                                toaster.setCustomAction(
                                    new AbstractAction() {
                                      private static final long serialVersionUID =
                                          4827542713848133369L;

                                      @Override
                                      public void actionPerformed(ActionEvent e) {
                                        SparkManager.getChatManager().getChatRoom(jid);
                                      }
                                    });
                              }

                              ChatRoom room = SparkManager.getChatManager().getChatRoom(jid);

                              if (localPref.getWindowTakesFocus()) {
                                SparkManager.getChatManager().activateChat(jid, nickname);
                              }

                              room.getTranscriptWindow()
                                  .insertNotificationMessage(
                                      infoText, ChatManager.NOTIFICATION_COLOR);
                            }
                          }
                          for (String s : removelater) {
                            sparkContacts.remove(s);
                          }
                        }
                      });
                } catch (Exception ex) {
                  ex.printStackTrace();
                }
              }
            },
            new PacketTypeFilter(Presence.class));
  }