View Javadoc

1   /*
2   * Copyright (c) 2003, the JUNG Project and the Regents of the University 
3   * of California
4   * All rights reserved.
5   *
6   * This software is open-source under the BSD license; see either
7   * "license.txt" or
8   * http://jung.sourceforge.net/license.txt for a description.
9   */
10  package edu.uci.ics.jung.visualization.renderers;
11  
12  import java.awt.Dimension;
13  
14  import edu.uci.ics.jung.algorithms.layout.Layout;
15  import edu.uci.ics.jung.visualization.RenderContext;
16  
17  /**
18   * The interface for drawing vertices, edges, and their labels.
19   * Implementations of this class can set specific renderers for
20   * each element, allowing custom control of each.
21   */
22  public interface Renderer<V,E> {
23  
24  	void render(RenderContext<V,E> rc, Layout<V,E> layout);
25  	void renderVertex(RenderContext<V,E> rc, Layout<V,E> layout, V v);
26  	void renderVertexLabel(RenderContext<V,E> rc, Layout<V,E> layout, V v);
27  	void renderEdge(RenderContext<V,E> rc, Layout<V,E> layout, E e);
28  	void renderEdgeLabel(RenderContext<V,E> rc, Layout<V,E> layout, E e);
29      void setVertexRenderer(Renderer.Vertex<V,E> r);
30      void setEdgeRenderer(Renderer.Edge<V,E> r);
31      void setVertexLabelRenderer(Renderer.VertexLabel<V,E> r);
32      void setEdgeLabelRenderer(Renderer.EdgeLabel<V,E> r);
33      Renderer.VertexLabel<V,E> getVertexLabelRenderer();
34      Renderer.Vertex<V,E> getVertexRenderer();
35      Renderer.Edge<V,E> getEdgeRenderer();
36      Renderer.EdgeLabel<V,E> getEdgeLabelRenderer();
37  
38  	interface Vertex<V,E> {
39  		void paintVertex(RenderContext<V,E> rc, Layout<V,E> layout, V v);
40  		class NOOP implements Vertex {
41  			public void paintVertex(RenderContext rc, Layout layout, Object v) {}
42  		};
43  	}
44      
45  	interface Edge<V,E> {
46  		void paintEdge(RenderContext<V,E> rc, Layout<V,E> layout, E e);
47  		EdgeArrowRenderingSupport getEdgeArrowRenderingSupport();
48  		void setEdgeArrowRenderingSupport(EdgeArrowRenderingSupport edgeArrowRenderingSupport);
49  		class NOOP implements Edge {
50  			public void paintEdge(RenderContext rc, Layout layout, Object e) {}
51  			public EdgeArrowRenderingSupport getEdgeArrowRenderingSupport(){return null;}
52  			public void setEdgeArrowRenderingSupport(EdgeArrowRenderingSupport edgeArrowRenderingSupport){}
53  		}
54  	}
55  	
56  	interface VertexLabel<V,E> {
57  		void labelVertex(RenderContext<V,E> rc, Layout<V,E> layout, V v, String label);
58  		Position getPosition();
59  		void setPosition(Position position);
60  		void setPositioner(Positioner positioner);
61  		Positioner getPositioner();
62  		class NOOP implements VertexLabel {
63  			public void labelVertex(RenderContext rc, Layout layout, Object v, String label) {}
64  			public Position getPosition() { return Position.CNTR; }
65  			public void setPosition(Position position) {}
66  			public Positioner getPositioner() {
67  				return new Positioner() {
68  					public Position getPosition(float x, float y, Dimension d) {
69  						return Position.CNTR;
70  					}};
71  			}
72  			public void setPositioner(Positioner positioner) {
73  			}
74  		}
75  		enum Position { N, NE, E, SE, S, SW, W, NW, CNTR, AUTO }
76  	    interface Positioner {
77  	    	Position getPosition(float x, float y, Dimension d);
78  	    }
79  
80  	}
81  	
82  	interface EdgeLabel<V,E> {
83  		void labelEdge(RenderContext<V,E> rc, Layout<V,E> layout, E e, String label);
84  		class NOOP implements EdgeLabel {
85  			public void labelEdge(RenderContext rc, Layout layout, Object e, String label) {}
86  		}
87  	}
88  }