Example #1
0
  @Override
  public void paint(Graphics2D g, IGizmo gizmo) {
    int orientation = gizmo.getOrientation();
    int x = gizmo.getX(), y = gizmo.getY();

    Flipper flipper = (Flipper) gizmo;

    Path2D.Double path = new Path2D.Double();
    path.moveTo(x, y + 0.25);
    path.lineTo(x, y + 1.75);
    path.curveTo(x, y + 2, x + 0.5, y + 2, x + 0.5, y + 1.75);
    path.lineTo(x + 0.5, y + 0.25);
    path.curveTo(x + 0.5, y, x, y, x, y + 0.25);

    if (flipper.getAngle() != 0)
      path.transform(AffineTransform.getRotateInstance(flipper.getAngle(), x + 0.25, y + 0.25));

    if (orientation != 0)
      path.transform(AffineTransform.getRotateInstance(Math.PI / 2 * orientation, x + 1, y + 1));

    g.setColor(Color.ORANGE);
    g.fill(path);

    g.setColor(Color.ORANGE.darker());
    g.draw(path);
  }
Example #2
0
  private void paintScaledTriangle(
      Graphics g, double x, double y, double size, int direction, boolean isEnabled) {
    size = Math.max(size, 2);
    Path2D.Double path = new Path2D.Double();
    path.moveTo(-size, size / 2);
    path.lineTo(size, size / 2);
    path.lineTo(0, -size / 2);
    path.closePath();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(Math.PI * (direction - 1) / 4);
    path.transform(affineTransform);

    Graphics2D g2d = (Graphics2D) g;
    double tx = x + size / 2;
    double ty = y + size / 2;
    g2d.translate(tx, ty);
    Color oldColor = g.getColor();
    if (!isEnabled) {
      g2d.translate(1, 0);
      g2d.setColor(highlight);
      g2d.fill(path);
      g2d.translate(-1, 0);
    }
    g2d.setColor(isEnabled ? darkShadow : shadow);
    g2d.fill(path);
    g2d.translate(-tx, -ty);
    g2d.setColor(oldColor);
  }
 private Shape createShape(double x, double y) {
   Path2D.Double path = new Path2D.Double();
   path.moveTo(x - 2, y);
   path.lineTo(x + 2, y);
   path.moveTo(x, y - 2);
   path.lineTo(x, y + 2);
   return path;
 }
Example #4
0
 private void makeShape(
     double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
   shape.moveTo(x1 + x, y1 + y);
   shape.lineTo(x2 + x, y2 + y);
   shape.lineTo(x3 + x, y3 + y);
   shape.lineTo(x4 + x, y4 + y);
   shape.closePath();
 }
Example #5
0
  /** Test of splitLine method, of class ShapeHelper. */
  @Test
  public void testSplitLine_Shape_double() {
    System.out.println("splitLine");

    Path2D.Double line = new Path2D.Double() {};
    line.moveTo(0, 0);
    line.lineTo(10, 10);
    line.lineTo(0, 20);
    line.lineTo(10, 30);
    line.lineTo(0, 40);

    double coords[] = new double[6];
    List<Shape> result1 = ShapeHelper.splitLine(line, 28.28);

    for (Shape shp : result1) {
      PathIterator it = shp.getPathIterator(null);
      System.out.println("Shape: ");

      while (!it.isDone()) {
        it.currentSegment(coords);
        System.out.println("(" + coords[0] + ";" + " " + coords[1] + ")");
        it.next();
      }
    }
    ;

    result1 = ShapeHelper.splitLine(line, 35.0);

    for (Shape shp : result1) {
      PathIterator it = shp.getPathIterator(null);
      System.out.println("Shape: ");

      while (!it.isDone()) {
        it.currentSegment(coords);
        System.out.println("(" + coords[0] + ";" + " " + coords[1] + ")");
        it.next();
      }
    }

    result1 = ShapeHelper.splitLine(line, 70.0);

    for (Shape shp : result1) {
      PathIterator it = shp.getPathIterator(null);
      System.out.println("Shape: ");

      while (!it.isDone()) {
        it.currentSegment(coords);
        System.out.println("(" + coords[0] + ";" + " " + coords[1] + ")");
        it.next();
      }
    }
  }
