1 package org.columba.calendar.ui.frame; 19 20 import java.awt.Color ; 21 import java.awt.Shape ; 22 import java.util.ArrayList ; 23 import java.util.Calendar ; 24 import java.util.GregorianCalendar ; 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 [] CATEGORIES = { new Integer (10), new Integer (11), 44 new Integer (12), new Integer (13) }; 45 46 static final String [] 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 56 public static void generateTestData() { 57 Object calendarsID = new Integer (9); 58 Object remoteCalendarsID = new Integer (100); 59 Object markID = CATEGORIES[0]; 60 Object susanID = CATEGORIES[1]; 61 Object michaelID = CATEGORIES[2]; 62 Object 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 defaultShape = new RoundRectangle(0, 0, 12, 12, 6, 6); 77 Color markColor = new Color (255, 180, 180); 78 Color 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 susanColor = new Color (200, 200, 255); 98 Color 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 michaelColor = new Color (255, 235, 100); 117 Color 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 gregColor = new Color (180, 245, 180); 137 Color 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 (2005, 0, 0).getTimeInMillis(); 157 long endMillis = new GregorianCalendar (2005, 12, 31).getTimeInMillis(); 158 ImmutableDateRange dr = new ImmutableDateRange(startMillis, endMillis, 159 false, null, null); 160 161 ArrayList 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 (2004, 11, 7, 168 11, 00), new GregorianCalendar (2004, 11, 7, 12, 00), 169 "Mark's Lunch"); 170 171 act.setCategoryIDs(new Object [] { susanID }); 172 ActivityDepository.getInstance().addBrokedActivity(act, 173 TestDataGenerator.class); 174 } 175 176 179 public static Activity createRecurringEvent(Calendar startTime, 180 Calendar endTime, String 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 Activity act = new DefaultActivity(dr, new Integer (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 |