View Javadoc

1   package org.catacomb.druid.gui.base;
2   
3   
4   import org.catacomb.druid.gui.edit.DruMenu;
5   import org.catacomb.druid.swing.DPanel;
6   import org.catacomb.druid.swing.DScrollablePanel;
7   import org.catacomb.interlish.interact.DComponent;
8   import org.catacomb.interlish.structure.InfoReceiver;
9   import org.catacomb.interlish.structure.MouseActor;
10  import org.catacomb.report.E;
11  
12  
13  import java.awt.Color;
14  import java.awt.Point;
15  
16  import java.awt.Dimension;
17  
18  import javax.swing.JPanel;
19  
20  public class DruPanel implements MouseActor {
21      static final long serialVersionUID = 1001;
22  
23      public static final int SCROLLABLE = 1;
24  
25      String id;
26      String title;
27      String tip;
28      String info;
29  
30      DPanel dPanel;
31  
32      public InfoReceiver infoReceiver;
33  
34      Color bgColor;
35      Color fgColor;
36  
37      DComponent tooltipTarget;
38  
39      public DruPanel() {
40          dPanel = new DPanel();
41          id = "";
42      }
43  
44      public DruPanel(int props) {
45          if (props == SCROLLABLE) {
46              dPanel = new DScrollablePanel();
47          } else {
48              dPanel = new DPanel();
49          }
50          id = "";
51      }
52  
53  
54      public void setTooltipTarget(DComponent dc) {
55          tooltipTarget = dc;
56      }
57  
58  
59      public DPanel getGUIPeer() {
60          return dPanel;
61      }
62  
63      public String toString() {
64          return getClass().getName() + " id=" + id;
65      }
66  
67  
68      public int[] getLocation() {
69          Point p = getGUIPeer().getLocation();
70          int[] ret = {(int)(p.getX()), (int)(p.getY())};
71          return ret;
72      }
73  
74  
75      public void setID(String s) {
76          id = s;
77      }
78  
79  
80      public String getID() {
81          return id;
82      }
83  
84  
85      public void setTitleInfo(String st, String si) {
86          title = st;
87          info = si;
88      }
89  
90  
91      public void setTitle(String s) {
92          if (title != null) {
93              E.warning("overwriting title " + title + " with " + s);
94          }
95          title = s;
96      }
97  
98      public void setTip(String s) {
99  
100         tip = s;
101         if (tip != null && tip.length() > 3) {
102             if (tooltipTarget != null) {
103                 tooltipTarget.setTooltip(tip);
104             } else {
105                 E.shortWarning("no target for tooltip " + s + " " + this);
106             }
107         }
108     }
109 
110     public String getTip() {
111         return tip;
112     }
113 
114 
115     public String getTitle() {
116         return title;
117     }
118 
119 
120 
121     public void setInfo(String s) {
122         info = s;
123     }
124 
125 
126     public String getInfo() {
127         return info;
128     }
129 
130 
131     public void setInfoReceiver(InfoReceiver ir) {
132         infoReceiver = ir;
133     }
134 
135     public InfoReceiver getInfoReceiver() {
136         return infoReceiver;
137     }
138 
139 
140     public void mouseButtonPressed() {
141         exportInfo();
142     }
143 
144 
145 
146     public void exportInfo() {
147         if (infoReceiver != null) {
148 
149             if (getInfo() != null && getInfo().length() > 0) {
150                 if (getTitle() == null || getTitle().startsWith("Panel")) {
151                     E.shortWarning("no title for panel exporting info " + this);
152                 }
153 
154                 infoReceiver.receiveInfo(getTitle(), getInfo());
155             }
156 
157         } else {
158             E.warning("no info receiver on " + this);
159             (new Exception()).printStackTrace();
160         }
161     }
162 
163 
164     public void setBg(Color c) {
165         bgColor = c;
166         dPanel.setBg(c);
167     }
168 
169     public void setFg(Color c) {
170         fgColor = c;
171         dPanel.setFg(c);
172     }
173 
174     public Color getBg() {
175         return bgColor;
176     }
177 
178     public void setColors(DruPanel dp) {
179         dp.setFallbackBackgroundColor(bgColor);
180         dp.setFallbackForegroundColor(fgColor);
181     }
182 
183 
184     public void setColors(DruLabel dp) {
185         dp.setBg(bgColor);
186         dp.setFg(fgColor);
187     }
188 
189 
190 
191 
192 
193 
194 
195     public void addPanel(DruPanel drup) {
196         setColors(drup);
197         dPanel.add(drup.getGUIPeer());
198     }
199 
200 
201     public void addMenu(DruMenu menu) {
202         menu.setBg(bgColor);
203         menu.setFg(fgColor);
204         dPanel.add(menu.getGUIPeer());
205     }
206 
207 
208     public void addCardPanel(DruPanel drup) {
209         setColors(drup);
210         dPanel.add(drup.getGUIPeer(), drup.getTitle());
211     }
212 
213     public void addPanel(DruPanel drup, Object constraints) {
214         dPanel.add(drup.getGUIPeer(), constraints);
215     }
216 
217     public void addRaw(JPanel jp, Object constraints) {
218         dPanel.add(jp, constraints);
219     }
220 
221     public void addDComponent(DComponent obj) {
222         dPanel.addDComponent(obj);
223     }
224 
225     public void addSingleDComponent(DComponent obj) {
226         setSingle();
227         dPanel.addDComponent(obj);
228         if (tip != null && tip.length() > 3) {
229             obj.setTooltip(tip);
230         }
231         tooltipTarget = obj;
232     }
233 
234     public void addDComponent(DComponent cpt, Object constraints) {
235         dPanel.addDComponent(cpt, constraints);
236     }
237 
238 
239     public void removeDComponent(DComponent cpt) {
240         dPanel.removeDComponent(cpt);
241     }
242 
243 
244     public void removeAll() {
245         dPanel.removeAll();
246     }
247 
248 
249 
250 
251 
252 
253     public void removePanel(DruPanel dp) {
254         dPanel.remove(dp.getGUIPeer());
255     }
256 
257 
258     public void postApply() {
259         // subclass for things taht use tips etc;
260     }
261 
262     public void setSingle() {
263         dPanel.setSingle();
264     }
265 
266 
267 
268     public void revalidate() {
269         dPanel.revalidate();
270     }
271 
272     public void validate() {
273         dPanel.validate();
274     }
275 
276     public void repaint() {
277         dPanel.repaint();
278     }
279 
280 
281     public void addBorder(int i, int j, int k, int l) {
282         dPanel.addBorder(i, j, k, l);
283     }
284 
285     public void setEmptyBorder(int i, int j, int k, int l) {
286         dPanel.setEmptyBorder(i, j, k, l);
287     }
288 
289 
290     public void setPreferredSize(int prefWidth, int prefHeight) {
291         dPanel.setPreferredSize(prefWidth, prefHeight);
292     }
293 
294 
295     public void addEtchedBorder(Color bg) {
296         dPanel.addEtchedBorder(bg);
297     }
298 
299 
300     public void addTitledBorder(String borderTitle, Color c) {
301         dPanel.addTitledBorder(borderTitle, c);
302     }
303 
304 
305     public void setEtchedBorder(Color bg) {
306         dPanel.setEtchedBorder(bg);
307     }
308 
309     public void setSunkenBorder(Color bg) {
310         dPanel.setSunkenBorder(bg);
311     }
312 
313 
314     public void addSunkenBorder(Color bg) {
315         dPanel.addSunkenBorder(bg);
316     }
317 
318     public void setBorderLayout(int xspace, int yspace) {
319         dPanel.setBorderLayout(xspace, yspace);
320     }
321 
322 
323     public Dimension getPreferredSize() {
324         return dPanel.getPreferredSize();
325     }
326 
327 
328     public void setFlowLayout() {
329         dPanel.setFlowLayout();
330     }
331 
332 
333 
334     public void setGridLayout(int nr, int nc, int dx, int dy) {
335         dPanel.setGridLayout(nr, nc, dx, dy);
336     }
337 
338     public void setFlowLeft(int dx, int dy) {
339         dPanel.setFlowLeft(dx, dy);
340     }
341 
342     public void setFlowRight(int dx, int dy) {
343         dPanel.setFlowRight(dx, dy);
344     }
345 
346     public void setFlowCenter(int dx, int dy) {
347         dPanel.setFlowCenter(dx, dy);
348     }
349 
350 
351     public void setEtchedUpBorder(Color c) {
352         dPanel.setEtchedUpBorder(c);
353     }
354 
355 
356     public void setPreferredSize(Dimension d) {
357         dPanel.setPreferredSize(d);
358     }
359 
360 
361     public int[] getXYLocationOnScreen() {
362         return dPanel.getXYLocationOnScreen();
363     }
364 
365     public void setBackgroundColor(Color color) {
366         bgColor = color;
367         setBg(bgColor);
368     }
369 
370     public void setFallbackBackgroundColor(Color bg) {
371         if (bgColor == null) {
372             bgColor = bg;
373             setBg(bg);
374         }
375     }
376 
377     public void seForegroundColor(Color color) {
378         fgColor = color;
379         setFg(fgColor);
380     }
381 
382     public void setFallbackForegroundColor(Color fg) {
383         if (fgColor == null) {
384             fgColor = fg;
385             setFg(fg);
386         }
387     }
388 
389 }