View Javadoc
1   /*
2    * Created on Jul 16, 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  import com.google.common.base.Functions;
16  
17  import edu.uci.ics.jung.visualization.util.VertexShapeFactory;
18  
19  
20  
21  /**
22   * 
23   * @author Joshua O'Madadhain
24   */
25  public abstract class AbstractVertexShapeTransformer<V> implements SettableVertexShapeTransformer<V>
26  {
27      protected Function<? super V,Integer> vsf;
28      protected Function<? super V,Float> varf;
29      protected VertexShapeFactory<V> factory;
30      public final static int DEFAULT_SIZE = 8;
31      public final static float DEFAULT_ASPECT_RATIO = 1.0f;
32      
33      public AbstractVertexShapeTransformer(Function<? super V,Integer> vsf, Function<? super V,Float> varf)
34      {
35          this.vsf = vsf;
36          this.varf = varf;
37          factory = new VertexShapeFactory<V>(vsf, varf);
38      }
39  
40  	public AbstractVertexShapeTransformer()
41      {
42          this(Functions.constant(DEFAULT_SIZE), 
43                  Functions.constant(DEFAULT_ASPECT_RATIO));
44      }
45      
46      public void setSizeTransformer(Function<V,Integer> vsf)
47      {
48          this.vsf = vsf;
49          factory = new VertexShapeFactory<V>(vsf, varf);
50      }
51      
52      public void setAspectRatioTransformer(Function<V,Float> varf)
53      {
54          this.varf = varf;
55          factory = new VertexShapeFactory<V>(vsf, varf);
56      }
57  }