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.*;
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.setModel(new BareComponentTreeModel(root,this));
22 setToggleClickCount(0);
24 javax.swing.plaf.basic.BasicTreeUI ui = new javax.swing.plaf.basic.BasicTreeUI();
27 ui.setExpandedIcon(TreeIcon.MINUS);
28 ui.setCollapsedIcon(TreeIcon.PLUS);
30 ui.setLeftChildIndent(15);
33 setBackground(Color.WHITE);
34 setShowsRootHandles(false);
36 setCellRenderer(new ComponentTreeRenderer());
38 // Expand whole tree by default
43 public void expandTree() {
44 for (int i=0; i<getRowCount(); i++)
49 private static class TreeIcon implements Icon{
50 public static final Icon PLUS = new TreeIcon(true);
51 public static final Icon MINUS = new TreeIcon(false);
55 private final static int width = 9;
56 private final static int height = 9;
57 private final static BasicStroke stroke = new BasicStroke(2);
60 private TreeIcon(boolean plus) {
64 public void paintIcon(Component c, Graphics g, int x, int y) {
65 Graphics2D g2 = (Graphics2D)g.create();
67 g2.setColor(Color.WHITE);
68 g2.fillRect(x,y,width,height);
70 g2.setColor(Color.DARK_GRAY);
71 g2.drawRect(x,y,width,height);
74 g2.drawLine(x+3, y+(height+1)/2, x+width-2, y+(height+1)/2);
76 g2.drawLine(x+(width+1)/2, y+3, x+(width+1)/2, y+height-2);
81 public int getIconWidth() {
85 public int getIconHeight() {