OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 137 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 137 Rev 153
1
package org.jopencalendar.ui;
1
package org.jopencalendar.ui;
2
 
2
 
3
import java.awt.BorderLayout;
3
import java.awt.BorderLayout;
4
import java.awt.Color;
4
import java.awt.Color;
5
import java.awt.Dimension;
5
import java.awt.Dimension;
6
import java.awt.Font;
6
import java.awt.Font;
7
import java.awt.Graphics;
7
import java.awt.Graphics;
8
import java.awt.GridLayout;
8
import java.awt.GridLayout;
9
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
10
import java.awt.event.ActionListener;
11
import java.awt.event.MouseAdapter;
11
import java.awt.event.MouseAdapter;
12
import java.awt.event.MouseEvent;
12
import java.awt.event.MouseEvent;
13
import java.awt.event.MouseListener;
13
import java.awt.event.MouseListener;
14
import java.beans.PropertyChangeEvent;
14
import java.beans.PropertyChangeEvent;
15
import java.beans.PropertyChangeListener;
15
import java.beans.PropertyChangeListener;
16
import java.text.DateFormat;
16
import java.text.DateFormat;
17
import java.text.DateFormatSymbols;
17
import java.text.DateFormatSymbols;
18
import java.text.SimpleDateFormat;
18
import java.text.SimpleDateFormat;
19
import java.util.ArrayList;
19
import java.util.ArrayList;
20
import java.util.Calendar;
20
import java.util.Calendar;
21
import java.util.Date;
21
import java.util.Date;
22
import java.util.List;
22
import java.util.List;
23
 
23
 
24
import javax.swing.BorderFactory;
24
import javax.swing.BorderFactory;
25
import javax.swing.ImageIcon;
25
import javax.swing.ImageIcon;
26
import javax.swing.JButton;
26
import javax.swing.JButton;
27
import javax.swing.JFrame;
27
import javax.swing.JFrame;
28
import javax.swing.JLabel;
28
import javax.swing.JLabel;
29
import javax.swing.JPanel;
29
import javax.swing.JPanel;
30
import javax.swing.JTextField;
30
import javax.swing.JTextField;
31
import javax.swing.SwingConstants;
31
import javax.swing.SwingConstants;
32
import javax.swing.SwingUtilities;
32
import javax.swing.SwingUtilities;
33
import javax.swing.UIManager;
33
import javax.swing.UIManager;
34
 
34
 
