KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > RadioButtonExample


1 /*
2  * $Id: RadioButtonExample.java,v 1.4 2005/04/01 10:21:32 blueshift 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.*;
17
18 /**
19  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
20  * @version $Revision: 1.4 $
21  */

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