Example #1
0
  /** Overrides <code>Graphics.drawRoundRect</code>. */
  public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Drawing round rect: "
                  + new Rectangle(x, y, width, height)
                  + " arcWidth: "
                  + arcWidth
                  + " archHeight: "
                  + arcHeight);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  }
 @Override
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   g.setColor(new Color(0, 0, 255, 50));
   g.fillRoundRect(x, y, width, height, 10, 10);
   g.setColor(Color.white);
   g.drawRoundRect(x + 2, y + 2, width - 4, height - 4, 10, 10);
 }
Example #3
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(LightColors.SLIGHTLY_GREEN);
   g.fillRoundRect(x + 4, y + 4, 32 - 8, 32 - 8, 8, 8);
   g.setColor(Color.GRAY);
   g.drawRoundRect(x + 4, y + 4, 32 - 8, 32 - 8, 8, 8);
 }
  @Override
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    final Graphics2D g2d = (Graphics2D) g;
    final Insets ins = getBorderInsets(c);
    final int yOff = (ins.top + ins.bottom) / 4;
    final boolean square = DarculaButtonUI.isSquare(c);
    int offset = JBUI.scale(square ? 1 : getOffset());
    if (c.hasFocus()) {
      DarculaUIUtil.paintFocusRing(g2d, offset, yOff, width - 2 * offset, height - 2 * yOff);
    } else {
      final GraphicsConfig config = new GraphicsConfig(g);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
      g2d.setPaint(
          UIUtil.getGradientPaint(
              width / 2,
              y + yOff + 1,
              Gray._80.withAlpha(90),
              width / 2,
              height - 2 * yOff,
              Gray._90.withAlpha(90)));
      // g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5);

      ((Graphics2D) g).setPaint(Gray._100.withAlpha(180));
      g.drawRoundRect(
          x + offset,
          y + yOff,
          width - 2 * offset,
          height - 2 * yOff,
          JBUI.scale(square ? 3 : 5),
          JBUI.scale(square ? 3 : 5));

      config.restore();
    }
  }
Example #5
0
  private void drawContainer(steps.array.bucket.Container c, Graphics g, int x, int y) {
    // calculate the size of all the printed values
    Dimension dims = getContainerDimensions(g, c);
    int totalWidth = dims.width, totalHeight = dims.height;
    String allValues = CONTAINER_VALUE_SPACING;
    for (int i = 0; i < c.theValues.length; i++) {
      allValues += c.theValues[i] + CONTAINER_VALUE_SPACING;
    }
    int textWidth =
        (int) g.getFontMetrics(g.getFont()).getStringBounds("" + allValues, g).getWidth();

    // draw a rectangle to fit them all
    g.drawRoundRect(x, y, totalWidth, totalHeight, ARC_RADIUS, ARC_RADIUS);

    // print the values in it
    g.drawString(allValues, x + (totalWidth - textWidth) / 2, y + 3 * totalHeight / 4);
  }
Example #6
0
  static void paintFocus(
      Graphics g, int x, int y, int width, int height, int r1, int r2, float grosor, Color color) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Stroke oldStroke = g2d.getStroke();

    g2d.setColor(color);
    g2d.setStroke(new BasicStroke(grosor));
    if (r1 == 0 && r2 == 0) {
      g.drawRect(x, y, width, height);
    } else {
      g.drawRoundRect(x, y, width - 1, height - 1, r1, r2);
    }

    g2d.setStroke(oldStroke);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
  }
Example #7
0
      /**
       * Draw one die including the letter centered in the middle of the die. If highlight is true,
       * we reverse the background and letter colors to highlight the die.
       */
      public void paintComponent(Graphics g) {
        super.paintComponent(g);

        int centeredXOffset, centeredYOffset;
        // Draw the blank die
        g.setColor((isHighlighted) ? FACECOLOR : DIECOLOR);
        g.fillRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);

        // Outline the die with black
        g.setColor(Color.black);
        g.drawRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);
        Graphics faceGraphics = faceLabel.getGraphics();
        faceGraphics.setColor(isHighlighted ? DIECOLOR : FACECOLOR);
        Color myColor = isHighlighted ? DIECOLOR : FACECOLOR;
        faceLabel.setForeground(myColor);
        faceLabel.setFont(FACEFONT);
        faceLabel.setText(face);
      }
