protected boolean accept(Component jc) {
   if (extListener != null && extListener.accept(jc)) {
     return true;
   }
   if (!(jc instanceof JComponent)) {
     return false;
   }
   if (jc instanceof TableCellEditor
       || jc instanceof TreeCellEditor
       || SwingUtilities.getAncestorOfClass(JTable.class, jc) != null
       || SwingUtilities.getAncestorOfClass(JTree.class, jc) != null
       || SwingUtilities.getAncestorOfClass(JList.class, jc) != null) {
     // Don't listen to cell editors, we can end up listening to them
     // multiple times, and the tree/table model will give us the event
     // we need
     return false;
   }
   return isProbablyAContainer(jc)
       || jc instanceof JList
       || jc instanceof JComboBox
       || jc instanceof JTree
       || jc instanceof JToggleButton
       || // covers toggle, radio, checkbox
       jc instanceof JTextComponent
       || jc instanceof JColorChooser
       || jc instanceof JSpinner
       || jc instanceof JSlider;
 }
    /**
     * Details have been retrieved.
     *
     * @param details the details retrieved if any.
     */
    public void detailsRetrieved(Iterator<GenericDetail> details) {
      // if treenode has changed ignore
      if (!source.equals(treeNode)) return;

      while (details.hasNext()) {
        GenericDetail d = details.next();

        if (d instanceof PhoneNumberDetail
            && !(d instanceof PagerDetail)
            && !(d instanceof FaxDetail)) {
          final PhoneNumberDetail pnd = (PhoneNumberDetail) d;
          if (pnd.getNumber() != null && pnd.getNumber().length() > 0) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    callButton.setEnabled(true);

                    if (pnd instanceof VideoDetail) {
                      callVideoButton.setEnabled(true);
                      desktopSharingButton.setEnabled(true);
                    }

                    treeContactList.refreshContact(uiContact);
                  }
                });

            return;
          }
        }
      }
    }
 public void valueChanged(TreeSelectionEvent e) {
   Node node = (Node) getTree().getLastSelectedPathComponent();
   if (getSheet() == null) return;
   if (node == null) {
     node = (Node) getTree().getPathForRow(0).getLastPathComponent();
   }
   nextToSetTo = node;
   if (getSheet().getObject() != nextToSetTo) {
     SwingUtilities.invokeLater(setSheetObject);
   }
 }
 private boolean fitsInBounds(final Rectangle rect) {
   final Container container = getParent();
   if (container instanceof JViewport) {
     final Container scrollPane = container.getParent();
     if (scrollPane instanceof JScrollPane) {
       final Rectangle rectangle =
           SwingUtilities.convertRectangle(this, rect, scrollPane.getParent());
       return scrollPane.getBounds().contains(rectangle);
     }
   }
   return true;
 }
 public synchronized void searchStarted(SearchEvent e) {
   debug("search Started");
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           TreeSelectionModel tsm = tree.getSelectionModel();
           tsm.clearSelection();
           topNode.removeAllChildren();
           ((DefaultTreeModel) tree.getModel()).reload();
           tree.invalidate();
           tree.repaint();
         }
       });
 }
  /**
   * Calls the given treeNode.
   *
   * @param treeNode the <tt>TreeNode</tt> to call
   */
  private void call(TreeNode treeNode, JButton button, boolean isVideo, boolean isDesktopSharing) {
    if (!(treeNode instanceof ContactNode)) return;

    UIContact contactDescriptor = ((ContactNode) treeNode).getContactDescriptor();

    Point location = new Point(button.getX(), button.getY() + button.getHeight());

    SwingUtilities.convertPointToScreen(location, treeContactList);

    location.y = location.y + treeContactList.getPathBounds(treeContactList.getSelectionPath()).y;
    location.x += 8;
    location.y -= 8;

    CallManager.call(contactDescriptor, isVideo, isDesktopSharing, treeContactList, location);
  }
  private void reset() {
    ApplicationManager.getApplication().assertIsDispatchThread();

    myUsageNodes.clear();
    myIsFirstVisibleUsageFound = false;

    myModel.reset();
    if (!myPresentation.isDetachedMode()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              if (isDisposed) return;
              TreeUtil.expand(myTree, 2);
            }
          });
    }
  }
 public synchronized void searchFinished(SearchEvent e) {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           TreeSelectionModel tsm = tree.getSelectionModel();
           if (lastTOCnode == null && topNode.getChildCount() > 0) {
             DefaultMutableTreeNode node = (DefaultMutableTreeNode) topNode.getFirstChild();
             if (node != null) {
               tsm.clearSelection();
               tsm.setSelectionPath(new TreePath(node.getPath()));
             }
           } else {
             // beep
             searchnav.getToolkit().beep();
           }
           searchparams.setCursor(paramCursor);
           tree.setCursor(treeCursor);
         }
       });
   return;
 }
  /**
   * Shows the appropriate user interface that would allow the user to add the given
   * <tt>SourceUIContact</tt> to their contact list.
   *
   * @param contact the contact to add
   */
  private void addContact(SourceUIContact contact) {
    SourceContact sourceContact = (SourceContact) contact.getDescriptor();

    List<ContactDetail> details =
        sourceContact.getContactDetails(OperationSetPersistentPresence.class);
    int detailsCount = details.size();

    if (detailsCount > 1) {
      JMenuItem addContactMenu =
          TreeContactList.createAddContactMenu((SourceContact) contact.getDescriptor());

      JPopupMenu popupMenu = ((JMenu) addContactMenu).getPopupMenu();

      // Add a title label.
      JLabel infoLabel = new JLabel();
      infoLabel.setText(
          "<html><b>"
              + GuiActivator.getResources().getI18NString("service.gui.ADD_CONTACT")
              + "</b></html>");

      popupMenu.insert(infoLabel, 0);
      popupMenu.insert(new Separator(), 1);

      popupMenu.setFocusable(true);
      popupMenu.setInvoker(treeContactList);

      Point location =
          new Point(
              addContactButton.getX(), addContactButton.getY() + addContactButton.getHeight());

      SwingUtilities.convertPointToScreen(location, treeContactList);

      location.y = location.y + treeContactList.getPathBounds(treeContactList.getSelectionPath()).y;

      popupMenu.setLocation(location.x + 8, location.y - 8);
      popupMenu.setVisible(true);
    } else if (details.size() == 1) {
      TreeContactList.showAddContactDialog(details.get(0), sourceContact.getDisplayName());
    }
  }
 private void rulesChanged() {
   ApplicationManager.getApplication().assertIsDispatchThread();
   final ArrayList<UsageState> states = new ArrayList<UsageState>();
   captureUsagesExpandState(new TreePath(myTree.getModel().getRoot()), states);
   final List<Usage> allUsages = new ArrayList<Usage>(myUsageNodes.keySet());
   Collections.sort(allUsages, USAGE_COMPARATOR);
   final Set<Usage> excludedUsages = getExcludedUsages();
   reset();
   myBuilder.setGroupingRules(getActiveGroupingRules(myProject));
   myBuilder.setFilteringRules(getActiveFilteringRules(myProject));
   ApplicationManager.getApplication()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               for (Usage usage : allUsages) {
                 if (!usage.isValid()) {
                   continue;
                 }
                 if (usage instanceof MergeableUsage) {
                   ((MergeableUsage) usage).reset();
                 }
                 appendUsage(usage);
               }
             }
           });
   excludeUsages(excludedUsages.toArray(new Usage[excludedUsages.size()]));
   if (myCentralPanel != null) {
     setupCentralPanel();
   }
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           if (isDisposed) return;
           restoreUsageExpandState(states);
           updateImmediately();
         }
       });
 }
 public synchronized void itemsFound(SearchEvent e) {
   SwingUtilities.invokeLater(new SearchItemsFound(e));
 }
