1 package org.catacomb.druid.swing;
2
3
4 import org.catacomb.druid.event.PanelListener;
5 import org.catacomb.interlish.interact.DComponent;
6 import org.catacomb.report.E;
7 import org.catacomb.util.ColorUtil;
8
9 import java.awt.Color;
10 import java.awt.Component;
11
12 import javax.swing.JTabbedPane;
13 import javax.swing.UIManager;
14 import javax.swing.event.ChangeEvent;
15 import javax.swing.event.ChangeListener;
16
17
18 public class DTabbedPane extends JTabbedPane implements DComponent, ChangeListener {
19
20 static final long serialVersionUID = 1001;
21
22
23 public PanelListener pListener;
24
25 int ntab;
26 String[] tabNames;
27
28 boolean dontReport;
29
30
31 public DTabbedPane() {
32 super();
33 dontReport = false;
34 addChangeListener(this);
35
36 ntab = 0;
37 tabNames = new String[20];
38 }
39
40
41 public void setTooltip(String s) {
42 setToolTipText(s);
43 }
44
45
46 public static void applyUIColors(Color c) {
47
48
49
50
51
52 Color cbr = ColorUtil.slightlyBrighter(c);
53 Color cdk = ColorUtil.slightlyDarker(c);
54 Color cdkdk = ColorUtil.slightlyDarker(cdk);
55
56 UIManager.put("TabbedPane.contentAreaColor", c);
57 UIManager.put("TabbedPane.selected", c);
58 UIManager.put("TabbedPane.selectedBackground", c);
59 UIManager.put("TabbedPane.unselectedBackground", cdk);
60
61 UIManager.put("TabbedPane.tabAreaBackground", c);
62 UIManager.put("TabbedPane.selectHighlight", cbr);
63 UIManager.put("TabbedPane.tabsOpaque", new Boolean(false));
64 UIManager.put("TabbedPane.borderHightlightColor", cdk);
65
66 UIManager.put("TabbedPane.light", cbr);
67 UIManager.put("TabbedPane.highlight", cbr);
68 UIManager.put("TabbedPane.shadow", cdk);
69 UIManager.put("TabbedPane.darkShadow", cdkdk);
70 UIManager.put("TabbedPane.focus", c);
71
72
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86 public void select(Object obj) {
87 setSelectedComponent((Component)obj);
88
89 report();
90 }
91
92
93 private void report() {
94 if (dontReport) {
95
96 } else {
97 if (pListener != null) {
98 Object obj = getSelectedComponent();
99 pListener.panelShown(obj);
100 }
101 }
102 }
103
104
105 public void setBg(Color c) {
106 setBackground(c);
107 }
108
109
110 public void setFg(Color c) {
111 setForeground(c);
112 }
113
114
115 public void setPanelListener(PanelListener pl) {
116 pListener = pl;
117 }
118
119
120 public void stateChanged(ChangeEvent cev) {
121 report();
122 }
123
124
125 public void addTab(String s, Component c) {
126 super.addTab(s, c);
127 E.error("shouldn't use");
128 }
129
130
131 public void addTab(String s, Component c, String tooltip) {
132 dontReport = true;
133
134 super.addTab(s, null, c, tooltip);
135 setBackgroundAt(ntab, null);
136 tabNames[ntab++] = s;
137
138 dontReport = false;
139 }
140
141
142 public void showTab(String s) {
143 boolean done = false;
144 for (int i = 0; i < ntab; i++) {
145 if (tabNames[i].equals(s)) {
146 done = true;
147 setSelectedIndex(i);
148 }
149 }
150 if (!done) {
151 E.error("no such tab " + s);
152 for (int i = 0; i < ntab; i++) {
153 E.info("tab " + i + " has name " + tabNames[i]);
154 }
155 }
156 }
157
158
159
160 }