本文整理汇总了Java中edu.uci.ics.jung.visualization.VisualizationViewer.getCenter方法的典型用法代码示例。如果您正苦于以下问题:Java VisualizationViewer.getCenter方法的具体用法?Java VisualizationViewer.getCenter怎么用?Java VisualizationViewer.getCenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.uci.ics.jung.visualization.VisualizationViewer
的用法示例。
在下文中一共展示了VisualizationViewer.getCenter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseDragged
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入方法依赖的package包/类
/**
* check the modifiers. If accepted, use the mouse drag motion
* to rotate the graph
*/
public void mouseDragged(MouseEvent e) {
if(down == null) return;
VisualizationViewer vv = (VisualizationViewer)e.getSource();
boolean accepted = checkModifiers(e);
if(accepted) {
MutableTransformer modelTransformer =
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
// rotate
vv.setCursor(cursor);
Point2D center = vv.getCenter();
Point2D q = down;
Point2D p = e.getPoint();
Point2D v1 = new Point2D.Double(center.getX()-p.getX(), center.getY()-p.getY());
Point2D v2 = new Point2D.Double(center.getX()-q.getX(), center.getY()-q.getY());
double theta = angleBetween(v1, v2);
modelTransformer.rotate(theta, vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, center));
down.x = e.getX();
down.y = e.getY();
e.consume();
}
}
示例2: mouseWheelMoved
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入方法依赖的package包/类
/**
* zoom the display in or out, depending on the direction of the
* mouse wheel motion.
*/
public void mouseWheelMoved(MouseWheelEvent e) {
boolean accepted = checkModifiers(e);
if(accepted == true) {
VisualizationViewer vv = (VisualizationViewer)e.getSource();
Point2D mouse = e.getPoint();
Point2D center = vv.getCenter();
int amount = e.getWheelRotation();
if(zoomAtMouse) {
if(amount > 0) {
scaler.scale(vv, in, mouse);
} else if(amount < 0) {
scaler.scale(vv, out, mouse);
}
} else {
if(amount > 0) {
scaler.scale(vv, in, center);
} else if(amount < 0) {
scaler.scale(vv, out, center);
}
}
e.consume();
vv.repaint();
}
}
示例3: mouseDragged
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入方法依赖的package包/类
/**
*
*
*
*
*/
public void mouseDragged(MouseEvent e) {
if(down == null) return;
VisualizationViewer vv = (VisualizationViewer)e.getSource();
boolean accepted = checkModifiers(e);
if(accepted) {
MutableTransformer modelTransformer =
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
vv.setCursor(cursor);
Point2D q = down;
Point2D p = e.getPoint();
float dx = (float) (p.getX()-q.getX());
float dy = (float) (p.getY()-q.getY());
Dimension d = vv.getSize();
float shx = 2.f*dx/d.height;
float shy = 2.f*dy/d.width;
Point2D center = vv.getCenter();
if(p.getX() < center.getX()) {
shy = -shy;
}
if(p.getY() < center.getY()) {
shx = -shx;
}
modelTransformer.shear(shx, shy, center);
down.x = e.getX();
down.y = e.getY();
e.consume();
}
}
示例4: centerGraph
import edu.uci.ics.jung.visualization.VisualizationViewer; //导入方法依赖的package包/类
/**
* This method finds the location of the graph relative to the viewer and
* shifts is so that it appears in the center of JUNG's VisualizationViewer.
*/
public static Point2D centerGraph(VisualizationViewer<Vertex, Edge> vv, BrowsableNetwork network, Layout<Vertex, Edge> layout,
EditingModalGraphMouse<Vertex, Edge> mouse) {
MutableTransformer layout2 = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
double top = Double.MAX_VALUE;
double bottom = Double.MAX_VALUE;
double left = Double.MAX_VALUE;
double right = Double.MAX_VALUE;
for (Vertex v : network.getVertices()) {
Point2D p;
if (layout instanceof AbstractLayout)
p = ((AbstractLayout<Vertex, Edge>) layout).transform(v);
else
p = ((TreeLayout<Vertex, Edge>) layout).transform(v);
Point2D invP = layout2.transform(p);
if (top < invP.getY() || top == Double.MAX_VALUE)
top = invP.getY();
if (bottom > invP.getY() || bottom == Double.MAX_VALUE)
bottom = invP.getY();
if (left > invP.getX() || left == Double.MAX_VALUE)
left = invP.getX();
if (right < invP.getX() || right == Double.MAX_VALUE)
right = invP.getX();
}
if (mouse != null) {
double scale = 0;
do {
scale = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).getScale();
mouse.mouseWheelMoved(new MouseWheelEvent(vv, 0, 0, 0, vv.getWidth() / 2, vv.getHeight() / 2, 1, false, 1, -1, -1));
} while (scale >= 1);
}
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)
.setScale(1, 1, new Point((int) (vv.getCenter().getX() - (right + left) / 2), (int) (vv.getCenter().getY() - (top + bottom) / 2)));
double deltaX = vv.getCenter().getX() - (right + left) / 2;
double deltaY = vv.getCenter().getY() - (top + bottom) / 2;
if (!Double.isInfinite(deltaX) && !Double.isInfinite(deltaY) && !Double.isNaN(deltaX) && !Double.isNaN(deltaY)) {
layout2.translate(deltaX, deltaY);
}
return vv.getCenter();
}