01: package org.wings.example;
02:
03: import java.awt.event.ActionEvent;
04: import java.awt.event.ActionListener;
05: import javax.swing.event.ChangeEvent;
06: import javax.swing.event.ChangeListener;
07: import org.wings.SButton;
08: import org.wings.SComponent;
09: import org.wings.SForm;
10: import org.wings.SGridLayout;
11: import org.wings.SSlider;
12: import org.wings.SLabel;
13: import org.wings.plaf.WingSetExample;
14:
15: /**
16: *
17: * @author Christian Schyma
18: */
19: public class SliderExample implements WingSetExample {
20: private SForm form;
21:
22: public SliderExample() {
23: }
24:
25: public void activateExample() {
26: final SLabel label = new SLabel("");
27:
28: SGridLayout layout = new SGridLayout(2);
29: layout.setHgap(10);
30: layout.setVgap(40);
31:
32: form = new SForm(layout);
33:
34: SSlider horizSlider1 = new SSlider(0, 200, 150);
35:
36: SSlider horizSlider2 = new SSlider(-100, 100, 50);
37:
38: SSlider horizSlider3 = new SSlider(-400, -200, -300);
39: horizSlider3.setMajorTickSpacing(25);
40: horizSlider3.setSnapToTicks(true);
41:
42: SSlider vertSlider = new SSlider(SSlider.VERTICAL, 0, 300, 0);
43: vertSlider.setMajorTickSpacing(30);
44: vertSlider.setSnapToTicks(true);
45: vertSlider.addChangeListener(new ChangeListener() {
46: public void stateChanged(ChangeEvent e) {
47: label.setText("value of slider 4 is "
48: + String.valueOf(((SSlider) e.getSource())
49: .getValue()));
50: }
51: });
52:
53: final SButton button = new SButton("store slider positions");
54: button.addActionListener(new ActionListener() {
55: public void actionPerformed(ActionEvent e) {
56: // just to simulate a POST
57: }
58: });
59:
60: form.add(new SLabel("slider 1 [0,200]"));
61: form.add(horizSlider1);
62:
63: form.add(new SLabel("slider 2 [-100, 100]"));
64: form.add(horizSlider2);
65:
66: form.add(new SLabel(
67: "slider 3 [-400, -200], snaps to every 25 ticks"));
68: form.add(horizSlider3);
69:
70: form.add(new SLabel(
71: "slider 4 [0, 300], snaps to every 30 ticks"));
72: form.add(vertSlider);
73:
74: form.add(button);
75: form.add(label);
76: }
77:
78: public void passivateExample() {
79: //To change body of implemented methods use File | Settings | File Templates.
80: }
81:
82: public SComponent getExample() {
83: return form;
84: }
85:
86: public String getExampleName() {
87: return "Slider";
88: }
89:
90: public String getExampleGroup() {
91: return "Experiment";
92: }
93: }
|