示例#1
0
  private static void graph(Polygon[] finalPolygons) {
    int weiners = 0;
    String[] Starter = sPoint.split(",");
    String[] Ender = ePoint.split(",");
    int endx = Integer.parseInt(Ender[0]);
    int endy = Integer.parseInt(Ender[1]);
    int G = 40;
    for (int i = 0; i < G; i++) {
      for (int j = 0; j < G; j++) {
        int loketest = 0;
        if ((i == Startx && j == Starty) || i == endx && j == endy) {
          loketest = 2;
        }
        for (Polygon helpme : finalPolygons) {
          if (helpme.contains(i, j)) {
            loketest = 1;
          }
        }
        if (loketest == 1) {
          System.out.print("1");
        } else if (loketest == 2) {
          System.out.print("X");
        } else {
          System.out.print("0");
        }
      }

      System.out.println("     \t");
      weiners++;
    }
  }
示例#2
0
    public LinePanel() {
      p = new Polygon();
      p.addPoint(nextX, nextY);
      addKeyListener(
          new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
              switch (e.getKeyCode()) {
                case KeyEvent.VK_UP:
                  nextY -= step;
                  break;
                case KeyEvent.VK_DOWN:
                  nextY += step;
                  break;
                case KeyEvent.VK_LEFT:
                  nextX -= step;
                  break;
                case KeyEvent.VK_RIGHT:
                  nextX += step;
                  break;
              }
              p.addPoint(nextX, nextY);
              repaint();
            }
          });
    }
示例#3
0
  // From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135
  void drawArrow(
      Graphics2D g2d,
      int xCenter,
      int yCenter,
      int x,
      int y,
      float stroke,
      BasicStroke drawStroke) {
    double aDir = Math.atan2(xCenter - x, yCenter - y);
    // Line can be dashed.
    g2d.setStroke(drawStroke);
    g2d.drawLine(x, y, xCenter, yCenter);
    // make the arrow head solid even if dash pattern has been specified
    g2d.setStroke(lineStroke);
    Polygon tmpPoly = new Polygon();
    int i1 = 12 + (int) (stroke * 2);
    // make the arrow head the same size regardless of the length length
    int i2 = 6 + (int) stroke;
    tmpPoly.addPoint(x, y);
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);

    // Remove this line to leave arrow head unpainted:
    g2d.fillPolygon(tmpPoly);
  }
    public void paintIcon(Component c, Graphics g, int x, int y) {
      int w = getIconWidth();
      int h = w;
      Polygon p = new Polygon();
      switch (direction) {
        case EAST:
          p.addPoint(x + 2, y);
          p.addPoint(x + w - 2, y + h / 2);
          p.addPoint(x + 2, y + h - 1);
          break;

        case SOUTH:
          p.addPoint(x, y + 2);
          p.addPoint(x + w / 2, y + h - 2);
          p.addPoint(x + w - 1, y + 2);
          break;
      }
      g.fillPolygon(p);
    }
