/**
   * Paints the progress string.
   *
   * @param g Graphics used for drawing.
   * @param x x location of bounding box
   * @param y y location of bounding box
   * @param width width of bounding box
   * @param height height of bounding box
   * @param fillStart start location, in x or y depending on orientation, of the filled portion of
   *     the progress bar.
   * @param amountFull size of the fill region, either width or height depending upon orientation.
   * @param b Insets of the progress bar.
   */
  private void paintString(
      Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2 = (Graphics2D) g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      g2.setColor(getSelectionBackground());
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(fillStart, y, amountFull, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    } else { // VERTICAL
      g2.setColor(getSelectionBackground());
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      g2.setFont(progressBar.getFont().deriveFont(rotate));
      renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(x, fillStart, width, amountFull);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
  }
Esempio n. 2
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);
  }
Esempio n. 3
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
Esempio n. 4
0
  @Override
  // TODO Auto-generated method stub
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    // Draws the two initial two YinYang symbols on the frame
    g2.setColor(color1);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.fill(new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.setColor(color2);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }
    g2.fill(new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }

    // Alters and prints the text on the screen
    g2.setColor(Color.BLACK);
    g2.setFont(font);
    g2.drawString("Score", 700, 25);
    g2.drawString(Integer.toString(points), 700, 75);
    g2.drawString("Misses", 800, 25);
    g2.drawString(Integer.toString(misses), 800, 75);
    g2.drawString("Time Left", 700, 110);
    timeDisplay = timeLeft / 100.0;
    g2.drawString(timeDisplay.toString(), 700, 160);
  }
Esempio n. 5
0
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setColor(Color.black);
    g2.fillRect(0, 0, 10, 70);
    g2.fillRect(60, 0, 10, 70);
    g2.fillRect(120, 0, 10, 70);

    g2.fillRect(0, 0, 130, 10);
    g2.fillRect(0, 60, 130, 10);

    g2.fillRect(70, 30, 50, 10);
    g2.fillRect(90, 10, 10, 50);

    fill(g2, fullRect, RoadDirection.CENTER);
    fill(g2, nw, RoadDirection.NW);
    fill(g2, ne, RoadDirection.NE);
    fill(g2, sw, RoadDirection.SW);
    fill(g2, se, RoadDirection.SE);

    g2.setFont(Font.decode("Arial-10"));
    g2.setColor(Color.black);
    SwingUtils.drawCenteredString(g, "CENTER", (int) fullRectStrPos.x, (int) fullRectStrPos.y);
    SwingUtils.drawCenteredString(g, "NW", (int) nwStrPos.x, (int) nwStrPos.y);
    SwingUtils.drawCenteredString(g, "NE", (int) neStrPos.x, (int) neStrPos.y);
    SwingUtils.drawCenteredString(g, "SW", (int) swStrPos.x, (int) swStrPos.y);
    SwingUtils.drawCenteredString(g, "SE", (int) seStrPos.x, (int) seStrPos.y);
  }
Esempio n. 6
0
  public void paint(java.awt.Graphics g) {
    if (element != null) {
      Rectangle bounds = element.jGetBounds();
      Graphics2D g2 = (Graphics2D) g;

      g2.setFont(font);

      int mitteX = bounds.x + (bounds.width) / 2;
      int mitteY = bounds.y + (bounds.height) / 2;

      int distanceY = 10;

      g2.setColor(new Color(204, 204, 255));
      g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);
      g2.setColor(Color.BLACK);
      g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);

      String caption = "dec(" + variable.getValue() + ")";

      FontMetrics fm = g2.getFontMetrics();
      Rectangle2D r = fm.getStringBounds(caption, g2);

      g2.setColor(Color.BLACK);
      g.drawString(
          caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3);
    }
    super.paint(g);
  }
