本文整理汇总了Java中edu.uci.ics.jung.visualization.VisualizationViewer类的典型用法代码示例。如果您正苦于以下问题:Java VisualizationViewer类的具体用法?Java VisualizationViewer怎么用?Java VisualizationViewer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VisualizationViewer类属于edu.uci.ics.jung.visualization包,在下文中一共展示了VisualizationViewer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MoveGraphNodes
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
/**
* Instantiates a new UndoableEdit for the movements of GraphNode's.
*
* @param graphController the graph controller
* @param visViewer the vis viewer
* @param nodesMovedOldPositions the nodes moved old positions
*/
public MoveGraphNodes(GraphEnvironmentController graphController, VisualizationViewer<GraphNode,GraphEdge> visViewer, HashMap<String, Point2D> nodesMovedOldPositions) {
this.graphController = graphController;
this.visViewer = visViewer;
this.nodesMovedOldPositions = nodesMovedOldPositions;
// --- evaluate the current positions ---
this.nodesMovedNewPositions = new HashMap<String, Point2D>();
for(String nodeID : this.nodesMovedOldPositions.keySet()) {
GraphElement graphElement = this.graphController.getNetworkModel().getGraphElement(nodeID);
if (graphElement instanceof GraphNode) {
GraphNode node = (GraphNode) this.graphController.getNetworkModel().getGraphElement(nodeID);
if (node!=null) {
Point2D point = new Point2D.Double(node.getPosition().getX(), node.getPosition().getY());
this.nodesMovedNewPositions.put(node.getId(), point);
}
}
}
this.sendNodesMovedNotification();
}
示例2: pickContainedVertices
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
@Override
protected void pickContainedVertices(VisualizationViewer<GraphNode, GraphEdge> vv, Point2D down,Point2D out, boolean clear) {
super.pickContainedVertices(vv, down, out, clear);
NetworkModelAdapter netAdapter = this.basicGraphGUI.getGraphEnvironmentController().getNetworkModelAdapter();
// --- Get the selected nodes ----------------
Set<GraphNode> nodesSelected = this.getVisViewer().getPickedVertexState().getPicked();
// --- Get the related NetworkComponent's ----
HashSet<NetworkComponent> components = netAdapter.getNetworkComponentsFullySelected(nodesSelected);
if (components!=null) {
// --- Run through NetworkComponents -----
for (NetworkComponent networkComponent : components) {
Vector<GraphElement> elements = netAdapter.getGraphElementsFromNetworkComponent(networkComponent);
for (GraphElement graphElement : elements) {
if (graphElement instanceof GraphEdge) {
this.getVisViewer().getPickedEdgeState().pick((GraphEdge) graphElement, true);
}
}
}
}
}
示例3: handlePopup
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
/**
* Implementation of the AbstractPopupGraphMousePlugin method. This is where the
* work gets done. You shouldn't have to modify unless you really want to...
* @param me the MousEvent
*/
protected void handlePopup(MouseEvent me) {
Point2D p = me.getPoint();
VisualizationViewer<GraphNode,GraphEdge> visView = this.basicGraphGui.getVisualizationViewer();
GraphElementAccessor<GraphNode,GraphEdge> pickSupport = visView.getPickSupport();
if(pickSupport != null) {
GraphNode vertex = (GraphNode) pickSupport.getVertex(visView.getGraphLayout(), p.getX(), p.getY());
if(vertex != null) {
//System.out.println("Vertex " + v + " was right clicked");
this.updateVertexMenu(vertex);
vertexPopup.show(visView, me.getX(), me.getY());
basicGraphGui.handleObjectRightClick(vertex);
} else {
GraphEdge edge = (GraphEdge) pickSupport.getEdge(visView.getGraphLayout(), p.getX(), p.getY());
if(edge != null) {
//System.out.println("Edge " + edge + " was right clicked");
this.updateEdgeMenu(edge);
edgePopup.show(visView, me.getX(), me.getY());
basicGraphGui.handleObjectRightClick(edge);
}
}
}
}
示例4: zoomOneToOneMoveFocus
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
/**
* Zoom one to one and move the focus, so that the elements as visible.
* @param visViewer the VisualizationViewer
*/
private void zoomOneToOneMoveFocus(VisualizationViewer<GraphNode, GraphEdge> visViewer) {
visViewer.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
visViewer.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
Graph<GraphNode, GraphEdge> graph = visViewer.getGraphLayout().getGraph();
Rectangle2D graphDimension = GraphGlobals.getGraphSpreadDimension(graph);
double moveXOnVisView = graphDimension.getX();
double moveYOnVisView = graphDimension.getX();
if (moveXOnVisView<=graphMargin) {
moveXOnVisView = 0;
} else {
moveXOnVisView = (graphMargin-graphDimension.getX());
}
if (moveYOnVisView<=graphMargin) {
moveYOnVisView = 0;
} else {
moveYOnVisView = (graphMargin-graphDimension.getY());
}
if ((moveXOnVisView!=0 || moveYOnVisView!=0)) {
visViewer.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(moveXOnVisView, moveYOnVisView);
}
}
示例5: pickContainedVertices
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
/**
* pick the vertices inside the rectangle created from points
* 'down' and 'out'
*/
protected void pickContainedVertices( VisualizationViewer<Room, Exit> vv, Point2D down, Point2D out, boolean clear ) {
Layout<Room, Exit> layout = vv.getGraphLayout();
PickedState<Room> pickedVertexState = vv.getPickedVertexState();
Rectangle2D pickRectangle = new Rectangle2D.Double();
pickRectangle.setFrameFromDiagonal( down, out );
if (pickedVertexState != null) {
if (clear) {
pickedVertexState.clear();
}
GraphElementAccessor<Room, Exit> pickSupport = vv.getPickSupport();
Collection<Room> picked = pickSupport.getVertices( layout, pickRectangle );
for (Room v : picked) {
pickedVertexState.pick( v, true );
}
}
}
示例6: renderElement
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
@Override
public void renderElement(JPanel jp, Object elem) {
if (elem instanceof ViwnNode) {
ViwnNode vn = (ViwnNode) elem;
// one node visualisation
Graph<ViwnNode, ViwnEdge> g = new DirectedSparseGraph<>();
g.addVertex(vn);
VisualizationViewer<ViwnNode, ViwnEdge> vv = new VisualizationViewer<>(new StaticLayout<>(g));
vv.getRenderer().setVertexRenderer(new ViwnVertexRenderer(vv.getRenderer().getVertexRenderer()));
vv.getRenderContext().setVertexShapeTransformer((ViwnNode v) -> v.getShape());
vv.getRenderContext().setVertexFillPaintTransformer(new ViwnVertexFillColor(vv.getPickedVertexState(), null));
vv.setVertexToolTipTransformer(new ViwnVertexToolTipTransformer());
vv.setPreferredSize(new Dimension(110, 50));
Point2D q = vv.getGraphLayout().transform(vn);
Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(lvc.getX() - q.getX(), lvc.getY() - q.getY());
jp.add(vv, "vfill br");
}
}
示例7: run
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
@Override
public void run() {
visualizationViewer = new VisualizationViewer<Vertex, Edge>(layout);
synchronized (this) {
this.notifyAll();
}
while(running) {
try {
System.out.println("Running a task");
tasks.take().run();
System.out.println("Finished a task");
} catch (InterruptedException e) {
JOptionPane.showMessageDialog(null, "Could not execute VisualizationViewer Task", "Visualization error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
}
示例8: getVisualizationViewer
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
/**
* Getter for JUNG's VisualizationViewer, creating it if it does not exist
*
* @return VisualizationViewer
*/
public VisualizationViewer<Vertex, Edge> getVisualizationViewer() {
// Create it if it didn't exist before
if (visualizationViewer == null) {
if (layout == null) {
synchronized (this) {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
visualizationViewer = new VisualizationViewer<Vertex, Edge>(layout, new Dimension(width, height));
visualizationViewer.setBackground(Color.WHITE);
}
return visualizationViewer;
}
示例9: handlePopup
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void handlePopup(MouseEvent e) {
final VisualizationViewer<V,E> vv =
(VisualizationViewer<V,E>)e.getSource();
Point2D p = e.getPoint();
GraphElementAccessor<V,E> pickSupport = vv.getPickSupport();
if(pickSupport != null) {
final V v = pickSupport.getVertex(vv.getGraphLayout(), p.getX(), p.getY());
if(v != null) {
updateVertexMenu(v, networkPanel, p);
vertexPopup.show(vv, e.getX(), e.getY());
} else {
final E edge = pickSupport.getEdge(vv.getGraphLayout(), p.getX(), p.getY());
if(edge != null) {
updateEdgeMenu(edge, networkPanel, p);
edgePopup.show(vv, e.getX(), e.getY());
}
}
}
}
示例10: getClickedElement
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
private GraphElement getClickedElement( VisualizationViewer<SEMOSSVertex, SEMOSSEdge> viewer,
double x, double y ) {
GraphElementAccessor<SEMOSSVertex, SEMOSSEdge> pickSupport
= viewer.getPickSupport();
SEMOSSVertex vert = pickSupport.getVertex( viewer.getGraphLayout(), x, y );
if ( null != vert ) {
return vert;
}
SEMOSSEdge edge = pickSupport.getEdge( viewer.getGraphLayout(), x, y );
if ( null != edge ) {
return edge;
}
return null;
}
示例11: handleRightClick
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
protected Set<SEMOSSVertex> handleRightClick(
VisualizationViewer<SEMOSSVertex, SEMOSSEdge> viewer,
GraphElement ele, MouseEvent e ) {
logger.debug( "The user right clicked." );
Set<SEMOSSVertex> vertHash = new HashSet<>();
Set<SEMOSSVertex> pickedVertices = viewer.getPickedVertexState().getPicked();
vertHash.addAll( pickedVertices );
SEMOSSVertex[] vertices
= pickedVertices.toArray( new SEMOSSVertex[pickedVertices.size()] );
// for now...
new GraphNodePopup( gps, ele, vertices, forTree ).show( e );
return vertHash;
}
示例12: mouseDragged
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
/**
* If startVertex is non-null, stretch an edge shape between startVertex and
* the mouse pointer to simulate edge creation
*/
@SuppressWarnings( "unchecked" )
@Override
public void mouseDragged( MouseEvent e ) {
if ( checkModifiers( e ) ) {
VisualizationViewer<V, E> vv
= (VisualizationViewer<V, E>) e.getSource();
if ( createMode == Creating.EDGE ) {
edgeSupport.midEdgeCreate( vv, e.getPoint() );
}
else if ( createMode == Creating.VERTEX ) {
vertexSupport.midVertexCreate( vv, e.getPoint() );
}
else if ( Creating.MOVE == createMode ) {
vv.getGraphLayout().setLocation( moveVertex, e.getPoint() );
}
}
}
示例13: mousePressed
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
if (checkModifiers(e)) {
startVertex = null;
down = null;
GUINode guiNode = canvas.getVertex(e);
Node node = guiNode == null? null : guiNode.getAssociatedNode();
if (node != null) {
final VisualizationViewer<GUINode, GUILink> vv = (VisualizationViewer<GUINode, GUILink>) e.getSource();
startVertex = guiNode;
down = e.getPoint();
transformEdgeShape(down, down);
vv.addPostRenderPaintable(edgePaintable);
transformArrowShape(down, e.getPoint());
vv.addPostRenderPaintable(arrowPaintable);
e.consume();
}
}
}
示例14: setUpView
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
private void setUpView(Graph graph)
{
// layout = new SpringLayout2(graph);
layout = new KKLayout(graph);
//layout.setSize(new Dimension(700,700));
vv = new VisualizationViewer(layout);
vv.setPreferredSize(new Dimension(900,900));
vv.setBackground( Color.white );
// Tell the renderer to use our own customized label rendering
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
getContentPane().add(new GraphZoomScrollPane(vv), BorderLayout.CENTER);
/*Mouse controller plugins*/
PluggableGraphMouse gm = new PluggableGraphMouse();
gm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON3_MASK));
gm.add(new ScalingGraphMousePlugin(new CrossoverScalingControl(), 0, 1.1f, 0.9f));
gm.add(new PickingGraphMousePlugin());
vv.setGraphMouse(gm);
}
示例15: getVertexPaintTransformer
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入依赖的package包/类
@Override
public Transformer<String, Paint> getVertexPaintTransformer(VisualizationViewer<String, String> viewer) {
return new Transformer<String, Paint>() {
@Override
public Paint transform(String name) {
if (viewer.getPickedVertexState().isPicked(name)) {
return GraphViewer.NODE_SELECTED;
} else if (sourceFilter.getSelectedIndex() > 0
&& ((SourceId) sourceFilter.getSelectedItem()).getId().equals(name)) {
return GraphViewer.NODE_ON_PATH;
} else {
return GraphViewer.NODE_BACKGROUND;
}
}
};
}