/** * Convenience method for getting the end point. */ @Override public Point2D.Double getEndPoint() { return getPoint(getNodeCount() - 1, 0); }
/** * Adds a control point. */ public void addNode(BezierPath.Node p) { addNode(getNodeCount(), p); }
@Override protected int getBezierNodeIndex() { return getBezierFigure().getNodeCount() - 1; } }
@Override public Point2D.Double locate(Figure owner) { BezierFigure plf = (BezierFigure) owner; if (index < plf.getNodeCount()) { return plf.getPoint(index, coord); } return new Point2D.Double(0, 0); }
@Override public boolean isCombinableWith(Handle h) { if (super.isCombinableWith(h)) { BezierControlPointHandle that = (BezierControlPointHandle) h; return that.index == this.index && that.controlPointIndex == this.controlPointIndex && that.getBezierFigure().getNodeCount() == this.getBezierFigure().getNodeCount(); } return false; }
/** * Convenience method for setting the point coordinate of the end point. * If the BezierFigure has not at least two nodes, nodes are added * to the figure until the BezierFigure has at least two nodes. */ public void setEndPoint(Point2D.Double p) { // Add two nodes if we haven't at least two nodes for (int i = getNodeCount(); i < 2; i++) { addNode(0, new BezierPath.Node(p.x, p.y)); } setPoint(getNodeCount() - 1, p); }
@Override public void draw(Graphics2D g) { if (createdFigure != null && // anchor != null && // mouseLocation != null &&// getView() == creationView) { g.setColor(Color.BLACK); g.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0f, new float[]{1f, 5f}, 0f)); g.drawLine(anchor.x, anchor.y, mouseLocation.x, mouseLocation.y); if (!isWorking && createdFigure.isClosed() && createdFigure.getNodeCount() > 1) { Point p = creationView.drawingToView(createdFigure.getStartPoint()); g.drawLine(mouseLocation.x, mouseLocation.y, p.x, p.y); } } }
/** * Convenience method for setting the point coordinate of the start point. * If the BezierFigure has not at least two nodes, nodes are added * to the figure until the BezierFigure has at least two nodes. */ public void setStartPoint(Point2D.Double p) { // Add two nodes if we haven't at least two nodes for (int i = getNodeCount(); i < 2; i++) { addNode(0, new BezierPath.Node(p.x, p.y)); } setPoint(0, p); }
@Override public void mouseMoved(MouseEvent evt) { if (createdFigure != null && anchor != null && mouseLocation != null) { if (evt.getSource() == creationView) { Rectangle r = new Rectangle(anchor); r.add(mouseLocation); r.add(evt.getPoint()); if (createdFigure.isClosed() && createdFigure.getNodeCount() > 0) { r.add(creationView.drawingToView(createdFigure.getStartPoint())); } r.grow(1, 1); fireAreaInvalidated(r); mouseLocation = evt.getPoint(); } } }
@Nullable protected BezierPath.Node getBezierNode() { return getOwner().getNodeCount() > index ? getOwner().getNode(index) : null; }
@Nullable protected BezierPath.Node getBezierNode() { return getBezierFigure().getNodeCount() > index ? getBezierFigure().getNode(index) : null; }
protected Point getLocation() { if (getBezierFigure().getNodeCount() > index) { Point2D.Double p = getBezierFigure().getPoint(index, controlPointIndex); if (getTransformOwner().get(TRANSFORM) != null) { getTransformOwner().get(TRANSFORM).transform(p, p); } return view.drawingToView(p); } else { return new Point(10, 10); } }
protected Point getLocation() { if (getOwner().getNodeCount() > index) { Point2D.Double p = getOwner().getPoint(index, 0); if (getTransformOwner().get(TRANSFORM) != null) { getTransformOwner().get(TRANSFORM).transform(p, p); } return view.drawingToView(p); } else { return new Point(10, 10); } }
@Override public void updateFigure(final OverlayView view, final BezierFigure figure) { super.updateFigure(view, figure); assert view.getData() instanceof GeneralPathOverlay; final GeneralPathOverlay gpo = (GeneralPathOverlay) view.getData(); final GeneralPathRegionOfInterest gpr = gpo.getRegionOfInterest(); final PathIterator pi = gpr.getGeneralPath().getPathIterator(null); final int nCount = figure.getNodeCount(); int i = 0; final double[] pos = new double[6]; while (!pi.isDone()) { pi.currentSegment(pos); final Node n = new Node(pos[0], pos[1]); if (i < nCount) figure.getNode(i).setTo(n); else figure.addNode(n); pi.next(); i++; } while (i < figure.getNodeCount()) figure.removeNode(i); }
@Nullable protected BezierPath.Node getBezierNode() { int index = getBezierNodeIndex(); return getBezierFigure().getNodeCount() > index ? getBezierFigure().getNode(index) : null; }
@Override public Rectangle2D.Double getDrawingArea() { Rectangle2D.Double r = super.getDrawingArea(); if (getNodeCount() > 1) { if (get(START_DECORATION) != null) { Point2D.Double p1 = getPoint(0, 0); Point2D.Double p2 = getPoint(1, 0); r.add(get(START_DECORATION).getDrawingArea(this, p1, p2)); } if (get(END_DECORATION) != null) { Point2D.Double p1 = getPoint(getNodeCount() - 1, 0); Point2D.Double p2 = getPoint(getNodeCount() - 2, 0); r.add(get(END_DECORATION).getDrawingArea(this, p1, p2)); } } return r; }
@Override public void updateOverlay(final BezierFigure figure, final OverlayView view) { super.updateOverlay(figure, view); assert view.getData() instanceof GeneralPathOverlay; final GeneralPathOverlay gpo = (GeneralPathOverlay) view.getData(); final GeneralPathRegionOfInterest gpr = gpo.getRegionOfInterest(); gpr.reset(); for (int i = 0; i < figure.getNodeCount(); i++) { final Node n = figure.getNode(i); if (i == 0) gpr.moveTo(n.x[0], n.y[0]); else gpr.lineTo(n.x[0], n.y[0]); } gpo.update(); }
@Override public void deactivate(DrawingEditor editor) { super.deactivate(editor); getView().setCursor(Cursor.getDefaultCursor()); if (createdFigure != null) { if (anchor != null && mouseLocation != null) { Rectangle r = new Rectangle(anchor); r.add(mouseLocation); if (createdFigure.getNodeCount() > 0 && createdFigure.isClosed()) { r.add(getView().drawingToView(createdFigure.getStartPoint())); } fireAreaInvalidated(r); } finishCreation(createdFigure, creationView); createdFigure = null; } }
protected void addPointToFigure(Point2D.Double newPoint) { int pointCount = createdFigure.getNodeCount(); createdFigure.willChange(); if (pointCount < 2) { createdFigure.addNode(new BezierPath.Node(newPoint)); } else { Point2D.Double endPoint = createdFigure.getEndPoint(); Point2D.Double secondLastPoint = (pointCount <= 1) ? endPoint : createdFigure.getPoint(pointCount - 2, 0); if (newPoint.equals(endPoint)) { // nothing to do } else if (pointCount > 1 && Geom.lineContainsPoint(newPoint.x, newPoint.y, secondLastPoint.x, secondLastPoint.y, endPoint.x, endPoint.y, 0.9f / getView().getScaleFactor())) { createdFigure.setPoint(pointCount - 1, 0, newPoint); } else { createdFigure.addNode(new BezierPath.Node(newPoint)); } } createdFigure.changed(); }
protected void writePoints(DOMOutput out) throws IOException { out.openElement("points"); if (isClosed()) { out.addAttribute("closed", true); } for (int i = 0, n = getNodeCount(); i < n; i++) { BezierPath.Node node = getNode(i); out.openElement("p"); out.addAttribute("mask", node.mask, 0); out.addAttribute("colinear", true); out.addAttribute("x", node.x[0]); out.addAttribute("y", node.y[0]); out.addAttribute("c1x", node.x[1], node.x[0]); out.addAttribute("c1y", node.y[1], node.y[0]); out.addAttribute("c2x", node.x[2], node.x[0]); out.addAttribute("c2y", node.y[2], node.y[0]); out.closeElement(); } out.closeElement(); }