1 /*
2 * Copyright (c) 2003, The JUNG Authors
3 *
4 * All rights reserved.
5 *
6 * This software is open-source under the BSD license; see either
7 * "license.txt" or
8 * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
9 */
10 /*
11 * Created on Mar 19, 2005
12 *
13 */
14 package edu.uci.ics.jung.visualization.picking;
15
16 import edu.uci.ics.jung.algorithms.layout.GraphElementAccessor;
17 import edu.uci.ics.jung.algorithms.layout.Layout;
18 import edu.uci.ics.jung.algorithms.layout.RadiusGraphElementAccessor;
19
20
21
22 /**
23 * Simple implementation of PickSupport that returns the vertex or edge
24 * that is closest to the specified location. This implementation
25 * provides the same picking options that were available in
26 * previous versions of AbstractLayout.
27 *
28 * @author Tom Nelson
29 * @author Joshua O'Madadhain
30 */
31 public class RadiusPickSupport<V, E>
32 extends RadiusGraphElementAccessor<V, E> implements GraphElementAccessor<V,E> {
33
34 public RadiusPickSupport() {
35 this(Math.sqrt(Double.MAX_VALUE - 1000));
36 }
37
38 /**
39 * Creates an instance with the specified maximum distance.
40 * @param maxDistance the farthest that a vertex can be from the selection point
41 * and still be 'picked'
42 */
43 public RadiusPickSupport(double maxDistance) {
44 super(maxDistance);
45 }
46
47 /**
48 * Gets the vertex nearest to the location of the (x,y) location selected,
49 * within a distance of <tt>maxDistance</tt>. Iterates through all
50 * visible vertices and checks their distance from the click. Override this
51 * method to provide a more efficient implementation.
52 */
53 public V getVertex(Layout<V,E> layout, double x, double y) {
54 return getVertex(layout, x, y, this.maxDistance);
55 }
56
57 /**
58 * Gets the vertex nearest to the location of the (x,y) location selected,
59 * within a distance of <tt>maxDistance</tt>. Iterates through all
60 * visible vertices and checks their distance from the click. Override this
61 * method to provide a more efficient implementation.
62 * @param layout the layout instance that records the positions for all vertices
63 * @param x the x coordinate of the pick point
64 * @param y the y coordinate of the pick point
65 * @param maxDistance vertices whose from (x, y) is > this cannot be returned
66 * @return the vertex whose center is closest to the pick point (x, y)
67 */
68 public V getVertex(Layout<V,E> layout, double x, double y, double maxDistance) {
69 return super.getVertex(layout, x, y, maxDistance);
70 }
71
72 /**
73 * Gets the edge nearest to the location of the (x,y) location selected.
74 * Calls the longer form of the call.
75 * @param layout the layout instance that records the positions for all vertices
76 * @param x the x coordinate of the pick point
77 * @param y the y coordinate of the pick point
78 * @return the vertex whose center is closest to the pick point (x, y)
79 */
80 public E getEdge(Layout<V,E> layout, double x, double y) {
81 return getEdge(layout, x, y, this.maxDistance);
82 }
83
84 /**
85 * Gets the edge nearest to the location of the (x,y) location selected,
86 * within a distance of <tt>maxDistance</tt>, Iterates through all
87 * visible edges and checks their distance from the click. Override this
88 * method to provide a more efficient implementation.
89 *
90 * @param x the x coordinate of the pick point
91 * @param y the y coordinate of the pick point
92 * @param maxDistance vertices whose from (x, y) is > this cannot be returned
93 * @return Edge closest to the click.
94 */
95 public E getEdge(Layout<V,E> layout, double x, double y, double maxDistance) {
96 return super.getEdge(layout, x, y, maxDistance);
97 }
98 }