KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > calendar > DateAreaBeanFactory


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.calendar;
19
20 import java.awt.Color JavaDoc;
21 import java.awt.Font JavaDoc;
22 import java.awt.Graphics2D JavaDoc;
23 import java.awt.Rectangle JavaDoc;
24 import java.awt.RenderingHints JavaDoc;
25 import java.awt.geom.Rectangle2D JavaDoc;
26 import java.beans.PropertyChangeEvent JavaDoc;
27 import java.text.DateFormat JavaDoc;
28 import java.text.SimpleDateFormat JavaDoc;
29 import java.util.Calendar JavaDoc;
30
31 import javax.swing.BorderFactory JavaDoc;
32 import javax.swing.SwingConstants JavaDoc;
33 import javax.swing.UIManager JavaDoc;
34
35 import org.columba.calendar.parser.ParserHelper;
36
37 import com.miginfocom.ashape.AShapeUtil;
38 import com.miginfocom.ashape.DefaultAShapeProvider;
39 import com.miginfocom.ashape.interaction.OverrideFilter;
40 import com.miginfocom.ashape.shapes.AShape;
41 import com.miginfocom.ashape.shapes.RootAShape;
42 import com.miginfocom.ashape.shapes.TextAShape;
43 import com.miginfocom.beans.DateAreaBean;
44 import com.miginfocom.beans.DateHeaderBean;
45 import com.miginfocom.beans.GridDimensionLayoutBean;
46 import com.miginfocom.calendar.activity.Activity;
47 import com.miginfocom.calendar.activity.ActivityInteractor;
48 import com.miginfocom.calendar.activity.renderer.AShapeRenderer;
49 import com.miginfocom.calendar.activity.view.ActivityView;
50 import com.miginfocom.calendar.datearea.DateArea;
51 import com.miginfocom.calendar.datearea.DefaultDateArea;
52 import com.miginfocom.calendar.decorators.AbstractGridDecorator;
53 import com.miginfocom.calendar.decorators.DateSeparatorDecorator;
54 import com.miginfocom.calendar.grid.DateGrid;
55 import com.miginfocom.calendar.grid.DefaultGridLineProvider;
56 import com.miginfocom.calendar.grid.Grid;
57 import com.miginfocom.calendar.grid.GridLineRepetition;
58 import com.miginfocom.calendar.grid.GridLineSpecProvider;
59 import com.miginfocom.calendar.grid.GridLineSpecification;
60 import com.miginfocom.calendar.header.CellDecorationRow;
61 import com.miginfocom.calendar.header.DateGridHeader;
62 import com.miginfocom.calendar.layout.ActivityLayout;
63 import com.miginfocom.calendar.layout.TimeBoundsLayout;
64 import com.miginfocom.util.dates.BoundaryRounder;
65 import com.miginfocom.util.dates.DateFormatList;
66 import com.miginfocom.util.dates.DateRange;
67 import com.miginfocom.util.dates.DateRangeI;
68 import com.miginfocom.util.dates.DateRangeRounder;
69 import com.miginfocom.util.dates.MutableDateRange;
70 import com.miginfocom.util.gfx.GfxUtil;
71 import com.miginfocom.util.gfx.ShapeGradientPaint;
72 import com.miginfocom.util.gfx.geometry.AbsRect;
73 import com.miginfocom.util.gfx.geometry.SizeSpec;
74 import com.miginfocom.util.gfx.geometry.numbers.AtEnd;
75 import com.miginfocom.util.gfx.geometry.numbers.AtFixed;
76 import com.miginfocom.util.gfx.geometry.numbers.AtFraction;
77 import com.miginfocom.util.gfx.geometry.numbers.AtStart;
78 import com.miginfocom.util.repetition.DefaultRepetition;
79
80 public class DateAreaBeanFactory {
81
82     private static final Color JavaDoc labelColor = Color.DARK_GRAY;
83
84     // glocal grid line colors
85
private static final Color JavaDoc darkGrayColor = new Color JavaDoc(220, 220, 220);
86
87     private static final Color JavaDoc lightGrayColor = new Color JavaDoc(240, 240, 240);
88
89     private static final Color JavaDoc darkDarkGrayColor = new Color JavaDoc(180, 180, 180);
90
91     public static final RootAShape HORSHAPE = ActivityShapeFactory
92             .createDefaultShape(SwingConstants.HORIZONTAL);
93
94     public static final RootAShape VERSHAPE = ActivityShapeFactory
95             .createDefaultShape(SwingConstants.VERTICAL);
96
97     /**
98      *
99      */

100     public static DateAreaBean initDailyDateArea() {
101
102         GridDimensionLayoutBean verticalGridDimensionLayout = new GridDimensionLayoutBean();
103         DateHeaderBean westDateHeaderBean = new DateHeaderBean();
104         // activityAShapeBean = new ActivityAShapeBean();
105
DateHeaderBean northDateHeaderBean = new DateHeaderBean();
106         com.miginfocom.beans.DateAreaBean dateAreaBean = new DateAreaBean();
107
108         // general grid size - if we don't set this property there won't be
109
// vertical scrollbars
110
verticalGridDimensionLayout.setRowSizeNormal(new SizeSpec(new AtFixed(
111                 20.0f), null, null));
112
113         // background
114
westDateHeaderBean.setBackgroundPaint(new ShapeGradientPaint(new Color JavaDoc(
115                 240, 240, 240), new Color JavaDoc(255, 255, 255), 0.0f, 0.7f, 0.6f,
116                 false));
117
118         // west header
119
westDateHeaderBean
120                 .setHeaderRows(new CellDecorationRow[] {
121                         // first row showing the hour
122
new CellDecorationRow(DateRangeI.RANGE_TYPE_HOUR,
123                                 new DateFormatList("HH", null), new AtFixed(
124                                         20.0f), new AbsRect(new AtStart(0.0f),
125                                         new AtStart(0.0f), new AtEnd(0.0f),
126                                         new AtEnd(0.0f), null, null, null),
127                                 (java.awt.Paint JavaDoc[]) null,
128                                 new java.awt.Paint JavaDoc[] { labelColor },
129                                 new DefaultRepetition(0, 1, null, null),
130                                 new java.awt.Font JavaDoc[] { UIManager.getFont(
131                                         "Label.font")
132                                         .deriveFont(Font.PLAIN, 16) },
133                                 new java.lang.Integer JavaDoc[] { null }, new AtStart(
134                                         3.0f), new AtStart(10.0f)),
135                         // second row showing the minutes
136
new com.miginfocom.calendar.header.CellDecorationRow(
137                                 com.miginfocom.util.dates.DateRangeI.RANGE_TYPE_MINUTE,
138                                 new DateFormatList("mm", null), new AtFixed(
139                                         20.0f), new AbsRect(new AtStart(0.0f),
140                                         new AtStart(0.0f), new AtEnd(0.0f),
141                                         new AtEnd(0.0f), null, null, null),
142                                 (java.awt.Paint JavaDoc[]) null, null,
143                                 new DefaultRepetition(0, 2, null, null),
144                                 new java.awt.Font JavaDoc[] { UIManager
145                                         .getFont("Label.font") },
146                                 new java.lang.Integer JavaDoc[] { null }, new AtStart(
147                                         5.0f), new AtStart(5.0f)) });
148
149         westDateHeaderBean
150                 .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON);
151
152         // north header background
153
northDateHeaderBean
154                 .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint(
155                         new Color JavaDoc(240, 240, 240), new java.awt.Color JavaDoc(255, 255,
156                                 255), 90.0f, 0.7f, 0.6f, false));
157
158         // north header cell decorator
159
CellDecorationRow northCellDecorationRow = new CellDecorationRow(
160                 DateRangeI.RANGE_TYPE_DAY, new DateFormatList("EE' 'dd MMM",
161                         null), new AtFixed(19.0f), new AbsRect(
162                         new AtStart(0.0f), new AtStart(0.0f), new AtEnd(0.0f),
163                         new AtEnd(0.0f), null, null, null),
164                 (java.awt.Paint JavaDoc[]) null, new java.awt.Paint JavaDoc[] { labelColor },
165                 new DefaultRepetition(0, 1, null, null),
166                 new java.awt.Font JavaDoc[] { UIManager.getFont("Label.font") },
167                 new java.lang.Integer JavaDoc[] { null }, new AtFraction(0.5f),
168                 new AtFraction(0.5f));
169
170         northDateHeaderBean.setHeaderRows(new CellDecorationRow[] {
171         // first header showing Day info
172
northCellDecorationRow });
173
174         northDateHeaderBean
175                 .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON);
176
177         // date area grid line
178
dateAreaBean.getDateArea().setGridLineSpecProvider(
179                 new GridLineSpecProvider() {
180                     public GridLineSpecification createSpecification(
181                             DateArea dateArea) {
182                         return new GridLineSpecification(
183                         // horizontal grid lines
184
new DefaultGridLineProvider(
185                                         new GridLineRepetition[] {
186                                                 // dark gray line at 12 and 13
187
new GridLineRepetition(0, 2,
188                                                         new AtStart(24f),
189                                                         new AtStart(26f), 1,
190                                                         darkDarkGrayColor,
191                                                         new AtStart(6f),
192                                                         new AtEnd(-6f)),
193                                                 // dark gray line every hour
194
new GridLineRepetition(1, 2,
195                                                         new AtStart(0.0f),
196                                                         null, 1,
197                                                         lightGrayColor,
198                                                         new AtStart(6f),
199                                                         new AtEnd(-6f)),
200                                                 // light gray line every 30 min
201
new GridLineRepetition(1, 1,
202                                                         new AtStart(0.0f),
203                                                         null, 1, darkGrayColor,
204                                                         new AtStart(6f),
205                                                         new AtEnd(-6f))
206
207                                         }),
208                                 // vertical grid lines
209
new DefaultGridLineProvider(
210                                         new GridLineRepetition[] {
211                                         // light gray line every day
212
new GridLineRepetition(1, 1,
213                                                 new AtStart(1f),
214                                                 new AtEnd(-1f), 1,
215                                                 darkGrayColor) }));
216                     }
217                 });
218
219         dateAreaBean.setDateAreaOuterBorder(javax.swing.BorderFactory
220                 .createLineBorder(lightGrayColor));
221
222         dateAreaBean.setNorthDateHeader(northDateHeaderBean);
223         dateAreaBean.setPrimaryDimension(javax.swing.SwingConstants.VERTICAL);
224         dateAreaBean
225                 .setPrimaryDimensionCellType(com.miginfocom.util.dates.DateRangeI.RANGE_TYPE_MINUTE);
226         dateAreaBean.setPrimaryDimensionCellTypeCount(30);
227         dateAreaBean.setPrimaryDimensionLayout(verticalGridDimensionLayout);
228         // dateAreaBean
229
// .setVisibleDateRangeString("20060101T000000000-20060107T235959999");
230
dateAreaBean.setWestDateHeader(westDateHeaderBean);
231         dateAreaBean.setWrapBoundary(new Integer JavaDoc(
232                 com.miginfocom.util.dates.DateRangeI.RANGE_TYPE_DAY));
233         dateAreaBean.getDateArea().setActivitiesSupported(true);
234
235         ((DateGridHeader) northDateHeaderBean.getHeader())
236                 .setGridLineSpecification(new GridLineSpecification(
237                         new DefaultGridLineProvider(new GridLineRepetition[] {
238                         // vertical light gray column separator line
239
new GridLineRepetition(0, 1, new AtStart(0f),
240                                         null, 1, lightGrayColor,
241                                         new AtStart(3f), new AtEnd(-3f))
242
243                                 }), null
244
245                 ));
246         ((DateGridHeader) westDateHeaderBean.getHeader())
247                 .setGridLineSpecification(new GridLineSpecification(
248                         new DefaultGridLineProvider(new GridLineRepetition[] {
249                         // horizontal light gray column separator line
250
new GridLineRepetition(0, 2, new AtStart(0f),
251                                         null, 1, darkGrayColor,
252                                         new AtStart(6f), new AtEnd(-6f)) }),
253                         null
254
255                 ));
256
257         // select current day
258

