Coverage details for edu.uci.ics.jung.visualization.control.ShearingGraphMousePlugin

LineHitsSource
1 /*
2  * Copyright (c) 2005, the JUNG Project and the Regents of the University
3  * of California
4  * All rights reserved.
5  *
6  * This software is open-source under the BSD license; see either
7  * "license.txt" or
8  * http://jung.sourceforge.net/license.txt for a description.
9  * Created on Mar 8, 2005
10  *
11  */
12 package edu.uci.ics.jung.visualization.control;
13  
14 import java.awt.BasicStroke;
15 import java.awt.Color;
16 import java.awt.Cursor;
17 import java.awt.Dimension;
18 import java.awt.Graphics;
19 import java.awt.Graphics2D;
20 import java.awt.Point;
21 import java.awt.RenderingHints;
22 import java.awt.Toolkit;
23 import java.awt.event.MouseEvent;
24 import java.awt.event.MouseListener;
25 import java.awt.event.MouseMotionListener;
26 import java.awt.geom.Point2D;
27 import java.awt.image.BufferedImage;
28 import java.util.Collections;
29  
30 import edu.uci.ics.jung.visualization.VisualizationViewer;
31 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
32  
33 /**
34  * ShearingGraphMousePlugin allows the user to drag with the mouse
35  * to shear the transform either in the horizontal or vertical direction.
36  * By default, the control or meta key must be depressed to activate
37  * shearing.
38  *
39  *
40  * @author Tom Nelson
41  */
42 public class ShearingGraphMousePlugin extends AbstractGraphMousePlugin
43     implements MouseListener, MouseMotionListener {
44  
450    private static int mask = MouseEvent.CTRL_MASK;
46     
47     static {
480        if(System.getProperty("os.name").startsWith("Mac")) {
490            mask = MouseEvent.META_MASK;
50         }
510    }
52     /**
53      * create an instance with default modifier values
54      */
55     public ShearingGraphMousePlugin() {
560        this(MouseEvent.BUTTON1_MASK | mask);
570    }
58  
59     /**
60      * create an instance with passed modifier values
61      * @param modifiers the mouse modifiers to use
62      */
63     public ShearingGraphMousePlugin(int modifiers) {
640        super(modifiers);
650        Dimension cd = Toolkit.getDefaultToolkit().getBestCursorSize(16,16);
660        BufferedImage cursorImage =
67                 new BufferedImage(cd.width,cd.height,BufferedImage.TYPE_INT_ARGB);
680        Graphics g = cursorImage.createGraphics();
690        Graphics2D g2 = (Graphics2D)g;
700        g2.addRenderingHints(Collections.singletonMap(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
710        g.setColor(new Color(0,0,0,0));
720        g.fillRect(0,0,16,16);
73         
740        int left = 0;
750        int top = 0;
760        int right = 15;
770        int bottom = 15;
78         
79 // g.setColor(Color.white);
80 // g2.setStroke(new BasicStroke(3));
81 // g.drawLine(left+2,top+5,right-2,top+5);
82 // g.drawLine(left+2,bottom-5,right-2,bottom-5);
83 // g.drawLine(left+2,top+5,left+4,top+3);
84 // g.drawLine(left+2,top+5,left+4,top+7);
85 // g.drawLine(right-2,bottom-5,right-4,bottom-3);
86 // g.drawLine(right-2,bottom-5,right-4,bottom-7);
87  
880        g.setColor(Color.black);
890        g2.setStroke(new BasicStroke(1));
900        g.drawLine(left+2,top+5,right-2,top+5);
910        g.drawLine(left+2,bottom-5,right-2,bottom-5);
920        g.drawLine(left+2,top+5,left+4,top+3);
930        g.drawLine(left+2,top+5,left+4,top+7);
940        g.drawLine(right-2,bottom-5,right-4,bottom-3);
950        g.drawLine(right-2,bottom-5,right-4,bottom-7);
960        g.dispose();
970        cursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(), "RotateCursor");
98  
990    }
100  
101     /**
102      *
103      * @param e the event
104      */
105     public void mousePressed(MouseEvent e) {
1060        VisualizationViewer vv = (VisualizationViewer)e.getSource();
1070        boolean accepted = checkModifiers(e);
1080        down = e.getPoint();
1090        if(accepted) {
1100            vv.setCursor(cursor);
111         }
1120    }
113     
114     /**
115      *
116      */
117     public void mouseReleased(MouseEvent e) {
1180        VisualizationViewer vv = (VisualizationViewer)e.getSource();
1190        down = null;
1200        vv.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1210    }
122     
123     /**
124      *
125      *
126      *
127      *
128      */
129     public void mouseDragged(MouseEvent e) {
1300        if(down == null) return;
1310        VisualizationViewer vv = (VisualizationViewer)e.getSource();
1320        boolean accepted = checkModifiers(e);
1330        if(accepted) {
1340            MutableTransformer modelTransformer = vv.getLayoutTransformer();
1350            vv.setCursor(cursor);
1360            Point2D q = down;
1370            Point2D p = e.getPoint();
1380            float dx = (float) (p.getX()-q.getX());
1390            float dy = (float) (p.getY()-q.getY());
140  
1410            Dimension d = vv.getSize();
1420            float shx = 2.f*dx/d.height;
1430            float shy = 2.f*dy/d.width;
1440            Point2D center = vv.getCenter();
1450            if(p.getX() < center.getX()) {
1460                shy = -shy;
147             }
1480            if(p.getY() < center.getY()) {
1490                shx = -shx;
150             }
1510            modelTransformer.shear(shx, shy, center);
1520            down.x = e.getX();
1530            down.y = e.getY();
154         
1550            e.consume();
156         }
1570    }
158  
159     public void mouseClicked(MouseEvent e) {
160         // TODO Auto-generated method stub
161         
1620    }
163  
164     public void mouseEntered(MouseEvent e) {
165         // TODO Auto-generated method stub
166         
1670    }
168  
169     public void mouseExited(MouseEvent e) {
170         // TODO Auto-generated method stub
171         
1720    }
173  
174     public void mouseMoved(MouseEvent e) {
175         // TODO Auto-generated method stub
176         
1770    }
178 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.