01: package org.airtodo.gui_common.components.widgets;
02:
03: import static org.air.framework.gui.box.Gap.medium;
04: import static org.air.framework.gui.box.Gap.small;
05:
06: import java.awt.Component;
07: import java.util.Map;
08:
09: import javax.swing.Box;
10: import javax.swing.JSlider;
11: import javax.swing.event.ChangeEvent;
12: import javax.swing.event.ChangeListener;
13:
14: import org.air.framework.core.Utils;
15: import org.air.framework.gui.box.BxX;
16: import org.air.framework.gui.box.BxY;
17: import org.air.framework.gui.widgets.RequiredLabel;
18: import org.air.framework.i18n.NlsColumns;
19: import org.airtodo.db.types.Progress;
20:
21: public class WidgetSlider extends BxY {
22: public static final String PROPERTY_SLIDER_ON_BORDER = "PROPERTY_SLIDER_ON_BORDER";
23:
24: private Enum enumColumn;
25:
26: private String text;
27: private boolean required;
28:
29: public WidgetSlider(Enum enumColumn, boolean required) {
30: this .enumColumn = enumColumn;
31: this .required = required;
32: text = NlsColumns.getText(enumColumn);
33: setVisible(text != null);
34: add(new BxX(getLabel(), small(), Box.createHorizontalGlue()));
35: add(new BxX(getSlider()));
36: add(medium());
37: }
38:
39: //
40: // getSlider
41: //
42: private JSlider slider;
43:
44: public JSlider getSlider() {
45: if (slider == null) {
46: slider = new JSlider();
47: slider.setSnapToTicks(true);
48: slider.setMajorTickSpacing(10);
49: slider.setPaintLabels(true);
50: slider.getModel().addChangeListener(new ChangeListener() {
51: public void stateChanged(ChangeEvent e) {
52: WidgetSlider.this .firePropertyChange(
53: PROPERTY_SLIDER_ON_BORDER, false, true);
54: }
55: });
56: }
57: return slider;
58: }
59:
60: private Component label;
61:
62: private Component getLabel() {
63: if (label == null)
64: label = new RequiredLabel(text + ":", required);
65: return label;
66: }
67:
68: public Progress getProgress() {
69: return new Progress(getSlider().getValue());
70: }
71:
72: private void setProgess(int progress) {
73: getSlider().setValue(progress);
74: }
75:
76: public void fromGui(Map map) {
77: map.put(Utils.getColumnIdentifier(enumColumn), getProgress());
78: }
79:
80: public void toGui(Map map) {
81: Progress progress = (Progress) map.get(Utils
82: .getColumnIdentifier(enumColumn));
83: setProgess(progress == null ? 0 : progress.getValue());
84: }
85:
86: }
|