xref: /titanic_41/usr/src/cmd/krb5/kadmin/gui/visualrt/sunsoft/jws/visual/rt/shadow/java/awt/WindowShadow.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  * @(#) WindowShadow.java 1.119 - last change made 07/28/97
34  */
35 
36 package sunsoft.jws.visual.rt.shadow.java.awt;
37 
38 import sunsoft.jws.visual.rt.base.*;
39 import sunsoft.jws.visual.rt.awt.*;
40 import sunsoft.jws.visual.rt.type.AnchorEnum;
41 import sunsoft.jws.visual.rt.base.Global;
42 
43 import java.util.*;
44 import java.awt.*;
45 
46 /* BEGIN JSTYLED */
47 /**
48  * Wraps an AWT widget.  The attributes available for this
49  * class are listed below.  In the type column, type names beginning
50  * with "sunsoft.jws.visual.rt" have been abbreviated to begin with "rt".
51  *
52  * <pre>
53  name            type                      default value
54  -----------------------------------------------------------------------
55  location        java.awt.Point            null
56  size            java.awt.Dimension        null
57  *  < /pre>
58 *
59 * location: location for the window, if the location is set before
60 * the window is mapped, then when the window is mapped, it will come
61 * up at the specified location.  If the location is set while the
62 * window is mapped, then window will immediately be moved to the new
63 * location.
64 *  < p>
65 * size: desired size for the window, if set before mapping, the
66 * window will later be mapped with this size.  However, the size
67 * dimensions are first checked to ensure that the dimensions are at
68 * least as big as the preferredSize. If set after mapping and
69 * non-null, the window will be resized to the new size after maxing
70 * with preferredSize.  "get" returns the value for the desired size,
71 * NOT the actual size of the window. The "size" attribute does not
72 * take effect when in layout mode.
73 *  < p>
74 * Check the super class for additional attributes.
75 *
76 * @see Window
77 * @version 1.119, 07/28/97
78 */
79 /* END JSTYLED */
80 
81 public class WindowShadow extends ContainerShadow {
82     private static final int PADX = 100;
83     private static final int PADY = 100;
84 
85     private static Point defaultLocation = new Point(100, 100);
86     private static Dimension defaultSize = new Dimension(100, 100);
87 
88     private boolean packed = false;
89 
setDefaultLocation(Point p)90     public static void setDefaultLocation(Point p) {
91         defaultLocation = p;
92     }
93 
getDefaultLocation()94     public static Point getDefaultLocation() {
95         return defaultLocation;
96     }
97 
setDefaultSize(Dimension d)98     public static void setDefaultSize(Dimension d) {
99         defaultSize = d;
100     }
101 
getDefaultSize()102     public static Dimension getDefaultSize() {
103         return defaultSize;
104     }
105 
106     private boolean layoutMode = false;
107 
WindowShadow()108     public WindowShadow() {
109         attributes.remove(/* NOI18N */"GBConstraints");
110         attributes.remove(/* NOI18N */"borderName");
111         attributes.remove(/* NOI18N */"flowRank");
112         attributes.remove(/* NOI18N */"anchor");
113         attributes.remove(/* NOI18N */"insets");
114 
115         attributes.add(/* NOI18N */"visible",
116 		       /* NOI18N */"java.lang.Boolean", Boolean.TRUE, NONBODY);
117 
118         attributes.add(/* NOI18N */"location",
119 		       /* NOI18N */"java.awt.Point", null, 0);
120         attributes.add(/* NOI18N */"layoutLocation",
121 		       /* NOI18N */"java.awt.Point", null, HIDDEN);
122         attributes.add(/* NOI18N */"currentLocation",
123 		       /* NOI18N */"java.awt.Point", null,
124 		       HIDDEN | TRANSIENT | READONLY);
125 
126         attributes.add(/* NOI18N */"size",
127 		       /* NOI18N */"java.awt.Dimension", null, 0);
128         attributes.add(/* NOI18N */"layoutSize",
129 		       /* NOI18N */"java.awt.Dimension", null, HIDDEN);
130         attributes.add(/* NOI18N */"currentSize",
131 		       /* NOI18N */"java.awt.Dimension", null,
132 		       HIDDEN | TRANSIENT | READONLY);
133     }
134 
useLayoutLocation()135     protected boolean useLayoutLocation() {
136         if (!layoutMode)
137             return false;
138 
139         if (inDesignerRoot())
140 	    return true;
141 
142         Group g = getGroup();
143         if (g == null)
144             return false;
145 
146         if (DesignerAccess.getWindow(g) != this)
147 	    return false;
148 
149         return (g.inDesignerRoot());
150     }
151 
useLayoutSize()152     protected boolean useLayoutSize() {
153         return (layoutMode && inDesignerRoot());
154     }
155 
getOnBody(String key)156     protected Object getOnBody(String key) {
157         Window win = (Window)body;
158 
159         if (key.equals(/* NOI18N */"location")) {
160             return getFromTable(key);
161         } else if (key.equals(/* NOI18N */"layoutLocation")) {
162             if (useLayoutLocation()) {
163                 // fix for Sun bug #4037679: layout window locations
164                 // are not being remembered. This is because
165                 // win.location() returns the location that the window
166                 // was created with, rather than the screen location.
167                 // So if the window moved, the location() method
168                 // doesn't report the new location. However,
169                 // locationOnScreen() only works if the window is
170                 // actually showing. Otherwise it throws an exception.
171                 //   -- Simran. 5/7/97
172                 Point loc;
173                 try {
174                     loc = win.getLocationOnScreen();
175                 } catch (IllegalComponentStateException e) {
176                     loc = win.getLocation();
177                 }
178 
179                 return loc;
180             } else
181                 return getFromTable(key);
182         } else if (key.equals(/* NOI18N */"currentLocation")) {
183             return win.location();
184         } else if (key.equals(/* NOI18N */"size")) {
185             return getFromTable(key);
186         } else if (key.equals(/* NOI18N */"layoutSize")) {
187             if (useLayoutSize())
188 		return win.size();
189             else
190                 return getFromTable(key);
191         } else if (key.equals(/* NOI18N */"currentSize")) {
192             return win.size();
193         } else {
194             return super.getOnBody(key);
195         }
196     }
197 
setOnBody(String key, Object value)198     protected void setOnBody(String key, Object value) {
199         Window win = (Window)body;
200 
201         if (key.equals(/* NOI18N */"location")) {
202             putInTable(key, value);
203             if (value != null && !useLayoutLocation()) {
204                 Point p = getWindowLocation(false);
205                 win.move(p.x, p.y);
206             }
207         } else if (key.equals(/* NOI18N */"layoutLocation")) {
208             putInTable(key, value);
209             if (value != null && useLayoutLocation()) {
210                 Point p = getWindowLocation(true);
211                 win.move(p.x, p.y);
212             }
213         } else if (key.equals(/* NOI18N */"size")) {
214             putInTable(key, value);
215             if (value != null && !useLayoutSize())
216 		win.resize(getWindowSize(win, false));
217         } else if (key.equals(/* NOI18N */"layoutSize")) {
218             putInTable(key, value);
219             if (value != null && useLayoutSize())
220 		win.resize(getWindowSize(win, true));
221         } else {
222             super.setOnBody(key, value);
223         }
224     }
225 
226     // REMIND: if Window had a frame attribute like a dialog it could be
227     // instantiated here (but would probably only work on Windows 96 at
228     // the moment)
createBody()229     public void createBody() {};
230 
registerBody()231     protected void registerBody() {
232         Window win = (Window)body;
233         if (!(win.getLayout() instanceof GBLayout)) {
234             GBLayout gridbag = new GBLayout();
235             double w[] = {1};
236             gridbag.columnWeights = w;
237             gridbag.rowWeights = w;
238 
239             win.setLayout(gridbag);
240         }
241 
242         super.registerBody();
243     }
244 
postCreate()245     protected void postCreate() {
246         super.postCreate();
247 
248         if (body instanceof RootWindow) {
249             if (layoutMode)
250                 ((RootWindow)body).layoutMode();
251             else
252                 ((RootWindow)body).previewMode();
253         }
254 
255         if (!doingShow())
256 	    showComponent(isVisible());
257     }
258 
preDestroy()259     protected void preDestroy() {
260         packed = false;
261     }
262 
263     /**
264      * Returns true if the window's group is currently visible,
265      * and the window's visible attribute is set to true.
266      */
isVisible()267     public boolean isVisible() {
268         if (!hasAttribute(/* NOI18N */"visible"))
269 	    return false;
270 
271         Boolean v = (Boolean) getFromTable(/* NOI18N */"visible");
272         if (!v.booleanValue())
273 	    return false;
274 
275         Group g = getRoot().getGroup();
276         if (g != null)
277             return g.isShowing();
278 
279         return true;
280     }
281 
updateContainerAttribute(AttributeManager child, String key, Object value)282     public void updateContainerAttribute(AttributeManager child,
283 					 String key, Object value) {
284         if (key.equals(/* NOI18N */"anchor")) {
285             GBConstraints c =
286 		(GBConstraints)child.get(/* NOI18N */"GBConstraints");
287             if (c == null)
288                 return;
289 
290             int anchor = ((AnchorEnum)value).intValue();
291             if (anchor != c.anchor) {
292                 c.anchor = anchor;
293                 child.set(/* NOI18N */"GBConstraints", c);
294             }
295         } else if (key.equals(/* NOI18N */"insets")) {
296             GBConstraints c =
297 		(GBConstraints)child.get(/* NOI18N */"GBConstraints");
298             if (c == null)
299                 return;
300 
301             Insets insets = (Insets)value;
302             if (c.insets != insets) {
303                 c.insets = insets;
304                 child.set(/* NOI18N */"GBConstraints", c);
305             }
306         } else if (key.equals(/* NOI18N */"GBConstraints")) {
307             GBConstraints c = (GBConstraints)value;
308             if (c == null)
309                 c = new GBConstraints();
310 
311             Shadow s = (Shadow)child;
312             Component comp = (Component)s.getBody();
313             if (comp == null)
314                 return;
315 
316             int anchor =
317 		((AnchorEnum)child.get(/* NOI18N */"anchor")).intValue();
318             c.anchor = anchor;
319             c.insets = (Insets)child.get(/* NOI18N */"insets");
320 
321             GBLayout gb = (GBLayout)((Window)body).getLayout();
322             gb.setConstraints(comp, c);
323         }
324     }
325 
pack()326     public void pack() {
327         checkCreate();
328 
329         // Get the body AFTER the call to checkCreate
330         Window win = (Window)body;
331 
332         boolean hasPeer = (win.getPeer() != null);
333 
334         if (!hasPeer) {
335             //
336             // Workaround for SGI: When a frame is shown with size
337             // (0,0), it will fill the entire screen area momentarily
338             // until reshape is called.  This causes annoying
339             // flickering behavior.
340             //
341             if (Global.isIrix()) {
342                 Dimension size = win.size();
343                 if (size.width == 0 || size.height == 0)
344                     win.reshape(0, 0, 40, 40);
345             }
346 
347             win.addNotify();
348 
349             Group g = getGroup();
350             if (g != null && DesignerAccess.getWindow(g) == this)
351 		DesignerAccess.preValidate(g);
352 
353             preValidate();
354         }
355 
356         // Reshape the window
357         resizePreferredSize(win, hasPeer);
358 
359         // Validate the window.
360         win.validate();
361 
362         // Set the packed flag to true
363         packed = true;
364     }
365 
366     /**
367      * Shows the component.  Calling showComponent does not affect the
368      * value of the visible attrbute.  You should use "show" instead of
369      * "showComponent".  The only reason this method exists is that
370      * Visual Java needs to use it in certain situations.
371      */
showComponent()372     public void showComponent() {
373         checkCreate();
374 
375         // Pack the window if necessary
376         Window win = (Window)body;
377 
378         if (packed && win.getPeer() == null)
379 	    packed = false;
380 
381         if (!packed)
382             pack();
383 
384         // Show the window
385         win.show();
386 
387         // Usually, calling show() on a visible Window will bring it
388         // to the front.  Unfortunately, it doesn't behave like this.
389         if (Global.isWindows()) {
390             win.toFront();
391         }
392 
393         // Make sure the window shows up right away.  This tends to make
394         // the user happier.
395         win.getToolkit().sync();
396     }
397 
checkCreate()398     protected void checkCreate() {
399         // Call create if it hasn't already been called.
400         if (!isCreated()) {
401             doingShow = true;
402             create();
403             doingShow = false;
404         }
405     }
406 
resizePreferredSize(Window win, boolean hasPeer)407     private void resizePreferredSize(Window win, boolean hasPeer) {
408         Point location = getWindowLocation(useLayoutLocation());
409         Dimension size = getWindowSize(win, useLayoutSize());
410 
411         constrainToScreen(win, location, size);
412 
413         if (win instanceof Dialog) {
414             // Adjust the location the first time the dialog is mapped
415             // after the peer has been created.  There is an AWT bug
416             // that screws up the location of the dialog, so we have
417             // to make this adjustment.
418             if (Global.isMotif() && !hasPeer) {
419                 location.x -= size.width/2;
420                 location.y -= size.height/2;
421             }
422 
423             win.reshape(location.x, location.y, size.width, size.height);
424         } else {
425             if (hasPeer)
426                 win.resize(size.width, size.height);
427             else
428                 win.reshape(location.x, location.y, size.width, size.height);
429         }
430     }
431 
getDialogLocation(Dialog dialog)432     private Point getDialogLocation(Dialog dialog) {
433         Frame frame = (Frame)dialog.getParent();
434         Point p = frame.location();
435         Dimension fsize = frame.size();
436         Dimension dsize = dialog.preferredSize();
437 
438         p.x += (fsize.width - dsize.width)/2;
439         p.y += (fsize.height - dsize.height)/2;
440 
441         return p;
442     }
443 
getWindowLocation(boolean layoutLocation)444     private Point getWindowLocation(boolean layoutLocation) {
445         if (body instanceof Dialog)
446             return getDialogLocation((Dialog)body);
447 
448         ContainerShadow panel = getPanel();
449         Point location = null;
450 
451         if (layoutLocation) {
452             if (panel != null)
453                 location = (Point) panel.get(/* NOI18N */"layoutLocation");
454             else
455                 location = (Point) getFromTable(/* NOI18N */"layoutLocation");
456 
457             if (location == null)
458                 location = getDefaultLocation();
459         } else {
460             location = (Point) getFromTable(/* NOI18N */"location");
461 
462             if (location == null)
463                 location = getDefaultLocation();
464         }
465 
466         return location;
467     }
468 
getWindowSize(Window win, boolean layoutSize)469     private Dimension getWindowSize(Window win, boolean layoutSize) {
470         ContainerShadow panel = getPanel();
471         Dimension size;
472 
473         if (layoutSize) {
474             if (panel != null)
475                 size = (Dimension) panel.get(/* NOI18N */"layoutSize");
476             else
477                 size = (Dimension) getFromTable(/* NOI18N */"layoutSize");
478 
479             if (size == null)
480                 size = getDefaultSize();
481         } else {
482             Dimension prefSize = win.preferredSize();
483             size = (Dimension) getFromTable(/* NOI18N */"size");
484 
485             if (size == null) {
486                 size = prefSize;
487             } else {
488                 size.width = Math.max(size.width, prefSize.width);
489                 size.height = Math.max(size.height, prefSize.height);
490             }
491         }
492 
493         return size;
494     }
495 
constrainToScreen(Window win, Point location, Dimension size)496     private void constrainToScreen(Window win, Point location, Dimension size) {
497         // Constrain the window to fit on the screen
498         Dimension screenSize = getScreenSize(win);
499 
500         int x = screenSize.width - size.width;
501         if (location.x > x)
502             location.x = x;
503         if (location.x < 0)
504             location.x = 0;
505 
506         int y = screenSize.height - size.height;
507         if (location.y > y)
508             location.y = y;
509         if (location.y < 0)
510             location.y = 0;
511 
512         int width = screenSize.width - location.x;
513         if (size.width > width)
514             size.width = width;
515 
516         int height = screenSize.height - location.y;
517         if (size.height > height)
518             size.height = height;
519     }
520 
getScreenSize(Window win)521     private Dimension getScreenSize(Window win) {
522         Dimension d = win.getToolkit().getScreenSize();
523         d.width -= 6;
524         d.height -= 6;
525 
526         if (Global.isWindows95()) {
527             // Subtract some extra space for the icon bar
528             d.height -= 30;
529         }
530 
531         return d;
532     }
533 
recurseInvalidate(Component comp)534     private void recurseInvalidate(Component comp) {
535         comp.invalidate();
536         if (comp instanceof Container) {
537             Container cntr = (Container)comp;
538             int count = cntr.countComponents();
539             for (int i = 0; i < count; i++)
540                 recurseInvalidate(cntr.getComponent(i));
541         }
542     }
543 
544     /**
545      * Disposes of the AWT top-level window so that window system
546      * resources are reclaimed.
547      */
destroyBody()548     protected void destroyBody() {
549         //
550         // Cache the location when the window is destroyed.
551         //
552         // "put" is called directly because "set" won't work if
553         // "isPanel" is true.
554         //
555         if (useLayoutLocation()) {
556             Point location = ((Window)body).location();
557             putInTable(/* NOI18N */"layoutLocation", location);
558         }
559 
560         ((Window)body).dispose();
561         body = null;
562     }
563 
564     /**
565      * "isPanel" flag.  If this flag is set, then this frame exists only
566      * to allow the panel to be edited in the builder.  When a saving or
567      * generation is performed, this window should be omitted.
568      */
569 
570     private boolean isPanel = false;
571     private String prevTitle = /* NOI18N */"Unnamed Window";
572 
isPanel()573     public boolean isPanel() {
574         return isPanel;
575     }
576 
isPanel(boolean isPanel)577     public void isPanel(boolean isPanel) {
578         if (this.isPanel != isPanel) {
579             if (isPanel) {
580                 prevTitle = (String)get(/* NOI18N */"title");
581                 set(/* NOI18N */"title", /* NOI18N */"PANEL");
582                 this.isPanel = isPanel;		// this must be last
583             } else {
584                 // Ordering is important here.  As soon as isPanel is
585                 // changed, the nature of this window changes (and
586                 // affects the isUniqueName call, for example.)  While
587                 // isPanel is still true, get("name") returns the name
588                 // of the surrounded panel.
589                 //
590                 this.isPanel = isPanel;		// this must be first
591 
592                 // It is possible that a new frame has been imported
593                 // or created that has the same name as this one (that
594                 // was surrounding a panel and was invisible in the
595                 // hierarchy.)  Until a frame has isPanel set to
596                 // false, it is never included in a unique name check,
597                 // so make sure that the window's name is unique in
598                 // the Root tree.  If the frame isn't in a Root tree
599                 // then don't worry about it.
600                 //
601                 if (getRoot() != null) {
602                     String name = (String) get(/* NOI18N */"name");
603                     if ((name == null)
604                         || !DesignerAccess.isUniqueName(getRoot(), name, this))
605 			set(/* NOI18N */"name",
606 			    DesignerAccess.getUniqueName(getRoot(), this));
607                 }
608 
609                 set(/* NOI18N */"title", prevTitle);
610             }
611         }
612     }
613 
614     /**
615      * If the "isPanel" flag is set, all the attributes should come from
616      * the child panel, not the frame.
617      */
618 
getPanel()619     public ContainerShadow getPanel() {
620         if (!isPanel)
621             return null;
622 
623         if (getChildCount() == 0)
624 	    return null;
625 
626         return (ContainerShadow)getChildList().nextElement();
627     }
628 
629     // Bug 4054883 Mark Davison July 9, 1997
630     // The next series of methods are implemented as a work around in which
631     // attributes are set on the VJLayout frame instead of the GBPanel
632     // if isPanel == false. This is just a quick and safe fix. The real solution
633     // is to get rid of the isPanel flag and associated behaviour altogether.
634 
635     private static Class enclosingFrame = null;
636 
637     /**
638      * Caching method which returns the enclosing frame (most likely VJLayout)
639      */
getEnclosingFrameClass()640     private Class getEnclosingFrameClass() {
641         if (enclosingFrame == null)
642             enclosingFrame = DesignerAccess.getFrameClass();
643 
644         return enclosingFrame;
645     }
646 
647     /**
648      * Tests to see if the object is an enclosing frame.
649      */
isEnclosingFrame(Object obj)650     private boolean isEnclosingFrame(Object obj) {
651         Class frame = getEnclosingFrameClass();
652         if (frame != null && frame.isInstance(body))
653 	    return true;
654         else
655             return false;
656     }
657 
658     /**
659      * Puts the attribute on the enclosed PanelShadow rather than on the
660      * WindowShadow.
661      * This bypasses the getPanel method because if VJLayout represents
662      * a Frame
663      * or Dialog, the attributes will be set on the VJLayout (which
664      * is incorrect).
665      */
setOnPanel(String key, Object value)666     protected void setOnPanel(String key, Object value) {
667         ContainerShadow panel = (ContainerShadow)getChildList().nextElement();
668         if (panel != null && panel instanceof PanelShadow)
669             panel.set(key, value);
670     }
671 
672     /**
673      * Retrieves the attributes from the panel thereby bypassing the
674      * isPanel flag.
675      */
getOnPanel(String key)676     protected Object getOnPanel(String key) {
677         ContainerShadow panel = (ContainerShadow)getChildList().nextElement();
678         if (panel != null && panel instanceof PanelShadow)
679             return panel.get(key);
680         return null;
681     }
682 
set(String key, Object value)683     public void set(String key, Object value) {
684         ContainerShadow panel = getPanel();
685 
686         if (panel != null &&
687 	    !key.equals(/* NOI18N */"location") &&
688 	    !key.equals(/* NOI18N */"layoutLocation") &&
689 	    !key.equals(/* NOI18N */"size") &&
690 	    !key.equals(/* NOI18N */"layoutSize")) {
691             panel.set(key, value);
692         } else if (key.equals(/* NOI18N */"visible")) {
693             if (!hasAttribute(/* NOI18N */"visible"))
694 		return;
695 
696             Boolean oldValue, newValue;
697 
698             oldValue = (Boolean)get(/* NOI18N */"visible");
699             newValue = (Boolean)value;
700 
701             // Don't let visible be set to false if we are the main
702             // container and we are running inside vjava.
703             if (inDesignerRoot() && isMainContainer()
704 		&& !newValue.booleanValue()) {
705 		    /* JSTYLED */
706                 throw new VJException(Global.getMsg("sunsoft.jws.visual.rt.awt.java.awt.WindowShadow.IllegalSetVisible"));
707             }
708 
709             super.set(key, value);
710 
711             if (!doingShow()) {
712                 if (oldValue.booleanValue() != newValue.booleanValue()) {
713                     showComponent(isVisible());
714                 }
715             }
716         } else {
717             // If the body is an enclosing frame, the atributes should not be
718             // set on the body.
719             if (isEnclosingFrame(body)) {
720                 if (key.equals(/* NOI18N */"background") ||
721 		    key.equals(/* NOI18N */"foreground")) {
722                     setOnPanel(key, value);
723                     return;
724                 }
725             }
726 
727             super.set(key, value);
728         }
729     }
730 
get(String key)731     public Object get(String key) {
732         ContainerShadow panel = getPanel();
733         if (panel != null &&
734 	    !key.equals(/* NOI18N */"location") &&
735 	    !key.equals(/* NOI18N */"layoutLocation") &&
736 	    !key.equals(/* NOI18N */"size") &&
737 	    !key.equals(/* NOI18N */"layoutSize"))
738 	    return panel.get(key);
739         else {
740             // If the body is an enclosing frame, the atributes should
741             // be retrieved from the panel.
742             if (isEnclosingFrame(body)) {
743                 if (key.equals(/* NOI18N */"background") ||
744 		    key.equals(/* NOI18N */"foreground"))
745 		    return getOnPanel(key);
746             }
747 
748             return super.get(key);
749         }
750     }
751 
getType(String key)752     public String getType(String key) {
753         ContainerShadow panel = getPanel();
754         if (panel != null)
755             return panel.getType(key);
756         else
757             return super.getType(key);
758     }
759 
getFlags(String key)760     public int getFlags(String key) {
761         ContainerShadow panel = getPanel();
762         if (panel != null)
763             return panel.getFlags(key);
764         else
765             return super.getFlags(key);
766     }
767 
hasAttribute(String key)768     public boolean hasAttribute(String key) {
769         ContainerShadow panel = getPanel();
770         if (panel != null)
771             return panel.hasAttribute(key);
772         else
773             return super.hasAttribute(key);
774     }
775 
hasAttribute(String key, String type)776     public boolean hasAttribute(String key, String type) {
777         ContainerShadow panel = getPanel();
778         if (panel != null)
779             return panel.hasAttribute(key, type);
780         else
781             return super.hasAttribute(key, type);
782     }
783 
getAttributeList()784     public AttributeList getAttributeList() {
785         ContainerShadow panel = getPanel();
786         if (panel != null)
787             return panel.getAttributeList();
788         else
789             return super.getAttributeList();
790     }
791 
refetchAttributeList()792     public void refetchAttributeList() {
793         ContainerShadow panel = getPanel();
794         if (panel != null)
795             panel.refetchAttributeList();
796         else
797             super.refetchAttributeList();
798     }
799 
layoutMode()800     public void layoutMode() {
801         super.layoutMode();
802         setLayout(true);
803     }
804 
previewMode()805     public void previewMode() {
806         super.previewMode();
807         setPreview(true);
808     }
809 
setLayout(boolean shouldResize)810     public void setLayout(boolean shouldResize) {
811         if (layoutMode)
812             return;
813 
814         layoutMode = true;
815 
816         if (body != null) {
817             Window win = (Window)body;
818 
819             if (body instanceof RootWindow)
820                 ((RootWindow)body).layoutMode();
821 
822             if (shouldResize) {
823                 if (win.getPeer() != null) {
824                     if (useLayoutLocation() || useLayoutSize()) {
825                         Point p = getWindowLocation(useLayoutLocation());
826                         Dimension d = getWindowSize(win, useLayoutSize());
827                         win.reshape(p.x, p.y, d.width, d.height);
828                     }
829                 }
830 
831                 win.validate();
832             }
833         }
834     }
835 
setPreview(boolean shouldResize)836     public void setPreview(boolean shouldResize) {
837         if (!layoutMode)
838             return;
839 
840         if (body != null) {
841             Window win = (Window)body;
842 
843             if (win instanceof RootWindow)
844                 ((RootWindow)win).previewMode();
845 
846             if (shouldResize) {
847                 if (win.getPeer() != null) {
848                     if (useLayoutLocation()) {
849                         putInTable(/* NOI18N */"layoutLocation",
850 				   win.location());
851                     }
852                     if (useLayoutSize()) {
853                         putInTable(/* NOI18N */"layoutSize", win.size());
854                     }
855 
856                     if (useLayoutLocation() || useLayoutSize()) {
857                         // fix for bug id 1263220 -kp commented out
858                         // was in their originally
859                         //	    Point p = getWindowLocation(false);
860                         Point p = getWindowLocation(useLayoutLocation());
861                         Dimension d = getWindowSize(win, false);
862                         constrainToScreen(win, p, d);
863                         win.reshape(p.x, p.y, d.width, d.height);
864                     }
865                 }
866 
867                 win.validate();
868             }
869         }
870 
871         layoutMode = false;
872     }
873 
previewSize()874     public Dimension previewSize() {
875         boolean isLayout = layoutMode;
876 
877         if (isLayout) {
878             setPreview(false);
879             super.previewMode();
880         }
881 
882         Dimension size = ((Window)body).preferredSize();
883         size = new Dimension(size.width, size.height);
884 
885         if (isLayout) {
886             setLayout(false);
887             super.layoutMode();
888         }
889 
890         return size;
891     }
892 
handleEvent(Message msg, Event evt)893     public boolean handleEvent(Message msg, Event evt) {
894         if (msg.target == this && evt.id == Event.WINDOW_MOVED) {
895             ContainerShadow panel = getPanel();
896             if (panel != null) {
897                 boolean dirty = DesignerAccess.getChangesMade();
898                 panel.set(/* NOI18N */"layoutLocation",
899 			  get(/* NOI18N */"layoutLocation"));
900                 panel.set(/* NOI18N */"layoutSize",
901 			  get(/* NOI18N */"layoutSize"));
902                 DesignerAccess.setChangesMade(dirty);
903             }
904         }
905 
906         return super.handleEvent(msg, evt);
907     }
908 }
909