1 package net.sf.openrocket.gui.main.componenttree;
3 import java.awt.BasicStroke;
5 import java.awt.Component;
6 import java.awt.Graphics;
7 import java.awt.Graphics2D;
9 import javax.swing.DropMode;
10 import javax.swing.Icon;
11 import javax.swing.JTree;
12 import javax.swing.ToolTipManager;
14 import net.sf.openrocket.document.OpenRocketDocument;
17 public class ComponentTree extends JTree {
18 private static final long serialVersionUID = 1L;
20 public ComponentTree(OpenRocketDocument document) {
22 this.setModel(new ComponentTreeModel(document.getRocket(), this));
23 this.setToggleClickCount(0);
25 javax.swing.plaf.basic.BasicTreeUI ui = new javax.swing.plaf.basic.BasicTreeUI();
28 ui.setExpandedIcon(TreeIcon.MINUS);
29 ui.setCollapsedIcon(TreeIcon.PLUS);
31 ui.setLeftChildIndent(15);
34 setBackground(Color.WHITE);
35 setShowsRootHandles(false);
37 setCellRenderer(new ComponentTreeRenderer());
39 this.setDragEnabled(true);
40 this.setDropMode(DropMode.INSERT);
41 this.setTransferHandler(new ComponentTreeTransferHandler(document));
43 // Expand whole tree by default
46 // Enable tooltips for this component
47 ToolTipManager.sharedInstance().registerComponent(this);
52 public void expandTree() {
53 for (int i = 0; i < getRowCount(); i++)
58 private static class TreeIcon implements Icon {
59 public static final Icon PLUS = new TreeIcon(true);
60 public static final Icon MINUS = new TreeIcon(false);
64 private final static int width = 9;
65 private final static int height = 9;
66 private final static BasicStroke stroke = new BasicStroke(2);
69 private TreeIcon(boolean plus) {
73 public void paintIcon(Component c, Graphics g, int x, int y) {
74 Graphics2D g2 = (Graphics2D) g.create();
76 g2.setColor(Color.WHITE);
77 g2.fillRect(x, y, width, height);
79 g2.setColor(Color.DARK_GRAY);
80 g2.drawRect(x, y, width, height);
83 g2.drawLine(x + 3, y + (height + 1) / 2, x + width - 2, y + (height + 1) / 2);
85 g2.drawLine(x + (width + 1) / 2, y + 3, x + (width + 1) / 2, y + height - 2);
90 public int getIconWidth() {
94 public int getIconHeight() {