Esempio n. 1
0
 public void paint(Graphics2D g, Rectangle layerBounds, boolean commit) {
   if (shape == null || stack == null) {
     return;
   }
   int full = 6;
   int half = 3;
   Rectangle2D.Double scratch = new Rectangle2D.Double(0, 0, full, full);
   g.setStroke(new BasicStroke(1F));
   int max = ((Adjustable) shape).getControlPointCount();
   double[] d = new double[max * 2];
   ((Adjustable) shape).getControlPoints(d);
   Point p = layer.getSurface().getLocation();
   for (int i = 0; i < d.length; i += 2) {
     d[i] -= p.x;
     d[i + 1] -= p.y;
     scratch.x = d[i] - half;
     scratch.y = d[i + 1] - half;
     g.setColor(Color.WHITE);
     g.fill(scratch);
     g.setColor(Color.BLACK);
     g.draw(scratch);
     if (cpoint != null && cpoint.getX() == d[i] && cpoint.getY() == d[i + 1]) {
       scratch.x -= 3;
       scratch.y -= 3;
       scratch.width += 6;
       scratch.height += 6;
       g.setColor(Color.YELLOW);
       g.draw(scratch);
     }
   }
 }
Esempio n. 2
0
 private void writeTextAreaElement(IXMLElement parent, SVGTextAreaFigure f) throws IOException {
     IXMLElement elem = parent.createElement("AREA");
     Rectangle2D.Double rect = f.getBounds();
     double grow = getPerpendicularHitGrowth(f);
     rect.x -= grow;
     rect.y -= grow;
     rect.width += grow;
     rect.height += grow;
     if (writeRectAttributes(elem, f, rect)) {
         parent.addChild(elem);
     }
 }
Esempio n. 3
0
  /**
   * Do any initial initialization here. This should be called by the {@link MosaicEngine} when or
   * before executing the first layout.
   */
  void init() {
    // Initialize the smallest node size/boundaryDividerCondition
    for (Node<T> n : getNodeList()) {
      double w = n.percentWidth * area.width;
      if (w < area.width) {
        area.width = w;
      }

      double h = n.percentHeight * area.height;
      if (h < area.height) {
        area.height = h;
      }
    }
  }
Esempio n. 4
0
 private boolean paintPlausibleRobot(Dimension d, Graphics2D g2d) {
   double sfactor =
       Math.min(d.width / 2.0, d.height / 2.0)
           / (seglengths[0] + seglengths[1] + seglengths[2] + seglengths[3]);
   g2d.scale(sfactor, -1.0 * sfactor);
   g2d.setColor(Color.gray);
   g2d.fill(j1circle);
   if (null == jointvals) {
     return true;
   }
   g2d.rotate(Math.toRadians(jointvals[1]));
   g2d.setColor(Color.yellow);
   g2d.fill(l0rect);
   g2d.translate(l0rect.width, 0.0);
   g2d.setColor(Color.gray);
   g2d.fill(j1circle);
   g2d.rotate(Math.toRadians(jointvals[2]));
   g2d.setColor(Color.yellow);
   g2d.fill(l1rect);
   g2d.translate(l1rect.width, 0.0);
   g2d.setColor(Color.gray);
   g2d.fill(j1circle);
   g2d.rotate(Math.toRadians(jointvals[3]));
   g2d.setColor(Color.yellow);
   g2d.fill(l2rect);
   g2d.translate(l2rect.width, 0.0);
   l3rect.width = this.seglengths[3] * Math.cos(Math.toRadians(jointvals[4]));
   if (l3rect.width <= 0) {
     return true;
   }
   g2d.setColor(Color.yellow);
   g2d.fill(l3rect);
   g2d.setColor(Color.gray);
   g2d.fill(j2circle);
   g2d.translate(l3rect.width, 0.0);
   g2d.setColor(Color.BLACK);
   l4rect.height = seglengths[4] * Math.abs(Math.cos(Math.toRadians(jointvals[5])));
   l4rect.y = -0.5 * l4rect.height;
   g2d.fill(l4rect);
   g2d.translate(0.0, l4rect.height / 2.0);
   g2d.fill(l5rect);
   g2d.translate(0.0, -l4rect.height);
   g2d.fill(l5rect);
   return false;
 }
