/**
   * Draws as much as possible of a given string into a 2d square region in a graphical space.
   *
   * @param g component onto which to draw
   * @param f font to use in drawing the string
   * @param s string to be drawn
   * @param xPos
   * @param yPos
   * @param width
   * @param height
   */
  public static void drawStringMultiline(
      Graphics2D g, Font f, String s, double xPos, double yPos, double width, double height) {
    FontMetrics fm = g.getFontMetrics(f);
    int w = fm.stringWidth(s);
    int h = fm.getAscent();
    // g.setColor(Color.LIGHT_GRAY);
    g.setColor(Color.BLACK);
    g.setFont(f);

    Scanner lineSplitter = new Scanner(s);
    // draw as much as can fit in each item
    // read all content from scanner, storing in string lists (where each string == 1 line), each
    // string should be as long as possible without overflowing the space
    int maxRows = (int) height / h;
    List<String> textRows = new ArrayList<>();
    while (lineSplitter.hasNextLine() && textRows.size() < maxRows) {
      String line = lineSplitter.nextLine();
      // if line is blank, insert to maintain paragraph seps
      if (line.trim().equals("")) {
        textRows.add("");
      }
      // else, pass to inner loop
      StringBuilder currentBuilder = new StringBuilder();
      int currentStrWidth = 0;
      Scanner splitter = new Scanner(line);
      while (splitter.hasNext() && textRows.size() < maxRows) {
        String token = splitter.next() + " ";
        // TODO incorporate weight detection, formatting for token?
        currentStrWidth += fm.stringWidth(token);
        if (currentStrWidth >= width) {
          // if string length >= glyph width, build row
          textRows.add(currentBuilder.toString());
          currentBuilder = new StringBuilder();
          currentBuilder.append(token);
          currentStrWidth = fm.stringWidth(token);
        } else {
          // if not yet at end of row, append to builder
          currentBuilder.append(token);
        }
      }

      // if we've still space and still have things to write, add them here
      if (textRows.size() < maxRows) {
        textRows.add(currentBuilder.toString());
        currentBuilder = new StringBuilder();
        currentStrWidth = 0;
      }
    }

    // write each line to object
    for (int t = 0; t < textRows.size(); t++) {
      String line = textRows.get(t);
      if (fm.stringWidth(line) <= width) {
        // ensure that string doesn't overflow the box
        //                g.drawString(line, (float) (xPos-(width/2.)), (float) (yPos-(height/2.) +
        // h * (t+1)));
        g.drawString(line, (float) xPos, (float) (yPos + h * (t + 1)));
      }
    }
  }
Example #2
0
 /** [Internal] */
 private void paintBackground(Graphics2D g2, Color theBackground) {
   Color color1 = g2.getColor();
   if (theBackground == null) theBackground = Color.white;
   g2.setColor(theBackground);
   g2.fillRect(0, 0, 30000, 30000);
   g2.setColor(color1);
 }
