TrustGrapher  r52
A playabale simulator for modelling trust between agents
D:/src/cu/trustGrapher/visualizer/GraphViewer.java
Go to the documentation of this file.
00001 
00002 package cu.trustGrapher.visualizer;
00003 
00004 import cu.repsystestbed.entities.Agent;
00005 import cu.repsystestbed.graphs.TestbedEdge;
00006 import cu.trustGrapher.graphs.JungAdapterGraph;
00007 import cu.trustGrapher.graphs.SimAbstractGraph;
00008 
00009 import edu.uci.ics.jung.algorithms.layout.Layout;
00010 import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
00011 import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
00012 import edu.uci.ics.jung.visualization.renderers.Renderer;
00013 
00014 import java.awt.Color;
00015 import java.awt.event.MouseAdapter;
00016 
00022 public class GraphViewer extends edu.uci.ics.jung.visualization.VisualizationViewer {
00023     private JungAdapterGraph fullGraph;
00024 
00026 
00033     public GraphViewer(final Layout layout, DefaultModalGraphMouse<Agent, TestbedEdge> gm, MouseAdapter mouseClickListener, SimAbstractGraph graph) {
00034         super(layout);
00035         this.fullGraph = graph.getReferenceGraph();
00036         // the default mouse makes the mouse usable as a picking tool (pick, drag vertices & edges) or as a transforming tool (pan, zoom)
00037         setGraphMouse(gm);
00038         addMouseListener(mouseClickListener); //This listener handles the mouse clicks to see if a popup event was done
00039 
00040         //the vertex labeler will use the tostring method which is fine, the Agent class has an appropriate toString() method implementation
00041         getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Agent>());
00042         getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
00043         //the Edge labeler will use the tostring method which is fine, each testbedEdge subclass has an appropriate toString() method implementation
00044         getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<TestbedEdge>());
00045         //Sets the predicates which decide whether the vertices and edges are displayed
00046         getRenderContext().setVertexIncludePredicate(graph);
00047         getRenderContext().setEdgeIncludePredicate(graph);
00048 
00049         setForeground(Color.white);
00050         setBackground(Color.GRAY);
00051     }
00052 
00056     public JungAdapterGraph getFullGraph(){
00057         return fullGraph;
00058     }
00059 }
00061