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 edge according to the <code>Paint</code>
22 * parameters given in the constructor, so that picked and
23 * non-picked edges can be made to look different.
24 *
25 * @author Tom Nelson
26 * @author Joshua O'Madadhain
27 *
28 */
29 public class PickableEdgePaintTransformer<E> implements Function<E,Paint> {
30 protected PickedInfo<E> pi;
31 protected Paint draw_paint;
32 protected Paint picked_paint;
33
34 /**
35 *
36 * @param pi specifies which vertices report as "picked"
37 * @param draw_paint <code>Paint</code> used to draw edge shapes
38 * @param picked_paint <code>Paint</code> used to draw picked edge shapes
39 */
40 public PickableEdgePaintTransformer(PickedInfo<E> pi, Paint draw_paint, Paint picked_paint) {
41 if (pi == null)
42 throw new IllegalArgumentException("PickedInfo instance must be non-null");
43 this.pi = pi;
44 this.draw_paint = draw_paint;
45 this.picked_paint = picked_paint;
46 }
47
48 /**
49 *
50 */
51 public Paint apply(E e) {
52 if (pi.isPicked(e)) {
53 return picked_paint;
54 }
55 else {
56 return draw_paint;
57 }
58 }
59 }