/** * 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 x-coordinate of an item. The current x value will become the * new starting x value, while the given value will become the new current * x and ending x values. This method also supports an optional referrer * item, whose x coordinate will become the new starting x coordinate * of item if item's current x value is NaN. * @param item the VisualItem to update * @param referrer an optional referrer VisualItem * @param x the x value to set */ public static void setX(VisualItem item, VisualItem referrer, double x) { double sx = item.getX(); if ( Double.isNaN(sx) ) sx = (referrer != null ? referrer.getX() : x); item.setStartX(sx); item.setEndX(x); item.setX(x); }
/** * @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()),
if ( poly == null ) { return null; } float x = (float)item.getX(); float y = (float)item.getY();
m_cur.setLocation( getWidth() / 2, getHeight() / 2 ); getAbsoluteCoordinate( m_cur, m_start ); m_end.setLocation( vi.getX() + xbias, vi.getY() + ybias );
fitem.velocity[1] = 0.0f; if ( Double.isNaN(item.getX()) ) { setX(item, referrer, 0.0); setY(item, referrer, 0.0);
/** * @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); } }
} catch ( IllegalArgumentException iae ) { /* ignored */ } float startX = (referrer == null ? 0f : (float)referrer.getX()); float startY = (referrer == null ? 0f : (float)referrer.getY()); startX = Float.isNaN(startX) ? 0f : startX;
double x = item.getX(); if ( Double.isNaN(x) || Double.isInfinite(x) ) x = 0;
double x = item.getX(); double y = item.getY();