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 java.awt.Paint;
15
16 import com.google.common.base.Function;
17
18 import edu.uci.ics.jung.visualization.picking.PickedInfo;
19
20 /**
21 * Paints each vertex according to the <code>Paint</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 PickableVertexPaintTransformer<V> implements Function<V,Paint> {
26
27 protected Paint fill_paint;
28 protected Paint picked_paint;
29 protected PickedInfo<V> pi;
30
31 /**
32 *
33 * @param pi specifies which vertices report as "picked"
34 * @param fill_paint <code>Paint</code> used to fill vertex shapes
35 * @param picked_paint <code>Paint</code> used to fill picked vertex shapes
36 */
37 public PickableVertexPaintTransformer(PickedInfo<V> pi,
38 Paint fill_paint, Paint picked_paint)
39 {
40 if (pi == null)
41 throw new IllegalArgumentException("PickedInfo instance must be non-null");
42 this.pi = pi;
43 this.fill_paint = fill_paint;
44 this.picked_paint = picked_paint;
45 }
46
47 public Paint apply(V v)
48 {
49 if (pi.isPicked(v))
50 return picked_paint;
51 else
52 return fill_paint;
53 }
54
55 }