Example #8
0
  public void paint(Graphics g) {
    Rectangle r = g.getClipBounds();

    showStatus("x: " + r.x + " y: " + r.y + " w: " + r.width + " h: " + r.height);

    for (int i = 0; i < numRects; i++) {
      Point lhc = randomPoint(); // left hand corner
      Dimension size = randomDimension();

      g.setColor(colors[(int) (Math.random() * 10)]);

      if (round) {
        if (fill)
          g.fillRoundRect(
              lhc.x,
              lhc.y,
              size.width,
              size.height,
              (int) (Math.random() * 250),
              (int) (Math.random() * 250));
        else
          g.drawRoundRect(
              lhc.x,
              lhc.y,
              size.width,
              size.height,
              (int) (Math.random() * 250),
              (int) (Math.random() * 250));
      } else if (threeD) {
        g.setColor(Color.lightGray);

        if (fill) g.fill3DRect(lhc.x, lhc.y, size.width, size.height, raise);
        else g.draw3DRect(lhc.x, lhc.y, size.width, size.height, raise);
      } else {
        if (fill) g.fillRect(lhc.x, lhc.y, size.width, size.height);
        else g.drawRect(lhc.x, lhc.y, size.width, size.height);
      }
      raise = raise ? false : true;
    }
  }
Example #9
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Set new color
    g.setColor(Color.red);

    // Draw a rectangle
    g.drawRect(5, 5, getWidth() / 2 - 10, getHeight() / 2 - 10);

    // Draw a rounded rectangle
    g.drawRoundRect(getWidth() / 2 + 5, 5, getWidth() / 2 - 10, getHeight() / 2 - 10, 60, 30);

    // Change the color to cyan
    g.setColor(Color.cyan);

    // Draw a 3D rectangle
    g.fill3DRect(5, getHeight() / 2 + 5, getWidth() / 2 - 10, getHeight() / 2 - 10, true);

    // Draw a raised 3D rectangle
    g.fill3DRect(
        getWidth() / 2 + 5, getHeight() / 2 + 5, getWidth() / 2 - 10, getHeight() / 2 - 10, false);
  }