Esempio n. 7
0
  @Override
  public void paintComponent(Graphics window) {
    super.paintComponent(window);

    Image bufferedImage = createImage(getWidth(), getHeight());
    Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();

    g2d.setPaint(gradient1);
    g2d.fillRect(0, 0, 300, 1000);

    if (showInstructions == true) {
      g2d.setColor(Color.YELLOW);
      g2d.setFont(font1);
      g2d.drawString("Instructions:", 10, 150);
      g2d.setFont(font3);
      g2d.drawString("To Play, Click New Game", 10, 200);
      g2d.drawString("Each game costs $1", 10, 230);
      g2d.drawString("Hit adds a card to your hand", 10, 260);
      g2d.drawString("Stand stops the game and", 10, 290);
      g2d.drawString("calculates each persons score", 10, 320);
      g2d.drawString("To play dealer, click Play Dealer", 10, 350);
      g2d.drawString("Enter your desired wager", 10, 380);
      g2d.drawString("Every time you score 20 or 21", 10, 470);
      g2d.drawString("you get one arcade token", 10, 500);
      g2d.drawString("Arcade Tokens can be redeemed", 10, 530);
      g2d.drawString("By closing instructions and clicking", 10, 560);
      g2d.drawString("Play Arcade Game", 10, 590);
    } else {
      g2d.setColor(Color.YELLOW);
      g2d.setFont(font1);
      g2d.drawString("Arcade Game:", 10, 250);
      g2d.setFont(font3);
      g2d.drawString("Select the game you would like", 10, 320);
      g2d.drawString("Click Play to Play.", 10, 350);
      g2d.drawString("Hold and Drag the Mouse", 10, 380);
      g2d.drawString("to move in Cube Runner", 10, 410);
      g2d.drawString("Press the mouse to sprint", 10, 440);
      g2d.drawString("in Spiral Game, and click", 10, 500);
      g2d.drawString("to Jump", 10, 530);
      g2d.drawString("Each game costs one token", 10, 560);
      g2d.drawString("", 10, 590);
    }
    g2d.setColor(Color.YELLOW);
    g2d.setFont(font1);
    g2d.drawString("Tokens: " + tempObject.tokens, 10, 700);
    window.drawImage(bufferedImage, 0, 0, this);
  }
Esempio n. 8
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);
  }
Esempio n. 9
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);
 }
Esempio n. 10
0
 /**
  * Write the given text string in the current font, left-aligned at (x, y).
  *
  * @param x the x-coordinate of the text
  * @param y the y-coordinate of the text
  * @param s the text
  */
 public static void textLeft(double x, double y, String s) {
   offscreen.setFont(font);
   FontMetrics metrics = offscreen.getFontMetrics();
   double xs = scaleX(x);
   double ys = scaleY(y);
   int hs = metrics.getDescent();
   offscreen.drawString(s, (float) (xs), (float) (ys + hs));
   draw();
 }
Esempio n. 11
0
  /**
   * Draw every char in separate terminal cell to guaranty equal width for different lines.
   * Nevertheless to improve kerning we draw word characters as one block for monospaced fonts.
   */
  private void drawChars(int x, int y, CharBuffer buf, TextStyle style, Graphics2D gfx) {
    final int blockLen = 1;
    int offset = 0;
    int drawCharsOffset = 0;

    // workaround to fix Swing bad rendering of bold special chars on Linux
    // TODO required for italic?
    CharBuffer renderingBuffer;
    if (mySettingsProvider.DECCompatibilityMode() && style.hasOption(TextStyle.Option.BOLD)) {
      renderingBuffer = CharUtils.heavyDecCompatibleBuffer(buf);
    } else {
      renderingBuffer = buf;
    }

    while (offset + blockLen <= buf.length()) {
      if (renderingBuffer.getBuf()[buf.getStart() + offset] == CharUtils.DWC) {
        offset += blockLen;
        drawCharsOffset += blockLen;
        continue; // dont' draw second part(fake one) of double width character
      }

      Font font = getFontToDisplay(buf.charAt(offset + blockLen - 1), style);
      //      while (myMonospaced && (offset + blockLen < buf.getLength()) &&
      // isWordCharacter(buf.charAt(offset + blockLen - 1))
      //              && (font == getFontToDisplay(buf.charAt(offset + blockLen - 1), style))) {
      //        blockLen++;
      //      }
      gfx.setFont(font);

      int descent = gfx.getFontMetrics(font).getDescent();
      int baseLine = (y + 1) * myCharSize.height - descent;
      int xCoord = (x + drawCharsOffset) * myCharSize.width;
      int textLength =
          CharUtils.getTextLengthDoubleWidthAware(
              buf.getBuf(),
              buf.getStart() + offset,
              blockLen,
              mySettingsProvider.ambiguousCharsAreDoubleWidth());

      int yCoord = y * myCharSize.height;

      gfx.setClip(
          xCoord,
          yCoord,
          Math.min(textLength * myCharSize.width, getWidth() - xCoord),
          Math.min(myCharSize.height, getHeight() - yCoord));

      gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));

      gfx.drawChars(renderingBuffer.getBuf(), buf.getStart() + offset, blockLen, xCoord, baseLine);

      drawCharsOffset += blockLen;
      offset += blockLen;
    }
    gfx.setClip(null);
  }