示例#5
0
  public void processPolygonSpline(boolean shiftDown) {
    mCurrPC.setBatchModeOn();
    if (!shiftDown) mCurrPC.unselectAll();

    // loop on spline pts to construct a Polygon
    Polygon srcArea = new Polygon();
    for (int s = 0; s < mSplinePoints.size(); s++) {
      Point p = (Point) mSplinePoints.elementAt(s);
      int x = p.x - mLeft - 5;
      int y = p.y - mTop - 5;

      srcArea.addPoint(x, y);
    }

    mSplinePoints.removeAllElements();

    // search for matches
    byte[] currFilterResults = fdm.getResults();
    double[] yArray1 = getYArray1();
    double[] xArray1 = getXArray1();
    double[] yArray2 = getYArray2();
    double[] xArray2 = getXArray2();
    Point p1 = new Point();
    Point p2 = new Point();

    for (int i = 0; i < mCurrPC.getSize(); i++) {
      if (!mIgnoreFilter
          && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i)))
        continue;
      double yi = yArray1[i];
      double xi = xArray1[i];
      double xi2 = Float.NaN;
      double yi2 = Float.NaN;
      double xx2 = Float.NaN;
      double yy2 = Float.NaN;

      // correct the X value if necessary
      xi = correctX(xi);

      double xx1 = (xi - winXOrigin) * winXScale;
      double yy1 = (yi - winYOrigin) * winYScale;

      // correct the Y coordinate if necessary
      yy1 = correctY(yy1);

      if (!isYAxisScaler()) {
        yi2 = yArray2[i];
        yy2 = (yi2 - winYOrigin) * winYScale;
        ;
        yy2 = correctY(yy2);
      } else yy2 = yy1;

      if (!isXAxisScaler()) {
        xi2 = xArray2[i];
        xi2 = correctX(xi2);
        xx2 = (xi2 - winXOrigin) * winXScale;
      } else xx2 = xx1;

      p1.setLocation((int) xx1, (int) yy1);
      p2.setLocation((int) xx2, (int) yy2);

      if (srcArea.contains(p1) || srcArea.contains(p2)) {
        mCurrPC.select(i);
      }
    }
    mViewManager.invalidateAllViews();
    mCurrPC.setBatchModeOff();
  }
示例#6
0
  public void processSectionSpline(boolean shiftDown) {
    mCurrPC.setBatchModeOn();

    if (!shiftDown) mCurrPC.unselectAll();

    // loop on spline pts
    for (int s = 0; s < mSplinePoints.size() - 2; s++) {
      Point p1 = (Point) mSplinePoints.elementAt(s);
      Point p2 = (Point) mSplinePoints.elementAt(s + 1);

      int x1 = p1.x - mLeft - 5;
      int y1 = p1.y - mTop - 5;
      int x2 = p2.x - mLeft - 5;
      int y2 = p2.y - mTop - 5;

      // construct the search polygon
      double dx = x1 - x2;
      double dy = y1 - y2;
      int width1 = ComputeSectionPixelWidth(p1);
      int width2 = ComputeSectionPixelWidth(p2);

      if (dx == 0 && dy == 0) return;
      double dist = (double) Math.pow(dx * dx + dy * dy, 0.5f);

      double p1x = x1 + (double) width1 * (-dy / dist);
      double p1y = y1 + (double) width1 * (dx / dist);

      double p2x = x1 - (double) width1 * (-dy / dist);
      double p2y = y1 - (double) width1 * (dx / dist);

      double p3x = x2 + (double) width2 * (-dy / dist);
      double p3y = y2 + (double) width2 * (dx / dist);

      double p4x = x2 - (double) width2 * (-dy / dist);
      double p4y = y2 - (double) width2 * (dx / dist);

      Polygon srcArea = new Polygon();
      srcArea.addPoint((int) p2x, (int) p2y);
      srcArea.addPoint((int) p1x, (int) p1y);
      srcArea.addPoint((int) p3x, (int) p3y);
      srcArea.addPoint((int) p4x, (int) p4y);

      // search for matches
      byte[] currFilterResults = fdm.getResults();
      double[] yArray1 = getYArray1();
      double[] xArray1 = getXArray1();
      double[] yArray2 = getYArray2();
      double[] xArray2 = getXArray2();
      mCurrPC.setBatchModeOn();
      for (int i = 0; i < mCurrPC.getSize(); i++) {
        if (!mIgnoreFilter
            && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i)))
          continue;
        double yi = yArray1[i];
        double xi = xArray1[i];
        double xi2 = Float.NaN;
        double yi2 = Float.NaN;
        double xx2 = Float.NaN;
        double yy2 = Float.NaN;

        // correct the X value if necessary
        xi = correctX(xi);

        double xx1 = (xi - winXOrigin) * winXScale;
        double yy1 = (yi - winYOrigin) * winYScale;

        // correct the Y coordinate if necessary
        yy1 = correctY(yy1);

        if (!isYAxisScaler()) {
          yi2 = yArray2[i];
          yy2 = (yi2 - winYOrigin) * winYScale;
          ;
          yy2 = correctY(yy2);
        } else yy2 = yy1;

        if (!isXAxisScaler()) {
          xi2 = xArray2[i];
          xi2 = correctX(xi2);
          xx2 = (xi2 - winXOrigin) * winXScale;
        } else xx2 = xx1;

        if (srcArea.contains(new Point((int) xx1, (int) yy1))
            || srcArea.contains(new Point((int) xx2, (int) yy2))) {
          mCurrPC.select(i);
        }
      }
    } // for splines

    mSplinePoints.removeAllElements();
    mViewManager.invalidateAllViews();
    mCurrPC.setBatchModeOff();
  }
