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 * @(#) CheckboxList.java 1.7 - last change made 07/25/97
34 */
35
36package sunsoft.jws.visual.rt.awt;
37
38import sunsoft.jws.visual.rt.awt.*;
39import java.awt.*;
40import java.util.Vector;
41
42public class CheckboxList extends ScrollPanel {
43    private CheckboxView view;
44
45    public CheckboxList() {
46        view = new CheckboxView();
47        add(view);
48
49        Vector items = view.items;
50        for (int i = 0; i < 100; i++)
51            items.addElement(/* NOI18N */"item" + i);
52
53        view.updateCheckboxes();
54    }
55}
56
57class CheckboxView extends Panel implements Scrollable {
58    Vector items;
59
60    private int curx, cury;
61    private GBLayout gridbag;
62    private Panel panel;
63
64    public CheckboxView() {
65        items = new Vector();
66
67        setLayout(null);
68        gridbag = new GBLayout();
69
70        panel = new Panel();
71        panel.setLayout(gridbag);
72
73        add(panel);
74    }
75
76    public void updateCheckboxes() {
77        panel.removeAll();
78        GBConstraints c = new GBConstraints();
79
80        c.gridx = 0;
81        c.gridy = 0;
82        c.fill = GBConstraints.BOTH;
83
84        int size = items.size();
85        for (int i = 0; i < items.size(); i++) {
86            Checkbox box = new Checkbox((String)items.elementAt(i));
87            gridbag.setConstraints(panel.add(box), c);
88
89            c.gridx++;
90            if (c.gridx == 3) {
91                c.gridx = 0;
92                c.gridy++;
93            }
94        }
95
96        if (panel.getPeer() != null) {
97            Dimension d = panel.minimumSize();
98            panel.reshape(0, 0, d.width, d.height);
99        }
100    }
101
102    public void addNotify() {
103        super.addNotify();
104        Dimension d = panel.minimumSize();
105        panel.reshape(0, 0, d.width, d.height);
106    }
107
108    public Dimension minimumSize() {
109        return new Dimension(150, 300);
110    }
111
112    public Dimension preferredSize() {
113        return minimumSize();
114    }
115
116    public void scrollX(int x) {
117        curx = -x;
118        panel.move(curx, cury);
119    }
120
121    public void scrollY(int y) {
122        cury = -y;
123        panel.move(curx, cury);
124    }
125
126    public Dimension scrollSize() {
127        return panel.minimumSize();
128    }
129
130    public Dimension viewSize(Dimension size) {
131        return size;
132    }
133
134    public int lineHeight() {
135        if (panel.countComponents() == 0)
136            return 1;
137
138        Component comp = panel.getComponent(0);
139        Dimension min = comp.minimumSize();
140        return min.height;
141    }
142}
143