259         // dateAreaBean.getDateArea().addDecorator(
260
// new CellLabelDecorator(dateAreaBean.getDateArea(), 20) {
261
// public void paintCell(java.awt.Graphics2D g2, int r, int c,
262
// java.awt.Rectangle b) {
263
// DateGrid dateGrid = (DateGrid) getGrid();
264
// DateRangeI dr = new DateRange(System
265
// .currentTimeMillis(),
266
// DateRangeI.RANGE_TYPE_DAY, 1, null, null);
267
// Rectangle[] rects = dateGrid.getBoundsForDateRange(dr,
268
// Grid.SIZE_MODE_INSIDE);
269
//
270
// g2.drawString("test", 0,0);
271
// //super.paintCell(g2, r, c, b);
272
// }
273
// });
274

275         // dateAreaBean.setActivityDepositoryContext();
276
// dateAreaBean.getDateArea().setActivitiesSupported(true);
277

278         //
279
// activity setup
280
//
281

282         // define activity layout
283
AtFixed forcedSize = new AtFixed(17);
284         TimeBoundsLayout layout = new TimeBoundsLayout(new AtFixed(2),
285                 new AtStart(2), new AtEnd(-2), 2);
286         dateAreaBean.setActivityLayouts(new ActivityLayout[] { layout });
287
288         DefaultAShapeProvider defaultShapeFactory = ((AShapeRenderer) dateAreaBean
289                 .getDateArea().getActivityViewRenderer()).getShapeProvider();
290
291         defaultShapeFactory.setShape(VERSHAPE, null);
292
293         return dateAreaBean;
294
295     }
296
297     public static DateAreaBean initMonthlyDateArea() {
298
299         GridDimensionLayoutBean monthlyVerticalGridDimensionLayout = new GridDimensionLayoutBean();
300         GridDimensionLayoutBean monthlyHorizontalGridDimensionLayout = new GridDimensionLayoutBean();
301         // monthlyActivityAShapeBean = new ActivityAShapeBean();
302
DateHeaderBean monthlyNorthDateHeaderBean = new DateHeaderBean();
303
304         DateAreaBean monthlyDateAreaBean = new DateAreaBean();
305
306         DateHeaderBean monthlyWestDateHeaderBean = new DateHeaderBean();
307         monthlyWestDateHeaderBean
308                 .setLabelRotation(TextAShape.TYPE_SINGE_LINE_ROT_CCW);
309
310         monthlyWestDateHeaderBean
311                 .setHeaderRows(new CellDecorationRow[] {
312                 // showing the week number
313
new CellDecorationRow(
314                         DateRangeI.RANGE_TYPE_WEEK,
315                         new DateFormatList("'W 'w", null),
316                         new AtFixed(17f),
317                         new AbsRect(new AtStart(0.0f), new AtStart(0.0f),
318                                 new AtEnd(0.0f), new AtEnd(0.0f), null, null,
319                                 null),
320                         (java.awt.Paint JavaDoc[]) null,
321                         new java.awt.Paint JavaDoc[] { labelColor },
322                         new DefaultRepetition(0, 1, null, null),
323                         new java.awt.Font JavaDoc[] { UIManager.getFont("Label.font") },
324                         new java.lang.Integer JavaDoc[] { null }, new AtFraction(0.5f),
325                         new AtStart(4f)) });
326
327         monthlyWestDateHeaderBean
328                 .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint(
329                         new java.awt.Color JavaDoc(240, 240, 240), new java.awt.Color JavaDoc(
330                                 255, 255, 255), 0.0f, 0.7f, 0.6f, false));
331
332         monthlyWestDateHeaderBean
333                 .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON);
334
335         monthlyNorthDateHeaderBean
336                 .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint(
337                         new java.awt.Color JavaDoc(240, 240, 240), new java.awt.Color JavaDoc(
338                                 255, 255, 255), 90.0f, 0.7f, 0.6f, false));
339
340         monthlyNorthDateHeaderBean
341                 .setHeaderRows(new CellDecorationRow[] { new com.miginfocom.calendar.header.CellDecorationRow(
342                         DateRangeI.RANGE_TYPE_DAY, new DateFormatList(
343                                 "EEEE|EEE|1E|", null), new AtFixed(20.0f),
344                         new AbsRect(new AtStart(0.0f), new AtStart(0.0f),
345                                 new AtEnd(0.0f), new AtEnd(0.0f), null, null,
346                                 null), (java.awt.Paint JavaDoc[]) null,
347                         new java.awt.Paint JavaDoc[] { labelColor }, null,
348                         new Font JavaDoc[] { UIManager.getFont("Label.font") },
349                         new Integer JavaDoc[] { null }, new AtFraction(0.5f),
350                         new AtFraction(0.5f)) });
351
352         monthlyNorthDateHeaderBean.setTextAntiAlias(GfxUtil.AA_HINT_ON);
353
354         monthlyDateAreaBean.setDateAreaOuterBorder(BorderFactory
355                 .createLineBorder(lightGrayColor));
356
357         monthlyDateAreaBean.setNorthDateHeader(monthlyNorthDateHeaderBean);
358         monthlyDateAreaBean.setWestDateHeader(monthlyWestDateHeaderBean);
359         monthlyDateAreaBean
360                 .setPrimaryDimensionLayout(monthlyVerticalGridDimensionLayout);
361         monthlyDateAreaBean
362                 .setSecondaryDimensionLayout(monthlyHorizontalGridDimensionLayout);
363
364         ((DateGridHeader) monthlyWestDateHeaderBean.getHeader())
365                 .setGridLineSpecification(new GridLineSpecification(
366                         new DefaultGridLineProvider(new GridLineRepetition[] {
367                         // horizontal light gray column separator line
368
new GridLineRepetition(0, 1, new AtStart(0f),
369                                         null, 1, lightGrayColor,
370                                         new AtStart(3f), new AtEnd(-3f))
371
372                                 }), null
373
374                 ));
375         ((DateGridHeader) monthlyNorthDateHeaderBean.getHeader())
376                 .setGridLineSpecification(new GridLineSpecification(
377                         new DefaultGridLineProvider(new GridLineRepetition[] {
378                         // vertical light gray column separator line
379
new GridLineRepetition(0, 1, new AtStart(0f),
380                                         null, 1, lightGrayColor,
381                                         new AtStart(3f), new AtEnd(-3f))
382
383                                 }), null
384
385                 ));
386         // date area grid line
387
monthlyDateAreaBean.getDateArea().setGridLineSpecProvider(
388                 new GridLineSpecProvider() {
389                     public GridLineSpecification createSpecification(
390                             DateArea dateArea) {
391                         return new GridLineSpecification(
392                                 // horizontal grid lines
393
new DefaultGridLineProvider(
394                                         new GridLineRepetition[] {
395                                         // dark gray line at 12 and 13
396
new GridLineRepetition(0, 1,
397                                                 new AtStart(0.1f), new AtEnd(
398                                                         -1f), 1, lightGrayColor) }),
399                                 // vertical grid lines
400
new DefaultGridLineProvider(
401                                         new GridLineRepetition[] {
402                                         // light gray line every day
403
new GridLineRepetition(0, 1, null,
404                                                 null, 1, lightGrayColor) }),// vertical
405
// grid
406
// lines
407
new DefaultGridLineProvider(
408                                         new GridLineRepetition[] {
409                                         // light gray line every day
410
new GridLineRepetition(0, 1,
411                                                 new AtStart(1f),
412                                                 new AtEnd(-2f), 1,
413                                                 lightGrayColor) }));
414                     }
415                 });
416
417         monthlyDateAreaBean.setPrimaryDimension(SwingConstants.HORIZONTAL);
418         monthlyDateAreaBean
419                 .setPrimaryDimensionCellType(DateRangeI.RANGE_TYPE_DAY);
420         monthlyDateAreaBean.setPrimaryDimensionCellTypeCount(1);
421         monthlyDateAreaBean.setWrapBoundary(DateRangeI.RANGE_TYPE_WEEK);
422
423         DefaultDateArea dateArea = monthlyDateAreaBean.getDateArea();
424         dateArea.setActivitiesSupported(true);
425
426         // select current day
427
monthlyDateAreaBean.getDateArea()
428                 .addDecorator(
429                         new AbstractGridDecorator(monthlyDateAreaBean
430                                 .getDateArea(), 20) {
431                             public void doPaint(Graphics2D JavaDoc g2, Rectangle JavaDoc bounds) {
432                                 DateGrid dateGrid = (DateGrid) getGrid();
433
434                                 DateRangeI dr = new DateRange(System
435                                         .currentTimeMillis(),
436                                         DateRangeI.RANGE_TYPE_DAY, 1, null,
437                                         null);
438                                 Rectangle JavaDoc[] rects = dateGrid
439                                         .getBoundsForDateRange(dr,
440                                                 Grid.SIZE_MODE_INSIDE);
441
442                                 g2.setColor(new Color JavaDoc(250, 250, 250));
443                                 for (int i = 0; i < rects.length; i++)
444                                     g2.fill(rects[i]);
445                             }
446
447                             public void gridChanged(PropertyChangeEvent JavaDoc e) {
448                             }
449
450                             public void dispose() {
451                             }
452                         });
453
454         final DateFormat JavaDoc defaultFormat = new SimpleDateFormat JavaDoc("MMMM dd");
455
456         monthlyDateAreaBean.getDateArea()
457                 .addDecorator(
458                         new AbstractGridDecorator(monthlyDateAreaBean
459                                 .getDateArea(), 20) {
460                             public void doPaint(Graphics2D JavaDoc g2, Rectangle JavaDoc bounds) {
461                                 DateGrid dateGrid = (DateGrid) getGrid();
462
463                                 RenderingHints JavaDoc qualityHints = new RenderingHints JavaDoc(
464                                         RenderingHints.KEY_ANTIALIASING,
465                                         RenderingHints.VALUE_ANTIALIAS_ON);
466                                 g2.setRenderingHints(qualityHints);
467
468                                 g2.setFont(UIManager.getFont("Label.font")
469                                         .deriveFont(Font.BOLD));
470
471                                 for (int i = 0; i < dateGrid.getRowCount(); i++) {
472                                     for (int j = 0; j < dateGrid
473                                             .getColumnCount(); j++) {
474                                         Rectangle JavaDoc r = dateGrid.getBoundsOfCell(
475                                                 i, j, Grid.SIZE_MODE_INSIDE,
476                                                 true);
477                                         DateRangeI range = dateGrid
478                                                 .getDateRangeForCell(i, j);
479                                         int day = range.getStart().get(
480                                                 Calendar.DAY_OF_MONTH);
481                                         int weekday = range.getStart().get(
482                                                 Calendar.DAY_OF_WEEK);
483                                         if (weekday == Calendar.SUNDAY)
484                                             g2
485                                                     .setColor(new Color JavaDoc(255,
486                                                             102, 102));
487                                         else
488                                             g2.setColor(darkDarkGrayColor);
489                                         String JavaDoc dayString = null;
490                                         if (day == 1) {
491                                             dayString = defaultFormat
492                                                     .format(range.getStart()
493                                                             .getTime());
494                                         } else
495                                             dayString = new Integer JavaDoc(day)
496                                                     .toString();
497
498                                         Rectangle2D JavaDoc rect = g2.getFontMetrics()
499                                                 .getStringBounds(dayString, g2);
500
501                                         int x2 = r.x + r.width - 1;
502                                         x2 -= Math.abs(rect.getWidth());
503                                         int y2 = r.y;
504                                         y2 += Math.abs(rect.getHeight());
505                                         g2.drawString(dayString, x2, y2);
506
507                                     }
508
509                                 }
510
511                             }
512
513                             public void gridChanged(PropertyChangeEvent JavaDoc e) {
514                             }
515
516                             public void dispose() {
517                             }
518                         });
519
520         dateArea.addDecorator(new DateSeparatorDecorator(dateArea, 700,
521                 DateRangeI.RANGE_TYPE_MONTH, darkDarkGrayColor));
522
523         //
524
// activity setup
525
//
526

