Пример #1
0
  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);
        }
      }
    }
  }
Пример #2
0
  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++;
        }
      }
    }
  }