Example #3
0
  public void StaticObjNew(StaticObj so) {
    Graphics2D g = radarArea.backImage.createGraphics();
    g.setColor(so_color);

    if (so instanceof Beacon) {
      g.drawOval(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Airfield) {
      int xa[] = new int[3], ya[] = new int[3];
      int l1 = grid_size / 2, l2 = grid_size / 6;
      xa[0] = convPos(so.pos.x);
      ya[0] = convPos(so.pos.y);
      xa[1] = convPos(so.pos.x) - l1 * so.dir.x - l2 * so.dir.y;
      ya[1] = convPos(so.pos.y) - l1 * so.dir.y + l2 * so.dir.x;
      xa[2] = convPos(so.pos.x) - l1 * so.dir.x + l2 * so.dir.y;
      ya[2] = convPos(so.pos.y) - l1 * so.dir.y - l2 * so.dir.x;
      g.drawPolygon(xa, ya, 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Exit) {
      g.drawRect(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Line) {
      g.setColor(line_color);
      g.drawLine(
          convPos(((Line) so).pos.x),
          convPos(((Line) so).pos.y),
          convPos(((Line) so).second_end.x),
          convPos(((Line) so).second_end.y));
    }

    radarArea.backIcon = new ImageIcon(radarArea.backImage);
    radarArea.back.setIcon(radarArea.backIcon);
  }
Example #4
0
  public void paintVertex(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setColor(this.getFillColor());
    g2.fill(this);
    g2.setColor(this.border);
    g2.draw(this);
  }
Example #5
0
 // initialize default image
 private BufferedImage getDefaultImage(int w, int h) {
   BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics2D = defaultImage.createGraphics();
   graphics2D.setColor(new Color(200, 200, 200));
   graphics2D.fillRect(0, 0, w, h);
   graphics2D.setColor(new Color(130, 130, 130));
   graphics2D.drawRect(0, 0, w - 1, h - 1);
   return defaultImage;
 }
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    int i, j, k;
    System.out.println("Starting painting");
    // draw sets

    if (firstTimeAround) {
      drawSet(g2);
      render();
      viewer.save("final_product_full.png");
      firstTimeAround = false;
    }
    // render();
    /* for(i=0;i<viewer.getWidth();i++){
        for(j=0;j<viewer.getHeight();j++){
            viewer.setPixel(i,j,Color3.BLACK);
        }
    }
    */

    g2.setBackground(Color.BLACK);

    //        if(newRender){
    for (i = minX; i < maxX; i++) {
      // System.out.println("line "+i);
      for (j = minY; j < maxY; j++) {

        g2.setColor(
            new Color(
                (float) viewer.getPixel(i, j).getR(),
                (float) viewer.getPixel(i, j).getG(),
                (float) viewer.getPixel(i, j).getB()));
        // g2.drawLine(i,j,1,1);
        Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1);
        g2.fill(node_circ);

        g2.setColor(Color.BLACK);

        // if(j*scale<viewer.getHeight()){
        //       j=0;//viewer.getHeight();
        // }

      }
      // if(i*scale<viewer.getWidth()){
      //    i=0;//viewer.getWidth();
      //  }
    }

    //  g2.drawImage(viewer.1)
    newRender = false;
    // }
    System.out.println("end painting");
  }
Example #7
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);
    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }
    if (gameOver) return;
    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    for (int index = 0; index < missile.length; index++) {
      if (missile[index].active) {
        g.setColor(Color.red);
        drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5);
      }
    }
    if (rocketRight) {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0);
    } else {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0);
    }
    for (int index = 0; index < numStars; index++) {
      g.setColor(Color.yellow);
      if (starActive[index])
        drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5);
    }
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Score: " + score, 10, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("HighScore: " + highScore, 300, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Lives: " + rocketLife, 150, 45);
    if (rocketLife == 0) {
      g.setColor(Color.red);
      g.setFont(new Font("Impact", Font.BOLD, 60));
      g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2));
    }
    gOld.drawImage(image, 0, 0, null);
  }
Example #8
0
  void renderer(Graphics2D g2d) {
    height = window.getHeight() - 20;
    width = window.getWidth();

    lastTime = curTime;
    curTime = System.currentTimeMillis();
    totalTime += curTime - lastTime;
    if (totalTime > 1000) {
      totalTime -= 1000;
      fps = frames;
      frames = 0;
    }
    ++frames;

    delta = 16.0 / (curTime - lastTime);
    if (delta < 0) delta = 0;

    g2d.setColor(Color.white);
    if (removeMode) g2d.fill(new Rectangle(0, 0, width, height));

    if (eventHandeler(g2d)) {
      renderBackground(g2d);
      return;
    }

    Graphics2D map = (Graphics2D) g2d.create();
    playerHandeler();
    xOffset = -player.body.getCenterX() + width / 2;
    yOffset = -player.body.getCenterY() + height / 2;

    if (-xOffset < bounds.getBounds2D().getX()) xOffset = -bounds.getBounds2D().getX();
    else if (-xOffset > bounds.getBounds2D().getMaxX() - width)
      xOffset = -bounds.getBounds2D().getMaxX() + width;

    if (-yOffset < bounds.getBounds2D().getY()) yOffset = -bounds.getBounds2D().getY();
    else if (-yOffset > bounds.getBounds2D().getMaxY() - height + 3)
      yOffset = -bounds.getBounds2D().getMaxY() + height - 3;

    map.translate(xOffset, yOffset);

    renderBackground(map);
    itemHandeler(map);
    enemieHandeler();
    characterHandeler(map);

    map.setColor(Color.black);
    map.draw(bounds);

    renderUI(g2d);
  }
