1 /*
2 * Created on Mar 10, 2005
3 *
4 * Copyright (c) 2005, The JUNG Authors
5 *
6 * All rights reserved.
7 *
8 * This software is open-source under the BSD license; see either
9 * "license.txt" or
10 * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
11 */
12 package edu.uci.ics.jung.visualization.decorators;
13
14 import javax.swing.Icon;
15
16 import com.google.common.base.Function;
17
18 import edu.uci.ics.jung.visualization.picking.PickedInfo;
19
20 /**
21 * Supplies an Icon for each vertex according to the <code>Icon</code>
22 * parameters given in the constructor, so that picked and
23 * non-picked vertices can be made to look different.
24 */
25 public class PickableVertexIconTransformer<V> implements Function<V,Icon> {
26
27 protected Icon icon;
28 protected Icon picked_icon;
29 protected PickedInfo<V> pi;
30
31 /**
32 *
33 * @param pi specifies which vertices report as "picked"
34 * @param icon <code>Icon</code> used to represent vertices
35 * @param picked_icon <code>Icon</code> used to represent picked vertices
36 */
37 public PickableVertexIconTransformer(PickedInfo<V> pi, Icon icon, Icon picked_icon)
38 {
39 if (pi == null)
40 throw new IllegalArgumentException("PickedInfo instance must be non-null");
41 this.pi = pi;
42 this.icon = icon;
43 this.picked_icon = picked_icon;
44 }
45
46 /**
47 * Returns the appropriate <code>Icon</code>, depending on picked state.
48 */
49 public Icon apply(V v) {
50 if (pi.isPicked(v))
51 return picked_icon;
52 else
53 return icon;
54 }
55 }