1 package org.columba.calendar.ui.calendar; 2 3 import com.miginfocom.ashape.AShapeUtil; 4 import com.miginfocom.ashape.PolygonShape; 5 import com.miginfocom.ashape.SizeRangeVisibility; 6 import com.miginfocom.ashape.animation.OverrideAnimator; 7 import com.miginfocom.ashape.animation.TimeLine; 8 import com.miginfocom.ashape.animation.animations.ColorAnimation; 9 import com.miginfocom.ashape.interaction.AnimatorCommand; 10 import com.miginfocom.ashape.interaction.MouseKeyInteractor; 11 import com.miginfocom.ashape.interaction.TimerInteractor; 12 import com.miginfocom.ashape.layout.CutEdgeAShapeLayout; 13 import com.miginfocom.ashape.layout.RowAShapeLayout; 14 import com.miginfocom.ashape.shapes.*; 15 import com.miginfocom.calendar.datearea.DefaultDateArea; 16 import com.miginfocom.util.FirstOrLastComparator; 17 import com.miginfocom.util.PropertyKey; 18 import com.miginfocom.util.gfx.GfxUtil; 19 import com.miginfocom.util.gfx.RoundRectangle; 20 import com.miginfocom.util.gfx.ShapeGradientPaint; 21 import com.miginfocom.util.gfx.SliceSpec; 22 import com.miginfocom.util.gfx.geometry.AbsRect; 23 import com.miginfocom.util.gfx.geometry.AtPoint; 24 import com.miginfocom.util.gfx.geometry.PlaceRect; 25 import com.miginfocom.util.gfx.geometry.filters.OperFilter; 26 import com.miginfocom.util.gfx.geometry.links.AShapeLinkNumber; 27 import com.miginfocom.util.gfx.geometry.links.PolyLinkNumber; 28 import com.miginfocom.util.gfx.geometry.numbers.*; 29 30 import javax.swing.*; 31 import java.awt.*; 32 import java.awt.event.MouseEvent ; 33 import java.awt.geom.Ellipse2D ; 34 import java.awt.geom.GeneralPath ; 35 import java.awt.image.BufferedImage ; 36 import java.util.HashMap ; 37 38 43 public class AShapeCreator { 44 45 49 54 public static RootAShape createClipTestShape() { 55 56 String text = "The lazy dog jumed over the aircraft carrier. asdfasdfasd fa sdfasdf asd fas dfa sdf"; 57 58 RowAShapeLayout vRowLayout = new RowAShapeLayout( 59 SwingConstants.VERTICAL, null); 60 61 ContainerAShape vRowContainer = new ContainerAShape("vBox", 62 AbsRect.FILL, vRowLayout); 63 64 ContainerAShape textContainer = new ContainerAShape("cs", AbsRect.FILL); 65 66 TextAShape textShape = new TextAShape("t1", text, AbsRect.FILL, 67 TextAShape.TYPE_WRAP_TEXT, new Font("tahoma", Font.PLAIN, 11), 68 Color.GRAY, new AtFraction(0.5f), new AtFraction(0.5f), 69 GfxUtil.AA_HINT_OFF); 70 71 textShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 72 73 textContainer.addSubShape(textShape); 74 75 vRowContainer.addSubShape(textContainer); 76 77 RootAShape root = new RootAShape(vRowContainer); 78 79 AShapeUtil.addEnterExitOverride(textShape, textShape, AShape.A_PAINT, 80 Color.WHITE, true, true); 81 82 return root; 83 } 84 85 89 public static RootAShape createLightShape() { 90 91 Color bgPaint = new Color(255, 200, 200); 92 93 95 97 99 101 Color outlinePaint = new Color(128, 0, 0); 102 103 Color moOutlinePaint = new Color(0, 0, 0); 104 105 Color textPaint = new Color(50, 50, 50); 106 107 109 Font titleFont = new Font("SansSerif", Font.BOLD, 11); 110 111 RootAShape root = new RootAShape(); 112 113 FillAShape bgAShape = new FillAShape("bg", new Rectangle(0, 0, 1, 1), 114 AbsRect.FILL_INSIDE, bgPaint, GfxUtil.AA_HINT_OFF); 115 116 PlaceRect contentAbsRect = new AbsRect(new AtStart(12), new AtStart(0), 117 new AtEnd(-1), new AtEnd(-1)); 118 119 ContainerAShape content = new ContainerAShape("dock", contentAbsRect, 120 new CutEdgeAShapeLayout()); 121 122 PlaceRect titleTextAbsRect = new AbsRect(new AtStart(0), 123 new AtStart(0), new AtEnd(0), new AtStart(12), null, null, null); 124 125 TextAShape timeTitleText = new TextAShape("titleText", "", 126 titleTextAbsRect, TextAShape.TYPE_SINGE_LINE, titleFont, 127 textPaint, new AtStart(0), new AtStart(-3), GfxUtil.AA_HINT_OFF); 128 129 DrawAShape outlineAShape = new DrawAShape("outline", new Rectangle(0, 130 0, 1, 1), AbsRect.FILL, outlinePaint, new BasicStroke(1f), 131 GfxUtil.AA_HINT_OFF); 132 133 outlineAShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 134 135 outlineAShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 136 .getPredefinedCursor(Cursor.MOVE_CURSOR)); 137 138 content.addSubShape(timeTitleText); 139 140 bgAShape.addSubShape(content); 141 142 root.addSubShape(bgAShape); 143 144 root.addSubShape(outlineAShape); 145 146 AShapeUtil.setResizeBoxes(root, SwingConstants.HORIZONTAL, 4); 147 148 AShapeUtil.addEnterExitOverride(outlineAShape, outlineAShape, 149 AShape.A_PAINT, moOutlinePaint, false, true); 150 151 153 PropertyKey trigger = MouseKeyInteractor.MOUSE_PRESS; 154 155 Integer button = new Integer (MouseEvent.BUTTON1); 156 157 AShapeUtil.addMouseFireEvent(outlineAShape, trigger, 158 DefaultDateArea.AE_SELECTED_PRESSED, false, false, button); 159 160 163 AShapeUtil.addMouseFireEvent(outlineAShape, trigger, 164 DefaultDateArea.AE_DRAG_PRESSED, false, true, button); 165 166 return root; 167 } 168 169 173 public static RootAShape createRelValueShape() { 174 175 RootAShape root = new RootAShape(); 176 177 PlaceRect pr = new AbsRect(new AtStart(0), new AtStart(0), 178 new AtEnd(0), new AtEnd(0)); 179 180 AShape fillShape = new FillAShape("fill", new Rectangle(0, 0, 1, 1), 181 pr, Color.BLACK, GfxUtil.AA_HINT_OFF); 182 183 root.addSubShape(fillShape); 184 185 return root; 186 } 187 188 194 public static RootAShape createTabbedShape() { 195 196 RootAShape root = new RootAShape(); 197 198 root.setRepaintPadding(new Insets(2, 2, 2, 2)); 199 200 root.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 201 202 root.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 203 .getPredefinedCursor(Cursor.MOVE_CURSOR)); 204 205 int tabHeight = 15; 206 207 int tabSlope = 15; 208 209 int tabGapWidth = 30; 211 213 AtNumber leftEdgeX = new AShapeLinkNumber(root, AtStart.START0, 214 PolyLinkNumber.X, true); 215 216 AtNumber rightEdgeX = new AShapeLinkNumber(root, AtEnd.END1, 217 PolyLinkNumber.X, true); 220 AtNumber topEdgeY = new AShapeLinkNumber(root, AtStart.START0, 221 PolyLinkNumber.Y, true); 222 223 AtNumber bottomEdgeY = new AShapeLinkNumber(root, AtEnd.END1, 224 PolyLinkNumber.Y, true); 227 AtNumber topMiddletX = new AShapeLinkNumber(root, new AtFraction(0.5f), 228 PolyLinkNumber.X, true); 229 230 AtNumber tabDiveStartX = new OperFilter(topMiddletX, OperFilter.SUB, 231 new AtFixed(tabGapWidth >> 1)); 232 233 AtNumber tabDiveEndX = new OperFilter(topMiddletX, OperFilter.ADD, 234 new AtFixed(tabGapWidth >> 1)); 235 236 AtNumber tabLowerY = new OperFilter(topEdgeY, OperFilter.ADD, 237 new AtFixed(tabHeight)); 238 239 241 PolygonShape leftTabShape = new PolygonShape(); 242 243 leftTabShape.addPoint(new AtPoint(leftEdgeX, topEdgeY)); 244 245 leftTabShape.addPoint(new AtPoint(tabDiveStartX, topEdgeY, 0, 0, 246 tabSlope, 0)); 247 248 leftTabShape.addPoint(new AtPoint(tabDiveEndX, tabLowerY, -0, 0, 0, 0)); 249 250 leftTabShape.addPoint(new AtPoint(rightEdgeX, tabLowerY)); 251 252 leftTabShape.addPoint(new AtPoint(rightEdgeX, bottomEdgeY)); 253 254 leftTabShape.addPoint(new AtPoint(leftEdgeX, bottomEdgeY)); 255 256 Color outlineColor = new Color(100, 100, 100); 257 258 Color tabBg = new Color(245, 245, 245); 259 260 Font tabTextFont = new Font("SansSerif", Font.BOLD, 12); 261 262 Font textFont = new Font("SansSerif", Font.PLAIN, 11); 263 264 AbsRect leftTabTextRect = new AbsRect(new AtStart(4), AtStart.START0, 265 new AtFraction(.4f), new AtStart(15)); 266 267 AbsRect textRect = new AbsRect(new AtStart(4), new AtStart(20), 268 new AtEnd(-5), AtEnd.END1); 269 270 SizeRangeVisibility hideIfSmallVis = new SizeRangeVisibility(true); 271 272 hideIfSmallVis.addHorizontalVisibilityRange(-1000, 35); 273 274 hideIfSmallVis.addVerticalVisibilityRange(-1000, 35); 275 276 AbsRect rightTabTextRect = new AbsRect(new AtFraction(.6f), 277 AtStart.START0, AtEnd.END1, new AtStart(15)); 278 279 AShape leftTab = new FillAShape("leftTab", leftTabShape, AbsRect.FILL, 280 tabBg, GfxUtil.AA_HINT_ON); 281 282 leftTab.setAttribute(AShape.A_VISIBILITY, hideIfSmallVis); 283 284 leftTab.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 285 286 AShape leftTabOutline = new DrawAShape("leftTabOutline", leftTabShape, 287 AbsRect.FILL, outlineColor, new BasicStroke(1f), 288 GfxUtil.AA_HINT_ON); 289 290 AShape leftTabText = new TextAShape("leftTabText", "Info", 291 leftTabTextRect, TextAShape.TYPE_SINGE_LINE, tabTextFont, 292 Color.DARK_GRAY, AtStart.START1, AtStart.START0, 293 GfxUtil.AA_HINT_OFF); 294 295 AShape leftText = new TextAShape("leftText", "$summary$", textRect, 296 TextAShape.TYPE_WRAP_TEXT, textFont, Color.DARK_GRAY, 297 AtStart.START0, AtStart.START0, GfxUtil.AA_HINT_OFF); 298 299 leftTabText.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 300 301 leftTabText.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 302 .getPredefinedCursor(Cursor.HAND_CURSOR)); 303 304 306 PolygonShape rightTabShape = new PolygonShape(); 307 308 rightTabShape.addPoint(new AtPoint(leftEdgeX, tabLowerY)); 309 310 rightTabShape 311 .addPoint(new AtPoint(tabDiveStartX, tabLowerY, 0, 0, 0, 0)); 312 313 rightTabShape.addPoint(new AtPoint(tabDiveEndX, topEdgeY, -tabSlope, 0, 314 0, 0)); 315 316 rightTabShape.addPoint(new AtPoint(rightEdgeX, topEdgeY)); 317 318 rightTabShape.addPoint(new AtPoint(rightEdgeX, bottomEdgeY)); 319 320 rightTabShape.addPoint(new AtPoint(leftEdgeX, bottomEdgeY)); 321 322 AShape rightTab = new FillAShape("rightTab", rightTabShape, 323 AbsRect.FILL, tabBg, GfxUtil.AA_HINT_ON); 324 325 rightTab.setAttribute(AShape.A_VISIBILITY, hideIfSmallVis); 326 327 rightTab.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 328 329 AShape rightTabOutline = new DrawAShape("rightTabOutline", 330 rightTabShape, AbsRect.FILL, outlineColor, new BasicStroke(1f), 331 GfxUtil.AA_HINT_ON); 332 333 AShape rightTabText = new TextAShape("rightTabText", "Times", 334 rightTabTextRect, TextAShape.TYPE_SINGE_LINE, tabTextFont, 335 Color.DARK_GRAY, AtEnd.END1, AtStart.START0, 336 GfxUtil.AA_HINT_OFF); 337 338 AShape rightText = new TextAShape("rightText", 339 "Start:\n $startTime$\nEnd:\n $endTimeExcl$", textRect, 340 TextAShape.TYPE_WRAP_TEXT, textFont, Color.DARK_GRAY, 341 AtStart.START0, AtStart.START0, GfxUtil.AA_HINT_OFF); 342 343 rightTabText.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 344 345 rightTabText.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 346 .getPredefinedCursor(Cursor.HAND_CURSOR)); 347 348 350 AShape smallFill = new FillAShape("smallFill", 351 new Rectangle(0, 0, 1, 1), AbsRect.FILL, tabBg, 352 GfxUtil.AA_HINT_OFF); 353 354 smallFill.setAttribute(AShape.A_VISIBILITY, hideIfSmallVis 355 .getInverted()); 356 357 smallFill.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 358 359 AShape smallOutline = new DrawAShape("smallOutline", new Rectangle(0, 360 0, 1, 1), AbsRect.FILL, outlineColor, new BasicStroke(1f), 361 GfxUtil.AA_HINT_ON); 362 363 AShape smallText = new TextAShape("smallText", "$startTime$ $summary$", 364 AbsRect.FILL_INSIDE, TextAShape.TYPE_SINGE_LINE, textFont, 365 Color.DARK_GRAY, AtStart.START1, AtStart.START0, 366 GfxUtil.AA_HINT_OFF); 367 368 ContainerAShape tabsContainer = new ContainerAShape("tabsContainer", 369 AbsRect.FILL); 370 371 rightTab.addSubShape(rightText); 372 373 rightTab.addSubShape(rightTabText); 374 375 rightTab.addSubShape(rightTabOutline); 376 377 leftTab.addSubShape(leftText); 378 379 leftTab.addSubShape(leftTabText); 380 381 leftTab.addSubShape(leftTabOutline); 382 383 tabsContainer.addSubShape(rightTab); 384 385 tabsContainer.addSubShape(leftTab); 386 387 smallFill.addSubShape(smallOutline); 388 389 smallFill.addSubShape(smallText); 390 391 root.addSubShape(tabsContainer); 392 393 root.addSubShape(smallFill); 394 395 AShapeUtil.setResizeBoxes(root, SwingConstants.VERTICAL, 4); 396 397 AShapeUtil.enableMouseOverCursor(root); 398 399 AShapeUtil.enableMouseOverState(root); 400 401 PropertyKey mpTrigger = MouseKeyInteractor.MOUSE_PRESS; 402 403 AShapeUtil.addEnterExitOverride(leftTab, leftTabOutline, 404 AShape.A_PAINT, Color.BLACK, true, true); 405 406 AShapeUtil.addEnterExitOverride(rightTab, rightTabOutline, 407 AShape.A_PAINT, Color.BLACK, true, true); 408 409 AShapeUtil.addEnterExitOverride(smallFill, smallOutline, 410 AShape.A_PAINT, Color.BLACK, true, true); 411 412 AShapeUtil.addEnterExitOverride(leftTabText, leftTabText, 413 AShape.A_UNDERLINE_HEIGHT, new Integer (1), true, true); 414 415 AShapeUtil.addEnterExitOverride(rightTabText, rightTabText, 416 AShape.A_UNDERLINE_HEIGHT, new Integer (1), true, true); 417 418 420 Integer button = new Integer (MouseEvent.BUTTON1); 421 422 AShapeUtil.addMouseFireEvent(root, mpTrigger, 423 DefaultDateArea.AE_SELECTED_PRESSED, false, false, button); 424 425 AShapeUtil.addMouseRemoveOverride(leftTabText, tabsContainer, 426 mpTrigger, true, AShape.A_SUB_SHAPE_SORTER, null, true, false); 427 428 AShapeUtil.addMouseOverride(rightTabText, tabsContainer, mpTrigger, 429 AShape.A_SUB_SHAPE_SORTER, new FirstOrLastComparator(rightTab, 430 false), true, false, false); 431 432 AShapeUtil.addMouseFireEvent(root, mpTrigger, 433 DefaultDateArea.AE_DRAG_PRESSED, false, true, button); 434 435 AShapeUtil.addMouseEventBlock(root, false, new Integer ( 436 MouseEvent.MOUSE_MOVED)); 437 438 440 return root; 441 } 442 443 451 public static RootAShape createGanttFolderShape(Paint bgPaint, Font font, 452 Color fgColor, Insets shadowInsets) { 453 454 RootAShape root = new RootAShape(); 455 456 root.setRepaintPadding(new Insets(2, 2, 4, 4)); 457 458 GeneralPath startPoly = new GeneralPath (); 459 460 startPoly.moveTo(0, 0); 461 462 startPoly.lineTo(10, 0); 463 464 startPoly.lineTo(0, 10); 465 466 startPoly.closePath(); 467 468 AbsRect startRect = new AbsRect(AtStart.START0, AtStart.START0, 469 new AtStart(10), new AtStart(10)); 470 471 FillAShape startShape = new FillAShape("start", startPoly, startRect, 472 Color.BLUE, GfxUtil.AA_HINT_ON); 473 474 476 479 483 486 489 FillAShape bgShape = new FillAShape("bgFill", 490 new Rectangle(0, 0, 1, 1), AbsRect.FILL, bgPaint, 491 GfxUtil.AA_HINT_OFF); 492 493 496 500 bgShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 501 502 bgShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 503 .getPredefinedCursor(Cursor.HAND_CURSOR)); 504 505 507 root.addSubShape(bgShape); 508 509 511 root.addSubShape(startShape); 512 513 515 return root; 516 } 517 518 526 public static RootAShape createGanttRect(Paint bgPaint, Font font, 527 Color fgColor, Insets shadowInsets) { 528 529 RootAShape root = new RootAShape(); 530 531 root.setRepaintPadding(new Insets(2, 2, 4, 4)); 532 533 535 538 542 545 548 FillAShape bgShape = new FillAShape("bgFill", 549 new Rectangle(0, 0, 1, 1), AbsRect.FILL, bgPaint, 550 GfxUtil.AA_HINT_OFF); 551 552 556 AbsRect textRect = new AbsRect(new AtStart(3), AtStart.START0, 557 new AtEnd(-3), AtEnd.END0); 558 559 AShape textShape = new TextAShape("text", "$duration$", textRect, 560 TextAShape.TYPE_SINGE_LINE, font, fgColor, AtFraction.CENTER, 561 AtStart.START0, GfxUtil.AA_HINT_OFF); 562 563 bgShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 564 565 bgShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 566 .getPredefinedCursor(Cursor.HAND_CURSOR)); 567 568 570 root.addSubShape(bgShape); 571 572 574 root.addSubShape(textShape); 575 576 AShapeUtil.enableMouseOverCursor(root); 577 578 AShapeUtil.setResizeBoxes(bgShape, SwingConstants.HORIZONTAL, 4); 579 580 AShapeUtil.addMouseEventBlock(bgShape, false, new Integer ( 581 MouseEvent.MOUSE_MOVED)); 582 583 return root; 584 } 585 586 592 public static RootAShape createDefaultPicShape() { 593 594 RootAShape root = new RootAShape(); 595 596 BufferedImage image = GfxUtil.getImageFromString("C:/testShape.png", 597 null, null); 598 599 SliceSpec sliceSpec = new SliceSpec(new Insets(15, 15, 15, 15), 600 SliceSpec.TYPE_TILE_CUT, SliceSpec.OPT_BORDER); 601 602 SlicedImageAShape slicedImageShape = new SlicedImageAShape("slice", 603 image, sliceSpec, AbsRect.FILL); 604 605 PlaceRect middleAbsRect = new AbsRect(new AtStart(5), new AtStart(5), 606 new AtEnd(-5), new AtEnd(-5)); 607 608 ShapeGradientPaint middBG = new ShapeGradientPaint(new Color(250, 250, 609 250), new Color(230, 230, 230), 270, 1f, 0.5f, false); 610 611 FillAShape middleBG = new FillAShape("middleBG", new Rectangle(0, 0, 1, 612 1), middleAbsRect, middBG, GfxUtil.AA_HINT_OFF); 613 614 slicedImageShape.addSubShape(middleBG); 615 616 618 AShapeUtil.setResizeBoxes(root, SwingConstants.VERTICAL, 4); 619 620 root.addSubShape(slicedImageShape); 621 622 return root; 623 } 624 625 629 public static RootAShape createDockLayoutShape() { 630 631 RootAShape root = new RootAShape(); 632 633 ContainerAShape dockAShape = new ContainerAShape("dock", AbsRect.FILL, 634 new CutEdgeAShapeLayout()); 635 636 639 642 645 648 FillAShape fillShape1A = new FillAShape("dockFill1", new Rectangle(0, 649 0, 1, 1), new AbsRect(SwingConstants.BOTTOM, new Integer (20), 650 null), Color.BLUE, GfxUtil.AA_HINT_OFF); 651 652 FillAShape fillShape2A = new FillAShape("dockFill2", new Rectangle(0, 653 0, 1, 1), new AbsRect(SwingConstants.RIGHT, new Integer (20), 654 null), Color.GREEN, GfxUtil.AA_HINT_OFF); 655 656 FillAShape fillShape3A = new FillAShape("dockFill3", new Rectangle(0, 657 0, 1, 1), 658 new AbsRect(SwingConstants.TOP, new Integer (20), null), 659 Color.YELLOW, GfxUtil.AA_HINT_OFF); 660 661 FillAShape fillShape4A = new FillAShape("dockFill4", new Rectangle(0, 662 0, 1, 1), 663 new AbsRect(SwingConstants.LEFT, new Float (1f), null), 664 Color.GRAY, GfxUtil.AA_HINT_OFF); 665 666 dockAShape.addSubShape(fillShape1A); 667 668 dockAShape.addSubShape(new DividerAShape(new AbsRect( 669 SwingConstants.BOTTOM, new Integer (1)), Color.RED)); 670 671 dockAShape.addSubShape(fillShape2A); 672 673 dockAShape.addSubShape(new DividerAShape(new AbsRect( 674 SwingConstants.RIGHT, new Integer (1)), Color.RED)); 675 676 dockAShape.addSubShape(fillShape3A); 677 678 dockAShape.addSubShape(new DividerAShape(new AbsRect( 679 SwingConstants.TOP, new Integer (1)), Color.RED)); 680 681 dockAShape.addSubShape(fillShape4A); 682 683 root.addSubShape(dockAShape); 684 685 root.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 686 687 root.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 688 .getPredefinedCursor(Cursor.MOVE_CURSOR)); 689 690 AShapeUtil.setResizeBoxes(root, SwingConstants.VERTICAL, 4); 691 692 return root; 693 } 694 695 702 public static RootAShape createBoxLayoutShape(Container parent) { 703 704 DrawAShape borderAShape = new DrawAShape("border", new Rectangle(0, 0, 705 1, 1), AbsRect.FILL, new Color(150, 150, 225), new BasicStroke( 706 1f), GfxUtil.AA_HINT_OFF); 707 708 AtRefNumber[] hSizes = new AtRefNumber[] { new AtFixed(12), 709 new AtFraction(1), new AtFixed(12) }; 710 711 RowAShapeLayout hRowLayout = new RowAShapeLayout( 712 SwingConstants.HORIZONTAL, hSizes); 713 714 ContainerAShape hBoxAShape = new ContainerAShape("hBox", 715 AbsRect.FILL_INSIDE, hRowLayout); 716 717 AtRefNumber[] vSizes = null; 718 719 ShapeGradientPaint vGapPaint = new ShapeGradientPaint(new Color(150, 720 150, 225), new Color(200, 200, 225), 0, 1f, 0.5f, false); 721 722 RowAShapeLayout vRowLayout = new RowAShapeLayout( 723 SwingConstants.VERTICAL, vSizes); 724 725 ContainerAShape vBoxAShape = new ContainerAShape("vBox", AbsRect.FILL, 726 vRowLayout); 727 728 vBoxAShape.addSubShape(createHorTextShape("t1", 729 "A demo text that is a little tad bit longer", new AtStart(2), 730 new AtStart(1))); 731 732 vBoxAShape.addSubShape(new DividerAShape(SwingConstants.HORIZONTAL, 733 new Integer (1), vGapPaint)); 734 735 vBoxAShape.addSubShape(createHorTextShape("t2", "Short demo text", 736 new AtEnd(0), new AtFraction(0.5f))); 737 738 vBoxAShape.addSubShape(new DividerAShape(SwingConstants.HORIZONTAL, 739 new Integer (1), vGapPaint)); 740 741 vBoxAShape.addSubShape(createHorTextShape("t3", "Shorter", new AtStart( 742 2), new AtFraction(0.5f))); 743 744 vBoxAShape.addSubShape(new DividerAShape(SwingConstants.HORIZONTAL, 745 new Integer (1), vGapPaint)); 746 747 vBoxAShape 748 .addSubShape(createHorTextShape( 749 "t4", 750 "This text just goes on and on and on.\n\nIt simply doesn't stop", 751 new AtEnd(-1), new AtEnd(-1))); 752 753 if (parent != null) { 754 755 vBoxAShape.addSubShape(createJComponentShape("Button 1", parent)); 756 757 vBoxAShape.addSubShape(createJComponentShape("Button 2", parent)); 758 759 vBoxAShape.addSubShape(createJComponentShape("Button 3", parent)); 760 761 vBoxAShape.addSubShape(createJComponentShape("Button 4", parent)); 762 763 } 764 765 hBoxAShape.addSubShape(createVerTextShape("v1", "MiG InfoCom AB", 766 TextAShape.TYPE_SINGE_LINE_ROT_CCW)); 767 768 hBoxAShape.addSubShape(vBoxAShape); 769 770 hBoxAShape.addSubShape(createVerTextShape("v2", "MiG InfoCom AB", 771 TextAShape.TYPE_SINGE_LINE_ROT_CW)); 772 773 borderAShape.addSubShape(hBoxAShape); 774 775 borderAShape.setAttributeDeep(AShape.A_CLIP_TYPE, 776 AShape.CLIP_PARENT_BOUNDS, 8); 777 778 RootAShape root = new RootAShape(borderAShape); 779 780 borderAShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 781 782 borderAShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 783 .getPredefinedCursor(Cursor.MOVE_CURSOR)); 784 785 AShapeUtil.enableMouseOverCursor(root); 786 787 AShapeUtil.enableMouseOverState(borderAShape); 788 789 AShapeUtil.setResizeBoxes(root, SwingConstants.VERTICAL, 4); 790 791 PropertyKey trigger = MouseKeyInteractor.MOUSE_PRESS; 792 793 Integer button = new Integer (MouseEvent.BUTTON1); 794 795 AShapeUtil.addMouseFireEvent(borderAShape, trigger, 796 DefaultDateArea.AE_DRAG_PRESSED, false, true, button); 797 798 ColorAnimation colAnim = new ColorAnimation(Color.GRAY, Color.BLACK); 799 800 802 for (int i = 1; i < 5; i++) { 803 804 String shapeName = "t" + i; 805 806 OverrideAnimator animator = new OverrideAnimator(colAnim, 807 new TimeLine(500, 10), AShape.A_PAINT, shapeName); 808 809 AnimatorCommand forwardCmd = new AnimatorCommand(animator, 810 OverrideAnimator.CMD_FORWARD); 811 812 AnimatorCommand backwardCmd = new AnimatorCommand(animator, 813 OverrideAnimator.CMD_BACKWARD); 814 815 AShapeUtil.addEnterExitCommands(root.getSubShapeDeep(shapeName), 816 forwardCmd, backwardCmd, true); 817 818 } 819 820 AShapeUtil.addMouseEventBlock(borderAShape, false, new Integer ( 821 MouseEvent.MOUSE_MOVED)); 822 823 return root; 824 } 825 826 834 public static AShape createHorTextShape(String name, String text, 835 AtRefRangeNumber xAlign, AtRefRangeNumber yAlign) { 836 837 ContainerAShape container = new ContainerAShape(); 838 839 ShapeGradientPaint bgPaint = new ShapeGradientPaint(new Color(200, 200, 840 255), new Color(230, 230, 255), 90, 1f, 0.5f, false); 841 842 FillAShape mainAShape = new FillAShape("box" + name, new Rectangle(0, 843 0, 1, 1), AbsRect.FILL, bgPaint, GfxUtil.AA_HINT_OFF); 844 845 Font font = new Font("tahoma", Font.PLAIN, 11); 846 847 TextAShape textAShape = new TextAShape(name, text, AbsRect.FILL, 848 TextAShape.TYPE_WRAP_TEXT, font, Color.GRAY, xAlign, yAlign, 849 GfxUtil.AA_HINT_OFF); 850 851 textAShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 852 .getPredefinedCursor(Cursor.HAND_CURSOR)); 853 854 mainAShape.addSubShape(textAShape); 855 856 container.addSubShape(mainAShape); 857 858 textAShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 859 860 return container; 861 } 862 863 870 public static AShape createVerTextShape(String name, String text, int rot) { 871 872 ContainerAShape container = new ContainerAShape(); 873 874 ShapeGradientPaint bgPaint = new ShapeGradientPaint(new Color(180, 180, 875 180), new Color(230, 230, 230), 90, 1f, 0.5f, false); 876 877 FillAShape mainAShape = new FillAShape("box" + name, new Rectangle(0, 878 0, 1, 1), AbsRect.FILL, bgPaint, GfxUtil.AA_HINT_OFF); 879 880 Font font = new Font("sansserif", Font.PLAIN, 11); 881 882 TextAShape textAShape = new TextAShape(name, text, AbsRect.FILL, rot, 883 font, new Color(255, 255, 255), new AtFraction(0f), 884 new AtFraction(0.5f), GfxUtil.AA_HINT_ON); 885 886 mainAShape.addSubShape(textAShape); 887 888 container.addSubShape(mainAShape); 889 890 892 return container; 893 } 894 895 901 public static AShape createJComponentShape(String name, Container parent) 902 903 { 904 905 ContainerAShape container = new ContainerAShape(); 906 907 JButton butt = new JButton(name); 908 909 parent.add(butt); 910 911 JComponentAShape componentAShape = new JComponentAShape(name, butt, 912 AbsRect.FILL); 913 914 componentAShape.setAttribute(AShape.A_PREFERRED_HEIGHT, new Integer ( 915 butt.getPreferredSize().height)); 916 917 container.addSubShape(componentAShape); 918 919 container.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 920 921 return container; 922 } 923 924 930 public static RootAShape createDarkGrayShape() 931 { 932 935 Paint bgPaint = new Color(245, 245, 245); 936 937 940 Paint titlePaint = new Color(120, 120, 120); 941 942 ContainerAShape containerAShape = new ContainerAShape("dcontainer", 943 AbsRect.FILL); 944 945 containerAShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 946 .getPredefinedCursor(Cursor.MOVE_CURSOR)); 947 948 containerAShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 949 950 ContainerAShape content = new ContainerAShape("ddock", AbsRect.FILL, 951 new CutEdgeAShapeLayout()); 952 953 955 PlaceRect bgAbsRect = new AbsRect(new AtStart(0), new AtStart(0), 956 new AtEnd(0), new AtEnd(0), null, null, new Insets(0, 0, 2, 2)); 957 958 FillAShape filledShadow = new FillAShape("dshadowShape", 959 new RoundRectangle(0, 0, 1, 1, 5, 5), bgAbsRect, new Color(0, 960 0, 0, 70), GfxUtil.AA_HINT_ON); 961 962 SliceSpec shwSI = new SliceSpec(new Insets(10, 10, 10, 10), 963 SliceSpec.TYPE_TILE_CUT, SliceSpec.OPT_BOTTOM_RIGHT); 964 965 FeatherAShape shadow = new FeatherAShape("dshadow", filledShadow, 966 new Color(255, 255, 255, 0), 5, shwSI); 967 968 970 PlaceRect titleDockRect = new AbsRect(SwingConstants.TOP, new Integer ( 971 11)); 972 973 FillAShape northTitle = new FillAShape("dtitle", new Rectangle(0, 0, 1, 974 1), titleDockRect, titlePaint, GfxUtil.AA_HINT_OFF); 975 976 PlaceRect nttAbsRect = new AbsRect(new AtStart(3), new AtStart(0), 977 new AtEnd(-2), new AtEnd(0), null, null, null); 978 979 TextAShape timeTitleText = new TextAShape("dtitleText", 980 "$startTime$ - $endTimeExcl$", nttAbsRect, 981 TextAShape.TYPE_SINGE_LINE, new Font("SansSerif", Font.PLAIN, 982 11), Color.WHITE, new AtStart(0), new AtStart(-3), 983 GfxUtil.AA_HINT_OFF, new Point(1, 1), Color.DARK_GRAY); 984 985 timeTitleText.setAttribute(AShape.A_CLIP_TYPE, 986 AShape.CLIP_PARENT_BOUNDS); 987 988 990 FillAShape textBackground = new FillAShape("dbackground", 991 new Rectangle(0, 0, 1, 1), new AbsRect(SwingConstants.BOTTOM, 992 new Float (1f)), bgPaint, GfxUtil.AA_HINT_OFF); 993 994 textBackground.setAttribute(AShape.A_CROP_TO_VISIBILITY_BOUNDS, 995 Boolean.TRUE); 996 997 ContainerAShape textDockContainerA = new ContainerAShape("dtextDock", 998 AbsRect.FILL_INSIDE, new CutEdgeAShapeLayout()); 999 1000 PlaceRect durDockRect = new AbsRect(SwingConstants.BOTTOM, new Integer ( 1001 11)); 1002 1003 TextAShape durText = new TextAShape("ddurText", "$duration$", 1004 durDockRect, TextAShape.TYPE_SINGE_LINE, new Font("sansserif", 1005 Font.PLAIN, 9), Color.GRAY, new AtEnd(0), 1006 new AtFraction(0.5f), GfxUtil.AA_HINT_OFF); 1007 1008 durText.setAttribute(AShape.A_CLIP_TYPE, AShape.CLIP_PARENT_BOUNDS); 1009 1010 PlaceRect textDockRect = new AbsRect(SwingConstants.TOP, new Float (1f)); 1011 1012 TextAShape mainText = new TextAShape("dtext", "$summary$", 1013 textDockRect, TextAShape.TYPE_WRAP_TEXT, new Font("sansserif", 1014 Font.PLAIN, 11), Color.DARK_GRAY, new AtStart(0), 1015 new AtStart(0), GfxUtil.AA_HINT_OFF); 1016 1017 mainText.setAttribute(AShape.A_CLIP_TYPE, AShape.CLIP_PARENT_BOUNDS); 1018 1019 1021 DrawAShape outline = new DrawAShape("doutline", new Rectangle(0, 0, 1, 1022 1), AbsRect.FILL, new Color(180, 180, 200), 1023 new BasicStroke(1f), GfxUtil.AA_HINT_OFF); 1024 1025 1027 containerAShape.addSubShape(shadow); 1028 1029 containerAShape.addSubShape(content); 1030 1031 content.addSubShape(northTitle); 1032 1033 northTitle.addSubShape(timeTitleText); 1034 1035 content.addSubShape(textBackground); 1036 1037 textBackground.addSubShape(textDockContainerA); 1038 1039 textDockContainerA.addSubShape(durText); 1040 1041 textDockContainerA.addSubShape(new DividerAShape(new AbsRect( 1042 SwingConstants.BOTTOM, new Integer (1)), Color.LIGHT_GRAY)); 1043 1044 textDockContainerA.addSubShape(mainText); 1045 1046 containerAShape.addSubShape(outline); 1047 1048 RootAShape root = new RootAShape(containerAShape); 1049 1050 root.setRepaintPadding(new Insets(2, 2, 4, 4)); 1051 1052 HashMap timerMap = new HashMap (); 1053 1054 timerMap.put(TimerInteractor.PROP_INITIAL_DELAY, new Integer (0)); 1055 1056 timerMap.put(TimerInteractor.PROP_REPEAT_MILLIS, new Integer (500)); 1057 1058 timerMap.put(TimerInteractor.PROP_REPEAT_COUNT, new Integer (11)); 1059 1060 AShapeUtil.enableMouseOverCursor(root); 1061 1062 AShapeUtil.enableMouseOverState(containerAShape); 1063 1064 AShapeUtil.setResizeBoxes(containerAShape, SwingConstants.VERTICAL, 14); 1065 1066 1068 PropertyKey trigger = MouseKeyInteractor.MOUSE_PRESS; 1069 1070 Integer button = new Integer (MouseEvent.BUTTON1); 1071 1072 AShapeUtil.addMouseFireEvent(containerAShape, trigger, 1073 DefaultDateArea.AE_SELECTED_PRESSED, true, false, button); 1074 1075 AShapeUtil.addMouseFireEvent(containerAShape, trigger, 1076 DefaultDateArea.AE_DRAG_PRESSED, true, true, button); 1077 1078 AShapeUtil.addMouseEventBlock(containerAShape, false, new Integer ( 1079 MouseEvent.MOUSE_MOVED)); 1080 1081 return root; 1082 } 1083 1084 1088 public static RootAShape createTraslucentShapeHorizontal() { 1089 Color bgPaint = new Color(255, 200, 200); 1090 1091 Color bulletPaint = null; 1092 1093 Color outlinePaint = new Color(128, 0, 0); 1094 1095 1097 Color textPaint = new Color(50, 50, 50); 1098 1099 Font titleFont = new Font("SansSerif", Font.BOLD, 10); 1100 1101 RootAShape root = new RootAShape(); 1102 1103 FillAShape bgAShape = new FillAShape("bg", new RoundRectangle(0, 0, 1, 1104 1, 8, 8), AbsRect.FILL_INSIDE, bgPaint, GfxUtil.AA_HINT_ON); 1105 1106 PlaceRect bulletRect = new AbsRect(new AtStart(2), new AtStart(2)); 1107 1108 FillAShape bulletAShape = new FillAShape("bulletBackground", 1109 new Ellipse2D.Float (0, 0, 8, 8), bulletRect, bulletPaint, 1110 GfxUtil.AA_HINT_ON); 1111 1112 PlaceRect contentAbsRect = new AbsRect(new AtStart(3), new AtStart(0), 1113 new AtEnd(-1), new AtEnd(-1)); 1114 1115 ContainerAShape content = new ContainerAShape("dock", contentAbsRect, 1116 new CutEdgeAShapeLayout()); 1117 1118 PlaceRect titleTextAbsRect = new AbsRect(new AtStart(0), 1119 new AtStart(0), new AtEnd(0), new AtEnd(-1), null, null, null); 1120 1121 TextAShape timeTitleText = new TextAShape("titleText", 1122 "$startTime$-$endTimeExcl$ $summary$", titleTextAbsRect, 1123 TextAShape.TYPE_WRAP_TEXT, titleFont, textPaint, 1124 new AtStart(0), new AtStart(-2), GfxUtil.AA_HINT_OFF); 1125 1126 DrawAShape outlineAShape = new DrawAShape("outline", 1127 new RoundRectangle(0, 0, 1, 1, 12, 12), AbsRect.FILL, 1128 outlinePaint, new BasicStroke(1.2f), GfxUtil.AA_HINT_ON); 1129 1130 outlineAShape.setAttribute(AShape.A_MOUSE_CURSOR, Cursor 1131 .getPredefinedCursor(Cursor.MOVE_CURSOR)); 1132 1133 outlineAShape.setAttribute(AShape.A_REPORT_HIT_AREA, Boolean.TRUE); 1134 1135 bgAShape.addSubShape(bulletAShape); 1136 1137 content.addSubShape(timeTitleText); 1138 bgAShape.addSubShape(content); 1139 root.addSubShape(bgAShape); 1140 root.addSubShape(outlineAShape); 1141 AShapeUtil.enableMouseOverCursor(root); 1142 AShapeUtil.enableMouseOverState(outlineAShape); 1143 AShapeUtil.setResizeBoxes(root, SwingConstants.HORIZONTAL, 4); 1144 1145 1148 1150 PropertyKey trigger = MouseKeyInteractor.MOUSE_PRESS; 1151 Integer button = new Integer (MouseEvent.BUTTON1); 1152 AShapeUtil.addMouseFireEvent(outlineAShape, trigger, 1153 DefaultDateArea.AE_SELECTED_PRESSED, true, false, button); 1154 AShapeUtil.addMouseFireEvent(outlineAShape, trigger, 1155 DefaultDateArea.AE_DRAG_PRESSED, true, true, button); 1156 AShapeUtil.addMouseEventBlock(outlineAShape, false, new Integer ( 1157 MouseEvent.MOUSE_MOVED)); 1158 1159 return root; 1160 } 1161} 1162 | Popular Tags |