35
public class DatePickerPanel extends JPanel implements ActionListener, MouseListener {
35
public class DatePickerPanel extends JPanel implements ActionListener, MouseListener {
36
 
36
 
37
    private static final long serialVersionUID = -2882634897084487051L;
37
    private static final long serialVersionUID = -2882634897084487051L;
38
    public static final String TIME_IN_MILLIS = "timeInMillis";
38
    public static final String TIME_IN_MILLIS = "timeInMillis";
39
    private int rowCount = 7;
39
    private int rowCount = 7;
40
    private int colCount = 7;
40
    private int colCount = 7;
41
    private int currentYear;
41
    private int currentYear;
42
    private int currentMonth;
42
    private int currentMonth;
43
    private List<DateLabel> labels = new ArrayList<DateLabel>();
43
    private List<DateLabel> labels = new ArrayList<DateLabel>();
44
    private JLabel title;
44
    private JLabel title;
45
    private JButton bRight;
45
    private JButton bRight;
46
    private JButton bLeft;
46
    private JButton bLeft;
47
    private Date selectedDate;
47
    private Date selectedDate;
48
 
48
 
49
    public DatePickerPanel() {
49
    public DatePickerPanel() {
50
        //
50
        //
51
        Calendar cal = Calendar.getInstance();
51
        Calendar cal = Calendar.getInstance();
52
        this.selectedDate = cal.getTime();
52
        this.selectedDate = cal.getTime();
53
        this.currentYear = cal.get(Calendar.YEAR);
53
        this.currentYear = cal.get(Calendar.YEAR);
54
        this.currentMonth = cal.get(Calendar.MONTH);
54
        this.currentMonth = cal.get(Calendar.MONTH);
55
        //
55
        //
56
 
56
 
57
        this.setLayout(new BorderLayout(2, 2));
57
        this.setLayout(new BorderLayout(2, 2));
58
        JPanel navigator = new JPanel();
58
        JPanel navigator = new JPanel();
59
        navigator.setLayout(new BorderLayout());
59
        navigator.setLayout(new BorderLayout());
-
 
60
        String leftFileName = "left.png";
-
 
61
        String rightFileName = "right.png";
-
 
62
        if (this.getFont().getSize() > 16) {
-
 
63
            leftFileName = "left_2x.png";
-
 
64
            rightFileName = "right_2x.png";
-
 
65
        }
60
        bLeft = new JButton(new ImageIcon(this.getClass().getResource("left.png")));
66
        bLeft = new JButton(new ImageIcon(this.getClass().getResource(leftFileName)));
61
        configureButton(bLeft);
67
        configureButton(bLeft);
62
 
68
 
63
        navigator.add(bLeft, BorderLayout.WEST);
69
        navigator.add(bLeft, BorderLayout.WEST);
64
        title = new JLabel("...", SwingConstants.CENTER);
70
        title = new JLabel("...", SwingConstants.CENTER);
65
        title.setFont(title.getFont().deriveFont(Font.BOLD));
71
        title.setFont(title.getFont().deriveFont(Font.BOLD));
66
        navigator.add(title, BorderLayout.CENTER);
72
        navigator.add(title, BorderLayout.CENTER);
-
 
73
 
67
        bRight = new JButton(new ImageIcon(this.getClass().getResource("right.png")));
74
        bRight = new JButton(new ImageIcon(this.getClass().getResource(rightFileName)));
68
        configureButton(bRight);
75
        configureButton(bRight);
69
        navigator.add(bRight, BorderLayout.EAST);
76
        navigator.add(bRight, BorderLayout.EAST);
70
        this.add(navigator, BorderLayout.NORTH);
77
        this.add(navigator, BorderLayout.NORTH);
71
        final JPanel dayPanel = new JPanel() {
78
        final JPanel dayPanel = new JPanel() {
72
 
79
 
73
            private static final long serialVersionUID = 1L;
80
            private static final long serialVersionUID = 1L;
74
 
81
 
75
            @Override
82
            @Override
76
            protected void paintComponent(Graphics g) {
83
            protected void paintComponent(Graphics g) {
77
                super.paintComponent(g);
84
                super.paintComponent(g);
78
                g.setColor(Color.GRAY);
85
                g.setColor(Color.GRAY);
79
                g.drawLine(0, 0, getWidth(), 0);
86
                g.drawLine(0, 0, getWidth(), 0);
80
            }
87
            }
81
        };
88
        };
82
        dayPanel.setBackground(Color.WHITE);
89
        dayPanel.setBackground(Color.WHITE);
83
        dayPanel.setLayout(new GridLayout(rowCount, colCount, 4, 4));
90
        dayPanel.setLayout(new GridLayout(rowCount, colCount, 4, 4));
84
        dayPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
91
        dayPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
85
        //
92
        //
86
 
93
 
87
        String[] dateFormatSymbols = new DateFormatSymbols().getShortWeekdays();
94
        String[] dateFormatSymbols = new DateFormatSymbols().getShortWeekdays();
88
        int f = cal.getFirstDayOfWeek();
95
        int f = cal.getFirstDayOfWeek();
89
 
96
 
90
        for (int i = 0; i < colCount; i++) {
97
        for (int i = 0; i < colCount; i++) {
91
            int j = i + f;
98
            int j = i + f;
92
            if (j >= 8) {
99
            if (j >= 8) {
93
                j = 1;
100
                j = 1;
94
            }
101
            }
95
            String d = dateFormatSymbols[j];
102
            String d = dateFormatSymbols[j];
96
            dayPanel.add(new JLabel(d, SwingConstants.RIGHT));
103
            final JLabel lDay = new JLabel(d, SwingConstants.RIGHT);
-
 
104
            lDay.setMinimumSize(new Dimension(lDay.getPreferredSize().width, lDay.getPreferredSize().width));
-
 
105
            dayPanel.add(lDay);
97
        }
106
        }
98
 
107
 
99
        //
108
        //
100
        int c = 0;
109
        int c = 0;
101
        final MouseAdapter mListener = new MouseAdapter() {
110
        final MouseAdapter mListener = new MouseAdapter() {
102
            public long select(MouseEvent e) {
111
            public long select(MouseEvent e) {
103
                if (e.getSource() instanceof DateLabel) {
112
                if (e.getSource() instanceof DateLabel) {
104
                    final DateLabel dateLabel = (DateLabel) e.getSource();
113
                    final DateLabel dateLabel = (DateLabel) e.getSource();
105
                    final Calendar c = Calendar.getInstance();
114
                    final Calendar c = Calendar.getInstance();
106
                    final long timeInMillis = dateLabel.getTimeInMillis();
115
                    final long timeInMillis = dateLabel.getTimeInMillis();
107
                    c.setTimeInMillis(timeInMillis);
116
                    c.setTimeInMillis(timeInMillis);
108
                    setSelectedDate(c);
117
                    setSelectedDate(c);
109
                    return timeInMillis;
118
                    return timeInMillis;
110
                }
119
                }
111
                return -1;
120
                return -1;
112
            }
121
            }
113
 
122
 
114
            @Override
123
            @Override
115
            public void mouseDragged(MouseEvent e) {
124
            public void mouseDragged(MouseEvent e) {
116
                e.setSource(dayPanel.getComponentAt(SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), dayPanel)));
125
                e.setSource(dayPanel.getComponentAt(SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), dayPanel)));
117
                select(e);
126
                select(e);
118
            }
127
            }
119
 
128
 
120
            @Override
129
            @Override
121
            public void mousePressed(MouseEvent e) {
130
            public void mousePressed(MouseEvent e) {
122
                // Nothing
131
                // Nothing
123
            }
132
            }
124
 
133
 
125
            @Override
134
            @Override
126
            public void mouseReleased(MouseEvent e) {
135
            public void mouseReleased(MouseEvent e) {
127
                e.setSource(dayPanel.getComponentAt(SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), dayPanel)));
136
                e.setSource(dayPanel.getComponentAt(SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), dayPanel)));
