Esempio n. 1
0
  private static Pair<Image, Point> createDragImage(
      final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) {
    if (c instanceof JComponent) {
      ((JComponent) c).setOpaque(true);
    }

    c.setForeground(tree.getForeground());
    c.setBackground(tree.getBackground());
    c.setFont(tree.getFont());
    c.setSize(c.getPreferredSize());
    final BufferedImage image =
        new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
    c.paint(g2);
    g2.dispose();

    Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2);

    if (adjustToPathUnderDragOrigin) {
      TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y);
      if (path != null) {
        Rectangle bounds = tree.getPathBounds(path);
        point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y);
      }
    }

    return new Pair<Image, Point>(image, point);
  }
  public void updateArchetypesList(final MavenArchetype selected) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    myLoadingIcon.setBackground(myArchetypesTree.getBackground());

    ((CardLayout) myArchetypesPanel.getLayout()).show(myArchetypesPanel, "loading");

    final Object currentUpdaterMarker = new Object();
    myCurrentUpdaterMarker = currentUpdaterMarker;

    ApplicationManager.getApplication()
        .executeOnPooledThread(
            new Runnable() {
              public void run() {
                final Set<MavenArchetype> archetypes =
                    MavenIndicesManager.getInstance().getArchetypes();

                //noinspection SSBasedInspection
                SwingUtilities.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (currentUpdaterMarker != myCurrentUpdaterMarker)
                          return; // Other updater has been run.

                        ((CardLayout) myArchetypesPanel.getLayout())
                            .show(myArchetypesPanel, "archetypes");

                        TreeNode root = groupAndSortArchetypes(archetypes);
                        TreeModel model = new DefaultTreeModel(root);
                        myArchetypesTree.setModel(model);

                        if (selected != null) {
                          TreePath path = findNodePath(selected, model, model.getRoot());
                          if (path != null) {
                            myArchetypesTree.expandPath(path.getParentPath());
                            TreeUtil.selectPath(myArchetypesTree, path, true);
                          }
                        }

                        updateArchetypeDescription();
                      }
                    });
              }
            });
  }