本文整理匯總了Java中edu.uci.ics.jung.algorithms.layout.Layout.transform方法的典型用法代碼示例。如果您正苦於以下問題:Java Layout.transform方法的具體用法?Java Layout.transform怎麽用?Java Layout.transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.uci.ics.jung.algorithms.layout.Layout
的用法示例。
在下文中一共展示了Layout.transform方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: centerVisualization
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
public void centerVisualization(V vertex, final boolean immediate) {
if (vertex != null) {
Layout<V,E> layout = this.getGraphLayout();
Point2D q = layout.transform(vertex);
Point2D lvc = this.getRenderContext().getMultiLayerTransformer().inverseTransform(this.getCenter());
final int steps = (immediate ? 1 : 10);
final double dx = (lvc.getX() - q.getX()) / steps;
final double dy = (lvc.getY() - q.getY()) / steps;
new Thread() {
public void run() {
MutableTransformer transformer = GraphVisualizationPanel.this.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
for (int i = 0; i < steps; i++) {
transformer.translate(dx, dy);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
}
}.start();
}
}
示例2: paintVertex
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* Paint vertex <code>v</code> on <code>g</code> at <code>(x,y)</code>.
*
* @param rc
* @param v
* @param layout
*/
protected void paintVertex(
RenderContext<ViwnNode, ViwnEdge> rc,
ViwnNode v,
Layout<ViwnNode, ViwnEdge> layout) {
Point2D p = layout.transform(v);
p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
if (v instanceof ViwnNodeSet) {
delegate.paintVertex(rc, layout, v);
renderSet(rc, p, (ViwnNodeSet) v);
} else if (v instanceof ViwnNodeSynset) {
renderSynset(rc, p, (ViwnNodeSynset) v, layout);
} else if (v instanceof ViwnNodeWord) {
delegate.paintVertex(rc, layout, v);
renderWord(rc, p, (ViwnNodeWord) v);
}
}
示例3: labelVertex
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
@Override
public void labelVertex(RenderContext<GUINode, GUILink> rc, Layout<GUINode, GUILink> layout, GUINode v, String label)
{
if (!callback.getVisualizationState().isVisibleInCanvas(v)) return;
if (callback.getVisualizationState().isCanvasShowNodeNames() && v.getLayer().isDefaultLayer())
{
Point2D vertexPositionInPixels = layout.transform(v);
vertexPositionInPixels = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, vertexPositionInPixels);
final Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), "<html><font color='black'>" + v.getLabel() + "</font></html>", rc.getPickedVertexState().isPicked(v), v);
final GraphicsDecorator g = rc.getGraphicsContext();
final Dimension dimensionMessage = component.getPreferredSize();
final Icon vertexIcon = v.getIcon();
final Rectangle2D boundsVertex = new Rectangle2D.Double(vertexPositionInPixels.getX() - vertexIcon.getIconWidth() / 2, vertexPositionInPixels.getY() - vertexIcon.getIconHeight() / 2, vertexIcon.getIconWidth(), vertexIcon.getIconHeight());
final Point anchorPointInPixels = getAnchorPoint(boundsVertex, dimensionMessage, Renderer.VertexLabel.Position.NE);
g.draw(component, rc.getRendererPane(), anchorPointInPixels.x, anchorPointInPixels.y, dimensionMessage.width, dimensionMessage.height, true);
}
}
示例4: paintVertex
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
@Override public void paintVertex(RenderContext<String, String> rc,
Layout<String, String> layout, String vertex) {
GraphicsDecorator graphicsContext = rc.getGraphicsContext();
Point2D center = layout.transform(vertex);
Shape shape = null;
Color color = null;
if(vertex.equals("Square")) {
shape = new Rectangle((int)center.getX()-10, (int)center.getY()-10, 20, 20);
color = new Color(127, 127, 0);
} else if(vertex.equals("Rectangle")) {
shape = new Rectangle((int)center.getX()-10, (int)center.getY()-20, 20, 40);
color = new Color(127, 0, 127);
} else if(vertex.equals("Circle")) {
shape = new Ellipse2D.Double(center.getX()-10, center.getY()-10, 20, 20);
color = new Color(0, 127, 127);
}
graphicsContext.setPaint(color);
graphicsContext.fill(shape);
}
示例5: getNodePositions
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
protected Map<String, Point2D> getNodePositions(Collection<V> nodes) {
Map<String, Point2D> map = new LinkedHashMap<>();
Layout<V, Edge<V>> layout = viewer.getGraphLayout();
for (V node : nodes) {
Point2D pos = layout.transform(node);
if (pos != null) {
map.put(node.getId(), new Point2D.Double(pos.getX(), pos.getY()));
} else {
logger.finest("pos = null");
}
}
return map;
}
示例6: getVertices
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
@Override
public Collection<V> getVertices(Layout<V, E> layout, Shape shape) {
Set<V> pickedVertices = new HashSet<>();
Shape iShape = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, shape);
for (V v : layout.getGraph().getVertices()) {
if (!vv.getRenderContext().getVertexIncludePredicate()
.evaluate(Context.<Graph<V, E>, V>getInstance(layout.getGraph(), v))) {
continue;
}
Point2D p = layout.transform(v);
if (p == null) {
continue;
}
p = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p);
if (iShape.contains(p)) {
pickedVertices.add(v);
}
}
return pickedVertices;
}
示例7: getVertices
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* Returns the vertices whose layout coordinates are contained in
* <code>Shape</code>.
* The shape is in screen coordinates, and the graph vertices
* are transformed to screen coordinates before they are tested
* for inclusion.
* @return the <code>Collection</code> of vertices whose <code>layout</code>
* coordinates are contained in <code>shape</code>.
*/
public Collection<V> getVertices(Layout<V, E> layout, Shape shape) {
Set<V> pickedVertices = new HashSet<V>();
// remove the view transform from the rectangle
shape = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, shape);
while(true) {
try {
for(V v : getFilteredVertices(layout)) {
Point2D p = layout.transform(v);
if(p == null) continue;
p = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p);
if(shape.contains(p)) {
pickedVertices.add(v);
}
}
break;
} catch(ConcurrentModificationException cme) {}
}
return pickedVertices;
}
示例8: getVertices
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* returns the vertices that are contained in the passed shape.
* The shape is in screen coordinates, and the graph vertices
* are transformed to screen coordinates before they are tested
* for inclusion
*/
public Collection<V> getVertices(Layout<V, E> layout, Shape rectangle) {
Set<V> pickedVertices = new HashSet<V>();
while(true) {
try {
for(V v : getFilteredVertices(layout)) {
Point2D p = layout.transform(v);
if(p == null) continue;
p = vv.getRenderContext().getMultiLayerTransformer().transform(p);
if(rectangle.contains(p)) {
pickedVertices.add(v);
}
}
break;
} catch(ConcurrentModificationException cme) {}
}
return pickedVertices;
}
示例9: labelVertex
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* Labels the specified vertex with the specified label.
* Uses the font specified by this instance's
* <code>VertexFontFunction</code>. (If the font is unspecified, the existing
* font for the graphics context is used.) If vertex label centering
* is active, the label is centered on the position of the vertex; otherwise
* the label is offset slightly.
*/
public void labelVertex(RenderContext<V,E> rc, Layout<V,E> layout, V v, String label) {
Graph<V,E> graph = layout.getGraph();
if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V,E>,V>getInstance(graph,v)) == false) {
return;
}
GraphicsDecorator g = rc.getGraphicsContext();
Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label,
rc.getPickedVertexState().isPicked(v), v);
Dimension d = component.getPreferredSize();
int h_offset = -d.width / 2;
int v_offset = -d.height / 2;
Point2D p = layout.transform(v);
p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
int x = (int)p.getX();
int y = (int)p.getY();
g.draw(component, rc.getRendererPane(), x+h_offset, y+v_offset, d.width, d.height, true);
Dimension size = component.getPreferredSize();
Rectangle bounds = new Rectangle(-size.width/2 -2, -size.height/2 -2, size.width+4, size.height);
shapes.put(v, bounds);
}
示例10: mouseDraggedSuperAction
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* This is the MouseDragged super action of the super class (because of several exceptions).
* @param me the MouseEvent
*/
private void mouseDraggedSuperAction(MouseEvent me) {
if(locked == false) {
VisualizationViewer<GraphNode,GraphEdge> vv = this.basicGraphGUI.getVisualizationViewer();
if(vertex != null) {
Point p = me.getPoint();
Point2D graphPoint = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(p);
Point2D graphDown = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(down);
Layout<GraphNode,GraphEdge> layout = vv.getGraphLayout();
double dx = graphPoint.getX()-graphDown.getX();
double dy = graphPoint.getY()-graphDown.getY();
PickedState<GraphNode> ps = vv.getPickedVertexState();
for(GraphNode v : ps.getPicked()) {
Point2D vp = layout.transform(v);
vp.setLocation(vp.getX()+dx, vp.getY()+dy);
layout.setLocation(v, vp);
}
down = p;
me.consume();
vv.repaint();
} else {
Point2D out = me.getPoint();
if(me.getModifiers() == this.addToSelectionModifiers || me.getModifiers() == modifiers) {
if (down!=null) {
rect.setFrameFromDiagonal(down,out);
vv.repaint();
}
}
}
}
}
示例11: paintIconForVertex
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* Paint <code>v</code>'s icon on <code>g</code> at <code>(x,y)</code>.
*/
protected void paintIconForVertex(RenderContext<V, E> rc, V v, Layout<V, E> layout) {
GraphicsDecorator g = rc.getGraphicsContext();
boolean vertexHit = true;
// get the shape to be rendered
Shape shape = rc.getVertexShapeTransformer().transform(v);
Point2D p = layout.transform(v);
p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
float x = (float) p.getX();
float y = (float) p.getY();
// create a transform that translates to the location of
// the vertex to be rendered
AffineTransform xform = AffineTransform.getTranslateInstance(x, y);
// transform the vertex shape with xtransform
shape = xform.createTransformedShape(shape);
vertexHit = vertexHit(rc, shape);
// rc.getViewTransformer().transform(shape).intersects(deviceRectangle);
if (vertexHit) {
if (rc.getVertexIconTransformer() != null) {
Icon icon = rc.getVertexIconTransformer().transform(v);
if (icon != null) {
g.draw(icon, rc.getScreenDevice(), shape, (int) x, (int) y);
} else {
paintShapeForVertex(rc, v, shape);
}
} else {
paintShapeForVertex(rc, v, shape);
}
}
}
示例12: getPosition
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* Return the position of the given vertex on the canvas
* @param vertex
* @return
*/
public Point2D getPosition(V vertex) {
Point2D pos = null;
if (vertex != null) {
Layout<V,E> layout = this.getGraphLayout();
pos = layout.transform(vertex);
// MutableTransformer transformer = GraphVisualizationPanel.this.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
// pos = transformer.inverseTransform(pos);
}
return (pos);
}
示例13: mouseDragged
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
/**
* If the mouse is over a picked vertex, drag all picked
* vertices with the mouse.
* If the mouse is not over a Vertex, draw the rectangle
* to select multiple Vertices
*/
@SuppressWarnings("unchecked")
public void mouseDragged( MouseEvent e ) {
if (locked == false) {
VisualizationViewer<Room, Exit> vv = (VisualizationViewer) e.getSource();
if (room != null) {
Point p = e.getPoint();
Point2D graphPoint = vv.getRenderContext().getMultiLayerTransformer().inverseTransform( p );
Point2D graphDown = vv.getRenderContext().getMultiLayerTransformer().inverseTransform( down );
Layout<Room, Exit> layout = vv.getGraphLayout();
double dx = graphPoint.getX() - graphDown.getX();
double dy = graphPoint.getY() - graphDown.getY();
PickedState<Room> ps = vv.getPickedVertexState();
for (Room v : ps.getPicked()) {
Point2D vp = layout.transform( v );
vp.setLocation( vp.getX() + dx, vp.getY() + dy );
layout.setLocation( v, vp );
}
down = p;
} else {
Point2D out = e.getPoint();
if (e.getModifiers() == this.addToSelectionModifiers ||
e.getModifiers() == modifiers) {
rect.setFrameFromDiagonal( down, out );
}
}
if (room != null) e.consume();
vv.repaint();
}
}
示例14: makeSaveObject
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
private static AreaSaveObject makeSaveObject( String basedir, SparseMultigraph<Room, Exit> graph, Layout<Room, Exit> layout ) throws IOException {
AreaSaveObject saveObject = new AreaSaveObject();
saveObject.setGraph( graph );
Map<Room, Point2D> locations = saveObject.getLocations();
for (Room room : graph.getVertices()) {
Point2D coord = layout.transform( room );
locations.put( room, coord );
}
saveObject.setFileName( getFileNameFrom( basedir, graph.getVertices().iterator().next().getArea().getName() ) );
// System.out.println("\n\n+nsaveobjectdone\n\n\n"+saveObject.getFileName());
return saveObject;
}
示例15: DeleteVertexUndoableAction
import edu.uci.ics.jung.algorithms.layout.Layout; //導入方法依賴的package包/類
public DeleteVertexUndoableAction(Layout<Vertex, Edge> layout, Vertex vertex) {
this.layout = layout;
this.graph = layout.getGraph();
this.vertex = vertex;
this.position = layout.transform(vertex);
this.incidentEdges = new ArrayList<IncidentEdge>();
for (Edge e : graph.getIncidentEdges(vertex)) {
this.incidentEdges.add(new IncidentEdge(e, graph.getEdgeType(e), graph.getEndpoints(e)));
}
}