KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > CheckBoxExample


1 /*
2  * $Id: CheckBoxExample.java,v 1.5 2005/05/26 13:18:07 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16 import org.wings.SButton;
17 import org.wings.SCheckBox;
18 import org.wings.SComponent;
19 import org.wings.SConstants;
20 import org.wings.SContainer;
21 import org.wings.SFlowDownLayout;
22 import org.wings.SForm;
23 import org.wings.SGridLayout;
24 import org.wings.SIcon;
25 import org.wings.SLabel;
26 import org.wings.SPanel;
27 import org.wings.SURLIcon;
28
29 /**
30  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
31  * @version $Revision: 1.5 $
32  */

33 public class CheckBoxExample
34         extends WingSetPane {
35     static final ClassLoader JavaDoc cl = WingSet.class.getClassLoader();
36     static final SIcon sel =
37             new SURLIcon("../icons/ComboBoxSelectedIcon.gif");
38     static final SIcon nsel =
39             new SURLIcon("../icons/ComboBoxIcon.gif");
40     static final SIcon dissel =
41             new SURLIcon("../icons/ComboBoxDisabledSelectedIcon.gif");
42     static final SIcon disnsel =
43             new SURLIcon("../icons/ComboBoxDisabledIcon.gif");
44     static final SIcon rollsel =
45             new SURLIcon("../icons/ComboBoxRolloverSelectedIcon.gif");
46     static final SIcon rollnsel =
47             new SURLIcon("../icons/ComboBoxRolloverIcon.gif");
48
49     public SComponent createExample() {
50         SPanel p = new SPanel(new SGridLayout(2));
51         p.add(new SLabel("<html><h4>CheckBoxes outside forms</h4>"));
52         p.add(new SLabel("<html><h4>Image CheckBoxes outside forms</h4>"));
53
54         p.add(createCheckBoxExample());
55         p.add(createImageCheckBoxExample());
56
57         SForm form = new SForm();
58         form.add(new SLabel("<html><h4>CheckBoxes in a form</h4>"));
59         form.add(createCheckBoxExample());
60         form.add(new SLabel("<html><br />"));
61         form.add(new SButton("submit"));
62         p.add(form);
63
64         form = new SForm();
65         form.add(new SLabel("<html><h4>Image CheckBoxes in a form</h4>"));
66         form.add(createImageCheckBoxExample());
67         form.add(new SLabel("<html><br />"));
68         form.add(new SButton("submit"));
69         p.add(form);
70         return p;
71     }
72
73
74     SContainer createCheckBoxExample() {
75         SPanel text = new SPanel();
76
77         for (int i = 0; i < 3; i++) {
78             SCheckBox b = new SCheckBox("text " + (i + 1));
79             // b.setBorder(new SLineBorder(1));
80
text.add(b);
81         }
82
83         return text;
84     }
85
86     SContainer createImageCheckBoxExample() {
87
88         SCheckBox[] boxes = new SCheckBox[9];
89         boxes[0] = new SCheckBox("testTL");
90         boxes[1] = new SCheckBox("testTC");
91         boxes[2] = new SCheckBox("testTR");
92         boxes[3] = new SCheckBox("testCL");
93         boxes[4] = new SCheckBox();
94         boxes[5] = new SCheckBox("testCR");
95         boxes[6] = new SCheckBox("testBL");
96         boxes[7] = new SCheckBox("testBC");
97         boxes[8] = new SCheckBox("testBR");
98
99         for (int i = 0; i < boxes.length; i++) {
100             boxes[i].setIcon(nsel);
101             boxes[i].setSelectedIcon(sel);
102             boxes[i].setDisabledIcon(disnsel);
103             boxes[i].setDisabledSelectedIcon(dissel);
104             boxes[i].setRolloverIcon(rollnsel);
105             boxes[i].setRolloverSelectedIcon(rollsel);
106             boxes[i].setPressedIcon(sel);
107             boxes[i].setToolTipText("CheckBox " + i);
108         }
109
110         boxes[0].setVerticalTextPosition(SConstants.TOP);
111         boxes[0].setHorizontalTextPosition(SConstants.LEFT);
112
113         boxes[1].setVerticalTextPosition(SConstants.TOP);
114         boxes[1].setHorizontalTextPosition(SConstants.CENTER);
115
116         boxes[2].setVerticalTextPosition(SConstants.TOP);
117         boxes[2].setHorizontalTextPosition(SConstants.RIGHT);
118
119         boxes[3].setVerticalTextPosition(SConstants.CENTER);
120         boxes[3].setHorizontalTextPosition(SConstants.LEFT);
121
122         boxes[4].setVerticalAlignment(SConstants.CENTER);
123         boxes[4].setHorizontalAlignment(SConstants.CENTER);
124
125         boxes[5].setVerticalTextPosition(SConstants.CENTER);
126         boxes[5].setHorizontalTextPosition(SConstants.RIGHT);
127
128         boxes[6].setVerticalTextPosition(SConstants.BOTTOM);
129         boxes[6].setHorizontalTextPosition(SConstants.LEFT);
130
131         boxes[7].setSelected(true);
132         boxes[7].setEnabled(false);
133         boxes[7].setVerticalTextPosition(SConstants.BOTTOM);
134         boxes[7].setHorizontalTextPosition(SConstants.CENTER);
135
136         boxes[8].setSelected(false);
137         boxes[8].setEnabled(false);
138         boxes[8].setVerticalTextPosition(SConstants.BOTTOM);
139         boxes[8].setHorizontalTextPosition(SConstants.RIGHT);
140
141         SPanel erg = new SPanel(new SFlowDownLayout());
142
143         SGridLayout grid = new SGridLayout(3, 3);
144         grid.setBorder(1);
145         SPanel b = new SPanel(grid);
146
147         for (int i = 0; i < boxes.length; i++)
148             b.add(boxes[i]);
149
150         erg.add(b);
151
152         return erg;
153     }
154 }
155
156
157
Popular Tags