public String getToolTipText(Point p) {
   ConnectionFigure f = (ConnectionFigure) getOwner();
   if (f.getLiner() == null && savedLiner == null) {
     ResourceBundleUtil labels = ResourceBundleUtil.getLAFBundle("org.jhotdraw.draw.Labels");
     BezierPath.Node node = getBezierNode();
     return (node == null)
         ? null
         : labels.getFormatted(
             "bezierNodeHandle.tip",
             labels.getFormatted(
                 (node.getMask() == 0)
                     ? "bezierNode.linearNode"
                     : ((node.getMask() == BezierPath.C1C2_MASK)
                         ? "bezierNode.cubicNode"
                         : "bezierNode.quadraticNode")));
   } else {
     return null;
   }
 }
  /**
   * Connects the figure to the new connectableConnector. If there is no new connectableConnector
   * the connection reverts to its original one.
   */
  public void trackEnd(Point anchor, Point lead, int modifiersEx) {
    ConnectionFigure f = getOwner();
    // Change node type
    if ((modifiersEx
                & (InputEvent.META_DOWN_MASK
                    | InputEvent.CTRL_DOWN_MASK
                    | InputEvent.ALT_DOWN_MASK
                    | InputEvent.SHIFT_DOWN_MASK))
            != 0
        && (modifiersEx & InputEvent.BUTTON2_DOWN_MASK) == 0) {
      f.willChange();
      int index = getBezierNodeIndex();
      BezierPath.Node v = f.getNode(index);
      if (index > 0 && index < f.getNodeCount()) {
        v.mask = (v.mask + 3) % 4;
      } else if (index == 0) {
        v.mask = ((v.mask & BezierPath.C2_MASK) == 0) ? BezierPath.C2_MASK : 0;
      } else {
        v.mask = ((v.mask & BezierPath.C1_MASK) == 0) ? BezierPath.C1_MASK : 0;
      }
      f.setNode(index, v);
      f.changed();
      fireHandleRequestSecondaryHandles();
    }

    Point2D.Double p = view.viewToDrawing(lead);
    view.getConstrainer().constrainPoint(p);
    Connector target = findConnectionTarget(p, view.getDrawing());
    if (target == null) {
      target = savedTarget;
    }

    setLocation(p);
    if (target != savedTarget) {
      disconnect();
      connect(target);
    }
    getOwner().setLiner(savedLiner);
    getOwner().updateConnection();
    connectableConnector = null;
    connectors = Collections.emptyList();
  }
예제 #3
0
  protected void readPoints(DOMInput in) throws IOException {
    path.clear();
    in.openElement("points");
    setClosed(in.getAttribute("closed", false));

    for (int i = 0, n = in.getElementCount("p"); i < n; i++) {
      in.openElement("p", i);
      BezierPath.Node node =
          new BezierPath.Node(
              in.getAttribute("mask", 0),
              in.getAttribute("x", 0d),
              in.getAttribute("y", 0d),
              in.getAttribute("c1x", in.getAttribute("x", 0d)),
              in.getAttribute("c1y", in.getAttribute("y", 0d)),
              in.getAttribute("c2x", in.getAttribute("x", 0d)),
              in.getAttribute("c2y", in.getAttribute("y", 0d)));
      node.keepColinear = in.getAttribute("colinear", true);
      path.add(node);
      path.invalidatePath();
      in.closeElement();
    }
    in.closeElement();
  }
예제 #4
0
 /** Sets the point coordinate of a control point. */
 public void setPoint(int index, int coord, Point2D.Double p) {
   BezierPath.Node cp = new BezierPath.Node(path.get(index));
   cp.setControlPoint(coord, p);
   setNode(index, cp);
 }
예제 #5
0
  /**
   * Returns a path which is cappedPath at the ends, to prevent it from drawing under the end caps.
   */
  protected BezierPath getCappedPath() {
    if (cappedPath == null) {
      cappedPath = path.clone();
      if (isClosed()) {
        cappedPath.setClosed(true);
      } else {
        if (cappedPath.size() > 1) {
          if (get(START_DECORATION) != null) {
            BezierPath.Node p0 = cappedPath.get(0);
            BezierPath.Node p1 = cappedPath.get(1);
            Point2D.Double pp;
            if ((p0.getMask() & BezierPath.C2_MASK) != 0) {
              pp = p0.getControlPoint(2);
            } else if ((p1.getMask() & BezierPath.C1_MASK) != 0) {
              pp = p1.getControlPoint(1);
            } else {
              pp = p1.getControlPoint(0);
            }
            double radius = get(START_DECORATION).getDecorationRadius(this);
            double lineLength = Geom.length(p0.getControlPoint(0), pp);
            cappedPath.set(
                0, 0, Geom.cap(pp, p0.getControlPoint(0), -Math.min(radius, lineLength)));
          }
          if (get(END_DECORATION) != null) {
            BezierPath.Node p0 = cappedPath.get(cappedPath.size() - 1);
            BezierPath.Node p1 = cappedPath.get(cappedPath.size() - 2);

            Point2D.Double pp;
            if ((p0.getMask() & BezierPath.C1_MASK) != 0) {
              pp = p0.getControlPoint(1);
            } else if ((p1.getMask() & BezierPath.C2_MASK) != 0) {
              pp = p1.getControlPoint(2);
            } else {
              pp = p1.getControlPoint(0);
            }

            double radius = get(END_DECORATION).getDecorationRadius(this);
            double lineLength = Geom.length(p0.getControlPoint(0), pp);
            cappedPath.set(
                cappedPath.size() - 1,
                0,
                Geom.cap(pp, p0.getControlPoint(0), -Math.min(radius, lineLength)));
          }
          cappedPath.invalidatePath();
        }
      }
    }
    return cappedPath;
  }