View Javadoc
1   /*
2    * Created on Oct 21, 2004
3    *
4    * Copyright (c) 2004, 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 com.google.common.base.Function;
15  
16  import edu.uci.ics.jung.graph.Graph;
17  import edu.uci.ics.jung.graph.util.Context;
18  import edu.uci.ics.jung.graph.util.EdgeType;
19  
20  
21  /**
22   * Returns the constructor-specified value for each edge type.
23   * 
24   * @author Joshua O'Madadhain
25   */
26  public class ConstantDirectionalEdgeValueTransformer<V,E> implements Function<Context<Graph<V,E>,E>,Number>
27  {
28      protected Double undirected_value;
29      protected Double directed_value;
30  
31      /**
32       * 
33       * @param undirected the value to return if the edge is undirected
34       * @param directed the value to return if the edge is directed
35       */
36      public ConstantDirectionalEdgeValueTransformer(double undirected, double directed)
37      {
38          this.undirected_value = new Double(undirected);
39          this.directed_value = new Double(directed);
40      }
41      
42      public Number apply(Context<Graph<V,E>,E> context) {
43      	Graph<V,E> graph = context.graph;
44      	E e = context.element;
45          if (graph.getEdgeType(e) == EdgeType.DIRECTED)
46              return directed_value;
47          else 
48              return undirected_value;
49      }
50      
51      /**
52       * Sets the value returned for undirected edges to <code>value</code>.
53       * @param value the new value to return for undirected edges
54       */
55      public void setUndirectedValue(double value)
56      {
57      	this.undirected_value = value;
58      }
59      
60      /**
61       * Sets the value returned for directed edges to <code>value</code>.
62       * @param value the new value to return for directed edges
63       */
64      public void setDirectedValue(double value)
65      {
66      	this.directed_value = value;
67      }
68  }