1 package org.columba.calendar.ui.calendar; 19 20 import java.awt.Color ; 21 import java.awt.Font ; 22 import java.awt.Graphics2D ; 23 import java.awt.Rectangle ; 24 import java.awt.RenderingHints ; 25 import java.awt.geom.Rectangle2D ; 26 import java.beans.PropertyChangeEvent ; 27 import java.text.DateFormat ; 28 import java.text.SimpleDateFormat ; 29 import java.util.Calendar ; 30 31 import javax.swing.BorderFactory ; 32 import javax.swing.SwingConstants ; 33 import javax.swing.UIManager ; 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 labelColor = Color.DARK_GRAY; 83 84 private static final Color darkGrayColor = new Color (220, 220, 220); 86 87 private static final Color lightGrayColor = new Color (240, 240, 240); 88 89 private static final Color darkDarkGrayColor = new Color (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 100 public static DateAreaBean initDailyDateArea() { 101 102 GridDimensionLayoutBean verticalGridDimensionLayout = new GridDimensionLayoutBean(); 103 DateHeaderBean westDateHeaderBean = new DateHeaderBean(); 104 DateHeaderBean northDateHeaderBean = new DateHeaderBean(); 106 com.miginfocom.beans.DateAreaBean dateAreaBean = new DateAreaBean(); 107 108 verticalGridDimensionLayout.setRowSizeNormal(new SizeSpec(new AtFixed( 111 20.0f), null, null)); 112 113 westDateHeaderBean.setBackgroundPaint(new ShapeGradientPaint(new Color ( 115 240, 240, 240), new Color (255, 255, 255), 0.0f, 0.7f, 0.6f, 116 false)); 117 118 westDateHeaderBean 120 .setHeaderRows(new CellDecorationRow[] { 121 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 []) null, 128 new java.awt.Paint [] { labelColor }, 129 new DefaultRepetition(0, 1, null, null), 130 new java.awt.Font [] { UIManager.getFont( 131 "Label.font") 132 .deriveFont(Font.PLAIN, 16) }, 133 new java.lang.Integer [] { null }, new AtStart( 134 3.0f), new AtStart(10.0f)), 135 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 []) null, null, 143 new DefaultRepetition(0, 2, null, null), 144 new java.awt.Font [] { UIManager 145 .getFont("Label.font") }, 146 new java.lang.Integer [] { 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 northDateHeaderBean 154 .setBackgroundPaint(new com.miginfocom.util.gfx.ShapeGradientPaint( 155 new Color (240, 240, 240), new java.awt.Color (255, 255, 156 255), 90.0f, 0.7f, 0.6f, false)); 157 158 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 []) null, new java.awt.Paint [] { labelColor }, 165 new DefaultRepetition(0, 1, null, null), 166 new java.awt.Font [] { UIManager.getFont("Label.font") }, 167 new java.lang.Integer [] { null }, new AtFraction(0.5f), 168 new AtFraction(0.5f)); 169 170 northDateHeaderBean.setHeaderRows(new CellDecorationRow[] { 171 northCellDecorationRow }); 173 174 northDateHeaderBean 175 .setTextAntiAlias(com.miginfocom.util.gfx.GfxUtil.AA_HINT_ON); 176 177 dateAreaBean.getDateArea().setGridLineSpecProvider( 179 new GridLineSpecProvider() { 180 public GridLineSpecification createSpecification( 181 DateArea dateArea) { 182 return new GridLineSpecification( 183 new DefaultGridLineProvider( 185 new GridLineRepetition[] { 186 new GridLineRepetition(0, 2, 188 new AtStart(24f), 189 new AtStart(26f), 1, 190 darkDarkGrayColor, 191 new AtStart(6f), 192 new AtEnd(-6f)), 193 new GridLineRepetition(1, 2, 195 new AtStart(0.0f), 196 null, 1, 197 lightGrayColor, 198 new AtStart(6f), 199 new AtEnd(-6f)), 200 new GridLineRepetition(1, 1, 202 new AtStart(0.0f), 203 null, 1, darkGrayColor, 204 new AtStart(6f), 205 new AtEnd(-6f)) 206 207 }), 208 new DefaultGridLineProvider( 210 new GridLineRepetition[] { 211 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.setWestDateHeader(westDateHeaderBean); 231 dateAreaBean.setWrapBoundary(new Integer ( 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 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 new GridLineRepetition(0, 2, new AtStart(0f), 251 null, 1, darkGrayColor, 252 new AtStart(6f), new AtEnd(-6f)) }), 253 null 254 255 )); 256 257 259 275 278 282 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 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 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 []) null, 321 new java.awt.Paint [] { labelColor }, 322 new DefaultRepetition(0, 1, null, null), 323 new java.awt.Font [] { UIManager.getFont("Label.font") }, 324 new java.lang.Integer [] { 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 (240, 240, 240), new java.awt.Color ( 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 (240, 240, 240), new java.awt.Color ( 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 []) null, 347 new java.awt.Paint [] { labelColor }, null, 348 new Font [] { UIManager.getFont("Label.font") }, 349 new Integer [] { 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 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 new GridLineRepetition(0, 1, new AtStart(0f), 380 null, 1, lightGrayColor, 381 new AtStart(3f), new AtEnd(-3f)) 382 383 }), null 384 385 )); 386 monthlyDateAreaBean.getDateArea().setGridLineSpecProvider( 388 new GridLineSpecProvider() { 389 public GridLineSpecification createSpecification( 390 DateArea dateArea) { 391 return new GridLineSpecification( 392 new DefaultGridLineProvider( 394 new GridLineRepetition[] { 395 new GridLineRepetition(0, 1, 397 new AtStart(0.1f), new AtEnd( 398 -1f), 1, lightGrayColor) }), 399 new DefaultGridLineProvider( 401 new GridLineRepetition[] { 402 new GridLineRepetition(0, 1, null, 404 null, 1, lightGrayColor) }), new DefaultGridLineProvider( 408 new GridLineRepetition[] { 409 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 monthlyDateAreaBean.getDateArea() 428 .addDecorator( 429 new AbstractGridDecorator(monthlyDateAreaBean 430 .getDateArea(), 20) { 431 public void doPaint(Graphics2D g2, Rectangle 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 [] rects = dateGrid 439 .getBoundsForDateRange(dr, 440 Grid.SIZE_MODE_INSIDE); 441 442 g2.setColor(new Color (250, 250, 250)); 443 for (int i = 0; i < rects.length; i++) 444 g2.fill(rects[i]); 445 } 446 447 public void gridChanged(PropertyChangeEvent e) { 448 } 449 450 public void dispose() { 451 } 452 }); 453 454 final DateFormat defaultFormat = new SimpleDateFormat ("MMMM dd"); 455 456 monthlyDateAreaBean.getDateArea() 457 .addDecorator( 458 new AbstractGridDecorator(monthlyDateAreaBean 459 .getDateArea(), 20) { 460 public void doPaint(Graphics2D g2, Rectangle bounds) { 461 DateGrid dateGrid = (DateGrid) getGrid(); 462 463 RenderingHints qualityHints = new RenderingHints ( 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 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 (255, 486 102, 102)); 487 else 488 g2.setColor(darkDarkGrayColor); 489 String dayString = null; 490 if (day == 1) { 491 dayString = defaultFormat 492 .format(range.getStart() 493 .getTime()); 494 } else 495 dayString = new Integer (day) 496 .toString(); 497 498 Rectangle2D 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 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 527 dateArea.setActivitiesSupported(true); 528 529 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 544 layout.setVisualDateRangeRounder(new DateRangeRounder() { 547 548 public MutableDateRange round(MutableDateRange arg0) { 549 550 MutableDateRange c = arg0.getDateRangeClone(); 551 552 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 ((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 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 |