本文整理汇总了Java中edu.uci.ics.jung.visualization.BasicVisualizationServer类的典型用法代码示例。如果您正苦于以下问题:Java BasicVisualizationServer类的具体用法?Java BasicVisualizationServer怎么用?Java BasicVisualizationServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicVisualizationServer类属于edu.uci.ics.jung.visualization包,在下文中一共展示了BasicVisualizationServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJUNG2
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
@Test
public void testJUNG2() throws Exception {
Graph<String, String> graph = new SparseMultigraph<String, String>();
graph.addVertex("state 1");
graph.addVertex("state 2");
graph.addVertex("state 3");
graph.addVertex("state 4");
graph.addVertex("state 5");
graph.addVertex("state 6");
graph.addEdge("edge 1", "state 1", "state 2", EdgeType.DIRECTED);
graph.addEdge("edge 2", "state 1", "state 3", EdgeType.DIRECTED);
graph.addEdge("edge 3", "state 1", "state 4", EdgeType.DIRECTED);
graph.addEdge("edge 4", "state 3", "state 4", EdgeType.DIRECTED);
CircleLayout<String, String> layout = new CircleLayout<String, String>(graph);
layout.setSize(new Dimension(300, 300));
BasicVisualizationServer<String, String> visualization = new BasicVisualizationServer<String, String>(layout);
visualization.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
visualization.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<String>());
visualization.setPreferredSize(new Dimension(350, 350));
JOptionPane.showMessageDialog(null, visualization);
}
示例2: graphToFile
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
private void graphToFile(BasicVisualizationServer<String, String> visualization, File file) throws IOException {
Dimension size = visualization.getSize();
int width = (int) (size.getWidth() + 1);
int height = (int) (size.getHeight() + 1);
LOG.debug("width: " + width);
LOG.debug("height: " + height);
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = bufferedImage.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, 900, 650);
visualization.setBounds(0, 0, 900, 650);
visualization.paint(graphics);
graphics.dispose();
ImageIO.write(bufferedImage, "png", file);
}
示例3: main
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public static void main(String [] args) {
ProcletModel pmodel = new ProcletModel("visit");
pmodel.buildFromDB();
pmodel.persistProcletModel();
ProcletBlock block1 = new ProcletBlock("b1",BlockType.PI,false,5);
ProcletBlock block2 = new ProcletBlock("b2",BlockType.PI,false,5);
pmodel.addBlock(block1);
pmodel.addBlock(block2);
ProcletPort port = new ProcletPort("p1",Direction.OUT,Signature.ONE,Signature.ONE);
ProcletPort port2 = new ProcletPort("p2",Direction.OUT,Signature.ONE,Signature.ONE);
pmodel.addProcletPort(port, block1);
pmodel.addProcletPort(port2, block1);
pmodel.getBlocks();
pmodel.getPortsBlock(block1);
// visualization
Layout layout = new CircleLayout(pmodel);
layout.setSize(new Dimension(300,300));
BasicVisualizationServer vv = new BasicVisualizationServer(layout);
vv.setPreferredSize(new Dimension(350,350));
JFrame frame = new JFrame("simple");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
示例4: main
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public static void main(String [] args) {
JOptionPane.showMessageDialog(null,
"Block already exists!",
"Error",
JOptionPane.ERROR_MESSAGE);
InteractionGraphs igraphs = InteractionGraphs.getInstance();
igraphs.buildFromDB();
InteractionGraph graph = igraphs.getGraph(new EntityMID("test"));
Layout<Integer,String> layout = new CircleLayout(graph);
layout.setSize(new Dimension(300,300));
BasicVisualizationServer<Integer,String> vv = new BasicVisualizationServer<Integer,String>(layout);
vv.setPreferredSize(new Dimension(350,350));
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
JFrame frame = new JFrame("simple");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
System.out.println("done");
}
示例5: run
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
/**
* This method runs the necessary calls to generate a JUNG visualizer with a GEXF file.
* Uses a graph from <code>GexfReader(String filename)</code> and Transformers from <code>org.iqt.gexf2jung.transformers</code> to make a <code>BasicVisualizationServer</code>.
* @param filename This must be acceptable by the constructor <code>File(filename)</code>
* @param width The width of the window
* @param height The height of the window
* @param x the X coordinate of the window's position
* @param y the Y coordinate of the window's position
* @throws ParserConfigurationException see <code>GexfReader.read(String filename)</code>
* @throws SAXException see <code>GexfReader.read(String filename)</code>
* @throws IOException Called if the filename is not valid.
* @see GexfReader
*/
public static void run(String filename, int width, int height, int x, int y) throws ParserConfigurationException, SAXException, IOException{
Graph<Node, Edge> g = GexfReader.read(filename);
Layout<Node, Edge> layout = new CircleLayout<Node, Edge>(g);
layout.setSize(new Dimension(width, height)); // sets the initial size of the space
// The BasicVisualizationServer<V,E> is parameterized by the edge types
BasicVisualizationServer<Node, Edge> vv
= new BasicVisualizationServer<Node, Edge>(layout);
vv.setPreferredSize(new Dimension(width, height)); //Sets the viewing area size
vv.getRenderContext().setVertexFillPaintTransformer(new GexfNodePaintTransformer());
vv.getRenderContext().setVertexShapeTransformer(new GexfNodeShapeTransformer());
vv.getRenderContext().setEdgeStrokeTransformer(new GexfEdgeStrokeTransformer());
vv.getRenderContext().setVertexLabelTransformer(new GexfNodeLabelTransformer());
vv.getRenderContext().setEdgeLabelTransformer(new GexfEdgeLabelTransformer());
vv.getRenderContext().setEdgeDrawPaintTransformer(new GexfEdgePaintTransformer());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO);
JFrame frame = new JFrame("Graph View");
frame.setLocation(x, y);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
示例6: GraphPanel
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public GraphPanel(DirectedSparseMultigraph<V, E> graph) {
// this.setLayout(new FlowLayout());
DirectedSparseMultigraph<V, E> graphTemp = new DirectedSparseMultigraph<V, E>();
for (V vertex : graph.getVertices()) {
if (graph.inDegree(vertex) > 0 || graph.outDegree(vertex) > 0) {
graphTemp.addVertex(vertex);
}
}
for (E edge : graph.getEdges()) {
if (graphTemp.containsVertex(graph.getSource(edge))
&& graphTemp.containsVertex(graph.getDest(edge))) {
graphTemp.addEdge(edge, graph.getSource(edge), graph.getDest(edge));
}
}
this.graph = graphTemp;
layout = new KKLayout<V, E>(this.graph);
layout.setSize(new Dimension(1000, 800)); // sets the initial size of the
// space
// The BasicVisualizationServer<V,E> is parameterized by the edge types
BasicVisualizationServer<V, E> server = new BasicVisualizationServer<V, E>(
layout);
server.setPreferredSize(new Dimension(1000, 800));
this.add(server);
}
示例7: writeTo
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
@Override
public void writeTo(Graph data, Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream out) throws IOException {
Integer width = Integer.parseInt(Optional.ofNullable(request.getParameter("width")).orElse(DEFAULT_WIDTH));
Integer height = Integer.parseInt(Optional.ofNullable(request.getParameter("height")).orElse(DEFAULT_HEIGHT));
String layoutName = Optional.ofNullable(request.getParameter("layout")).orElse(DEFAULT_LAYOUT);
GraphJung<Graph> graph = new GraphJung<Graph>(data);
AbstractLayout<Vertex, Edge> layout = getLayout(graph, layoutName);
layout.setSize(new Dimension(width, height));
BasicVisualizationServer<Vertex, Edge> viz = new BasicVisualizationServer<>(layout);
viz.setPreferredSize(new Dimension(width, height));
viz.getRenderContext().setEdgeLabelTransformer(edgeLabelTransformer);
viz.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
viz.getRenderContext().setVertexFillPaintTransformer(vertexColorTransformer);
BufferedImage bi = renderImage(viz);
String imageType = null;
if (mediaType.equals(CustomMediaTypes.IMAGE_JPEG_TYPE)) {
imageType = "jpg";
} else if (mediaType.equals(CustomMediaTypes.IMAGE_PNG_TYPE)) {
imageType = "png";
}
ImageIO.write(bi, imageType, out);
}
示例8: main
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public static void main(String[] args) {
File f = new File( "./data/DSPM_01.graphml" );
SimpleGraphView sgv = new SimpleGraphView( f ); //We create our graph in here
// The Layout<V, E> is parameterized by the vertex and edge types
Layout<Integer, String> layout = new CircleLayout(sgv.g);
layout.setSize(new Dimension(300,300)); // sets the initial size of the layout space
// The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
BasicVisualizationServer<Integer,String> vv = new BasicVisualizationServer<Integer,String>(layout);
vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size
JFrame frame = new JFrame("Simple Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
示例9: graphToFile
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
private static void graphToFile(BasicVisualizationServer<String, String> visualization, File file)
throws IOException {
Dimension size = visualization.getSize();
int width = (int) (size.getWidth() + 1);
int height = (int) (size.getHeight() + 1);
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = bufferedImage.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, 900, 650);
visualization.setBounds(0, 0, 900, 650);
visualization.paint(graphics);
graphics.dispose();
ImageIO.write(bufferedImage, "png", file);
}
示例10: testVisualizeProtocol
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
@Test
public void testVisualizeProtocol() throws Exception {
BasicVisualizationServer<String, String> visualization = createGraph();
// JOptionPane.showMessageDialog(null, visualization);
File tmpFile = File.createTempFile("graph-", ".png");
graphToFile(visualization, tmpFile);
LOG.debug("tmp file: " + tmpFile.getAbsolutePath());
}
示例11: plot
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public void plot() {
BNplot sgv = this; //We create our graph in here
// The Layout<V, E> is parameterized by the vertex and edge types
// Layout<Integer, String> layout = new CircleLayout(sgv.g);
// Layout<String, String> layout = new ISOMLayout<String, String>(sgv.g);
Layout<String, String> layout = new KKLayout<String, String>(sgv.g);
layout.setSize(new Dimension(600,600)); // sets the initial size of the layout space
// The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
BasicVisualizationServer<String,String> vv = new BasicVisualizationServer<String,String>(layout);
vv_global=vv;
vv.setPreferredSize(new Dimension(650,650)); //Sets the viewing area size
// vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.setBackground(Color.white);
// vv.getRenderContext().setVertexShapeTransformer(vertexShape);
JFrame frame = new JFrame("Behavior Network Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
// vv.getRenderContext().setVertexFillPaintTransformer(vertexColor);
}
示例12: visualizeNetworkGraph
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public static JFrame visualizeNetworkGraph(Graph<NetworkVertex, NetworkEdge> graph) {
Layout<NetworkVertex, NetworkEdge> layout = new ISOMLayout<>(graph);
layout.setSize(new Dimension(600, 600));
BasicVisualizationServer<NetworkVertex, NetworkEdge> vv = new BasicVisualizationServer<>(layout);
vv.setPreferredSize(new Dimension(700, 700));
Transformer<NetworkVertex, Paint> vertexPaint = v -> {
if (v instanceof Host) {
Host host = (Host) v;
return host.isFree() ? Color.GREEN : Color.RED;
} else {
return Color.GRAY;
}
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Transformer<NetworkVertex, String> vertexLabel = v -> v.getId();
vv.getRenderContext().setVertexLabelTransformer(vertexLabel);
vv.getRenderer().getVertexLabelRenderer().setPosition(edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position.AUTO);
Transformer<NetworkEdge, String> edgeLabel = networkEdge -> networkEdge.getTailPort() + "->" + networkEdge.getHeadPort();
vv.getRenderContext().setEdgeLabelTransformer(edgeLabel);
JFrame frame = new JFrame("Simple Graph View 2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
return frame;
}
示例13: generateGraph
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public static void generateGraph(File graphFile) throws IOException {
BasicVisualizationServer<String, String> visualization = createGraph();
graphToFile(visualization, graphFile);
}
示例14: visualize
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
public void visualize(TinkerGraph graph) {
GraphJung<TinkerGraph> graphJung = new GraphJung<TinkerGraph>(graph);
Layout<Vertex, Edge> layout = new CircleLayout<Vertex, Edge>(graphJung);
layout.setSize(new Dimension(400, 400));
BasicVisualizationServer<Vertex, Edge> viz = new BasicVisualizationServer<Vertex, Edge>(
layout);
viz.setPreferredSize(new Dimension(550, 550));
Transformer<Vertex, String> vertexLabelTransformer = new Transformer<Vertex, String>() {
public String transform(Vertex vertex) {
String vertexLabel = "";
if (vertex
.getProperty(NerdleGraphTransformer.PROPERTY_CLAUSE_TYPE) == NerdleGraphTransformer.VALUE_CLAUSE_TYPE_PREDICATE) {
vertexLabel = ((String) vertex
.getProperty(NerdleGraphTransformer.PROPERTY_VERBTEXT)
+ " { " + (String) vertex
.getProperty(NerdleGraphTransformer.PROPERTY_CLAUSE_TYPE))
+ " } "
+ vertex.getProperty(NerdleGraphTransformer.PROPERTY_SENTENCE);
} else {
vertexLabel = ((String) vertex
.getProperty(NerdleGraphTransformer.PROPERTY_TEXT)
+ " { " + (String) vertex
.getProperty(NerdleGraphTransformer.PROPERTY_NER))
+ ", "
+ vertex.getProperty(NerdleGraphTransformer.PROPERTY_CLAUSE_TYPE)
+ " } ";
}
return vertexLabel;
}
};
Transformer<Edge, String> edgeLabelTransformer = new Transformer<Edge, String>() {
public String transform(Edge edge) {
return edge.getLabel();
}
};
viz.getRenderContext().setEdgeLabelTransformer(edgeLabelTransformer);
viz.getRenderContext()
.setVertexLabelTransformer(vertexLabelTransformer);
JFrame frame = new JFrame("Nerdle Graph Visualizer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(viz);
frame.pack();
frame.setVisible(true);
}
示例15: visualize
import edu.uci.ics.jung.visualization.BasicVisualizationServer; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void visualize(JungNetwork graph, String title, int type)
{
// The Layout<V, E> is parameterized by the vertex and edge types
Layout<JungVertex, JungEdge> layout = null;
switch (type)
{
case CIRCLE:
layout = new CircleLayout<JungVertex, JungEdge>(graph);
break;
case SPRING:
layout = new SpringLayout<JungVertex, JungEdge>(graph);
break;
case FR:
layout = new FRLayout<JungVertex, JungEdge>(graph);
break;
case ISOM:
layout = new ISOMLayout<JungVertex, JungEdge>(graph);
break;
case DAG:
layout = new DAGLayout<JungVertex, JungEdge>(graph);
break;
case SPRING2:
layout = new SpringLayout2<JungVertex, JungEdge>(graph);
break;
default:
layout = new KKLayout<JungVertex, JungEdge>(graph);
}
layout.setSize(new Dimension(800,800)); // sets the initial size of the space
// The BasicVisualizationServer<V,E> is parameterized by the edge types
BasicVisualizationServer<JungVertex,JungEdge> vv =
new BasicVisualizationServer<JungVertex,JungEdge>(layout);
vv.setPreferredSize(new Dimension(900,900)); //Sets the viewing area size
vv.scaleToLayout(new LayoutScalingControl() );
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}