/** * Get the distance between the x,y points of two VisualItems. * @param vi1 the first VisualItem * @param vi2 the second VisualItem * @return the distance between the items' x,y coordinates */ public static double distance(VisualItem vi1, VisualItem vi2) { double dx = vi1.getX() - vi2.getX(); double dy = vi1.getY() - vi2.getY(); return Math.sqrt(dx*dx + dy*dy); }
/** * Helper method, which calculates the top-left co-ordinate of an item * given the item's alignment. */ protected static void getAlignedPoint(Point2D p, VisualItem item, double w, double h, int xAlign, int yAlign) { double x = item.getX(), y = item.getY(); if ( Double.isNaN(x) || Double.isInfinite(x) ) x = 0; // safety check if ( Double.isNaN(y) || Double.isInfinite(y) ) y = 0; // safety check if ( xAlign == Constants.CENTER ) { x = x-(w/2); } else if ( xAlign == Constants.RIGHT ) { x = x-w; } if ( yAlign == Constants.CENTER ) { y = y-(h/2); } else if ( yAlign == Constants.BOTTOM ) { y = y-h; } p.setLocation(x,y); }
/** * Return the centroid (averaged location) of a group of items. * @param iter an iterator of VisualItems * @param p a Point2D instance in which to store the result * @return the centroid point. This is the same object as the * parameter <code>p</code>. */ public static Point2D getCentroid(Iterator iter, Point2D p) { double cx = 0, cy = 0; int count = 0; while ( iter.hasNext() ) { VisualItem item = (VisualItem)iter.next(); double x = item.getX(), y = item.getY(); if ( !(Double.isInfinite(x) || Double.isNaN(x)) && !(Double.isInfinite(y) || Double.isNaN(y)) ) { cx += x; cy += y; count++; } } if ( count > 0 ) { cx /= count; cy /= count; } p.setLocation(cx, cy); return p; }
/** * Update the y-coordinate of an item. The current y value will become the * new starting y value, while the given value will become the new current * x and ending y values. This method also supports an optional referrer * item, whose y coordinate will become the new starting y coordinate * of item if item's current x value is NaN. * @param item the VisualItem to update * @param referrer an optional referrer VisualItem * @param y the y value to set */ public static void setY(VisualItem item, VisualItem referrer, double y) { double sy = item.getY(); if ( Double.isNaN(sy) ) sy = (referrer != null ? referrer.getY() : y); item.setStartY(sy); item.setEndY(y); item.setY(y); }
/** * @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */ public void setBounds(VisualItem item) { item.setBounds(item.getX(), item.getY(), 0, 0); }
m_cur.setLocation(getWidth()/2, getHeight()/2); getAbsoluteCoordinate(m_cur, m_start); m_end.setLocation(vi.getX()+xbias, vi.getY()+ybias); } else { m_cur.setLocation(m_start.getX() + frac*(m_end.getX()-m_start.getX()),
m_cur.setLocation( getWidth() / 2, getHeight() / 2 ); getAbsoluteCoordinate( m_cur, m_start ); m_end.setLocation( vi.getX() + xbias, vi.getY() + ybias );
float y = (float)item.getY();
/** * @see prefuse.controls.Control#itemDragged(prefuse.visual.VisualItem, java.awt.event.MouseEvent) */ public void itemDragged(VisualItem item, MouseEvent e) { if (!SwingUtilities.isLeftMouseButton(e)) return; dragged = true; Display d = (Display)e.getComponent(); d.getAbsoluteCoordinate(e.getPoint(), temp); double dx = temp.getX()-down.getX(); double dy = temp.getY()-down.getY(); double x = item.getX(); double y = item.getY(); item.setStartX(x); item.setStartY(y); item.setX(x+dx); item.setY(y+dy); item.setEndX(x+dx); item.setEndY(y+dy); if ( repaint ) item.getVisualization().repaint(); down.setLocation(temp); if ( action != null ) d.getVisualization().run(action); }
/** * @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */ public void setBounds(VisualItem item) { if ( !m_manageBounds ) return; Shape shape = getShape(item); if ( shape == null ) { item.setBounds(item.getX(), item.getY(), 0, 0); } else { GraphicsLib.setBounds(item, shape, getStroke(item)); } }
protected static void move(VisualItem item, double dx, double dy) { if ( item instanceof AggregateItem ) { Iterator items = ((AggregateItem)item).items(); while ( items.hasNext() ) { move((VisualItem)items.next(), dx, dy); } } else { double x = item.getX(); double y = item.getY(); item.setStartX(x); item.setStartY(y); item.setX(x+dx); item.setY(y+dy); item.setEndX(x+dx); item.setEndY(y+dy); } }
/** * @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */ public void setBounds(VisualItem item) { if ( !m_manageBounds ) return; Shape shape = getShape(item); if ( shape == null ) { item.setBounds(item.getX(), item.getY(), 0, 0); } else if ( shape == m_line ) { GraphicsLib.setBounds(item, shape, getStroke(item)); } else { m_box.add(m_line.getX1(),m_line.getY1()); m_box.add(m_line.getX2(),m_line.getY2()); item.setBounds(m_box.getMinX(), m_box.getMinY(), m_box.getWidth(), m_box.getHeight()); } }
/** * @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */ public void setBounds(VisualItem item) { if ( !m_manageBounds ) return; Shape shape = getShape(item); if ( shape == null ) { item.setBounds(item.getX(), item.getY(), 0, 0); return; } GraphicsLib.setBounds(item, shape, getStroke(item)); if ( m_curArrow != null ) { Rectangle2D bBox = (Rectangle2D)item.get(VisualItem.BOUNDS); Rectangle2D.union(bBox, m_curArrow.getBounds2D(), bBox); } }
float startY = (referrer == null ? 0f : (float)referrer.getY()); startX = Float.isNaN(startX) ? 0f : startX; startY = Float.isNaN(startY) ? 0f : startY;
if ( Double.isNaN(x) || Double.isInfinite(x) ) x = 0; double y = item.getY(); if ( Double.isNaN(y) || Double.isInfinite(y) ) y = 0;
Rectangle2D bBox = item.getBounds(); double x = item.getX(); double y = item.getY();