OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 137 | Rev 168 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 137 Rev 150
Line 27... Line 27...
27
import javax.swing.SpinnerNumberModel;
27
import javax.swing.SpinnerNumberModel;
28
import javax.swing.event.ChangeEvent;
28
import javax.swing.event.ChangeEvent;
29
import javax.swing.event.ChangeListener;
29
import javax.swing.event.ChangeListener;
30
 
30
 
31
public class CalendarWithToolBar extends JPanel {
31
public class CalendarWithToolBar extends JPanel {
32
    private WeekView weekView;
32
    private final WeekView weekView;
33
    private JSpinner spinWeek;
33
    private final JSpinner spinWeek;
34
    private JSpinner spinYear;
34
    private final JSpinner spinYear;
-
 
35
    private final DatePicker picker;
35
    private String title;
36
    private String title;
36
    final JScrollPane contentPane = new JScrollPane();
37
    final JScrollPane contentPane = new JScrollPane();
37
 
38
 
38
    public CalendarWithToolBar(JCalendarItemProvider manager) {
39
    public CalendarWithToolBar(JCalendarItemProvider manager) {
39
        this(manager, false);
40
        this(manager, false);
40
    }
41
    }
41
 
42
 
42
    public CalendarWithToolBar(JCalendarItemProvider manager, boolean showPrintButton) {
43
    public CalendarWithToolBar(JCalendarItemProvider manager, boolean showPrintButton) {
-
 
44
        this.weekView = new WeekView(manager);
-
 
45
 
43
        JPanel toolbar = new JPanel();
46
        JPanel toolbar = new JPanel();
44
        toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
47
        toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
45
 
48
 
46
        Calendar cal = Calendar.getInstance();
49
        Calendar cal = Calendar.getInstance();
47
        int week = cal.get(Calendar.WEEK_OF_YEAR);
50
        int week = cal.get(Calendar.WEEK_OF_YEAR);
Line 74... Line 77...
74
        toolbar.add(spinWeek);
77
        toolbar.add(spinWeek);
75
        toolbar.add(new JLabel(" de "));
78
        toolbar.add(new JLabel(" de "));
76
        spinYear = new JSpinner(new SpinnerNumberModel(year, 1000, year + 20, 1));
79
        spinYear = new JSpinner(new SpinnerNumberModel(year, 1000, year + 20, 1));
77
        toolbar.add(spinYear);
80
        toolbar.add(spinYear);
78
        //
81
        //
79
        final DatePicker picker = new DatePicker(false);
82
        this.picker = new DatePicker(false);
80
        toolbar.add(picker);
83
        toolbar.add(picker);
81
        //
84
        //
82
 
85
 
83
        final JSlider zoomSlider = new JSlider(1, 9, 1);
86
        final JSlider zoomSlider = createZoomSlider(this.weekView);
84
        zoomSlider.setSnapToTicks(true);
-
 
85
        zoomSlider.setMajorTickSpacing(1);
-
 
86
        zoomSlider.setPaintTicks(true);
-
 
87
        zoomSlider.addChangeListener(new ChangeListener() {
-
 
88
 
-
 
89
            @Override
-
 
90
            public void stateChanged(ChangeEvent e) {
-
 
91
                weekView.setZoom(zoomSlider.getValue());
-
 
92
            }
-
 
93
        });
-
 
94
        toolbar.add(new JLabel(" Zoom"));
87
        toolbar.add(new JLabel(" Zoom"));
95
        toolbar.add(zoomSlider);
88
        toolbar.add(zoomSlider);
96
        if (showPrintButton) {
89
        if (showPrintButton) {
97
            final JButton jButton = new JButton("Imprimer");
90
            final JButton jButton = new JButton("Imprimer");
98
            jButton.addActionListener(new ActionListener() {
91
            jButton.addActionListener(new ActionListener() {
Line 131... Line 124...
131
        c.fill = GridBagConstraints.BOTH;
124
        c.fill = GridBagConstraints.BOTH;
132
        c.weighty = 1;
125
        c.weighty = 1;
133
 
126
 
134
        contentPane.setBorder(BorderFactory.createEmptyBorder());
127
        contentPane.setBorder(BorderFactory.createEmptyBorder());
135
        contentPane.setOpaque(false);
128
        contentPane.setOpaque(false);
136
        weekView = new WeekView(manager);
-
 
137
        contentPane.setColumnHeaderView(new WeekViewHeader(weekView));
129
        contentPane.setColumnHeaderView(new WeekViewHeader(weekView));
138
        contentPane.setViewportView(weekView);
130
        contentPane.setViewportView(weekView);
139
        contentPane.getViewport().setBackground(Color.WHITE);
131
        contentPane.getViewport().setBackground(Color.WHITE);
140
        final MouseWheelListener[] l = contentPane.getMouseWheelListeners();
132
        final MouseWheelListener[] l = contentPane.getMouseWheelListeners();
141
        for (int i = 0; i < l.length; i++) {
133
        for (int i = 0; i < l.length; i++) {
Line 187... Line 179...
187
            }
179
            }
188
        });
180
        });
189
 
181
 
190
    }
182
    }
191
 
183
 
-
 
184
    public static JSlider createZoomSlider(final MultipleDayView mdview) {
-
 
185
        final JSlider zoomSlider = new JSlider(1, 9, 1);
-
 
186
        zoomSlider.setSnapToTicks(true);
-
 
187
        zoomSlider.setMajorTickSpacing(1);
-
 
188
        zoomSlider.setPaintTicks(true);
-
 
189
        zoomSlider.addChangeListener(new ChangeListener() {
-
 
190
            @Override
-
 
191
            public void stateChanged(ChangeEvent e) {
-
 
192
                mdview.setZoom(zoomSlider.getValue());
-
 
193
            }
-
 
194
        });
-
 
195
        mdview.addPropertyChangeListener("zoom", new PropertyChangeListener() {
-
 
196
            @Override
-
 
197
            public void propertyChange(PropertyChangeEvent evt) {
-
 
198
                zoomSlider.setValue(((Number) evt.getNewValue()).intValue());
-
 
199
            }
-
 
200
        });
-
 
201
        return zoomSlider;
-
 
202
    }
-
 
203
 
192
    protected void addWeek(int i) {
204
    protected void addWeek(int i) {
193
        Calendar c = getCurrentDate();
205
        Calendar c = getCurrentDate();
194
        c.add(Calendar.DAY_OF_YEAR, i * 7);
206
        c.add(Calendar.DAY_OF_YEAR, i * 7);
195
        final int year = c.get(Calendar.YEAR);
207
        final int year = c.get(Calendar.YEAR);
196
        final int week = c.get(Calendar.WEEK_OF_YEAR);
208
        final int week = c.get(Calendar.WEEK_OF_YEAR);
Line 205... Line 217...
205
        c.set(Calendar.YEAR, getYear());
217
        c.set(Calendar.YEAR, getYear());
206
        c.set(Calendar.WEEK_OF_YEAR, getWeek());
218
        c.set(Calendar.WEEK_OF_YEAR, getWeek());
207
        return c;
219
        return c;
208
    }
220
    }
209
 
221
 
-
 
222
    public final void setCurrentDate(final Calendar c) {
-
 
223
        this.setCurrentDate(c.getTime());
-
 
224
    }
-
 
225
 
-
 
226
    public final void setCurrentDate(final Date d) {
-
 
227
        this.picker.setDate(d);
-
 
228
    }
-
 
229
 
210
    private void configureButton(JButton b) {
230
    private void configureButton(JButton b) {
211
        b.setOpaque(false);
231
        b.setOpaque(false);
212
        b.setBorderPainted(false);
232
        b.setBorderPainted(false);
213
        b.setFocusPainted(false);
233
        b.setFocusPainted(false);
214
        b.setContentAreaFilled(false);
234
        b.setContentAreaFilled(false);