本文整理汇总了Java中edu.uci.ics.jung.algorithms.layout.SpringLayout类的典型用法代码示例。如果您正苦于以下问题:Java SpringLayout类的具体用法?Java SpringLayout怎么用?Java SpringLayout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SpringLayout类属于edu.uci.ics.jung.algorithms.layout包,在下文中一共展示了SpringLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildJungLayout
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
@Override
protected Layout<GraphNode,GraphEdge> buildJungLayout(
DirectedGraph<GraphNode, GraphEdge> jungGraph,
Dimension layoutSize) {
SpringLayout<GraphNode, GraphEdge> result =
new SpringLayout<GraphNode, GraphEdge>(jungGraph);
result.setSize(layoutSize);
if (force.isSet()) {
result.setForceMultiplier(force.getValue());
}
if (range.isSet()) {
result.setRepulsionRange(range.getValue());
}
if (stretch.isSet()) {
result.setStretch(stretch.getValue());
}
return result;
}
示例2: getLayout
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
private static AbstractLayout<Vertex, Edge> getLayout(GraphJung<Graph> graph, String layoutName) {
switch (layoutName) {
case "KKLayout":
return new KKLayout<>(graph);
case "CircleLayout":
return new CircleLayout<>(graph);
case "FRLayout":
return new FRLayout<>(graph);
case "FRLayout2":
return new FRLayout2<>(graph);
case "ISOMLayout":
return new ISOMLayout<>(graph);
case "SpringLayout":
return new SpringLayout<>(graph);
default:
return new KKLayout<>(graph);
}
}
示例3: doSpringLayout
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
private void doSpringLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, int repulsion) {
SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
layout.setInitializer(initializer(graphLayout));
layout.setSize(size);
layout.setRepulsionRange(repulsion);
int count = 0;
while(!layout.done() && count < 700) {
layout.step();
count++;
}
for(VertexRef v : jungGraph.getVertices()) {
graphLayout.setLocation(v, (int)layout.getX(v), (int)layout.getY(v));
}
}
示例4: newLayout
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
private Layout<Node, Edge> newLayout(final Diagram diagram) {
final Layout<Node, Edge> diagramLayout;
if (layout != null && layout.startsWith("spring")) {
diagramLayout = new SpringLayout<Node, Edge>(diagram, new ConstantTransformer(Integer.parseInt(config("spring", "100"))));
} else if (layout != null && layout.startsWith("kk")) {
Distance<Node> distance = new DijkstraDistance<Node, Edge>(diagram);
if (layout.endsWith("unweight")) {
distance = new UnweightedShortestPath<Node, Edge>(diagram);
}
diagramLayout = new KKLayout<Node, Edge>(diagram, distance);
} else if (layout != null && layout.equalsIgnoreCase("circle")) {
diagramLayout = new CircleLayout<Node, Edge>(diagram);
} else if (layout != null && layout.equalsIgnoreCase("fr")) {
diagramLayout = new FRLayout<Node, Edge>(diagram);
} else {
final LevelLayout levelLayout = new LevelLayout(diagram);
levelLayout.adjust = adjust;
diagramLayout = levelLayout;
}
return diagramLayout;
}
示例5: getCombos
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
/**
* @return
*/
@SuppressWarnings("unchecked")
private Class<? extends Layout>[] getCombos()
{
List<Class<? extends Layout>> layouts = new ArrayList<Class<? extends Layout>>();
layouts.add(KKLayout.class);
layouts.add(FRLayout.class);
layouts.add(CircleLayout.class);
layouts.add(SpringLayout.class);
layouts.add(SpringLayout2.class);
layouts.add(ISOMLayout.class);
return layouts.toArray(new Class[0]);
}
示例6: getCombos
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
/**
* @return
*/
@SuppressWarnings("unchecked")
private static Class<? extends Layout>[] getCombos()
{
List<Class<? extends Layout>> layouts = new ArrayList<Class<? extends Layout>>();
layouts.add(KKLayout.class);
layouts.add(FRLayout.class);
layouts.add(CircleLayout.class);
layouts.add(SpringLayout.class);
layouts.add(SpringLayout2.class);
layouts.add(ISOMLayout.class);
return layouts.toArray(new Class[0]);
}
示例7: updateLayoutGraph
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
private void updateLayoutGraph()
{
Layout<Vertex,Edge> newlayout = null;
if(((String)layoutChoiceComboBox.getSelectedItem()).equals("FRLayout"))
{
newlayout = new FRLayout<Vertex,Edge>(sequenceGraph);
((FRLayout<Vertex,Edge>)newlayout).setMaxIterations(200);
}
else if(((String)layoutChoiceComboBox.getSelectedItem()).equals("KKLayout"))
{
newlayout = new KKLayout<Vertex,Edge>(sequenceGraph);
((KKLayout<Vertex,Edge>)newlayout).setMaxIterations(200);
}
else if(((String)layoutChoiceComboBox.getSelectedItem()).equals("SpringLayout"))
{
newlayout = new SpringLayout<Vertex,Edge>(sequenceGraph);
}
else if(((String)layoutChoiceComboBox.getSelectedItem()).equals("ISOMLayout"))
{
newlayout = new ISOMLayout<Vertex,Edge>(sequenceGraph);
}
else
{
throw new Error("Error choice: wrong layout name");
}
newlayout.setInitializer(networkCanvas.getGraphLayout());
newlayout.setSize(networkCanvas.getSize());
LayoutTransition<Vertex,Edge> transition =
new LayoutTransition<Vertex,Edge>(networkCanvas, networkCanvas.getGraphLayout(), newlayout);
Animator animator = new Animator(transition);
animator.start();
networkCanvas.getRenderContext().getMultiLayerTransformer().setToIdentity(); // What is the use of those lines ?
networkCanvas.repaint();
}
示例8: DependencyGraphScene
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
DependencyGraphScene(ObservableGraph<ArtifactGraphNode, ArtifactGraphEdge> graph, DelegateForest<ArtifactGraphNode, ArtifactGraphEdge> forest, MavenProject prj, Project nbProj, DependencyGraphTopComponent tc,
POMModel model) {
super(graph, new FRLayout<>(forest));
layoutModel = new DefaultComboBoxModel<>();
layoutModel.addElement(layout());
// These rarely work but look nice when they do
// layoutModel.addElement(new BalloonLayout<>(forest));
// layoutModel.addElement(new RadialTreeLayout<>(forest));
layoutModel.addElement(new CircleLayout<>(graph));
layoutModel.addElement(new FRLayout<>(graph));
layoutModel.addElement(new FRLayout2<>(graph));
layoutModel.addElement(new KKLayout<>(graph));
TreeLayout<ArtifactGraphNode, ArtifactGraphEdge> treeLayout = new TreeLayout<>(forest, 200, 90);
layoutModel.addElement(treeLayout);
layoutModel.addElement(new ISOMLayout<>(graph));
layoutModel.addElement(new SpringLayout<>(graph));
layoutModel.addElement(new SpringLayout2<>(graph));
layoutModel.setSelectedItem(layout());
moveAction = ActionFactory.createMoveAction(null, new MP());
this.forest = forest;
project = prj;
nbProject = nbProj;
this.tc = tc;
this.model = model;
mainLayer = new LayerWidget(this);
addChild(mainLayer);
connectionLayer = new LayerWidget(this);
addChild(connectionLayer);
//getActions().addAction(this.createObjectHoverAction());
getActions().addAction(hoverAction);
getActions().addAction(ActionFactory.createSelectAction(allActionsP));
getActions().addAction(zoomAction);
getActions().addAction(panAction);
getActions().addAction(editAction);
getActions().addAction(popupMenuAction);
getActions().addAction(new ScrollWheelZoomAction());
}
示例9: TradeNetworkView
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
public TradeNetworkView(
final TradeNetworkReport tradeNetwork) {
this.tradeNetwork = tradeNetwork;
myGraph = new DirectedSparseGraph<Agent, WeightedEdge>();
layout = new SpringLayout<Agent, WeightedEdge>(myGraph);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
intialiseGUI();
}
});
}
示例10: LayoutSpring2D
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
public LayoutSpring2D(Graph2D graph){
super(graph, false);
mDimension = new Dimension(1000, 1000);
mStretch = 0.7;
mRepulsionRange = 100;
mForceMultiplier = 1.0 / 3.0;
mLayout = new SpringLayout<>(mGraph.getGraph(), mLengthFunction);
mLayout.setStretch(mStretch);
mLayout.setRepulsionRange(mRepulsionRange);
mLayout.setForceMultiplier(mForceMultiplier);
mLayout.setSize(mDimension);
}
示例11: createDefaultCombobox
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
public static CLayoutCombobox createDefaultCombobox() {
CLayoutCombobox chooser = new CLayoutCombobox();
chooser.addLayoutClass(KCircleLayout.class, "Circle");
chooser.addLayoutClass(FRLayout.class, "Fruchterman-Reingold");
chooser.addLayoutClass(KKLayout.class, "Kamada-Kawai");
chooser.addLayoutClass(SpringLayout.class, "Spring");
//chooser.addLayoutClass(SpringLayout2.class, "Spring2");
//chooser.addLayoutClass(ISOMLayout.class, "Self-Organizing Map");
return chooser;
}
示例12: init
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
@Override
public void init() {
//create a graph
Graph<Number,Number> ig = Graphs.<Number,Number>synchronizedDirectedGraph(new DirectedSparseMultigraph<Number,Number>());
ObservableGraph<Number,Number> og = new ObservableGraph<Number,Number>(ig);
og.addGraphEventListener(new GraphEventListener<Number,Number>() {
public void handleGraphEvent(GraphEvent<Number, Number> evt) {
System.err.println("got "+evt);
}});
this.g = og;
//create a graphdraw
layout = new FRLayout2<Number,Number>(g);
// ((FRLayout)layout).setMaxIterations(200);
vv = new VisualizationViewer<Number,Number>(layout, new Dimension(600,600));
JRootPane rp = this.getRootPane();
rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
getContentPane().setLayout(new BorderLayout());
getContentPane().setBackground(java.awt.Color.lightGray);
getContentPane().setFont(new Font("Serif", Font.PLAIN, 12));
vv.getModel().getRelaxer().setSleepTime(500);
vv.setGraphMouse(new DefaultModalGraphMouse<Number,Number>());
vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>());
vv.setForeground(Color.white);
getContentPane().add(vv);
switchLayout = new JButton("Switch to SpringLayout");
switchLayout.addActionListener(new ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent ae) {
Dimension d = new Dimension(600,600);
if (switchLayout.getText().indexOf("Spring") > 0) {
switchLayout.setText("Switch to FRLayout");
layout = new SpringLayout<Number,Number>(g,
new ConstantTransformer(EDGE_LENGTH));
layout.setSize(d);
vv.getModel().setGraphLayout(layout, d);
} else {
switchLayout.setText("Switch to SpringLayout");
layout = new FRLayout<Number,Number>(g, d);
vv.getModel().setGraphLayout(layout, d);
}
}
});
getContentPane().add(switchLayout, BorderLayout.SOUTH);
timer = new Timer();
}
示例13: switchLayout
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
public void switchLayout(GraphLayout type) {
Layout<N, EdgeWrapper<E>> layout = null;
switch (type) {
case KKLayout:
layout = new KKLayout<N, EdgeWrapper<E>>(graph);
break;
case FRLayout:
layout = new FRLayout<N, EdgeWrapper<E>>(graph);
break;
case ISOMLayout:
layout = new ISOMLayout<N, EdgeWrapper<E>>(graph);
break;
case SpringLayout:
layout = new SpringLayout<N, EdgeWrapper<E>>(graph);
break;
case CircleLayout:
layout = new CircleLayout<N, EdgeWrapper<E>>(graph);
break;
case FRLayout2:
layout = new FRLayout2<N, EdgeWrapper<E>>(graph);
break;
case SpringLayout2:
layout = new SpringLayout2<N, EdgeWrapper<E>>(graph);
break;
default:
break;
}
if (graph.getVertexCount() < 100) {
layout.setInitializer(vv.getGraphLayout());
layout.setSize(getSize());
LayoutTransition<N, EdgeWrapper<E>> lt = new LayoutTransition<N, EdgeWrapper<E>>(vv, vv.getGraphLayout(),
layout);
Animator animator = new Animator(lt);
animator.start();
vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
repaint(500);
} else {
vv.setModel(new DefaultVisualizationModel<N, EdgeWrapper<E>>(layout));
repaint(500);
}
}
示例14: createLayout
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的package包/类
private Layout createLayout(G graph, String layout, double repultion , double attraction, int maxIterations, double nodeDensity) {
PersistentLayout test = null;
if (layout.equals("CircleLayout")) {
CircleLayout circleLayoutLayout = new CircleLayout<String, String>(graph);
test = new MyPersistentLayoutImpl(circleLayoutLayout);
} else if (layout.equals("KKLayout")) {
KKLayout kkLayout = new KKLayout<String, String>(graph);
kkLayout.setMaxIterations(maxIterations);
test = new MyPersistentLayoutImpl(kkLayout);
} else if (layout.equals("SpringLayout")) {
test = new MyPersistentLayoutImpl(new SpringLayout<String, String>(graph));
} else if (layout.equals("SpringLayout2")) {
test = new MyPersistentLayoutImpl(new SpringLayout2<String, String>(graph));
} else if (layout.equals("ISOMLayout")) {
test = new MyPersistentLayoutImpl(new ISOMLayout<String, String>(graph));
} else if (layout.equals("FRLayout2")) {
FRLayout2 frLayout2 = new FRLayout2<String, String>(graph);
frLayout2.setRepulsionMultiplier(10);
test = new MyPersistentLayoutImpl(frLayout2);
}
else {
FRLayout frLayout = new FRLayout<String, String>(graph);
frLayout.setRepulsionMultiplier(repultion);
frLayout.setAttractionMultiplier(attraction);
frLayout.setMaxIterations(maxIterations);
test = new MyPersistentLayoutImpl(frLayout);
}
int vertexCount = currentGraph.getVertexCount();
Dimension parent1 = parent.getSize();
int x = (int) (Math.sqrt(vertexCount / nodeDensity));
int y = (int) (Math.sqrt(vertexCount / nodeDensity));
if (x < parent1.width) {
x = parent1.width - 50;
} else {
x = x * (parent1.width - 50) / 1000;
}
if (y < parent1.height) {
y = parent1.height - 150;
} else {
y = y * (parent1.height - 150) / 1000;
}
if (parent1.height*parent1.width > Integer.MAX_VALUE){
x=7680;
y=4320;
}
// i
System.out.println("X: " + x + "Y: " + y + "width: " + parent1.width + "heigth: " + parent1.height);
test.setSize(new Dimension(new Dimension(x, y)));
return test;
}
示例15: visualize
import edu.uci.ics.jung.algorithms.layout.SpringLayout; //导入依赖的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);
}