View Javadoc
1   /*
2    * Created on Jul 18, 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 java.awt.Shape;
15  
16  import com.google.common.base.Function;
17  
18  import edu.uci.ics.jung.graph.Graph;
19  import edu.uci.ics.jung.graph.util.Context;
20  import edu.uci.ics.jung.graph.util.EdgeType;
21  import edu.uci.ics.jung.visualization.util.ArrowFactory;
22  
23  /**
24   * Returns wedge arrows for undirected edges and notched arrows
25   * for directed edges, of the specified dimensions.
26   * 
27   * @author Joshua O'Madadhain
28   */
29  public class DirectionalEdgeArrowTransformer<V,E> implements Function<Context<Graph<V,E>,E>,Shape> {
30      protected Shape undirected_arrow;
31      protected Shape directed_arrow;
32      
33      public DirectionalEdgeArrowTransformer(int length, int width, int notch_depth)
34      {
35          directed_arrow = ArrowFactory.getNotchedArrow(width, length, notch_depth);
36          undirected_arrow = ArrowFactory.getWedgeArrow(width, length);
37      }
38      
39      /**
40       * 
41       */
42      public Shape apply(Context<Graph<V,E>,E> context)
43      {
44          if (context.graph.getEdgeType(context.element) == EdgeType.DIRECTED)
45              return directed_arrow;
46          else 
47              return undirected_arrow;
48      }
49  
50  }