KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > JPanel


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: JPanel.java,v $
11    Revision 1.25 2004/05/07 15:42:47 bobintetley
12    *** empty log message ***
13
14    Revision 1.24 2004/05/07 12:11:18 bobintetley
15    Default layout fixes and correct behaviour for null layout
16
17    Revision 1.23 2004/04/30 23:18:26 dannaab
18    List selection support, misc bug fixes
19
20    Revision 1.22 2004/04/30 13:20:43 bobintetley
21    Fix to unrealised peer preferred sizes, forwarding window events to
22    content panes and fix for mouse drag events.
23
24    Revision 1.21 2004/04/28 08:38:11 bobintetley
25    Hierarchy fixes, code cleanup for base classes, additional javadocs and use of flag to identify JComponent descendants with peers
26
27    Revision 1.20 2004/04/27 06:37:44 bobintetley
28    Corrected hierarchy with JComponent descending Container
29
30    Revision 1.19 2004/04/23 00:52:32 dannaab
31    Handle borders in a Swing-like way. Implement EmptyBorder & TitledBorder
32
33    Revision 1.18 2004/03/30 14:22:27 bobintetley
34    Fix to Component min/max sizing code, fix to JPanel insets with titled
35    borders (all of which indirectly fix problems with BoxLayout). Addition
36    of ComponentAdapter
37
38    Revision 1.17 2004/02/02 12:36:37 bobintetley
39    Proper JScrollPane/ScrollBar implementation
40
41    Revision 1.16 2004/01/27 09:05:11 bobintetley
42    ListModel and List Selection implemented. ScrollPane fix so all components
43       scrollable
44
45    Revision 1.15 2004/01/26 12:02:49 bobintetley
46    JPanel titled border support
47
48    Revision 1.14 2004/01/09 14:48:26 bobintetley
49    Experiments for titled border
50
51    Revision 1.13 2004/01/05 15:29:37 bobintetley
52    TableLayout fixes
53
54    Revision 1.12 2004/01/05 10:09:52 bobintetley
55    Various fixes for new layouts
56
57    Revision 1.11 2003/12/22 11:01:42 bobintetley
58    JPanel resize hints can be given on the fly
59
60    Revision 1.10 2003/12/17 09:03:14 bobintetley
61    Closely matches Swing behaviour + JScrollPane support for Panels
62
63    Revision 1.9 2003/12/16 17:46:17 bobintetley
64    Additional thread safety methods
65
66    Revision 1.8 2003/12/15 18:29:57 bobintetley
67    Changed setParent() method to setSwingWTParent() to avoid conflicts with applications
68
69    Revision 1.7 2003/12/15 15:54:25 bobintetley
70    Additional core methods
71
72    Revision 1.6 2003/12/14 09:13:38 bobintetley
73    Added CVS log to source headers
74
75  */

76
77
78 package swingwtx.swing;
79
80 import org.eclipse.swt.SWT;
81 import org.eclipse.swt.widgets.Composite;
82
83 public class JPanel extends JComponent {
84
85     /** The panel's peer */
86     protected Composite ppeer = null;
87     protected boolean opaque = true;
88
89     /** Creates a new JPanel */
90     public JPanel() {this(false);}
91     /** Creates a new JPanel with the specified buffering scheme
92      * @param isDoubleBuffered Whether or not to double buffer paint callbacks
93      */

94     public JPanel(boolean isDoubleBuffered) { this(new swingwt.awt.FlowLayout(), false); }
95     /** Creates a new JPanel with the specified layout
96      * @param layout The layout manager to use
97      */

98     public JPanel(swingwt.awt.LayoutManager layout) { setLayout(layout); }
99     /** Creates a new JPanel with the specified layout and buffering scheme
100      * @param layout The layout manager to use
101      * @param isDoubleBuffered Whether or not to double buffer paint callbacks
102      */

103     public JPanel(swingwt.awt.LayoutManager layout, boolean isDoubleBuffered) { setLayout(layout); }
104     /** Creates a new JPanel with the specified layout
105      * @param layout The layout manager to use
106      */

107     public JPanel(swingwt.awt.LayoutManager2 layout) { setLayout(layout); }
108     /** Creates a new JPanel with the specified layout and buffering scheme
109      * @param layout The layout manager to use
110      * @param isDoubleBuffered Whether or not to double buffer paint callbacks
111      */

112     public JPanel(swingwt.awt.LayoutManager2 layout, boolean isDoubleBuffered) { setLayout(layout); }
113     /** Overriden to calculate non-realised
114      * preferred size.
115      */

116     protected swingwt.awt.Dimension calculatePreferredSize() {
117         // Default 300x200
118
swingwt.awt.Dimension size = new swingwt.awt.Dimension(300, 200);
119         setSize(size);
120         return size;
121     }
122     
123     /** Callback for when this is added to a Container to create the
124      * peer and load cached values.
125      */

126     public void setSwingWTParent(swingwt.awt.Container parent) throws Exception JavaDoc {
127         descendantHasPeer = true;
128         ppeer = new Composite(parent.getComposite(), SWT.NONE);
129         peer = ppeer;
130         composite = ppeer;
131         this.parent = parent;
132         super.setSwingWTParent(parent);
133     }
134
135     /** Sets the border for the Panel
136      * @param b The new border
137      */

138     public void setBorder(swingwtx.swing.border.Border b) {
139         border = b;
140     }
141
142     /**
143      * Return how large this panel would like to be if it's inside a ScrollPane, rather
144      * than how large it actually is. This is used by layout managers when determining
145      * how to layout the components. If you need the actual size of a JPanel in
146      * a scroll pane, use getPeerSize() which always return the
147      * correct values.
148      */

149     public swingwt.awt.Dimension getSize() {
150         if (parent instanceof JScrollPane)
151             return getPreferredSize();
152         else
153             return super.getSize();
154     }
155     /** Returns the width of the peer
156      * @return the width
157      */

158     public int getWidth() { return getSize().width; }
159     /** Returns the height of the peer
160      * @return the height
161      */

162     public int getHeight() { return getSize().height; }
163
164 }
165
Popular Tags