Exemple #12
0
  public static ActionCallback showAndSelect(
      final JTree tree,
      int top,
      int bottom,
      final int row,
      final int previous,
      boolean addToSelection,
      final boolean scroll) {
    final TreePath path = tree.getPathForRow(row);

    if (path == null) return new ActionCallback.Done();

    final int size = tree.getRowCount();
    if (size == 0) {
      tree.clearSelection();
      return new ActionCallback.Done();
    }
    if (top < 0) {
      top = 0;
    }
    if (bottom >= size) {
      bottom = size - 1;
    }

    if (row >= tree.getRowCount()) return new ActionCallback.Done();

    if (!tree.isValid()) {
      tree.validate();
    }

    final Rectangle rowBounds = tree.getRowBounds(row);
    if (rowBounds == null) return new ActionCallback.Done();

    Rectangle topBounds = tree.getRowBounds(top);
    if (topBounds == null) {
      topBounds = rowBounds;
    }

    Rectangle bottomBounds = tree.getRowBounds(bottom);
    if (bottomBounds == null) {
      bottomBounds = rowBounds;
    }

    Rectangle bounds = topBounds.union(bottomBounds);
    bounds.x = rowBounds.x;
    bounds.width = rowBounds.width;

    final Rectangle visible = tree.getVisibleRect();
    if (visible.contains(bounds)) {
      bounds = null;
    } else {
      final Component comp =
          tree.getCellRenderer()
              .getTreeCellRendererComponent(
                  tree, path.getLastPathComponent(), true, true, false, row, false);

      if (comp instanceof SimpleColoredComponent) {
        final SimpleColoredComponent renderer = ((SimpleColoredComponent) comp);
        final Dimension scrollableSize = renderer.computePreferredSize(true);
        bounds.width = scrollableSize.width;
      }
    }

    final ActionCallback callback = new ActionCallback();

    if (!tree.isRowSelected(row)) {
      if (addToSelection) {
        tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row));
      } else {
        tree.setSelectionRow(row);
      }
    }

    if (bounds != null) {
      final Range<Integer> range = getExpandControlRange(tree, path);
      if (range != null) {
        int delta = bounds.x - range.getFrom().intValue();
        bounds.x -= delta;
        bounds.width -= delta;
      }

      if (visible.width < bounds.width) {
        bounds.width = visible.width;
      }

      final Rectangle b1 = bounds;
      final Runnable runnable =
          new Runnable() {
            public void run() {
              if (scroll) {
                tree.scrollRectToVisible(b1);
              }
              callback.setDone();
            }
          };

      if (ApplicationManager.getApplication().isUnitTestMode()) {
        runnable.run();
      } else {
        SwingUtilities.invokeLater(runnable);
      }
    } else {
      callback.setDone();
    }

    return callback;
  }