Exemplo n.º 1
0
 /**
  * icon is painted with correct number of stones in the pit/mancala
  *
  * @param c properties for painting
  * @param g graphics object
  * @param x x location of icon
  * @param y y location of icon
  */
 public void paintIcon(Component c, Graphics g, int x, int y) {
   int iterateNum = data[pitNum];
   if (iterateNum > 5) {
     iterateNum = 5;
   }
   Graphics2D g2 = (Graphics2D) g;
   if (pitNum == 6 || pitNum == 13) {
     pitShape = s.getMancalaShape();
     g2.setColor(s.getPitColor());
     g2.fill(pitShape);
     for (int i = 0; i < data[pitNum]; i++) {
       RectangularShape temp = s.getStoneShape(i, data[pitNum], true);
       g2.setColor(s.getStoneColor());
       g2.draw(temp);
       g2.fill(temp);
     }
   } else {
     pitShape = s.getPitShape();
     g2.setColor(s.getPitColor());
     g2.fill(pitShape);
     for (int i = 0; i < data[pitNum]; i++) {
       RectangularShape temp = s.getStoneShape(i, data[pitNum], false);
       g2.setColor(s.getStoneColor());
       g2.draw(temp);
       g2.fill(temp);
     }
   }
 }
Exemplo n.º 2
0
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String message = "Hello, World!";

    Font f = new Font("Serif", Font.BOLD, 36);
    g2.setFont(f);

    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D bounds = f.getStringBounds(message, context);

    double x = (getWidth() - bounds.getWidth()) / 2;
    double y = (getHeight() - bounds.getHeight()) / 2;

    double ascent = -bounds.getY();
    double baseY = y + ascent;

    g2.drawString(message, (int) x, (int) baseY);

    g2.setPaint(Color.LIGHT_GRAY);

    g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY));
    Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());
    g2.draw(rect);
  }
Exemplo n.º 3
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    currentX = leftMargin;
    currentY = topMargin;

    // Draw the links

    for (int i = 0; i < linkLines.length; i++) {
      if (weights[i].isActive()) {
        g2.setPaint(weights[i].getColor());
        g2.draw(linkLines[i]);
      }
    }

    g2.setPaint(Color.black);

    // Draw the input neurons
    g2.drawString("Inputs", (float) currentX, (float) currentY);
    currentY += titleSpace;

    for (int i = 0; i < genome.getInputs(); i++) {
      g2.drawImage(inputNeuron, (int) currentX, (int) currentY, null);
      currentY += space;
    }

    // Draw the hidden Neurons
    currentX += space;
    currentY = topMargin;
    g2.drawString("Hidden Layers", (float) currentX, (float) currentY);

    for (int i = 0; i < genome.getHiddenLayers(); i++) {
      currentY = topMargin + titleSpace;
      for (int j = 0; j < genome.getNeuronsInHiddenLayer(); j++) {
        g2.drawImage(hiddenNeuron, (int) currentX, (int) currentY, null);
        currentY += space;
      }
      currentX += space;
    }

    // Draw the output neurons
    currentY = topMargin;
    g2.drawString("Outputs", (float) currentX, (float) currentY);
    currentY += titleSpace;

    for (int i = 0; i < genome.getOutputs(); i++) {
      g2.drawImage(outputNeuron, (int) currentX, (int) currentY, null);
      currentY += space;
    }

    // Draw the links

    for (int i = 0; i < linkLines.length; i++) {
      if (weights[i].isActive()) {
        g2.setPaint(weights[i].getColor());
        g2.draw(linkLines[i]);
      }
    }
  }
Exemplo n.º 4
0
  /**
   * Render the View to the given graphic context. This implementation render the interior first,
   * then the outline.
   */
  public void paint(Graphics2D g, Rectangle2D a) {
    if (!a.intersects(getBounds())) return;
    if (image != null) { // paint bitmap
      g.drawImage(image, text2ModelTr, null);
      // debug:
      g.setPaint(Color.red);
      g.draw(this.bounds);
      super.paint(g, a); // possibly paint framebox if non-null
    } else { // paint textlayout
      super.paint(g, a); // possibly paint framebox if non-null

      AffineTransform oldAT = g.getTransform();
      // paint text in black
      g.setPaint(Color.black);
      // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font
      // being mirrored...
      g.transform(text2ModelTr); // also include rotation
      textLayout.draw(g, 0.0f, 0.0f);
      // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre)
      // get back to previous transform
      g.setTransform(oldAT);
      if (DEBUG) {
        g.setPaint(Color.red);
        g.draw(bounds);
      }
    }
  }