Esempio n. 12
0
  /** Draw vertices on top of the edge structure */
  public void drawNodes(Graphics2D gg) {
    Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
    // Run through the traversal and draw each vertex
    // using an Ellipse2D
    // The draw point has been determined previously in
    // calcNodeCoords()
    while (nodeList.hasMoreElements()) {
      TreeVertex vertex = (TreeVertex) nodeList.nextElement();
      // Don't draw virtual nodes
      if (vertex.isVirtual()) continue;

      // If tree is incomplete and we're on the top layer, skip it
      if (argument.isMultiRoots() && vertex.getLayer() == 0) continue;

      Point corner = vertex.getDrawPoint();
      Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM);
      vertex.setShape(node, this);

      // Fill the interior of the node with vertex's fillPaint
      gg.setPaint(vertex.fillPaint);
      gg.fill(node);

      // Draw the outline with vertex's outlinePaint; bold if selected
      gg.setPaint(vertex.outlinePaint);
      if (vertex.isSelected()) {
        gg.setStroke(selectStroke);
      } else {
        gg.setStroke(solidStroke);
      }
      gg.draw(node);

      // Draw the short label on top of the vertex
      gg.setPaint(vertex.textPaint);
      String shortLabelString = new String(vertex.getShortLabel());
      if (shortLabelString.length() == 1) {
        gg.setFont(labelFont1);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4);
      } else if (shortLabelString.length() == 2) {
        gg.setFont(labelFont2);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4);
      }
    }
  }
Esempio n. 13
0
 /** Draws a message centered in the window. */
 private void drawMessage(Graphics2D g2, String message) {
   g2.setColor(Color.WHITE);
   g2.setFont(new Font("serif", Font.PLAIN, 72));
   // Calculate the size of the text so we can center it in the window
   FontMetrics metrics = g2.getFontMetrics();
   Rectangle2D textBounds = metrics.getStringBounds(message, g2);
   g2.drawString(
       message,
       windowWidth / 2 - (int) textBounds.getCenterX(),
       windowHeight / 2 - (int) textBounds.getCenterY());
 }
