Esempio n. 1
0
 public void drawTo(Graphics g, Line line) {
   if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return;
   if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) {
     Point p1 = calc.tileToMinimap(t1);
     Point p2 = calc.tileToMinimap(t2);
     Point p3 = calc.tileToMinimap(line.getTile2());
     Point p4 = calc.tileToMinimap(line.getTile1());
     GeneralPath path = new GeneralPath();
     path.moveTo(p1.x, p1.y);
     path.lineTo(p2.x, p2.y);
     path.lineTo(p3.x, p3.y);
     path.lineTo(p4.x, p4.y);
     path.closePath();
     g.setColor(POLY_FILL);
     ((Graphics2D) g).fill(path);
     ((Graphics2D) g).draw(path);
   }
   Point last = null, p;
   g.setColor(Color.ORANGE);
   for (RSTile t : pathList) {
     if (calc.tileOnMap(t)) {
       p = calc.tileToMinimap(t);
       g.fillOval(p.x - 2, p.y - 2, 5, 5);
       if (last != null) g.drawLine(p.x, p.y, last.x, last.y);
       last = p;
     } else last = null;
   }
 }
Esempio n. 2
0
 /**
  * Draws a Line object on the GrapherPanel as a 1 pixel wide line ending on the points defining
  * the Line object.
  *
  * @param The Line to paint.
  */
 private void paintLine(Line l) {
   g.setColor(Color.YELLOW);
   g.drawLine(
       250 + (int) (l.getPointA().getX() * 25),
       250 - (int) (l.getPointA().getY() * 25),
       250 + (int) (l.getPointB().getX() * 25),
       250 - (int) (l.getPointB().getY() * 25));
 }
Esempio n. 3
0
 /**
  * Draws a Polygon object on the GrapherPanel as a series of 1 pixel wide lines contained in the
  * polygon's sides variable.
  *
  * @param The Polygon to paint.
  */
 private void paintPolygon(Polygon p) {
   g.setColor(Color.GREEN);
   for (Line l : p.getSides()) {
     g.drawLine(
         250 + (int) (l.getPointA().getX() * 25),
         250 - (int) (l.getPointA().getY() * 25),
         250 + (int) (l.getPointB().getX() * 25),
         250 - (int) (l.getPointB().getY() * 25));
   }
 }
Esempio n. 4
0
 /**
  * Draws a Triangle object on the GrapherPanel as a series of 1 pixel wide lines contained in the
  * Triangle's sides variable.
  *
  * @param The Triangle to paint.
  */
 private void paintTriangle(Triangle t) {
   g.setColor(Color.GREEN);
   for (Line l : t.getSides()) {
     g.drawLine(
         250 + (int) (l.getPointA().getX() * 25),
         250 - (int) (l.getPointA().getY() * 25),
         250 + (int) (l.getPointB().getX() * 25),
         250 - (int) (l.getPointB().getY() * 25));
   }
 }
Esempio n. 5
0
 void lineWidth() {
   int width = (int) IJ.getNumber("Line Width:", Line.getWidth());
   if (width == IJ.CANCELED) return;
   Line.setWidth(width);
   LineWidthAdjuster.update();
   ImagePlus imp = WindowManager.getCurrentImage();
   if (imp != null && imp.isProcessor()) {
     ImageProcessor ip = imp.getProcessor();
     ip.setLineWidth(Line.getWidth());
     Roi roi = imp.getRoi();
     if (roi != null && roi.isLine()) imp.draw();
   }
 }
Esempio n. 6
0
 public Line render(String text, Color c) {
   Line t = new Line(text);
   Coord sz = strsize(text);
   if (sz.x < 1) sz = sz.add(1, 0);
   t.img = TexI.mkbuf(sz);
   Graphics g = t.img.createGraphics();
   if (aa) Utils.AA(g);
   g.setFont(font);
   g.setColor(c);
   t.m = g.getFontMetrics();
   g.drawString(text, 0, t.m.getAscent());
   g.dispose();
   return (t);
 }
  public void changeColor() {

    // set initial color of top left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.cyan);
    }
    // set initial color of top right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.magenta);
    }
    // set initial color of bottom left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.yellow);
    }
    // set initial color of bottom right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.black);
    }
  }
