本文整理汇总了Java中org.jgrapht.ext.JGraphXAdapter类的典型用法代码示例。如果您正苦于以下问题:Java JGraphXAdapter类的具体用法?Java JGraphXAdapter怎么用?Java JGraphXAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JGraphXAdapter类属于org.jgrapht.ext包,在下文中一共展示了JGraphXAdapter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAndShowGui
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
private static void createAndShowGui(double threshold, boolean showEdgeLabels) {
JFrame frame = new JFrame("NewGraph");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ListenableGraph<String, MyEdge> g = buildGraph(threshold, showEdgeLabels);
JGraphXAdapter<String, MyEdge> graphAdapter =
new JGraphXAdapter<String, MyEdge>(g);
mxIGraphLayout layout = new mxCircleLayout(graphAdapter);
layout.execute(graphAdapter.getDefaultParent());
frame.add(new mxGraphComponent(graphAdapter));
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
示例2: GKAGraph
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
private GKAGraph(GraphType type){
this.type = type;
// Choose if it will be directed or undirected
if (isDirected()){
jGraph = new ListenableDirectedGraph<>(new DirectedPseudograph<>(GKAEdge.class));
}else{
jGraph = new ListenableUndirectedGraph<>(new Pseudograph<>(GKAEdge.class));
}
// JGXAdapter for showing the Graph in Swing
mxgraph = new JGraphXAdapter<>(getjGraph());
// Changing EdgeStyle when is undirected
if (!isDirected()){
getMxgraph().getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_ENDARROW, "none");
}
setGraphConfig();
}
示例3: createCFG
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
public void createCFG() {
ProgramASTNode progNode = new ProgramASTNode(roots.toArray(new ASTNode[0]));
CFG cfg = progNode.createCFG();
JGraphXAdapter jgxAdapter = new JGraphXAdapter(cfg.getGraph());
jgxAdapter.setAutoSizeCells(true);
jgxAdapter.setCellsResizable(true);
// jgxAdapter.alignCells(mxConstants.ALIGN_CENTER);
mxStylesheet stylesheet = jgxAdapter.getStylesheet();
Hashtable<String, Object> style = new Hashtable<String, Object>();
style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
style.put(mxConstants.STYLE_OPACITY, 50);
style.put(mxConstants.STYLE_FONTCOLOR, "#774400");
stylesheet.putCellStyle("ROUNDED", style);
jgxAdapter.setStylesheet(stylesheet);
jgxAdapter.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
mxGraphComponent graphComponent = new mxGraphComponent(jgxAdapter);
graphComponent.setWheelScrollingEnabled(false);
mxGraphModel graphModel = (mxGraphModel)graphComponent.getGraph().getModel();
cfgPane.add(graphComponent);
mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapter);
layout.execute(jgxAdapter.getDefaultParent());
this.addMouseWheelListener(e -> {
mxGraphView view = graphComponent.getGraph().getView();
int notches = e.getWheelRotation();
double scale = view.getScale();
double newScale = view.getScale() - ((double) notches / 61.8033988272);
view.setScale(newScale);
});
cfgPane.revalidate();
cfgPane.repaint();
}
示例4: createAST
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
public void createAST() {
Logger.getAnonymousLogger().info(" Graph: " + graph);
ProgramASTNode progNode = new ProgramASTNode(roots.toArray(new ASTNode[0]));
JGraphXAdapter jgxAdapter = new JGraphXAdapter(progNode.getAST());
jgxAdapter.setAutoSizeCells(true);
jgxAdapter.setCellsResizable(true);
// jgxAdapter.alignCells(mxConstants.ALIGN_CENTER);
mxStylesheet stylesheet = jgxAdapter.getStylesheet();
Hashtable<String, Object> style = new Hashtable<String, Object>();
style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
style.put(mxConstants.STYLE_OPACITY, 50);
style.put(mxConstants.STYLE_FONTCOLOR, "#774400");
stylesheet.putCellStyle("ROUNDED", style);
jgxAdapter.setStylesheet(stylesheet);
jgxAdapter.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
mxGraphComponent graphComponent = new mxGraphComponent(jgxAdapter);
graphComponent.setWheelScrollingEnabled(false);
mxGraphModel graphModel = (mxGraphModel)graphComponent.getGraph().getModel();
astPane.add(graphComponent);
mxGraphLayout layout = new mxCompactTreeLayout(jgxAdapter, false);
layout.execute(jgxAdapter.getDefaultParent());
this.addMouseWheelListener(e -> {
mxGraphView view = graphComponent.getGraph().getView();
int notches = e.getWheelRotation();
double scale = view.getScale();
double newScale = view.getScale() - ((double) notches / 61.8033988272);
view.setScale(newScale);
System.out.println(scale + " -> " + newScale);
});
astPane.revalidate();
astPane.repaint();
}
示例5: createAndShowGui
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
private static <X,Y> void createAndShowGui(String title, ListenableGraph<X,Y> dw) {
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Map<String, Object> edgeStyle = new HashMap<String, Object>();
edgeStyle.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL);
edgeStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
edgeStyle.put(mxConstants.STYLE_STROKECOLOR, "#000000");
edgeStyle.put(mxConstants.STYLE_FONTCOLOR, "#000000");
edgeStyle.put(mxConstants.STYLE_NOLABEL, true);
mxStylesheet stylesheet = new mxStylesheet();
stylesheet.setDefaultEdgeStyle(edgeStyle);
JGraphXAdapter<X, Y> graphAdapter = new JGraphXAdapter<X, Y>(dw);
graphAdapter.setStylesheet(stylesheet);
mxCompactTreeLayout layout = new mxCompactTreeLayout(graphAdapter);
layout.setNodeDistance(30);
layout.setLevelDistance(60);
layout.execute(graphAdapter.getDefaultParent());
frame.add(new mxGraphComponent(graphAdapter));
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
frame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
}
示例6: saveGraph
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
private void saveGraph(UndirectedGraph<TupleWithTable, DefaultEdge> instancesGraph) {
JGraphXAdapter<TupleWithTable, DefaultEdge> jgxAdapterContext = new JGraphXAdapter<TupleWithTable, DefaultEdge>(instancesGraph);
jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_ENDARROW, "0");
jgxAdapterContext.setCellsEditable(false);
jgxAdapterContext.setCellsMovable(false);
jgxAdapterContext.setEdgeLabelsMovable(false);
jgxAdapterContext.setCellsDeletable(false);
jgxAdapterContext.setCellsDisconnectable(false);
jgxAdapterContext.setCellsResizable(false);
jgxAdapterContext.setCellsBendable(false);
JFrame frame = new JFrame();
mxGraphComponent mxGraphComponent = new mxGraphComponent(jgxAdapterContext);
frame.getContentPane().add(mxGraphComponent, BorderLayout.CENTER);
mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapterContext);
layout.execute(jgxAdapterContext.getDefaultParent());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Graph");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
try {
while (true) {
Thread.sleep(500);
}
} catch (InterruptedException ex) {
java.util.logging.Logger.getLogger(ComputeInstanceSimilarityBlock.class.getName()).log(Level.SEVERE, null, ex);
}
// try {
// BufferedImage image = mxCellRenderer.createBufferedImage(jgxAdapterContext, null, 1, Color.WHITE, true, null);
// ImageIO.write(image, "PNG", new File("/Temp/bart/similarity/instances-graph.png"));
// } catch (IOException ex) {
// logger.error("Unable to save graph image: " + ex.getLocalizedMessage());
// }
}
示例7: showTGDGraph
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
private void showTGDGraph(DirectedGraph<TGDStratum, DefaultEdge> strataGraph) {
JGraphXAdapter<TGDStratum, DefaultEdge> jgxAdapterContext = new JGraphXAdapter<TGDStratum, DefaultEdge>(strataGraph);
jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
// jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_ENDARROW, "0");
jgxAdapterContext.setCellsEditable(false);
jgxAdapterContext.setCellsMovable(false);
jgxAdapterContext.setEdgeLabelsMovable(false);
jgxAdapterContext.setCellsDeletable(false);
jgxAdapterContext.setCellsDisconnectable(false);
jgxAdapterContext.setCellsResizable(false);
jgxAdapterContext.setCellsBendable(false);
JFrame frame = new JFrame();
mxGraphComponent mxGraphComponent = new mxGraphComponent(jgxAdapterContext);
frame.getContentPane().add(mxGraphComponent, BorderLayout.CENTER);
mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapterContext);
layout.execute(jgxAdapterContext.getDefaultParent());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Graph");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
try {
BufferedImage image = mxCellRenderer.createBufferedImage(jgxAdapterContext, null, 1, Color.WHITE, true, null);
ImageIO.write(image, "PNG", new File("/Temp/llunatic/tgd-graph.png"));
} catch (IOException ex) {
logger.error("Unable to save graph image: " + ex.getLocalizedMessage());
}
}
示例8: showEGDGraph
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
private void showEGDGraph(DirectedGraph<EGDStratum, DefaultEdge> strataGraph) {
JGraphXAdapter<EGDStratum, DefaultEdge> jgxAdapterContext = new JGraphXAdapter<EGDStratum, DefaultEdge>(strataGraph);
jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
// jgxAdapterContext.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_ENDARROW, "0");
jgxAdapterContext.setCellsEditable(false);
jgxAdapterContext.setCellsMovable(false);
jgxAdapterContext.setEdgeLabelsMovable(false);
jgxAdapterContext.setCellsDeletable(false);
jgxAdapterContext.setCellsDisconnectable(false);
jgxAdapterContext.setCellsResizable(false);
jgxAdapterContext.setCellsBendable(false);
JFrame frame = new JFrame();
mxGraphComponent mxGraphComponent = new mxGraphComponent(jgxAdapterContext);
frame.getContentPane().add(mxGraphComponent, BorderLayout.CENTER);
mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapterContext);
layout.execute(jgxAdapterContext.getDefaultParent());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Graph");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
try {
BufferedImage image = mxCellRenderer.createBufferedImage(jgxAdapterContext, null, 1, Color.WHITE, true, null);
ImageIO.write(image, "PNG", new File("/Temp/llunatic/egd-graph.png"));
} catch (IOException ex) {
logger.error("Unable to save graph image: " + ex.getLocalizedMessage());
}
}
示例9: init
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
@Override
public void init() {
graph = new ListenableDirectedGraph<>(DefaultEdge.class);
adapter = new JGraphModelAdapter(graph);
jgraph = new JGraph(adapter);
adjustDisplaySettings(jgraph);
getContentPane( ).add(jgraph );
resize( DEFAULT_SIZE );
Main.main(null);
ProgramASTNode progNode = new ProgramASTNode(roots.toArray(new ASTNode[0]));
CFG cfg = progNode.createCFG();
// System.out.println(cfg.reduce());
// JGraph cfgGraph = new JGraph(new JGraphXAdapter(cfg.getGraph()));
JGraphXAdapter jgxAdapter = new JGraphXAdapter(cfg.getGraph());
jgxAdapter.setAutoSizeCells(true);
jgxAdapter.setCellsResizable(true);
// jgxAdapter.alignCells(mxConstants.ALIGN_CENTER);
mxStylesheet stylesheet = jgxAdapter.getStylesheet();
Hashtable<String, Object> style = new Hashtable<String, Object>();
style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
style.put(mxConstants.STYLE_OPACITY, 50);
style.put(mxConstants.STYLE_FONTCOLOR, "#774400");
stylesheet.putCellStyle("ROUNDED", style);
jgxAdapter.setStylesheet(stylesheet);
jgxAdapter.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
mxGraphComponent graphComponent = new mxGraphComponent(jgxAdapter);
graphComponent.setWheelScrollingEnabled(false);
mxGraphModel graphModel = (mxGraphModel)graphComponent.getGraph().getModel();
// Collection<Object> cells = graphModel.getCells().values();
// mxUtils.setCellStyles(graphComponent.getGraph().getModel(),
// cells.toArray(), mxConstants.STYLE_ENDARROW, mxConstants.NONE);
getContentPane().add(graphComponent);
mxHierarchicalLayout layout = new mxHierarchicalLayout(jgxAdapter);
layout.execute(jgxAdapter.getDefaultParent());
this.addMouseWheelListener(e -> {
mxGraphView view = graphComponent.getGraph().getView();
int notches = e.getWheelRotation();
double scale = view.getScale();
double newScale = view.getScale() - ((double) notches / 61.8033988272);
view.setScale(newScale);
});
// adjustDisplaySettings(cfgGraph);
// getContentPane().add(cfgGraph);
// final JGraphTreeLayout hir = new JGraphTreeLayout();
// final JGraphFacade graphFacade = new JGraphFacade(cfgGraph, new Object[] {cfg.start});
// graphFacade.setOrdered(true);
// hir.setPositionMultipleTrees(true);
// hir.setTreeDistance(50);
// hir.setLevelDistance(50);
// hir.run(graphFacade);
// final Map nestedMap = graphFacade.createNestedMap(true, true);
// cfgGraph.getGraphLayoutCache().edit(nestedMap);
// SwingUtilities.invokeLater(() -> {
// mxGraphView view = graphComponent.getGraph().getView();
// int compLen = graphComponent.getWidth();
// int viewLen = (int)view.getGraphBounds().getWidth();
// System.out.println("Complen: " + compLen + ", viewlen: " + viewLen);
// System.out.println("Scale: " + (double)compLen/viewLen * view.getScale());
// view.setScale(2);
// });
}
示例10: update
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
public void update() {
app.updating = true;
NARGraph g = new NARGraph();
g.add(nar, filter,
new NARGraph.DefaultGraphizer(true,true,false,false,showSyntax)
);
app.graph = g;
// create a visualization using JGraph, via an adapter
JGraphXAdapter layout = new JGraphXAdapter(g) {
};
app.layout = layout;
/*
mxCompactTreeLayout layout2 =
new mxCompactTreeLayout(jgxAdapter);
layout2.setUseBoundingBox(false);
layout2.setResizeParent(true);
layout2.setLevelDistance(30);
layout2.setNodeDistance(50);
layout2.execute(jgxAdapter.getDefaultParent());
*/
mxFastOrganicLayout l =
//new mxCompactTreeLayout(jgxAdapter);
new mxFastOrganicLayout(layout);
//new mxCircleLayout(jgxAdapter);
l.setForceConstant(edgeDistance*10f);
l.execute(layout.getDefaultParent());
/*
mxOrganicLayout layout =
//new mxCompactTreeLayout(jgxAdapter);
new mxOrganicLayout(jgxAdapter);
//new mxCircleLayout(jgxAdapter);
layout.setEdgeLengthCostFactor(0.001);*/
app.updating = false;
}
示例11: JGraphXGraphPanel
import org.jgrapht.ext.JGraphXAdapter; //导入依赖的package包/类
public JGraphXGraphPanel(NAR n) {
super(new BorderLayout());
NARGraph g = new NARGraph();
g.add(n, IncludeEverything, new NARGraph.DefaultGraphizer(true,true,true,true,true));
// create a visualization using JGraph, via an adapter
jgxAdapter = new JGraphXAdapter(g) {
};
mxGraphComponent mxc = new mxGraphComponent(jgxAdapter) {
};
mxc.setAntiAlias(true);
mxc.setConnectable(false);
mxc.setExportEnabled(false);
mxc.setFoldingEnabled(false);
mxc.setPanning(true);
mxc.setTextAntiAlias(true);
add(new JScrollPane(mxc), BorderLayout.CENTER);
mxFastOrganicLayout layout =
//new mxCompactTreeLayout(jgxAdapter);
new mxFastOrganicLayout(jgxAdapter);
//new mxCircleLayout(jgxAdapter);
layout.setForceConstant(150);
layout.execute(jgxAdapter.getDefaultParent());
/*
mxOrganicLayout layout =
//new mxCompactTreeLayout(jgxAdapter);
new mxOrganicLayout(jgxAdapter);
//new mxCircleLayout(jgxAdapter);
layout.setEdgeLengthCostFactor(0.001);*/
/*
mxCompactTreeLayout layout =
new mxCompactTreeLayout(jgxAdapter);
layout.setLevelDistance(40);
layout.setNodeDistance(50);
layout.execute(jgxAdapter.getDefaultParent());*/
jgxAdapter.setConnectableEdges(false);
jgxAdapter.setCellsDisconnectable(false);
jgxAdapter.setEdgeLabelsMovable(false);
//jgxAdapter.setCellsLocked(true);
}