xref: /titanic_41/usr/src/cmd/krb5/kadmin/gui/visualrt/sunsoft/jws/visual/rt/awt/GBPanel.java (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * ident	"%Z%%M%	%I%	%E% SMI"
24  *
25  * Copyright (c) 2000 by Sun Microsystems, Inc.
26  * All rights reserved.
27  */
28 
29 /*
30  *        Copyright (C) 1996  Active Software, Inc.
31  *                  All rights reserved.
32  *
33  * @(#) GBPanel.java 1.35 - last change made 06/17/97
34  */
35 
36 package sunsoft.jws.visual.rt.awt;
37 
38 import sunsoft.jws.visual.rt.base.Global;
39 
40 import sunsoft.jws.visual.rt.base.*;
41 import java.awt.*;
42 
43 public class GBPanel extends VJPanel {
44 
45     private static Class gbclass;
46 
47     private boolean runtime = true;
48     private GBContainer cntr;
49     private GBLayout mgr;
50 
GBPanel()51     public GBPanel() {
52         setLayout(new GBLayout());
53     }
54 
handleEvent(Event evt)55     public boolean handleEvent(Event evt) {
56         if (cntr != null)
57             return cntr.handleEvent(evt);
58         else
59             return super.handleEvent(evt);
60     }
61 
setRuntime(boolean rt)62     public void setRuntime(boolean rt) {
63         if (runtime == rt)
64             return;
65 
66         runtime = rt;
67 
68         if (runtime) {
69             cntr.setGBPanel(null);
70             cntr = null;
71         } else {
72             if (gbclass == null)
73                 gbclass = DesignerAccess.getGBPanelClass();
74 
75             try {
76                 cntr = (GBContainer)gbclass.newInstance();
77             }
78             catch (IllegalAccessException ex) {
79                 throw new Error(ex.toString());
80             }
81             catch (InstantiationException ex) {
82                 throw new Error(ex.toString());
83             }
84 
85             cntr.setGBPanel(this);
86         }
87     }
88 
getGBContainer()89     public GBContainer getGBContainer() {
90         return cntr;
91     }
92 
93     //
94     // Special hack for flow layout so that it
95     // can re-adjust its vertical
96     // size based on the horizontal space available.
97     // This method is needed
98     // to make the flow layout take up more space
99     // vertically when it runs
100     // short on horizontal space.
101     //
layout()102     public void layout() {
103         boolean hasFlow = false;
104         int count = countComponents();
105         GBLayout gridbag = (GBLayout)getLayout();
106         Component comp;
107         LayoutManager mgr;
108 
109         for (int i = 0; i < count; i++) {
110             comp = getComponent(i);
111             if (comp instanceof Container) {
112                 mgr = ((Container)comp).getLayout();
113                 if (mgr instanceof VJFlowLayout) {
114                     hasFlow = true;
115                     ((VJFlowLayout)mgr).setMinimumWidth(0);
116                 }
117             }
118         }
119 
120         if (hasFlow) {
121             gridbag.layoutContainerNoReshape(this);
122 
123             for (int i = 0; i < count; i++) {
124                 comp = getComponent(i);
125                 if (comp instanceof Container) {
126                     mgr = ((Container)comp).getLayout();
127                     if (mgr instanceof VJFlowLayout) {
128                         GBConstraints c = gridbag.getConstraints(comp);
129                         if (c.size != null)
130                             ((VJFlowLayout)mgr).setMinimumWidth(
131 								c.size.width);
132                     }
133                 }
134             }
135         }
136 
137         super.layout();
138 
139         if (hasFlow) {
140             for (int i = 0; i < count; i++) {
141                 comp = getComponent(i);
142                 if (comp instanceof Container) {
143                     mgr = ((Container)comp).getLayout();
144                     if (mgr instanceof VJFlowLayout) {
145                         ((VJFlowLayout)mgr).setMinimumWidth(0);
146                     }
147                 }
148             }
149         }
150 
151         if (cntr != null)
152             cntr.layout();
153     }
154 
155     //
156     // Forwarding of container methods
157     //
158 
setLayout(LayoutManager mgr)159     public void setLayout(LayoutManager mgr) {
160         if (cntr != null)
161             cntr.setLayout(mgr);
162         else
163             super.setLayout(mgr);
164         updateLayout();
165     }
166 
setLayoutSuper(LayoutManager mgr)167     public void setLayoutSuper(LayoutManager mgr) {
168         super.setLayout(mgr);
169         updateLayout();
170     }
171 
updateLayout()172     private void updateLayout() {
173         LayoutManager m = getLayout();
174         if (m instanceof GBLayout)
175             mgr = (GBLayout)m;
176         else
177             mgr = null;
178     }
179 
180     // #ifdef JDK1.1
addImpl(Component comp, Object constraints, int index)181     protected void addImpl(Component comp, Object constraints,
182 			   int index) {
183         super.addImpl(comp, constraints, index);
184         doAdd(comp);
185     }
186     // #else
187     // public Component add(Component comp, int pos) {
188     //   super.add(comp, pos);
189     //   doAdd(comp);
190     //   return comp;
191     // }
192     // #endif
193 
194 
doAdd(Component comp)195     private void doAdd(Component comp) {
196         if (cntr != null)
197             cntr.add(comp);
198     }
199 
remove(Component comp)200     public void remove(Component comp) {
201         super.remove(comp);
202         if (cntr != null)
203             cntr.remove(comp);
204     }
205 
removeAll()206     public void removeAll() {
207         super.removeAll();
208         if (cntr != null)
209             cntr.removeAll();
210     }
211 
update(Graphics g)212     public void update(Graphics g) {
213         if (Global.isWindows())
214             g = getGraphics();
215 
216         if (cntr != null)
217             cntr.update(g);
218 
219         super.update(g);
220     }
221 
paint(Graphics g)222     public void paint(Graphics g) {
223         if (Global.isWindows())
224             g = getGraphics();
225 
226         if (cntr != null)
227             cntr.paint(g);
228 
229         super.paint(g);
230     }
231 
reshape(int x, int y, int w, int h)232     public void reshape(int x, int y, int w, int h) {
233         super.reshape(x, y, w, h);
234         if (cntr != null)
235             cntr.reshape(x, y, w, h);
236     }
237 
238     //
239     // Layout and Preview modes
240     //
241 
layoutMode()242     public void layoutMode() {
243         if (cntr != null)
244             cntr.layoutMode();
245     }
246 
previewMode()247     public void previewMode() {
248         if (cntr != null)
249             cntr.previewMode();
250     }
251 
252     //
253     // Constraints
254     //
255 
setConstraints(Component comp, GBConstraints c)256     public void setConstraints(Component comp, GBConstraints c) {
257         if (c == null)
258             /* JSTYLED */
259 	    throw new Error(Global.getMsg("sunsoft.jws.visual.rt.awt.GBPanel.null__constraints"));
260 
261         if (cntr != null)
262             cntr.setConstraints(comp, c);
263         else if (mgr != null)
264             mgr.setConstraints(comp, c);
265     }
266 
getConstraints(Component comp)267     public GBConstraints getConstraints(Component comp) {
268         if (cntr != null)
269             return cntr.getConstraints(comp);
270         else if (mgr != null)
271             return mgr.getConstraints(comp);
272         else
273             return null;
274     }
275 
276     //
277     // GBLayout attributes
278     //
279 
setColumnWeights(double w[])280     public void setColumnWeights(double w[]) {
281         if (cntr != null)
282             cntr.setColumnWeights(w);
283         else if (mgr != null)
284             mgr.columnWeights = w;
285     }
286 
setRowWeights(double w[])287     public void setRowWeights(double w[]) {
288         if (cntr != null)
289             cntr.setRowWeights(w);
290         else if (mgr != null)
291             mgr.rowWeights = w;
292     }
293 
getColumnWeights()294     public double [] getColumnWeights() {
295         if (cntr != null)
296             return cntr.getColumnWeights();
297         else if (mgr != null)
298             return mgr.columnWeights;
299         else
300             return null;
301     }
302 
getRowWeights()303     public double [] getRowWeights() {
304         if (cntr != null)
305             return cntr.getRowWeights();
306         else if (mgr != null)
307             return mgr.rowWeights;
308         else
309             return null;
310     }
311 
setColumnWidths(int w[])312     public void setColumnWidths(int w[]) {
313         if (cntr != null)
314             cntr.setColumnWidths(w);
315         else if (mgr != null)
316             mgr.columnWidths = w;
317     }
318 
setRowHeights(int h[])319     public void setRowHeights(int h[]) {
320         if (cntr != null)
321             cntr.setRowHeights(h);
322         else if (mgr != null)
323             mgr.rowHeights = h;
324     }
325 
getColumnWidths()326     public int[] getColumnWidths() {
327         if (cntr != null)
328             return cntr.getColumnWidths();
329         else if (mgr != null)
330             return mgr.columnWidths;
331         else
332             return null;
333     }
334 
getRowHeights()335     public int[] getRowHeights() {
336         if (cntr != null)
337             return cntr.getRowHeights();
338         else if (mgr != null)
339             return mgr.rowHeights;
340         else
341             return null;
342     }
343 }
344