Esempio n. 8
0
 void addSelection() {
   ImagePlus imp = IJ.getImage();
   String macroOptions = Macro.getOptions();
   if (macroOptions != null && IJ.macroRunning() && macroOptions.indexOf("remove") != -1) {
     imp.setOverlay(null);
     return;
   }
   Roi roi = imp.getRoi();
   if (roi == null && imp.getOverlay() != null) {
     GenericDialog gd = new GenericDialog("No Selection");
     gd.addMessage("\"Overlay>Add\" requires a selection.");
     gd.setInsets(15, 40, 0);
     gd.addCheckbox("Remove existing overlay", false);
     gd.showDialog();
     if (gd.wasCanceled()) return;
     if (gd.getNextBoolean()) imp.setOverlay(null);
     return;
   }
   if (roi == null) {
     IJ.error("This command requires a selection.");
     return;
   }
   roi = (Roi) roi.clone();
   if (roi.getStrokeColor() == null) roi.setStrokeColor(Toolbar.getForegroundColor());
   int width = Line.getWidth();
   Rectangle bounds = roi.getBounds();
   boolean tooWide = width > Math.max(bounds.width, bounds.height) / 3.0;
   if (roi.getStroke() == null && width > 1 && !tooWide) roi.setStrokeWidth(Line.getWidth());
   Overlay overlay = imp.getOverlay();
   if (overlay != null && overlay.size() > 0 && !roi.isDrawingTool()) {
     Roi roi2 = overlay.get(overlay.size() - 1);
     if (roi.getStroke() == null) roi.setStrokeWidth(roi2.getStrokeWidth());
     if (roi.getFillColor() == null) roi.setFillColor(roi2.getFillColor());
   }
   boolean points = roi instanceof PointRoi && ((PolygonRoi) roi).getNCoordinates() > 1;
   if (points) roi.setStrokeColor(Color.red);
   if (!IJ.altKeyDown() && !(roi instanceof Arrow)) {
     RoiProperties rp = new RoiProperties("Add to Overlay", roi);
     if (!rp.showDialog()) return;
   }
   String name = roi.getName();
   boolean newOverlay = name != null && name.equals("new-overlay");
   if (overlay == null || newOverlay) overlay = new Overlay();
   overlay.add(roi);
   imp.setOverlay(overlay);
   overlay2 = overlay;
   if (points || (roi instanceof ImageRoi) || (roi instanceof Arrow)) imp.killRoi();
   Undo.setup(Undo.OVERLAY_ADDITION, imp);
 }
Esempio n. 9
0
    private Line makeLine(Element lineNode, ClassGraphics graphics) {

      Lineprops lp = getLineProps(lineNode);

      int w = graphics.getBoundWidth();
      int h = graphics.getBoundHeight();
      FixedCoords fc1 = getFixedCoords(lineNode, w, h, "1");
      FixedCoords fc2 = getFixedCoords(lineNode, w, h, "2");

      Line newLine =
          new Line(fc1.x, fc1.y, fc2.x, fc2.y, getColor(lineNode), lp.strokeWidth, lp.lineType);
      newLine.setFixedX1(fc1.fx);
      newLine.setFixedX2(fc2.fx);
      newLine.setFixedY1(fc1.fy);
      newLine.setFixedY2(fc2.fy);

      return newLine;
    }
Esempio n. 10
0
 /** Draws an outline of this OvalRoi on the image. */
 public void drawPixels(ImageProcessor ip) {
   Polygon p = getPolygon();
   if (p.npoints > 0) {
     int saveWidth = ip.getLineWidth();
     if (getStrokeWidth() > 1f) ip.setLineWidth((int) Math.round(getStrokeWidth()));
     ip.drawPolygon(p);
     ip.setLineWidth(saveWidth);
   }
   if (Line.getWidth() > 1 || getStrokeWidth() > 1) updateFullWindow = true;
 }
  private void mixerComboBoxActionPerformed() {
    Mixer mixer = AudioSystem.getMixer((Mixer.Info) mixerComboBox.getSelectedItem());

    Line.Info lineInfo = mixer.getSourceLineInfo(new Line.Info(Clip.class))[0];

    boolean volumeSupported;
    boolean panSupported;

    try {
      Line line = mixer.getLine(lineInfo);

      volumeSupported = line.isControlSupported(FloatControl.Type.MASTER_GAIN);
      panSupported = line.isControlSupported(FloatControl.Type.PAN);
    } catch (LineUnavailableException e) {
      volumeSupported = false;
      panSupported = false;
    }

    enableMixerVolumeCheckBox.setEnabled(volumeSupported);
    enableMixerPanCheckBox.setEnabled(panSupported);
  }
Esempio n. 12
0
  public boolean isPickedBy(Point p) {
    boolean result = false;
    Iterator<Point> points = myPoints.iterator();
    // A polyline has at least two points
    Point last = points.next();
    do {
      Point current = points.next();
      if (Line.segmentIsPickedBy(last, current, p)) {
        result = true;
        break;
      }
      last = current;
    } while (points.hasNext());

    return result;
  }
