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 * @(#) BorderPanelShadow.java 1.19 - last change made 06/12/97
34 */
35
36package sunsoft.jws.visual.rt.shadow;
37
38import sunsoft.jws.visual.rt.awt.VJPanel;
39import sunsoft.jws.visual.rt.base.*;
40import sunsoft.jws.visual.rt.shadow.GBPanelShadow;
41import java.awt.*;
42import java.util.Enumeration;
43
44/**
45 * Wraps an AWT widget.  The attributes available for this
46 * class are listed below.  In the type column, type names beginning
47 * with "sunsoft.jws.visual.rt" have been abbreviated to begin with
48 * "rt".
49 *
50 * < pre >
51name            type                      default value
52-----------------------------------------------------------------------
53useCenter       java.lang.Boolean         true
54useEast         java.lang.Boolean         true
55useNorth        java.lang.Boolean         true
56useSouth        java.lang.Boolean         true
57useWest         java.lang.Boolean         true
58*  < /pre>
59*
60* The attributes for this class allow you to select which of the five
61* border panel cells are going to be used.  When you set them to
62* false, whatever was in that cell is deleted and the cell will no
63* longer appear in the border layout for use in arranging components.
64*  < p>
65* Check the super class for additional attributes.
66*
67* @see BorderLayout
68* @version 1.19, 06/12/97
69*/
70public class BorderPanelShadow extends VJPanelShadow {
71    public BorderPanelShadow() {
72        attributes.add(/* NOI18N */"useCenter",
73		       /* NOI18N */"java.lang.Boolean", Boolean.TRUE, 0);
74        attributes.add(/* NOI18N */"useNorth",
75		       /* NOI18N */"java.lang.Boolean", Boolean.TRUE, 0);
76        attributes.add(/* NOI18N */"useSouth",
77		       /* NOI18N */"java.lang.Boolean", Boolean.TRUE, 0);
78        attributes.add(/* NOI18N */"useEast",
79		       /* NOI18N */"java.lang.Boolean", Boolean.TRUE, 0);
80        attributes.add(/* NOI18N */"useWest",
81		       /* NOI18N */"java.lang.Boolean", Boolean.TRUE, 0);
82    }
83
84    protected Object getOnBody(String key) {
85        Panel panel = (Panel)body;
86
87        if (key.equals(/* NOI18N */"useCenter") ||
88	    key.equals(/* NOI18N */"useNorth") ||
89	    key.equals(/* NOI18N */"useSouth") ||
90	    key.equals(/* NOI18N */"useEast") ||
91	    key.equals(/* NOI18N */"useWest")) {
92            return getFromTable(key);
93        } else {
94            return super.getOnBody(key);
95        }
96    }
97
98    protected void setOnBody(String key, Object value) {
99        Panel panel = (Panel)body;
100
101        if (key.equals(/* NOI18N */"useCenter") ||
102	    key.equals(/* NOI18N */"useNorth") ||
103	    key.equals(/* NOI18N */"useSouth") ||
104	    key.equals(/* NOI18N */"useEast") ||
105	    key.equals(/* NOI18N */"useWest")) {
106            // border names differ from the keys "useWest" -> "West"
107            adjustChild(key.substring(3),
108			((Boolean)value).booleanValue());
109        } else {
110            super.setOnBody(key, value);
111        }
112    }
113
114    private void adjustChild(String borderName, boolean create) {
115        AttributeManager mgr = lookupChild(borderName);
116
117        if (create) {
118            if (mgr != null)
119                return;
120
121            double wx[] = {1};
122            double wy[] = {1};
123
124            GBPanelShadow panel = new GBPanelShadow();
125            panel.set(/* NOI18N */"layoutName", borderName);
126            panel.set(/* NOI18N */"columnWeights", wx);
127            panel.set(/* NOI18N */"rowWeights", wy);
128
129            add(panel);
130            panel.create();
131        } else {
132            if (mgr == null)
133                return;
134
135            GBPanelShadow panel = (GBPanelShadow)mgr;
136            panel.destroy();
137            remove(panel);
138        }
139    }
140
141    private AttributeManager lookupChild(String borderName) {
142        Enumeration e = getChildList();
143        while (e.hasMoreElements()) {
144            AttributeManager mgr = (AttributeManager)e.nextElement();
145            String name = (String)mgr.get(/* NOI18N */"layoutName");
146
147            if (name == null)
148                continue;
149
150            if (name.equals(borderName))
151                return mgr;
152        }
153
154        return null;
155    }
156
157    public void updateContainerAttribute(AttributeManager child,
158					 String key, Object value) {
159        if (!key.equals(/* NOI18N */"layoutName"))
160            return;
161
162        Shadow s = (Shadow)child;
163        Component comp = (Component)s.getBody();
164        if (comp == null)
165            return;
166
167        String borderName = (String)value;
168        if (borderName == null)
169            borderName = /* NOI18N */"Center";
170
171        Panel panel = (Panel)body;
172        BorderLayout bd = (BorderLayout)panel.getLayout();
173
174        bd.addLayoutComponent(borderName, comp);
175    }
176
177    public void createBody() {
178        Panel panel = new VJPanel();
179        panel.setLayout(new BorderLayout());
180        body = panel;
181    }
182
183    protected void postCreate() {
184        Enumeration e = getChildList();
185        while (e.hasMoreElements()) {
186            AttributeManager mgr = (AttributeManager)e.nextElement();
187            String borderName =
188		(String)mgr.get(/* NOI18N */"layoutName");
189
190            if (borderName == null)
191                continue;
192
193            if (borderName.equals(/* NOI18N */"Center"))
194                set(/* NOI18N */"useCenter", Boolean.TRUE);
195            else if (borderName.equals(/* NOI18N */"North"))
196                set(/* NOI18N */"useNorth", Boolean.TRUE);
197            else if (borderName.equals(/* NOI18N */"South"))
198                set(/* NOI18N */"useSouth", Boolean.TRUE);
199            else if (borderName.equals(/* NOI18N */"East"))
200                set(/* NOI18N */"useEast", Boolean.TRUE);
201            else if (borderName.equals(/* NOI18N */"West"))
202                set(/* NOI18N */"useWest", Boolean.TRUE);
203        }
204
205        super.postCreate();
206    }
207}
208