Esempio n. 14
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (nodes.get(0) == null) {
      return;
    }
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.blue);
    int x = 0;
    int y = 0;
    double xs = (double) (this.getWidth() - b - (nodes.get(0).r * nodeScaling));
    double ys = (double) (this.getHeight() - b - (nodes.get(0).r * nodeScaling) - noticeBorder);
    g2.setColor(Color.black);
    g2.fillRect(0, 0, this.getWidth(), this.getHeight());
    g2.setColor(Color.blue);
    drawNode s;
    drawNode d;
    RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);
    g2.setColor(Color.white);
    if (!ignoreLinks) {
      for (drawLink L : links.values()) {
        g2.setColor(L.color);
        s = nodes.get(L.sid);
        d = nodes.get(L.eid);
        if (s != null && d != null) {
          g2.drawLine(
              (int) ((s.x * xs) + (s.r * nodeScaling) / 2d),
              (int) ((s.y * ys) + (s.r * nodeScaling) / 2d),
              (int) ((d.x * xs) + (d.r * nodeScaling) / 2d),
              (int) ((d.y * ys) + (d.r * nodeScaling) / 2d));
        }
      }
    }
    for (drawNode N : nodes.values()) {
      g2.setColor(N.color);
      g2.fill(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
      g2.setColor(Color.black);
      g2.draw(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
    }
    if (showInfoForNode != -1 && nodeInfo.containsKey(showInfoForNode)) {
      drawNode N = nodes.get(showInfoForNode);

      x = (int) (N.x * xs + N.r * nodeScaling) + 3;
      y = (int) (N.y * ys);
      CTB.flipShift = (int) (N.r * nodeScaling) + 5;
      CTB.draw(g2, x, y, this.getWidth(), this.getHeight(), nodeInfo.get(showInfoForNode));
    }
    g2.setColor(Color.white);
    g2.setFont(new Font("Arial", Font.PLAIN, 10));
    g2.drawString("Ruud van de Bovenkamp - NAS", b, this.getHeight() - b);
    doneDrawing = true;
  }
Esempio n. 15
0
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(Color.WHITE);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   if (isDead) {
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 30));
     g2.drawString("Game Over!", 300, 300);
     g2.drawString("Your final score was " + score, 250, 330);
     moverTimer.stop();
     scoreTimer.stop();
   } else {
     topWall.paint(g2);
     bottomWall.paint(g2);
     bird.paint(g2);
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 20));
     g2.drawString("Score: " + score, 50, 50);
   }
 }
 public void draw(Graphics2D g) {
   g.setColor(fillColor);
   g.fill(gp);
   g.setColor(Color.black);
   g.draw(gp);
   for (int i = 0; i < points.size(); i++) {
     GlyphPoint p = points.get(i);
     g.setColor(Color.red);
     g.draw(p.gp);
     g.setColor(Color.blue);
     g.setFont(gfont);
     g.drawString(String.valueOf(i), p.x + 3, p.y + 3);
   }
   g.setColor(Color.black);
   //	    System.out.println("Advance: "+advance);
   g.draw(advp);
   if (name != null) {
     g.setFont(gfont);
     g.drawString(name, 0, -40);
   }
 }
Esempio n. 17
0
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;

      // paint ball, paddle, and brick configuration
      g2.drawImage(background.getImage(), 0, 0, null);
      bconfig.paint(g2);
      paddle.paint(g2);
      ball.paint(g2);
      g2.setColor(Color.WHITE);
      g2.setFont(new Font("Serif", Font.PLAIN, 20));
      g2.drawString("Score: " + score, 15, 20);
      if (ball.getY() > 500) {
        g2.setColor(Color.WHITE);
        g2.setFont(new Font("Serif", Font.PLAIN, 30));
        g2.drawString("Game Over!", 200, 300);
        g2.drawString("Your final score was " + score, 150, 330);
        timer.stop();
      }
    }
Esempio n. 18
0
 private synchronized void doBuffer(Graphics2D g2, boolean opq, Rectangle rt) {
   origTransform = g2.getTransform();
   if (opq && rt != null) g2.clearRect(rt.x, rt.y, rt.width, rt.height);
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   if (inBuffer) { // System.out.println("upps");
     for (int i = 0; i < a1x.size(); i++) doPaint(g2, a1x.get(i), a2x.get(i));
     origTransform = null;
     return;
   }
   for (int i = 0; i < a1.size(); i++) doPaint(g2, a1.get(i), a2.get(i));
   origTransform = null;
 }
 void drawMessage(Graphics2D g2d) {
   if (promptMsg == null) {
     return;
   }
   g2d.setFont(fontMsg);
   g2d.setColor(new Color(1f, 1f, 1f, 1));
   int sw = g2d.getFontMetrics().stringWidth(promptMsg);
   int sh = g2d.getFontMetrics().getMaxAscent();
   Rectangle ubound = (new ScreenUnion()).getBounds();
   for (int i = 0; i < Screen.getNumberScreens(); i++) {
     Rectangle bound = Screen.getBounds(i);
     int cx = bound.x + (bound.width - sw) / 2 - ubound.x;
     int cy = bound.y + (bound.height - sh) / 2 - ubound.y;
     g2d.drawString(promptMsg, cx, cy);
   }
 }
