001: package org.airtodo.gui_common.components.widgets;
002:
003: import static org.air.framework.gui.box.Gap.small;
004:
005: import java.beans.PropertyChangeEvent;
006: import java.beans.PropertyChangeListener;
007: import java.util.Map;
008:
009: import javax.swing.Box;
010: import javax.swing.JCheckBox;
011: import javax.swing.JLabel;
012: import javax.swing.event.ChangeEvent;
013: import javax.swing.event.ChangeListener;
014:
015: import org.air.framework.core.Utils;
016: import org.air.framework.gui.box.BxX;
017: import org.air.framework.gui.box.BxY;
018: import org.air.framework.i18n.NlsColumns;
019: import org.air.framework.i18n.NlsMessages;
020: import org.air.framework.properties.Icons;
021: import org.airtodo.db.types.Freezed;
022:
023: public class WidgetProgressPanel extends BxY {
024: public static enum NLS {
025: TITLE_PROGRESS
026: }
027:
028: private static final String NLS_TITLE_PROGRESS = NlsMessages
029: .getString(NLS.TITLE_PROGRESS);
030: private Enum enumCompletion;
031: private Enum enumFreezed;
032: private boolean required;
033:
034: public WidgetProgressPanel(Enum completion, Enum freezed,
035: boolean required) {
036: super (NLS_TITLE_PROGRESS);
037: init(completion, freezed, required);
038: }
039:
040: public WidgetProgressPanel(Enum completion, Enum freezed) {
041: super (NLS_TITLE_PROGRESS);
042: init(completion, freezed, false);
043: }
044:
045: private void init(Enum completion, Enum freezed, boolean required) {
046: this .enumCompletion = completion;
047: this .enumFreezed = freezed;
048: this .required = required;
049: add(getSlider());
050: add(new BxX(getCheckBox(), small(), getLabelFreezed(), Box
051: .createHorizontalGlue()));
052: }
053:
054: //
055: // getSlider
056: //
057: private WidgetSlider slider;
058:
059: private WidgetSlider getSlider() {
060: if (slider == null) {
061: slider = new WidgetSlider(enumCompletion, required);
062: slider.addPropertyChangeListener(
063: WidgetSlider.PROPERTY_SLIDER_ON_BORDER,
064: new PropertyChangeListener() {
065: public void propertyChange(
066: PropertyChangeEvent evt) {
067: int value = slider.getSlider().getValue();
068: if (value == 0 || value == 100) {
069: getLabelFreezed().setIcon(null);
070: getCheckBox().setEnabled(false);
071: getCheckBox().setSelected(false);
072: } else
073: getCheckBox().setEnabled(true);
074: }
075: });
076: }
077: return slider;
078: }
079:
080: //
081: // getCheckBox
082: //
083: private JCheckBox checkBox;
084:
085: private JCheckBox getCheckBox() {
086: if (checkBox == null) {
087: checkBox = new JCheckBox(NlsColumns.getText(enumFreezed));
088: checkBox.addChangeListener(new ChangeListener() {
089: public void stateChanged(ChangeEvent e) {
090: getLabelFreezed().setIcon(
091: checkBox.isSelected() ? Icons.STOP : null);
092: }
093: });
094: }
095: return checkBox;
096: }
097:
098: //
099: // getLabelFreezed
100: //
101: private JLabel labelFreezed;
102:
103: private JLabel getLabelFreezed() {
104: if (labelFreezed == null)
105: labelFreezed = new JLabel();
106: return labelFreezed;
107: }
108:
109: public void fromGui(Map map) {
110: getSlider().fromGui(map);
111: boolean freezed = getCheckBox().isSelected();
112: map.put(Utils.getColumnIdentifier(enumFreezed), new Freezed(
113: freezed));
114: }
115:
116: public void toGui(Map map) {
117: getSlider().toGui(map);
118: Freezed freezed = (Freezed) map.get(Utils
119: .getColumnIdentifier(enumFreezed));
120: if (freezed != null)
121: getCheckBox().setSelected(freezed.getValue());
122: }
123: }
|