Exemplo n.º 1
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);
 }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
0
  @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 = square ? 1 : getOffset();
    if (c.hasFocus()) {
      if (DarculaButtonUI.isHelpButton((JComponent) c)) {
        int w = c.getWidth();
        int h = c.getHeight();
        DarculaUIUtil.paintFocusOval(g2d, (w - 22) / 2, (h - 22) / 2, 22, 22);
      } else {
        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));
      if (DarculaButtonUI.isHelpButton((JComponent) c)) {
        int w = c.getWidth();
        int h = c.getHeight();
        g.drawOval((w - 22) / 2, (h - 22) / 2, 22, 22);
      } else {
        g.drawRoundRect(
            x + offset,
            y + yOff,
            width - 2 * offset,
            height - 2 * yOff,
            square ? 3 : 5,
            square ? 3 : 5);
      }

      config.restore();
    }
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
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);
      }
Exemplo n.º 6
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);
  }
 // 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);
 }
Exemplo n.º 8
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);
       }
     }
   }
 }