Esempio n. 20
0
 protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) {
   // Calculate the width of the string.
   FontRenderContext frc = g2.getFontRenderContext();
   TextLayout subLayout = new TextLayout(s, mFont, frc);
   float advance = subLayout.getAdvance();
   // Fill the background rectangle with a gradient.
   GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2);
   g2.setPaint(gradient);
   Rectangle2D bounds = mLayout.getBounds();
   Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight());
   g2.fill(back);
   // Draw the string over the gradient rectangle.
   g2.setPaint(Color.white);
   g2.setFont(mFont);
   g2.drawString(s, (float) x, (float) -bounds.getY());
   return advance;
 }
Esempio n. 21
0
  private void establishFontMetrics() {
    final BufferedImage img = createBufferedImage(1, 1);
    final Graphics2D graphics = img.createGraphics();
    graphics.setFont(myNormalFont);

    final float lineSpace = mySettingsProvider.getLineSpace();
    final FontMetrics fo = graphics.getFontMetrics();

    myDescent = fo.getDescent();
    myCharSize.width = fo.charWidth('W');
    myCharSize.height = fo.getHeight() + (int) (lineSpace * 2);
    myDescent += lineSpace;

    myMonospaced = isMonospaced(fo);
    if (!myMonospaced) {
      LOG.info("WARNING: Font " + myNormalFont.getName() + " is non-monospaced");
    }

    img.flush();
    graphics.dispose();
  }
Esempio n. 22
0
    protected BufferedImage makeImage() {
      BufferedImage image =
          new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D g = image.createGraphics();

      g.setPaint(Color.WHITE);
      g.fill3DRect(0, 0, IMAGE_SIZE, IMAGE_SIZE, false);

      g.setPaint(Color.RED);
      g.setFont(Font.decode("ARIAL-BOLD-50"));

      g.drawString(Long.toString(++this.counter) + " frames", 10, IMAGE_SIZE / 4);
      g.drawString(
          Long.toString((System.currentTimeMillis() - start) / 1000) + " sec", 10, IMAGE_SIZE / 2);
      g.drawString(
          "Heap:" + Long.toString(Runtime.getRuntime().totalMemory()), 10, 3 * IMAGE_SIZE / 4);

      g.dispose();

      return image;
    }
Esempio n. 23
0
 private synchronized void toBuffer(int s, Object a) {
   a1.add(s);
   a2.add(a);
   if (s == clear) {
     clearBuffer();
   }
   if (s == opaque) theOpaque = (Boolean) a;
   if (s == setBackground) theBackground = (Color) a;
   if (inBuffer) return;
   if (isSetter(s)) return;
   Graphics g = getGraphics();
   if (g == null) return;
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   for (int i = 0; i < a1.size() - 1; i++) {
     int s1 = a1.get(i);
     Object s2 = a2.get(i);
     if (isSetter(s1)) doPaint(g2, s1, s2);
   }
   doPaint((Graphics2D) g, s, a);
 }
Esempio n. 24
0
  private void drawInputMethodUncommitedChars(Graphics2D gfx) {
    if (myInputMethodUncommitedChars != null && myInputMethodUncommitedChars.length() > 0) {
      int x = myCursor.getCoordX() * myCharSize.width;
      int y = (myCursor.getCoordY()) * myCharSize.height - 2;

      int len = (myInputMethodUncommitedChars.length()) * myCharSize.width;

      gfx.setColor(getBackground());
      gfx.fillRect(x, (myCursor.getCoordY() - 1) * myCharSize.height, len, myCharSize.height);

      gfx.setColor(getForeground());
      gfx.setFont(myNormalFont);

      gfx.drawString(myInputMethodUncommitedChars, x, y);
      Stroke saved = gfx.getStroke();
      BasicStroke dotted =
          new BasicStroke(
              1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[] {0, 2, 0, 2}, 0);
      gfx.setStroke(dotted);

      gfx.drawLine(x, y, x + len, y);
      gfx.setStroke(saved);
    }
  }