Esempio n. 13
0
  private ArrayList<RSTile> generatePath(Line[] lines) {
    double minStep = 5, maxStep = 10, wander = 3;
    if (lines.length < 2) return null;
    ArrayList<RSTile> path = new ArrayList<RSTile>();
    Line l1, l2 = lines[0];
    double distFromCenter = random(0, l2.getDistance() + 1);
    RSTile p = l2.translate((int) distFromCenter);
    distFromCenter = l2.getDistance() / 2 - distFromCenter;
    double centerXdist, centerYdist, line1Xdist, line1Ydist, line2Xdist, line2Ydist;
    double line1dist, line2dist, centerDist;
    double x, y;
    double distOnLine, last, cap1, cap2, move;
    double distFromCenterX1, distFromCenterY1, distFromCenterX2, distFromCenterY2;
    double force1, force2, slopeX, slopeY, slopeDist;
    boolean finished;
    int lastX = p.getX(), lastY = p.getY(), curX, curY;
    double dist, xdist, ydist;
    for (int i = 1; i < lines.length; i++) {
      l1 = l2;
      l2 = lines[i];
      centerXdist = l2.getCenterX() - l1.getCenterX();
      centerYdist = l2.getCenterY() - l1.getCenterY();
      centerDist = Math.sqrt(centerXdist * centerXdist + centerYdist * centerYdist);
      line1Xdist = l2.getX() - l1.getX();
      line1Ydist = l2.getY() - l1.getY();
      line2Xdist = l2.getX2() - l1.getX2();
      line2Ydist = l2.getY2() - l1.getY2();

      centerXdist /= centerDist;
      centerYdist /= centerDist;
      line1Xdist /= centerDist;
      line1Ydist /= centerDist;
      line2Xdist /= centerDist;
      line2Ydist /= centerDist;
      distOnLine = 0;
      last = 0;
      finished = false;
      while (!finished) {

        distOnLine += random(minStep, maxStep);
        if (distOnLine >= centerDist) {
          distOnLine = centerDist;
          finished = true;
        }
        x = centerXdist * distOnLine + l1.getCenterX();
        y = centerYdist * distOnLine + l1.getCenterY();

        distFromCenterX1 = x - (line1Xdist * distOnLine + l1.getX());
        distFromCenterY1 = y - (line1Ydist * distOnLine + l1.getY());

        distFromCenterX2 = x - (line2Xdist * distOnLine + l1.getX2());
        distFromCenterY2 = y - (line2Ydist * distOnLine + l1.getY2());

        slopeX = distFromCenterX2 - distFromCenterX1;
        slopeY = distFromCenterY2 - distFromCenterY1;
        slopeDist = Math.sqrt(slopeX * slopeX + slopeY * slopeY);
        slopeX /= slopeDist;
        slopeY /= slopeDist;

        line1dist =
            Math.sqrt(distFromCenterX1 * distFromCenterX1 + distFromCenterY1 * distFromCenterY1);
        line2dist =
            Math.sqrt(distFromCenterX2 * distFromCenterX2 + distFromCenterY2 * distFromCenterY2);

        move = (distOnLine - last) / maxStep * wander;

        force1 = line1dist + distFromCenter;
        force2 = line2dist - distFromCenter;

        cap1 = Math.min(move, force1);
        cap2 = Math.min(move, force2);

        if (force1 < 0) distFromCenter -= force1;
        else if (force2 < 0) distFromCenter += force2;
        else distFromCenter += random(-cap1, cap2);

        if (finished) {
          RSTile t = l2.translateFromCenter(distFromCenter);
          curX = t.getX();
          curY = t.getY();
        } else {
          curX =
              (int)
                  Math.round(distOnLine * centerXdist + l1.getCenterX() + distFromCenter * slopeX);
          curY =
              (int)
                  Math.round(distOnLine * centerYdist + l1.getCenterY() + distFromCenter * slopeY);
        }

        xdist = curX - lastX;
        ydist = curY - lastY;
        dist = Math.sqrt(xdist * xdist + ydist * ydist);
        xdist /= dist;
        ydist /= dist;
        for (int j = 0; j < dist; j++)
          path.add(
              new RSTile((int) Math.round(xdist * j + lastX), (int) Math.round(ydist * j + lastY)));

        last = distOnLine;
        lastX = curX;
        lastY = curY;
      }
    }
    return cutUp(path);
  }
Esempio n. 14
0
 /**
  * creates a copy of this Line object. This method creates a new Line, sets its locations, sets
  * its select state, and returns the new Line.
  */
 public Object clone() {
   Line l = new Line(startX, startY, endX, endY);
   l.setLocation(getLocation());
   l.setSelectState(getSelectState());
   return l;
 }
Esempio n. 15
0
 public PortNode(Line port) {
   super(port.getLineInfo(), true);
   this.port = port;
 }