private void groupCluster(AggregateLayout<Number,Number> layout, Set<Number> vertices) { if(vertices.size() < layout.getGraph().getVertexCount()) { Point2D center = layout.apply(vertices.iterator().next()); Graph<Number,Number> subGraph = SparseMultigraph.<Number,Number>getFactory().get(); for(Number v : vertices) { subGraph.addVertex(v); } Layout<Number,Number> subLayout = new CircleLayout<Number,Number>(subGraph); subLayout.setInitializer(vv.getGraphLayout()); subLayout.setSize(new Dimension(40,40)); layout.put(subLayout,center); vv.repaint(); } } }
public void actionPerformed(ActionEvent arg0) { JComboBox jcb = (JComboBox)arg0.getSource(); Object[] constructorArgs = {panelcan.graph}; Class layoutC = (Class)LAYOUTS.get(jcb.getSelectedItem()); try { Constructor constructor = layoutC.getConstructor(new Class[]{Graph.class}); Object o = constructor.newInstance(constructorArgs); Layout l = (Layout)o; l.setSize(panelcan.vv.getSize()); panelcan.layout.removeAll(); panelcan.layout.setDelegate(l); // set zoom to identity panelcan.vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); l_zoom_slider.setValue(50); panelcan.reinitializeCanvas(); } catch(Exception e) { e.printStackTrace(); } } }
/** * Adds the agent. * * @param agent The agent to add. */ public void addAgent(Component agent) { graph.addVertexElement(agent); VisRunner runner = new VisRunner((IterativeContext)layout); layout.initialize(); runner.prerelax(); visible_agents.add(agent); }
/** * Groups a cluster (set) of agents into a sublayout. * * @param vertices */ protected void groupCluster(Set vertices) { if(vertices.size() > 1 && vertices.size() < graph.getVertexCount()) { // if(vertices.size() < layout.getGraph().getVertexCount()) { Point2D center = layout.transform(vertices.iterator().next()); Graph subGraph = (Graph)graphFactory.create(); for(Iterator it = vertices.iterator(); it.hasNext();) { subGraph.addVertex(it.next()); } Layout subLayout = new GraphCircleLayout(subGraph); subLayout.setInitializer(vv.getGraphLayout()); subLayout.setSize(new Dimension(40, 40)); layout.put(subLayout, center); } }
double y = 0; for(String vertex : picked) { Point2D p = clusteringLayout.apply(vertex); x += p.getX(); y += p.getY(); subLayout.setInitializer(vv.getGraphLayout()); subLayout.setSize(subLayoutSize); clusteringLayout.put(subLayout,center); vv.setGraphLayout(clusteringLayout); this.clusteringLayout.removeAll(); vv.setGraphLayout(clusteringLayout);
public void setLocation(V v, Point2D location) { boolean wasInSublayout = false; for(Layout<V,E> layout : layouts.keySet()) { if(layout.getGraph().getVertices().contains(v)) { Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(-center.getX()+d.width/2,-center.getY()+d.height/2); Point2D localLocation = at.transform(location, null); layout.setLocation(v, localLocation); wasInSublayout = true; } } if(wasInSublayout == false && getGraph().getVertices().contains(v)) { delegate.setLocation(v, location); } }
layout = new AggregateLayout(new KKLayout(graph)); layout.setSize(new Dimension(300, 300)); staticLayout = new StaticLayout(graph, layout); vv = new VisualizationViewer(staticLayout);
layout.initialize(); staticLayout.setSize(layout.getSize()); GraphLayoutTransition lt = new GraphLayoutTransition(vv, vv.getGraphLayout(), staticLayout);
clusteringLayout = new AggregateLayout<String,Number>(new FRLayout<String,Number>(graph));
public void itemStateChanged(ItemEvent e) { if(e.getStateChange() == ItemEvent.SELECTED) { @SuppressWarnings({ "unchecked", "rawtypes" }) Class<CircleLayout> clazz = (Class<CircleLayout>)e.getItem(); try { Layout<String,Number> layout = getLayoutFor(clazz, graph); layout.setInitializer(vv.getGraphLayout()); clusteringLayout.setDelegate(layout); vv.setGraphLayout(clusteringLayout); } catch(Exception ex) { ex.printStackTrace(); } } }});
/** * Lock agent postions. */ protected void lockAgents() { // lock positions of all vertices for initializing only new vertices for(Iterator it = graph.getVertices().iterator(); it.hasNext();) { layout.lock(it.next(), true); } }
/** * @param v * @param location * @see edu.uci.ics.jung.algorithms.layout.Layout#setLocation(java.lang.Object, java.awt.geom.Point2D) */ public void setLocation(V v, Point2D location) { boolean wasInSublayout = false; for(Layout<V,E> layout : layouts.keySet()) { if(layout.getGraph().getVertices().contains(v)) { Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(-center.getX()+d.width/2,-center.getY()+d.height/2); Point2D localLocation = at.transform(location, null); layout.setLocation(v, localLocation); wasInSublayout = true; } } if(wasInSublayout == false && getGraph().getVertices().contains(v)) { delegate.setLocation(v, location); } }
layout.initialize(); staticLayout.setSize(layout.getSize()); GraphLayoutTransition lt = new GraphLayoutTransition(vv, vv.getGraphLayout(), staticLayout);
new AggregateLayout<Number,Number>(new FRLayout<Number,Number>(graph));
/** * Unlock agent positions */ protected void unlockAgents() { // unlock all vertices again for(Iterator it = graph.getVertices().iterator(); it.hasNext();) { layout.lock(it.next(), false); } }