Example #6
0
  @Override
  public void paint(Graphics2D g, double xOffset, double yOffset, int markerSize) {

    g.setStroke(stroke);
    double halfSize = (double) markerSize / 2;

    // Make a triangle
    Path2D.Double path = new Path2D.Double();
    path.moveTo(xOffset - halfSize, yOffset - halfSize + markerSize - 1);
    path.lineTo(xOffset - halfSize + markerSize, yOffset - halfSize + markerSize - 1);
    path.lineTo(xOffset, yOffset - halfSize - 1);
    path.closePath();
    g.fill(path);
  }
 private Path2D.Double getPath() {
   double width = getWidth() - 1;
   double height = getHeight();
   Path2D.Double path = new Path2D.Double();
   path.moveTo(0.0, arcwidth);
   path.curveTo(0.0, 0.0, arcwidth, 0.0, arcwidth, 0.0);
   path.lineTo(width - arcwidth, 0.0);
   path.curveTo(width, 0.0, width, arcwidth, width, arcwidth);
   path.lineTo(width, height);
   // path.curveTo(width, height, width - arcwidth, height, width - arcwidth, height);
   path.lineTo(0.0, height);
   // path.curveTo(0.0, height, 0.0, height - arcwidth, 0, height - arcwidth);
   path.closePath();
   return path;
 }
Example #8
0
  @Override
  public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {

    if (getDel()) return;

    path.lineTo(getX() * parent.getWidth(), getY() * parent.getHeight());
  }
Example #9
0
  @Override
  public void paint(Graphics2D g, double xOffset, double yOffset) {

    g.setStroke(stroke);

    // Make a diamond
    double diamondHalfSize = Marker.HALF_SIZE * 1.3;

    Path2D.Double path = new Path2D.Double();
    path.moveTo(xOffset - diamondHalfSize, yOffset);
    path.lineTo(xOffset, yOffset - diamondHalfSize);
    path.lineTo(xOffset + diamondHalfSize, yOffset);
    path.lineTo(xOffset, yOffset + diamondHalfSize);
    path.closePath();
    g.fill(path);
  }
Example #10
0
  public void calculatePath() {
    path = new Path2D.Double();

    path.moveTo(xpoints[0], ypoints[0]);
    for (int i = 1; i < npoints; i++) path.lineTo(xpoints[i], ypoints[i]);

    bounds = path.getBounds2D();
  }
Example #11
0
  /**
   * Loads an individual polygon from the polygon file.
   *
   * @param bufferedReader The reader connected to the polygon file placed at the first record of a
   *     polygon section.
   * @return An area representing the section polygon.
   */
  private Area loadSectionPolygon(BufferedReader bufferedReader) throws IOException {
    Path2D.Double polygonPath;
    double[] beginPoint = null;

    // Create a new path to represent this polygon.
    polygonPath = new Path2D.Double();

    while (true) {
      String sectionLine;
      double[] coordinates;

      // Read until a non-empty line is obtained.
      do {
        sectionLine = bufferedReader.readLine();

        // It is invalid for the file to end without a section "END" record.
        if (sectionLine == null) {
          throw new OsmosisRuntimeException(
              "File terminated prematurely without a section END record.");
        }

        // Remove any whitespace.
        sectionLine = sectionLine.trim();

      } while (sectionLine.length() == 0);

      // Stop reading when the section END record is reached.
      if ("END".equals(sectionLine)) {
        break;
      }

      // Parse the line into its coordinates.
      coordinates = parseCoordinates(sectionLine);

      // Add the current point to the path.
      if (beginPoint != null) {
        polygonPath.lineTo(coordinates[0], coordinates[1]);
      } else {
        polygonPath.moveTo(coordinates[0], coordinates[1]);
        beginPoint = coordinates;
      }
    }

    // If we received data, draw another line from the final point back to the beginning point.
    if (beginPoint != null) {
      polygonPath.moveTo(beginPoint[0], beginPoint[1]);
    }

    // Convert the path into an area and return.
    return new Area(polygonPath);
  }
Example #12
0
 private Path2D.Double makeStar(int r1, int r2, int vc) {
   int or = Math.max(r1, r2);
   int ir = Math.min(r1, r2);
   double agl = 0d;
   double add = 2 * Math.PI / (vc * 2);
   Path2D.Double p = new Path2D.Double();
   p.moveTo(or * 1, or * 0);
   for (int i = 0; i < vc * 2 - 1; i++) {
     agl += add;
     int r = i % 2 == 0 ? ir : or;
     p.lineTo(r * Math.cos(agl), r * Math.sin(agl));
   }
   p.closePath();
   AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 2, or, 0);
   return new Path2D.Double(p, at);
 }