示例#7
0
  public void rubberbandEnded(Rubberband rb, boolean shiftDown) {
    // get the limits and zoom the plot
    if (mCurrPC == null) return;
    Rectangle rbRect = rb.getBounds();
    if (rbRect.width == 0 || rbRect.height == 0) {
      // click selection
      if (toolMode == Constants.SELECT_MODE) {
        // find any matches at the mouseclick location
        int x = rbRect.x - mLeft - 5;
        int y = rbRect.y - mTop - 5;

        // construct a search region;
        int[] xpoints = {x - 1, x + 1, x + 1, x - 1, x - 1};
        int[] ypoints = {y - 1, y - 1, y + 1, y + 1, y - 1};
        Polygon sr = new Polygon(xpoints, ypoints, 5);

        if (!shiftDown) mCurrPC.unselectAll();

        mCurrPC.setBatchModeOn();

        byte[] currFilterResults = fdm.getResults();
        double[] yArray1 = getYArray1();
        double[] xArray1 = getXArray1();
        double[] yArray2 = getYArray2();
        double[] xArray2 = getXArray2();

        for (int i = 0; i < mCurrPC.getSize(); i++) {
          if (!mIgnoreFilter && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4)
              || !mCurrPC.isSelectedLayer(i)) continue;

          // search for matches
          double yi = yArray1[i];
          double xi = xArray1[i];
          double xi2 = Float.NaN;
          double yi2 = Float.NaN;
          double x2 = Float.NaN;
          double y2 = Float.NaN;

          // correct the X value if necessary
          xi = correctX(xi);

          double x1 = (xi - winXOrigin) * winXScale;
          double y1 = (yi - winYOrigin) * winYScale;

          // correct the Y coordinate if necessary
          y1 = correctY(y1);

          if (!isYAxisScaler()) {
            yi2 = yArray2[i];
            y2 = (yi2 - winYOrigin) * winYScale;
            y2 = correctY(y2);
          } else y2 = y1;

          if (!isXAxisScaler()) {
            xi2 = xArray2[i];
            xi2 = correctX(xi2);
            x2 = (xi2 - winXOrigin) * winXScale;
          } else x2 = x1;

          if (sr.contains(new Point((int) x1, (int) y1))
              || sr.contains(new Point((int) x2, (int) y2))) {
            mCurrPC.select(i);
          }
        }
        mViewManager.invalidateAllViews();
        mCurrPC.setBatchModeOff();
      } else if (toolMode == Constants.ZOOM_MODE) {
        if (!shiftDown) {
          doZoomIn(rbRect);
        } else {
          // zoom out
          double xInc = getXZoomIncrement();
          double yInc = getYZoomIncrement();
          double[] oldYs = {getMaxYVal(), getMinYVal()};
          double[] newYs = {
            getMinYVal() < 0 ? getMinYVal() - yInc : getMinYVal() + yInc,
            getMaxYVal() < 0 ? getMaxYVal() - yInc : getMaxYVal() + yInc
          };
          double[] oldXs = {getMinXVal(), getMaxXVal()};
          double[] newXs = {
            getMinXVal() < 0 ? getMinXVal() - xInc : getMinXVal() + xInc,
            getMaxXVal() < 0 ? getMaxXVal() - xInc : getMaxXVal() + xInc
          };
          this.zoomDomain(oldYs, newYs, oldXs, newXs);
        }
        mViewManager.invalidateAllViews();
      }
    } else {
      // region selected
      int x = rbRect.x - mLeft - 5;
      int y = rbRect.y - mTop - 5;
      int x2 = x + rbRect.width;
      int y2 = y + rbRect.height;
      Point p1 = new Point();
      Point p2 = new Point();

      if (toolMode == Constants.SELECT_MODE) {
        if (!shiftDown) mCurrPC.unselectAll();

        // construct a search region;
        int[] xpoints = {x, x2, x2, x, x};
        int[] ypoints = {y, y, y2, y2, y};
        Polygon sr = new Polygon(xpoints, ypoints, 5);

        // search for matches
        byte[] currFilterResults = fdm.getResults();
        double[] yArray1 = getYArray1();
        double[] xArray1 = getXArray1();
        double[] yArray2 = getYArray2();
        double[] xArray2 = getXArray2();

        mCurrPC.setBatchModeOn();
        for (int i = 0; i < mCurrPC.getSize(); i++) {
          if (!mIgnoreFilter
              && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i)))
            continue;

          double yi = yArray1[i];
          double xi = xArray1[i];
          double xi2 = Float.NaN;
          double yi2 = Float.NaN;
          double xx2 = Float.NaN;
          double yy2 = Float.NaN;

          // correct the X value if necessary
          xi = correctX(xi);

          double xx1 = (xi - winXOrigin) * winXScale;
          double yy1 = (yi - winYOrigin) * winYScale;

          // correct the Y coordinate if necessary
          yy1 = correctY(yy1);

          if (!isYAxisScaler()) {
            yi2 = yArray2[i];
            yy2 = (yi2 - winYOrigin) * winYScale;
            yy2 = correctY(yy2);
          } else yy2 = yy1;

          if (!isXAxisScaler()) {
            xi2 = xArray2[i];
            xi2 = correctX(xi2);
            xx2 = (xi2 - winXOrigin) * winXScale;
          } else xx2 = xx1;

          p1.setLocation((int) xx1, (int) yy1);
          p2.setLocation((int) xx2, (int) yy2);

          if (sr.contains(p1) || sr.contains(p2)) {
            mCurrPC.select(i);
          }
        }
        mViewManager.invalidateAllViews();
        mCurrPC.setBatchModeOff();
      } else if (toolMode == Constants.ZOOM_MODE) {
        // correct the x value if necessary
        double xx = correctX((double) x);
        double xx2 = correctX((double) x2);

        // correct the Y coordinate if necessary
        double yy = correctY((double) y);
        double yy2 = correctY((double) y2);

        double newX = (xx / winXScale) + winXOrigin;
        double newX2 = (xx2 / winXScale) + winXOrigin;
        double newY = (yy / winYScale) + winYOrigin;
        double newY2 = (yy2 / winYScale) + winYOrigin;

        double[] oldYs = {getMaxYVal(), getMinYVal()};
        if (this.toString().indexOf("Depth") >= 0) {
          double temp = newY2;
          newY2 = newY;
          newY = temp;
        }
        double[] newYs = {newY2, newY};

        double[] oldXs = {getMinXVal(), getMaxXVal()};
        double[] newXs = {newX, newX2};
        this.zoomDomain(oldYs, newYs, oldXs, newXs);
        mViewManager.invalidateAllViews();
      }
    }
  }
 public Rectangle getBounds() {
   return areaShape.getBounds();
 }
 // PMElement interface methods
 public void translate(int x, int y) {
   areaShape.translate(x, y);
 }
package gui;