1 /* 2 * TouchGraph LLC. Apache-Style Software License 3 * 4 * 5 * Copyright (c) 2001-2002 Alexander Shapiro. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * 19 * 3. The end-user documentation included with the redistribution, 20 * if any, must include the following acknowledgment: 21 * "This product includes software developed by 22 * TouchGraph LLC (http://www.touchgraph.com/)." 23 * Alternately, this acknowledgment may appear in the software itself, 24 * if and wherever such third-party acknowledgments normally appear. 25 * 26 * 4. The names "TouchGraph" or "TouchGraph LLC" must not be used to endorse 27 * or promote products derived from this software without prior written 28 * permission. For written permission, please contact 29 * alex@touchgraph.com 30 * 31 * 5. Products derived from this software may not be called "TouchGraph", 32 * nor may "TouchGraph" appear in their name, without prior written 33 * permission of alex@touchgraph.com. 34 * 35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 38 * DISCLAIMED. IN NO EVENT SHALL TOUCHGRAPH OR ITS CONTRIBUTORS BE 39 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 43 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 44 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 * ==================================================================== 47 * 48 */ 49 50 package com.touchgraph.graphlayout.interaction; 51 52 import java.awt.*; 53 import java.awt.event.MouseEvent; 54 55 import com.touchgraph.graphlayout.*; 56 57 /*** DragMultiselectUI contains code for selecting a group on nodes 58 * by enclosing them in a dotted box. 59 * 60 * @author Alexander Shapiro 61 * @version 1.21 $Id: DragMultiselectUI.java,v 1.1.1.1 2004/02/06 08:44:07 keesj Exp $ 62 */ 63 public class DragMultiselectUI extends TGAbstractDragUI implements TGPaintListener { 64 65 TGPoint2D mousePos=null; 66 TGPoint2D startPos = null; 67 68 DragMultiselectUI( TGPanel tgp ) { 69 super(tgp); 70 } 71 72 public void preActivate() { 73 startPos = null; 74 mousePos = null; 75 tgPanel.addPaintListener(this); 76 } 77 78 public void preDeactivate() { 79 tgPanel.removePaintListener(this); 80 tgPanel.repaint(); 81 }; 82 83 84 public void mousePressed(MouseEvent e) { 85 startPos = new TGPoint2D(e.getX(), e.getY()); 86 mousePos = new TGPoint2D(startPos); 87 } 88 89 90 public void mouseReleased(MouseEvent e) {} 91 92 public void mouseDragged(MouseEvent e) { 93 mousePos.setLocation(e.getX(), e.getY()); 94 tgPanel.multiSelect(startPos,mousePos); 95 tgPanel.repaint(); 96 } 97 98 99 100 public void paintFirst(Graphics g) {}; 101 public void paintAfterEdges(Graphics g) {}; 102 103 public void paintLast(Graphics g) { 104 105 if(mousePos==null) return; 106 107 g.setColor(Color.black); 108 109 int x,y,w,h; 110 111 if (startPos.x<mousePos.x) { 112 x=(int) startPos.x; 113 w=(int) (mousePos.x-startPos.x); 114 } 115 else { 116 x=(int) mousePos.x; 117 w=(int) (startPos.x-mousePos.x); 118 } 119 120 if (startPos.y<mousePos.y) { 121 y=(int) startPos.y; 122 h=(int) (mousePos.y-startPos.y); 123 } 124 else { 125 y=(int) mousePos.y; 126 h=(int) (startPos.y-mousePos.y); 127 } 128 129 //God, where are the line styles when you need them 130 for(int horiz = x;horiz<x+w;horiz+=2){ 131 g.drawLine(horiz,y,horiz,y); //Drawing lines because there is no way 132 g.drawLine(horiz,y+h,horiz,y+h); //to draw a single pixel. 133 } 134 for(int vert = y;vert<y+h;vert+=2){ 135 g.drawLine(x,vert,x,vert); 136 g.drawLine(x+w,vert,x+w,vert); 137 } 138 139 } 140 141 } // end