| Line | Hits | Source |
|---|---|---|
| 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.event.MouseEvent; | |
| 15 | import java.awt.event.MouseWheelEvent; | |
| 16 | import java.awt.event.MouseWheelListener; | |
| 17 | ||
| 18 | import edu.uci.ics.jung.visualization.VisualizationViewer; | |
| 19 | import edu.uci.ics.jung.visualization.transform.LensTransformer; | |
| 20 | import edu.uci.ics.jung.visualization.transform.MutableTransformer; | |
| 21 | ||
| 22 | /** | |
| 23 | * HyperbolicMagnificationGraphMousePlugin changes the magnification | |
| 24 | * within the Hyperbolic projection of the HyperbolicTransformer. | |
| 25 | * | |
| 26 | * @author Tom Nelson | |
| 27 | */ | |
| 28 | public class LensMagnificationGraphMousePlugin extends AbstractGraphMousePlugin | |
| 29 | implements MouseWheelListener { | |
| 30 | ||
| 31 | 0 | protected float floor = .5f; |
| 32 | ||
| 33 | 0 | protected float ceiling = .9f; |
| 34 | ||
| 35 | 0 | protected float delta = .02f; |
| 36 | ||
| 37 | /** | |
| 38 | * create an instance with default zoom in/out values | |
| 39 | */ | |
| 40 | public LensMagnificationGraphMousePlugin() { | |
| 41 | 0 | this(MouseEvent.CTRL_MASK); |
| 42 | 0 | } |
| 43 | ||
| 44 | /** | |
| 45 | * create an instance with passed modifiers | |
| 46 | * @param modifiers | |
| 47 | */ | |
| 48 | public LensMagnificationGraphMousePlugin(float floor, float ceiling, float delta) { | |
| 49 | 0 | this(MouseEvent.CTRL_MASK, floor, ceiling, delta); |
| 50 | 0 | } |
| 51 | ||
| 52 | public LensMagnificationGraphMousePlugin(int modifiers) { | |
| 53 | 0 | this(modifiers, .5f, .9f, .02f); |
| 54 | 0 | } |
| 55 | public LensMagnificationGraphMousePlugin(int modifiers, float floor, float ceiling, float delta) { | |
| 56 | 0 | super(modifiers); |
| 57 | 0 | this.floor = floor; |
| 58 | 0 | this.ceiling = ceiling; |
| 59 | 0 | this.delta = delta; |
| 60 | 0 | } |
| 61 | /** | |
| 62 | * override to check equality with a mask | |
| 63 | */ | |
| 64 | public boolean checkModifiers(MouseEvent e) { | |
| 65 | 0 | return (e.getModifiers() & modifiers) != 0; |
| 66 | } | |
| 67 | ||
| 68 | private void changeMagnification(MutableTransformer transformer, float delta) { | |
| 69 | 0 | if(transformer instanceof LensTransformer) { |
| 70 | 0 | LensTransformer ht = (LensTransformer)transformer; |
| 71 | 0 | float magnification = ht.getMagnification() + delta; |
| 72 | 0 | magnification = Math.max(floor, magnification); |
| 73 | 0 | magnification = Math.min(magnification, ceiling); |
| 74 | 0 | ht.setMagnification(magnification); |
| 75 | } | |
| 76 | 0 | } |
| 77 | /** | |
| 78 | * zoom the display in or out, depending on the direction of the | |
| 79 | * mouse wheel motion. | |
| 80 | */ | |
| 81 | public void mouseWheelMoved(MouseWheelEvent e) { | |
| 82 | 0 | boolean accepted = checkModifiers(e); |
| 83 | 0 | float delta = this.delta; |
| 84 | 0 | if(accepted == true) { |
| 85 | 0 | VisualizationViewer vv = (VisualizationViewer)e.getSource(); |
| 86 | 0 | MutableTransformer modelTransformer = vv.getLayoutTransformer(); |
| 87 | 0 | MutableTransformer viewTransformer = vv.getViewTransformer(); |
| 88 | 0 | int amount = e.getWheelRotation(); |
| 89 | 0 | if(amount < 0) { |
| 90 | 0 | delta = -delta; |
| 91 | } | |
| 92 | 0 | changeMagnification(modelTransformer, delta); |
| 93 | 0 | changeMagnification(viewTransformer, delta); |
| 94 | 0 | vv.repaint(); |
| 95 | 0 | e.consume(); |
| 96 | } | |
| 97 | 0 | } |
| 98 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |