KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > custom > JCoolBar


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: JCoolBar.java,v $
11    Revision 1.3 2004/04/28 08:38:06 bobintetley
12    Hierarchy fixes, code cleanup for base classes, additional javadocs and use of flag to identify JComponent descendants with peers
13
14    Revision 1.2 2004/01/26 08:10:59 bobintetley
15    Many bugfixes and addition of SwingSet
16
17    Revision 1.1 2004/01/20 07:38:05 bobintetley
18    Bug fixes and compatibility methods
19
20    Revision 1.2 2004/01/09 10:33:57 bobintetley
21    Changes for JToolBar to allow platform ToolBars, mixed with other components
22
23    Revision 1.1 2003/12/17 17:02:12 bobintetley
24    JCoolBar! (Not a real Swing component, but allows you to get at the
25    SWT functionality much easier than SWT does!)
26
27
28 */

29
30
31 package swingwtx.custom;
32
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.CoolBar;
36 import org.eclipse.swt.widgets.CoolItem;
37
38 import swingwtx.swing.JComponent;
39 import swingwtx.swing.SwingUtilities;
40 import swingwtx.swing.SwingWTUtils;
41
42 /**
43  * Not a real Swing component, but since Swing doesn't do them and SWT does, I
44  * could hardly leave them out, could I?
45  *
46  * Just add components to this thing - for each component you add (JToolBar
47  * for example), it will get it's own CoolItem drag handle to move it around.
48  */

49 public class JCoolBar extends JComponent {
50     
51     protected CoolBar ppeer = null;
52     protected boolean pFloatable = true;
53
54     public JCoolBar() {}
55     
56     public Control getPeer() { return ppeer; }
57     
58     /**
59      * Overridden from awt.Container so we can create CoolItems
60      * for each added component
61      */

62     public swingwt.awt.Component add(swingwt.awt.Component c) {
63         
64         // Do the normal add stuff
65
super.add(c);
66         
67         // For each component we add to the coolbar
68
// we need to create a CoolItem and associate it with it.
69
// =====
70
// This is nasty to get your head round, but if neither component
71
// has been created yet, the components will be stored in a buffer
72
// by the superclass. It will call down to this version of the
73
// add method when the time comes to add the components
74
// for real (and the following code becomes active).
75
if (SwingWTUtils.isSWTControlAvailable(c.getPeer())) {
76             CoolItem cool = new CoolItem(ppeer, SWT.NONE);
77             cool.setControl(c.getPeer());
78             cool.setMinimumSize(c.getPeer().computeSize(-1, -1));
79             cool.setSize(c.getPeer().computeSize(-1, -1));
80         }
81         
82         return c;
83     }
84     
85     public boolean isFloatable() { return pFloatable; }
86     public void setFloatable(final boolean b) {
87         pFloatable = b;
88         if (SwingWTUtils.isSWTControlAvailable(ppeer)) {
89             SwingUtilities.invokeSync(new Runnable JavaDoc() {
90                 public void run() {
91                     ppeer.setLocked(!b);
92                 }
93             });
94         }
95     }
96     
97     /** Overridden - layouts are not allowed */
98     public void setLayout(swingwt.awt.LayoutManager l) { }
99     public void setLayout(swingwt.awt.LayoutManager2 l) { }
100     
101     public void setSwingWTParent(swingwt.awt.Container parent) throws Exception JavaDoc {
102         descendantHasPeer = true;
103         ppeer = new CoolBar(parent.getComposite(), SWT.BORDER);
104         peer = ppeer;
105         composite = ppeer;
106         this.parent = parent;
107         ppeer.setLocked(!pFloatable);
108         super.setSwingWTParent(parent);
109     }
110     
111 }
112
Popular Tags