Example #10
0
  // 選單切換
  private void changeMeun() {
    if (page == -1) {
      setFont(16);
      switch (menustate) {
        case 0:
          // Select----------------------------
          g.setColor(255, 255, 255);
          g.drawString("開始遊戲", disWidth + 60, disHeight + 120, 0);
          // ----------------------------------
          g.setColor(69, 118, 181);
          g.drawString("繼續遊戲", disWidth + 60, disHeight + 140, 0);
          g.drawString("結束遊戲", disWidth + 60, disHeight + 160, 0);
          break;
        case 1:
          g.setColor(69, 118, 181);
          g.drawString("開始遊戲", disWidth + 60, disHeight + 120, 0);
          // Select----------------------------
          g.setColor(255, 255, 255);
          g.drawString("繼續遊戲", disWidth + 60, disHeight + 140, 0);
          // ----------------------------------
          g.setColor(69, 118, 181);
          g.drawString("結束遊戲", disWidth + 60, disHeight + 160, 0);
          break;
        case 2:
          g.setColor(69, 118, 181);
          g.drawString("開始遊戲", disWidth + 60, disHeight + 120, 0);
          g.drawString("繼續遊戲", disWidth + 60, disHeight + 140, 0);
          // Select----------------------------
          g.setColor(255, 255, 255);
          g.drawString("結束遊戲", disWidth + 60, disHeight + 160, 0);
          // ----------------------------------
          break;
      }
    } else {
      setFont(0);
      switch (menustate) {
        case 0:
          // Select------------------------
          g.setColor(255, 255, 255);
          g.drawRoundRect(disWidth + 52, disHeight + 93, 95, 15, 15, 15);
          g.drawString(nowString[0], disWidth + 22, disHeight + 90, 0);
          // ------------------------------
          g.setColor(69, 118, 181);
          g.drawRoundRect(disWidth + 52, disHeight + 113, 95, 15, 15, 15);
          g.drawString(nowString[1], disWidth + 22, disHeight + 110, 0);

          g.drawString(nowString[2], disWidth + 88, disHeight + 165, 0);
          g.drawString(nowString[3], disWidth + 128, disHeight + 165, 0);
          break;
        case 1:
          if (page == 0) { // 當為輸入帳號時顯示
            g.setColor(69, 118, 181);
            g.drawRoundRect(disWidth + 52, disHeight + 93, 95, 15, 15, 15);
            g.drawString(nowString[0], disWidth + 22, disHeight + 90, 0);
          }
          if (page == 0 || page == 2) { // 當為輸入帳號與遊戲名稱時顯示
            // Select------------------------
            g.setColor(255, 255, 255);
            g.drawRoundRect(disWidth + 52, disHeight + 113, 95, 15, 15, 15);
            g.drawString(nowString[1], disWidth + 22, disHeight + 110, 0);
            // ------------------------------
          }
          g.setColor(69, 118, 181);
          g.drawString(nowString[2], disWidth + 88, disHeight + 165, 0);
          g.drawString(nowString[3], disWidth + 128, disHeight + 165, 0);
          // System.out.println(menustate);
          break;
        case 3:
          if (page == 0) { // 當為輸入帳號時顯示
            g.setColor(69, 118, 181);
            g.drawRoundRect(disWidth + 52, disHeight + 93, 95, 15, 15, 15);
            g.drawString(nowString[0], disWidth + 22, disHeight + 90, 0);
          }
          if (page == 0 || page == 2) { // 當為輸入帳號與遊戲名稱時顯示
            g.setColor(69, 118, 181);
            g.drawRoundRect(disWidth + 52, disHeight + 113, 95, 15, 15, 15);
            g.drawString(nowString[1], disWidth + 22, disHeight + 110, 0);
          }
          // Select--------------------------
          g.setColor(255, 255, 255);
          g.drawString(nowString[2], disWidth + 88, disHeight + 165, 0);
          // --------------------------------
          g.setColor(69, 118, 181);
          g.drawString(nowString[3], disWidth + 128, disHeight + 165, 0);
          break;
        case 2:
          if (page == 0) {
            g.setColor(69, 118, 181);
            g.drawRoundRect(disWidth + 52, disHeight + 93, 95, 15, 15, 15);
            g.drawString(nowString[0], disWidth + 22, disHeight + 90, 0);
          }
          if (page == 0 || page == 2) {
            g.setColor(69, 118, 181);
            g.drawRoundRect(disWidth + 52, disHeight + 113, 95, 15, 15, 15);
            g.drawString(nowString[1], disWidth + 22, disHeight + 110, 0);
          }
          g.setColor(69, 118, 181);
          g.drawString(nowString[2], disWidth + 88, disHeight + 165, 0);
          // Select-------------------------
          g.setColor(255, 255, 255);
          g.drawString(nowString[3], disWidth + 128, disHeight + 165, 0);
          // -------------------------------
          break;
      }
    }
    flushGraphics();
  }
 public void drawFrame(Graphics g) {
   Rectangle r = displayBox();
   g.drawRoundRect(r.x, r.y, r.width - 1, r.height - 1, fArcWidth, fArcHeight);
 }
 // This class represents rectangle shapes with rounded corners.
 // (Note that it uses the inherited version of the
 // containsPoint(x,y) method, even though that is not perfectly
 // accurate when (x,y) is near one of the corners.)
 void draw(Graphics g) {
   g.setColor(color);
   g.fillRoundRect(left, top, width, height, width / 3, height / 3);
   g.setColor(Color.black);
   g.drawRoundRect(left, top, width, height, width / 3, height / 3);
 }