Exemplo n.º 5
0
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      int w = getWidth();
      int h = getHeight();
      int pointSize = Math.max(Math.min(w, h) / 80, 4);

      double xInc = (double) (w - 2 * PAD) / (MAX_X - 1);
      double scale = (double) (h - 2 * PAD) / MAX_Y;
      // Draw abcissa.
      int tickInc = MAX_X / 10;
      for (int i = 0; i <= MAX_X; i += tickInc) {
        int x = PAD + (int) (i * xInc);
        int y = h - PAD;
        g.drawString(Integer.toString(i), x - 5, y + 20);
        g2.draw(new Line2D.Double(x, y - 5, x, y + 5));
      }
      g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD));
      AffineTransform orig = g2.getTransform();
      g2.rotate(-Math.PI / 2);
      g2.setColor(Color.black);
      g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3);
      g2.setTransform(orig);

      // Draw ordinate.
      tickInc = (h - PAD) / 10;

      for (int i = tickInc; i < h - PAD; i += tickInc) {
        int x = PAD;
        int closest_10 = ((int) (i / scale) / 10) * 10;

        int y = h - PAD - (int) (closest_10 * scale);
        if (y < PAD) break;
        String tickMark = Integer.toString(closest_10);
        int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth();
        g.drawString(tickMark, x - stringLen - 8, y + 5);
        g2.draw(new Line2D.Double(x - 5, y, x + 5, y));
      }
      g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD));
      g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40);

      for (int index = 0; index < plot_data.size(); index++) {
        int[] data = plot_data.get(index);

        // Mark data points.
        g2.setPaint(plot_colors.get(index));

        for (int i = 0; i < data.length; i++) {
          double x = PAD + i * xInc;
          double y = h - PAD - scale * data[i];
          g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize));
        }

        g2.setFont(textFont);
        int stringHeight =
            (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight();
        g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight);
      }
    }
Exemplo n.º 6
0
  public void paintBoard(Graphics2D g2) {

    double gbwidth = boardGridSize * 8d + lineLoc, gbheight = boardGridSize * 9d + lineLoc;
    g2.setPaint(red);
    g2.draw3DRect((int) lineLoc / 2, (int) lineLoc / 2, (int) gbwidth, (int) gbheight, true);
    g2.draw3DRect(
        (int) lineLoc / 2 + 3, (int) lineLoc / 2 + 3, (int) gbwidth - 6, (int) gbheight - 7, false);
    g2.setPaint(fg);
    for (int i = 0; i < 10; i++) {
      g2.draw(
          new Line2D.Double(
              lineLoc,
              lineLoc + boardGridSize * i,
              lineLoc + boardGridSize * 8,
              lineLoc + boardGridSize * i));
    }
    for (int i = 0; i < 9; i++) {
      g2.draw(
          new Line2D.Double(
              lineLoc + boardGridSize * i,
              lineLoc,
              lineLoc + boardGridSize * i,
              lineLoc + boardGridSize * 4));
      if (i == 0 || i == 8)
        g2.draw(
            new Line2D.Double(
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 4,
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 9));
      else
        g2.draw(
            new Line2D.Double(
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 5,
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 9));
    }
    drawX(lineLoc + boardGridSize * 4, lineLoc + boardGridSize, g2);
    drawX(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 8, g2);
    // black Pao
    drawLocation(lineLoc + boardGridSize, lineLoc + boardGridSize * 2, center, g2);
    drawLocation(lineLoc + boardGridSize * 7, lineLoc + boardGridSize * 2, center, g2);
    // red Pao
    drawLocation(lineLoc + boardGridSize, lineLoc + boardGridSize * 7, center, g2);
    drawLocation(lineLoc + boardGridSize * 7, lineLoc + boardGridSize * 7, center, g2);
    // black Zu
    drawLocation(lineLoc, lineLoc + boardGridSize * 3, right, g2);
    drawLocation(lineLoc + boardGridSize * 2, lineLoc + boardGridSize * 3, center, g2);
    drawLocation(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 3, center, g2);
    drawLocation(lineLoc + boardGridSize * 6, lineLoc + boardGridSize * 3, center, g2);
    drawLocation(lineLoc + boardGridSize * 8, lineLoc + boardGridSize * 3, left, g2);
    // red bin
    drawLocation(lineLoc, lineLoc + boardGridSize * 6, right, g2);
    drawLocation(lineLoc + boardGridSize * 2, lineLoc + boardGridSize * 6, center, g2);
    drawLocation(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 6, center, g2);
    drawLocation(lineLoc + boardGridSize * 6, lineLoc + boardGridSize * 6, center, g2);
    drawLocation(lineLoc + boardGridSize * 8, lineLoc + boardGridSize * 6, left, g2);
    // ----------------------------------------------------------------------
  }
