1 package org.catacomb.druid.gui.base;
2
3
4 import org.catacomb.druid.event.StateListener;
5 import org.catacomb.interlish.interact.DComponent;
6 import org.catacomb.report.E;
7
8
9 public class DruPseudoCardPanel extends DruSubcontainerPanel {
10
11 static final long serialVersionUID = 1001;
12
13 int npanel;
14 DruPanel[] panels;
15 String[] names;
16
17 int ipanel;
18
19 int nlistener;
20 StateListener[] listeners;
21
22
23 public DruPseudoCardPanel() {
24 panels = new DruPanel[10];
25 names = new String[10];
26
27 setSingle();
28
29 panels = new DruPanel[10];
30 names = new String[10];
31 }
32
33
34
35 public void subAddPanel(DruPanel drup) {
36 setColors(drup);
37
38 if (bgColor.getRed() == 240 && bgColor.getGreen() == 240) {
39 E.info("got the 240 color...");
40
41 }
42
43
44 panels[npanel] = drup;
45 names[npanel] = drup.getTitle();
46
47 npanel += 1;
48
49 if (npanel == 1) {
50 getGUIPeer().addDComponent(drup.getGUIPeer());
51 ipanel = 0;
52 }
53 }
54
55
56 public void subAddDComponent(DComponent dcpt) {
57 E.error("only accept DruPanels");
58 }
59
60
61
62 public boolean containsCard(String s) {
63 return (getCardIndex(s) >= 0);
64 }
65
66
67 private int getCardIndex(String s) {
68 int ishow = -1;
69 for (int i = 0; i < npanel; i++) {
70 if (s.equals(names[i])) {
71 ishow = i;
72 }
73 }
74 return ishow;
75 }
76
77
78 public void showCard(String s) {
79 int ishow = getCardIndex(s);
80
81 if (ishow == -1) {
82 E.error(" - unknown card in pseudo card panel " + s);
83
84 } else if (ishow == ipanel) {
85
86
87 } else {
88 showIthCard(ishow);
89
90 }
91
92 revalidate();
93
94 }
95
96
97
98 private void notifyListeners(String stat) {
99 for (int i = 0; i < nlistener; i++) {
100 listeners[i].stateChanged(stat);
101 }
102 }
103
104
105
106 public void addStateListener(StateListener sl) {
107 if (listeners == null) {
108 listeners = new StateListener[4];
109 }
110 listeners[nlistener++] = sl;
111 }
112
113
114
115 public void nextCard() {
116
117 ipanel = (ipanel + 1) % npanel;
118 if (ipanel == npanel) {
119 ipanel = 0;
120 }
121 showIthCard(ipanel);
122 }
123
124
125
126 private void showIthCard(int ip) {
127 getGUIPeer().removeDComponent(panels[ipanel].getGUIPeer());
128 ipanel = ip;
129 getGUIPeer().addDComponent(panels[ipanel].getGUIPeer());
130
131 notifyListeners(names[ip]);
132 revalidate();
133 }
134
135
136 public void subRemoveAll() {
137 E.missing();
138 }
139
140 }