View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 11 package com.sun.xml.registry.client.browser.graph; 12 13 import com.jgraph.JGraph; 14 15 import com.jgraph.event.GraphSelectionEvent; 16 import com.jgraph.event.GraphSelectionListener; 17 18 import com.jgraph.graph.*; 19 20 import com.sun.xml.registry.client.browser.FindParamsPanel; 21 import com.sun.xml.registry.client.browser.JAXRClient; 22 import com.sun.xml.registry.client.browser.JBDialog; 23 import com.sun.xml.registry.client.browser.JBEditorDialog; 24 import com.sun.xml.registry.client.browser.RegistryBrowser; 25 26 import java.awt.*; 27 import java.awt.event.*; 28 29 import java.net.URL; 30 31 import java.util.ArrayList; 32 import java.util.Collection; 33 import java.util.HashMap; 34 import java.util.HashSet; 35 import java.util.Hashtable; 36 import java.util.Iterator; 37 import java.util.Map; 38 39 import javax.swing.*; 40 import javax.swing.event.UndoableEditEvent; 41 42 import javax.xml.registry.BusinessLifeCycleManager; 43 import javax.xml.registry.JAXRException; 44 import javax.xml.registry.UnsupportedCapabilityException; 45 import javax.xml.registry.infomodel.Association; 46 import javax.xml.registry.infomodel.Classification; 47 import javax.xml.registry.infomodel.ClassificationScheme; 48 import javax.xml.registry.infomodel.Concept; 49 import javax.xml.registry.infomodel.ExternalIdentifier; 50 import javax.xml.registry.infomodel.InternationalString; 51 import javax.xml.registry.infomodel.Organization; 52 import javax.xml.registry.infomodel.RegistryObject; 53 import javax.xml.registry.infomodel.Service; 54 import javax.xml.registry.infomodel.ServiceBinding; 55 import javax.xml.registry.infomodel.SpecificationLink; 56 import javax.xml.registry.infomodel.User; 57 58 59 /*** 60 * Specialized JGraph for JAXR Browser 61 * 62 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 63 */ 64 public class JBGraph extends JGraph implements GraphSelectionListener, 65 KeyListener { 66 67 static int LINK_TYPE_UNSPECIFIED = 0; 68 static int LINK_TYPE_ASSOCIATION = 1; 69 static int LINK_TYPE_COMPOSITION = 2; 70 static int LINK_TYPE_AGGREGATION = 3; 71 72 // Undo Manager 73 74 /*** DOCUMENT ME! */ 75 protected GraphUndoManager undoManager; 76 private JToolBar toolBar = null; 77 private HashMap registryObjectToCellMap = new HashMap(); 78 private com.sun.xml.registry.client.browser.TreeCombo objectTypeCombo=null; 79 80 // Actions which Change State 81 protected Action undo; 82 83 // Actions which Change State 84 protected Action redo; 85 86 // Actions which Change State 87 protected Action remove; 88 89 // Actions which Change State 90 //protected Action group; 91 92 // Actions which Change State 93 //protected Action ungroup; 94 95 // Actions which Change State 96 protected Action tofront; 97 98 // Actions which Change State 99 protected Action toback; 100 101 // Actions which Change State 102 //protected Action cut; 103 104 // Actions which Change State 105 //protected Action copy; 106 107 // Actions which Change State 108 //protected Action paste; 109 110 private boolean editable = true; 111 112 /*** 113 * Creates a new JBGraph object. 114 */ 115 public JBGraph() { 116 this(new JBGraphModel()); 117 } 118 119 /*** 120 * Creates a new JBGraph object. 121 * 122 * @param model DOCUMENT ME! 123 */ 124 public JBGraph(JBGraphModel model) { 125 super(model); 126 127 // Use a Custom Marquee Handler 128 setMarqueeHandler(new JBMarqueeHandler(this)); 129 130 // Tell the Graph to Select new Cells upon Insertion 131 setSelectNewCells(true); 132 133 // Make Ports Visible by Default 134 setPortsVisible(true); 135 136 // Use the Grid (but don't make it Visible) 137 setGridEnabled(true); 138 139 // Set the Grid Size to 10 Pixel 140 setGridSize(6); 141 142 // Set the Snap Size to 2 Pixel 143 setSnapSize(1); 144 145 // Construct Command History 146 // 147 // Create a GraphUndoManager which also Updates the ToolBar 148 undoManager = 149 new GraphUndoManager() { 150 151 // Override Superclass 152 public void undoableEditHappened(UndoableEditEvent e) { 153 154 // First Invoke Superclass 155 super.undoableEditHappened(e); 156 157 // Then Update Undo/Redo Buttons 158 updateHistoryButtons(); 159 } 160 }; 161 162 // Add Listeners to Graph 163 // 164 // Register UndoManager with the Model 165 getModel().addUndoableEditListener(undoManager); 166 167 // Update ToolBar based on Selection Changes 168 getSelectionModel().addGraphSelectionListener(this); 169 170 // Listen for Delete Keystroke when the Graph has Focus 171 addKeyListener(this); 172 173 toolBar = createToolBar(); 174 } 175 176 // Override Superclass Method to Return Custom EdgeView 177 protected EdgeView createEdgeView(Edge e, CellMapper cm) { 178 179 // Return Custom EdgeView 180 return new EdgeView(e, this, cm) { 181 182 // Override Superclass Method 183 public boolean isAddPointEvent(MouseEvent event) { 184 185 // Points are Added using Shift-Click 186 return event.isShiftDown(); 187 } 188 189 // Override Superclass Method 190 public boolean isRemovePointEvent(MouseEvent event) { 191 192 // Points are Removed using Shift-Click 193 return event.isShiftDown(); 194 } 195 }; 196 } 197 198 // Insert a new Vertex at point 199 public void insert(Point point) { 200 RegistryBrowser.setWaitCursor(); 201 202 try { 203 204 if (RegistryBrowser.getInstance().getClient().getConnection() == null) { 205 RegistryBrowser.displayError("Connect to a registry by specifying Registry Location first."); 206 207 return; 208 } 209 210 RegistryObject ro = createRegistryObject(); 211 212 // Construct Vertex with no Label 213 JBGraphCell vertex = new JBGraphCell(ro, true); 214 215 registryObjectToCellMap.put(ro, vertex); 216 217 // Add one Floating Port 218 vertex.add(new DefaultPort()); 219 220 // Snap the Point to the Grid 221 point = snap(new Point(point)); 222 223 // Default Size for the new Vertex 224 Dimension size = new Dimension(25, 25); 225 226 // Create a Map that holds the attributes for the Vertex 227 Map map = GraphConstants.createMap(); 228 229 // Add a Bounds Attribute to the Map 230 GraphConstants.setBounds(map, new Rectangle(point, size)); 231 232 // Add a Border Color Attribute to the Map 233 GraphConstants.setBorderColor(map, Color.black); 234 235 // Add a White Background 236 GraphConstants.setBackground(map, Color.white); 237 238 // Make Vertex Opaque 239 GraphConstants.setOpaque(map, true); 240 241 // Construct a Map from cells to Maps (for insert) 242 Hashtable attributes = new Hashtable(); 243 244 // Associate the Vertex with its Attributes 245 attributes.put(vertex, map); 246 247 // Insert the Vertex and its Attributes 248 getModel().insert(new Object[] { vertex }, null, null, 249 attributes); 250 } catch (JAXRException e) { 251 e.printStackTrace(); 252 RegistryBrowser.displayError(e); 253 } 254 255 RegistryBrowser.setDefaultCursor(); 256 } 257 258 // save changes to graph 259 public void save() { 260 RegistryBrowser.setWaitCursor(); 261 262 Object[] selectedCells = getSelectionCells(); 263 HashSet objectsToSave = new HashSet(); 264 265 for (int i = 0; i < selectedCells.length; i++) { 266 267 if (selectedCells[i] instanceof JBGraphCell) { 268 269 RegistryObject ro = 270 ((JBGraphCell)selectedCells[i]).getRegistryObject(); 271 objectsToSave.add(ro); 272 } 273 else if (selectedCells[i] instanceof DefaultGraphCell) { 274 //This is the case when save done of a Collection element 275 //For now all elements will be processed as it is not obvious 276 //how to figure out which element was selected 277 DefaultGraphCell cell = (DefaultGraphCell)selectedCells[i]; 278 java.util.List children = cell.getChildren(); 279 if (children != null) 280 { 281 Iterator iter = children.iterator(); 282 while (iter.hasNext()) { 283 Object obj = iter.next(); 284 if (obj instanceof JBGraphCell) { 285 RegistryObject ro = ((JBGraphCell)obj).getRegistryObject(); 286 objectsToSave.add(ro); 287 } 288 } 289 } 290 } 291 } 292 293 try { 294 295 JAXRClient client = 296 RegistryBrowser.getInstance().getClient(); 297 client.saveObjects(objectsToSave); 298 } catch (JAXRException e) { 299 RegistryBrowser.displayError(e); 300 } 301 302 RegistryBrowser.setDefaultCursor(); 303 } 304 305 // export changes to graph 306 public void export() { 307 RegistryBrowser.setWaitCursor(); 308 309 Object[] selectedCells = getSelectionCells(); 310 HashSet objectsToExport = new HashSet(); 311 312 for (int i = 0; i < selectedCells.length; i++) { 313 314 if (selectedCells[i] instanceof JBGraphCell) { 315 316 RegistryObject ro = 317 ((JBGraphCell)selectedCells[i]).getRegistryObject(); 318 objectsToExport.add(ro); 319 } 320 else if (selectedCells[i] instanceof DefaultGraphCell) { 321 //This is the case when save done of a Collection element 322 //For now all elements will be processed as it is not obvious 323 //how to figure out which element was selected 324 DefaultGraphCell cell = (DefaultGraphCell)selectedCells[i]; 325 java.util.List children = cell.getChildren(); 326 Iterator iter = children.iterator(); 327 if (children != null) 328 { 329 while (iter.hasNext()) { 330 Object obj = iter.next(); 331 if (obj instanceof JBGraphCell) { 332 RegistryObject ro = ((JBGraphCell)obj).getRegistryObject(); 333 objectsToExport.add(ro); 334 } 335 } 336 } 337 } 338 } 339 340 JAXRClient client = RegistryBrowser.getInstance().getClient(); 341 client.exportObjects(objectsToExport); 342 RegistryBrowser.setDefaultCursor(); 343 } 344 345 // Insert a new Edge between source and target 346 public void connect(Port source, Port target) { 347 348 try { 349 350 if (RegistryBrowser.getInstance().getClient().getConnection() == null) { 351 RegistryBrowser.displayError("Connect to a registry by specifying Registry Location first."); 352 353 return; 354 } 355 356 Object srcObj = (((DefaultPort)source).getParent()); 357 Object targetObj = (((DefaultPort)target).getParent()); 358 359 if (!((srcObj instanceof JBGraphCell) 360 && (srcObj instanceof JBGraphCell))) { 361 362 return; 363 } 364 365 RegistryObject srcRO = 366 ((JBGraphCell)srcObj).getRegistryObject(); 367 RegistryObject targetRO = 368 ((JBGraphCell)targetObj).getRegistryObject(); 369 370 RelationshipPanel relPanel = 371 new RelationshipPanel(srcRO, targetRO); 372 JBDialog dialog = 373 new JBDialog(RegistryBrowser.getInstance(), true, 374 relPanel); 375 dialog.setTitle("Relationship"); 376 dialog.setEditable(editable); 377 dialog.setVisible(true); 378 379 if (dialog.getStatus() != JBDialog.OK_STATUS) { 380 381 return; 382 } 383 384 String relationshipType = relPanel.getRelationshipType(); 385 386 boolean reverse = false; 387 boolean directed = true; 388 int linkType = LINK_TYPE_ASSOCIATION; 389 390 String relationshipName = relPanel.getRelationshipName(); 391 boolean collection = true; 392 393 if (relationshipType == RelationshipPanel.RELATIONSHIP_TYPE_ASSOCIATION) { 394 directed = true; 395 collection = false; 396 linkType = LINK_TYPE_ASSOCIATION; 397 } else if (relationshipType == RelationshipPanel.RELATIONSHIP_TYPE_REFERENCE) { 398 directed = true; 399 relPanel.setReferenceAttributeOnSourceObject(); 400 } 401 402 /* 403 GraphConstants.setLineBegin(aggregateStyle, GraphConstants.DIAMOND); 404 GraphConstants.setBeginFill(aggregateStyle, true); 405 GraphConstants.setBeginSize(aggregateStyle, 6); 406 GraphConstants.setLineEnd(aggregateStyle, GraphConstants.SIMPLE); 407 GraphConstants.setEndSize(aggregateStyle, 8); 408 GraphConstants.setFontSize(aggregateStyle, 10); 409 boolean reverse = false; 410 String relationshipName = ""; 411 boolean collection=true; 412 */ 413 414 // Connections that will be inserted into the Model 415 ConnectionSet cs = new ConnectionSet(); 416 417 // Construct Edge with no label 418 DefaultEdge edge = new DefaultEdge(relationshipName); 419 420 // Create Connection between source and target using edge 421 if (!reverse) { 422 cs.connect(edge, source, target); 423 } else { 424 cs.connect(edge, target, source); 425 } 426 427 // Create a Map thath holds the attributes for the edge 428 Map map = GraphConstants.createMap(); 429 430 if (directed == true) { 431 GraphConstants.setLineEnd(map, GraphConstants.SIMPLE); 432 } else { 433 } 434 435 if (linkType == LINK_TYPE_COMPOSITION) { 436 GraphConstants.setBeginFill(map, true); 437 GraphConstants.setLineBegin(map, GraphConstants.DIAMOND); 438 } else if (linkType == LINK_TYPE_AGGREGATION) { 439 GraphConstants.setBeginFill(map, false); 440 GraphConstants.setLineBegin(map, GraphConstants.DIAMOND); 441 } 442 443 // Construct a Map from cells to Maps (for insert) 444 Hashtable attributes = new Hashtable(); 445 446 // Associate the Edge with its Attributes 447 attributes.put(edge, map); 448 449 // Insert the Edge and its Attributes 450 getModel().insert(new Object[] { edge }, cs, null, 451 attributes); 452 } catch (JAXRException e) { 453 RegistryBrowser.displayError(e); 454 } 455 } 456 457 // Create a Group that Contains the Cells 458 public DefaultGraphCell group(Object[] cells) { 459 460 DefaultGraphCell group = null; 461 462 // Order Cells by View Layering 463 cells = getView().order(cells); 464 465 // If Any Cells in View 466 if ((cells != null) && (cells.length > 0)) { 467 468 // Create Group Cell 469 group = new DefaultGraphCell(); 470 471 DefaultPort port = new DefaultPort("Center"); 472 group.add(port); 473 474 // Create Change Information 475 ParentMap map = new ParentMap(); 476 477 // Insert Child Parent Entries 478 for (int i = 0; i < cells.length; i++) { 479 map.addEntry(cells[i], group); 480 } 481 482 // Insert into model 483 getModel().insert(new Object[] { group }, null, map, null); 484 } 485 486 return group; 487 } 488 489 // Ungroup the Groups in Cells and Select the Children 490 public void ungroup(Object[] cells) { 491 492 // If any Cells 493 if ((cells != null) && (cells.length > 0)) { 494 495 // List that Holds the Groups 496 ArrayList groups = new ArrayList(); 497 498 // List that Holds the Children 499 ArrayList children = new ArrayList(); 500 501 // Loop Cells 502 for (int i = 0; i < cells.length; i++) { 503 504 // If Cell is a Group 505 if (isGroup(cells[i])) { 506 507 // Add to List of Groups 508 groups.add(cells[i]); 509 510 // Loop Children of Cell 511 for (int j = 0; 512 j < getModel().getChildCount(cells[i]); j++) { 513 514 // Get Child from Model 515 Object child = getModel().getChild(cells[i], j); 516 517 // If Not Port 518 if (!(child instanceof Port)) { 519 520 // Add to Children List 521 children.add(child); 522 } 523 } 524 } 525 } 526 527 // Remove Groups from Model (Without Children) 528 getModel().remove(groups.toArray()); 529 530 // Select Children 531 setSelectionCells(children.toArray()); 532 } 533 } 534 535 // Determines if a Cell is a Group 536 public boolean isGroup(Object cell) { 537 538 // Map the Cell to its View 539 CellView view = getView().getMapping(cell, false); 540 541 if (view != null) { 542 543 return !view.isLeaf(); 544 } 545 546 return false; 547 } 548 549 // Brings the Specified Cells to Front 550 public void toFront(Object[] c) { 551 552 if ((c != null) && (c.length > 0)) { 553 getView().toFront(getView().getMapping(c)); 554 } 555 } 556 557 // Sends the Specified Cells to Back 558 public void toBack(Object[] c) { 559 560 if ((c != null) && (c.length > 0)) { 561 getView().toBack(getView().getMapping(c)); 562 } 563 } 564 565 // Undo the last Change to the Model or the View 566 public void undo() { 567 568 try { 569 undoManager.undo(getView()); 570 } catch (Exception ex) { 571 System.err.println(ex); 572 } finally { 573 updateHistoryButtons(); 574 } 575 } 576 577 // Redo the last Change to the Model or the View 578 public void redo() { 579 580 try { 581 undoManager.redo(getView()); 582 } catch (Exception ex) { 583 System.err.println(ex); 584 } finally { 585 updateHistoryButtons(); 586 } 587 } 588 589 // Update Undo/Redo Button State based on Undo Manager 590 protected void updateHistoryButtons() { 591 592 // The View Argument Defines the Context 593 undo.setEnabled(undoManager.canUndo(getView())); 594 redo.setEnabled(undoManager.canRedo(getView())); 595 } 596 597 // 598 // Listeners 599 // 600 // From GraphSelectionListener Interface 601 public void valueChanged(GraphSelectionEvent e) { 602 603 // Group Button only Enabled if more than One Cell Selected 604 //group.setEnabled(getSelectionCount() > 1); 605 606 // Update Button States based on Current Selection 607 boolean enabled = !isSelectionEmpty(); 608 remove.setEnabled(enabled); 609 //ungroup.setEnabled(enabled); 610 tofront.setEnabled(enabled); 611 toback.setEnabled(enabled); 612 //copy.setEnabled(enabled); 613 //cut.setEnabled(enabled); 614 615 /* 616 //Show selected cell's details if RegistryObjectDialog isVisible 617 RegistryObjectDialog dialog = RegistryBrowser.getInstance().getRegistryObjectDialog(); 618 619 if (dialog.isVisible()) { 620 Object[] selectedCells = getSelectionCells(); 621 if ((selectedCells.length == 1) && (selectedCells[0] instanceof JBGraphCell)) { 622 dialog.setRegistryObject(((JBGraphCell)selectedCells[0]).getRegistryObject()); 623 } 624 else { 625 dialog.setRegistryObject(null); 626 } 627 } 628 */ 629 } 630 631 // 632 // KeyListener for Delete KeyStroke 633 // 634 public void keyReleased(KeyEvent e) { 635 } 636 637 /*** 638 * DOCUMENT ME! 639 * 640 * @param e DOCUMENT ME! 641 */ 642 public void keyTyped(KeyEvent e) { 643 } 644 645 /*** 646 * DOCUMENT ME! 647 * 648 * @param e DOCUMENT ME! 649 */ 650 public void keyPressed(KeyEvent e) { 651 652 // Listen for Delete Key Press 653 if (e.getKeyCode() == KeyEvent.VK_DELETE) { 654 655 // Execute Remove Action on Delete Key Press 656 remove.actionPerformed(null); 657 } 658 } 659 660 /*** 661 * DOCUMENT ME! 662 * 663 * @param ro DOCUMENT ME! 664 * @param bounds DOCUMENT ME! 665 * @param createIcon DOCUMENT ME! 666 * 667 * @return DOCUMENT ME! 668 */ 669 public JBGraphCell addRegistryObject(RegistryObject ro, 670 Rectangle bounds, 671 boolean createIcon) { 672 673 JBGraphCell cell = null; 674 675 //Only add if not already present 676 if (!(registryObjectToCellMap.containsKey(ro))) { 677 678 // Create Vertex 679 cell = new JBGraphCell(ro, createIcon); 680 681 Map viewMap = new Hashtable(); 682 Map map; 683 684 map = GraphConstants.createMap(); 685 viewMap.put(cell, map); 686 687 GraphConstants.setBounds(map, bounds); 688 689 Object[] insert = new Object[] { cell }; 690 getModel().insert(insert, null, null, viewMap); 691 692 registryObjectToCellMap.put(ro, cell); 693 694 Component c = getCellRenderer(cell); 695 696 if (c instanceof JComponent) { 697 ((JComponent)c).setToolTipText(getToolTipText(ro)); 698 } 699 } 700 701 return cell; 702 } 703 704 /*** 705 * DOCUMENT ME! 706 * 707 * @param ro DOCUMENT ME! 708 * 709 * @return DOCUMENT ME! 710 */ 711 private String getToolTipText(RegistryObject ro) { 712 713 String toolTipText = null; 714 715 try { 716 717 String name = RegistryBrowser.getName(ro); 718 719 if (name != null && name.length() != 0) { 720 toolTipText += ("Name: " + name); 721 } 722 723 String desc = RegistryBrowser.getDescription(ro); 724 725 if (desc != null) { 726 toolTipText += ("\nDescription: " + desc); 727 } 728 } catch (JAXRException e) { 729 RegistryBrowser.displayError(e); 730 } 731 732 return toolTipText; 733 } 734 735 /*** 736 * DOCUMENT ME! 737 * 738 * @param sourceCell DOCUMENT ME! 739 * @param ro DOCUMENT ME! 740 * @param bounds DOCUMENT ME! 741 * @param relationshipName DOCUMENT ME! 742 * @param reverseDirection DOCUMENT ME! 743 * 744 * @return DOCUMENT ME! 745 */ 746 public JBGraphCell addRelatedObject(JBGraphCell sourceCell, 747 RegistryObject ro, 748 Rectangle bounds, 749 String relationshipName, 750 boolean reverseDirection) { 751 752 JBGraphCell targetCell = null; 753 754 //Only add if not already present 755 if (!(registryObjectToCellMap.containsKey(ro))) { 756 targetCell = addRegistryObject(ro, bounds, true); 757 758 if (!reverseDirection) { 759 connectCells(sourceCell, targetCell, relationshipName, 760 false); 761 } else { 762 connectCells(targetCell, sourceCell, relationshipName, 763 false); 764 } 765 } 766 767 return targetCell; 768 } 769 770 /*** 771 * DOCUMENT ME! 772 * 773 * @param sourceCell DOCUMENT ME! 774 * @param targetCell DOCUMENT ME! 775 * @param relationshipName DOCUMENT ME! 776 * @param reverseDirection DOCUMENT ME! 777 */ 778 public void connectCells(JBGraphCell sourceCell, 779 DefaultGraphCell targetCell, 780 String relationshipName, 781 boolean reverseDirection) { 782 783 //Create the edge between sourceCell and targetCell 784 Map aggregateStyle = GraphConstants.createMap(); 785 GraphConstants.setLineBegin(aggregateStyle, 786 GraphConstants.DIAMOND); 787 GraphConstants.setBeginFill(aggregateStyle, true); 788 GraphConstants.setBeginSize(aggregateStyle, 6); 789 GraphConstants.setLineEnd(aggregateStyle, GraphConstants.SIMPLE); 790 GraphConstants.setEndSize(aggregateStyle, 8); 791 792 //GraphConstants.setLabelPosition(aggregateStyle, new Point(500, 1200)); 793 GraphConstants.setFontSize(aggregateStyle, 10); 794 795 ConnectionSet cs = new ConnectionSet(); 796 Map viewAttributes = new Hashtable(); 797 798 DefaultEdge edge = new DefaultEdge(relationshipName); 799 800 if (!reverseDirection) { 801 cs.connect(edge, sourceCell.getChildAt(0), 802 targetCell.getChildAt(0)); 803 } else { 804 cs.connect(edge, targetCell.getChildAt(0), 805 sourceCell.getChildAt(0)); 806 } 807 808 viewAttributes.put(edge, aggregateStyle); 809 810 Object[] insert = new Object[] { edge }; 811 getModel().insert(insert, cs, null, viewAttributes); 812 } 813 814 /*** 815 * DOCUMENT ME! 816 * 817 * @param cell DOCUMENT ME! 818 * 819 * @return DOCUMENT ME! 820 */ 821 private Component getCellRenderer(GraphCell cell) { 822 823 GraphView graphView = getView(); 824 CellView cellView = graphView.getMapping(cell, true); 825 Component renderer = 826 cellView.getRendererComponent(this, false, false, false); 827 828 return renderer; 829 } 830 831 /*** 832 * DOCUMENT ME! 833 * 834 * @param cell DOCUMENT ME! 835 */ 836 void showRelatedObjects(JBGraphCell cell) { 837 RegistryBrowser.setWaitCursor(); 838 839 RegistryObject ro = cell.getRegistryObject(); 840 841 ArrayList relatedCells = showRelatedObjects(cell, ro); 842 843 ArrayList moreRelatedCells = null; 844 845 if (ro instanceof javax.xml.registry.infomodel.Organization) { 846 moreRelatedCells = 847 showRelatedObjects(cell, (Organization)ro); 848 } else if (ro instanceof javax.xml.registry.infomodel.Service) { 849 moreRelatedCells = showRelatedObjects(cell, (Service)ro); 850 } else if (ro instanceof javax.xml.registry.infomodel.ServiceBinding) { 851 moreRelatedCells = 852 showRelatedObjects(cell, (ServiceBinding)ro); 853 } else if (ro instanceof javax.xml.registry.infomodel.SpecificationLink) { 854 moreRelatedCells = 855 showRelatedObjects(cell, (SpecificationLink)ro); 856 } else if (ro instanceof javax.xml.registry.infomodel.User) { 857 moreRelatedCells = showRelatedObjects(cell, (User)ro); 858 } else if (ro instanceof javax.xml.registry.infomodel.Classification) { 859 moreRelatedCells = 860 showRelatedObjects(cell, (Classification)ro); 861 } else if (ro instanceof javax.xml.registry.infomodel.ExternalIdentifier) { 862 moreRelatedCells = 863 showRelatedObjects(cell, (ExternalIdentifier)ro); 864 } else if (ro instanceof javax.xml.registry.infomodel.ClassificationScheme) { 865 moreRelatedCells = 866 showRelatedObjects(cell, (ClassificationScheme)ro); 867 } else if (ro instanceof javax.xml.registry.infomodel.Concept) { 868 moreRelatedCells = showRelatedObjects(cell, (Concept)ro); 869 } 870 871 if (moreRelatedCells != null) { 872 relatedCells.addAll(moreRelatedCells); 873 } 874 875 System.err.println("relatedCells.size() = " 876 + relatedCells.size()); 877 circleLayout(this, cell, relatedCells); 878 RegistryBrowser.setDefaultCursor(); 879 } 880 881 /*** 882 * DOCUMENT ME! 883 * 884 * @param cell DOCUMENT ME! 885 */ 886 void browseObject(JBGraphCell cell) { 887 888 RegistryObject ro = cell.getRegistryObject(); 889 890 JBGraphPanel.browseObject((Window)(SwingUtilities.getRoot(this)), 891 ro, editable); 892 } 893 894 /*** 895 * DOCUMENT ME! 896 * 897 * @param cell DOCUMENT ME! 898 */ 899 public void retrieveItem(JBGraphCell cell) { 900 RegistryBrowser.retrieveItem(cell.getRegistryObject()); 901 } 902 903 /*** 904 * DOCUMENT ME! 905 * 906 * @param cell DOCUMENT ME! 907 */ 908 public void showAuditTrail(JBGraphCell cell) { 909 RegistryBrowser.showAuditTrail(cell.getRegistryObject()); 910 } 911 912 /*** 913 * DOCUMENT ME! 914 * 915 * @param objs DOCUMENT ME! 916 * 917 * @return DOCUMENT ME! 918 */ 919 private DefaultGraphCell createGroupFromObjectCollection(Collection objs) { 920 921 DefaultGraphCell groupCell = null; 922 923 if (objs != null) { 924 925 ArrayList groupedCells = new ArrayList(); 926 927 boolean createIcon = true; 928 int x = 50; 929 Iterator iter = objs.iterator(); 930 931 while (iter.hasNext()) { 932 933 RegistryObject ro = (RegistryObject)iter.next(); 934 935 //System.err.println("ro = " + ro.getName().getValue()); 936 //Use any existing cell for the ro or create new cell 937 JBGraphCell newCell = 938 (JBGraphCell)registryObjectToCellMap.get(ro); 939 940 if (newCell == null) { 941 newCell = 942 addRegistryObject(ro, 943 new Rectangle(0, x, 50, 50), 944 createIcon); 945 createIcon = false; 946 } 947 948 CellView newCellView = 949 getView().getMapping(newCell, false); 950 951 Rectangle bounds = newCellView.getBounds(); 952 x += (1.25 * bounds.height); 953 groupedCells.add(newCell); 954 } 955 956 if (groupedCells.size() > 0) { 957 groupCell = group(groupedCells.toArray()); 958 } 959 } 960 961 return groupCell; 962 } 963 964 /*** 965 * DOCUMENT ME! 966 * 967 * @param cell DOCUMENT ME! 968 * @param ro DOCUMENT ME! 969 * 970 * @return ArrayList of GraphCell for the related objects. 971 */ 972 private ArrayList showRelatedObjects(JBGraphCell cell, 973 RegistryObject ro) { 974 975 ArrayList relatedCells = new ArrayList(); 976 if (ro == null) { 977 return relatedCells; 978 } 979 980 try { 981 982 CellView cellView = getView().getMapping(cell, false); 983 Rectangle bounds = cellView.getBounds(); 984 985 //Classifications 986 Collection classifications = ro.getClassifications(); 987 DefaultGraphCell groupCell = 988 createGroupFromObjectCollection(classifications); 989 990 if (groupCell != null) { 991 connectCells(cell, groupCell, "classifications", false); 992 relatedCells.add(groupCell); 993 } 994 995 //ExternalIdentifiers 996 Collection extIds = ro.getExternalIdentifiers(); 997 groupCell = createGroupFromObjectCollection(extIds); 998 999 if (groupCell != null) { 1000 connectCells(cell, groupCell, "externalIdentifiers", 1001 false); 1002 relatedCells.add(groupCell); 1003 } 1004 1005 //ExternalLinks 1006 Collection extLinks = ro.getExternalLinks(); 1007 groupCell = createGroupFromObjectCollection(extLinks); 1008 1009 if (groupCell != null) { 1010 connectCells(cell, groupCell, "externalLinks", false); 1011 relatedCells.add(groupCell); 1012 } 1013 1014 /* 1015 //RegistryPackages 1016 try { 1017 Collection pkgs = ro.getRegistryPackages(); 1018 Iterator iter = pkgs.iterator(); 1019 while (iter.hasNext()) { 1020 RegistryPackage pkg = (RegistryPackage)iter.next(); 1021 if (pkg != null) { 1022 JBGraphCell newCell = addRelatedObject(cell, pkg, new Rectangle(0, 0, 50, 50), "HasMember", true); 1023 relatedCells.add(newCell); 1024 } 1025 } 1026 } catch (UnsupportedCapabilityException e) { 1027 } 1028 **/ 1029 1030 //Associations 1031 try { 1032 1033 Collection assocs = ro.getAssociations(); 1034 Iterator iter = assocs.iterator(); 1035 1036 while (iter.hasNext()) { 1037 1038 Association assoc = (Association)iter.next(); 1039 RegistryObject srcObj = assoc.getSourceObject(); 1040 RegistryObject targetObj = assoc.getTargetObject(); 1041 Concept concept = 1042 assoc.getAssociationType(); 1043 1044 String label = "associatedWith"; 1045 1046 if (concept != null) { 1047 label = concept.getValue(); 1048 } 1049 1050 if ((srcObj != null) && (targetObj != null)) { 1051 1052 JBGraphCell newCell = null; 1053 1054 if (srcObj.getKey().getId().equalsIgnoreCase(ro.getKey() 1055 .getId())) { 1056 1057 //ro is the source, newCell is the target 1058 newCell = 1059 addRelatedObject(cell, targetObj, 1060 new Rectangle(bounds.x 1061 + 100, 1062 bounds.y, 1063 50, 50), 1064 label, false); 1065 } else { 1066 1067 //ro is the target, newCell is the source 1068 newCell = 1069 addRelatedObject(cell, srcObj, 1070 new Rectangle(bounds.x 1071 + 100, 1072 bounds.y, 1073 50, 50), 1074 label, true); 1075 } 1076 1077 relatedCells.add(newCell); 1078 } else { 1079 System.err.println("Invalid association. Source or traget is null: " 1080 + assoc.getKey().getId()); 1081 } 1082 } 1083 } catch (UnsupportedCapabilityException e) { 1084 } 1085 } catch (JAXRException e) { 1086 RegistryBrowser.displayError(e); 1087 } 1088 1089 return relatedCells; 1090 } 1091 1092 /*** 1093 * DOCUMENT ME! 1094 * 1095 * @param cell DOCUMENT ME! 1096 * @param org DOCUMENT ME! 1097 * 1098 * @return DOCUMENT ME! 1099 */ 1100 private ArrayList showRelatedObjects(JBGraphCell cell, 1101 Organization org) { 1102 1103 ArrayList relatedCells = new ArrayList(); 1104 if (org == null) { 1105 return relatedCells; 1106 } 1107 1108 try { 1109 1110 //services 1111 Collection services = org.getServices(); 1112 DefaultGraphCell groupCell = 1113 createGroupFromObjectCollection(services); 1114 1115 if (groupCell != null) { 1116 connectCells(cell, groupCell, "services", false); 1117 relatedCells.add(groupCell); 1118 } 1119 1120 //parent Organization 1121 try { 1122 1123 Organization parentOrg = org.getParentOrganization(); 1124 1125 if (parentOrg != null) { 1126 1127 JBGraphCell newCell = 1128 addRelatedObject(cell, parentOrg, 1129 new Rectangle(0, 0, 50, 50), 1130 "parent Oragnization", false); 1131 relatedCells.add(newCell); 1132 } 1133 } catch (UnsupportedCapabilityException e) { 1134 } 1135 1136 //children Organizations 1137 try { 1138 1139 Collection children = org.getChildOrganizations(); 1140 groupCell = createGroupFromObjectCollection(children); 1141 1142 if (groupCell != null) { 1143 connectCells(cell, groupCell, 1144 "parent Organization", true); 1145 relatedCells.add(groupCell); 1146 } 1147 } catch (UnsupportedCapabilityException e) { 1148 } 1149 1150 //users 1151 Collection users = org.getUsers(); 1152 groupCell = createGroupFromObjectCollection(users); 1153 1154 if (groupCell != null) { 1155 connectCells(cell, groupCell, "users", false); 1156 relatedCells.add(groupCell); 1157 } 1158 1159 //Primary contact 1160 1161 /* 1162 User primContact = org.getPrimaryContact(); 1163 JBGraphCell primContactCell = (JBGraphCell)registryObjectToCellMap.get(primContact); 1164 if (primContactCell != null) { 1165 connectCells(cell, primContactCell, "primary contact", false); 1166 relatedCells.add(primContactCell); 1167 } 1168 */ 1169 } catch (JAXRException e) { 1170 RegistryBrowser.displayError(e); 1171 } 1172 1173 return relatedCells; 1174 } 1175 1176 /*** 1177 * DOCUMENT ME! 1178 * 1179 * @param cell DOCUMENT ME! 1180 * @param service DOCUMENT ME! 1181 * 1182 * @return DOCUMENT ME! 1183 */ 1184 private ArrayList showRelatedObjects(JBGraphCell cell, 1185 Service service) { 1186 1187 ArrayList relatedCells = new ArrayList(); 1188 if (service == null) { 1189 return relatedCells; 1190 } 1191 1192 try { 1193 1194 //bindings 1195 Collection bindings = service.getServiceBindings(); 1196 DefaultGraphCell groupCell = 1197 createGroupFromObjectCollection(bindings); 1198 1199 if (groupCell != null) { 1200 connectCells(cell, groupCell, "service bindings", false); 1201 relatedCells.add(groupCell); 1202 } 1203 1204 //parent Organization 1205 Organization parentOrg = service.getProvidingOrganization(); 1206 1207 if (parentOrg != null) { 1208 1209 JBGraphCell newCell = 1210 addRelatedObject(cell, parentOrg, 1211 new Rectangle(0, 0, 50, 50), 1212 "parent Oragnization", false); 1213 relatedCells.add(newCell); 1214 } 1215 } catch (JAXRException e) { 1216 RegistryBrowser.displayError(e); 1217 } 1218 1219 return relatedCells; 1220 } 1221 1222 /*** 1223 * DOCUMENT ME! 1224 * 1225 * @param cell DOCUMENT ME! 1226 * @param binding DOCUMENT ME! 1227 * 1228 * @return DOCUMENT ME! 1229 */ 1230 private ArrayList showRelatedObjects(JBGraphCell cell, 1231 ServiceBinding binding) { 1232 1233 ArrayList relatedCells = new ArrayList(); 1234 if (binding == null) { 1235 return relatedCells; 1236 } 1237 1238 try { 1239 1240 //specLinks 1241 Collection specLinks = binding.getSpecificationLinks(); 1242 System.err.println("Binding has " + specLinks.size() 1243 + " specLinks"); 1244 1245 DefaultGraphCell groupCell = 1246 createGroupFromObjectCollection(specLinks); 1247 1248 if (groupCell != null) { 1249 connectCells(cell, groupCell, "specification links", 1250 false); 1251 relatedCells.add(groupCell); 1252 } 1253 1254 //parent Service 1255 //Service parentService = binding.getService(); 1256 //JBGraphCell newCell = addRelatedObject(cell, parentService, new Rectangle(0, 0, 50, 50), "parent Service", false); 1257 //relatedCells.add(newCell); 1258 } catch (JAXRException e) { 1259 RegistryBrowser.displayError(e); 1260 } 1261 1262 return relatedCells; 1263 } 1264 1265 /*** 1266 * DOCUMENT ME! 1267 * 1268 * @param cell DOCUMENT ME! 1269 * @param specLink DOCUMENT ME! 1270 * 1271 * @return DOCUMENT ME! 1272 */ 1273 private ArrayList showRelatedObjects(JBGraphCell cell, 1274 SpecificationLink specLink) { 1275 1276 ArrayList relatedCells = new ArrayList(); 1277 if (specLink == null) { 1278 return relatedCells; 1279 } 1280 1281 try { 1282 1283 //specificationObject 1284 RegistryObject specObject = 1285 specLink.getSpecificationObject(); 1286 1287 if (specObject != null) { 1288 JBGraphCell newCell = 1289 addRelatedObject(cell, specObject, 1290 new Rectangle(0, 0, 50, 50), 1291 "specification object", false); 1292 relatedCells.add(newCell); 1293 1294 //parent Service 1295 //Service parentBinding = specLink.getServiceBinding(); 1296 //JBGraphCell newCell = addRelatedObject(cell, parentServiceBinding, new Rectangle(0, 0, 50, 50), "parent ServiceBinding", false); 1297 } 1298 } catch (JAXRException e) { 1299 RegistryBrowser.displayError(e); 1300 } 1301 1302 return relatedCells; 1303 } 1304 1305 /*** 1306 * DOCUMENT ME! 1307 * 1308 * @param cell DOCUMENT ME! 1309 * @param user DOCUMENT ME! 1310 * 1311 * @return DOCUMENT ME! 1312 */ 1313 private ArrayList showRelatedObjects(JBGraphCell cell, User user) { 1314 1315 ArrayList relatedCells = new ArrayList(); 1316 if (user == null) { 1317 return relatedCells; 1318 } 1319 1320 try { 1321 1322 //parent Organization 1323 Organization org = user.getOrganization(); 1324 if (org != null) { 1325 JBGraphCell newCell = 1326 addRelatedObject(cell, org, 1327 new Rectangle(0, 0, 50, 50), 1328 "affiliated with", false); 1329 relatedCells.add(newCell); 1330 } 1331 } catch (JAXRException e) { 1332 RegistryBrowser.displayError(e); 1333 } 1334 1335 return relatedCells; 1336 } 1337 1338 /*** 1339 * DOCUMENT ME! 1340 * 1341 * @param cell DOCUMENT ME! 1342 * @param classification DOCUMENT ME! 1343 * 1344 * @return DOCUMENT ME! 1345 */ 1346 private ArrayList showRelatedObjects(JBGraphCell cell, 1347 Classification classification) { 1348 1349 ArrayList relatedCells = new ArrayList(); 1350 if (classification == null) { 1351 return relatedCells; 1352 } 1353 1354 try { 1355 1356 //scheme 1357 ClassificationScheme scheme = 1358 classification.getClassificationScheme(); 1359 JBGraphCell newCell = 1360 addRelatedObject(cell, scheme, 1361 new Rectangle(0, 0, 50, 50), 1362 "classification scheme", false); 1363 relatedCells.add(newCell); 1364 1365 //Concept 1366 Concept concept = classification.getConcept(); 1367 1368 if (concept != null) { 1369 newCell = 1370 addRelatedObject(cell, concept, 1371 new Rectangle(0, 0, 50, 50), 1372 "value", false); 1373 relatedCells.add(newCell); 1374 } 1375 } catch (JAXRException e) { 1376 RegistryBrowser.displayError(e); 1377 } 1378 1379 return relatedCells; 1380 } 1381 1382 /*** 1383 * DOCUMENT ME! 1384 * 1385 * @param cell DOCUMENT ME! 1386 * @param externalIdentifier DOCUMENT ME! 1387 * 1388 * @return DOCUMENT ME! 1389 */ 1390 private ArrayList showRelatedObjects(JBGraphCell cell, 1391 ExternalIdentifier externalIdentifier) { 1392 1393 ArrayList relatedCells = new ArrayList(); 1394 if (externalIdentifier == null) { 1395 return relatedCells; 1396 } 1397 1398 try { 1399 1400 //scheme 1401 ClassificationScheme scheme = 1402 externalIdentifier.getIdentificationScheme(); 1403 JBGraphCell newCell = 1404 addRelatedObject(cell, scheme, 1405 new Rectangle(0, 0, 50, 50), 1406 "identification scheme", false); 1407 relatedCells.add(newCell); 1408 } catch (JAXRException e) { 1409 RegistryBrowser.displayError(e); 1410 } 1411 1412 return relatedCells; 1413 } 1414 1415 /*** 1416 * DOCUMENT ME! 1417 * 1418 * @param cell DOCUMENT ME! 1419 * @param scheme DOCUMENT ME! 1420 * 1421 * @return DOCUMENT ME! 1422 */ 1423 private ArrayList showRelatedObjects(JBGraphCell cell, 1424 ClassificationScheme scheme) { 1425 1426 ArrayList relatedCells = new ArrayList(); 1427 if (scheme == null) { 1428 return relatedCells; 1429 } 1430 1431 try { 1432 1433 //bindings 1434 Collection childConcepts = scheme.getChildrenConcepts(); 1435 DefaultGraphCell groupCell = 1436 createGroupFromObjectCollection(childConcepts); 1437 1438 if (groupCell != null) { 1439 connectCells(cell, groupCell, "child Concepts", false); 1440 relatedCells.add(groupCell); 1441 } 1442 } catch (JAXRException e) { 1443 RegistryBrowser.displayError(e); 1444 } 1445 1446 return relatedCells; 1447 } 1448 1449 /*** 1450 * DOCUMENT ME! 1451 * 1452 * @param cell DOCUMENT ME! 1453 * @param concept DOCUMENT ME! 1454 * 1455 * @return DOCUMENT ME! 1456 */ 1457 private ArrayList showRelatedObjects(JBGraphCell cell, 1458 Concept concept) { 1459 1460 ArrayList relatedCells = new ArrayList(); 1461 if (concept == null) { 1462 return relatedCells; 1463 } 1464 1465 try { 1466 1467 //parent Organization 1468 Concept parentConcept = concept.getParentConcept(); 1469 1470 if (parentConcept != null) { 1471 1472 JBGraphCell newCell = 1473 addRelatedObject(cell, parentConcept, 1474 new Rectangle(0, 0, 50, 50), 1475 "parent", false); 1476 relatedCells.add(newCell); 1477 } else { 1478 1479 ClassificationScheme scheme = 1480 concept.getClassificationScheme(); 1481 1482 if (scheme != null) { 1483 1484 JBGraphCell newCell = 1485 addRelatedObject(cell, scheme, 1486 new Rectangle(0, 0, 50, 50), 1487 "classification scheme", false); 1488 relatedCells.add(newCell); 1489 } 1490 } 1491 1492 //child Concepts 1493 Collection childConcepts = concept.getChildrenConcepts(); 1494 DefaultGraphCell groupCell = 1495 createGroupFromObjectCollection(childConcepts); 1496 1497 if (groupCell != null) { 1498 connectCells(cell, groupCell, "child Concepts", false); 1499 relatedCells.add(groupCell); 1500 } 1501 } catch (JAXRException e) { 1502 RegistryBrowser.displayError(e); 1503 } 1504 1505 return relatedCells; 1506 } 1507 1508 /*** 1509 * Create a RegistryObject based on teh current setting of 1510 * objectTypeCombo 1511 * 1512 * @return DOCUMENT ME! 1513 * 1514 * @throws JAXRException DOCUMENT ME! 1515 */ 1516 private RegistryObject createRegistryObject() throws JAXRException { 1517 1518 RegistryObject ro = null; 1519 1520 JAXRClient client = 1521 RegistryBrowser.getInstance().getClient(); 1522 BusinessLifeCycleManager lcm = 1523 client.getBusinessLifeCycleManager(); 1524 1525 String objectType = (objectTypeCombo.getSelectedItem()).toString(); 1526 1527 com.sun.xml.registry.ebxml.util.QueryUtil qu = com.sun.xml.registry.ebxml.util.QueryUtil.getInstance(); 1528 if (qu.getUnsupportedObjectTypes().contains(objectType)) { 1529 throw new JAXRException("Search not supported for: " + objectType); 1530 } 1531 1532 boolean isIntrinsic = com.sun.xml.registry.client.browser.BusinessQueryPanel.isIntrinsicObjectType(objectType); 1533 String newObjectType = objectType; 1534 1535 if (!isIntrinsic) { 1536 newObjectType = "ExtrinsicObject"; 1537 } 1538 1539 ro = (RegistryObject)(lcm.createObject(newObjectType)); 1540 1541 if (ro instanceof com.sun.xml.registry.ebxml.infomodel.ExtrinsicObjectImpl) { 1542 com.sun.xml.registry.ebxml.infomodel.ExtrinsicObjectImpl eo = 1543 (com.sun.xml.registry.ebxml.infomodel.ExtrinsicObjectImpl)ro; 1544 1545 //Need to convert to urn:uuid later 1546 eo.setObjectType(objectType); 1547 } 1548 1549 1550 return ro; 1551 } 1552 1553 1554 /*** 1555 * DOCUMENT ME! 1556 * 1557 * @return DOCUMENT ME! 1558 */ 1559 public JToolBar createToolBar() { 1560 1561 JButton button = null; 1562 JToolBar toolbar = new JToolBar(); 1563 toolbar.setFloatable(false); 1564 1565 com.sun.xml.registry.client.browser.ConceptsTreeModel objectTypesTreeModel = com.sun.xml.registry.client.browser.BusinessQueryPanel.getObjectTypesTreeModel(); 1566 objectTypeCombo = new com.sun.xml.registry.client.browser.TreeCombo(objectTypesTreeModel); 1567 toolbar.add(objectTypeCombo); 1568 1569 // Insert 1570 URL insertUrl = 1571 getClass().getClassLoader().getResource("icons/insert.gif"); 1572 ImageIcon insertIcon = new ImageIcon(insertUrl); 1573 button = 1574 toolbar.add(new AbstractAction("", insertIcon) { 1575 public void actionPerformed(ActionEvent e) { 1576 insert(new Point(10, 10)); 1577 } 1578 }); 1579 button.setText(""); //an icon-only button 1580 button.setToolTipText("Insert"); 1581 1582 // Toggle Connect Mode 1583 URL connectUrl = 1584 getClass().getClassLoader().getResource("icons/connecton.gif"); 1585 ImageIcon connectIcon = new ImageIcon(connectUrl); 1586 button = 1587 toolbar.add(new AbstractAction("", connectIcon) { 1588 public void actionPerformed(ActionEvent e) { 1589 setPortsVisible(!isPortsVisible()); 1590 1591 URL connectUrl; 1592 1593 if (isPortsVisible()) { 1594 connectUrl = 1595 getClass() 1596 .getClassLoader() 1597 .getResource("icons/connecton.gif"); 1598 } else { 1599 connectUrl = 1600 getClass() 1601 .getClassLoader() 1602 .getResource("icons/connectoff.gif"); 1603 } 1604 1605 ImageIcon connectIcon = 1606 new ImageIcon(connectUrl); 1607 putValue(SMALL_ICON, connectIcon); 1608 } 1609 }); 1610 button.setText(""); //an icon-only button 1611 button.setToolTipText("Toggle Connect Mode"); 1612 1613 // Undo 1614 toolbar.addSeparator(); 1615 1616 URL undoUrl = 1617 getClass().getClassLoader().getResource("icons/undo.gif"); 1618 ImageIcon undoIcon = new ImageIcon(undoUrl); 1619 undo = 1620 new AbstractAction("", undoIcon) { 1621 public void actionPerformed(ActionEvent e) { 1622 undo(); 1623 } 1624 }; 1625 undo.setEnabled(false); 1626 button = toolbar.add(undo); 1627 button.setText(""); //an icon-only button 1628 button.setToolTipText("Undo"); 1629 1630 // Redo 1631 URL redoUrl = 1632 getClass().getClassLoader().getResource("icons/redo.gif"); 1633 ImageIcon redoIcon = new ImageIcon(redoUrl); 1634 redo = 1635 new AbstractAction("", redoIcon) { 1636 public void actionPerformed(ActionEvent e) { 1637 redo(); 1638 } 1639 }; 1640 redo.setEnabled(false); 1641 button = toolbar.add(redo); 1642 button.setText(""); //an icon-only button 1643 button.setToolTipText("Redo"); 1644 1645 // 1646 // Edit Block 1647 // 1648 toolbar.addSeparator(); 1649 1650 Action action; 1651 URL url; 1652 1653 // Copy 1654 action = TransferHandler.getCopyAction(); 1655 url = getClass().getClassLoader().getResource("icons/copy.gif"); 1656 action.putValue(Action.SMALL_ICON, new ImageIcon(url)); 1657 //Commented out until we can figure out how to assign new id to copied objects 1658 //button = toolbar.add(copy = new EventRedirector(action)); 1659 button.setText(""); //an icon-only button 1660 button.setToolTipText("Copy"); 1661 1662 // Paste 1663 action = TransferHandler.getPasteAction(); 1664 url = getClass().getClassLoader().getResource("icons/paste.gif"); 1665 action.putValue(Action.SMALL_ICON, new ImageIcon(url)); 1666 //Commented out until we can figure out how to assign new id to copied objects 1667 //button = toolbar.add(paste = new EventRedirector(action)); 1668 button.setText(""); //an icon-only button 1669 button.setToolTipText("Paste"); 1670 1671 // Cut 1672 action = TransferHandler.getCutAction(); 1673 url = getClass().getClassLoader().getResource("icons/cut.gif"); 1674 action.putValue(Action.SMALL_ICON, new ImageIcon(url)); 1675 //Commented out until we can figure out how to assign new id to copied objects 1676 //button = toolbar.add(cut = new EventRedirector(action)); 1677 button.setText(""); //an icon-only button 1678 button.setToolTipText("Cut"); 1679 1680 // Remove 1681 URL removeUrl = 1682 getClass().getClassLoader().getResource("icons/delete.gif"); 1683 ImageIcon removeIcon = new ImageIcon(removeUrl); 1684 remove = 1685 new AbstractAction("", removeIcon) { 1686 public void actionPerformed(ActionEvent e) { 1687 1688 if (!isSelectionEmpty()) { 1689 1690 Object[] cells = getSelectionCells(); 1691 cells = getDescendants(cells); 1692 getModel().remove(cells); 1693 1694 //Remove entry from map of cells on the graph 1695 for (int i = 0; i < cells.length; i++) { 1696 1697 Object cell = cells[i]; 1698 1699 if (cell instanceof JBGraphCell) { 1700 1701 RegistryObject ro = 1702 ((JBGraphCell)cell) 1703 .getRegistryObject(); 1704 registryObjectToCellMap.remove(ro); 1705 } 1706 } 1707 } 1708 } 1709 }; 1710 remove.setEnabled(false); 1711 button = toolbar.add(remove); 1712 button.setText(""); //an icon-only button 1713 button.setToolTipText("Remove"); 1714 1715 // Zoom Std 1716 toolbar.addSeparator(); 1717 1718 URL zoomUrl = 1719 getClass().getClassLoader().getResource("icons/zoom.gif"); 1720 ImageIcon zoomIcon = new ImageIcon(zoomUrl); 1721 button = 1722 toolbar.add(new AbstractAction("", zoomIcon) { 1723 public void actionPerformed(ActionEvent e) { 1724 setScale(1.0); 1725 } 1726 }); 1727 button.setText(""); //an icon-only button 1728 button.setToolTipText("Zoom"); 1729 1730 // Zoom In 1731 URL zoomInUrl = 1732 getClass().getClassLoader().getResource("icons/zoomin.gif"); 1733 ImageIcon zoomInIcon = new ImageIcon(zoomInUrl); 1734 button = 1735 toolbar.add(new AbstractAction("", zoomInIcon) { 1736 public void actionPerformed(ActionEvent e) { 1737 setScale(2 * getScale()); 1738 } 1739 }); 1740 button.setText(""); //an icon-only button 1741 button.setToolTipText("Zoom In"); 1742 1743 // Zoom Out 1744 URL zoomOutUrl = 1745 getClass().getClassLoader().getResource("icons/zoomout.gif"); 1746 ImageIcon zoomOutIcon = new ImageIcon(zoomOutUrl); 1747 button = 1748 toolbar.add(new AbstractAction("", zoomOutIcon) { 1749 public void actionPerformed(ActionEvent e) { 1750 setScale(getScale() / 2); 1751 } 1752 }); 1753 button.setText(""); //an icon-only button 1754 button.setToolTipText("Zoom Out"); 1755 1756 // Group 1757 /* 1758 toolbar.addSeparator(); 1759 1760 URL groupUrl = 1761 getClass().getClassLoader().getResource("icons/group.gif"); 1762 ImageIcon groupIcon = new ImageIcon(groupUrl); 1763 group = 1764 new AbstractAction("", groupIcon) { 1765 public void actionPerformed(ActionEvent e) { 1766 group(getSelectionCells()); 1767 } 1768 }; 1769 group.setEnabled(false); 1770 //button = toolbar.add(group); 1771 button.setText(""); //an icon-only button 1772 button.setToolTipText("Group"); 1773 1774 // Ungroup 1775 URL ungroupUrl = 1776 getClass().getClassLoader().getResource("icons/ungroup.gif"); 1777 ImageIcon ungroupIcon = new ImageIcon(ungroupUrl); 1778 ungroup = 1779 new AbstractAction("", ungroupIcon) { 1780 public void actionPerformed(ActionEvent e) { 1781 ungroup(getSelectionCells()); 1782 } 1783 }; 1784 ungroup.setEnabled(false); 1785 //button = toolbar.add(ungroup); 1786 button.setText(""); //an icon-only button 1787 button.setToolTipText("Ungroup"); 1788 */ 1789 1790 // To Front 1791 toolbar.addSeparator(); 1792 1793 URL toFrontUrl = 1794 getClass().getClassLoader().getResource("icons/tofront.gif"); 1795 ImageIcon toFrontIcon = new ImageIcon(toFrontUrl); 1796 tofront = 1797 new AbstractAction("", toFrontIcon) { 1798 public void actionPerformed(ActionEvent e) { 1799 1800 if (!isSelectionEmpty()) { 1801 toFront(getSelectionCells()); 1802 } 1803 } 1804 }; 1805 tofront.setEnabled(false); 1806 button = toolbar.add(tofront); 1807 button.setText(""); //an icon-only button 1808 button.setToolTipText("To Front"); 1809 1810 // To Back 1811 URL toBackUrl = 1812 getClass().getClassLoader().getResource("icons/toback.gif"); 1813 ImageIcon toBackIcon = new ImageIcon(toBackUrl); 1814 toback = 1815 new AbstractAction("", toBackIcon) { 1816 public void actionPerformed(ActionEvent e) { 1817 1818 if (!isSelectionEmpty()) { 1819 toBack(getSelectionCells()); 1820 } 1821 } 1822 }; 1823 toback.setEnabled(false); 1824 button = toolbar.add(toback); 1825 button.setText(""); //an icon-only button 1826 button.setToolTipText("To Back"); 1827 1828 return toolbar; 1829 } 1830 1831 /*** 1832 * DOCUMENT ME! 1833 * 1834 * @return DOCUMENT ME! 1835 */ 1836 public JToolBar getToolBar() { 1837 1838 return toolBar; 1839 } 1840 1841 /*** 1842 * DOCUMENT ME! 1843 * 1844 * @param cell DOCUMENT ME! 1845 */ 1846 void editCell(JBGraphCell cell) { 1847 1848 RegistryObject ro = cell.getRegistryObject(); 1849 1850 if (ro != null) { 1851 JBEditorDialog.showObjectDetails(this, ro, false, editable); 1852 } 1853 } 1854 1855 /*** 1856 * DOCUMENT ME! 1857 * 1858 * @param graph DOCUMENT ME! 1859 */ 1860 public static void circleLayout(JGraph graph) { 1861 1862 Object[] selectedCells = graph.getSelectionCells(); 1863 1864 if (selectedCells.length > 1) { 1865 1866 GraphCell hubCell = (GraphCell)selectedCells[0]; 1867 1868 ArrayList spokeCells = new ArrayList(); 1869 1870 for (int i = 1; i < selectedCells.length; i++) { 1871 spokeCells.add(selectedCells[i]); 1872 } 1873 1874 circleLayout(graph, hubCell, spokeCells); 1875 } 1876 } 1877 1878 /*** 1879 * Given a graph, a hub vertex in a graph and a list of spoke 1880 * vertices in teh graph this will modify the location of the 1881 * spokes so that they are laid out in a circle around the hub 1882 * started with first spoke at an angle of 135 degrees (left of 1883 * V). 1884 * 1885 * @param graph DOCUMENT ME! 1886 * @param hubCell DOCUMENT ME! 1887 * @param spokeCells DOCUMENT ME! 1888 */ 1889 public static void circleLayout(JGraph graph, GraphCell hubCell, 1890 ArrayList spokeCells) { 1891 1892 if (spokeCells.size() == 0) { 1893 1894 return; 1895 } 1896 1897 GraphView graphView = graph.getView(); 1898 CellView hubCellView = graphView.getMapping(hubCell, true); 1899 1900 // Maximum width or height 1901 int max = 0; 1902 Rectangle bounds = hubCellView.getBounds(); 1903 1904 // Update Maximum 1905 if (bounds != null) { 1906 max = Math.max(Math.max(bounds.width, bounds.height), max); 1907 } 1908 1909 //Now get the spokeCellViews 1910 ArrayList spokeCellViews = new ArrayList(); 1911 1912 Iterator iter = spokeCells.iterator(); 1913 1914 while (iter.hasNext()) { 1915 1916 GraphCell spokeCell = (GraphCell)iter.next(); 1917 CellView spokeCellView = 1918 graphView.getMapping(spokeCell, true); 1919 1920 if (spokeCellView != null) { 1921 spokeCellViews.add(spokeCellView); 1922 } else { 1923 System.err.println("Null spokeCellView for spokeCell: " 1924 + spokeCell); 1925 } 1926 1927 // Fetch Bounds 1928 //bounds = spokeCellView.getBounds(); 1929 // Update Maximum 1930 //if (bounds != null) 1931 // max = Math.max(Math.max(bounds.width, bounds.height), max); 1932 } 1933 1934 Rectangle hubBounds = hubCellView.getBounds(); 1935 1936 // Compute Radius 1937 int r = 1938 (int)Math.max(((spokeCellViews.size()) * max) / Math.PI, 100); 1939 1940 //System.err.println("Origin=" + hubBounds.getLocation() + " radius = " + r); 1941 //Set max radius to 250 pixels. 1942 if (r > 250) { 1943 r = 250; 1944 } 1945 1946 // Compute step angle in radians 1947 double stepAngle = 1948 Math.toRadians(360.0 / ((double)(spokeCellViews.size()))); 1949 1950 //System.err.println("cellCount=" + spokeCellViews.size() + " stepAngle= " + stepAngle); 1951 //angle from hub to a spoke. 1952 double theta = Math.toRadians(90.0); 1953 1954 if ((spokeCells.size() % 2) == 0) { 1955 theta = Math.toRadians(135.0); 1956 } 1957 1958 // Arrange spokes in a circle around hub. 1959 iter = spokeCellViews.iterator(); 1960 1961 while (iter.hasNext()) { 1962 1963 VertexView spokeCellView = (VertexView)iter.next(); 1964 DefaultGraphCell spokeCell = 1965 (DefaultGraphCell)spokeCellView.getCell(); 1966 Rectangle spokeBounds = spokeCellView.getBounds(); 1967 1968 //System.err.println("Cell=" + spokeCell.getUserObject() + " theta= " + theta); 1969 // Update Location 1970 if (spokeBounds != null) { 1971 1972 int x = 1973 (hubBounds.x + (int)(r * Math.cos(theta))) 1974 - (int)((spokeBounds.width) / 2.0); 1975 int y = 1976 hubBounds.y - (int)(r * Math.sin(theta)) 1977 - (int)((spokeBounds.height) / 2.0); 1978 1979 translate(spokeCellView, x - spokeBounds.x, 1980 y - spokeBounds.y); 1981 1982 //spokeBounds.setLocation(x, y); 1983 //System.err.println("X=" + x + " Y=" + y); 1984 } 1985 1986 theta -= stepAngle; 1987 } 1988 } 1989 1990 //Workaround for bug in JGraph where a group does not move 1991 //by setLocation 1992 private static void translate(CellView view, int dx, int dy) { 1993 1994 if (view.isLeaf()) { 1995 GraphConstants.translate(view.getAttributes(), dx, dy); 1996 } else { 1997 1998 CellView[] childViews = view.getChildViews(); 1999 2000 for (int i = 0; i < childViews.length; i++) { 2001 translate(childViews[i], dx, dy); 2002 } 2003 } 2004 } 2005 2006 public JBGraphCell getJBGraphCellAt(DefaultGraphCell parent, int x, int y) { 2007 JBGraphCell jbCell = null; 2008 2009 java.util.List children = parent.getChildren(); 2010 if (children != null) { 2011 Iterator iter = children.iterator(); 2012 while (iter.hasNext()) { 2013 Object obj = iter.next(); 2014 if (obj instanceof JBGraphCell) { 2015 JBGraphCell _jbCell = (JBGraphCell)obj; 2016 Rectangle bounds = getCellBounds(_jbCell); 2017 if (bounds.contains(x, y)) { 2018 jbCell = _jbCell; 2019 break; 2020 } 2021 } 2022 } 2023 } 2024 2025 return jbCell; 2026 } 2027 2028 // This will change the source of the actionevent to graph. 2029 protected class EventRedirector extends AbstractAction { 2030 2031 /*** DOCUMENT ME! */ 2032 protected Action action; 2033 2034 // Construct the "Wrapper" Action 2035 public EventRedirector(Action a) { 2036 super("", (ImageIcon)a.getValue(Action.SMALL_ICON)); 2037 this.action = a; 2038 } 2039 2040 // Redirect the Actionevent 2041 public void actionPerformed(ActionEvent e) { 2042 e = new ActionEvent(JBGraph.this, e.getID(), 2043 e.getActionCommand(), e.getModifiers()); 2044 action.actionPerformed(e); 2045 } 2046 } 2047 2048 /*** 2049 * Sets whether this dialog is read-only or editable. 2050 */ 2051 public void setEditable(boolean editable) { 2052 this.editable = editable; 2053 } 2054 2055 /*** 2056 * Tells whether this dialog is read-only or editable. 2057 */ 2058 public boolean isEditable() { 2059 return editable; 2060 } 2061 2062 }

This page was automatically generated by Maven