Exemplo n.º 7
0
  public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    g2d.draw(
        new Ellipse2D.Double(
            centerx - (centery - 500),
            centery - (centery - 500),
            2 * (centery - 500),
            2 * (centery - 500)));

    try {
      g2d.draw(
          new Ellipse2D.Double(
              player.x - player.size / 2, player.y - player.size / 2, player.size, player.size));
    } catch (NullPointerException e) {
    }

    k = 1;
    while (k <= ballCount) {

      g2d.draw(
          new Ellipse2D.Double(
              ball[k].x - ball[k].size / 2,
              ball[k].y - ball[k].size / 2,
              ball[k].size,
              ball[k].size));
      k++;
    }
  }
Exemplo n.º 8
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;

    Graphics2D g2d = (Graphics2D) g.create();

    g2d.translate(centerX, centerY); // Set Graphics2D transform origin to center of panel

    g2d.setColor(fgColor);
    bar.setFrame(-barWidth / 2, -barHeight / 2 + barHeight * barPosition, barWidth, barHeight);
    g2d.fill(bar);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (Spike spike : spikes) {
      if (spike != null) {
        double opacity = 255;
        if (spike.getDirection() == 0) {
          opacity = getWidth() * 0.5 - 70 - spike.getPosition().getX();
        } else {
          opacity = spike.getPosition().getX() + getWidth() * 0.5 - 70;
        }
        g2d.setColor(new Color(0, 0, 0, (int) clamp(opacity * 10, 0, 255)));
        g2d.fill(spike);
      }
    }
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2d.setColor(Color.BLACK);
    g2d.draw(barCross);
    g2d.setStroke(new BasicStroke(2));
    g2d.draw(barFrame);
    g2d.dispose();
  }
 public void paint(Graphics g) {
   Graphics2D g_2d = (Graphics2D) g;
   Ellipse2D ellipse = new Ellipse2D.Double(0, 2, 80, 80);
   Rectangle2D rect = new Rectangle2D.Double(40, 2, 80, 80);
   Area a1 = new Area(ellipse);
   Area a2 = new Area(rect);
   a1.intersect(a2); // "Óë"
   g_2d.fill(a1);
   ellipse.setFrame(130, 2, 80, 80);
   rect.setFrame(170, 2, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.add(a2); // "»ò"
   g_2d.draw(a1);
   ellipse.setFrame(0, 90, 80, 80);
   rect.setFrame(40, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.subtract(a2); // "²î"
   g_2d.draw(a1);
   ellipse.setFrame(130, 90, 80, 80);
   rect.setFrame(170, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.exclusiveOr(a2); // "Òì»ò"
   g_2d.fill(a1);
 }
Exemplo n.º 10
0
  public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2D = (Graphics2D) g;
    int x = this.getWidth();
    int y = this.getHeight();
    int z = 4;

    if (orientation.equals(DesktopBar.WEST)) {
      int[] X = {x - z, x - z, 2 * x / 5, x / 2, z, x / 2, 2 * x / 5};
      int[] Y = {2 * y / 5, 3 * y / 5, 3 * y / 5, y - z, y / 2, z, 2 * y / 5};
      g2D.draw(new Polygon(X, Y, 7));
    }
    if (orientation.equals(DesktopBar.EAST)) {
      int[] X = {z, z, 2 * x / 3, x / 2, x - z, x / 2, 2 * x / 3};
      int[] Y = {2 * y / 5, 3 * y / 5, 3 * y / 5, y - z, y / 2, z, 2 * y / 5};
      g2D.draw(new Polygon(X, Y, 7));
    }
    if (orientation.equals(DesktopBar.NORTH)) {
      int[] X = {2 * x / 5, 3 * x / 5, 3 * x / 5, x - z, x / 2, z, 2 * x / 5};
      int[] Y = {y - z, y - z, 2 * y / 5, y / 2, z, y / 2, 2 * y / 5};
      g2D.draw(new Polygon(X, Y, 7));
    }
    if (orientation.equals(DesktopBar.SOUTH)) {
      int[] X = {2 * x / 5, 3 * x / 5, 3 * x / 5, x - z, x / 2, z, 2 * x / 5};
      int[] Y = {z, z, 2 * y / 3, y / 2, y - z, y / 2, 2 * y / 3};
      g2D.draw(new Polygon(X, Y, 7));
    }
  }
Exemplo n.º 11
0
 private void drawArrow(Graphics2D g2, double theta, double x0, double y0) {
   double x = x0 - barb * Math.cos(theta + phi);
   double y = y0 - barb * Math.sin(theta + phi);
   g2.draw(new Line2D.Double(x0, y0, x, y));
   x = x0 - barb * Math.cos(theta - phi);
   y = y0 - barb * Math.sin(theta - phi);
   g2.draw(new Line2D.Double(x0, y0, x, y));
 }
Exemplo n.º 12
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }
Exemplo n.º 13
0
 public void drawX(double x0, double y0, Graphics2D g2) {
   //
   g2.draw(
       new Line2D.Double(
           x0 - boardGridSize, y0 - boardGridSize, x0 + boardGridSize, y0 + boardGridSize));
   g2.draw(
       new Line2D.Double(
           x0 - boardGridSize, y0 + boardGridSize, x0 + boardGridSize, y0 - boardGridSize));
 }
Exemplo n.º 14
0
  public void paint(Graphics g) {
    System.out.println("paint");
    Graphics2D g2d = (Graphics2D) g;

    Point1 p1, p2;

    n = paintInfo.size();

    if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除

    for (int i = 0; i < n - 1; i++) {
      p1 = (Point1) paintInfo.elementAt(i);
      p2 = (Point1) paintInfo.elementAt(i + 1);
      size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

      g2d.setColor(p1.col);
      g2d.setStroke(size);

      if (p1.tool == p2.tool) {
        switch (p1.tool) {
          case 0: // 画笔
            Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line1);
            break;

          case 1: // 橡皮
            g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);
            break;

          case 3: // 画直线
            Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line2);
            break;

          case 4: // 画圆
            Ellipse2D ellipse =
                new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(ellipse);
            break;

          case 5: // 画矩形
            Rectangle2D rect =
                new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(rect);
            break;

          case 6: // 截断,跳过
            i = i + 1;
            break;

          default:
        } // end switch
      } // end if
    } // end for
  }