Esempio n. 5
0
 private void writeRectElement(IXMLElement parent, SVGRectFigure f) throws IOException {
     IXMLElement elem = parent.createElement("AREA");
     boolean isContained;
     if (f.getArcHeight() == 0 && f.getArcWidth() == 0) {
         Rectangle2D.Double rect = f.getBounds();
         double grow = getPerpendicularHitGrowth(f);
         rect.x -= grow;
         rect.y -= grow;
         rect.width += grow;
         rect.height += grow;
         isContained = writeRectAttributes(elem, f, rect);
     } else {
         isContained = writePolyAttributes(elem, f,
                 new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)).
                 createStrokedShape(new RoundRectangle2D.Double(
                 f.getX(), f.getY(), f.getWidth(), f.getHeight(),
                 f.getArcWidth(), f.getArcHeight()
                 )));
     }
     if (isContained) {
         parent.addChild(elem);
     }
 }
Esempio n. 6
0
 private void updateCollisionRectangle(double x, double y, int width, int height) {
   _collisionRectangle.x = x - 2;
   _collisionRectangle.y = y - 2;
   _collisionRectangle.width = width + 2;
   _collisionRectangle.height = height + 2;
 }
Esempio n. 7
0
  public void lineout(ConnectionFigure figure) {
    BezierPath path = ((LineConnectionFigure) figure).getBezierPath();
    Connector start = figure.getStartConnector();
    Connector end = figure.getEndConnector();
    if (start == null || end == null || path == null) {
      return;
    }

    // Special treatment if the connection connects the same figure
    if (figure.getStartFigure() == figure.getEndFigure()) {
      // Ensure path has exactly 4 nodes
      while (path.size() < 4) {
        path.add(1, new BezierPath.Node(0, 0));
      }
      while (path.size() > 4) {
        path.remove(1);
      }
      Point2D.Double sp = start.findStart(figure);
      Point2D.Double ep = end.findEnd(figure);
      Rectangle2D.Double sb = start.getBounds();
      Rectangle2D.Double eb = end.getBounds();
      int soutcode = sb.outcode(sp);
      if (soutcode == 0) {
        soutcode = Geom.outcode(sb, eb);
      }
      int eoutcode = eb.outcode(ep);
      if (eoutcode == 0) {
        eoutcode = Geom.outcode(sb, eb);
      }

      path.get(0).moveTo(sp);
      path.get(path.size() - 1).moveTo(ep);

      switch (soutcode) {
        case Geom.OUT_TOP:
          eoutcode = Geom.OUT_LEFT;
          break;
        case Geom.OUT_RIGHT:
          eoutcode = Geom.OUT_TOP;
          break;
        case Geom.OUT_BOTTOM:
          eoutcode = Geom.OUT_RIGHT;
          break;
        case Geom.OUT_LEFT:
          eoutcode = Geom.OUT_BOTTOM;
          break;
        default:
          eoutcode = Geom.OUT_TOP;
          soutcode = Geom.OUT_RIGHT;
          break;
      }
      // path.get(0).moveTo(sp.x + shoulderSize, sp.y);
      path.get(0).mask = BezierPath.C2_MASK;
      if ((soutcode & Geom.OUT_RIGHT) != 0) {
        path.get(0).x[2] = sp.x + shoulderSize;
        path.get(0).y[2] = sp.y;
      } else if ((soutcode & Geom.OUT_LEFT) != 0) {
        path.get(0).x[2] = sp.x - shoulderSize;
        path.get(0).y[2] = sp.y;
      } else if ((soutcode & Geom.OUT_BOTTOM) != 0) {
        path.get(0).x[2] = sp.x;
        path.get(0).y[2] = sp.y + shoulderSize;
      } else {
        path.get(0).x[2] = sp.x;
        path.get(0).y[2] = sp.y - shoulderSize;
      }
      path.get(1).mask = BezierPath.C2_MASK;
      path.get(1).moveTo(sp.x + shoulderSize, (sp.y + ep.y) / 2);
      path.get(1).x[2] = sp.x + shoulderSize;
      path.get(1).y[2] = ep.y - shoulderSize;
      path.get(2).mask = BezierPath.C1_MASK;
      path.get(2).moveTo((sp.x + ep.x) / 2, ep.y - shoulderSize);
      path.get(2).x[1] = sp.x + shoulderSize;
      path.get(2).y[1] = ep.y - shoulderSize;
      path.get(3).mask = BezierPath.C1_MASK;
      if ((eoutcode & Geom.OUT_RIGHT) != 0) {
        path.get(3).x[1] = ep.x + shoulderSize;
        path.get(3).y[1] = ep.y;
      } else if ((eoutcode & Geom.OUT_LEFT) != 0) {
        path.get(3).x[1] = ep.x - shoulderSize;
        path.get(3).y[1] = ep.y;
      } else if ((eoutcode & Geom.OUT_BOTTOM) != 0) {
        path.get(3).x[1] = ep.x;
        path.get(3).y[1] = ep.y + shoulderSize;
      } else {
        path.get(3).x[1] = ep.x;
        path.get(3).y[1] = ep.y - shoulderSize;
      }
    } else {
      Point2D.Double sp = start.findStart(figure);
      Point2D.Double ep = end.findEnd(figure);

      path.clear();

      if (sp.x == ep.x || sp.y == ep.y) {
        path.add(new BezierPath.Node(ep.x, ep.y));
      } else {
        Rectangle2D.Double sb = start.getBounds();
        sb.x += 5d;
        sb.y += 5d;
        sb.width -= 10d;
        sb.height -= 10d;
        Rectangle2D.Double eb = end.getBounds();
        eb.x += 5d;
        eb.y += 5d;
        eb.width -= 10d;
        eb.height -= 10d;

        int soutcode = sb.outcode(sp);
        if (soutcode == 0) {
          soutcode = Geom.outcode(sb, eb);
        }
        int eoutcode = eb.outcode(ep);
        if (eoutcode == 0) {
          eoutcode = Geom.outcode(eb, sb);
        }

        if ((soutcode & (Geom.OUT_TOP | Geom.OUT_BOTTOM)) != 0
            && (eoutcode & (Geom.OUT_TOP | Geom.OUT_BOTTOM)) != 0) {
          path.add(
              new BezierPath.Node(
                  BezierPath.C2_MASK, sp.x, sp.y, sp.x, sp.y, sp.x, (sp.y + ep.y) / 2));
          path.add(
              new BezierPath.Node(
                  BezierPath.C1_MASK, ep.x, ep.y, ep.x, (sp.y + ep.y) / 2, ep.x, ep.y));
        } else if ((soutcode & (Geom.OUT_LEFT | Geom.OUT_RIGHT)) != 0
            && (eoutcode & (Geom.OUT_LEFT | Geom.OUT_RIGHT)) != 0) {
          path.add(
              new BezierPath.Node(
                  BezierPath.C2_MASK, sp.x, sp.y, sp.x, sp.y, (sp.x + ep.x) / 2, sp.y));
          path.add(
              new BezierPath.Node(
                  BezierPath.C1_MASK, ep.x, ep.y, (sp.x + ep.x) / 2, ep.y, ep.x, ep.y));
        } else if (soutcode == Geom.OUT_BOTTOM || soutcode == Geom.OUT_TOP) {
          path.add(new BezierPath.Node(BezierPath.C2_MASK, sp.x, sp.y, sp.x, sp.y, sp.x, ep.y));
          path.add(new BezierPath.Node(ep.x, ep.y));
        } else {
          path.add(new BezierPath.Node(BezierPath.C2_MASK, sp.x, sp.y, sp.x, sp.y, ep.x, sp.y));
          path.add(new BezierPath.Node(ep.x, ep.y));
        }
      }
    }

    path.invalidatePath();
  }