OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Details | 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);
32
        int gCount = 0;
33
        JCalendarItemGroup g = new JCalendarItemGroup();
34
        g.setName("Group " + gCount);
35
        Flag flag = new Flag("planned", new ImageIcon(JCalendarItemProvider.class.getResource("calendar_small.png")), "Planned", "planned item");
36
        for (int d = 0; d < 8; d++) {
37
            JCalendarItem i = new JCalendarItem();
38
            i.addFlag(flag);
39
            i.setSummary(year + ": day " + dayOfYear);
40
            i.setDtStart(cal);
41
            Calendar cal2 = (Calendar) cal.clone();
42
            cal2.add(Calendar.HOUR_OF_DAY, 1);
43
            i.setDtEnd(cal2);
44
            i.setDayOnly(false);
45
            g.addItem(i);
46
            l.add(i);
47
            if (d % 3 == 0) {
48
                gCount++;
49
                g = new JCalendarItemGroup();
50
                g.setName("Group " + gCount);
51
            }
52
            if (d % 2 == 0) {
53
                i.setLocation("Location" + d);
54
            }
55
        }
56
 
57
        return l;
58
    }
59
 
60
    /**
61
     * @param week 1 - 52
62
     * @param year
63
     */
64
    public List<JCalendarItem> getItemInWeek(int week, int year) {
65
        final List<JCalendarItem> l = new ArrayList<JCalendarItem>();
66
        JCalendarItem i = new JCalendarItem();
67
        Calendar cal = Calendar.getInstance();
68
        cal.set(Calendar.YEAR, year);
69
        cal.set(Calendar.WEEK_OF_YEAR, week);
70
        cal.set(Calendar.HOUR_OF_DAY, 8);
71
        cal.set(Calendar.MINUTE, 0);
72
        i.setSummary("In W: " + week + " year:" + year);
73
        i.setDtStart(cal);
74
        Calendar cal2 = (Calendar) cal.clone();
75
        cal2.add(Calendar.HOUR_OF_DAY, 1);
76
        i.setDtEnd(cal2);
77
        i.setDayOnly(true);
78
        l.add(i);
79
        int gCount = 0;
80
        JCalendarItemGroup g = new JCalendarItemGroup();
81
        g.setName("Group " + gCount);
82
        final Flag flag = new Flag("planned", new ImageIcon(JCalendarItemProvider.class.getResource("calendar_small.png")), "Planned", "planned item");
83
 
84
        for (int d = 1; d < 6; d++) {
85
            {
86
                JCalendarItem item = new JCalendarItem();
87
                item.addFlag(flag);
88
                cal.clear();
89
                cal.set(Calendar.YEAR, year);
90
                cal.set(Calendar.WEEK_OF_YEAR, week);
91
                cal.set(Calendar.HOUR_OF_DAY, 7);
92
                cal.set(Calendar.MINUTE, 0);
93
                cal.add(Calendar.DAY_OF_WEEK, d);
94
                item.setSummary(year + ": day " + d);
95
                item.setDtStart(cal);
96
                Calendar c2 = (Calendar) cal.clone();
97
                c2.set(Calendar.HOUR_OF_DAY, 7 + d);
98
                item.setDtEnd(c2);
99
                item.setDayOnly(false);
100
                g.addItem(item);
101
                l.add(item);
102
                if (d % 2 == 0) {
103
                    gCount++;
104
                    g = new JCalendarItemGroup();
105
                    g.setName("Group " + gCount);
106
                }
107
                if (d % 2 == 0) {
108
                    i.setLocation("Location" + d);
109
                }
110
            }
111
            {
112
                JCalendarItem item = new JCalendarItem();
113
                cal.clear();
114
                cal.set(Calendar.YEAR, year);
115
                cal.set(Calendar.WEEK_OF_YEAR, week);
116
                cal.set(Calendar.HOUR_OF_DAY, 7);
117
                cal.set(Calendar.MINUTE, 0);
118
                cal.add(Calendar.DAY_OF_WEEK, d);
119
                item.setSummary(year + ": day " + d);
120
                item.setDtStart(cal);
121
                Calendar c2 = (Calendar) cal.clone();
122
                c2.set(Calendar.HOUR_OF_DAY, 7 + d);
123
                item.setDtEnd(c2);
124
                item.setDayOnly(false);
125
                g.addItem(item);
126
                l.add(item);
127
                if (d % 2 == 0) {
128
                    gCount++;
129
                    g = new JCalendarItemGroup();
130
                    g.setName("Group " + gCount);
131
                }
132
            }
133
            {
134
                JCalendarItem item = new JCalendarItem();
135
                cal.clear();
136
                cal.set(Calendar.YEAR, year);
137
                cal.set(Calendar.WEEK_OF_YEAR, week);
138
                cal.set(Calendar.HOUR_OF_DAY, 7);
139
                cal.set(Calendar.MINUTE, 0);
140
                cal.add(Calendar.DAY_OF_WEEK, d);
141
                item.setSummary(year + ": day " + d);
142
                item.setDtStart(cal);
143
                Calendar c2 = (Calendar) cal.clone();
144
                c2.set(Calendar.HOUR_OF_DAY, 7 + d);
145
                item.setDtEnd(c2);
146
                item.setDayOnly(false);
147
                g.addItem(item);
148
                l.add(item);
149
                if (d % 2 == 0) {
150
                    gCount++;
151
                    g = new JCalendarItemGroup();
152
                    g.setName("Group " + gCount);
153
                }
154
            }
155
            {
156
                JCalendarItem item = new JCalendarItem();
157
                cal.clear();
158
                cal.set(Calendar.YEAR, year);
159
                cal.set(Calendar.WEEK_OF_YEAR, week);
160
                cal.set(Calendar.HOUR_OF_DAY, 8);
161
                cal.set(Calendar.MINUTE, 0);
162
                cal.add(Calendar.DAY_OF_WEEK, d);
163
                item.setSummary(year + ": day " + d);
164
                item.setDtStart(cal);
165
                Calendar c2 = (Calendar) cal.clone();
166
                c2.set(Calendar.HOUR_OF_DAY, 8 + d);
167
                item.setDtEnd(c2);
168
                item.setDayOnly(false);
169
                g.addItem(item);
170
                l.add(item);
171
                if (d % 2 == 0) {
172
                    gCount++;
173
                    g = new JCalendarItemGroup();
174
                    g.setName("Group " + gCount);
175
                }
176
            }
177
        }
178
 
179
        return l;
180
    }