Exemplo n.º 15
0
 public void Draw(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setColor(Color.red);
   g2.draw(new Line2D.Double(getfirstX(), getfirstY(), getsecondX(), getsecondY()));
   Ellipse2D circle1 = new Ellipse2D.Double(getfirstX() - 5, getfirstY() - 5, 10, 10);
   Ellipse2D circle2 = new Ellipse2D.Double(getsecondX() - 5, getsecondY() - 5, 10, 10);
   g2.draw(circle1);
   g2.fill(circle1);
   g2.draw(circle2);
   g2.fill(circle2);
 }
Exemplo n.º 16
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    double theta, x, y;

    g2.setPaint(Color.blue);
    double x1 = w * 3 / 24, y1 = h * 3 / 32, x2 = w * 11 / 24, y2 = y1;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    // draw this arrow head at point x2, y2 and measure
    // angle theta relative to same point, ie, y2 - and x2 -
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);

    x1 = w * 3 / 8;
    y1 = h * 13 / 15;
    x2 = w * 2 / 3;
    y2 = y1;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y1 - y2, x1 - x2);
    drawArrow(g2, theta, x1, y1);

    g2.setPaint(Color.red);
    x1 = w * 3 / 24;
    y1 = h * 4 / 32;
    x2 = x1;
    y2 = h * 18 / 32;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);

    g2.setPaint(Color.orange);
    x1 = w * 5 / 32;
    y1 = h * 27 / 32;
    x2 = w * 27 / 32;
    y2 = h * 5 / 32;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);

    g2.setPaint(Color.green.darker());
    x1 = w / 2;
    y1 = h / 2;
    x2 = w * 27 / 32;
    y2 = h * 27 / 32;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);
  }