128
                long timeInMillis = select(e);
137
                long timeInMillis = select(e);
129
                if (timeInMillis >= 0) {
138
                if (timeInMillis >= 0) {
130
                    firePropertyChange(TIME_IN_MILLIS, Long.valueOf(0), Long.valueOf(timeInMillis));
139
                    firePropertyChange(TIME_IN_MILLIS, Long.valueOf(0), Long.valueOf(timeInMillis));
131
                }
140
                }
132
            }
141
            }
133
        };
142
        };
134
 
143
 
135
        for (int i = 0; i < rowCount - 1; i++) {
144
        for (int i = 0; i < rowCount - 1; i++) {
136
            for (int j = 0; j < colCount; j++) {
145
            for (int j = 0; j < colCount; j++) {
137
                final DateLabel label = new DateLabel(String.valueOf(c), SwingConstants.RIGHT);
146
                final DateLabel label = new DateLabel(String.valueOf(c), SwingConstants.RIGHT);
138
                label.addMouseListener(mListener);
147
                label.addMouseListener(mListener);
139
                label.addMouseMotionListener(mListener);
148
                label.addMouseMotionListener(mListener);
140
                label.setOpaque(true);
149
                label.setOpaque(true);
141
                this.labels.add(label);
150
                this.labels.add(label);
142
                dayPanel.add(label);
151
                dayPanel.add(label);
143
                c++;
152
                c++;
144
            }
153
            }
145
 
154
 
146
        }
155
        }
147
 
156
 
148
        this.add(dayPanel, BorderLayout.CENTER);
157
        this.add(dayPanel, BorderLayout.CENTER);
149
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
158
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
150
        // Today
159
        // Today
