コード例 #1
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
コード例 #2
0
ファイル: Homework10.java プロジェクト: Sfhillier/YinYang
  @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);
  }
コード例 #3
0
ファイル: VerticalButtonUI.java プロジェクト: zoso10/skriv
  @Override
  public void paint(Graphics g, JComponent c) {
    JButton button = (JButton) c;
    String text = button.getText();
    Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    FontMetrics fm = g.getFontMetrics();
    paintViewInsets = c.getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;

    // Use inverted height &amp; width
    paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform tr = g2.getTransform();

    if (angle == 90) {
      g2.rotate(Math.PI / 2);
      g2.translate(0, -c.getWidth());
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    } else if (angle == 270) {
      g2.rotate(-Math.PI / 2);
      g2.translate(-c.getHeight(), 0);
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    }

    if (icon != null) {
      icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      int textX = paintTextR.x;
      int textY = paintTextR.y + fm.getAscent();

      if (button.isEnabled()) {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      } else {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      }
    }

    g2.setTransform(tr);
  }
コード例 #4
0
ファイル: Spaceship.java プロジェクト: LukeJHarvey/SpaceShip
  public void drawStar(int xpos, int ypos, double rot, double xscale, double yscale) {
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.fillOval(-10, -10, 20, 20);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
コード例 #5
0
ファイル: Spaceship.java プロジェクト: LukeJHarvey/SpaceShip
  public void drawCircle(int xpos, int ypos, double rot, double xscale, double yscale, int width) {
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.fillOval(-width / 2, -width / 2, width, width);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
コード例 #6
0
ファイル: Plot.java プロジェクト: rohitlways/kodejava
 void drawCenteredString(Graphics2D g2d, String string, int x0, int y0, float angle) {
   FontRenderContext frc = g2d.getFontRenderContext();
   Rectangle2D bounds = g2d.getFont().getStringBounds(string, frc);
   LineMetrics metrics = g2d.getFont().getLineMetrics(string, frc);
   if (angle == 0) {
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
   } else {
     g2d.rotate(angle, x0, y0);
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
     g2d.rotate(-angle, x0, y0);
   }
 }
コード例 #7
0
ファイル: Spaceship.java プロジェクト: LukeJHarvey/SpaceShip
  public void drawRocket(
      Image image, int xpos, int ypos, double rot, double xscale, double yscale) {
    int width = rocketImage.getWidth(this);
    int height = rocketImage.getHeight(this);
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.drawImage(image, -width / 2, -height / 2, width, height, this);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
コード例 #8
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
コード例 #9
0
ファイル: RocPlot.java プロジェクト: lizziesilver/tetrad
  private void drawYLabel(Graphics g) {
    g.setFont(fontBold);

    // # radians to rotate.
    double theta = -Math.PI / 2;

    Rectangle plotRect = getPlotRect();
    /*
     The y axis laabel.
    */
    String yLabel = "True Positive Fraction";
    int stringWidth = fm.stringWidth(yLabel);

    // where to begin drawing (the rotated image)
    Point translate =
        new Point(fm.getAscent(), plotRect.y + (plotRect.height / 2 + stringWidth / 2));

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform save = g2.getTransform();

    g2.translate(translate.x, translate.y);
    g2.rotate(theta);

    g2.setColor(boundaryColor);
    g2.drawString(yLabel, 0, 0);

    g2.setTransform(save);
  }
コード例 #10
0
ファイル: PlotWindow.java プロジェクト: kareemhalabi/comp250
    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);
      }
    }
コード例 #11
0
ファイル: PicturePanel.java プロジェクト: hvatum/Skole
 /**
  * Paints this component.
  *
  * @param g The Graphics2D graphics content to paint this component in.
  */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2D = (Graphics2D) g;
   if (orientation > 0)
     g2D.rotate(Math.PI * orientation / 2.0, imageWidth / 2.0, imageHeight / 2.0);
   g.drawImage(image, 0, 0, imageWidth, imageHeight, this);
   if (topImage != null) g2D.drawImage(topImage, 0, 0, imageWidth, imageHeight, this);
 }
コード例 #12
0
  public Image rotateImage(Image tilePiece, int degree) {

    ImageIcon icon = new ImageIcon(tilePiece);
    BufferedImage blankCanvas = new BufferedImage(80, 80, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) blankCanvas.getGraphics();
    g2.rotate(Math.toRadians(degree), 40, 40);
    g2.drawImage(tilePiece, 0, 0, this);
    return blankCanvas;
  }
