001: package vicazh.hyperpool.stream;
002:
003: import java.awt.event.*;
004: import java.text.*;
005: import java.util.*;
006: import javax.swing.*;
007: import org.jfree.ui.*;
008:
009: /**
010: * The graphic period service
011: *
012: * @author Victor Zhigunov
013: * @version 0.4.0
014: */
015: abstract public class IPeriodService extends IFileService {
016: private JButton buttonStart;
017:
018: private JButton buttonEnd;
019:
020: private JComboBox box;
021:
022: private JDialog dialog;
023:
024: private JOptionPane optionPane;
025:
026: private DateChooserPanel panel;
027:
028: /**
029: * @param interfaceClass
030: * interface class
031: * @param name
032: * service name
033: * @param buttonClear
034: * clear button
035: * @param dialogClear
036: * clear dialog
037: * @param buttonStart
038: * start date range button
039: * @param buttonEnd
040: * end date range button
041: * @param box
042: * time period value combo box
043: * @param dialog
044: * date select dialog
045: * @param b1
046: * period radio button
047: * @param b2
048: * range radio button
049: */
050: public IPeriodService(Class<?> interfaceClass, String name,
051: JButton buttonClear, JDialog dialogClear,
052: JButton buttonStart, JButton buttonEnd, JComboBox box,
053: JDialog dialog, AbstractButton b1, AbstractButton b2) {
054: super (interfaceClass, name, buttonClear, dialogClear);
055: this .buttonStart = buttonStart;
056: buttonStart.addActionListener(new ActionListener() {
057: public void actionPerformed(ActionEvent e) {
058: panel.setDate(new Date());
059: IPeriodService.this .dialog
060: .setLocationRelativeTo(IPeriodService.this .dialog
061: .getOwner());
062: IPeriodService.this .dialog.setVisible(true);
063: Object value = optionPane.getValue();
064: if (value == JOptionPane.UNINITIALIZED_VALUE)
065: return;
066: optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
067: if (((Integer) value).intValue() != JOptionPane.OK_OPTION)
068: return;
069: setStart();
070: }
071: });
072: this .buttonEnd = buttonEnd;
073: buttonEnd.addActionListener(new ActionListener() {
074: public void actionPerformed(ActionEvent e) {
075: panel.setDate(new Date());
076: IPeriodService.this .dialog
077: .setLocationRelativeTo(IPeriodService.this .dialog
078: .getOwner());
079: IPeriodService.this .dialog.setVisible(true);
080: Object value = optionPane.getValue();
081: if (value == JOptionPane.UNINITIALIZED_VALUE)
082: return;
083: optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
084: if (((Integer) value).intValue() != JOptionPane.OK_OPTION)
085: return;
086: setEnd();
087: }
088: });
089: this .box = box;
090: box.addActionListener(new ActionListener() {
091: public void actionPerformed(ActionEvent e) {
092: pc.period = ((ILong) IPeriodService.this .box
093: .getSelectedItem()).value;
094: }
095: });
096: this .dialog = dialog;
097: optionPane = (JOptionPane) dialog.getContentPane();
098: optionPane.addPropertyChangeListener(this );
099: b1.addActionListener(new ActionListener() {
100: public void actionPerformed(ActionEvent e) {
101: pc.type = false;
102: setControls();
103: }
104: });
105: b2.addActionListener(new ActionListener() {
106: public void actionPerformed(ActionEvent e) {
107: pc.type = true;
108: setControls();
109: }
110: });
111: setPanel();
112: setStart();
113: setEnd();
114: setControls();
115: }
116:
117: protected PeriodControl pc = new PeriodControl();
118:
119: private void setControls() {
120: box.setEnabled(!pc.type);
121: buttonStart.setEnabled(pc.type);
122: buttonEnd.setEnabled(pc.type);
123: }
124:
125: private void setStart() {
126: Date d = PeriodControl.firstTime(panel.getDate());
127: if (pc.end != null && d.after(pc.end))
128: return;
129: pc.start = d;
130: buttonStart.setText(DateFormat.getDateInstance().format(
131: pc.start));
132: }
133:
134: private void setEnd() {
135: Date d = PeriodControl.lastTime(panel.getDate());
136: if (pc.start != null && d.before(pc.start))
137: return;
138: pc.end = d;
139: buttonEnd.setText(DateFormat.getDateInstance().format(pc.end));
140: }
141:
142: private void setPanel() {
143: panel = new DateChooserPanel();
144: optionPane.setMessage(panel);
145: dialog.pack();
146: }
147:
148: public void updateUI() {
149: setPanel();
150: SwingUtilities.updateComponentTreeUI(dialog);
151: super.updateUI();
152: }
153:
154: }
|