Esempio n. 25
0
    public void run() {

      Thread me = Thread.currentThread();

      while (thread == me && !isShowing() || getSize().width == 0) {
        try {
          thread.sleep(500);
        } catch (InterruptedException e) {
          return;
        }
      }

      while (thread == me && isShowing()) {
        Dimension d = getSize();
        if (d.width != w || d.height != h) {
          w = d.width;
          h = d.height;
          bimg = (BufferedImage) createImage(w, h);
          big = bimg.createGraphics();
          big.setFont(font);
          FontMetrics fm = big.getFontMetrics(font);
          ascent = (int) fm.getAscent();
          descent = (int) fm.getDescent();
        }
        repaint();
        try {
          thread.sleep(sleepAmount);
        } catch (InterruptedException e) {
          break;
        }
        if (MemoryMonitor.dateStampCB.isSelected()) {
          System.out.println(new Date().toString() + " " + usedStr);
        }
      }
      thread = null;
    }
Esempio n. 26
0
  public void onRepaint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    String paintText = "Hide Paint";

    if (hidePaint) {
      paintText = "Show Paint";
      g.setColor(color1);
      g.fillRoundRect(closePaint.x, closePaint.y, closePaint.width, closePaint.height, 16, 16);
      g.setColor(color3);
      g.drawString(paintText, 435, 27);
    } else {
      g.setColor(color2);
      g.fillRoundRect(closePaint.x, closePaint.y, closePaint.width, closePaint.height, 16, 16);
      g.setColor(color3);
      g.drawString(paintText, 438, 27);

      final int skillPercent = skills.getPercentToNextLevel(Skills.FARMING);
      final int skillXP = skills.getExpToNextLevel(Skills.FARMING);
      final String xpToLevel;
      if (skillXP >= 1000) xpToLevel = Integer.toString(skillXP / 1000) + "k";
      else xpToLevel = Integer.toString(skillXP);
      final int nextLevel = skills.getRealLevel(Skills.FARMING) + 1;
      final int profit = marketPriceOfHerbs * numHerbsFarmed - marketPriceOfSeeds * numSeedsPlanted;
      final String profitMade;
      if (profit >= 100000) profitMade = Integer.toString(profit / 1000) + "k";
      else profitMade = Integer.toString(profit);

      String displayStatus = status;
      if (displayStatus == "Breaking while herbs grow: ")
        displayStatus += breakTimer.toRemainingString();

      int mouseX, mouseY;
      mouseX = (int) mouse.getLocation().getX();
      mouseY = (int) mouse.getLocation().getY();

      g.setColor(color1);
      g.drawLine(mouseX - 1000, mouseY, mouseX + 1000, mouseY);
      g.drawLine(mouseX, mouseY - 1000, mouseX, mouseY + 1000);
      g.fillRect(69, 320, 450, 21);
      g.setColor(color2);
      g.fillRect(69, 320, 450 * skillPercent / 100, 21);
      g.drawImage(img1, 0, 243, null);
      g.setFont(font1);
      g.drawString("Version: " + scriptVersion, 431, 471);
      g.setColor(color3);
      g.drawString(skillPercent + "% to level " + nextLevel + " (" + xpToLevel + " xp)", 216, 334);
      g.setColor(color1);
      g.drawString("Time Running: " + runTime.toElapsedString(), 102, 398);
      g.drawString("Herbs Farmed: " + numHerbsFarmed, 319, 399);
      g.drawString("Profit Made: " + profitMade, 319, 416);
      g.drawString("Seeds Planted: " + numSeedsPlanted, 102, 415);
      g.drawString("Seed Type: " + seedType, 102, 431);
      g.drawString("Status: " + displayStatus, 102, 449);

      if (currentLocation == Location.ARDOUGNE)
        for (int i = 1; i < camelotPath.length; i++) camelotPath[i].drawTo(g1, camelotPath[i - 1]);
      if (currentLocation == Location.CAMELOT)
        for (int i = 1; i < faladorPath.length; i++) faladorPath[i].drawTo(g1, faladorPath[i - 1]);
      if (currentLocation == Location.FALADOR)
        for (int i = 1; i < ardougnePath.length; i++)
          ardougnePath[i].drawTo(g1, ardougnePath[i - 1]);
    }
  }
    private void doPaint(Graphics g) {
      GraphicsUtil.setupAntialiasing(g);

      final boolean isEmpty = getIcon() == null && StringUtil.isEmpty(getText());
      final Dimension size = getSize();
      if (isSmallVariant()) {
        final Graphics2D g2 = (Graphics2D) g;
        g2.setColor(UIUtil.getControlColor());
        final int w = getWidth();
        final int h = getHeight();
        if (getModel().isArmed() && getModel().isPressed()) {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getControlColor(),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.8)));
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  ColorUtil.shift(UIUtil.getControlColor(), 1.1),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.9)));
        }
        g2.fillRect(2, 0, w - 2, h);
        GraphicsUtil.setupAntialiasing(g2);
        if (!myMouseInside) {
          g2.setPaint(
              new GradientPaint(
                  0, 0, UIUtil.getBorderColor(), 0, h, UIUtil.getBorderColor().darker()));
          // g2.setColor(UIUtil.getBorderColor());
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getBorderColor().darker(),
                  0,
                  h,
                  UIUtil.getBorderColor().darker().darker()));
        }
        g2.drawRect(2, 0, w - 3, h - 1);
        final Icon icon = getIcon();
        int x = 7;
        if (icon != null) {
          icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
          x += icon.getIconWidth() + 3;
        }
        if (!StringUtil.isEmpty(getText())) {
          final Font font = getFont();
          g2.setFont(font);
          g2.setColor(UIManager.getColor("Panel.foreground"));
          g2.drawString(getText(), x, (size.height + font.getSize()) / 2 - 1);
        }
      } else {
        super.paintComponent(g);
      }
      final Insets insets = super.getInsets();
      final Icon icon = isEnabled() ? ARROW_ICON : DISABLED_ARROW_ICON;
      final int x;
      if (isEmpty) {
        x = (size.width - icon.getIconWidth()) / 2;
      } else {
        if (isSmallVariant()) {
          x = size.width - icon.getIconWidth() - insets.right + 1;
        } else {
          x =
              size.width
                  - icon.getIconWidth()
                  - insets.right
                  + (UIUtil.isUnderNimbusLookAndFeel() ? -3 : 2);
        }
      }
      if (UIUtil.isUnderDarcula()) {
        g.setXORMode(new Color(208, 188, 159));
      }
      icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
      g.setPaintMode();
    }