Example #13
0
  @Test
  public void testGetPointAt() {
    Path2D.Double path = new Path2D.Double();
    path.moveTo(10, 10);

    path.lineTo(20, 10);
    path.lineTo(20, 20);

    Double pointAt = ShapeHelper.getPointAt(path, 30);

    System.out.println("PT: " + pointAt.getX() + ";" + pointAt.getY());
    assertEquals(pointAt.getX(), 20.0, 0.00001);
    assertEquals(pointAt.getY(), 30.0, 0.00001);

    path = new Path2D.Double();
  }
  private void setPath() {
    path.reset();
    int n = points.length;

    for (int j = 0; j <= numberOfInterpolationPoints; j++) {
      double t = (double) j / numberOfInterpolationPoints; // [0 <= t <= 1.0]
      double x = 0;
      double y = 0;
      for (int k = 0; k < n; k++) {
        x += B(n - 1, k, t) * points[k].x;
        y += B(n - 1, k, t) * points[k].y;
      }
      if (j > 0) {
        path.lineTo(x, y);
      } else {
        path.moveTo(x, y);
      }
    } // end for
  } // end setPath
Example #15
0
  protected void updatePath(double x, double y) {
    if (path == null) {
      path = new Path2D.Double(Path2D.WIND_EVEN_ODD);
      path.moveTo(x, y);
      bounds = new Rectangle2D.Double(x, y, 0, 0);
    } else {
      path.lineTo(x, y);

      double _xmax = bounds.getMaxX();
      double _ymax = bounds.getMaxY();
      double _xmin = bounds.getMinX();
      double _ymin = bounds.getMinY();

      if (x < _xmin) _xmin = x;
      else if (x > _xmax) _xmax = x;
      if (y < _ymin) _ymin = y;
      else if (y > _ymax) _ymax = y;

      bounds = new Rectangle2D.Double(_xmin, _ymin, _xmax - _xmin, _ymax - _ymin);
    }
  }
Example #16
0
  @Override
  public void render(Graphics2D g) {
    // TODO Auto-generated method stub

    if (((IntegerPropertyType) this.getProperty("Bubble").getValue()).intValue() > 0) {
      Rectangle2D.Double[] points = new Rectangle2D.Double[this.getNumberOfNodes()];
      for (int i = 0; i < this.getNumberOfNodes(); i++) {
        Rectangle2D r = this.getPointBounds(i);

        // points[i] = new Rectangle2D.Double(this.getNodeX(i) - this.getNodeSize(i)/2,
        // this.getNodeY(i) - this.getNodeSize(i)/2, this.getNodeSize(i), this.getNodeSize(i));
        points[i] =
            new Rectangle2D.Double(
                this.getNodeX(i) - r.getWidth() / 2,
                this.getNodeY(i) - r.getHeight() / 2,
                r.getWidth(),
                r.getHeight());
      }

      //	this.setAspect(PointAspectType.RECT_NO_LABEL);

      int[] s1 = this.getSelectedNodes();
      int[] s2 = new int[this.getNumberOfNodes() - s1.length];
      for (int i = 0, c = 0; i < this.getNumberOfNodes(); i++) {
        boolean found = false;
        for (int j = 0; j < s1.length; j++)
          if (s1[j] == i) {
            found = true;
            break;
          }
        ;
        if (!found) {
          s2[c] = i;
          c++;
        }
      }
      int[][] sets = new int[2][];
      sets[0] = s1;
      sets[1] = s2;

      this.bubbleSets = new BubbleSets(points, sets);
      bubbleSets.computeContour(10, 100, this.getNodeSize(0) / 2, 0);
    }

    if (bigGrid != null) {
      g.drawImage(bigGrid, bigGridSX, bigGridSY, null);
    }

    if (bubbleSets != null) {
      bubbleSets.computeContour(
          ((IntegerPropertyType) this.getProperty("BubbleCellSize").getValue()).intValue(),
          ((IntegerPropertyType) this.getProperty("BubbleR1").getValue()).intValue(),
          this.getNodeSize(0) / 5,
          0);

      /*	for (int i=0;  bubbleSets.paths != null && i<bubbleSets.paths.size(); i++)
      {
      	for (int j=1; j<bubbleSets.paths.get(i).size(); j++)
      	{
      		Point2D.Double p1 = bubbleSets.paths.get(i).get(j-1);
      		Point2D.Double p2 = bubbleSets.paths.get(i).get(j);
      		g.drawLine((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y);
      	}
      }*/

      // the grid

      double contThresh =
          ((DoublePropertyType) this.getProperty("BubbleThresh").getValue()).doubleValue();

      /*for (int i=0; bubbleSets.grid != null && i<bubbleSets.grid.length; i++)
      {
      	for (int j=0; j<bubbleSets.grid[i].length; j++)
      	{
      		int cx = (int)bubbleSets.centroid.x;
      		int cy = (int)bubbleSets.centroid.y;


      		double degd = bubbleSets.grid[i][j];


      		if (degd < 0) degd = 0; if (degd > 1) degd = 1;
      		if (degd > contThresh) degd = 0.5;
      		int deg = (int)(255* degd);
      		if (deg < 0) deg = 0;

      		if (deg == 0)
      			continue;


      		g.setColor(new Color(255-deg, 255, 255-deg, 100));



      		g.fillRect((int)(bubbleSets.minX + i*bubbleSets.cellSize),(int)( bubbleSets.minY + j*bubbleSets.cellSize),(int)bubbleSets.cellSize, (int)bubbleSets.cellSize);
      	}
      }*/

      Point2D.Double[][] lin =
          Util.marchingSquares(
              bubbleSets.grid,
              bubbleSets.cellSize,
              new Point2D.Double(bubbleSets.minX, bubbleSets.minY),
              contThresh);

      g.setColor(Color.green);
      g.setStroke(new BasicStroke(2));

      Path2D.Double path = new Path2D.Double();
      for (int i = 0; i < lin.length; i++) {

        if (lin[i].length > 0) path.moveTo((int) lin[i][0].x, (int) lin[i][0].y);

        for (int j = 1; j < lin[i].length; j++) path.lineTo((int) lin[i][j].x, (int) lin[i][j].y);

        path.closePath();
      }
      //  path.closePath();
      g.fill(path);
      if (lin.length > 1) g.setColor(Color.red);
      else g.setColor(Color.black);

      Color[] cs = {
        Color.red, Color.blue, Color.orange, Color.black, Color.cyan, Color.MAGENTA, Color.pink
      };
      for (int i = 0; i < lin.length; i++) {
        g.setColor(cs[i]);
        for (int j = 1; j < lin[i].length; j++)
          g.drawLine(
              (int) lin[i][j - 1].x, (int) lin[i][j - 1].y, (int) lin[i][j].x, (int) lin[i][j].y);
      }

      // g.draw(path);

    }
    super.render(g);
  }