Exemplo n.º 17
0
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   int w = getWidth();
   int h = getHeight();
   // Draw ordinate.
   g2.draw(new Line2D.Double(Points, Points, Points, h - Points));
   // Draw abcissa.
   g2.draw(new Line2D.Double(Points, h - Points, w - Points, h - Points));
   // Draw labels.
   Font font = g2.getFont();
   FontRenderContext frc = g2.getFontRenderContext();
   LineMetrics lm = font.getLineMetrics("0", frc);
   float sh = lm.getAscent() + lm.getDescent();
   // Ordinate label.
   String s = "Strecke";
   float sy = Points + ((h - 2 * Points) - s.length() * sh) / 2 + lm.getAscent();
   for (int i = 0; i < s.length(); i++) {
     String letter = String.valueOf(s.charAt(i));
     float sw = (float) font.getStringBounds(letter, frc).getWidth();
     float sx = (Points - sw) / 2;
     g2.drawString(letter, sx, sy);
     sy += sh;
   }
   // Abcissa label.
   s = "Datum";
   sy = h - Points + (Points - sh) / 2 + lm.getAscent();
   float sw = (float) font.getStringBounds(s, frc).getWidth();
   float sx = (w - sw) / 2;
   g2.drawString(s, sx, sy);
   // Draw lines.
   double xInc = (double) (w - 2 * Points) / (data.length - 1);
   double scale = (double) (h - 2 * Points) / getMax();
   g2.setPaint(Color.green.darker());
   for (int i = 0; i < data.length - 1; i++) {
     double x1 = Points + i * xInc;
     double y1 = h - Points - scale * data[i];
     double x2 = Points + (i + 1) * xInc;
     double y2 = h - Points - scale * data[i + 1];
     g2.draw(new Line2D.Double(x1, y1, x2, y2));
   }
   // Mark data points.
   g2.setPaint(Color.red);
   for (int i = 0; i < data.length; i++) {
     double x = Points + i * xInc;
     double y = h - Points - scale * data[i];
     g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
   }
 }
Exemplo n.º 18
0
  /** Draws the game */
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    /** Draw all the non-falling blocks on the board. Non-OUTSIDE blocks have rounded corners. */
    for (int row = 0; row < board.getHeight(); row++) {
      for (int column = 0; column < board.getWidth(); column++) {
        if (board.getSquareType(row, column) != SquareType.OUTSIDE) {
          Shape tetrominoBlock =
              new RoundRectangle2D.Double(
                  column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5);
          g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column)));
          g2.fill(tetrominoBlock);
          g2.draw(tetrominoBlock);
        } else {
          Shape tetrominoBlock =
              new Rectangle2D.Double(
                  column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT);
          g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column)));
          g2.fill(tetrominoBlock);
          g2.draw(tetrominoBlock);
        }
      }
    }

    Poly tempPoly = board.getFalling();
    if (tempPoly != null) {

      for (int row = 0; row < tempPoly.getSize(); row++) {
        for (int column = 0; column < tempPoly.getSize(); column++) {
          if (tempPoly.getSquareType(row, column) != SquareType.EMPTY) {
            Shape tetrominoBlock =
                new RoundRectangle2D.Double(
                    (column + board.getFallingPosX()) * SQUARE_WIDTH,
                    (row + board.getFallingPosY()) * SQUARE_HEIGHT,
                    SQUARE_WIDTH,
                    SQUARE_HEIGHT,
                    5,
                    5);
            g2.setColor(SQUARE_COLOR.get(tempPoly.getSquareType(row, column)));
            g2.fill(tetrominoBlock);
            g2.draw(tetrominoBlock);
          }
        }
      }
    }
  }
 /**
  * Drawer : draw the grid of the component.
  *
  * @param g Graphics2D of the component (casted from getGraphics).
  */
 private void drawGrid(Graphics2D g) {
   g.setPaint(grid);
   g.setStroke(new BasicStroke(1));
   g.draw(
       new Line2D.Double(
           retrieveBarLeft,
           this.getHeight() - retrieveBarBottom,
           this.getWidth() - retrieveBarRight,
           this.getHeight() - retrieveBarBottom)); // abcisses
   g.draw(
       new Line2D.Double(
           retrieveBarLeft,
           this.getHeight() - retrieveBarBottom,
           retrieveBarLeft,
           retrieveBarTop)); // ordonnees
 }