コード例 #13
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   RenderingHints hints = new RenderingHints(null);
   hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
   g2.setRenderingHints(hints);
   g2.rotate(-Math.toRadians(degrees), w / 2, h / 2);
   g2.drawImage(dimg, 0, 0, this);
   g2.dispose();
 }
コード例 #14
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees, rescaled
   * to w-by-h.
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param w the width of the image
   * @param h the height of the image
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double w, double h, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    double ws = factorX(w);
    double hs = factorY(h);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");
    if (ws <= 1 && hs <= 1) pixel(x, y);

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image,
        (int) Math.round(xs - ws / 2.0),
        (int) Math.round(ys - hs / 2.0),
        (int) Math.round(ws),
        (int) Math.round(hs),
        null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
コード例 #15
0
  /**
   * Paint the component.
   *
   * @param g The graphics context for painting
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    fRenderer.paintComponent(g2, fButtonDelegate, this, 0, 0, getWidth(), getHeight(), true);

    ButtonModel model = getModel();
    boolean doOffset = model.isPressed() && model.isArmed();
    int offsetAmount = UIManager.getInt("Button.textShiftOffset");
    double degrees = Math.toRadians(-90);

    if (fRotation == LEFT) {
      int h = getHeight();
      g2.translate(0, h);
      g2.rotate(degrees);
      if (doOffset) {
        g2.translate(-offsetAmount, offsetAmount);
      }

      fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true);
      if (doOffset) {
        g2.translate(offsetAmount, -offsetAmount);
      }
      g2.rotate(-degrees);

      g2.translate(0, -h);
    } else {
      int w = getWidth();
      g2.translate(w, 0);
      g2.rotate(-degrees);
      if (doOffset) {
        g2.translate(offsetAmount, -offsetAmount);
      }
      fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true);
      if (doOffset) {
        g2.translate(-offsetAmount, offsetAmount);
      }
      g2.rotate(degrees);
      g2.translate(-w, 0);
    }
  }
コード例 #16
0
ファイル: JCanvas.java プロジェクト: xaleth09/Connect4-AI
 public static BufferedImage rotateImage(BufferedImage bi) {
   int w = bi.getWidth();
   int h = bi.getHeight();
   BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white); // getBackground());
   g2.fillRect(0, 0, h, w);
   g2.rotate(90 * Math.PI / 180);
   g2.drawImage(bi, 0, -h, w, h, null); // this);
   g2.dispose();
   return image;
 }
コード例 #17
0
    public void paintLogo(Component c, Graphics g, int x, int y, int w, int h) {
      if (hasLogo(c)) {
        Graphics2D g2D = (Graphics2D) g;

        Font savedFont = g2D.getFont();
        g.setFont(logoFont);
        FontMetrics fm = JTattooUtilities.getFontMetrics((JComponent) c, g, c.getFont());
        String logo =
            JTattooUtilities.getClippedText(
                AbstractLookAndFeel.getTheme().getLogoString(), fm, h - 16);

        AffineTransform savedTransform = g2D.getTransform();

        Color fc = getLogoColorHi();
        Color bc = getLogoColorLo();

        if (JTattooUtilities.isLeftToRight(c)) {
          g2D.translate(fm.getAscent() + 1, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        } else {
          g2D.translate(w - shadowSize - 4, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        }

        g2D.setTransform(savedTransform);
        g2D.setFont(savedFont);
      }
    }
コード例 #18
0
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      Graphics2D g2 = (Graphics2D) g;

      if (!text.equals("")) {
        g2.translate(0, getSize().getHeight());
        g2.rotate(-Math.PI / 2);
        g2.setColor(Color.black);
        g2.drawString(text, 20, 14);

        g2.translate(0, -getSize().getHeight());
        g2.transform(AffineTransform.getQuadrantRotateInstance(1));
      }
    }
コード例 #19
0
ファイル: My29.java プロジェクト: Buzov/Java_lesson
  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);
  }
コード例 #20
0
 public void paintComponent(Graphics g1) {
   Graphics2D g = (Graphics2D) g1;
   float width = getWidth();
   float height = getHeight();
   AffineTransform save = g.getTransform();
   AffineTransform save_tmp;
   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (45.0 <= rotate && rotate < 135.0) {
     g.translate(width, 0.0);
     g.rotate(Math.PI * rotate / 180, 0.0, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else if (135.0 <= rotate && rotate < 225.0) {
     g.rotate(Math.PI * rotate / 180, width / 2, height / 2);
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   } else if (225.0 <= rotate && rotate < 315.0) {
     g.translate(-height, 0.0);
     g.rotate(Math.PI * rotate / 180, height, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           30,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[0]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           32,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[1]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           32,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[2]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           33,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[3]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           33,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[4]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           32,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[5]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           30,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[6]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           33,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[7]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           32,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[8]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           30,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[9]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           32,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[10]);
   g.setStroke(new BasicStroke(2F));
   g.setColor(
       GeColor.getColor(
           32,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[11]);
   g.setTransform(save);
 }
コード例 #21
0
ファイル: MapPanel.java プロジェクト: agale123/Catan
  public synchronized void paint(Graphics graphics) {

    Graphics2D g = (Graphics2D) graphics;

    Image water = Toolkit.getDefaultToolkit().getImage("catanui/water.jpg");
    g.drawImage(water, 0, 0, this);

    for (Hex o : _hexes) {
      o.paint(g, _display_offset[0], _display_offset[1]);
    }

    g.translate(_display_offset[0] + 2, _display_offset[1] - 1);
    synchronized (portContents) {
      for (Pair c : portContents.keySet()) {

        int lowx =
            hexleft
                + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                    / 2
                    * intervalSide[0]
                + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                    / 2
                    * intervalSide[1]
                + (((CoordPair) c.getA()).getX() % 2) * intervalSide[0];
        int lowy = hextop + ((CoordPair) c.getA()).getY() * intervalUp;
        int highx =
            hexleft
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[0]
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[1]
                + (((CoordPair) c.getB()).getX() % 2) * intervalSide[0];
        int highy = hextop + ((CoordPair) c.getB()).getY() * intervalUp;

        int dx = highx - lowx;
        int dy = highy - lowy;
        double rad = Math.atan((1.0) * dy / dx);

        if (dx < 0) rad += Math.PI;

        g.translate(lowx, lowy);
        g.rotate(rad);
        g.drawImage(
            BoardObject.images.get(BoardObject.type2port.get(portContents.get(c))), 0, -75, null);
        g.rotate(-rad);
        g.translate((-1) * lowx, (-1) * lowy);
      }
    }
    g.translate((-1) * _display_offset[0], (-1) * _display_offset[1]);

    synchronized (roadContents) {
      for (Pair c : roadContents.keySet()) {

        Road r =
            new Road(
                hexleft
                    + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                        / 2
                        * intervalSide[0]
                    + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                        / 2
                        * intervalSide[1]
                    + (((CoordPair) c.getA()).getX() % 2) * intervalSide[0],
                hextop + ((CoordPair) c.getA()).getY() * intervalUp);

        r.setX2(
            hexleft
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[0]
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[1]
                + (((CoordPair) c.getB()).getX() % 2) * intervalSide[0]);
        r.setY2(hextop + ((CoordPair) c.getB()).getY() * intervalUp);

        r.setColor(roadContents.get(c));
        r.paint(g, _display_offset[0], _display_offset[1]);
      }
    }

    synchronized (vertexContents) {
      for (CoordPair c : vertexContents.keySet()) {
        int newx =
            hexleft
                + ((c._x - (c._x % 2)) / 2 * intervalSide[0]
                    + (c._x - (c._x % 2)) / 2 * intervalSide[1]
                    + (c._x % 2) * intervalSide[0])
                - 20;
        int newy = hextop + c._y * intervalUp - 20;

        if ((BoardObject.type) (vertexContents.get(c).getA()) == BoardObject.type.SETTLEMENT) {
          Settlement s = new Settlement(newx, newy, (Integer) (vertexContents.get(c).getB()));
          s.paint(g, _display_offset[0], _display_offset[1]);
        } else if ((BoardObject.type) (vertexContents.get(c).getA()) == BoardObject.type.CITY) {
          City s = new City(newx, newy, (Integer) (vertexContents.get(c).getB()));
          s.paint(g, _display_offset[0], _display_offset[1]);
        } else System.out.println("neither -_-");
      }
    }

    g.setColor(Color.GRAY);
    g.fill(new Rectangle(0, 0, 110, 60));
    g.setColor(Color.LIGHT_GRAY);
    g.fill(new Rectangle(3, 3, 104, 56));
    if (_dieRoll > 0) {
      BufferedImage r1img =
          diceImage.getSubimage((int) (Math.floor((twoDice[0] - 1) * 94.7)), 0, 94, 93);
      g.drawImage(r1img, 5, 7, 48, 47, null);
      BufferedImage r2img =
          diceImage.getSubimage((int) (Math.floor((twoDice[1] - 1) * 94.7)), 0, 94, 93);
      g.drawImage(r2img, 55, 7, 48, 47, null);
    }

    if (_up != null) _up.paint(g);

    if (!_gameOver.equals("") && !_dismiss) {
      _currAlpha += 0.007;
    }
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _currAlpha));
    g.setColor(Color.GRAY);
    g.fill(new Rectangle(-20, 0, 1020, 650));
    g.setColor(Color.BLACK);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) 1.0));
    if (!_gameOver.equals("")) {

      if (_currAlpha >= 0.8) {
        if (_gameOver.equals(gameLogic._name)) {
          g.drawString("Congratulations, you won!", 350, 200);
        } else {
          g.drawString(_gameOver + " has won!", 350, 200);
        }
        _dismiss = true;
      } else repaint();
    }
  }
コード例 #22
0
  public void paint(final Graphics g, final JComponent c) {
    final AnchoredButton button = (AnchoredButton) c;

    final String text = button.getText();
    final Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    final FontMetrics fm = button.getFontMetrics(button.getFont());
    ourViewInsets = c.getInsets(ourViewInsets);

    ourViewRect.x = ourViewInsets.left;
    ourViewRect.y = ourViewInsets.top;

    final ToolWindowAnchor anchor = button.getAnchor();

    // Use inverted height & width
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      ourViewRect.height = c.getWidth() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getHeight() - (ourViewInsets.top + ourViewInsets.bottom);
    } else {
      ourViewRect.height = c.getHeight() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getWidth() - (ourViewInsets.top + ourViewInsets.bottom);
    }

    ourIconRect.x = ourIconRect.y = ourIconRect.width = ourIconRect.height = 0;
    ourTextRect.x = ourTextRect.y = ourTextRect.width = ourTextRect.height = 0;

    final String clippedText =
        SwingUtilities.layoutCompoundLabel(
            c,
            fm,
            text,
            icon,
            button.getVerticalAlignment(),
            button.getHorizontalAlignment(),
            button.getVerticalTextPosition(),
            button.getHorizontalTextPosition(),
            ourViewRect,
            ourIconRect,
            ourTextRect,
            button.getText() == null ? 0 : button.getIconTextGap());

    // Paint button's background

    final Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    final ButtonModel model = button.getModel();

    final Color background = button.getBackground();

    Color toBorder = model.isRollover() ? new Color(0, 0, 0, 50) : null;
    final boolean vertical = anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT;

    if (model.isArmed() && model.isPressed() || model.isSelected()) {
      g2.setColor(new Color(0, 0, 0, 30));
      g2.fillRect(3, 3, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);

      g2.setColor(new Color(0, 0, 0, 120));
      g2.drawLine(2, 2, 3 + button.getWidth() - (vertical ? 7 : 6), 2);
      g2.drawLine(2, 3, 2, 3 + button.getHeight() - 7);

      g2.setColor(new Color(0, 0, 0, 40));
      g2.drawRect(3, 3, button.getWidth() - (vertical ? 7 : 6), button.getHeight() - 7);

      g2.setColor(new Color(255, 255, 255, 110));
      g2.drawLine(
          3,
          button.getHeight() - 3,
          3 + button.getWidth() - (vertical ? 6 : 5),
          button.getHeight() - 3);
      g2.drawLine(
          3 + button.getWidth() - (vertical ? 6 : 5),
          2,
          3 + button.getWidth() - (vertical ? 6 : 5),
          3 + button.getHeight() - 7);

      toBorder = null;
    }

    if (toBorder != null) {
      g.setColor(toBorder);
      g.drawRect(2, 2, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);
    }

    AffineTransform tr = null;
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      tr = g2.getTransform();
      if (ToolWindowAnchor.RIGHT == anchor) {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(c, g2, ourIconRect.y, ourIconRect.x);
        }
        g2.rotate(Math.PI / 2);
        g2.translate(0, -c.getWidth());
      } else {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(
              c, g2, ourIconRect.y, c.getHeight() - ourIconRect.x - icon.getIconHeight());
        }
        g2.rotate(-Math.PI / 2);
        g2.translate(-c.getHeight(), 0);
      }
    } else {
      if (icon != null) {
        icon.paintIcon(c, g2, ourIconRect.x, ourIconRect.y);
      }
    }

    // paint text

    if (text != null) {
      if (model.isEnabled()) {
        if (model.isArmed() && model.isPressed() || model.isSelected()) {
          g.setColor(background);
        } else {
          g.setColor(button.getForeground());
        }
      } else {
        g.setColor(background.darker());
      }
      /* Draw the Text */
      if (model.isEnabled()) {
        /** * paint the text normally */
        g.setColor(button.getForeground());
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      } else {
        /** * paint the text disabled ** */
        if (model.isSelected()) {
          g.setColor(c.getBackground());
        } else {
          g.setColor(getDisabledTextColor());
        }
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      }
    }
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      g2.setTransform(tr);
    }
  }
