View Javadoc
1 /*** 2 * MyGrappaAdapter.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 9 * Copyright 2003 ELCA Informatique SA 10 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 11 * www.elca.ch 12 * 13 * This library is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU Lesser General Public License 15 * as published by the Free Software Foundation; either version 2.1 of 16 * the License, or (at your option) any later version. 17 * 18 * This library is distributed in the hope that it will be useful, but 19 * WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 * Lesser General Public License for more details. 22 * 23 * You should have received a copy of the GNU Lesser General Public 24 * License along with this library; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 26 * USA 27 */ 28 29 package ch.elca.dependency.view; 30 31 import att.grappa.*; 32 import ch.elca.dependency.core.Selection; 33 import ch.elca.dependency.gui.DependencyDetails; 34 import java.awt.Color; 35 import java.awt.Graphics2D; 36 import java.awt.event.ActionEvent; 37 import java.awt.event.ActionListener; 38 import java.awt.event.InputEvent; 39 import java.awt.geom.AffineTransform; 40 import java.awt.geom.Rectangle2D; 41 import java.awt.print.PageFormat; 42 import java.awt.print.PrinterJob; 43 import java.util.*; 44 import javax.swing.JFrame; 45 import javax.swing.JOptionPane; 46 import org.apache.log4j.Category; 47 48 /*** 49 * A GrappaAdapter for the <code>att.grappa.GrappaPanel</code> class. 50 * 51 * @author Christoph Trutmann 52 * @version 1.0-beta 53 */ 54 public class MyGrappaAdapter implements GrappaConstants, GrappaListener, ActionListener { 55 56 /*** 57 * Log4j category to invoke the log statements. 58 */ 59 private static final Category CAT = Category.getInstance(MyGrappaAdapter.class); 60 61 /*** 62 * Specifies whether it is possible to drag a node to a new position.<br> 63 * By default it is diabled. 64 */ 65 private boolean m_dragEnabled = false; 66 67 /*** 68 * <code>Selection</code> interface. 69 */ 70 private Selection m_select; 71 72 /*** 73 * <code>DependencyDetail</code> interface. 74 */ 75 private DependencyDetails m_detail; 76 77 /*** 78 * Zoom factor for zoom in. Default is 0.5. 79 */ 80 private double m_positiveZoomFact = 0.5d; 81 82 /*** 83 * Zoom factor for zoom out. Default is 0.5. 84 */ 85 private double m_negativeZoomFact = 0.333d; 86 87 /*** 88 * References the <code>Selection</code> interface for notify the other 89 * views about changing selections. And also the 90 * <code>DependencyDetails</code> interface for showing additional 91 * dependency information for an arbitrary edge. 92 * 93 * @param select Selection interface. 94 */ 95 public void reference(Selection select, DependencyDetails detail){ 96 m_select = select; 97 m_detail = detail; 98 } 99 100 /*** 101 * Sets the zoom factor for the zoom out / in. 102 * 103 * @param fact Zoom factor. 104 */ 105 public void setZoomFactor(double positive, double negative) { 106 m_positiveZoomFact = positive; 107 m_negativeZoomFact = negative; 108 } 109 110 111 /*** 112 * The method called when a mouse click occurs on a displayed subgraph. 113 * 114 * @param subg displayed subgraph where action occurred 115 * @param elem subgraph element in which action occurred 116 * @param pt the point where the action occurred (graph coordinates) 117 * @param modifiers mouse modifiers in effect 118 * @param clickCount count of mouse clicks that triggered this action 119 * @param panel specific panel where the action occurred 120 */ 121 public void grappaClicked(Subgraph subg, Element elem, GrappaPoint pt, 122 int modifiers, int clickCount, GrappaPanel panel) { 123 124 // disable selecting a subgraph 125 // 126 if ( elem instanceof Subgraph ) { 127 clearSelection(panel, subg); 128 return; 129 } 130 131 if((modifiers&InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { 132 if(clickCount == 1) { 133 134 // disable edge selection 135 // 136 if ( elem instanceof Edge ) { 137 clearSelection(panel, subg); 138 return; 139 } 140 141 // looks like Java has a single click occur on the way to a 142 // multiple click, so this code always executes (which is 143 // not necessarily a bad thing) 144 // 145 if(subg.getGraph().isSelectable()) { 146 if(modifiers == InputEvent.BUTTON1_MASK) { 147 // select element 148 if(elem == null) { 149 clearSelection(panel, subg); 150 } else { 151 if(subg.currentSelection != null) { 152 // if the element is selected yet 153 if(subg.currentSelection == elem) return; 154 // if an element is not selected yet 155 if(subg.currentSelection instanceof Element) { 156 ((Element)(subg.currentSelection)) 157 .highlight &= ~HIGHLIGHT_MASK; 158 } else { 159 Vector vec = ((Vector)(subg.currentSelection)); 160 for(int i = 0; i < vec.size(); i++) { 161 ((Element)(vec.elementAt(i))).highlight &= ~HIGHLIGHT_MASK; 162 } 163 } 164 subg.currentSelection = null; 165 } 166 elem.highlight |= SELECTION_MASK; 167 subg.currentSelection = elem; 168 169 // this code is added by ctr 170 // 171 if ( subg.currentSelection instanceof Node ) { 172 Node nodeTmp = (Node)subg.currentSelection; 173 174 // notify the selection model 175 ArrayList list = new ArrayList(); 176 list.add(nodeTmp.getName()); 177 m_select.selectPackages(list); 178 179 // select all the outgoing edges 180 Enumeration outEdgeEnum = nodeTmp.outEdgeElements(); 181 boolean firstRun = true; 182 Vector vect = null; 183 while ( outEdgeEnum.hasMoreElements() ) { 184 if ( firstRun ) { 185 vect = new Vector(); 186 vect.add(subg.currentSelection); 187 firstRun = false; 188 } 189 190 Edge edgeTmp = (Edge)outEdgeEnum.nextElement(); 191 edgeTmp.highlight |= SELECTION_MASK; 192 vect.add(edgeTmp); 193 } 194 if ( vect != null ) { 195 subg.currentSelection = vect; 196 } 197 } 198 // 199 // until here 200 201 subg.getGraph().repaint(); 202 panel.repaint(); 203 } 204 205 // added by ctr 206 // 207 } else if ( modifiers == (InputEvent.BUTTON1_MASK|InputEvent.ALT_MASK) ) { 208 // select element 209 if(elem == null) { 210 if(subg.currentSelection != null) { 211 if(subg.currentSelection instanceof Element) { 212 ((Element)(subg.currentSelection)) 213 .highlight &= ~HIGHLIGHT_MASK; 214 } else { 215 Vector vec 216 = ((Vector)(subg.currentSelection)); 217 for(int i = 0; i < vec.size(); i++) { 218 ((Element)(vec.elementAt(i))) 219 .highlight &= ~HIGHLIGHT_MASK; 220 } 221 } 222 subg.currentSelection = null; 223 subg.getGraph().repaint(); 224 panel.repaint(); 225 } 226 } else { 227 if(subg.currentSelection != null) { 228 // if the element is selected yet 229 if(subg.currentSelection == elem) return; 230 // if an element is not selected yet 231 if(subg.currentSelection instanceof Element) { 232 ((Element)(subg.currentSelection)) 233 .highlight &= ~HIGHLIGHT_MASK; 234 } else { 235 Vector vec = ((Vector)(subg.currentSelection)); 236 for(int i = 0; i < vec.size(); i++) { 237 ((Element)(vec.elementAt(i))).highlight &= ~HIGHLIGHT_MASK; 238 } 239 } 240 subg.currentSelection = null; 241 } 242 elem.highlight |= SELECTION_MASK; 243 subg.currentSelection = elem; 244 245 if ( subg.currentSelection instanceof Node ) { 246 Node nodeTmp = (Node)subg.currentSelection; 247 248 // notify the selection model 249 ArrayList list = new ArrayList(); 250 list.add(nodeTmp.getName()); 251 m_select.selectPackages(list); 252 253 // select all the outgoing edges 254 Enumeration inEdgeEnum = nodeTmp.inEdgeElements(); 255 boolean firstRun = true; 256 Vector vect = null; 257 while ( inEdgeEnum.hasMoreElements() ) { 258 if ( firstRun ) { 259 vect = new Vector(); 260 vect.add(subg.currentSelection); 261 firstRun = false; 262 } 263 264 Edge edgeTmp = (Edge)inEdgeEnum.nextElement(); 265 edgeTmp.highlight |= SELECTION_MASK; 266 vect.add(edgeTmp); 267 } 268 if ( vect != null ) { 269 subg.currentSelection = vect; 270 } 271 } 272 subg.getGraph().repaint(); 273 panel.repaint(); 274 } 275 } 276 } 277 // executed within each double click 278 } else if ( clickCount == 2 ){ 279 // if the double click occured on a edge element 280 if ( elem instanceof Edge ) { 281 m_detail.showDetails((Edge)elem); 282 } 283 } 284 else { 285 // multiple clicks 286 // this code executes for each click beyond the second 287 //System.err.println("clickCount="+clickCount); 288 } 289 } 290 } 291 292 /*** 293 * The method called when a mouse press occurs on a displayed subgraph. 294 * 295 * @param subg displayed subgraph where action occurred 296 * @param elem subgraph element in which action occurred 297 * @param pt the point where the action occurred (graph coordinates) 298 * @param modifiers mouse modifiers in effect 299 * @param panel specific panel where the action occurred 300 */ 301 public void grappaPressed(Subgraph subg, Element elem, GrappaPoint pt, int modifiers, GrappaPanel panel) { 302 if((modifiers&(InputEvent.BUTTON2_MASK|InputEvent.BUTTON3_MASK)) != 0 && (modifiers&(InputEvent.BUTTON2_MASK|InputEvent.BUTTON3_MASK)) == modifiers) { 303 // pop-up menu if button2 or button3 304 javax.swing.JPopupMenu popup = new javax.swing.JPopupMenu(); 305 javax.swing.JMenuItem item = null; 306 307 popup.add(item = new javax.swing.JMenuItem("Print")); 308 item.addActionListener(this); 309 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("print.gif")); 310 popup.addSeparator(); 311 if(subg.currentSelection != null) { 312 popup.add(item = new javax.swing.JMenuItem("Clear Selection")); 313 item.addActionListener(this); 314 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("null.png")); 315 popup.addSeparator(); 316 popup.add(item = new javax.swing.JMenuItem("Preview Delete")); 317 item.addActionListener(this); 318 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("null.png")); 319 popup.add(item = new javax.swing.JMenuItem("Cancel Preview")); 320 item.addActionListener(this); 321 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("undo.gif")); 322 popup.add(item = new javax.swing.JMenuItem("Delete Selection")); 323 item.addActionListener(this); 324 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("delete.gif")); 325 popup.addSeparator(); 326 } 327 if(panel.hasOutline()) { 328 popup.add(item = new javax.swing.JMenuItem("Zoom to Sweep")); 329 item.addActionListener(this); 330 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("null.png")); 331 } 332 popup.add(item = new javax.swing.JMenuItem("Zoom In")); 333 item.addActionListener(this); 334 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("zoomIn.gif")); 335 popup.add(item = new javax.swing.JMenuItem("Zoom Out")); 336 item.addActionListener(this); 337 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("zoomOut.gif")); 338 popup.add(item = new javax.swing.JMenuItem("Reset Zoom")); 339 item.setIcon(ch.elca.dependency.util.IconGrabber.getIcon("null.png")); 340 item.addActionListener(this); 341 if(subg.hasEmptySubgraphs()) { 342 popup.addSeparator(); 343 popup.add(item = new javax.swing.JMenuItem("Remove Empty Subgraphs")); 344 item.addActionListener(this); 345 } 346 347 java.awt.geom.Point2D mpt = panel.getTransform().transform(pt,null); 348 popup.show(panel,(int)mpt.getX(),(int)mpt.getY()); 349 } 350 } 351 352 /*** 353 * The method called when a mouse release occurs on a displayed subgraph. 354 * 355 * @param subg displayed subgraph where action occurred 356 * @param elem subgraph element in which action occurred 357 * @param pt the point where the action occurred (graph coordinates) 358 * @param modifiers mouse modifiers in effect 359 * @param pressedElem subgraph element in which the most recent mouse press occurred 360 * @param pressedPt the point where the most recent mouse press occurred (graph coordinates) 361 * @param pressedModifiers mouse modifiers in effect when the most recent mouse press occurred 362 * @param outline enclosing box specification from the previous drag position (for XOR reset purposes) 363 * @param panel specific panel where the action occurred 364 */ 365 public void grappaReleased(Subgraph subg, Element elem, GrappaPoint pt, int modifiers, 366 Element pressedElem, GrappaPoint pressedPt, int pressedModifiers, 367 GrappaBox outline, GrappaPanel panel) { 368 369 panel.repaint(); 370 } 371 372 /*** 373 * The method called when a mouse drag occurs on a displayed subgraph. 374 * 375 * @param subg displayed subgraph where action occurred 376 * @param currentPt the current drag point 377 * @param currentModifiers the current drag mouse modifiers 378 * @param pressedElem subgraph element in which the most recent mouse press occurred 379 * @param pressedPt the point where the most recent mouse press occurred (graph coordinates) 380 * @param pressedModifiers mouse modifiers in effect when the most recent mouse press occurred 381 * @param outline enclosing box specification from the previous drag position (for XOR reset purposes) 382 * @param panel specific panel where the action occurred 383 */ 384 public void grappaDragged(Subgraph subg, GrappaPoint currentPt, int currentModifiers, 385 Element pressedElem, GrappaPoint pressedPt, int pressedModifiers, 386 GrappaBox outline, GrappaPanel panel) { 387 388 if((currentModifiers&InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { 389 if(currentModifiers == InputEvent.BUTTON1_MASK || currentModifiers == (InputEvent.BUTTON1_MASK|InputEvent.CTRL_MASK)) { 390 391 // draging on a node 392 if ( (pressedElem instanceof Node) && m_dragEnabled ){ 393 // change position of the node 394 Node nodeTmp = (Node)pressedElem; 395 nodeTmp.setAttribute(GrappaConstants.POS_ATTR, currentPt); 396 397 // attach the edge to the moved node 398 Enumeration inEdgeEnum = nodeTmp.inEdgeElements(); 399 Enumeration outEdgeEnum = nodeTmp.outEdgeElements(); 400 GrappaPoint centerPoint = nodeTmp.getCenterPoint(); 401 402 // set head of in edges to the center of the moved node 403 while ( inEdgeEnum.hasMoreElements() ) { 404 Edge edgeTmp = (Edge)inEdgeEnum.nextElement(); 405 406 GrappaPoint[] points = new GrappaPoint[2]; 407 points[0] = currentPt; 408 points[1] = new GrappaPoint(edgeTmp.getTail() 409 .getAttribute("pos").getStringValue()); 410 411 edgeTmp.setAttribute( 412 GrappaConstants.POS_ATTR, 413 new GrappaLine(points, GrappaLine.HEAD_ARROW_EDGE)); 414 } 415 416 // set tail of out edges to the center of the moved node 417 while ( outEdgeEnum.hasMoreElements() ) { 418 Edge edgeTmp = (Edge)outEdgeEnum.nextElement(); 419 420 GrappaPoint[] points = new GrappaPoint[2]; 421 points[0] = new GrappaPoint(edgeTmp.getHead() 422 .getAttribute("pos").getStringValue()); 423 points[1] = currentPt; 424 425 edgeTmp.setAttribute( 426 GrappaConstants.POS_ATTR, 427 new GrappaLine(points, GrappaLine.HEAD_ARROW_EDGE)); 428 } 429 430 // this can surely be handled much nicer!!! 431 subg.getGraph().repaint(); 432 panel.repaint(); 433 } 434 // dragging beside a node (on the panel | edge) 435 else { 436 Graphics2D g2d = (Graphics2D)(panel.getGraphics()); 437 AffineTransform orig = g2d.getTransform(); 438 g2d.setTransform(panel.getTransform()); 439 g2d.setXORMode(Color.darkGray); 440 if(outline != null) { 441 g2d.draw(outline); 442 } 443 GrappaBox box = GrappaSupport.boxFromCorners(pressedPt.x, pressedPt.y, currentPt.x, currentPt.y); 444 g2d.draw(box); 445 g2d.setPaintMode(); 446 g2d.setTransform(orig); 447 } 448 } 449 } 450 } 451 452 /*** 453 * The method called when a element tooltip is needed. 454 * 455 * @param subg displayed subgraph where action occurred 456 * @param elem subgraph element in which action occurred 457 * @param pt the point where the action occurred (graph coordinates) 458 * @param modifiers mouse modifiers in effect 459 * @param panel specific panel where the action occurred 460 * 461 * @return the tip to be displayed or null; in this implementation, 462 * if the mouse is in a graph element that 463 * has its <I>tip</I> attribute defined, then that text is returned. 464 * If that attribute is not set, the element name is returned. 465 * If the mouse is outside the graph bounds, then the text supplied 466 * to the graph setToolTipText method is supplied. 467 */ 468 public String grappaTip(Subgraph subg, Element elem, GrappaPoint pt, int modifiers, GrappaPanel panel) { 469 String tip = null; 470 471 if(elem == null) { 472 if((tip = panel.getToolTipText()) == null) { 473 if((tip = subg.getGraph().getToolTipText()) == null) { 474 tip = Grappa.getToolTipText(); 475 } 476 } 477 } else { 478 switch(elem.getType()) { 479 case SUBGRAPH: 480 Subgraph sg = (Subgraph)elem; 481 if((tip = (String)sg.getAttributeValue(TIP_ATTR)) == null) { 482 if(subg.getShowSubgraphLabels()) { 483 tip = sg.getName(); 484 } else { 485 if((tip = (String)sg.getAttributeValue(LABEL_ATTR)) == null) { 486 tip = sg.getName(); 487 } 488 } 489 tip = "Subgraph: " + tip; 490 } 491 break; 492 case EDGE: 493 Edge edge = (Edge)elem; 494 if((tip = (String)edge.getAttributeValue(TIP_ATTR)) == null) { 495 if(subg.getShowEdgeLabels()) { 496 tip = edge.toString(); 497 } else { 498 if((tip = (String)edge.getAttributeValue(LABEL_ATTR)) == null) { 499 tip = edge.toString(); 500 } 501 } 502 tip = "Edge: " + tip; 503 } 504 break; 505 case NODE: 506 Node node = (Node)elem; 507 if((tip = (String)node.getAttributeValue(TIP_ATTR)) == null) { 508 if(subg.getShowNodeLabels()) { 509 tip = node.getName(); 510 } else { 511 if((tip = (String)node.getAttributeValue(LABEL_ATTR)) == null || tip.equals("//N")) { 512 tip = node.getName(); 513 } 514 } 515 tip = "Node: " + tip; 516 } 517 break; 518 default: 519 throw new RuntimeException("unexpected type (" + elem.getType() + ")"); 520 } 521 } 522 523 return(tip); 524 } 525 526 /////////////////////////////////////////////////////////////////////////// 527 // 528 // ActionListener 529 // 530 /////////////////////////////////////////////////////////////////////////// 531 532 /*** 533 * Invoked when an action occurs. 534 * 535 * @param aev the action event trigger. 536 */ 537 public void actionPerformed(ActionEvent aev) { 538 Object src = aev.getSource(); 539 if(src instanceof javax.swing.JMenuItem) { 540 Object parent = ((javax.swing.JMenuItem)src).getParent(); 541 if(parent instanceof javax.swing.JPopupMenu) { 542 Object invoker = ((javax.swing.JPopupMenu)(((javax.swing.JMenuItem)src).getParent())).getInvoker(); 543 if(invoker instanceof GrappaPanel) { 544 GrappaPanel gp = (GrappaPanel)invoker; 545 Subgraph subg = gp.getSubgraph(); 546 String text = ((javax.swing.JMenuItem)src).getText(); 547 // cancel the deletion preview 548 if(text.startsWith("Cancel")) { 549 if(subg.currentSelection == null) return; 550 if(subg.currentSelection instanceof Element) { 551 GrappaSupport.setHighlight((Element)(subg.currentSelection), DELETION_MASK, HIGHLIGHT_OFF); 552 } else { 553 Vector vec = (Vector)(subg.currentSelection); 554 for(int i = 0; i < vec.size(); i++) { 555 GrappaSupport.setHighlight((Element)(vec.elementAt(i)), DELETION_MASK, HIGHLIGHT_OFF); 556 } 557 } 558 subg.getGraph().repaint(); 559 gp.repaint(); // added by ctr 560 } 561 // clear the selection 562 else if(text.startsWith("Clear")) { 563 clearSelection(gp, subg); 564 gp.repaint(); 565 } 566 // enable dragging a node to an other position 567 else if( text.startsWith("Enable") ) { 568 m_dragEnabled = true; 569 } 570 // disable dragging a node to an other position 571 else if ( text.startsWith("Disable") ) { 572 m_dragEnabled = false; 573 } 574 // preview the deletion 575 else if(text.startsWith("Preview")) { 576 if(subg.currentSelection == null) return; 577 if(subg.currentSelection instanceof Element) { 578 GrappaSupport.setHighlight((Element)(subg.currentSelection), DELETION_MASK, HIGHLIGHT_ON); 579 } else { 580 Vector vec = (Vector)(subg.currentSelection); 581 for(int i = 0; i < vec.size(); i++) { 582 GrappaSupport.setHighlight((Element)(vec.elementAt(i)), DELETION_MASK, HIGHLIGHT_ON); 583 } 584 } 585 subg.getGraph().repaint(); 586 gp.repaint(); // added by ctr 587 } 588 // perform the deletion 589 else if(text.startsWith("Delete")) { 590 if(subg.currentSelection == null) return; 591 592 int result = JOptionPane.showConfirmDialog(new JFrame() 593 ,"Do you really want to delete selected nodes?", 594 "Delete nodes", 595 JOptionPane.YES_NO_OPTION); 596 597 if (result == JOptionPane.NO_OPTION) { 598 return; 599 } 600 601 if(subg.currentSelection instanceof Element) { 602 ((Element)(subg.currentSelection)).delete(); 603 } else { 604 Vector vec = (Vector)(subg.currentSelection); 605 for(int i = 0; i < vec.size(); i++) { 606 ((Element)(vec.elementAt(i))).delete(); 607 } 608 } 609 610 subg.currentSelection = null; 611 m_select.clearSelection(); 612 subg.getGraph().repaint(); 613 gp.repaint(); 614 } 615 // remove all the empty subgraphs 616 else if(text.startsWith("Remove")) { 617 subg.removeEmptySubgraphs(); 618 } 619 // reset the zoom 620 else if(text.startsWith("Reset")) { 621 gp.resetZoom(); 622 gp.clearOutline(); 623 } 624 // print the whole graph 625 else if(text.startsWith("Print")) { 626 PageFormat pf = new PageFormat(); 627 Rectangle2D bb = subg.getBoundingBox(); 628 if(bb.getWidth() > bb.getHeight()) 629 pf.setOrientation(PageFormat.LANDSCAPE); 630 try { 631 PrinterJob printJob = PrinterJob.getPrinterJob(); 632 printJob.setPrintable(gp, pf); 633 if (printJob.printDialog()) { 634 printJob.print(); 635 } 636 } catch (Exception ex) { 637 Grappa.displayException(ex, "Problem with print request"); 638 } 639 } 640 // tool tips on | off 641 else if(text.startsWith("ToolTips")) { 642 if(text.indexOf("Off") > 0) { 643 gp.setToolTipText(null); 644 } else { 645 String tip = subg.getGraph().getToolTipText(); 646 if(tip == null) { 647 tip = Grappa.getToolTipText(); 648 } 649 gp.setToolTipText(tip); 650 } 651 } 652 // zoom in 653 else if(text.startsWith("Zoom In")) { 654 gp.multiplyScaleFactor(1d + m_positiveZoomFact); 655 gp.clearOutline(); 656 } 657 // zoom out 658 else if(text.startsWith("Zoom Out")) { 659 gp.multiplyScaleFactor(1d - m_negativeZoomFact); 660 gp.clearOutline(); 661 } 662 // zoom to sweep 663 else if(text.startsWith("Zoom to")) { 664 //if(subg.currentSelection == null) return; 665 gp.zoomToOutline(); 666 gp.clearOutline(); 667 } 668 } 669 } 670 } 671 } 672 673 /////////////////////////////////////////////////////////////////////////// 674 675 private void drillDown(Subgraph subg, Vector elems, int mode, int setting) { 676 // clear old selection 677 m_select.clearSelection(); 678 679 Object obj = null; 680 for(int i = 0; i < elems.size(); i++) { 681 obj = elems.elementAt(i); 682 if(obj instanceof Vector) { 683 drillDown(subg, (Vector)obj, mode, setting); 684 } else { 685 // do not allow edge selection 686 if ( obj instanceof Edge ) { 687 continue; 688 } 689 690 GrappaSupport.setHighlight(((Element)obj), mode, setting); 691 switch(setting) { 692 case HIGHLIGHT_TOGGLE: 693 if((((Element)obj).highlight&mode) == mode) { 694 if(subg.currentSelection == null) { 695 subg.currentSelection = obj; 696 } else if(subg.currentSelection instanceof Element) { 697 Object crnt = subg.currentSelection; 698 subg.currentSelection = new Vector(); 699 ((Vector)(subg.currentSelection)).add(crnt); 700 ((Vector)(subg.currentSelection)).add(obj); 701 } else { 702 ((Vector)(subg.currentSelection)).add(obj); 703 } 704 } else { 705 if(subg.currentSelection == obj) { 706 subg.currentSelection = null; 707 } else if(subg.currentSelection instanceof Vector) { 708 ((Vector)(subg.currentSelection)).remove(obj); 709 } 710 } 711 break; 712 case HIGHLIGHT_ON: 713 if(subg.currentSelection == null) { 714 subg.currentSelection = obj; 715 } else if(subg.currentSelection instanceof Element) { 716 Object crnt = subg.currentSelection; 717 subg.currentSelection = new Vector(); 718 ((Vector)(subg.currentSelection)).add(crnt); 719 ((Vector)(subg.currentSelection)).add(obj); 720 } else { 721 ((Vector)(subg.currentSelection)).add(obj); 722 } 723 break; 724 case HIGHLIGHT_OFF: 725 if(subg.currentSelection != null) { 726 if(subg.currentSelection == obj) { 727 subg.currentSelection = null; 728 } else if(subg.currentSelection instanceof Vector) { 729 ((Vector)(subg.currentSelection)).remove(obj); 730 } 731 } 732 break; 733 } 734 } 735 } 736 } 737 738 /*** 739 * Clears all the selections in all the views. 740 */ 741 public void clearSelection(GrappaPanel panel, Subgraph subg){ 742 if (subg.currentSelection == null) { 743 return; 744 } 745 if(subg.currentSelection instanceof Element) { 746 GrappaSupport.setHighlight((Element)(subg.currentSelection), 0, HIGHLIGHT_OFF); 747 } else if (subg.currentSelection instanceof Vector) { 748 Vector vec = (Vector)(subg.currentSelection); 749 for(int i = 0; i < vec.size(); i++) { 750 GrappaSupport.setHighlight((Element)(vec.elementAt(i)), 0, HIGHLIGHT_OFF); 751 } 752 } 753 subg.currentSelection = null; 754 subg.getGraph().repaint(); 755 panel.repaint(); 756 m_select.clearSelection(); 757 } 758 }

This page was automatically generated by Maven