Example #17
0
  void createBubbles() {
    if (clusters == null) return;

    synchronized (this.bigGridCompute) {
      String sm = ((StringPropertyType) (this.getProperty("Smaller").getValue())).stringValue();
      String[] smaller = sm.split(",");

      ArrayList<String> nodes = graph.getNodes();

      int minx = 999999999;
      int miny = 999999999;
      int maxx = -999999999;
      int maxy = -999999999;
      for (int i = 0; i < nodes.size(); i++) {
        int x = drawer.getX(i);
        int y = drawer.getY(i);

        if (x < minx) minx = x;
        if (x > maxx) maxx = x;
        if (y < miny) miny = y;
        if (y > maxy) maxy = y;
      }
      minx = minx - 500;
      maxx = maxx + 500;
      miny = miny - 100;
      maxy = maxy + 100;

      bigGrid = new BufferedImage(maxx - minx, maxy - miny, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = bigGrid.createGraphics();

      bigGridSX = minx;
      bigGridSY = miny;

      for (int j = 0; j < clusterTypes.size(); j++) {
        int ct = 0;
        for (int i = 0; i < nodes.size(); i++) if (clusterTypes.get(j).equals(clusters[i])) ct++;

        Rectangle2D.Double[] points = new Rectangle2D.Double[nodes.size()];
        int[] s1 = new int[ct];
        int[] s2 = new int[nodes.size() - ct];

        ct = 0;
        int ct2 = 0;
        for (int i = 0; i < nodes.size(); i++) {
          Rectangle2D r = this.getPointBounds(i);
          points[i] =
              new Rectangle2D.Double(
                  this.getNodeX(i) - r.getWidth() / 2,
                  this.getNodeY(i) - r.getHeight() / 2,
                  r.getWidth(),
                  r.getHeight());

          if (!clusterTypes.get(j).equals(clusters[i])) {
            s2[ct2] = i;
            ct2++;
          } else {
            s1[ct] = i;
            ct++;
          }
        }

        int[][] sets = new int[2][];
        sets[0] = s1;
        sets[1] = s2;

        BubbleSets bs = new BubbleSets(points, sets);
        int r = ((IntegerPropertyType) this.getProperty("BubbleR1").getValue()).intValue();
        boolean b = false;
        for (int k = 0; k < smaller.length; k++)
          if (smaller[k].equals(clusterTypes.get(j))) b = true;
        if (b) r = r / 2;
        bs.computeContour(
            ((IntegerPropertyType) this.getProperty("BubbleCellSize").getValue()).intValue(),
            r,
            this.getNodeSize(0) / 5,
            0);
        double contThresh =
            ((DoublePropertyType) this.getProperty("BubbleThresh").getValue()).doubleValue();
        // Point2D.Double[][] lin = Util.marchingSquares(bs.grid, bs.cellSize, new
        // Point2D.Double(bs.minX, bs.minY), contThresh);

        Color c = this.getColor(s1[0]);

        double re1 = (c.getRed() + 20 - 105. / 255. * 230.) / (150. / 255.);
        double gr1 = (c.getGreen() + 20 - 105. / 255. * 230.) / (150. / 255.);
        double bl1 = (c.getBlue() + 20 - 105. / 255. * 230.) / (150. / 255.);

        if (re1 < 0) re1 = 0;
        if (re1 > 255) re1 = 255;
        if (gr1 < 0) gr1 = 0;
        if (gr1 > 255) gr1 = 255;
        if (bl1 < 0) bl1 = 0;
        if (bl1 > 255) bl1 = 255;

        c = new Color((int) re1, (int) gr1, (int) bl1, 150);
        Color c2 = new Color((int) re1, (int) gr1, (int) bl1, 140);
        Color c3 = new Color((int) re1, (int) gr1, (int) bl1, 130);

        // Color c3 = new Color((int)(0.2*c.getRed()),
        // (int)(0.2*c.getGreen()),(int)(0.2*c.getBlue()), 50);
        g.setColor(c);

        for (int i = 0; bs.grid != null && i < bs.grid.length; i++) {
          for (int k = 0; k < bs.grid[i].length; k++) {
            double degd = bs.grid[i][k];

            if (degd < 0) degd = 0;
            if (degd > 1) degd = 1;
            if (degd > contThresh) {
              if (degd > contThresh * 1.5) g.setColor(c);
              else if (degd > contThresh * 1.25) g.setColor(c2);
              else g.setColor(c3);

              g.fillRect(
                  (int) (bs.minX + i * bs.cellSize - bigGridSX),
                  (int) (bs.minY + k * bs.cellSize - bigGridSY),
                  (int) bs.cellSize,
                  (int) bs.cellSize);
            }
          }
        }

        Point2D.Double[][] lin =
            Util.marchingSquares(
                bs.grid, bs.cellSize, new Point2D.Double(bs.minX, bs.minY), contThresh);

        int lum = (c.getRed() + c.getGreen() + c.getBlue()) / 3;
        lum = (int) (0.3 * lum);

        int minc = Math.min(c.getRed(), Math.min(c.getGreen(), c.getBlue()));
        int maxc = Math.max(c.getRed(), Math.max(c.getGreen(), c.getBlue()));

        double re = lum + (200 - lum) * (c.getRed() - minc) / ((double) maxc - minc);
        double gr = lum + (200 - lum) * (c.getGreen() - minc) / ((double) maxc - minc);
        double bl = lum + (200 - lum) * (c.getBlue() - minc) / ((double) maxc - minc);

        Color c4 = new Color((int) re, (int) gr, (int) bl, 75);
        g.setColor(c4);
        g.setStroke(new BasicStroke(4));

        Path2D.Double path = new Path2D.Double();
        for (int i = 0; i < lin.length; i++) {
          if (lin[i].length > 0)
            path.moveTo((int) lin[i][0].x - bigGridSX, (int) lin[i][0].y - bigGridSY);
          for (int k = 1; k < lin[i].length; k++) {
            Point2D.Double p1 = lin[i][k - 1];
            Point2D.Double p2 = lin[i][k];
            //  g.drawLine((int)lin[i][k-1].x  - bigGridSX, (int)lin[i][k-1].y - bigGridSY,
            // (int)lin[i][k].x  - bigGridSX, (int)lin[i][k].y- bigGridSY);
            path.lineTo((int) lin[i][k].x - bigGridSX, (int) lin[i][k].y - bigGridSY);
          }
          path.closePath();
        }
        g.draw(path);
      }
    }
  }