1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.awt.Dimension;
|
---|
4 | import java.awt.Rectangle;
|
---|
5 | import java.awt.Shape;
|
---|
6 | import java.security.InvalidParameterException;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import javax.swing.JFrame;
|
---|
10 |
|
---|
11 | import org.apache.commons.collections15.Transformer;
|
---|
12 |
|
---|
13 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
14 | import de.ugoe.cs.eventbench.models.Trie.Edge;
|
---|
15 | import de.ugoe.cs.eventbench.models.Trie.TrieVertex;
|
---|
16 | import de.ugoe.cs.eventbench.models.TrieBasedModel;
|
---|
17 | import de.ugoe.cs.util.console.Command;
|
---|
18 | import de.ugoe.cs.util.console.Console;
|
---|
19 | import edu.uci.ics.jung.algorithms.layout.Layout;
|
---|
20 | import edu.uci.ics.jung.algorithms.layout.TreeLayout;
|
---|
21 | import edu.uci.ics.jung.graph.Tree;
|
---|
22 | import edu.uci.ics.jung.visualization.BasicVisualizationServer;
|
---|
23 | import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
|
---|
24 | import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
|
---|
25 |
|
---|
26 | public class CMDshowTrie implements Command {
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public void help() {
|
---|
30 | Console.println("Usage: showTrie <modelName>");
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void run(List<Object> parameters) {
|
---|
35 | String modelname;
|
---|
36 | try {
|
---|
37 | modelname = (String) parameters.get(0);
|
---|
38 | } catch (Exception e) {
|
---|
39 | throw new InvalidParameterException();
|
---|
40 | }
|
---|
41 |
|
---|
42 | Object dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
43 | if( dataObject==null ) {
|
---|
44 | Console.printerrln("No model with name " + modelname + "found");
|
---|
45 | } else {
|
---|
46 | TrieBasedModel model = (TrieBasedModel) dataObject;
|
---|
47 | Tree<TrieVertex, Edge> graph = model.getTrieGraph();
|
---|
48 | Layout<TrieVertex, Edge> layout = new TreeLayout<TrieVertex, Edge>(graph, 60);
|
---|
49 | // The BasicVisualizationServer<V,E> is parameterized by the edge types
|
---|
50 | BasicVisualizationServer<TrieVertex,Edge> vv =
|
---|
51 | new BasicVisualizationServer<TrieVertex,Edge>(layout);
|
---|
52 | vv.setPreferredSize(new Dimension(1100,850)); //Sets the viewing area size
|
---|
53 |
|
---|
54 |
|
---|
55 | final Rectangle rect = new Rectangle(40, 20);
|
---|
56 |
|
---|
57 | Transformer<TrieVertex, Shape> vertexShapeTransformer =
|
---|
58 | new Transformer<TrieVertex, Shape>() {
|
---|
59 | public Shape transform(TrieVertex s) {
|
---|
60 | return rect;
|
---|
61 | }
|
---|
62 | };
|
---|
63 | vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
|
---|
64 | vv.getRenderContext().setVertexShapeTransformer(vertexShapeTransformer);
|
---|
65 | vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<TrieVertex>());
|
---|
66 |
|
---|
67 | JFrame frame = new JFrame("Trie");
|
---|
68 | frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
---|
69 | frame.getContentPane().add(vv);
|
---|
70 | frame.pack();
|
---|
71 | frame.setVisible(true);
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 | }
|
---|