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 * @(#) ImageLabelShadow.java 1.30 - last change made 07/25/97
34 */
35
36package sunsoft.jws.visual.rt.shadow;
37
38import sunsoft.jws.visual.rt.base.VJException;
39import sunsoft.jws.visual.rt.type.ImageRef;
40import sunsoft.jws.visual.rt.shadow.java.awt.CanvasShadow;
41import sunsoft.jws.visual.rt.awt.ImageLabel;
42import sunsoft.jws.visual.rt.base.Global;
43
44import java.applet.Applet;
45import java.awt.Color;
46
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
51 * "rt".
52 *
53 * < pre>
54name            type                      default value
55-----------------------------------------------------------------------
56image           rt.type.ImageRef          null
57padWidth        java.lang.Integer         0
58*  < /pre>
59*
60* Check the super class for additional attributes.
61*
62* @see ImageLabel
63* @version 	1.30, 07/25/97
64*/
65public class ImageLabelShadow extends CanvasShadow {
66    public ImageLabelShadow() {
67        attributes.add(/* NOI18N */"image",
68		       /* NOI18N */"sunsoft.jws.visual.rt.type.ImageRef",
69		       null, 0);
70        attributes.add(/* NOI18N */"padWidth",
71		       /* NOI18N */"java.lang.Integer",
72		       new Integer(0), 0);
73
74        // foreground color is meaningless to an image label or button
75        // so don't let it be user editable
76        attributes.add(/* NOI18N */"foreground",
77		       /* NOI18N */"java.awt.Color", Color.black, HIDDEN);
78    }
79
80    protected Object getOnBody(String key) {
81        if (key.equals(/* NOI18N */"padWidth"))
82            return (new Integer(((ImageLabel) body).getPadWidth()));
83        else if (key.equals(/* NOI18N */"image"))
84            // no value available from body
85	    return (getFromTable(/* NOI18N */"image"));
86        else
87            return (super.getOnBody(key));
88    }
89
90    protected void setOnBody(String key, Object value) {
91        ImageLabel label = (ImageLabel)body;
92
93        if (key.equals(/* NOI18N */"padWidth"))
94            label.setPadWidth(((Integer) value).intValue());
95        else if (key.equals(/* NOI18N */"image")) {
96            ImageRef ref = (ImageRef)value;
97            if (ref == null)
98                label.setImage(null);
99            else {
100                Applet applet = getGroup().getApplet();
101                try {
102                    label.setImage(ref.getImage(label, applet));
103                    label.setDefaultWidth(ref.getWidth(label, applet));
104                    label.setDefaultHeight(
105			ref.getHeight(label, applet));
106                }
107                catch (VJException ex) {
108                    // XXX If the image file is not found
109                    // while loading the root, then
110                    //     isLive() will return false even
111                    //     though it should return true.
112                    //     Throwing an exception can cause the
113                    //     whole root not to load, which is
114                    //     too drastic.  The layout windows
115                    //     has to come up so that the user can
116                    //     fix the problem.
117                    // if (isLive())
118		    System.out.println(
119			Global.fmtMsg("sunsoft.jws.visual.rt.shadow.Error",
120				      ex.getMessage()));
121                    // else
122		    //  throw ex;
123                }
124            }
125        }
126        else
127            super.setOnBody(key, value);
128    }
129
130    public void createBody() {
131        body = new ImageLabel(null);
132    }
133}
134