KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > frame > TestDataGenerator


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.calendar.ui.frame;
19
20 import java.awt.Color JavaDoc;
21 import java.awt.Shape JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Calendar JavaDoc;
24 import java.util.GregorianCalendar JavaDoc;
25
26 import com.miginfocom.ashape.shapes.AShape;
27 import com.miginfocom.calendar.activity.Activity;
28 import com.miginfocom.calendar.activity.ActivityDepository;
29 import com.miginfocom.calendar.activity.DefaultActivity;
30 import com.miginfocom.calendar.activity.recurrence.ByXXXRuleData;
31 import com.miginfocom.calendar.activity.recurrence.CompositeRecurrence;
32 import com.miginfocom.calendar.activity.recurrence.RecurrenceRule;
33 import com.miginfocom.calendar.category.Category;
34 import com.miginfocom.calendar.category.CategoryDepository;
35 import com.miginfocom.util.ActivityHelper;
36 import com.miginfocom.util.dates.ImmutableDateRange;
37 import com.miginfocom.util.gfx.GfxUtil;
38 import com.miginfocom.util.gfx.RoundRectangle;
39 import com.miginfocom.util.gfx.ShapeGradientPaint;
40
41 public class TestDataGenerator {
42
43     static final Object JavaDoc[] CATEGORIES = { new Integer JavaDoc(10), new Integer JavaDoc(11),
44             new Integer JavaDoc(12), new Integer JavaDoc(13) };
45
46     static final String JavaDoc[] TITLES = { "Going to the Gym",
47             "Meeting with the Board", "Taking Mick to Icehockey",
48             "Lunch with Susanne", "Lunch with Matt", "Meeting about the Site",
49             "Template work", "Fix the car", "Take the car to the shop",
50             "Call Chris about the fishing trip", "Major cleaning",
51             "Rafactoring code" };
52
53     /**
54      *
55      */

56     public static void generateTestData() {
57         Object JavaDoc calendarsID = new Integer JavaDoc(9);
58         Object JavaDoc remoteCalendarsID = new Integer JavaDoc(100);
59         Object JavaDoc markID = CATEGORIES[0];
60         Object JavaDoc susanID = CATEGORIES[1];
61         Object JavaDoc michaelID = CATEGORIES[2];
62         Object JavaDoc gregID = CATEGORIES[3];
63
64         Category root = CategoryDepository.getRoot();
65
66         Category calendars = root.addSubCategory(calendarsID, "Local");
67         calendars.addSubCategory(markID, "Mark");
68         calendars.addSubCategory(susanID, "Susan");
69         calendars.addSubCategory(michaelID, "Michael");
70         calendars.addSubCategory(gregID, "Greg");
71         
72         root.addSubCategory(remoteCalendarsID, "Web");
73
74         
75         
76         Shape JavaDoc defaultShape = new RoundRectangle(0, 0, 12, 12, 6, 6);
77         Color JavaDoc markColor = new Color JavaDoc(255, 180, 180);
78         Color JavaDoc markOutlineColor = GfxUtil.tintColor(markColor, -0.4f);
79         CategoryDepository.setOverride(markID, "bg", AShape.A_PAINT, markColor);
80         CategoryDepository.setOverride(markID, "bgTrans", AShape.A_PAINT,
81                 GfxUtil.alphaColor(markColor, 145));
82         CategoryDepository.setOverride(markID, "outline", AShape.A_PAINT,
83                 markOutlineColor);
84         CategoryDepository.setOverride(markID, "treeCheckBox", AShape.A_PAINT,
85                 new ShapeGradientPaint(markColor, 0.2f, 115, false));
86         CategoryDepository.setOverride(markID, "treeCheckBoxOutline",
87                 AShape.A_PAINT, markOutlineColor);
88         CategoryDepository.setOverride(markID, "titleText", AShape.A_PAINT,
89                 markOutlineColor);
90         CategoryDepository.setOverride(markID, "mainText", AShape.A_PAINT,
91                 markOutlineColor);
92         CategoryDepository.setOverride(markID, "treeCheckBox", AShape.A_SHAPE,
93                 defaultShape);
94         CategoryDepository.setOverride(markID, "treeCheckBoxOutline",
95                 AShape.A_SHAPE, defaultShape);
96
97         Color JavaDoc susanColor = new Color JavaDoc(200, 200, 255);
98         Color JavaDoc susanOutlineColor = GfxUtil.tintColor(susanColor, -0.4f);
99         CategoryDepository.setOverride(susanID, "bg", AShape.A_PAINT,
100                 susanColor);
101         CategoryDepository.setOverride(susanID, "bgTrans", AShape.A_PAINT,
102                 GfxUtil.alphaColor(susanColor, 145));
103         CategoryDepository.setOverride(susanID, "outline", AShape.A_PAINT,
104                 susanOutlineColor);
105         CategoryDepository.setOverride(susanID, "treeCheckBox", AShape.A_PAINT,
106                 new ShapeGradientPaint(susanColor, 0.2f, 115, false));
107         CategoryDepository.setOverride(susanID, "treeCheckBoxOutline",
108                 AShape.A_PAINT, susanOutlineColor);
109         CategoryDepository.setOverride(susanID, "titleText", AShape.A_PAINT,
110                 susanOutlineColor);
111         CategoryDepository.setOverride(susanID, "mainText", AShape.A_PAINT,
112                 susanOutlineColor);
113         CategoryDepository.setOverride(susanID, "treeCheckBox", AShape.A_SHAPE,
114                 defaultShape);
115
116         Color JavaDoc michaelColor = new Color JavaDoc(255, 235, 100);
117         Color JavaDoc michaelOutlineColor = GfxUtil.tintColor(michaelColor, -0.4f);
118         CategoryDepository.setOverride(michaelID, "bg", AShape.A_PAINT,
119                 michaelColor);
120         CategoryDepository.setOverride(michaelID, "bgTrans", AShape.A_PAINT,
121                 GfxUtil.alphaColor(michaelColor, 145));
122         CategoryDepository.setOverride(michaelID, "outline", AShape.A_PAINT,
123                 michaelOutlineColor);
124         CategoryDepository.setOverride(michaelID, "treeCheckBox",
125                 AShape.A_PAINT, new ShapeGradientPaint(michaelColor, 0.2f, 115,
126                         false));
127         CategoryDepository.setOverride(michaelID, "treeCheckBoxOutline",
128                 AShape.A_PAINT, michaelOutlineColor);
129         CategoryDepository.setOverride(michaelID, "titleText", AShape.A_PAINT,
130                 michaelOutlineColor);
131         CategoryDepository.setOverride(michaelID, "mainText", AShape.A_PAINT,
132                 michaelOutlineColor);
133         CategoryDepository.setOverride(michaelID, "treeCheckBox",
134                 AShape.A_SHAPE, defaultShape);
135
136         Color JavaDoc gregColor = new Color JavaDoc(180, 245, 180);
137         Color JavaDoc gregOutlineColor = GfxUtil.tintColor(gregColor, -0.4f);
138         CategoryDepository.setOverride(gregID, "bg", AShape.A_PAINT, gregColor);
139         CategoryDepository.setOverride(gregID, "bgTrans", AShape.A_PAINT,
140                 GfxUtil.alphaColor(gregColor, 145));
141         CategoryDepository.setOverride(gregID, "outline", AShape.A_PAINT,
142                 gregOutlineColor);
143         CategoryDepository.setOverride(gregID, "treeCheckBox", AShape.A_PAINT,
144                 new ShapeGradientPaint(gregColor, 0.2f, 115, false));
145         CategoryDepository.setOverride(gregID, "treeCheckBoxOutline",
146                 AShape.A_PAINT, gregOutlineColor);
147         CategoryDepository.setOverride(gregID, "titleText", AShape.A_PAINT,
148                 gregOutlineColor);
149         CategoryDepository.setOverride(gregID, "mainText", AShape.A_PAINT,
150                 gregOutlineColor);
151         CategoryDepository.setOverride(gregID, "treeCheckBox", AShape.A_SHAPE,
152                 defaultShape);
153
154         calendars.setPropertyDeep(Category.PROP_IS_HIDDEN, Boolean.FALSE, null);
155
156         long startMillis = new GregorianCalendar JavaDoc(2005, 0, 0).getTimeInMillis();
157         long endMillis = new GregorianCalendar JavaDoc(2005, 12, 31).getTimeInMillis();
158         ImmutableDateRange dr = new ImmutableDateRange(startMillis, endMillis,
159                 false, null, null);
160
161         ArrayList JavaDoc acts = ActivityHelper.createActivities(dr, TITLES, null,
162                 CATEGORIES, null, 15 * 60000, 60 * 60000, 24 * 60 * 60000,
163                 15 * 60000, 4 * 60 * 60000, 10000);
164         ActivityDepository.getInstance().addBrokedActivities(acts,
165                 TestDataGenerator.class);
166
167         Activity act = createRecurringEvent(new GregorianCalendar JavaDoc(2004, 11, 7,
168                 11, 00), new GregorianCalendar JavaDoc(2004, 11, 7, 12, 00),
169                 "Mark's Lunch");
170
171         act.setCategoryIDs(new Object JavaDoc[] { susanID });
172         ActivityDepository.getInstance().addBrokedActivity(act,
173                 TestDataGenerator.class);
174     }
175
176     /**
177      * @return
178      */

179     public static Activity createRecurringEvent(Calendar JavaDoc startTime,
180             Calendar JavaDoc endTime, String JavaDoc description) {
181
182         long startMillis = startTime.getTimeInMillis();
183         long endMillis = endTime.getTimeInMillis();
184         ImmutableDateRange dr = new ImmutableDateRange(startMillis, endMillis,
185                 false, null, null);
186
187         // A recurring event
188
Activity act = new DefaultActivity(dr, new Integer JavaDoc(1111));
189         act.setSummary(description);
190
191         CompositeRecurrence comRec = new CompositeRecurrence();
192         comRec.addIncludingRecurrence(new RecurrenceRule(Calendar.DAY_OF_YEAR,
193                 1));
194
195         RecurrenceRule exWeekEnd = new RecurrenceRule(Calendar.DAY_OF_YEAR, 1);
196         exWeekEnd.addByXXXRule(new ByXXXRuleData(Calendar.DAY_OF_WEEK,
197                 new int[] { Calendar.SATURDAY, Calendar.SUNDAY }));
198         comRec.addExcludingRecurrence(exWeekEnd);
199
200         act.setRecurrence(comRec);
201         return act;
202     }
203
204 }
205
Popular Tags