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); }
/** * Tries to calculate the position to use for showing hint for the given node of the given tree. * * @param node target node for which a hint should be shown * @param tree target tree that contains given node * @return preferred hint position (in coordinates relative to the given tree) if it's possible to * calculate the one; <code>null</code> otherwise */ @Nullable public static Point getHintPosition( @NotNull GradleProjectStructureNode<?> node, @NotNull Tree tree) { final Rectangle bounds = tree.getPathBounds(new TreePath(node.getPath())); if (bounds == null) { return null; } final Icon icon = ((GradleProjectStructureNode) node).getDescriptor().getOpenIcon(); int xAdjustment = 0; if (icon != null) { xAdjustment = icon.getIconWidth(); } return new Point(bounds.x + xAdjustment, bounds.y + bounds.height); }