1 package net.sf.openrocket.gui.main;
3 import java.awt.BasicStroke;
5 import java.awt.Component;
6 import java.awt.Graphics;
7 import java.awt.Graphics2D;
9 import javax.swing.Icon;
10 import javax.swing.JTree;
12 import net.sf.openrocket.rocketcomponent.RocketComponent;
15 public class ComponentTree extends JTree {
16 private static final long serialVersionUID = 1L;
18 public ComponentTree(RocketComponent root) {
20 this.setModel(new ComponentTreeModel(root,this));
21 this.setToggleClickCount(0);
23 javax.swing.plaf.basic.BasicTreeUI ui = new javax.swing.plaf.basic.BasicTreeUI();
26 ui.setExpandedIcon(TreeIcon.MINUS);
27 ui.setCollapsedIcon(TreeIcon.PLUS);
29 ui.setLeftChildIndent(15);
32 setBackground(Color.WHITE);
33 setShowsRootHandles(false);
35 setCellRenderer(new ComponentTreeRenderer());
37 // Expand whole tree by default
42 public void expandTree() {
43 for (int i=0; i<getRowCount(); i++)
48 private static class TreeIcon implements Icon{
49 public static final Icon PLUS = new TreeIcon(true);
50 public static final Icon MINUS = new TreeIcon(false);
54 private final static int width = 9;
55 private final static int height = 9;
56 private final static BasicStroke stroke = new BasicStroke(2);
59 private TreeIcon(boolean plus) {
63 public void paintIcon(Component c, Graphics g, int x, int y) {
64 Graphics2D g2 = (Graphics2D)g.create();
66 g2.setColor(Color.WHITE);
67 g2.fillRect(x,y,width,height);
69 g2.setColor(Color.DARK_GRAY);
70 g2.drawRect(x,y,width,height);
73 g2.drawLine(x+3, y+(height+1)/2, x+width-2, y+(height+1)/2);
75 g2.drawLine(x+(width+1)/2, y+3, x+(width+1)/2, y+height-2);
80 public int getIconWidth() {
84 public int getIconHeight() {