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 * @(#) TextListShadow.java 1.11 - last change made 08/12/97 34 */ 35 36package sunsoft.jws.visual.rt.shadow; 37 38import sunsoft.jws.visual.rt.shadow.java.awt.CanvasShadow; 39import sunsoft.jws.visual.rt.awt.TextList; 40import sunsoft.jws.visual.rt.awt.StringVector; 41import sunsoft.jws.visual.rt.base.Global; 42 43import java.util.*; 44import java.awt.SystemColor; 45import java.awt.*; 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 "rt". 51 * 52 * <pre> 53 * name type default value 54 * ----------------------------------------------------------------------- 55 * allowMultipleSelections java.lang.Boolean false 56 * items [Ljava.lang.String; item1, item2 57 * selectedItem java.lang.String null 58 * selectedItems [Ljava.lang.String; null 59 * visibleRows java.lang.Integer 10 60 * < /pre> 61 * 62 * visibleRows: how many rows are visible in the list, changing the 63 * number affects the size of the component in the vertical dimension. 64 * < p> 65 * Check the super class for additional attributes. 66 * 67 * @see TextList 68 * @see StringVector 69 * @version 1.11, 08/12/97 70 */ 71public class TextListShadow extends CanvasShadow { 72 public TextListShadow() { 73 attributes.add(/* NOI18N */"allowMultipleSelections", 74 /* NOI18N */"java.lang.Boolean", 75 Boolean.FALSE, 0); 76 String sa[] = { /* NOI18N */"item1", /* NOI18N */"item2"}; 77 attributes.add(/* NOI18N */"items", 78 /* NOI18N */"[Ljava.lang.String;", sa, 0); 79 attributes.add(/* NOI18N */"selectedItem", 80 /* NOI18N */"java.lang.String", null, HIDDEN); 81 attributes.add(/* NOI18N */"selectedItems", 82 /* NOI18N */"[Ljava.lang.String;", null, HIDDEN); 83 attributes.add(/* NOI18N */"visibleRows", 84 /* NOI18N */"java.lang.Integer", 85 new Integer(10), 0); 86 87 // This is a work around for JDK color bug. 88 // The defaults are not correctly set 89 if (Global.isWindows()) { 90 attributes.add(/* NOI18N */"background", 91 /* NOI18N */"java.awt.Color", 92 SystemColor.window, DONTFETCH); 93 } 94 if (Global.isMotif()) { 95 attributes.add(/* NOI18N */"background", 96 /* NOI18N */"java.awt.Color", 97 SystemColor.text, DONTFETCH); 98 attributes.add(/* NOI18N */"foreground", 99 /* NOI18N */"java.awt.Color", 100 SystemColor.textText, DONTFETCH); 101 } 102 } 103 104 protected Object getOnBody(String key) { 105 TextList list = (TextList)body; 106 107 if (key.equals(/* NOI18N */"allowMultipleSelections")) { 108 return new Boolean(list.allowsMultipleSelections()); 109 } else if (key.equals(/* NOI18N */"items")) { 110 return getFromTable(/* NOI18N */"items"); 111 } else if (key.equals(/* NOI18N */"visibleRows")) { 112 return new Integer(list.getMinimumRows()); 113 } else if (key.equals(/* NOI18N */"selectedItem")) { 114 return list.getSelectedItem(); 115 } else if (key.equals(/* NOI18N */"selectedItems")) { 116 return list.getSelectedItems(); 117 } else 118 return (super.getOnBody(key)); 119 } 120 121 protected void setOnBody(String key, Object value) { 122 TextList list = (TextList)body; 123 124 if (key.equals(/* NOI18N */"allowMultipleSelections")) { 125 list.setMultipleSelections( 126 ((Boolean)value).booleanValue()); 127 } else if (key.equals(/* NOI18N */"items")) { 128 String names[] = (String [])value; 129 StringVector items = list.items(); 130 items.removeAllElements(); 131 132 if (names != null) { 133 for (int i = 0; i < names.length; i++) 134 items.addElement(names[i]); 135 } 136 137 list.updateView(); 138 } else if (key.equals(/* NOI18N */"visibleRows")) { 139 list.setMinimumRows(((Integer)value).intValue()); 140 } else if (key.equals(/* NOI18N */"selectedItem")) { 141 int index = -1; 142 if (value != null) 143 index = list.items().indexOf((String)value); 144 list.select(index); 145 } else if (key.equals(/* NOI18N */"selectedItems")) { 146 String items[] = (String[])value; 147 if (list.allowsMultipleSelections()) { 148 list.deselectAll(); 149 if (items != null) { 150 for (int i = 0; i < items.length; i++) 151 list.select(items[i]); 152 } 153 } else { 154 if (items != null && items.length != 0) 155 list.select(items[0]); 156 else 157 list.select(null); 158 } 159 } else { 160 super.setOnBody(key, value); 161 } 162 } 163 164 public void createBody() { 165 body = new TextList(); 166 } 167} 168