OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 141 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 141 Rev 150
Line 20... Line 20...
20
import javax.swing.JLabel;
20
import javax.swing.JLabel;
21
import javax.swing.JPanel;
21
import javax.swing.JPanel;
22
import javax.swing.JScrollPane;
22
import javax.swing.JScrollPane;
23
import javax.swing.JSeparator;
23
import javax.swing.JSeparator;
24
import javax.swing.JSlider;
24
import javax.swing.JSlider;
25
import javax.swing.event.ChangeEvent;
-
 
26
import javax.swing.event.ChangeListener;
-
 
27
 
25
 
-
 
26
import org.jopencalendar.ui.CalendarWithToolBar;
28
import org.jopencalendar.ui.DatePicker;
27
import org.jopencalendar.ui.DatePicker;
29
import org.jopencalendar.ui.DayView;
28
import org.jopencalendar.ui.DayView;
30
import org.jopencalendar.ui.ItemPartView;
29
import org.jopencalendar.ui.ItemPartView;
31
import org.jopencalendar.ui.MultipleDayView;
30
import org.jopencalendar.ui.MultipleDayView;
32
import org.jopencalendar.ui.MultipleDayViewHeader;
31
import org.jopencalendar.ui.MultipleDayViewHeader;
33
 
32
 
34
public class MultipleDayCalendarWithToolBar extends JPanel {
33
public class MultipleDayCalendarWithToolBar extends JPanel {
35
    private OperationDayView weekView;
34
    private final OperationDayView weekView;
36
 
35
 
37
    final JScrollPane contentPane = new JScrollPane();
36
    final JScrollPane contentPane = new JScrollPane();
38
    private Date date;
37
    private final DatePicker jDate;
39
 
38
 
40
    public MultipleDayCalendarWithToolBar(OperationDayView mDayView) {
39
    public MultipleDayCalendarWithToolBar(OperationDayView mDayView) {
-
 
40
        this.weekView = mDayView;
-
 
41
 
41
        JPanel toolbar = new JPanel();
42
        JPanel toolbar = new JPanel();
42
        toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
43
        toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
43
 
44
 
44
        Calendar cal = Calendar.getInstance();
-
 
45
 
-
 
46
        this.date = cal.getTime();
-
 
47
        final DatePicker jDate = new DatePicker(false);
45
        this.jDate = new DatePicker(false);
48
        jDate.setDate(date);
-
 
49
        JButton bLeft = createButton(new ImageIcon(DayView.class.getResource("left.png")));
46
        JButton bLeft = createButton(new ImageIcon(DayView.class.getResource("left.png")));
50
        JButton bRight = createButton(new ImageIcon(DayView.class.getResource("right.png")));
47
        JButton bRight = createButton(new ImageIcon(DayView.class.getResource("right.png")));
51
        toolbar.add(bLeft);
48
        toolbar.add(bLeft);
52
        toolbar.add(bRight);
49
        toolbar.add(bRight);
53
        toolbar.add(jDate);
50
        toolbar.add(jDate);
54
        final JSlider zoomSlider = new JSlider(1, 9, 1);
51
        final JSlider zoomSlider = CalendarWithToolBar.createZoomSlider(this.getWeekView());
55
        zoomSlider.setSnapToTicks(true);
-
 
56
        zoomSlider.setMajorTickSpacing(1);
-
 
57
        zoomSlider.setPaintTicks(true);
-
 
58
        zoomSlider.addChangeListener(new ChangeListener() {
-
 
59
 
-
 
60
            @Override
-
 
61
            public void stateChanged(ChangeEvent e) {
-
 
62
                weekView.setZoom(zoomSlider.getValue());
-
 
63
            }
-
 
64
        });
-
 
65
        toolbar.add(new JLabel(" Zoom"));
52
        toolbar.add(new JLabel(" Zoom"));
66
        toolbar.add(zoomSlider);
53
        toolbar.add(zoomSlider);
67
        JButton reloadButton = createButton(new ImageIcon(ItemPartView.class.getResource("auto.png")));
54
        JButton reloadButton = createButton(new ImageIcon(ItemPartView.class.getResource("auto.png")));
68
        toolbar.add(reloadButton);
55
        toolbar.add(reloadButton);
69
        reloadButton.addActionListener(new ActionListener() {
56
        reloadButton.addActionListener(new ActionListener() {
Line 87... Line 74...
87
        c.fill = GridBagConstraints.BOTH;
74
        c.fill = GridBagConstraints.BOTH;
88
        c.weighty = 1;
75
        c.weighty = 1;
89
 
76
 
90
        contentPane.setBorder(BorderFactory.createEmptyBorder());
77
        contentPane.setBorder(BorderFactory.createEmptyBorder());
91
        contentPane.setOpaque(false);
78
        contentPane.setOpaque(false);
92
        weekView = mDayView;
-
 
93
        contentPane.setColumnHeaderView(new MultipleDayViewHeader(weekView));
79
        contentPane.setColumnHeaderView(new MultipleDayViewHeader(weekView));
94
        contentPane.setViewportView(weekView);
80
        contentPane.setViewportView(weekView);
95
        contentPane.getViewport().setBackground(Color.WHITE);
81
        contentPane.getViewport().setBackground(Color.WHITE);
96
        final MouseWheelListener[] l = contentPane.getMouseWheelListeners();
82
        final MouseWheelListener[] l = contentPane.getMouseWheelListeners();
97
        for (int i = 0; i < l.length; i++) {
83
        for (int i = 0; i < l.length; i++) {
Line 107... Line 93...
107
        });
93
        });
108
 
94
 
109
        this.add(contentPane, c);
95
        this.add(contentPane, c);
110
        final int value = 300;
96
        final int value = 300;
111
        contentPane.getVerticalScrollBar().setValue(value);
97
        contentPane.getVerticalScrollBar().setValue(value);
112
        weekView.loadDay(date);
-
 
113
 
98
 
114
        jDate.addPropertyChangeListener("value", new PropertyChangeListener() {
99
        jDate.addPropertyChangeListener("value", new PropertyChangeListener() {
115
 
-
 
116
            @Override
100
            @Override
117
            public void propertyChange(PropertyChangeEvent evt) {
101
            public void propertyChange(PropertyChangeEvent evt) {
118
                if (evt.getNewValue() != null) {
102
                if (evt.getNewValue() != null) {
119
                    final Date d = (Date) evt.getNewValue();
103
                    final Date d = (Date) evt.getNewValue();
120
                    date = d;
-
 
121
                    weekView.loadDay(d);
104
                    weekView.loadDay(d);
122
                }
105
                }
123
            }
106
            }
124
        });
107
        });
-
 
108
        // initial value (don't leave null value)
-
 
109
        assert getDate() == null : "Pb with constructor";
-
 
110
        setDate(new Date());
-
 
111
 
125
        bLeft.addActionListener(new ActionListener() {
112
        bLeft.addActionListener(new ActionListener() {
126
 
113
 
127
            @Override
114
            @Override
128
            public void actionPerformed(ActionEvent e) {
115
            public void actionPerformed(ActionEvent e) {
129
                Calendar c = Calendar.getInstance();
116
                Calendar c = Calendar.getInstance();
130
                c.setTime(date);
117
                c.setTime(getDate());
131
                c.add(Calendar.DAY_OF_YEAR, -1);
118
                c.add(Calendar.DAY_OF_YEAR, -1);
132
                final Date time = c.getTime();
119
                final Date time = c.getTime();
133
                jDate.setDate(time);
120
                setDate(time);
134
                date = time;
-
 
135
            }
121
            }
136
        });
122
        });
137
        bRight.addActionListener(new ActionListener() {
123
        bRight.addActionListener(new ActionListener() {
138
 
124
 
139
            @Override
125
            @Override
140
            public void actionPerformed(ActionEvent e) {
126
            public void actionPerformed(ActionEvent e) {
141
                Calendar c = Calendar.getInstance();
127
                Calendar c = Calendar.getInstance();
142
                c.setTime(date);
128
                c.setTime(getDate());
143
                c.add(Calendar.DAY_OF_YEAR, 1);
129
                c.add(Calendar.DAY_OF_YEAR, 1);
144
                final Date time = c.getTime();
130
                final Date time = c.getTime();
145
                jDate.setDate(time);
131
                setDate(time);
146
                date = time;
-
 
147
            }
132
            }
148
        });
133
        });
149
 
134
 
150
    }
135
    }
151
 
136
 
-
 
137
    public final void setDate(Date date) {
-
 
138
        this.jDate.setDate(date);
-
 
139
    }
-
 
140
 
-
 
141
    public final Date getDate() {
-
 
142
        return this.jDate.getDate();
-
 
143
    }
-
 
144
 
152
    public void reload() {
145
    public void reload() {
153
        weekView.reload();
146
        weekView.reload();
154
    }
147
    }
155
 
148
 
156
    public MultipleDayView getWeekView() {
149
    public MultipleDayView getWeekView() {