527         dateArea.setActivitiesSupported(true);
528
529         // define activity layout
530
AtFixed forcedSize = new AtFixed(17);
531         TimeBoundsLayout layout = new TimeBoundsLayout(new AtFixed(2),
532                 new AtStart(17), new AtEnd(-2), 2, forcedSize, null, null,
533                 null, new BoundaryRounder(DateRangeI.RANGE_TYPE_DAY, true,
534                         true, false));
535         monthlyDateAreaBean.setActivityLayouts(new ActivityLayout[] { layout });
536
537         DefaultAShapeProvider defaultShapeFactory = ((AShapeRenderer) dateArea
538                 .getActivityViewRenderer()).getShapeProvider();
539
540         defaultShapeFactory.setShape(HORSHAPE, null);
541         // defaultShapeFactory.setShape(AShapeCreator.createTraslucentShapeHorizontal(),
542
// null);
543

544         // layout.setVisualDateRangeRounder(new BoundaryRounder(DateRangeI.RANGE_TYPE_DAY, true, false, false));
545
// DateRangeRounder for AllDay Events
546
layout.setVisualDateRangeRounder(new DateRangeRounder() {
547
548             public MutableDateRange round(MutableDateRange arg0) {
549                 
550                 MutableDateRange c = arg0.getDateRangeClone();
551                 
552                 // set the start to 00:00:00
553
c.setStartField(java.util.Calendar.MINUTE, 0);
554                 c.setStartField(java.util.Calendar.SECOND, 0);
555                 c.setStartField(java.util.Calendar.HOUR_OF_DAY, 0);
556                 
557                 // if the end is on 00:00:00, round it to 23:59:59.999
558
if ((arg0.getEnd().get(java.util.Calendar.HOUR_OF_DAY) == 0)
559                     && (arg0.getEnd().get(java.util.Calendar.MINUTE) == 0)
560                     && (arg0.getEnd().get(java.util.Calendar.SECOND) == 0)) {
561
562                     c.setEndMillis(arg0.getEndMillis()-1, false);
563
564                 } else {
565                     // else set it to 23:59:59.999
566
c.setEndField(java.util.Calendar.MINUTE, 59);
567                     c.setEndField(java.util.Calendar.SECOND, 59);
568                     c.setEndField(java.util.Calendar.HOUR_OF_DAY, 23);
569                 }
570                 
571                 return c;
572             }
573             
574         });
575
576         return monthlyDateAreaBean;
577     }
578
579 }
580
Popular Tags