View Javadoc
1   /*
2    * Copyright (c) 2005, The JUNG Authors
3    * All rights reserved.
4    *
5    * This software is open-source under the BSD license; see either "license.txt"
6    * or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
7    *
8    * Created on Aug 23, 2005
9    */
10  
11  package edu.uci.ics.jung.algorithms.layout;
12  
13  import java.awt.Dimension;
14  import java.awt.geom.Point2D;
15  
16  import com.google.common.base.Function;
17  
18  import edu.uci.ics.jung.algorithms.util.IterativeContext;
19  import edu.uci.ics.jung.graph.Graph;
20  
21  /**
22   * a pure decorator for the Layout interface. Intended to be overridden
23   * to provide specific behavior decoration
24   * 
25   * @author Tom Nelson 
26   *
27   */
28  public abstract class LayoutDecorator<V, E> implements Layout<V, E>, IterativeContext {
29      
30      protected Layout<V, E> delegate;
31      
32  	/**
33  	 * Creates an instance backed by the specified {@code delegate}.
34  	 * @param delegate the layout to which this instance is delegating
35  	 */
36      public LayoutDecorator(Layout<V, E> delegate) {
37          this.delegate = delegate;
38      }
39  
40      /**
41       * @return the backing (delegate) layout.
42       */
43      public Layout<V,E> getDelegate() {
44          return delegate;
45      }
46  
47      public void setDelegate(Layout<V,E> delegate) {
48          this.delegate = delegate;
49      }
50  
51      public void step() {
52      	if(delegate instanceof IterativeContext) {
53      		((IterativeContext)delegate).step();
54      	}
55      }
56  
57  	public void initialize() {
58  		delegate.initialize();
59  	}
60  
61  	public void setInitializer(Function<V, Point2D> initializer) {
62  		delegate.setInitializer(initializer);
63  	}
64  
65  	public void setLocation(V v, Point2D location) {
66  		delegate.setLocation(v, location);
67  	}
68  
69      public Dimension getSize() {
70          return delegate.getSize();
71      }
72  
73      public Graph<V, E> getGraph() {
74          return delegate.getGraph();
75      }
76  
77      public Point2D transform(V v) {
78          return delegate.apply(v);
79      }
80  
81      public boolean done() {
82      	if(delegate instanceof IterativeContext) {
83      		return ((IterativeContext)delegate).done();
84      	}
85      	return true;
86      }
87  
88      public void lock(V v, boolean state) {
89          delegate.lock(v, state);
90      }
91  
92      public boolean isLocked(V v) {
93          return delegate.isLocked(v);
94      }
95      
96      public void setSize(Dimension d) {
97          delegate.setSize(d);
98      }
99  
100     public void reset() {
101     	delegate.reset();
102     }
103     
104     public void setGraph(Graph<V, E> graph) {
105         delegate.setGraph(graph);
106     }
107 }