/** * Sets bounds based on the zoom about a given point. * The effective zoom point is between current center and mouse position... * close to center =%gt; 100% at the given point, close to edge =%gt; 10% at * the given point. * @param gc associated component * @param localZoomPoint focal point for zoom * @param factor how much to zoom */ public static void zoomPoint(JGraphicComponent gc, Point2D localZoomPoint, double factor) { Rectangle2D.Double localBounds = getLocalBounds(gc); double cx = .1 * localZoomPoint.getX() + .9 * localBounds.getCenterX(); double cy = .1 * localZoomPoint.getY() + .9 * localBounds.getCenterY(); double wx = localBounds.getWidth(); double wy = localBounds.getHeight(); setDesiredLocalBounds(gc, new Rectangle2D.Double( cx - .5 * factor * wx, cy - .5 * factor * wy, factor * wx, factor * wy)); }
@Override protected Point2D.Double getCenter() { Rectangle2D.Double bounds = getTransformedBounds(); return new Point2D.Double(bounds.getCenterX(), bounds.getCenterY()); }
/** * Creates an animating zoom using a particular timer, about the center of * the screen. * @param gc associated component * @param factor how far to zoom, representing the new scale * @return timer running the animation */ public static javax.swing.Timer zoomCenterAnimated(JGraphicComponent gc, double factor) { Rectangle2D.Double rect = getLocalBounds(gc); Point2D.Double center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); return zoomPointAnimated(gc, center, factor); }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
/** * Creates an animating zoom using a particular timer. * @param gc associated component * @param p the coordinate of the point to center zoom about, in local * coordinates * @param factor how far to zoom, representing the new scale * @return timer running the animation */ public static javax.swing.Timer zoomPointAnimated(final JGraphicComponent gc, Point2D.Double p, final double factor) { Rectangle2D.Double rect = getLocalBounds(gc); final double cx = .1 * p.x + .9 * rect.getCenterX(); final double cy = .1 * p.y + .9 * rect.getCenterY(); final double wx = rect.getWidth(); final double wy = rect.getHeight(); return AnimationStep.animate(0, ANIM_STEPS, ANIM_DELAY_MILLIS, new AnimationStep(){ @Override @InvokedFromThread("AnimationStep") public void run(int idx, double pct) { double zoomValue = 1.0 + (factor - 1.0) * pct; setDesiredLocalBounds(gc, new Rectangle2D.Double( cx - .5 * zoomValue * wx, cy - .5 * zoomValue * wy, wx + zoomValue * wx, wy + zoomValue * wy)); } }); }
/** * Zooms out for the given component (about the center). * @param gc associated component * @param animate if true, result will animate * @return timer running the animation */ public static javax.swing.Timer zoomOut(JGraphicComponent gc, boolean animate) { Rectangle2D.Double rect = getLocalBounds(gc); Point2D.Double center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); if (animate) { return zoomCoordBoxAnimated(gc, new Point2D.Double(center.x-rect.getWidth(), center.y-rect.getHeight()), new Point2D.Double(center.x+rect.getWidth(), center.y+rect.getHeight())); } else { setDesiredLocalBounds(gc, new Rectangle2D.Double(center.x-rect.getWidth(), center.y-rect.getHeight(), 2*rect.getWidth(), 2*rect.getHeight())); return null; } }
/** * Zooms in for the given component (about the center). * @param gc associated component * @param animate if true, result will animate * @return timer running the animation (null if not animating) */ public static javax.swing.Timer zoomIn(JGraphicComponent gc, boolean animate) { Rectangle2D.Double rect = getLocalBounds(gc); Point2D.Double center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); if (animate) { return zoomCoordBoxAnimated(gc, new Point2D.Double(center.x-.25*rect.getWidth(), center.y-.25*rect.getHeight()), new Point2D.Double(center.x+.25*rect.getWidth(), center.y+.25*rect.getHeight())); } else { setDesiredLocalBounds(gc, new Rectangle2D.Double(center.x-.25*rect.getWidth(), center.y-.25*rect.getHeight(), .5*rect.getWidth(), .5*rect.getHeight())); return null; } }
protected void generateEdges(Tree parent) { if (!getTree().isLeaf(parent)) { Rectangle2D.Double parentBounds = getBoundsOfNode(parent); // System.out.println("%% parent("+getText(parent)+")="+parentBounds); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.y; for (Tree child : getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); // System.out.println("%% child("+getText(child)+")="+childBounds); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMaxY(); doc.line(x1, y1, x2, y2); generateEdges(child); } } }
protected void generateEdges(Tree parent) { if (!getTree().isLeaf(parent)) { Rectangle2D.Double parentBounds = getBoundsOfNode(parent); // System.out.println("%% parent("+getText(parent)+")="+parentBounds); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.y; for (Tree child : getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); // System.out.println("%% child("+getText(child)+")="+childBounds); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMaxY(); doc.line(x1, y1, x2, y2); generateEdges(child); } } }
protected void generateEdges(Tree parent) { if (!getTree().isLeaf(parent)) { Rectangle2D.Double parentBounds = getBoundsOfNode(parent); // System.out.println("%% parent("+getText(parent)+")="+parentBounds); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.y; for (Tree child : getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); // System.out.println("%% child("+getText(child)+")="+childBounds); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMaxY(); doc.line(x1, y1, x2, y2); generateEdges(child); } } }
protected void generateEdges(Tree parent) { if (!getTree().isLeaf(parent)) { Rectangle2D.Double parentBounds = getBoundsOfNode(parent); // System.out.println("%% parent("+getText(parent)+")="+parentBounds); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.y; for (Tree child : getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); // System.out.println("%% child("+getText(child)+")="+childBounds); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMaxY(); doc.line(x1, y1, x2, y2); generateEdges(child); } } }
protected void generateEdges(Tree parent) { if (!getTree().isLeaf(parent)) { Rectangle2D.Double parentBounds = getBoundsOfNode(parent); // System.out.println("%% parent("+getText(parent)+")="+parentBounds); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.y; for (Tree child : getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); // System.out.println("%% child("+getText(child)+")="+childBounds); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMaxY(); doc.line(x1, y1, x2, y2); generateEdges(child); } } }
protected void generateEdges(Writer writer, Tree parent) throws IOException { if (!getTree().isLeaf(parent)) { Rectangle2D.Double b1 = getBoundsOfNode(parent); double x1 = b1.getCenterX(); double y1 = b1.getCenterY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); writer.write(line(""+x1, ""+y1, ""+x2, ""+y2, "stroke:black; stroke-width:1px;")); generateEdges(writer, child); } } }
protected void generateEdges(Writer writer, Tree parent) throws IOException { if (!getTree().isLeaf(parent)) { Rectangle2D.Double b1 = getBoundsOfNode(parent); double x1 = b1.getCenterX(); double y1 = b1.getCenterY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); writer.write(line(""+x1, ""+y1, ""+x2, ""+y2, "stroke:black; stroke-width:1px;")); generateEdges(writer, child); } } }
protected void generateEdges(Writer writer, Tree parent) throws IOException { if (!getTree().isLeaf(parent)) { Rectangle2D.Double b1 = getBoundsOfNode(parent); double x1 = b1.getCenterX(); double y1 = b1.getCenterY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); writer.write(line(""+x1, ""+y1, ""+x2, ""+y2, "stroke:black; stroke-width:1px;")); generateEdges(writer, child); } } }
@Override protected Point2D.Double getOrigin() { // This handle is placed above the figure. // We move it up by a handlesizes, so that it won't overlap with // the handles from TransformHandleKit. Rectangle2D.Double bounds = getTransformedBounds(); Point2D.Double origin = new Point2D.Double(bounds.getCenterX(), bounds.y - getHandlesize() / view.getScaleFactor()); return origin; } }