Example #9
0
    void draw(Graphics2D g) {

      // toX/toY is tip of arrow and fx/fy is a point on the line -
      // fx/fy is used to determine direction & angle

      AffineTransform at = AffineTransform.getTranslateInstance(toX, toY);
      int b = 9;
      double theta = Math.toRadians(20);
      // The idea of using a GeneralPath is so we can
      // create the (three lines that make up the) arrow
      // (only) one time and then use AffineTransform to
      // place it anywhere we want.
      GeneralPath path = new GeneralPath();

      // distance between line and the arrow mark <** not **
      // Start a new line segment from the position of (0,0).
      path.moveTo(0, 0);
      // Create one of the two arrow head lines.
      int x = (int) (-b * Math.cos(theta));
      int y = (int) (b * Math.sin(theta));
      path.lineTo(x, y);

      // distance between line and the arrow mark <** not **
      // Make the other arrow head line.
      int x2 = (int) (-b * Math.cos(-theta));
      int y2 = (int) (b * Math.sin(-theta));
      // path.moveTo(0,0);
      path.lineTo(x2, y2);
      path.closePath();

      // theta is in radians
      double s, t;
      s = toY - fy; // calculate slopes.
      t = toX - fx;
      if (t != 0) {
        s = s / t;
        theta = Math.atan(s);
        if (t < 0) theta += Math.PI;
      } else if (s < 0) theta = -(Math.PI / 2);
      else theta = Math.PI / 2;

      at.rotate(theta);
      // at.rotate(theta,toX,toY);
      Shape shape = at.createTransformedShape(path);
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
      g.fill(shape);
      g.draw(shape);
    }
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setColor(Color.white);
   g2.fillRect(0, 0, getWidth(), getHeight());
   AffineTransform at = new AffineTransform(0.5, 0, 0, -0.5, 30, getHeight() * 3 / 4);
   g2.transform(at);
   g2.setColor(Color.black);
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setRenderingHint(
       RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   //	System.out.println("Showing="+showing);
   if (showing != null) {
     showing.draw(g2);
   }
 }
Example #11
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);
          }
        }
      }
    }
  }
  protected void paintComponent(Graphics g2) {
    super.paintComponent(g2);

    Graphics2D g = (Graphics2D) g2;
    test.draw(g2, 0, 0);
    // Shape triangle = new Polygon(new int[] {15, 20, 10}, new int[] {0, 10, 10}, 3);

    Shape square = new Rectangle2D.Double(0, 0, 30, 30);

    g.setColor(Color.white);

    g.translate(20, 20);
    // g.rotate(theta, 10, 10);
    // g.fill(star);

    // g.setColor(new Color(0, 86, 141));
    // g.fill(square);
    if (star2 != null) g.fill(star2);

    // Graphics2D g3 = (Graphics2D) g;
    // 3.fill(star);

    // g.setStroke(new BasicStroke(1));
    // g.translate(x, y);
    // g.draw(line);
    // g.draw(line2);

  }
 public void backgroundImpl() {
   if (backgroundAlpha) {
     // Create a small array that can be used to set the pixels several times.
     // Using a single-pixel line of length 'width' is a tradeoff between
     // speed (setting each pixel individually is too slow) and memory
     // (an array for width*height would waste lots of memory if it stayed
     // resident, and would terrify the gc if it were re-created on each trip
     // to background().
     WritableRaster raster = ((BufferedImage) image).getRaster();
     if ((clearPixels == null) || (clearPixels.length < width)) {
       clearPixels = new int[width];
     }
     java.util.Arrays.fill(clearPixels, backgroundColor);
     for (int i = 0; i < height; i++) {
       raster.setDataElements(0, i, width, 1, clearPixels);
     }
   } else {
     // new Exception().printStackTrace(System.out);
     // in case people do transformations before background(),
     // need to handle this with a push/reset/pop
     pushMatrix();
     resetMatrix();
     g2.setColor(new Color(backgroundColor)); // , backgroundAlpha));
     g2.fillRect(0, 0, width, height);
     popMatrix();
   }
 }
 protected void drawShape(Shape s) {
   if (fillGradient) {
     g2.setPaint(fillGradientObject);
     g2.fill(s);
   } else if (fill) {
     g2.setColor(fillColorObject);
     g2.fill(s);
   }
   if (strokeGradient) {
     g2.setPaint(strokeGradientObject);
     g2.draw(s);
   } else if (stroke) {
     g2.setColor(strokeColorObject);
     g2.draw(s);
   }
 }
Example #15
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);
      }
    }