Esempio n. 28
0
 private void paintScore(Graphics2D g2d) {
   Font font = new Font("sans", Font.PLAIN, 36);
   g2d.setColor(Color.green);
   g2d.setFont(font);
   g2d.drawString((int) c.getPoints() + "", 10, 50);
 }
  public void paintComponent(java.awt.Graphics g) {
    if (offer == null || g == null) return;

    Graphics2D g2d = (Graphics2D) g;
    AffineTransform origTx = g2d.getTransform();
    AffineTransform at = new AffineTransform();

    int x = getSize().width;
    int y = getSize().height;

    int xGap = 25;
    int yGap = 35;

    int xPaint = x - xGap;
    int yPaint = y - yGap;

    int maxRows = offer.maxRows;
    int maxCols = offer.maxCols;

    g2d.setColor(Color.lightGray);
    g2d.clearRect(0, 0, x, y);

    double xDist = ((double) xPaint) / maxCols, yDist = ((double) yPaint) / maxRows;

    // I = resourcen
    for (int i = 0; i < maxCols; i++) {
      // J= farben
      for (int j = 0; j < maxRows; j++) {
        if (offer.history[i][j] != 0) {
          g2d.setColor(color[offer.history[i][j]]);
          g2d.fillRect(
              xGap + (int) (xDist * i),
              yGap + yPaint - (int) (yDist * (j + 1)),
              (int) (xDist + 1),
              (int) (yDist + 1));
        }
      }
    }

    g2d.setColor(Color.black);
    // Rotate 90 degrees clockwise about the position (x, y)
    at.rotate(-Math.PI / 2, y / 2, y / 2);
    g2d.transform(at);

    // Draw the string at the position (x, y)
    g2d.setFont(new Font("Arial", Font.ITALIC, 15));
    g2d.drawString("Capacity of resource", 20, 14);

    // Rotate back
    g2d.setTransform(origTx);

    for (int i = 0; i < maxRows; i++) {
      g2d.drawLine(xGap, yGap + (int) (yDist * i), xGap + xPaint, yGap + (int) (yDist * i));
      g2d.drawLine(xGap, yGap + (int) (yDist * i + 1), xGap + xPaint, yGap + (int) (yDist * i + 1));
    }
    g2d.drawLine(
        xGap,
        yGap + (int) (yDist * maxRows) - 1,
        xGap + xPaint,
        yGap + (int) (yDist * maxRows) - 1);
    g2d.drawLine(
        xGap,
        yGap + (int) (yDist * maxRows) - 2,
        xGap + xPaint,
        yGap + (int) (yDist * maxRows) - 2);

    g2d.setFont(new Font("Dialog", Font.BOLD, 12));
    g2d.drawString("t = ", 10, 16);
    for (int i = 0; i < maxCols; i++) {
      g2d.drawLine(xGap + (int) (xDist * i), yGap, xGap + (int) (xDist * i), y);
      g2d.drawLine(xGap + (int) (xDist * i + 1), yGap, xGap + (int) (xDist * i + 1), y);
      g2d.drawString(String.valueOf(i + 1), xGap + (int) (xDist * i) + (i < 9 ? 8 : 4), 16);
    }
    g2d.drawLine(xGap + (int) (xDist * maxCols) - 1, yGap, xGap + (int) (xDist * maxCols) - 1, y);
    g2d.drawLine(xGap + (int) (xDist * maxCols) - 2, yGap, xGap + (int) (xDist * maxCols) - 2, y);
  }