Exemplo n.º 20
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;
   }
 }
Exemplo n.º 21
0
 // This method will draw the figure to a graphical context.  Note that only non-null
 // values are drawn and that the predefined draw() method within the Graphics2D class
 // is used to draw the actual chunks.  This method can draw any figure that implements
 // the Shape interface.  For more info, look up Graphics2D and Shape in the Java API
 public void draw(Graphics2D g) {
   for (int i = 0; i < numChunks; i++) {
     if (chunks[i] != null) {
       g.draw(chunks[i]);
     }
   }
 }
Exemplo n.º 22
0
 /** Draws the edge structure of the tree */
 public void drawEdges(Graphics2D gg) {
   gg.setPaint(Color.black);
   Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
   // For each vertex...
   while (nodeList.hasMoreElements()) {
     // Get its edge list...
     TreeVertex vertex = (TreeVertex) nodeList.nextElement();
     Enumeration edges = vertex.getEdgeList().elements();
     // For each edge in the list...
     while (edges.hasMoreElements()) {
       TreeEdge edge = (TreeEdge) edges.nextElement();
       // If we have several vertices on layer 0, only draw
       // edges for layers below that
       if (!(argument.isMultiRoots() && vertex.getLayer() == 0)) {
         // If the edge has been selected with the mouse,
         // use a thick line
         if (edge.isSelected()) {
           gg.setStroke(selectStroke);
         }
         gg.draw(edge.getShape(this));
         // If we used a thick line, reset the stroke to normal
         // line for next edge.
         if (edge.isSelected()) {
           gg.setStroke(solidStroke);
         }
         TreeVertex edgeSource = edge.getDestVertex();
       }
     }
   }
 }
Exemplo n.º 23
0
 /**
  * Erases a given shape's outline on the screen.
  *
  * @param shape the shape object to be erased
  */
 public void eraseOutline(Shape shape) {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColour);
   graphic.draw(shape); // erase by drawing background colour
   graphic.setColor(original);
   canvas.repaint();
 }
  /**
   * Drawer : draw the historic curve of the component.
   *
   * @param g Graphics2D of the component (casted from getGraphics).
   */
  private void drawCurve(Graphics2D g) {
    // calculate resizing an graphical zone.
    float spaceBetween =
        (float) ((this.getWidth() - (retrieveBarLeft + retrieveBarRight)) / (1.0 * nbPoints));
    float multiplicatorHeight =
        (float) ((this.getHeight() - (retrieveBarTop + retrieveBarBottom)) / (1.0 * maxValue));

    shapes = new ArrayList<>();
    for (int i = 0; i < values.length - 1; i++) {
      // generating shape array
      Point p1 =
          new Point(
              (int) (retrieveBarLeft + (i * spaceBetween)),
              (int) ((getHeight() - retrieveBarBottom) - (values[i] * multiplicatorHeight)));
      Point p2 =
          new Point(
              (int) (retrieveBarLeft + ((i + 1) * spaceBetween)),
              (int) ((getHeight() - retrieveBarBottom) - (values[i + 1] * multiplicatorHeight)));
      currentShape = new Line2D.Double(p1, p2);
      shapes.add(currentShape);
    }

    // draw the curve from shape array
    g.setPaint(line);
    g.setStroke(new BasicStroke(1));
    for (Shape shape : shapes) {
      g.draw(shape);
    }
  }