コード例 #23
0
ファイル: JCanvas.java プロジェクト: xaleth09/Connect4-AI
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
コード例 #24
0
 public void paintComponent(Graphics g1) {
   animationCount = 1;
   if (!visible) return;
   Graphics2D g = (Graphics2D) g1;
   float width = getWidth();
   float height = getHeight();
   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (45.0 <= rotate && rotate < 135.0) {
     g.translate(width, 0.0);
     g.rotate(Math.PI * rotate / 180, 0.0, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else if (135.0 <= rotate && rotate < 225.0) {
     g.rotate(Math.PI * rotate / 180, width / 2, height / 2);
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   } else if (225.0 <= rotate && rotate < 315.0) {
     g.translate(-height, 0.0);
     g.rotate(Math.PI * rotate / 180, height, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   if ((dd.dynType & GeDyn.mDynType_Rotate) != 0 && dd.rotate != 0) {
     g.rotate(
         Math.PI * dd.rotate / 180,
         (dd.x0 - getX()) * original_width / width,
         (dd.y0 - getY()) * original_height / height);
   }
   AffineTransform save = g.getTransform();
   AffineTransform save_tmp;
   int rounds = 1;
   if (fillLevel != 1F) rounds = 2;
   int oldColor = 0;
   for (int i = 0; i < rounds; i++) {
     if (rounds == 2) {
       switch (i) {
         case 0:
           if (levelColorTone != GeColor.COLOR_TONE_NO) {
             oldColor = colorTone;
             colorTone = levelColorTone;
           } else if (levelFillColor != GeColor.COLOR_NO) {
             oldColor = fillColor;
             fillColor = levelFillColor;
           }
           break;
         case 1:
           if (levelColorTone != GeColor.COLOR_TONE_NO) colorTone = oldColor;
           else if (levelFillColor != GeColor.COLOR_NO) fillColor = oldColor;
           break;
       }
       switch (levelDirection) {
         case Ge.DIRECTION_UP:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     fillLevel * original_height + Ge.cJBean_Offset,
                     original_width,
                     original_height));
           else
             g.setClip(
                 new Rectangle2D.Float(
                     0F, 0F, original_width, fillLevel * original_height + Ge.cJBean_Offset));
           break;
         case Ge.DIRECTION_DOWN:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     0F,
                     original_width,
                     (1 - fillLevel) * original_height + Ge.cJBean_Offset));
           else
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     (1 - fillLevel) * original_height + Ge.cJBean_Offset,
                     original_width,
                     original_height));
           break;
         case Ge.DIRECTION_RIGHT:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     fillLevel * original_width + Ge.cJBean_Offset,
                     0F,
                     original_width,
                     original_height));
           else
             g.setClip(
                 new Rectangle2D.Float(0F, 0F, fillLevel * width + Ge.cJBean_Offset, height));
           break;
         case Ge.DIRECTION_LEFT:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     0F,
                     (1 - fillLevel) * original_width + Ge.cJBean_Offset,
                     original_height));
           else
             g.setClip(
                 new Rectangle2D.Float(
                     (1 - fillLevel) * original_width + Ge.cJBean_Offset,
                     0F,
                     original_width,
                     original_height));
           break;
       }
     }
     {
       int fcolor =
           GeColor.getDrawtype(
               293,
               colorTone,
               colorShift,
               colorIntensity,
               colorBrightness,
               colorInverse,
               fillColor,
               dimmed);
       if (gradient == GeGradient.eGradient_No) {
         g.setColor(GeColor.getColor(fcolor));
         g.fill(shapes[0]);
       } else {
         GeGradient.paint(
             g,
             gradient,
             2,
             -2,
             2F,
             2F,
             13.6808F,
             14.8208F,
             false,
             293,
             colorTone,
             colorShift,
             colorIntensity,
             colorInverse,
             fillColor,
             dimmed);
         g.fill(shapes[0]);
       }
       if (shadow != 0) {
         g.setColor(GeColor.shiftColor(fcolor, -2, colorInverse));
         g.fill(shapes[1]);
         g.setColor(GeColor.shiftColor(fcolor, 2, colorInverse));
         g.fill(shapes[2]);
       }
       g.setStroke(new BasicStroke(1F));
       g.setColor(
           GeColor.getColor(
               0,
               colorTone,
               colorShift,
               colorIntensity,
               colorBrightness,
               colorInverse,
               borderColor,
               dimmed));
       g.draw(shapes[0]);
     }
   }
   if (rounds == 2) g.setClip(null);
   g.setTransform(save);
 }
