Package java.awt

Examples of java.awt.Graphics2D


   * @param event the report event.
   */
  public void pageStarted(final ReportEvent event)
  {
    final BufferedImage image = new BufferedImage(150, 50, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = image.createGraphics();
    final JButton bt = new JButton("A Button");
    bt.setSize(90, 20);
    final JRadioButton radio = new JRadioButton("A radio button");
    radio.setSize(100, 20);

    g2.setColor(Color.darkGray);
    bt.paint(g2);
    g2.setColor(Color.blue);
    g2.setTransform(AffineTransform.getTranslateInstance(20, 20));
    radio.paint(g2);
    g2.setTransform(AffineTransform.getTranslateInstance(0, 0));
    g2.setPaint(Color.green);
    g2.setFont(new Font("Serif", Font.PLAIN, 10));
    g2.drawString("You are viewing a graphics of JFreeReport on index "
        + event.getState().getCurrentDataItem(), 10, 10);
    g2.dispose();
    try
    {
      functionValue = new DefaultImageReference(image);
    }
    catch (IOException e)
View Full Code Here


            MessageFormat.format(fileName, new Object[]{new Integer(i)});
        final BufferedImage image = createImage(report.getPageDefinition());

        final Rectangle rect = new Rectangle(0, 0, image.getWidth(), image.getHeight());
        // prepare the image by filling it ...
        final Graphics2D g2 = image.createGraphics();
        g2.setPaint(Color.white);
        g2.fill(rect);

        final PageDrawable pageDrawable = prc.getPageDrawable(i);
        pageDrawable.draw(g2, rect);
        g2.dispose();

        // convert to PNG ...
        final PngEncoder encoder = new PngEncoder(image, true, 0, 9);
        final byte[] data = encoder.pngEncode();
View Full Code Here

   */
  public void paintValue(Graphics gfx, Rectangle box)
  {
    if (gfx instanceof Graphics2D)
    {
      Graphics2D graphics2D = (Graphics2D) gfx;
      graphics2D.setStroke(value);
      graphics2D.drawLine(box.x, box.height / 2 + box.y, box.x + box.width, box.height / 2 + box.y);
    }
  }
View Full Code Here

    public void paintComponent(Graphics g)
    {
      super.paintComponent(g);
      if (sampleValue != null)
      {
        Graphics2D g2d = (Graphics2D) g;
        Stroke origStroke = g2d.getStroke();
        Color origColor = g2d.getColor();
        Shape origClip = g2d.getClip();

        g2d.setStroke(sampleValue);

        g2d.drawLine(getInsets().left + 1, (getHeight() / 2) + 1, getWidth() - (getInsets().right + 1), (getHeight() / 2) + 1);

        g2d.setClip(origClip);
        g2d.setStroke(origStroke);
        g2d.setColor(origColor);
      }

    }
View Full Code Here

      this.basicStroke = basicStroke;
    }

    public void paintIcon(Component c, Graphics g, int x, int y)
    {
      Graphics2D g2d = (Graphics2D) g;
      Color origColor = g2d.getColor();
      Object hint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      Stroke origStroke = g2d.getStroke();

      g2d.translate(x, y);

      g2d.setColor(Color.BLACK);
      g2d.setStroke(basicStroke);

      g2d.drawLine(0, getIconHeight() / 2, getIconWidth(), getIconHeight() / 2);
      g2d.setColor(origColor);

      g2d.translate(-x, -y);
      g2d.setStroke(origStroke);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
    }
View Full Code Here

    final WaitingImageObserver obs = new WaitingImageObserver(source);
    obs.waitImageLoaded();

    final BufferedImage bImage = new BufferedImage((int) (width * scale), (int) (height * scale), BufferedImage.TYPE_INT_ARGB);

    final Graphics2D graph = bImage.createGraphics();
    graph.setTransform(AffineTransform.getScaleInstance(scale, scale));
    graph.drawImage(source, AffineTransform.getScaleInstance(scale, scale), null);
    graph.dispose();
    return bImage;
  }
View Full Code Here

     * @param angle
     */
    public static void drawAngledString(Graphics g, String text, int x, int y,
                                        double angle) {

        Graphics2D g2D = (Graphics2D) g;
        AffineTransform oldAt = g2D.getTransform();
        AffineTransform at = new AffineTransform(oldAt);
        at.rotate(angle, x, y);
        g2D.setTransform(at);
        g2D.drawString(text, x, y);
        g2D.setTransform(oldAt);
    }
View Full Code Here

     * settings
     *
     * @param g
     */
    protected void setGraphics(Graphics g) {
        Graphics2D g2D = (Graphics2D) g;
        saveStroke = g2D.getStroke();
        savePaint = g2D.getPaint();
        if (stroke != null)
            g2D.setStroke(stroke);
        if (paint != null)
            g2D.setPaint(paint);
    }
View Full Code Here

    if (scale < 1.0d) {
      tx.scale(scale, scale);
    }

    Color bgColor = null;
    Graphics2D g2d = outImage.createGraphics();
    g2d.setColor(bgColor);
    g2d.fillRect(0, 0, scaledW, scaledH);
    g2d.drawImage(inImage, tx, null);
    g2d.dispose();

    label.setIcon(new ImageIcon(outImage));
    label.setProperty("horizontalAlignment", new Integer(JLabel.CENTER));
    label.setProperty("opaque", Boolean.TRUE);
    return label;
View Full Code Here

     * ...
     *
     * @param g
     */
    protected void restoreGraphics(Graphics g) {
        Graphics2D g2D = (Graphics2D) g;
        g2D.setStroke(saveStroke);
        g2D.setPaint(savePaint);
    }
View Full Code Here

TOP

Related Classes of java.awt.Graphics2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.