151
        final JLabel date = new JLabel(df.format(new Date()), SwingConstants.CENTER);
160
        final JLabel date = new JLabel(df.format(new Date()), SwingConstants.CENTER);
152
        date.setBorder(BorderFactory.createEmptyBorder(4, 3, 5, 3));
161
        date.setBorder(BorderFactory.createEmptyBorder(4, 3, 5, 3));
153
        this.add(date, BorderLayout.SOUTH);
162
        this.add(date, BorderLayout.SOUTH);
154
        //
163
        //
155
        updateLabels();
164
        updateLabels();
156
        bRight.addActionListener(this);
165
        bRight.addActionListener(this);
157
        bLeft.addActionListener(this);
166
        bLeft.addActionListener(this);
158
        date.addMouseListener(this);
167
        date.addMouseListener(this);
159
 
168
 
160
    }
169
    }
161
 
170
 
162
    public Date getSelectedDate() {
171
    public Date getSelectedDate() {
163
        return selectedDate;
172
        return selectedDate;
164
    }
173
    }
165
 
174
 
166
    public void setSelectedDate(Calendar cal) {
175
    public void setSelectedDate(Calendar cal) {
167
        if (cal == null) {
176
        if (cal == null) {
168
            this.selectedDate = null;
177
            this.selectedDate = null;
169
            setDate(Calendar.getInstance());
178
            setDate(Calendar.getInstance());
170
        } else if (this.selectedDate == null || !this.selectedDate.equals(cal.getTime())) {
179
        } else if (this.selectedDate == null || !this.selectedDate.equals(cal.getTime())) {
171
            this.selectedDate = cal.getTime();
180
            this.selectedDate = cal.getTime();
172
            setDate(cal);
181
            setDate(cal);
173
        }
182
        }
174
    }
183
    }
175
 
184
 
176
    public void setDate(Calendar cal) {
185
    public void setDate(Calendar cal) {
177
        this.currentYear = cal.get(Calendar.YEAR);
186
        this.currentYear = cal.get(Calendar.YEAR);
178
        this.currentMonth = cal.get(Calendar.MONTH);
187
        this.currentMonth = cal.get(Calendar.MONTH);
179
        updateLabels();
188
        updateLabels();
180
    }
189
    }
181
 
190
 
182
    private void configureButton(final JButton button) {
191
    private void configureButton(final JButton button) {
183
        int buttonSize = 28;
192
        int buttonSize = button.getIcon().getIconWidth() + 8;
184
        button.setMinimumSize(new Dimension(buttonSize, buttonSize));
193
        button.setMinimumSize(new Dimension(buttonSize, buttonSize));
185
        button.setPreferredSize(new Dimension(buttonSize, buttonSize));
194
        button.setPreferredSize(new Dimension(buttonSize, buttonSize));
186
        button.setFocusPainted(false);
195
        button.setFocusPainted(false);
187
        button.setBorderPainted(false);
196
        button.setBorderPainted(false);
188
        button.setBorder(null);
197
        button.setBorder(null);
189
        button.setContentAreaFilled(false);
198
        button.setContentAreaFilled(false);
190
        button.setOpaque(false);
199
        button.setOpaque(false);
191
    }
200
    }
192
 
201
 