181
 
182
    public List<JCalendarItem> getItemInYear(int year, int week1, int week2) {
183
        List<JCalendarItem> l = new ArrayList<JCalendarItem>();
184
        Calendar cal = Calendar.getInstance();
185
        cal.clear();
186
        cal.set(Calendar.YEAR, year);
187
        int gCount = 0;
188
        JCalendarItemGroup g = new JCalendarItemGroup();
189
        JCalendarItemGroup g0 = g;
190
        g.setName("Group " + gCount);
191
        for (int d = 1; d < 350; d++) {
192
            JCalendarItem i = new JCalendarItem();
193
            cal.set(Calendar.DAY_OF_YEAR, d);
194
            cal.set(Calendar.HOUR_OF_DAY, 8);
195
            cal.set(Calendar.MINUTE, 0);
196
            i.setSummary(year + ": day " + d);
197
            i.setDtStart(cal);
198
            Calendar cal2 = (Calendar) cal.clone();
199
            cal2.add(Calendar.HOUR_OF_DAY, 1);
200
            i.setDtEnd(cal2);
201
            i.setDayOnly(false);
202
            g.addItem(i);
203
            l.add(i);
204
            if (d % 8 == 0) {
205
                gCount++;
206
                g = new JCalendarItemGroup();
207
                g.setName("Group " + gCount);
208
            }
209
 
210
        }
211
        JCalendarItem i = new JCalendarItem();
212
        i.setColor(Color.RED);
213
        cal.set(Calendar.DAY_OF_YEAR, 3);
214
        cal.set(Calendar.HOUR_OF_DAY, 8);
215
        cal.set(Calendar.MINUTE, 0);
216
        i.setSummary(year + ": day " + 3);
217
        i.setDtStart(cal);
218
        Calendar cal2 = (Calendar) cal.clone();
219
        cal2.add(Calendar.HOUR_OF_DAY, 1);
220
        i.setDtEnd(cal2);
221
        i.setDayOnly(false);
222
        g0.addItem(i);
223
        l.add(i);
224
 
225
        return l;
226
    }
227
}