Example #16
0
  /**
   * Draw method
   *
   * @param g2 Graphics element
   * @param select Selected node
   */
  public void draw(Graphics2D g2, boolean select) {
    Point pinit = new Point(centre.x - 25, centre.y - 25);
    Point pfin = new Point(centre.x + 25, centre.y + 25);
    figure =
        new RoundRectangle2D.Float(
            pinit.x, pinit.y, Math.abs(pfin.x - pinit.x), Math.abs(pfin.y - pinit.y), 20, 20);

    g2.setColor(Color.black);
    if (select) {
      Stroke s = g2.getStroke();
      g2.setStroke(
          new BasicStroke(
              5, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {1, 1}, 0));
      g2.draw(figure);
      g2.setStroke(s);
    } else {
      g2.draw(figure);
    }
    g2.drawImage(image, centre.x - 25, centre.y - 25, 50, 50, pd);

    g2.setFont(new Font("Courier", Font.BOLD + Font.ITALIC, 12));
    FontMetrics metrics = g2.getFontMetrics();
    int width = metrics.stringWidth(dsc.getName());
    int height = metrics.getHeight();
    g2.drawString(dsc.getName(), centre.x - width / 2, centre.y + 40);
  }
Example #17
0
 /**
  * Method to paint this path segment
  *
  * @param g the graphics context
  */
 public void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   BasicStroke penStroke = new BasicStroke(this.width);
   g2.setStroke(penStroke);
   g2.setColor(this.color);
   g2.draw(this.line);
 }
Example #18
0
 /**
  * draw the symbol at the specified location
  *
  * @param g Graphics to draw to
  * @param x x location
  * @param y y location
  * @param width width to draw
  * @param height height to draw
  */
 public void draw(Graphics2D g, int x, int y, int width, int height) {
   g.setColor(getForeground());
   if (drawer == null) {
     drawer = makeDrawer();
   }
   drawer.draw(g, x, y, width, height, windSpeed, windDirection);
 }
Example #19
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
Example #20
0
 public void draw(Graphics2D g2, boolean shouldFlip) {
   Font font = new Font("Sans_Serif", Font.PLAIN, 30);
   g2.setColor(Color.orange);
   g2.fillOval((int) x - 10, (int) (FieldConstants.FIELD_HEIGHT - y - 10), 20, 20);
   font = new Font("Sans_Serif", Font.PLAIN, 18);
   g2.setFont(font);
   g2.drawString(Double.toString(confidence), x, FieldConstants.FIELD_HEIGHT - y + 60);
 }
Example #21
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);
  }
Example #22
0
    /** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */
    @Override
    public void render(Graphics2D g, VisualItem item) {
      Shape s = getShape(item);
      GraphicsLib.paint(g, item, m_line, getStroke(item), getRenderType(item));

      // check if we have a text label, if so, render it
      String str;
      if (item.canGetString(VisualItem.LABEL)) {
        str = (String) item.getString(VisualItem.LABEL);
        if (str != null && !str.equals("")) {
          float x = (float) m_box.getMinX();
          float y = (float) m_box.getMinY() + m_ascent;

          // draw label background
          GraphicsLib.paint(g, item, s, null, RENDER_TYPE_FILL);

          AffineTransform origTransform = g.getTransform();
          AffineTransform transform = this.getTransform(item);
          if (transform != null) {
            g.setTransform(transform);
          }

          g.setFont(item.getFont());
          g.setColor(ColorLib.getColor(item.getTextColor()));

          if (!(str.length() > 5
              && str.substring(str.length() - 5, str.length()).equals("_last"))) {

            g.setColor(Color.WHITE);
            // TODO properly hunt down source of null str! for now, triage
            if (str != null) {
              // bump y down by appropriate amount
              FontMetrics fm = g.getFontMetrics(item.getFont());
              int strHeight = fm.getAscent();
              //                        g.drawString(str, x, y);
              g.drawString(str, x, y + strHeight);
            }

            if (transform != null) {
              g.setTransform(origTransform);
            }
          }
        }
      }
    }
 protected void strokeShape(Shape s) {
   if (strokeGradient) {
     g2.setPaint(strokeGradientObject);
     g2.draw(s);
   } else if (stroke) {
     g2.setColor(strokeColorObject);
     g2.draw(s);
   }
 }
