1 23 24 package org.objectweb.fractal.gui.graph.view; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.graph.model.Display; 29 import org.objectweb.fractal.gui.graph.model.DisplayListener; 30 import org.objectweb.fractal.gui.graph.model.GraphModel; 31 import org.objectweb.fractal.gui.graph.model.GraphModelListener; 32 import org.objectweb.fractal.gui.graph.model.Rect; 33 import org.objectweb.fractal.gui.graph.model.Tools; 34 import org.objectweb.fractal.gui.model.ClientInterface; 35 import org.objectweb.fractal.gui.model.Component; 36 import org.objectweb.fractal.gui.model.Configuration; 37 import org.objectweb.fractal.gui.model.ConfigurationListener; 38 import org.objectweb.fractal.gui.model.Interface; 39 import org.objectweb.fractal.gui.model.ServerInterface; 40 import org.objectweb.fractal.gui.selection.model.Selection; 41 import org.objectweb.fractal.gui.selection.model.SelectionListener; 42 import org.objectweb.fractal.gui.admin.model.AdminModel; 43 import org.objectweb.fractal.gui.admin.model.AdminModelListener; 44 import org.objectweb.fractal.swing.JPanelImpl; 45 46 import cwi.SVGGraphics.SVGGraphics; 47 48 import java.awt.AWTEvent ; 49 import java.awt.Color ; 50 import java.awt.Font ; 51 import java.awt.Graphics ; 52 import java.awt.Graphics2D ; 53 import java.awt.Image ; 54 import java.awt.Point ; 55 import java.awt.Rectangle ; 56 import java.awt.RenderingHints ; 57 import java.awt.Shape ; 58 import java.awt.print.Printable ; 59 import java.awt.print.PageFormat ; 60 import java.awt.print.Book ; 61 import java.awt.print.PrinterJob ; 62 import java.awt.print.PrinterException ; 63 import java.awt.event.ComponentAdapter ; 64 import java.awt.event.ComponentEvent ; 65 import java.awt.event.MouseEvent ; 66 import java.util.List ; 67 import java.util.GregorianCalendar ; 68 import java.util.Calendar ; 69 import java.util.Map ; 70 import java.util.HashMap ; 71 import java.util.Iterator ; 72 73 82 83 public class BasicGraphView extends JPanelImpl implements 84 DisplayListener, 85 AdminModelListener, 86 GraphModelListener, 87 ConfigurationListener, 88 SelectionListener, 89 Printer, 90 Printable , 91 BindingController 92 { 93 94 98 99 public final static String CONFIGURATION_BINDING = "configuration"; 100 101 104 105 public final static String GRAPH_BINDING = "graph"; 106 107 110 111 public final static String SELECTION_BINDING = "selection"; 112 113 116 117 public final static String DISPLAY_BINDING = "display"; 118 119 122 public final static String ADMIN_BINDING = "admin"; 123 124 127 128 public final static String TOOLS_BINDING = "tools"; 129 130 133 134 public final static String COMPONENT_RENDERER_BINDING = "component-renderer"; 135 136 139 140 public final static String BINDING_RENDERER_BINDING = "binding-renderer"; 141 142 146 147 public final static String GRAPH_VIEW_LISTENERS_BINDING = 148 "graph-view-listeners"; 149 150 153 154 private Configuration configuration; 155 156 159 160 private GraphModel graphModel; 161 162 165 166 private Selection selection; 167 168 171 172 private Display display; 173 174 177 178 private AdminModel admin; 179 180 183 184 private Tools tools; 185 186 189 190 private ComponentRenderer cRenderer; 191 192 195 196 private BindingRenderer bRenderer; 197 198 201 202 private Map graphViewListeners; 203 204 private int w, h, xo, yo; 205 206 private int wp, hp, xp, yp; 207 208 private boolean printInProgress = false; 209 210 private Component ctp; 212 private Image offScreen; 213 214 private boolean dirty; 215 216 private Point bindPoint; 217 218 private int typePrint; 219 220 static String UN = new String (System.getProperty("user.name")); 221 222 static final String [] mois = { 223 "Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", 224 "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."}; 225 226 229 230 public BasicGraphView () { 231 graphViewListeners = new HashMap (); 232 enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); 233 addComponentListener( 234 new ComponentAdapter () { 235 public void componentResized (final ComponentEvent e) { 236 w = e.getComponent().getSize().width; 237 h = e.getComponent().getSize().height; 238 xo = 0; 239 yo = 0; 240 if (w > 0 && h > 0) { 241 if (display != null) { 242 display.setScreenSize(new Rectangle (xo, yo, w, h)); 244 } 245 offScreen = createOffscreenImage(w, h); 246 redraw(); 247 } 248 } 249 }); 250 } 251 252 256 public String [] listFc () { 257 int size = graphViewListeners.size(); 258 String [] names = new String [size + 8]; 259 graphViewListeners.keySet().toArray(names); 260 names[size] = COMPONENT_RENDERER_BINDING; 261 names[size + 1] = BINDING_RENDERER_BINDING; 262 names[size + 2] = DISPLAY_BINDING; 263 names[size + 3] = TOOLS_BINDING; 264 names[size + 4] = SELECTION_BINDING; 265 names[size + 5] = CONFIGURATION_BINDING; 266 names[size + 6] = GRAPH_BINDING; 267 names[size + 7] = ADMIN_BINDING; 268 return names; 269 } 270 271 public Object lookupFc (final String clientItfName) { 272 if (COMPONENT_RENDERER_BINDING.equals(clientItfName)) { 273 return cRenderer; 274 } else if (BINDING_RENDERER_BINDING.equals(clientItfName)) { 275 return bRenderer; 276 } else if (DISPLAY_BINDING.equals(clientItfName)) { 277 return display; 278 } else if (ADMIN_BINDING.equals(clientItfName)) { 279 return admin; 280 } else if (TOOLS_BINDING.equals(clientItfName)) { 281 return tools; 282 } else if (SELECTION_BINDING.equals(clientItfName)) { 283 return selection; 284 } else if (CONFIGURATION_BINDING.equals(clientItfName)) { 285 return configuration; 286 } else if (GRAPH_BINDING.equals(clientItfName)) { 287 return graphModel; 288 } else if (clientItfName.startsWith(GRAPH_VIEW_LISTENERS_BINDING)) { 289 return graphViewListeners.get(clientItfName); 290 } 291 return null; 292 } 293 294 public void bindFc ( 295 final String clientItfName, 296 final Object serverItf) 297 { 298 if (COMPONENT_RENDERER_BINDING.equals(clientItfName)) { 299 cRenderer = (ComponentRenderer)serverItf; 300 } else if (BINDING_RENDERER_BINDING.equals(clientItfName)) { 301 bRenderer = (BindingRenderer)serverItf; 302 } else if (DISPLAY_BINDING.equals(clientItfName)) { 303 display = (Display)serverItf; 304 } else if (ADMIN_BINDING.equals(clientItfName)) { 305 admin = (AdminModel)serverItf; 306 } else if (TOOLS_BINDING.equals(clientItfName)) { 307 tools = (Tools)serverItf; 308 } else if (SELECTION_BINDING.equals(clientItfName)) { 309 selection = (Selection)serverItf; 310 } else if (CONFIGURATION_BINDING.equals(clientItfName)) { 311 configuration = (Configuration)serverItf; 312 } else if (GRAPH_BINDING.equals(clientItfName)) { 313 graphModel = (GraphModel)serverItf; 314 } else if (clientItfName.startsWith(GRAPH_VIEW_LISTENERS_BINDING)) { 315 graphViewListeners.put(clientItfName, serverItf); 316 } 317 } 318 319 public void unbindFc (final String clientItfName) { 320 if (COMPONENT_RENDERER_BINDING.equals(clientItfName)) { 321 cRenderer = null; 322 } else if (BINDING_RENDERER_BINDING.equals(clientItfName)) { 323 bRenderer = null; 324 } else if (DISPLAY_BINDING.equals(clientItfName)) { 325 display = null; 326 } else if (ADMIN_BINDING.equals(clientItfName)) { 327 admin = null; 328 } else if (TOOLS_BINDING.equals(clientItfName)) { 329 tools = null; 330 } else if (SELECTION_BINDING.equals(clientItfName)) { 331 selection = null; 332 } else if (CONFIGURATION_BINDING.equals(clientItfName)) { 333 configuration = null; 334 } else if (GRAPH_BINDING.equals(clientItfName)) { 335 graphModel = null; 336 } else if (clientItfName.startsWith(GRAPH_VIEW_LISTENERS_BINDING)) { 337 graphViewListeners.remove(clientItfName); 338 } 339 } 340 341 345 public void displayedAreaChanged (final Rect oldValue) { 346 redraw(); 347 } 348 349 public void antialiasingChanged () { 350 redraw(); 351 } 352 353 public void maxDepthChanged () { 354 redraw(); 355 } 356 357 public void itfNameDisplayModeChanged () { 358 redraw(); 359 } 360 361 365 public void componentCreated (Component model) { 366 redraw(); 367 } 368 369 public void componentDeleted (Component model) { 370 redraw(); 371 } 372 373 public void componentStarted (Component model) { 374 redraw(); 375 } 376 377 public void componentStopped (Component model) { 378 redraw(); 379 } 380 381 385 public void selectionChanged () { 386 redraw(); 387 } 388 389 393 public void setType (int ntype) { 394 typePrint = ntype; 395 } 396 397 public boolean print (final boolean ask, Component c) { 398 399 if (typePrint == Printer.TYPE_EXPORT) { 400 SVGGraphics svg = SVGGraphics.create (this); 401 if (svg == null) return false; 402 drawShapes(svg, c); 403 svg.close(); 404 return true; 405 } 406 407 PrinterJob job = PrinterJob.getPrinterJob(); 408 Book bk = new Book (); 409 if (ask) bk.append (new PaintCover(), job.defaultPage()); 410 ctp = c; 411 412 PageFormat page = job.defaultPage(); 414 page.setOrientation(PageFormat.LANDSCAPE); 415 xp = (int)page.getImageableX(); 416 yp = (int)page.getImageableY()+30; 417 wp = w - 2*xp; 418 hp = h - 2*yp; 419 422 bk.append (this, page); 423 if (c.getMasterComponent() != null) { 424 c = c.getMasterComponent(); 425 } 426 if (selection != null) { 427 selection.selectComponent(c); 428 } 429 configuration.setRootComponent(c); 430 431 job.setPageable(bk); 433 434 if (ask) { 436 if (job.printDialog()) imprime (job); 437 else return false; 438 } else { 439 imprime (job); 440 } 441 return true; 442 } 443 444 private void imprime (final PrinterJob job) { 445 try { 446 447 int oldxo = xo; 448 int oldyo = yo; 449 int oldw = w; 450 int oldh = h; 451 xo = xp; yo = yp; w = wp; h = hp; 452 453 printInProgress = true; 454 job.print(); 455 456 xo = oldxo; 457 yo = oldyo; 458 w = oldw; 459 h = oldh; 460 461 printInProgress = false; 462 } catch (Exception exc) { 463 exc.printStackTrace(); 464 } 465 } 466 467 471 public int print (final Graphics g, final PageFormat pf, final int pageIndex) 472 throws PrinterException 473 { 474 drawShapes((Graphics2D ) g, ctp); 475 return Printable.PAGE_EXISTS; 476 } 477 478 482 public void changeCountChanged (Component component, long changeCount) { 483 } 485 486 public void rootComponentChanged (final Component oldValue) { 487 Iterator i = graphViewListeners.values().iterator(); 488 while (i.hasNext()) { 489 GraphViewListener l = (GraphViewListener)i.next(); 490 l.viewChanged(); 491 } 492 redraw(); 493 } 494 495 public void nameChanged (final Component component, final String oldValue) { 496 redraw(); 497 } 498 499 public void typeChanged (final Component component, final String oldValue) { 500 redraw(); 501 } 502 503 public void implementationChanged ( 504 final Component component, 505 final String oldValue) 506 { 507 redraw(); 508 } 509 510 public void interfaceNameChanged ( 511 final Interface i, 512 final String oldValue) 513 { 514 redraw(); 515 } 516 517 public void interfaceSignatureChanged ( 518 final Interface i, 519 final String oldValue) 520 { 521 redraw(); 522 } 523 524 public void interfaceContingencyChanged ( 525 final Interface i, 526 final boolean oldValue) 527 { 528 redraw(); 529 } 530 531 public void interfaceCardinalityChanged ( 532 final Interface i, 533 final boolean oldValue) 534 { 535 redraw(); 536 } 537 538 public void clientInterfaceAdded ( 539 final Component component, 540 final ClientInterface i, 541 final int index) 542 { 543 redraw(); 544 } 545 546 public void clientInterfaceRemoved ( 547 final Component component, 548 final ClientInterface i, 549 final int index) 550 { 551 redraw(); 552 } 553 554 public void serverInterfaceAdded ( 555 final Component component, 556 final ServerInterface i, 557 final int index) 558 { 559 redraw(); 560 } 561 562 public void serverInterfaceRemoved ( 563 final Component component, 564 final ServerInterface i, 565 final int index) 566 { 567 redraw(); 568 } 569 570 public void interfaceBound ( 571 final ClientInterface citf, 572 final ServerInterface sitf) { 573 redraw(); 574 } 575 576 public void interfaceRebound ( 577 final ClientInterface citf, 578 final ServerInterface oldSitf) 579 { 580 redraw(); 581 } 582 583 public void interfaceUnbound ( 584 final ClientInterface citf, 585 final ServerInterface sitf) 586 { 587 redraw(); 588 } 589 590 public void attributeControllerChanged ( 591 final Component component, 592 final String oldValue) 593 { 594 redraw(); 595 } 596 597 public void attributeChanged ( 598 final Component component, 599 final String attributeName, 600 final String oldValue) 601 { 602 redraw(); 603 } 604 605 public void templateControllerDescriptorChanged ( 606 final Component component, 607 final String oldValue) 608 { 609 redraw(); 610 } 611 612 public void componentControllerDescriptorChanged ( 613 final Component component, 614 final String oldValue) 615 { 616 redraw(); 617 } 618 619 public void subComponentAdded ( 620 final Component parent, 621 final Component child, 622 final int index) 623 { 624 redraw(); 625 } 626 627 public void subComponentRemoved ( 628 final Component parent, 629 final Component child, 630 final int index) 631 { 632 redraw(); 633 } 634 635 639 public void componentColorChanged ( 640 final Component component, 641 final Color oldColor) 642 { 643 if (configuration.getRootComponent().contains(component)) { 644 redraw(); 645 } 646 } 647 648 public void componentPositionChanged ( 649 final Component component, 650 final Rect oldValue) 651 { 652 if (configuration.getRootComponent().contains(component)) { 653 redraw(); 654 } 655 } 656 657 661 protected void processMouseEvent (final MouseEvent e) { 662 if (configuration == null) { 663 return; 664 } 665 int x = e.getX(); 666 int y = e.getY(); 667 ComponentPart p = getComponentPart(x, y); 668 669 GraphViewListener l; 670 Iterator i = graphViewListeners.values().iterator(); 671 672 boolean needRedraw = tools != null && tools.getTool() == Tools.BIND; 673 674 switch (e.getID()) { 675 case MouseEvent.MOUSE_PRESSED: 676 while (i.hasNext()) { 677 l = (GraphViewListener)i.next(); 678 l.mousePressed(e, p); 679 } 680 break; 681 682 case MouseEvent.MOUSE_RELEASED: 683 while (i.hasNext()) { 684 l = (GraphViewListener)i.next(); 685 l.mouseReleased(e, p); 686 } 687 break; 688 689 case MouseEvent.MOUSE_CLICKED: 690 while (i.hasNext()) { 691 l = (GraphViewListener)i.next(); 692 l.mouseClicked(e, p); 693 } 694 break; 695 696 case MouseEvent.MOUSE_ENTERED: 697 while (i.hasNext()) { 698 l = (GraphViewListener)i.next(); 699 l.mouseEntered(e); 700 } 701 break; 702 703 case MouseEvent.MOUSE_EXITED: 704 while (i.hasNext()) { 705 l = (GraphViewListener)i.next(); 706 l.mouseExited(e); 707 } 708 break; 709 710 default: 711 break; 712 } 713 714 if (needRedraw) { 715 redraw(); 716 } 717 super.processMouseEvent(e); 718 } 719 720 protected void processMouseMotionEvent (final MouseEvent e) { 721 if (configuration == null) { 722 return; 723 } 724 725 boolean needRedraw = tools != null && tools.getTool() == Tools.BIND; 726 727 Iterator i = graphViewListeners.values().iterator(); 728 GraphViewListener l; 729 bindPoint = e.getPoint(); 730 731 switch (e.getID()) { 732 case MouseEvent.MOUSE_DRAGGED: 733 while (i.hasNext()) { 734 l = (GraphViewListener)i.next(); 735 l.mouseDragged(e); 736 } 737 break; 738 739 case MouseEvent.MOUSE_MOVED: 740 int x = e.getX(); 741 int y = e.getY(); 742 ComponentPart p = getComponentPart(x, y); 743 while (i.hasNext()) { 744 l = (GraphViewListener)i.next(); 745 l.mouseMoved(e, p); 746 } 747 break; 748 749 default: 750 break; 751 } 752 753 if (needRedraw) { 754 redraw(); 755 } 756 757 super.processMouseMotionEvent(e); 758 } 759 760 762 public void paint (final Graphics g) { 763 if (offScreen != null) { 764 if (printInProgress) { 765 g.drawImage(offScreen, xo, yo, w, h, this); 766 } else { 767 g.drawImage(offScreen, xo, yo, w, h, this); 768 } 769 } 770 } 771 772 public void repaint () { 773 paint(getGraphics()); 774 } 775 776 public void setVisible (final boolean visible) { 777 super.setVisible(visible); 778 if (visible && dirty) { 779 redraw(); 780 } 781 } 782 783 787 Image createOffscreenImage (final int w, final int h) { 788 return createImage(w, h); 789 } 790 791 private ComponentPart getComponentPart (final int x, final int y) { 792 Component root = configuration.getRootComponent(); 793 Rectangle r = new Rectangle (xo, yo, w, h); 794 if (display != null) { 795 r = getRectangle(r, display.getDisplayedArea()); 796 } else { 797 r = getRectangle(r, new Rect(0.1, 0.1, 0.9, 0.9)); 798 } 799 800 int depth = display == null ? 0 : display.getMaxDepth(); 801 ComponentPart part = getComponentPart(root, r, x, y, depth); 802 if (part == null) { 803 part = new ComponentPart(null, null, 0, new Rectangle (xo, yo, w, h)); 804 } 805 return part; 806 } 807 808 private ComponentPart getComponentPart ( 809 final Component c, 810 final Rectangle r, 811 final int x, 812 final int y, 813 final int depth) 814 { 815 if (r.width <= 0 || r.height <= 0) { 816 return null; 817 } 818 if (!r.intersects(new Rectangle (xo, yo, w, h))) { 819 return null; 820 } 821 822 ComponentPart part = cRenderer.getComponentPart(c, r, depth > 0, x, y); 824 825 if (part != null && part.getPart() == ComponentPart.CONTENT) { 826 if (depth > 0 && c.isComposite()) { 827 List subComponents = c.getSubComponents(); 829 for (int i = 0; i < subComponents.size(); ++i) { 830 Component subC = (Component)subComponents.get(i); 831 Rectangle subR = cRenderer.getSubComponentArea(c, r); 832 subR = getRectangle(subR, graphModel.getComponentPosition(subC)); 833 ComponentPart subPart = getComponentPart(subC, subR, x, y, depth - 1); 834 if (subPart != null) { 835 return subPart; 836 } 837 } 838 } 839 } 840 return part; 841 } 842 843 synchronized void redraw () { 844 if (offScreen == null || configuration == null) { 845 return; 846 } 847 if (!isVisible()) { 848 dirty = true; 849 return; 850 } 851 dirty = false; 852 853 final Graphics2D g = (Graphics2D )offScreen.getGraphics(); 854 g.setRenderingHint ( 855 RenderingHints.KEY_ANTIALIASING, 856 display != null && display.isAntialiasing() 857 ? RenderingHints.VALUE_ANTIALIAS_ON 858 : RenderingHints.VALUE_ANTIALIAS_OFF); 859 860 g.setColor(Color.white); 861 g.fillRect(0, 0, w, h); 862 863 final Component root = configuration.getRootComponent(); 864 Rectangle r = new Rectangle (xo, yo, w, h); 865 if (display != null) { 866 r = getRectangle(r, display.getDisplayedArea()); 867 } else { 868 r = getRectangle(r, new Rect(0.1, 0.1, 0.9, 0.9)); 869 } 870 drawComponent(g, root, r, display == null ? 0 : display.getMaxDepth()); 871 repaint(); 872 } 873 874 875 synchronized void drawShapes (final Graphics2D g, final Component c) { 876 if (offScreen == null || configuration == null) { 877 return; 878 } 879 if (!isVisible()) { 880 dirty = true; 881 return; 882 } 883 dirty = false; 884 g.setRenderingHint( 885 RenderingHints.KEY_ANTIALIASING, 886 display != null && display.isAntialiasing() 887 ? RenderingHints.VALUE_ANTIALIAS_ON 888 : RenderingHints.VALUE_ANTIALIAS_OFF); 889 890 g.setColor(Color.white); 891 g.fillRect(0, 0, w, h); 892 893 Rectangle r = new Rectangle (xo, yo, w, h); 895 if (display != null) { 896 r = getRectangle(r, display.getDisplayedArea()); 897 } else { 898 r = getRectangle(r, new Rect(0.1, 0.1, 0.9, 0.9)); 899 } 900 drawComponent(g, c, r, display == null ? 0 : display.getMaxDepth()); 901 paint (g); 902 } 903 904 905 private void drawComponent ( 906 final Graphics g, 907 final Component c, 908 final Rectangle r, 909 final int depth) 910 { 911 if (r.width <= 0 || r.height <= 0) { 912 return; 913 } 914 if (!r.intersects(new Rectangle (xo, yo, w, h))) { 915 return; 916 } 917 boolean expanded = depth > 0 && c.isComposite(); 918 919 int instance = ComponentRenderer.NO_INSTANCE; 920 if (admin != null) { 921 if (admin.getInstance(c) != null) { 922 if (admin.isStarted(c)) { 923 instance = ComponentRenderer.STARTED; 924 } else { 925 instance = ComponentRenderer.STOPPED; 926 } 927 } 928 } 929 930 Color color = graphModel.getComponentColor(c); 932 if (display == null) 933 cRenderer.drawComponent(g, c, selection, r, color, expanded, 0, instance); 934 else cRenderer.drawComponent 935 (g, c, selection, r, color, expanded, display.getItfNameDisplayMode(), instance); 936 937 if (expanded) { 938 Shape clip = g.getClip(); 940 Rectangle s = cRenderer.getSubComponentArea(c, r); 941 g.clipRect(s.x, s.y, s.width, s.height); 942 943 List subComponents = c.getSubComponents(); 944 for (int i = subComponents.size() - 1; i >= 0; --i) { 945 Component subC = (Component)subComponents.get(i); 946 Rectangle subR = getRectangle(s, graphModel.getComponentPosition(subC)); 947 drawComponent(g, subC, subR, depth - 1); 948 } 949 950 for (int i = subComponents.size() - 1; i >= 0; --i) { 951 Component subC = (Component)subComponents.get(i); 952 Rectangle subR = getRectangle(s, graphModel.getComponentPosition(subC)); 953 drawExternalBindings(g, c, r, subC, subR, i); 954 } 955 drawInternalBindings(g, c, r); 957 g.setClip(clip); 958 } 959 } 960 961 private void drawExternalBindings ( 962 final Graphics g, 963 final Component p, 964 final Rectangle pr, 965 final Component c, 966 final Rectangle r, 967 final int rg) 968 { 969 List l = c.getClientInterfaces(); 970 for (int i = 0; i < l.size(); ++i) { 971 ClientInterface citf = (ClientInterface)l.get(i); 972 if (citf.getBinding() != null) { 973 ServerInterface sitf = citf.getBinding().getServerInterface(); 974 Component server = sitf.getOwner(); 975 Point cp = cRenderer.getInterfacePosition(c, r, citf); 976 977 Rectangle t; 978 if (server == p) { 979 t = pr; 980 } else if (server.getParent() != c.getParent()) { 981 continue; 982 } else { 983 Rectangle s = cRenderer.getSubComponentArea(p, pr); 984 t = getRectangle(s, graphModel.getComponentPosition(server)); 985 } 986 Point sp = cRenderer.getInterfacePosition(server, t, sitf); 987 bRenderer.drawBinding(g, r, t, cp, sp, citf.getBinding(), rg+i); 988 } 989 990 if (tools != null && 991 tools.getTool() == Tools.BIND && 992 tools.getBindInterface() == citf) 993 { 994 Point cp = cRenderer.getInterfacePosition(c, r, citf); 995 bRenderer.drawBinding(g, r, null, cp, bindPoint, citf.getBinding(), rg+i); 996 } 997 } 998 } 999 1000 1001 private void drawInternalBindings ( 1002 final Graphics g, 1003 final Component c, 1004 final Rectangle r) 1005 { 1006 if (!c.isComposite()) { 1007 return; 1008 } 1009 1010 List l = c.getServerInterfaces(); 1011 for (int i = 0; i < l.size(); ++i) { 1012 Interface itf = (Interface)l.get(i); 1013 1014 ClientInterface citf = (ClientInterface)itf.getComplementaryInterface(); 1015 if (citf.getBinding() != null) { 1016 Point sp; 1017 Rectangle t; 1018 Point cp = cRenderer.getInterfacePosition(c, r, citf); 1019 ServerInterface sitf = citf.getBinding().getServerInterface(); 1020 Component server = sitf.getOwner(); 1021 1022 if (server != c) { 1023 Rectangle s = cRenderer.getSubComponentArea(c, r); 1024 t = getRectangle(s, graphModel.getComponentPosition(server)); 1025 sp = cRenderer.getInterfacePosition(server, t, sitf); 1026 } else { 1027 t = r; 1028 sp = cRenderer.getInterfacePosition(server, r, sitf); 1029 } 1030 bRenderer.drawBinding(g, r, t, cp, sp, citf.getBinding(), i); 1031 } 1032 1033 if (tools != null && 1034 tools.getTool() == Tools.BIND && 1035 tools.getBindInterface() == citf) 1036 { 1037 Point cp = cRenderer.getInterfacePosition(c, r, citf); 1038 bRenderer.drawBinding(g, r, null, cp, bindPoint, citf.getBinding(), i); 1039 } 1040 } 1041 } 1042 1043 private Rectangle getRectangle (final Rectangle r, final Rect rect) { 1044 int h0 = r.x + (int)(r.width * rect.x0); 1045 int v0 = r.y + (int)(r.height * rect.y0); 1046 int h1 = r.x + (int)(r.width * rect.x1); 1047 int v1 = r.y + (int)(r.height * rect.y1); 1048 return new Rectangle (h0, v0, h1 - h0, v1 - v0); 1049 } 1050 1051 class PaintCover implements Printable 1052 { 1053 private Component c; 1054 1055 public int print(Graphics g, PageFormat pf, int pageIndex) 1056 throws PrinterException 1057 { 1058 g.setColor(Color.black); 1059 g.setFont(new Font ("MonoSpaced", Font.PLAIN, 14)); 1060 GregorianCalendar grcl = new GregorianCalendar (); 1061 1062 g.drawString("Printing by FractalGUI", 100, 100); 1063 g.drawString("for : "+UN, 120, 120); 1064 g.drawString("Component : '"+configuration.getRootComponent().getName() 1065 +"'", 120, 140); 1066 g.drawString("Date : "+mois[grcl.get(Calendar.MONTH)]+", " 1067 +grcl.get(Calendar.DAY_OF_MONTH)+"th "+grcl.get(Calendar.YEAR) 1068 , 120, 160); 1069 g.drawString("Time : "+grcl.get(Calendar.HOUR_OF_DAY) 1070 +"H"+grcl.get(Calendar.MINUTE) 1071 , 120, 180); 1072 return Printable.PAGE_EXISTS; 1073 } 1074 } 1075} 1076 | Popular Tags |