View Javadoc

1   /*
2    * Copyright (c) 2005, the JUNG Project and the Regents of the University of
3    * California All rights reserved.
4    *
5    * This software is open-source under the BSD license; see either "license.txt"
6    * or http://jung.sourceforge.net/license.txt for a description.
7    *
8    * Created on Jul 11, 2005
9    */
10  
11  package edu.uci.ics.jung.visualization.transform.shape;
12  
13  import java.awt.Graphics2D;
14  import java.awt.Shape;
15  
16  import edu.uci.ics.jung.visualization.transform.BidirectionalTransformer;
17  import edu.uci.ics.jung.visualization.transform.HyperbolicTransformer;
18  
19  
20  /**
21   * subclassed to pass certain operations thru the transformer
22   * before the base class method is applied
23   * This is useful when you want to apply non-affine transformations
24   * to the Graphics2D used to draw elements of the graph.
25   * 
26   * @author Tom Nelson 
27   *
28   *
29   */
30  public class TransformingFlatnessGraphics extends TransformingGraphics {
31      
32  	float flatness = 0;
33  
34      public TransformingFlatnessGraphics(BidirectionalTransformer transformer) {
35          this(transformer, null);
36      }
37      
38      public TransformingFlatnessGraphics(BidirectionalTransformer transformer, Graphics2D delegate) {
39          super(transformer, delegate);
40      }
41      
42      public void draw(Shape s, float flatness) {
43          Shape shape = null;
44          if(transformer instanceof ShapeFlatnessTransformer) {
45              shape = ((ShapeFlatnessTransformer)transformer).transform(s, flatness);
46          } else {
47              shape = ((ShapeTransformer)transformer).transform(s);
48          }
49          delegate.draw(shape);
50          
51      }
52      
53      public void fill(Shape s, float flatness) {
54          Shape shape = null;
55          if(transformer instanceof HyperbolicTransformer) {
56              shape = ((HyperbolicShapeTransformer)transformer).transform(s, flatness);
57          } else {
58              shape = ((ShapeTransformer)transformer).transform(s);
59          }
60          delegate.fill(shape);
61      }
62  }