193
    private void updateLabels() {
202
    private void updateLabels() {
194
        int selectedYear = -1;
203
        int selectedYear = -1;
195
        int selectedDay = -1;
204
        int selectedDay = -1;
196
        if (selectedDate != null) {
205
        if (selectedDate != null) {
197
            Calendar calSelected = Calendar.getInstance();
206
            Calendar calSelected = Calendar.getInstance();
198
            calSelected.setTime(this.selectedDate);
207
            calSelected.setTime(this.selectedDate);
199
            selectedYear = calSelected.get(Calendar.YEAR);
208
            selectedYear = calSelected.get(Calendar.YEAR);
200
            selectedDay = calSelected.get(Calendar.DAY_OF_YEAR);
209
            selectedDay = calSelected.get(Calendar.DAY_OF_YEAR);
201
        }
210
        }
202
 
211
 
203
        Calendar cal = Calendar.getInstance();
212
        Calendar cal = Calendar.getInstance();
204
        int todayYear = cal.get(Calendar.YEAR);
213
        int todayYear = cal.get(Calendar.YEAR);
205
        int todayDay = cal.get(Calendar.DAY_OF_YEAR);
214
        int todayDay = cal.get(Calendar.DAY_OF_YEAR);
206
        cal.clear();
215
        cal.clear();
207
        cal.set(Calendar.YEAR, this.currentYear);
216
        cal.set(Calendar.YEAR, this.currentYear);
208
        cal.set(Calendar.MONTH, this.currentMonth);
217
        cal.set(Calendar.MONTH, this.currentMonth);
209
        cal.set(Calendar.DAY_OF_MONTH, 1);
218
        cal.set(Calendar.DAY_OF_MONTH, 1);
210
        SimpleDateFormat sdf = new SimpleDateFormat("MMMM yyyy");
219
        SimpleDateFormat sdf = new SimpleDateFormat("MMMM yyyy");
211
        title.setText(sdf.format(cal.getTime()));
220
        title.setText(sdf.format(cal.getTime()));
212
 
221
 
213
        int f = cal.getFirstDayOfWeek();
222
        int f = cal.getFirstDayOfWeek();
214
        int offset = cal.get(Calendar.DAY_OF_WEEK) - f + 1; // offset du 1er jour du mois par
223
        int offset = cal.get(Calendar.DAY_OF_WEEK) - f + 1; // offset du 1er jour du mois par
215
                                                            // rapport a
224
                                                            // rapport a
216
 
225
 
217
        if (offset < 2) {
226
        if (offset < 2) {
218
            offset += 7;
227
            offset += 7;
219
        }
228
        }
220
 
229
 
221
        // grille
230
        // grille
222
        cal.add(Calendar.DAY_OF_YEAR, -offset);
231
        cal.add(Calendar.DAY_OF_YEAR, -offset);
223
 
232
 
224
        int c = 0;
233
        int c = 0;
225
        for (int i = 0; i < rowCount - 1; i++) {
234
        for (int i = 0; i < rowCount - 1; i++) {
226
            for (int j = 0; j < colCount; j++) {
235
            for (int j = 0; j < colCount; j++) {
227
                cal.add(Calendar.DAY_OF_YEAR, 1);
236
                cal.add(Calendar.DAY_OF_YEAR, 1);
228
                final DateLabel label = this.labels.get(c);
237
                final DateLabel label = this.labels.get(c);
229
                label.setDate(cal);
238
                label.setDate(cal);
230
                label.setText(cal.get(Calendar.DAY_OF_MONTH) + "  ");
239
                label.setText(cal.get(Calendar.DAY_OF_MONTH) + "  ");
231
                if (cal.get(Calendar.MONTH) != this.currentMonth) {
240
                if (cal.get(Calendar.MONTH) != this.currentMonth) {
232
                    if (!label.getForeground().equals(Color.GRAY))
241
                    if (!label.getForeground().equals(Color.GRAY))
233
                        label.setForeground(Color.GRAY);
242
                        label.setForeground(Color.GRAY);
234
                } else {
243
                } else {
235
                    if (!label.getForeground().equals(Color.BLACK))
244
                    if (!label.getForeground().equals(Color.BLACK))
236
                        label.setForeground(Color.BLACK);
245
                        label.setForeground(Color.BLACK);
237
                }
246
                }
238
                if (cal.get(Calendar.YEAR) == todayYear && cal.get(Calendar.DAY_OF_YEAR) == todayDay) {
247
                if (cal.get(Calendar.YEAR) == todayYear && cal.get(Calendar.DAY_OF_YEAR) == todayDay) {
239
                    label.setBackground(Color.LIGHT_GRAY);
248
                    label.setBackground(Color.LIGHT_GRAY);
240
                    label.setForeground(Color.WHITE);
249
                    label.setForeground(Color.WHITE);
241
                } else {
250
                } else {
242
                    label.setBackground(Color.WHITE);
251
                    label.setBackground(Color.WHITE);
243
                }
252
                }
244
                if (cal.get(Calendar.YEAR) == selectedYear && cal.get(Calendar.DAY_OF_YEAR) == selectedDay) {
253
                if (cal.get(Calendar.YEAR) == selectedYear && cal.get(Calendar.DAY_OF_YEAR) == selectedDay) {
245
                    label.setBackground(new Color(232, 242, 250));
254
                    label.setBackground(new Color(232, 242, 250));
246
                    label.setForeground(Color.BLACK);
255
                    label.setForeground(Color.BLACK);
247
                }
256
                }
248
                c++;
257
                c++;
249
            }
258
            }
250
 
259
 
251
        }
260
        }
252
 
261
 
253
    }
262
    }