Exemplo n.º 25
0
  /**
   * Draws the markers and closed walls of a given cell a in the Graphics2D object g2
   *
   * @param g2 the Graphics2D object within which this Cell is being drawn
   * @param a the Cell that is being drawn
   */
  public void drawCell(Graphics2D g2, Cell a) {
    // paint the proper markers for the Cell in the proper order
    if (this.grid.hasMarker(a, MazeGrid.MARKER3)) this.paintMarker3(g2, a);
    if (this.grid.hasMarker(a, MazeGrid.MARKER1)) this.paintMarker1(g2, a);
    else if (this.grid.hasMarker(a, MazeGrid.MARKER2)) this.paintMarker2(g2, a);

    // paint the walls of the Cell
    byte directions = this.grid.getCellDirections(a);
    g2.setColor(Color.BLACK);
    if ((directions & MazeGrid.DIR_RIGHT) == 0) {
      Line2D.Float wall =
          new Line2D.Float(
              this.cellWidth * a.col + this.cellWidth - 1,
              this.cellWidth * a.row + 0,
              this.cellWidth * a.col + this.cellWidth - 1,
              this.cellWidth * a.row + this.cellWidth - 1);
      g2.draw(wall);
    }
    if ((directions & MazeGrid.DIR_UP) == 0) {
      Line2D.Float wall =
          new Line2D.Float(
              this.cellWidth * a.col + 0,
              this.cellWidth * a.row + 0,
              this.cellWidth * a.col + this.cellWidth - 1,
              this.cellWidth * a.row + 0);
      g2.draw(wall);
    }
    if ((directions & MazeGrid.DIR_LEFT) == 0) {
      Line2D.Float wall =
          new Line2D.Float(
              this.cellWidth * a.col + 0,
              this.cellWidth * a.row + 0,
              this.cellWidth * a.col + 0,
              this.cellWidth * a.row + this.cellWidth - 1);
      g2.draw(wall);
    }
    if ((directions & MazeGrid.DIR_DOWN) == 0) {
      Line2D.Float wall =
          new Line2D.Float(
              this.cellWidth * a.col + 0,
              this.cellWidth * a.row + this.cellWidth - 1,
              this.cellWidth * a.col + this.cellWidth - 1,
              this.cellWidth * a.row + this.cellWidth - 1);
      g2.draw(wall);
    }
  }
Exemplo n.º 26
0
  public void paintComponent(Graphics g) {
    // необходиом чтобы текст коректно отрисовывался в окне
    super.paintComponent(g);
    // рисуем текст в окне
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform t = g2.getTransform();
    g.drawString("It is text", 5, 5);
    // создание шрифта
    Font f = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f);
    g2.drawString("It is new text", 5, 33);
    String[] fontNames =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 5; i < 20; i++) {
      g2.rotate(-0.05);
      g2.setColor(
          new Color(
              (int) (Math.random() * 255),
              (int) (Math.random() * 255),
              (int) (Math.random() * 255)));
      Font f1 = new Font(fontNames[i], Font.BOLD, 20);
      g2.setFont(f1);
      g2.drawString(fontNames[i], 5, 20 * i);
    }
    // текст в центре

    g2.setTransform(t); // возращение к кординатам, которые запонилив начале
    Font f2 = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f2);
    String s = "It is center!";
    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D r = f2.getStringBounds(s, context);
    double x1 = (getWidth() - r.getWidth()) / 2;
    double y1 = (getHeight() - r.getHeight()) / 2;
    double ascent = -r.getY(); // узнаем высоту текста
    double y2 = y1 + ascent;
    Rectangle2D rect = new Rectangle2D.Double(x1, y1, r.getWidth(), r.getHeight());
    g2.setColor(Color.YELLOW);
    g2.fill(rect);
    g2.setColor(Color.red);
    g2.drawString(s, (int) x1, (int) y2);
    g2.setColor(Color.blue);
    g2.draw(new Line2D.Double(x1, y2, x1 + r.getWidth(), y2));

    g2.draw(rect);
  }
Exemplo n.º 27
0
 public void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1);
   g2.setPaint(Color.YELLOW);
   g2.fill(rect);
   g2.setPaint(Color.BLUE);
   g2.draw(rect);
 }
