OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 137 Rev 178
Line 41... Line 41...
41
 
41
 
42
    /**
42
    /**
43
     * Load week
43
     * Load week
44
     * 
44
     * 
45
     * @param week the week number (1 - 52)
45
     * @param week the week number (1 - 52)
46
     * */
46
     */
47
    public void loadWeek(final int week, final int year, boolean forceReload) {
47
    public void loadWeek(final int week, final int year, boolean forceReload) {
48
        if (!forceReload) {
-
 
49
            if (week == this.week && year == this.year) {
48
        if (!forceReload && week == this.week && year == this.year) {
50
                return;
49
            return;
51
            }
50
        }
52
        }
-
 
53
        this.week = week;
51
        this.week = week;
54
        this.year = year;
52
        this.year = year;
55
        Calendar c = getFirstDayCalendar();
53
        Calendar c = getFirstDayCalendar();
56
        final int columnCount = this.getColumnCount();
54
        final int columnCount = this.getColumnCount();
57
        for (int i = 0; i < columnCount; i++) {
55
        for (int i = 0; i < columnCount; i++) {
Line 62... Line 60...
62
 
60
 
63
        SwingWorker<List<JCalendarItem>, Object> w = new SwingWorker<List<JCalendarItem>, Object>() {
61
        SwingWorker<List<JCalendarItem>, Object> w = new SwingWorker<List<JCalendarItem>, Object>() {
64
 
62
 
65
            @Override
63
            @Override
66
            protected List<JCalendarItem> doInBackground() throws Exception {
64
            protected List<JCalendarItem> doInBackground() throws Exception {
67
                return manager.getItemInWeek(week, year);
65
                return WeekView.this.manager.getItemInWeek(week, year);
68
            }
66
            }
69
 
67
 
-
 
68
            @Override
70
            protected void done() {
69
            protected void done() {
71
                try {
70
                try {
72
                    List<JCalendarItem> l = get();
71
                    List<JCalendarItem> l = get();
73
                    List<List<JCalendarItem>> items = new ArrayList<List<JCalendarItem>>();
72
                    List<List<JCalendarItem>> items = new ArrayList<>();
74
                    for (int i = 0; i < columnCount; i++) {
73
                    for (int i = 0; i < columnCount; i++) {
75
                        List<JCalendarItem> list = new ArrayList<JCalendarItem>();
74
                        List<JCalendarItem> list = new ArrayList<>();
76
                        int d = daysOfYear[i];
75
                        int d = WeekView.this.daysOfYear[i];
77
                        int y = years[i];
76
                        int y = WeekView.this.years[i];
78
                        for (JCalendarItem jCalendarItem : l) {
77
                        for (JCalendarItem jCalendarItem : l) {
79
                            if (jCalendarItem.getDtStart().get(Calendar.DAY_OF_YEAR) == d && jCalendarItem.getDtStart().get(Calendar.YEAR) == y) {
78
                            if (jCalendarItem.getDtStart().get(Calendar.DAY_OF_YEAR) == d && jCalendarItem.getDtStart().get(Calendar.YEAR) == y) {
80
                                list.add(jCalendarItem);
79
                                list.add(jCalendarItem);
81
                            }
80
                            }
82
                        }
81
                        }
Line 85... Line 84...
85
                    setItems(items);
84
                    setItems(items);
86
                } catch (Exception e) {
85
                } catch (Exception e) {
87
                    throw new IllegalStateException("error while getting items", e);
86
                    throw new IllegalStateException("error while getting items", e);
88
                }
87
                }
89
 
88
 
90
            };
89
            }
91
        };
90
        };
92
        w.execute();
91
        w.execute();
93
    }
92
    }
94
 
93
 
95
    public void setWeekEndMinimised(boolean b) {
94
    public void setWeekEndMinimised(boolean b) {
96
        weekEndMinimised = b;
95
        this.weekEndMinimised = b;
97
        repaint();
96
        repaint();
98
    }
97
    }
99
 
98
 
-
 
99
    @Override
100
    public void paintHeader(Graphics g) {
100
    public void paintHeader(Graphics g) {
101
 
-
 
102
        g.setColor(Color.WHITE);
101
        g.setColor(Color.WHITE);
103
        g.fillRect(0, 0, this.getWidth() + 100, getHeaderHeight());
102
        g.fillRect(0, 0, this.getWidth() + 100, getHeaderHeight());
104
        g.setColor(Color.GRAY);
103
        g.setColor(Color.GRAY);
105
        // Vertical lines
104
        // Vertical lines
106
        int columnCount = 7;
105
        int columnCount = 7;
Line 168... Line 167...
168
        int todayYear = today.get(Calendar.YEAR);
167
        int todayYear = today.get(Calendar.YEAR);
169
        int todayDay = today.get(Calendar.DAY_OF_YEAR);
168
        int todayDay = today.get(Calendar.DAY_OF_YEAR);
170
 
169
 
171
        Calendar c = getFirstDayCalendar();
170
        Calendar c = getFirstDayCalendar();
172
        final DateFormat df;
171
        final DateFormat df;
173
        if (!weekEndMinimised) {
172
        if (!this.weekEndMinimised) {
174
            df = new SimpleDateFormat("EEEE d");
173
            df = new SimpleDateFormat("EEEE d");
175
        } else {
174
        } else {
176
            df = new SimpleDateFormat("E d");
175
            df = new SimpleDateFormat("E d");
177
        }
176
        }
178
        for (int i = 0; i < columnCount; i++) {
177
        for (int i = 0; i < columnCount; i++) {
Line 205... Line 204...
205
    private String getMonthName(int day, int year) {
204
    private String getMonthName(int day, int year) {
206
        Calendar c = Calendar.getInstance();
205
        Calendar c = Calendar.getInstance();
207
        c.set(year, 1, 0, 0, 0, 0);
206
        c.set(year, 1, 0, 0, 0, 0);
208
        c.set(Calendar.MILLISECOND, 0);
207
        c.set(Calendar.MILLISECOND, 0);
209
        c.set(Calendar.DAY_OF_YEAR, day);
208
        c.set(Calendar.DAY_OF_YEAR, day);
210
        return monthAndYearFormat.format(c.getTime()).toUpperCase();
209
        return this.monthAndYearFormat.format(c.getTime()).toUpperCase();
211
    }
210
    }
212
 
211
 
213
    private Calendar getFirstDayCalendar() {
212
    private Calendar getFirstDayCalendar() {
214
        Calendar c = Calendar.getInstance();
213
        Calendar c = Calendar.getInstance();
215
        c.set(this.year, 1, 0, 0, 0, 0);
214
        c.set(this.year, 1, 0, 0, 0, 0);
Line 220... Line 219...
220
    }
219
    }
221
 
220
 
222
    @Override
221
    @Override
223
    public String getColumnTitle(int index) {
222
    public String getColumnTitle(int index) {
224
        final DateFormat df;
223
        final DateFormat df;
225
        if (!weekEndMinimised) {
224
        if (!this.weekEndMinimised) {
226
            df = new SimpleDateFormat("EEEE d");
225
            df = new SimpleDateFormat("EEEE d");
227
        } else {
226
        } else {
228
            df = new SimpleDateFormat("E d");
227
            df = new SimpleDateFormat("E d");
229
        }
228
        }
230
        Calendar c = getFirstDayCalendar();
229
        Calendar c = getFirstDayCalendar();
Line 246... Line 245...
246
    }
245
    }
247
 
246
 
248
    @Override
247
    @Override
249
    public int getColumnWidth(int column) {
248
    public int getColumnWidth(int column) {
250
        final int c;
249
        final int c;
251
        if (weekEndMinimised) {
250
        if (this.weekEndMinimised) {
252
            int minSize = 50;
251
            int minSize = 50;
253
            if (column == 5 || column == 6) {
252
            if (column == 5 || column == 6) {
254
                return minSize;
253
                return minSize;
255
            } else {
254
            } else {
256
                c = (this.getWidth() - HOURS_LABEL_WIDTH - 2 * minSize) / (getColumnCount() - 2);
255
                c = (this.getWidth() - HOURS_LABEL_WIDTH - 2 * minSize) / (getColumnCount() - 2);