本文整理匯總了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();
}