254
 
263
 
255
    @Override
264
    @Override
256
    public void setFocusable(boolean focusable) {
265
    public void setFocusable(boolean focusable) {
257
        super.setFocusable(focusable);
266
        super.setFocusable(focusable);
258
        bRight.setFocusable(focusable);
267
        bRight.setFocusable(focusable);
259
        bLeft.setFocusable(focusable);
268
        bLeft.setFocusable(focusable);
260
    }
269
    }
261
 
270
 
262
    public static void main(String[] args) {
271
    public static void main(String[] args) {
263
        SwingUtilities.invokeLater(new Runnable() {
272
        SwingUtilities.invokeLater(new Runnable() {
264
            public void run() {
273
            public void run() {
265
                try {
274
                try {
266
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
275
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
267
                } catch (Exception e1) {
276
                } catch (Exception e1) {
268
                    e1.printStackTrace();
277
                    e1.printStackTrace();
269
                }
278
                }
270
                final JFrame f = new JFrame();
279
                final JFrame f = new JFrame();
271
                final DatePickerPanel picker = new DatePickerPanel();
280
                final DatePickerPanel picker = new DatePickerPanel();
272
                picker.addPropertyChangeListener(TIME_IN_MILLIS, new PropertyChangeListener() {
281
                picker.addPropertyChangeListener(TIME_IN_MILLIS, new PropertyChangeListener() {
273
 
282
 
274
                    @Override
283
                    @Override
275
                    public void propertyChange(PropertyChangeEvent evt) {
284
                    public void propertyChange(PropertyChangeEvent evt) {
276
                        final Long millis = (Long) evt.getNewValue();
285
                        final Long millis = (Long) evt.getNewValue();
277
                        Calendar c = Calendar.getInstance();
286
                        Calendar c = Calendar.getInstance();
278
                        c.setTimeInMillis(millis);
287
                        c.setTimeInMillis(millis);
279
                        f.dispose();
288
                        f.dispose();
280
 
289
 
281
                    }
290
                    }
282
                });
291
                });
283
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
292
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
284
                f.setContentPane(picker);
293
                f.setContentPane(picker);
285
                f.pack();
294
                f.pack();
286
                f.setLocationRelativeTo(null);
295
                f.setLocationRelativeTo(null);
287
                f.setVisible(true);
296
                f.setVisible(true);
288
 
297
 
289
                final JFrame f1 = new JFrame();
298
                final JFrame f1 = new JFrame();
290
                final DatePicker p = new DatePicker();
299
                final DatePicker p = new DatePicker();
291
                Calendar c = Calendar.getInstance();
300
                Calendar c = Calendar.getInstance();
292
                c.set(Calendar.YEAR, 2010);
301
                c.set(Calendar.YEAR, 2010);
293
                c.set(Calendar.MONTH, 2);
302
                c.set(Calendar.MONTH, 2);
294
                c.set(Calendar.DAY_OF_MONTH, 1);
303
                c.set(Calendar.DAY_OF_MONTH, 1);
295
 
304
 
296
                p.setDate(c.getTime());
305
                p.setDate(c.getTime());
297
                p.setDate(null);
306
                p.setDate(null);
298
                final JPanel pRed = new JPanel();
307
                final JPanel pRed = new JPanel();
299
                pRed.setBackground(Color.RED);
308
                pRed.setBackground(Color.RED);
300
                pRed.add(p);
309
                pRed.add(p);
301
                pRed.add(new JTextField("Dummy TextField"));
310
                pRed.add(new JTextField("Dummy TextField"));
302
 
311
 
303
                f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
312
                f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
304
                f1.setContentPane(pRed);
313
                f1.setContentPane(pRed);
305
                f1.pack();
314
                f1.pack();
306
                f1.setLocation(f.getLocation().x + f.getWidth() + 10, f.getLocation().y);
315
                f1.setLocation(f.getLocation().x + f.getWidth() + 10, f.getLocation().y);
307
                f1.setVisible(true);
316
                f1.setVisible(true);
308
 
317
 
309
            }
318
            }
310
        });
319
        });
311
 
320
 
312
    }
321
    }