Esempio n. 30
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    Graphics2D canvas = (Graphics2D) g;

    if (panelBackground != null) {
      canvas.drawImage(panelBackground, 0, 0, getPanelWidth(), getPanelHeight(), null);
    }

    if (dalekDamageImage != null) {
      // int w = 100;
      // int h = (int)  (dalekImage.getHeight(null) * w / dalekImage.getWidth(null)  );

      int h = 200;
      // int w = dalekDamageImage.scaleWidth(h);

      int w = h * dalekDamageImage.getWidth(null) / dalekDamageImage.getHeight(null);

      BufferedImage thumbImage = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekDamageImage, 0, 0, w, h, null);

      canvas.drawImage(thumbImage, getPanelWidth() / 2 - (w / 2), getPanelHeight() - h - 16, null);

      //	g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), 32 ,null);

    }
    if (dalekTacticalImage != null) {

      // int h = 400;
      // int w = dalekTacticalImage.scaleWidth(h);

      BufferedImage thumbImage =
          new BufferedImage(
              dalekTacticalImage.getWidth(),
              dalekTacticalImage.getHeight(),
              BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekTacticalImage, 0, 0, null);

      // g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), getPanelHeight() - h - 16 ,null);

      canvas.drawImage(thumbImage, 0, 32, null);

      /*
      Iterator<WeaponUI> it = dalekTacticalImage.iterator();
      int y = 32;
      while (it.hasNext()) {
      	g.drawImage(it.next(),0, y ,null);
      	y += 40; // really want height of WeaponUI.
      }
       */

    }

    // Move to Buffered Image
    if (this.getEngineRun() > 0) {
      this.drawEngineAt(
          canvas, 16, 256, this.getEngineWalk(), this.getEngineRun(), this.getEngineCurrent());
    }
    if (this.name != null) {
      canvas.setFont(techFont);
      canvas.drawString(this.name, 16, 24);
    }
  }