View Javadoc
1   /*
2   * Copyright (c) 2003, The JUNG Authors 
3   *
4   * All rights reserved.
5   *
6   * This software is open-source under the BSD license; see either
7   * "license.txt" or
8   * https://github.com/jrtom/jung/blob/master/LICENSE 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  		@SuppressWarnings("rawtypes")
41  		class NOOP implements Vertex {
42  			public void paintVertex(RenderContext rc, Layout layout, Object v) {}
43  		};
44  	}
45      
46  	interface Edge<V,E> {
47  		void paintEdge(RenderContext<V,E> rc, Layout<V,E> layout, E e);
48  		EdgeArrowRenderingSupport<V, E> getEdgeArrowRenderingSupport();
49  		void setEdgeArrowRenderingSupport(EdgeArrowRenderingSupport<V, E> edgeArrowRenderingSupport);
50  		@SuppressWarnings("rawtypes")
51  		class NOOP implements Edge {
52  			public void paintEdge(RenderContext rc, Layout layout, Object e) {}
53  			public EdgeArrowRenderingSupport getEdgeArrowRenderingSupport(){return null;}
54  			public void setEdgeArrowRenderingSupport(EdgeArrowRenderingSupport edgeArrowRenderingSupport){}
55  		}
56  	}
57  	
58  	interface VertexLabel<V,E> {
59  		void labelVertex(RenderContext<V,E> rc, Layout<V,E> layout, V v, String label);
60  		Position getPosition();
61  		void setPosition(Position position);
62  		void setPositioner(Positioner positioner);
63  		Positioner getPositioner();
64  		@SuppressWarnings("rawtypes")
65  		class NOOP implements VertexLabel {
66  			public void labelVertex(RenderContext rc, Layout layout, Object v, String label) {}
67  			public Position getPosition() { return Position.CNTR; }
68  			public void setPosition(Position position) {}
69  			public Positioner getPositioner() {
70  				return new Positioner() {
71  					public Position getPosition(float x, float y, Dimension d) {
72  						return Position.CNTR;
73  					}};
74  			}
75  			public void setPositioner(Positioner positioner) {
76  			}
77  		}
78  		enum Position { N, NE, E, SE, S, SW, W, NW, CNTR, AUTO }
79  	    interface Positioner {
80  	    	Position getPosition(float x, float y, Dimension d);
81  	    }
82  
83  	}
84  	
85  	interface EdgeLabel<V,E> {
86  		void labelEdge(RenderContext<V,E> rc, Layout<V,E> layout, E e, String label);
87  		@SuppressWarnings("rawtypes")
88  		class NOOP implements EdgeLabel {
89  			public void labelEdge(RenderContext rc, Layout layout, Object e, String label) {}
90  		}
91  	}
92  }