OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 137 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
137 ilm 1
package org.jopencalendar.ui;
2
 
3
import java.awt.Color;
4
import java.util.ArrayList;
5
import java.util.Calendar;
6
import java.util.List;
7
 
8
import javax.swing.ImageIcon;
9
 
10
import org.jopencalendar.model.Flag;
11
import org.jopencalendar.model.JCalendarItem;
12
import org.jopencalendar.model.JCalendarItemGroup;
13
 
14
public class JCalendarItemProvider {
15
    private String name;
16
 
17
    public JCalendarItemProvider(String name) {
18
        this.name = name;
19
    }
20
 
21
    public String getName() {
22
        return name;
23
    }
24
 
25
    public List<JCalendarItem> getItemInDay(int dayOfYear, int year) {
26
        List<JCalendarItem> l = new ArrayList<JCalendarItem>();
27
        Calendar cal = Calendar.getInstance();
28
        cal.clear();
29
        cal.set(Calendar.YEAR, year);
30
        cal.set(Calendar.DAY_OF_YEAR, dayOfYear);
31
        cal.add(Calendar.HOUR_OF_DAY, 8);
168 ilm 32
 
137 ilm 33
        int gCount = 0;
34
        JCalendarItemGroup g = new JCalendarItemGroup();
35
        g.setName("Group " + gCount);
36
        Flag flag = new Flag("planned", new ImageIcon(JCalendarItemProvider.class.getResource("calendar_small.png")), "Planned", "planned item");
168 ilm 37
 
38
        JCalendarItem item0 = new JCalendarItem();
39
        item0.addFlag(flag);
40
        item0.setSummary("5 minutes");
41
        item0.setDtStart(cal);
42
        Calendar c2 = (Calendar) cal.clone();
43
        c2.add(Calendar.MINUTE, 5);
44
        item0.setDtEnd(c2);
45
        item0.setDayOnly(false);
46
        g.addItem(item0);
47
        l.add(item0);
48
 
137 ilm 49
        for (int d = 0; d < 8; d++) {
50
            JCalendarItem i = new JCalendarItem();
51
            i.addFlag(flag);
52
            i.setSummary(year + ": day " + dayOfYear);
53
            i.setDtStart(cal);
54
            Calendar cal2 = (Calendar) cal.clone();
55
            cal2.add(Calendar.HOUR_OF_DAY, 1);
56
            i.setDtEnd(cal2);
57
            i.setDayOnly(false);
58
            g.addItem(i);
59
            l.add(i);
60
            if (d % 3 == 0) {
61
                gCount++;
62
                g = new JCalendarItemGroup();
63
                g.setName("Group " + gCount);
64
            }
65
            if (d % 2 == 0) {
66
                i.setLocation("Location" + d);
67
            }
68
        }
69
 
70
        return l;
71
    }
72
 
73
    /**
74
     * @param week 1 - 52
75
     * @param year
76
     */
77
    public List<JCalendarItem> getItemInWeek(int week, int year) {
78
        final List<JCalendarItem> l = new ArrayList<JCalendarItem>();
79
        JCalendarItem i = new JCalendarItem();
80
        Calendar cal = Calendar.getInstance();
81
        cal.set(Calendar.YEAR, year);
82
        cal.set(Calendar.WEEK_OF_YEAR, week);
83
        cal.set(Calendar.HOUR_OF_DAY, 8);
84
        cal.set(Calendar.MINUTE, 0);
85
        i.setSummary("In W: " + week + " year:" + year);
86
        i.setDtStart(cal);
87
        Calendar cal2 = (Calendar) cal.clone();
88
        cal2.add(Calendar.HOUR_OF_DAY, 1);
89
        i.setDtEnd(cal2);
90
        i.setDayOnly(true);
91
        l.add(i);
92
        int gCount = 0;
93
        JCalendarItemGroup g = new JCalendarItemGroup();
94
        g.setName("Group " + gCount);
95
        final Flag flag = new Flag("planned", new ImageIcon(JCalendarItemProvider.class.getResource("calendar_small.png")), "Planned", "planned item");
168 ilm 96
        JCalendarItem item0 = new JCalendarItem();
97
        item0.addFlag(flag);
98
        item0.setSummary("5 minutes");
99
        item0.setDtStart(cal);
100
        Calendar cal3 = (Calendar) cal.clone();
101
        cal3.add(Calendar.MINUTE, 5);
102
        item0.setDtEnd(cal3);
103
        item0.setDayOnly(false);
104
        g.addItem(item0);
105
        l.add(item0);
137 ilm 106
 
107
        for (int d = 1; d < 6; d++) {
108
            {
109
                JCalendarItem item = new JCalendarItem();
110
                item.addFlag(flag);
111
                cal.clear();
112
                cal.set(Calendar.YEAR, year);
113
                cal.set(Calendar.WEEK_OF_YEAR, week);
114
                cal.set(Calendar.HOUR_OF_DAY, 7);
115
                cal.set(Calendar.MINUTE, 0);
116
                cal.add(Calendar.DAY_OF_WEEK, d);
117
                item.setSummary(year + ": day " + d);
118
                item.setDtStart(cal);
119
                Calendar c2 = (Calendar) cal.clone();
120
                c2.set(Calendar.HOUR_OF_DAY, 7 + d);
121
                item.setDtEnd(c2);
122
                item.setDayOnly(false);
123
                g.addItem(item);
124
                l.add(item);
125
                if (d % 2 == 0) {
126
                    gCount++;
127
                    g = new JCalendarItemGroup();
128
                    g.setName("Group " + gCount);
129
                }
130
                if (d % 2 == 0) {
131
                    i.setLocation("Location" + d);
132
                }
133
            }
134
            {
135
                JCalendarItem item = new JCalendarItem();
136
                cal.clear();
137
                cal.set(Calendar.YEAR, year);
138
                cal.set(Calendar.WEEK_OF_YEAR, week);
139
                cal.set(Calendar.HOUR_OF_DAY, 7);
140
                cal.set(Calendar.MINUTE, 0);
141
                cal.add(Calendar.DAY_OF_WEEK, d);
142
                item.setSummary(year + ": day " + d);
143
                item.setDtStart(cal);
144
                Calendar c2 = (Calendar) cal.clone();
145
                c2.set(Calendar.HOUR_OF_DAY, 7 + d);
146
                item.setDtEnd(c2);
147
                item.setDayOnly(false);
148
                g.addItem(item);
149
                l.add(item);
150
                if (d % 2 == 0) {
151
                    gCount++;
152
                    g = new JCalendarItemGroup();
153
                    g.setName("Group " + gCount);
154
                }
155
            }
156
            {
157
                JCalendarItem item = new JCalendarItem();
158
                cal.clear();
159
                cal.set(Calendar.YEAR, year);
160
                cal.set(Calendar.WEEK_OF_YEAR, week);
161
                cal.set(Calendar.HOUR_OF_DAY, 7);
162
                cal.set(Calendar.MINUTE, 0);
163
                cal.add(Calendar.DAY_OF_WEEK, d);
164
                item.setSummary(year + ": day " + d);
165
                item.setDtStart(cal);
166
                Calendar c2 = (Calendar) cal.clone();
167
                c2.set(Calendar.HOUR_OF_DAY, 7 + d);
168
                item.setDtEnd(c2);
169
                item.setDayOnly(false);
170
                g.addItem(item);
171
                l.add(item);
172
                if (d % 2 == 0) {
173
                    gCount++;
174
                    g = new JCalendarItemGroup();
175
                    g.setName("Group " + gCount);
176
                }
177
            }
178
            {
179
                JCalendarItem item = new JCalendarItem();
180
                cal.clear();
181
                cal.set(Calendar.YEAR, year);
182
                cal.set(Calendar.WEEK_OF_YEAR, week);
183
                cal.set(Calendar.HOUR_OF_DAY, 8);
184
                cal.set(Calendar.MINUTE, 0);
185
                cal.add(Calendar.DAY_OF_WEEK, d);
186
                item.setSummary(year + ": day " + d);
187
                item.setDtStart(cal);
188
                Calendar c2 = (Calendar) cal.clone();
189
                c2.set(Calendar.HOUR_OF_DAY, 8 + d);
190
                item.setDtEnd(c2);
191
                item.setDayOnly(false);
192
                g.addItem(item);
193
                l.add(item);
194
                if (d % 2 == 0) {
195
                    gCount++;
196
                    g = new JCalendarItemGroup();
197
                    g.setName("Group " + gCount);
198
                }
199
            }
200
        }
201
 
202
        return l;
203
    }
204
 
205
    public List<JCalendarItem> getItemInYear(int year, int week1, int week2) {
206
        List<JCalendarItem> l = new ArrayList<JCalendarItem>();
207
        Calendar cal = Calendar.getInstance();
208
        cal.clear();
209
        cal.set(Calendar.YEAR, year);
210
        int gCount = 0;
211
        JCalendarItemGroup g = new JCalendarItemGroup();
212
        JCalendarItemGroup g0 = g;
213
        g.setName("Group " + gCount);
214
        for (int d = 1; d < 350; d++) {
215
            JCalendarItem i = new JCalendarItem();
216
            cal.set(Calendar.DAY_OF_YEAR, d);
217
            cal.set(Calendar.HOUR_OF_DAY, 8);
218
            cal.set(Calendar.MINUTE, 0);
219
            i.setSummary(year + ": day " + d);
220
            i.setDtStart(cal);
221
            Calendar cal2 = (Calendar) cal.clone();
222
            cal2.add(Calendar.HOUR_OF_DAY, 1);
223
            i.setDtEnd(cal2);
224
            i.setDayOnly(false);
225
            g.addItem(i);
226
            l.add(i);
227
            if (d % 8 == 0) {
228
                gCount++;
229
                g = new JCalendarItemGroup();
230
                g.setName("Group " + gCount);
231
            }
232
 
233
        }
234
        JCalendarItem i = new JCalendarItem();
235
        i.setColor(Color.RED);
236
        cal.set(Calendar.DAY_OF_YEAR, 3);
237
        cal.set(Calendar.HOUR_OF_DAY, 8);
238
        cal.set(Calendar.MINUTE, 0);
239
        i.setSummary(year + ": day " + 3);
240
        i.setDtStart(cal);
241
        Calendar cal2 = (Calendar) cal.clone();
242
        cal2.add(Calendar.HOUR_OF_DAY, 1);
243
        i.setDtEnd(cal2);
244
        i.setDayOnly(false);
245
        g0.addItem(i);
246
        l.add(i);
247
 
248
        return l;
249
    }
250
}