Example #24
0
 void renderUI(Graphics2D g2d) {
   g2d.setFont(new Font("Courier New", Font.PLAIN, 12));
   g2d.setColor(Color.white);
   if (removeMode) g2d.setColor(Color.black);
   if (player.health < 0) player.health = 0;
   g2d.drawString(String.format("Helath: %s", player.health), 10, 20);
   g2d.drawString(String.format("Kills: %s", player.score), 10, 40);
   int WLevel = (Integer) player.weapon[player.currentWeapon][10];
   if (WLevel == 5)
     g2d.drawString(String.format("Current Weapon: %s:Max", player.currentWeapon), 10, 60);
   else
     g2d.drawString(String.format("Current Weapon: %s:%s", player.currentWeapon, WLevel), 10, 60);
   g2d.setColor(Color.gray);
   g2d.drawString(String.format("Level: %s", difficulty), 10, 80);
   g2d.setColor(Color.black);
   if (showDebug) g2d.drawString(String.format("FPS: %s", fps), 10, 100);
   if (cheated) g2d.drawString("You cheated, no highscore will be saved", 200, height - 15);
 }
 /**
  * How MazeGrid.MARKER2 should be painted. Change this if you want marker2 to be painted
  * differently.
  */
 private void paintMarker2(Graphics2D g2, Cell a) {
   g2.setColor(Color.BLUE);
   g2.fill(
       new Rectangle2D.Double(
           this.cellWidth * a.col + (0.4 * this.cellWidth) - 1,
           this.cellWidth * a.row + (0.4 * this.cellWidth) - 1,
           0.4 * this.cellWidth,
           0.4 * this.cellWidth));
 }
 protected void fillShape(Shape s) {
   if (fillGradient) {
     g2.setPaint(fillGradientObject);
     g2.fill(s);
   } else if (fill) {
     g2.setColor(fillColorObject);
     g2.fill(s);
   }
 }
Example #27
0
  /**
   * A rendering method to draw this label to the given Graphics2D object, with the additional
   * option of allowing the "long" lines to be drawn. Due to the fact that the relative drawing
   * point of a state is its x and y co-ordinates and for a Transition there is a workOutMiddle()
   * method, the relative x and y values must be supplied to this method. Usually this method will
   * be called from inside a Transition render method or a State render method.
   *
   * @param g2 the Graphics2D component upon which to draw this label.
   * @param x the x position upon which to make relative co-ordinates exact.
   * @param y the y position upon which to make relative co-ordinates exact.
   * @param longLines flag to determine whether the long version of this label should be drawn.
   */
  public void render(Graphics2D g2, double x, double y, boolean longLines) {
    intersects(new Rectangle2D.Double(0, 0, 1, 1));
    StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n");
    if (selected) {
      g2.setColor(Color.green);
    } else {
      g2.setColor(theColour);
    }
    g2.setFont(theFont);
    int i = 0;
    boolean doneLong = false;
    while (tokens.hasMoreTokens()) {
      if (doneLong)
        g2.drawString(
            tokens.nextToken(),
            (float) (x + offsetX),
            (float) (y + offsetY + ((i * (theFont.getSize() + 2)))));
      else {
        if (!longLines)
          g2.drawString(
              tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
        else
          g2.drawString(
              getName() + ": " + tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
      }
      i++;
      doneLong = true;
    }

    /*if(intersects != null)
    {
        g2.setColor(Color.magenta);
        for(int j = 0; j < intersects.size(); j++)
        {
            Rectangle2D rect = (Rectangle2D)intersects.get(j);
            g2.draw(rect);
        }
    }*/

  }
 /**
  * method to draw the tail of the balloon
  *
  * @param ellipseHeight the height of the ellipse
  * @param fillColor the color to bill the balloon with
  * @param outlineColor the color to outline the balloon with
  * @param g2 the 2d graphics context
  */
 protected void drawTail(int ellipseHeight, Color fillColor, Color outlineColor, Graphics2D g2) {
   Point tailEnd = getTailEnd();
   Point upperLeft = getUpperLeft();
   int margin = getMargin();
   int halfWidth = getWidth() / 2;
   int topY = upperLeft.y + ellipseHeight;
   int startX = upperLeft.x + halfWidth - margin;
   int endX = upperLeft.x + halfWidth + margin;
   GeneralPath triangle = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3);
   triangle.moveTo(startX, topY);
   triangle.lineTo(endX, topY);
   triangle.lineTo(tailEnd.x, tailEnd.y);
   triangle.lineTo(startX, topY);
   g2.setColor(fillColor);
   g2.fill(triangle);
   g2.setColor(outlineColor);
   g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, startX, topY));
   g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, endX, topY));
 }
  private void drawBlock(Graphics2D g, double x, GraphBlock gb) {
    double y0 = getTimeY(gb.getStartTime());
    double y1 = getTimeY(gb.getEndTime());

    double x0 = x - active_width / 2;
    Color c = getThreadBlockColor(gb.getThread());
    Rectangle2D r = new Rectangle2D.Double(x0, y0, active_width, y1 - y0);
    g.setColor(c);
    g.fill(r);
  }
Example #30
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
  }