コード例 #25
0
ファイル: JopButtonset.java プロジェクト: jordibrus/proview
 public void paintComponent(Graphics g1) {
   Graphics2D g = (Graphics2D) g1;
   float width = getWidth();
   float height = getHeight();
   AffineTransform save = g.getTransform();
   AffineTransform save_tmp;
   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (45.0 <= rotate && rotate < 135.0) {
     g.translate(width, 0.0);
     g.rotate(Math.PI * rotate / 180, 0.0, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else if (135.0 <= rotate && rotate < 225.0) {
     g.rotate(Math.PI * rotate / 180, width / 2, height / 2);
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   } else if (225.0 <= rotate && rotate < 315.0) {
     g.translate(-height, 0.0);
     g.rotate(Math.PI * rotate / 180, height, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   g.setColor(
       GeColor.getColor(
           22,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           fillColor,
           false));
   g.fill(shapes[0]);
   g.setColor(
       GeColor.getColor(
           20,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           fillColor,
           false));
   g.fill(shapes[1]);
   g.setColor(
       GeColor.getColor(
           23,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           fillColor,
           false));
   g.fill(shapes[2]);
   g.setStroke(new BasicStroke(1F));
   g.setColor(
       GeColor.getColor(
           0,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           borderColor,
           false));
   g.draw(shapes[3]);
   g.setColor(Color.black);
   g.setFont(annot1Font);
   save_tmp = g.getTransform();
   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
   g.transform(
       AffineTransform.getScaleInstance(original_width / width * height / original_height, 1));
   g.drawString(annot1, 13 * original_height / height * width / original_width, 22F);
   g.setTransform(save_tmp);
   g.setTransform(save);
 }
コード例 #26
0
ファイル: NimbusIcon.java プロジェクト: ru-doc/java-sdk
  @Override
  public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) {
    Painter painter = null;
    if (context != null) {
      painter = (Painter) context.getStyle().get(context, key);
    }
    if (painter == null) {
      painter = (Painter) UIManager.get(prefix + "[Enabled]." + key);
    }

    if (painter != null && context != null) {
      JComponent c = context.getComponent();
      boolean rotate = false;
      boolean flip = false;
      // translatex and translatey are additional translations that
      // must occur on the graphics context when rendering a toolbar
      // icon
      int translatex = 0;
      int translatey = 0;
      if (c instanceof JToolBar) {
        JToolBar toolbar = (JToolBar) c;
        rotate = toolbar.getOrientation() == JToolBar.VERTICAL;
        flip = !toolbar.getComponentOrientation().isLeftToRight();
        Object o = NimbusLookAndFeel.resolveToolbarConstraint(toolbar);
        // we only do the +1 hack for UIResource borders, assuming
        // that the border is probably going to be our border
        if (toolbar.getBorder() instanceof UIResource) {
          if (o == BorderLayout.SOUTH) {
            translatey = 1;
          } else if (o == BorderLayout.EAST) {
            translatex = 1;
          }
        }
      }
      if (g instanceof Graphics2D) {
        Graphics2D gfx = (Graphics2D) g;
        gfx.translate(x, y);
        gfx.translate(translatex, translatey);
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
          gfx.translate(0, w);
          gfx.rotate(Math.toRadians(-90));
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
          gfx.translate(w, 0);
          gfx.scale(-1, 1);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.translate(-translatex, -translatey);
        gfx.translate(-x, -y);
      } else {
        // use image if we are printing to a Java 1.1 PrintGraphics as
        // it is not a instance of Graphics2D
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gfx = img.createGraphics();
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.dispose();
        g.drawImage(img, x, y, null);
        img = null;
      }
    }
  }