001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package wingset;
014:
015: import org.wings.*;
016: import org.wings.plaf.css.RadioButtonCG;
017:
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020:
021: /**
022: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
023: */
024: public class RadioButtonExample extends WingSetPane {
025: final static int[] textHPos = new int[] { SConstants.LEFT,
026: SConstants.CENTER, SConstants.RIGHT };
027: final static int[] textVPos = new int[] { SConstants.TOP,
028: SConstants.CENTER, SConstants.BOTTOM };
029:
030: static final SIcon sel = new SResourceIcon(
031: "org/wings/icons/green_light_on.png");
032: static final SIcon nsel = new SResourceIcon(
033: "org/wings/icons/green_light_off.png");
034: static final SIcon dissel = new SResourceIcon(
035: "org/wings/icons/green_light_on_disabled.png");
036: static final SIcon disnsel = new SResourceIcon(
037: "org/wings/icons/green_light_off_disabled.png");
038: static final SIcon rollsel = new SResourceIcon(
039: "org/wings/icons/green_light_on.png");
040: static final SIcon rollnsel = new SResourceIcon(
041: "org/wings/icons/green_light_on.png");
042:
043: static SIcon backup_sel;
044: static SIcon backup_nsel;
045: static SIcon backup_dissel;
046: static SIcon backup_disnsel;
047: static SIcon backup_rollsel;
048: static SIcon backup_rollnsel;
049:
050: private ButtonControls controls;
051:
052: private final SLabel reportLabel = new SLabel("No button pressed");
053: protected ActionListener action = new java.awt.event.ActionListener() {
054: public void actionPerformed(ActionEvent e) {
055: reportLabel.setText("<html>Button <b>'"
056: + e.getActionCommand() + "'</b> pressed");
057: }
058: };
059: private SRadioButton[] buttons;
060:
061: protected SComponent createControls() {
062: controls = new ButtonControls();
063: return controls;
064: }
065:
066: public SComponent createExample() {
067: return createRadioButtonExample();
068: }
069:
070: SContainer createRadioButtonExample() {
071: SButtonGroup group = new SButtonGroup();
072: buttons = new SRadioButton[9];
073:
074: for (int i = 0; i < buttons.length; i++) {
075: SRadioButton button = buttons[i] = new SRadioButton("Text "
076: + (i + 1));
077: button.setShowAsFormComponent(true);
078: button.setActionCommand("radio" + (i + 1));
079: button.setToolTipText("RadioButton " + (i + 1));
080: button.setName("radio" + (i + 1));
081: button.setVerticalTextPosition(textVPos[(i / 3) % 3]);
082: button.setHorizontalTextPosition(textHPos[i % 3]);
083: group.add(button);
084: controls.addControllable(button);
085: }
086:
087: final SGridLayout grid = new SGridLayout(3);
088: final SPanel buttonGrid = new SPanel(grid);
089: grid.setBorder(1);
090: grid.setHgap(10);
091: grid.setVgap(10);
092:
093: for (int i = 0; i < buttons.length; i++) {
094: buttons[i].addActionListener(action);
095: buttonGrid.add(buttons[i]);
096: }
097:
098: final SPanel panel = new SPanel(new SGridLayout(2, 1, 0, 20));
099: panel.add(buttonGrid);
100: panel.add(reportLabel);
101:
102: return panel;
103: }
104:
105: class ButtonControls extends ComponentControls {
106: public ButtonControls() {
107: formComponentCheckBox.setSelected(true);
108: final SCheckBox customIcons = new SCheckBox("custom icons");
109: customIcons
110: .setToolTipText("define custom icons for usage as checkboxes");
111: customIcons
112: .addActionListener(new java.awt.event.ActionListener() {
113: public void actionPerformed(ActionEvent e) {
114: for (int i = 0; i < buttons.length; i++) {
115: SRadioButton button = buttons[i];
116: if (i != 4 && customIcons.isSelected()) {
117: backup_nsel = button.getIcon();
118: backup_sel = button
119: .getSelectedIcon();
120: backup_disnsel = button
121: .getDisabledIcon();
122: backup_dissel = button
123: .getDisabledSelectedIcon();
124: backup_rollnsel = button
125: .getRolloverIcon();
126: backup_rollsel = button
127: .getRolloverSelectedIcon();
128: button.setIcon(nsel);
129: button.setSelectedIcon(sel);
130: button.setDisabledIcon(disnsel);
131: button
132: .setDisabledSelectedIcon(dissel);
133: button.setRolloverIcon(rollnsel);
134: button
135: .setRolloverSelectedIcon(rollsel);
136: } else {
137: button.setIcon(backup_nsel);
138: button.setSelectedIcon(backup_sel);
139: button
140: .setDisabledIcon(backup_disnsel);
141: button
142: .setDisabledSelectedIcon(backup_dissel);
143: button
144: .setRolloverIcon(backup_rollnsel);
145: button
146: .setRolloverSelectedIcon(backup_rollsel);
147: }
148: }
149: }
150: });
151: addControl(customIcons);
152:
153: final SCheckBox useImages = new SCheckBox("icons in form");
154: useImages
155: .setToolTipText("use images in form elements - if you defined custom images, use those");
156: final RadioButtonCG cg = (RadioButtonCG) getSession()
157: .getCGManager().getCG(SRadioButton.class);
158: useImages.setSelected(true);
159: cg.setUseIconsInForm(true);
160: useImages
161: .addActionListener(new java.awt.event.ActionListener() {
162: public void actionPerformed(ActionEvent e) {
163: cg
164: .setUseIconsInForm(useImages
165: .isSelected());
166: RadioButtonExample.this.reload();
167: }
168: });
169: addControl(useImages);
170: }
171: }
172: }
|