1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
public class ContactView extends JFrame implements INaomiProcess {
private ISender sender = null;
private Graph<String, String> effectiveGraph;
private Graph<String, String> authGraph;
private Collection<String> allVertices;
private Collection<String> allEdges;
private JFrame jf;
Layout<String,String> layoutEffectiveGraphe;
Layout<String,String> layoutAuthGraph;
BasicVisualizationServer<String,String> effectiveVv;
BasicVisualizationServer<String,String> authVv;
JPanel authPanel;
JPanel effectivePanel;
JTabbedPane mainPanel;
public ContactView(String title, String agentPath, String resPath){
authGraph = new DirectedSparseGraph<String, String>();
effectiveGraph = new DirectedSparseGraph<String, String>();
// Create some MyNode objects to use as vertices
String n1 = new String("1"); String n2 = new String("2"); String n3 = new String("3");
String n4 = new String("4"); String n5 = new String("5"); // note n1-n5 declared elsewhere.
// Add some directed edges along with the vertices to the graph
authGraph.addEdge(new String("bouh"),n1, n2, EdgeType.DIRECTED); // This method
authGraph.addEdge(new String("bouh1"),n2, n3, EdgeType.DIRECTED);
authGraph.addEdge(new String("bouh2"), n3, n5, EdgeType.DIRECTED);
authGraph.addEdge(new String("bouh3"), n5, n4, EdgeType.DIRECTED); // or we can use
authGraph.addEdge(new String("bouh4"), n4, n2); // In a directed graph the
authGraph.addEdge(new String("bouh5"), n3, n1); // first node is the source
authGraph.addEdge(new String("bouh6"), n2, n5);// and the second the destination
effectiveGraph.addEdge(new String("bouh"),n1, n2, EdgeType.DIRECTED); // This method
effectiveGraph.addEdge(new String("bouh1"),n2, n3, EdgeType.DIRECTED);
effectiveGraph.addEdge(new String("bouh2"), n3, n5, EdgeType.DIRECTED);
effectiveGraph.addEdge(new String("bouh3"), n5, n4, EdgeType.DIRECTED); // or we can use
effectiveGraph.addEdge(new String("bouh4"), n4, n2); // In a directed graph the
effectiveGraph.addEdge(new String("bouh5"), n3, n1); // first node is the source
effectiveGraph.addEdge(new String("bouh6"), n2, n5);// and the second the destination
layoutAuthGraph = new CircleLayout(authGraph);
layoutAuthGraph.setSize(new Dimension(300,300));
authVv = new BasicVisualizationServer<String, String>(layoutAuthGraph);
authVv.setPreferredSize(new Dimension(350,350));
authPanel = new JPanel();
authPanel.add(authVv);
layoutEffectiveGraphe = new CircleLayout(authGraph);
layoutEffectiveGraphe.setSize(new Dimension(300,300));
effectiveVv = new BasicVisualizationServer<String, String>(layoutAuthGraph);
effectiveVv.setPreferredSize(new Dimension(350,350));
effectivePanel = new JPanel();
effectivePanel.add(effectiveVv);
mainPanel = new JTabbedPane();
mainPanel.addTab("Authorized links", authPanel);
mainPanel.addTab("Effective links", effectivePanel);
// Set up a new stroke Transformer for the edges
float dash[] = {10.0f};
final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
Transformer<String, Stroke> edgeStrokeTransformer =
new Transformer<String, Stroke>() {
public Stroke transform(String s) {
return edgeStroke;
}
};
authVv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
authVv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
authVv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
effectiveVv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
effectiveVv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
effectiveVv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
JFrame frame = new JFrame("Simple Graph View 2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setVisible(true);
} |
Partager