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 * @(#) @(#) TextAreaShadow.java 1.19 - last change made 08/12/97
34 */
35
36package sunsoft.jws.visual.rt.shadow.java.awt;
37
38import sunsoft.jws.visual.rt.awt.GBConstraints;
39import java.awt.TextArea;
40import java.awt.SystemColor;
41import sunsoft.jws.visual.rt.base.Global;
42
43/**
44 * Wraps an AWT widget.  The attributes available for this
45 * class are listed below.  In the type column, type names beginning
46 * with "sunsoft.jws.visual.rt" have been abbreviated to begin with "rt".
47 *
48 * <pre>
49name            type                      default value
50-----------------------------------------------------------------------
51numColumns      java.lang.Integer         10
52numRows         java.lang.Integer         10
53*  < /pre>
54*
55* Check the super class for additional attributes.
56*
57* @see TextArea
58* @version 	1.19, 08/12/97
59*/
60public class TextAreaShadow extends TextComponentShadow {
61    public TextAreaShadow() {
62        attributes.add(/* NOI18N */"numColumns",
63		       /* NOI18N */"java.lang.Integer", new Integer(10),
64		       CONSTRUCTOR);
65        attributes.add(/* NOI18N */"numRows",
66		       /* NOI18N */"java.lang.Integer", new Integer(10),
67		       CONSTRUCTOR);
68
69        GBConstraints c = (GBConstraints)get(/* NOI18N */"GBConstraints");
70        c.fill = GBConstraints.BOTH;
71        attributes.add(/* NOI18N */"GBConstraints",
72		       /* NOI18N */"sunsoft.jws.visual.rt.awt.GBConstraints",
73		    c);
74
75        // This is a work around for JDK color bug. The defaults are
76        // not correctly set
77        if (Global.isWindows())  {
78            attributes.add(/* NOI18N */"background",
79			   /* NOI18N */"java.awt.Color",
80			   SystemColor.window, DONTFETCH);
81        }
82        if (Global.isMotif())  {
83            attributes.add(/* NOI18N */"background",
84			   /* NOI18N */"java.awt.Color",
85			   SystemColor.text, DONTFETCH);
86            attributes.add(/* NOI18N */"foreground",
87			   /* NOI18N */"java.awt.Color",
88			   SystemColor.textText, DONTFETCH);
89        }
90    }
91
92    protected Object getOnBody(String key) {
93        TextArea textarea = (TextArea)body;
94
95        if (key.equals(/* NOI18N */"text")) {
96            return textarea.getText();
97        } else if (key.equals(/* NOI18N */"numColumns")) {
98            return new Integer(textarea.getColumns());
99        } else if (key.equals(/* NOI18N */"numRows")) {
100            return new Integer(textarea.getRows());
101        } else {
102            return super.getOnBody(key);
103        }
104    }
105
106    protected void setOnBody(String key, Object value) {
107        TextArea textarea = (TextArea)body;
108
109        if (key.equals(/* NOI18N */"text")) {
110            String text = (String)value;
111            String text2 = textarea.getText();
112            if (text == null)
113                text = /* NOI18N */"";
114            if (!text.equals(text2))
115		textarea.setText(text);
116        } else if (key.equals(/* NOI18N */"numColumns")) {
117            return;	// can't set this attribute dynamically
118        } else if (key.equals(/* NOI18N */"numRows")) {
119            return;	// can't set this attribute dynamically
120        } else {
121            super.setOnBody(key, value);
122        }
123    }
124
125    public void createBody() {
126        boolean initText, initColumns, initRows;
127        String initTextValue;
128        Integer initColumnsValue, initRowsValue;
129
130        initTextValue = (String)getFromTable(/* NOI18N */"text");
131        initText = (initTextValue != null);
132
133        initColumnsValue = (Integer) (getFromTable(/* NOI18N */"numColumns"));
134        initColumns = (initColumnsValue != null);
135
136        initRowsValue = (Integer) (getFromTable(/* NOI18N */"numRows"));
137        initRows = (initRowsValue != null);
138
139        if (initText & initColumns & initRows) {
140            body = new TextArea(initTextValue, initRowsValue.intValue(),
141				initColumnsValue.intValue());
142        } else if (initColumns & initRows) {
143            body = new TextArea(initRowsValue.intValue(),
144				initColumnsValue.intValue());
145        } else if (initText) {
146            body = new TextArea(initTextValue);
147        } else {
148            body = new TextArea();
149        }
150    }
151}
152