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.CheckBoxCG;
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 CheckBoxExample 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 SCheckBox[] buttons;
060:
061: protected SComponent createControls() {
062: controls = new ButtonControls();
063: return controls;
064: }
065:
066: public SComponent createExample() {
067: return createCheckBoxExample();
068: }
069:
070: SContainer createCheckBoxExample() {
071: buttons = new SCheckBox[9];
072:
073: for (int i = 0; i < buttons.length; i++) {
074: SCheckBox button = buttons[i] = new SCheckBox("Text "
075: + (i + 1));
076: if (i == 4)
077: button.setText(null);
078: button.setShowAsFormComponent(true);
079: button.setActionCommand("check" + (i + 1));
080: button.setToolTipText("CheckBox " + (i + 1));
081: button.setName("check" + (i + 1));
082: button.setVerticalTextPosition(textVPos[(i / 3) % 3]);
083: button.setHorizontalTextPosition(textHPos[i % 3]);
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: .addActionListener(new java.awt.event.ActionListener() {
111: public void actionPerformed(ActionEvent e) {
112: for (int i = 0; i < buttons.length; i++) {
113: SCheckBox button = buttons[i];
114: if (i != 4 && customIcons.isSelected()) {
115: backup_nsel = button.getIcon();
116: backup_sel = button
117: .getSelectedIcon();
118: backup_disnsel = button
119: .getDisabledIcon();
120: backup_dissel = button
121: .getDisabledSelectedIcon();
122: backup_rollnsel = button
123: .getRolloverIcon();
124: backup_rollsel = button
125: .getRolloverSelectedIcon();
126: button.setIcon(nsel);
127: button.setSelectedIcon(sel);
128: button.setDisabledIcon(disnsel);
129: button
130: .setDisabledSelectedIcon(dissel);
131: button.setRolloverIcon(rollnsel);
132: button
133: .setRolloverSelectedIcon(rollsel);
134: } else {
135: button.setIcon(backup_nsel);
136: button.setSelectedIcon(backup_sel);
137: button
138: .setDisabledIcon(backup_disnsel);
139: button
140: .setDisabledSelectedIcon(backup_dissel);
141: button
142: .setRolloverIcon(backup_rollnsel);
143: button
144: .setRolloverSelectedIcon(backup_rollsel);
145: }
146: }
147: }
148: });
149: addControl(customIcons);
150:
151: final SCheckBox useImages = new SCheckBox("icons in form");
152: final CheckBoxCG cg = (CheckBoxCG) getSession()
153: .getCGManager().getCG(SCheckBox.class);
154: useImages.setSelected(true);
155: cg.setUseIconsInForm(true);
156: useImages
157: .addActionListener(new java.awt.event.ActionListener() {
158: public void actionPerformed(ActionEvent e) {
159: cg
160: .setUseIconsInForm(useImages
161: .isSelected());
162: CheckBoxExample.this.reload();
163: }
164: });
165: addControl(useImages);
166: }
167: }
168: }
|