Exemplo n.º 28
0
  // draws the tree, starting from the given node, in the region with x values
  // ranging
  // from minX to maxX, with y value beginning at y, and next level at y +
  // yIncr.
  private void drawTree(Graphics2D g2, TreeNode<E> t, int minX, int maxX, int y, int yIncr) {
    // skip if empty
    if (t == null) return;

    // compute useful coordinates
    int x = (minX + maxX) / 2;
    int nextY = y + yIncr;

    // draw black lines
    g2.setPaint(Color.black);
    if (t.left != null) {
      int nextX = (minX + x) / 2;
      g2.draw(new Line2D.Double(x, y, nextX, nextY));
    }
    if (t.right != null) {
      int nextX = (x + maxX) / 2;
      g2.draw(new Line2D.Double(x, y, nextX, nextY));
    }

    // measure text
    FontMetrics font = g2.getFontMetrics();
    String text = t.data + "";
    int textHeight = font.getHeight();
    int textWidth = font.stringWidth(text);

    // draw the box around the node
    Rectangle2D.Double box =
        new Rectangle2D.Double(
            x - textWidth / 2 - ARC_PAD,
            y - textHeight / 2 - ARC_PAD,
            textWidth + 2 * ARC_PAD,
            textHeight + 2 * ARC_PAD);
    Color c = new Color(187, 224, 227);
    g2.setPaint(c);
    g2.fill(box);
    // draw black border
    g2.setPaint(Color.black);
    g2.draw(box);

    // draw text
    g2.drawString(text, x - textWidth / 2, y + textHeight / 2);

    // draw children
    drawTree(g2, t.left, minX, x, nextY, yIncr);
    drawTree(g2, t.right, x, maxX, nextY, yIncr);
  }
Exemplo n.º 29
0
 /**
  * Draw a polygon with the given (x[i], y[i]) coordinates.
  *
  * @param x an array of all the x-coordindates of the polygon
  * @param y an array of all the y-coordindates of the polygon
  */
 public static void polygon(double[] x, double[] y) {
   int N = x.length;
   GeneralPath path = new GeneralPath();
   path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
   for (int i = 0; i < N; i++) path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
   path.closePath();
   offscreen.draw(path);
   draw();
 }
Exemplo n.º 30
0
  private void paintFirms(Graphics2D g2d) {

    Rectangle2D rec = new Rectangle2D.Double();
    ArrayList<Firm> firms = SleepStoneTest.firms;

    Stroke normalStroke = new BasicStroke();
    Stroke boldStroke = new BasicStroke(4f);

    g2d.setStroke(boldStroke);
    for (Firm x : firms) {
      rec.setRect(firmsPlace.get(x));
      FirmStatus status = x.getStatus();

      g2d.setColor(Color.black);

      g2d.drawString(x.getFirmName(), Math.round(rec.getMinX()), Math.round(rec.getMaxY() + 15d));

      g2d.drawString(
          Integer.toString(x.getWorkers().size()),
          Math.round(rec.getMinX()),
          Math.round(rec.getMinY() - 15d));
      // g2d.setColor(Color.RED);
      g2d.drawImage(
          firmIcon.getImage(),
          (int) rec.getX(),
          (int) rec.getY(),
          (int) rec.getWidth(),
          (int) rec.getHeight(),
          FirmStatus.getStatusColor(status),
          null);

      // draw the jobs done indicator
      if (status == FirmStatus.PRODUCING) {
        g2d.setColor(Color.black);
        g2d.setStroke(boldStroke);
        Rectangle jobsIndicator =
            new Rectangle(
                (int) rec.getMaxX() + 5,
                (int) rec.getMinY(),
                (int) (firmSpacing / 2d),
                (int) rec.getHeight());
        g2d.draw(jobsIndicator);
        float jobsToDo = x.getJobsToDo();
        float jobsDone = x.getJobsDone().availablePermits();
        float percentComplete = jobsDone / jobsToDo;
        g2d.setColor(Color.BLUE);
        jobsIndicator.setBounds(
            (int) rec.getMaxX() + 5,
            (int) rec.getMinY(),
            (int) (firmSpacing / 2d),
            (int) (((float) (rec.getHeight())) * percentComplete));
        g2d.fill(jobsIndicator);
        g2d.setStroke(normalStroke);
      }
      // index++;
    }
  }