Example #13
0
    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);

      // Get the appropriate size for the figure
      int width = getWidth();
      int height = getHeight();

      switch (type) {
        case LINE: // Display two cross lines
          g.setColor(Color.BLACK);
          g.drawLine(10, 10, width - 10, height - 10);
          g.drawLine(width - 10, 10, 10, height - 10);
          break;
        case RECTANGLE: // Display a rectangle
          g.setColor(Color.blue);
          if (filled)
            g.fillRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          else
            g.drawRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          break;
        case ROUND_RECTANGLE: // Display a round-cornered rectangle
          g.setColor(Color.red);
          if (filled)
            g.fillRoundRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                20,
                20);
          else
            g.drawRoundRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                20,
                20);
          break;
        case OVAL: // Display an Oval
          g.setColor(Color.black);
          if (filled)
            g.fillOval(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          else
            g.drawOval(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          break;
        case ARC: // Display an arc
          g.setColor(Color.blue);
          if (filled) {
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                0,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                90,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                180,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                270,
                30);
          } else {
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                0,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                90,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                180,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                270,
                30);
          }
          break;

        case POLYGON:
          g.setColor(Color.red);
          int radius = (int) (0.4 * Math.min(width, height));
          int xCenter = (int) (0.4 * width);
          int yCenter = (int) (0.4 * height);
          Polygon p = new Polygon();
          p.addPoint(xCenter + radius, yCenter);

          p.addPoint(
              (int) (xCenter + radius * Math.cos(2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(2 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(2 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(3 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(3 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(4 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(4 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(5 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(5 * 2 * Math.PI / 6)));

          if (filled) {
            g.fillPolygon(p);
          } else {
            g.drawPolygon(p);
          }
          break;

        default:
          g.setColor(Color.BLACK);
          g.drawLine(10, 10, width - 10, height - 10);
          g.drawLine(width - 10, 10, 10, height - 10);
          break;
      }
    }
Example #14
0
 @Override
 public void paintComponent(Graphics g) {
   if (!antiRepeat && ChessEngine.choice == 0) {
     antiRepeat = true;
     userAsBlack();
   }
   super.paintComponent(g);
   this.setBackground(new Color(200, 100, 0));
   this.addMouseListener(this);
   this.addMouseMotionListener(this);
   // System.out.println("test");
   this.addComponentListener(
       new ComponentAdapter() {
         @Override
         public void componentResized(ComponentEvent e) {
           squareSize = (int) ((Math.min(getHeight(), getWidth()) - 2 * border) / 8);
         }
       });
   for (int i = 0; i < 64; i += 2) { // draw
     g.fillRect(
         (i % 8 + (i / 8) % 2) * squareSize + border,
         (i / 8) * squareSize + border,
         squareSize,
         squareSize);
     g.setColor(new Color(150, 50, 30));
     g.fillRect(
         ((i + 1) % 8 - ((i + 1) / 8) % 2) * squareSize + border,
         ((i + 1) / 8) * squareSize + border,
         squareSize,
         squareSize);
   }
   Image chessPieceImage;
   chessPieceImage = new ImageIcon("ChessPieces.png").getImage();
   for (int i = 0; i < 64; i++) { // draw piece
     int j = -1, k = -1;
     switch (ChessEngine.chessboard[i / 8][i % 8]) {
       case "P":
         j = 5;
         k = 1 - ChessEngine.choice;
         break;
       case "p":
         j = 5;
         k = ChessEngine.choice;
         break;
       case "R":
         j = 2;
         k = 1 - ChessEngine.choice;
         break;
       case "r":
         j = 2;
         k = ChessEngine.choice;
         break;
       case "K":
         j = 4;
         k = 1 - ChessEngine.choice;
         break;
       case "k":
         j = 4;
         k = ChessEngine.choice;
         break;
       case "B":
         j = 3;
         k = 1 - ChessEngine.choice;
         break;
       case "b":
         j = 3;
         k = ChessEngine.choice;
         break;
       case "Q":
         j = 1;
         k = 1 - ChessEngine.choice;
         break;
       case "q":
         j = 1;
         k = ChessEngine.choice;
         break;
       case "A":
         j = 0;
         k = 1 - ChessEngine.choice;
         break;
       case "a":
         j = 0;
         k = ChessEngine.choice;
         break;
     }
     if (j != -1 && k != -1) {
       g.drawImage(
           chessPieceImage,
           (i % 8) * squareSize + border + mouseDrag[i / 8][i % 8][0],
           (i / 8) * squareSize + border + mouseDrag[i / 8][i % 8][1],
           (i % 8 + 1) * squareSize + border + mouseDrag[i / 8][i % 8][0],
           (i / 8 + 1) * squareSize + border + mouseDrag[i / 8][i % 8][1],
           j * 64,
           k * 64,
           (j + 1) * 64,
           (k + 1) * 64,
           this);
     }
     // g.drawString(ChessEngine.chessboard[i/8][i%8], (i%8)*squareSize+border+13,
     // (i/8)*squareSize+border+21);
   }
   g.setColor(Color.BLUE);
   for (int i = 0; i < 8; i++) {
     for (int j = 0; j < 8; j++) {
       if (!chessboard[i][j].equals(ChessEngine.chessboard[i][j])) {
         g.drawRoundRect(
             j * squareSize + border + 3,
             i * squareSize + border + 3,
             squareSize - 6,
             squareSize - 6,
             10,
             10);
         g.drawRoundRect(
             j * squareSize + border + 4,
             i * squareSize + border + 4,
             squareSize - 8,
             squareSize - 8,
             10,
             10);
       }
     }
   }
 }