313
 
322
 
314
    @Override
323
    @Override
315
    public void actionPerformed(ActionEvent e) {
324
    public void actionPerformed(ActionEvent e) {
316
        // Buttons + / -
325
        // Buttons + / -
317
        Calendar cal = Calendar.getInstance();
326
        Calendar cal = Calendar.getInstance();
318
        cal.clear();
327
        cal.clear();
319
        cal.set(Calendar.YEAR, this.currentYear);
328
        cal.set(Calendar.YEAR, this.currentYear);
320
        cal.set(Calendar.MONTH, this.currentMonth);
329
        cal.set(Calendar.MONTH, this.currentMonth);
321
        if (e.getSource().equals(this.bLeft)) {
330
        if (e.getSource().equals(this.bLeft)) {
322
            cal.add(Calendar.MONTH, -1);
331
            cal.add(Calendar.MONTH, -1);
323
        } else if (e.getSource().equals(this.bRight)) {
332
        } else if (e.getSource().equals(this.bRight)) {
324
            cal.add(Calendar.MONTH, 1);
333
            cal.add(Calendar.MONTH, 1);
325
        }
334
        }
326
        setDate(cal);
335
        setDate(cal);
327
    }
336
    }
328
 
337
 
329
    @Override
338
    @Override
330
    public void mouseClicked(MouseEvent e) {
339
    public void mouseClicked(MouseEvent e) {
331
    }
340
    }
332
 
341
 
333
    @Override
342
    @Override
334
    public void mousePressed(MouseEvent e) {
343
    public void mousePressed(MouseEvent e) {
335
        Calendar cal = Calendar.getInstance();
344
        Calendar cal = Calendar.getInstance();
336
        cal.set(Calendar.SECOND, 0);
345
        cal.set(Calendar.SECOND, 0);
337
        cal.set(Calendar.MILLISECOND, 0);
346
        cal.set(Calendar.MILLISECOND, 0);
338
        if (e.getClickCount() > 1) {
347
        if (e.getClickCount() > 1) {
339
            setSelectedDate(cal);
348
            setSelectedDate(cal);
340
            firePropertyChange(TIME_IN_MILLIS, Long.valueOf(0), Long.valueOf(cal.getTimeInMillis()));
349
            firePropertyChange(TIME_IN_MILLIS, Long.valueOf(0), Long.valueOf(cal.getTimeInMillis()));
341
        } else {
350
        } else {
342
            setDate(cal);
351
            setDate(cal);
343
        }
352
        }
344
    }
353
    }
345
 
354
 
346
    @Override
355
    @Override
347
    public void mouseReleased(MouseEvent e) {
356
    public void mouseReleased(MouseEvent e) {
-
 
357
        // Nothing
348
    }
358
    }
349
 
359
 
350
    @Override
360
    @Override
351
    public void mouseEntered(MouseEvent e) {
361
    public void mouseEntered(MouseEvent e) {
-
 
362
        // Nothing
352
    }
363
    }
353
 
364
 
354
    @Override
365
    @Override
355
    public void mouseExited(MouseEvent e) {
366
    public void mouseExited(MouseEvent e) {
-
 
367
        // Nothing
356
    }
368
    }
357
 
369
 
358
}
370
}