Package java.awt

Examples of java.awt.Graphics2D


            throw new IOException("java.awt.Image fetch aborted or errored");
        }
        int w = pg.getWidth();
        int h = pg.getHeight();
        PdfTemplate tp = cb.createTemplate(w, h);
        Graphics2D g2d = tp.createGraphics(w, h, true, quality);
        g2d.drawImage(awtImage, 0, 0, null);
        g2d.dispose();
        return getInstance(tp);
    }
View Full Code Here


    BufferedImage old_img = (BufferedImage)ImageIO.read(new File(img_fn))
    int width = old_img.getWidth();
    int height = old_img.getHeight();
   
    BufferedImage new_img = new BufferedImage(height,width,BufferedImage.TYPE_INT_RGB);       
        Graphics2D g2d =new_img.createGraphics();
       
        AffineTransform origXform = g2d.getTransform();
        AffineTransform newXform = (AffineTransform)(origXform.clone());
        // center of rotation is center of the panel
        double xRot = 0;
        double yRot = 0;
    switch(orient){
    case 3:
      xRot = width/2.0;
      yRot = height/2.0;
    case 6:
          xRot = height/2.0;
          yRot = xRot;
      break;
    case 8:
          xRot = width/2.0;
          yRot = xRot;
          break;
        default:
          return false;
    }
        newXform.rotate(Math.toRadians(radian), xRot, yRot);

        g2d.setTransform(newXform);  
        // draw image centered in panel
        g2d.drawImage(old_img, 0, 0, null);
        // Reset to Original
        g2d.setTransform(origXform);

        FileOutputStream out = new FileOutputStream(dest_fn);
        try{
          ImageIO.write(new_img, "JPG", out);
        }finally{
View Full Code Here

        setPreferredSize(new Dimension(
                root.getMaxPageWidth(c, pagePaintingClearanceWidth),
                root.getLastPage().getPaintingBottom() + PAGE_PAINTING_CLEARANCE_HEIGHT));
        revalidate();

        Graphics2D g = ((Java2DOutputDevice)c.getOutputDevice()).getGraphics();
        Shape working = g.getClip();

        List pages = root.getPages();
        c.setPageCount(pages.size());
        for (int i = 0; i < pages.size(); i++) {
            PageBox page = (PageBox)pages.get(i);
            c.setPage(i, page);

            g.setClip(working);
           
            Rectangle overall = page.getScreenPaintingBounds(c, pagePaintingClearanceWidth);
            overall.x -= 1;
            overall.y -= 1;
            overall.width += 1;
            overall.height += 1;
           
            Rectangle bounds = new Rectangle(overall);
            bounds.width += 1;
            bounds.height += 1;
            if (working.intersects(bounds)) {
                page.paintBackground(c, pagePaintingClearanceWidth, Layer.PAGED_MODE_SCREEN);
                page.paintMarginAreas(c, pagePaintingClearanceWidth, Layer.PAGED_MODE_SCREEN);
                page.paintBorder(c, pagePaintingClearanceWidth, Layer.PAGED_MODE_SCREEN);
               
                Color old = g.getColor();
               
                g.setColor(Color.BLACK);
                g.drawRect(overall.x, overall.y, overall.width, overall.height);
                g.setColor(old);
               
                Rectangle content = page.getPagedViewClippingBounds(c, pagePaintingClearanceWidth);
                g.clip(content);
               
                int left = pagePaintingClearanceWidth +
                    page.getMarginBorderPadding(c, CalculatedStyle.LEFT);
                int top = page.getPaintingTop()
                    + page.getMarginBorderPadding(c, CalculatedStyle.TOP)
                    - page.getTop();
               
                g.translate(left, top);
                root.paint(c);
                g.translate(-left, -top);
               
                g.setClip(working);
            }
        }
       
        g.setClip(working);
    }
View Full Code Here

                renderer.getLineMetrics(fc.getGraphics(), awtFont, string));
    }
   
    public int getWidth(FontContext fontContext, FSFont font, String string) {
        Java2DFontContext fc = (Java2DFontContext)fontContext;
        Graphics2D graphics = fc.getGraphics();
        Font awtFont = ((AWTFSFont)font).getAWTFont();
        return (int)Math.ceil(renderer.getLogicalBounds(
                graphics, awtFont, string).getWidth());
    }
View Full Code Here

     * from the @see java.awt.print.Printable interface.
     */
    public int print(Graphics g, PageFormat pf, int page) {
        try {

            Graphics2D g2 = (Graphics2D) g;
           
            if (g2r == null) {
                g2r = new Graphics2DRenderer();
                g2r.getSharedContext().setPrint(true);
                g2r.getSharedContext().setInteractive(false);
View Full Code Here

        mGhostImage = new BufferedImage(lbl2.getWidth(), lbl2
            .getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);

        mTreeImage = new BufferedImage(this.getWidth(), this.getHeight(),
            BufferedImage.TYPE_INT_ARGB_PRE);
        Graphics2D g2t = mTreeImage.createGraphics();
        this.paint(g2t);
        g2t.dispose();

        // Get a graphics context for this image
        Graphics2D g2 = mGhostImage.createGraphics();

        // Ask the cell renderer to paint itself into the BufferedImage
        lbl2.paint(g2);

        // Use DST_OVER to cause under-painting to occur
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER,
            0.5f));

        Color c1 = new Color(UIManager.getDefaults().getColor(
            "Tree.selectionBackground").getRGB());
        c1 = c1.darker();

        g2.setPaint(new GradientPaint(0, 0, c1, getWidth(), 0, new Color(255,
            255, 255, 0)));

        // Paint under the JLabel's text
        g2.fillRect(0, 0, getWidth(), mGhostImage.getHeight());

        // Finished with the graphics context now
        g2.dispose();

        mCurrentPoint = e.getDragOrigin();

        e.startDrag(null, mGhostImage, new Point(15, 5),
            new TransferNode(), this);
View Full Code Here

              this.paintImmediately(mCueLine.getBounds());

              mCueLine.setRect(((PluginTree) ((DropTarget) e.getSource())
                  .getComponent()).getPathBounds(targetPath));

              Graphics2D g2 = (Graphics2D) getGraphics();
              Color c = new Color(255, 0, 0, 40);
              g2.setColor(c);
              g2.fill(mCueLine);
              mPlugin = temp;
            }
          } else {
            e.rejectDrag();
          }
        } catch (Exception e2) {
          e.rejectDrag();
        }

        if (reject && !rejected) {
          e.rejectDrag();
          this.paintImmediately(mCueLine.getBounds());
          mPlugin = null;
          rejected = true;
        }

        Point location = (Point) e.getLocation().clone();

        if (flavors[0].getHumanPresentableName().equals("NodeExport")
            && ((mCurrentPoint.x != location.x) || (mCurrentPoint.y != location.y))) {

          if (!DragSource.isDragImageSupported()) {
            Graphics2D g2 = (Graphics2D) getGraphics();

            Rectangle2D old = (Rectangle2D) mGhostRect.clone();

            // Remember where you are about to draw the new ghost image
            mGhostRect.setRect(location.x + 20, location.y, mGhostImage
                .getWidth(), mGhostImage.getHeight());

            Rectangle2D target = (Rectangle2D) old.clone();
            target.add(mGhostRect);

            BufferedImage bf = new BufferedImage((int) target.getWidth(),
                (int) target.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
            Graphics2D g2b = bf.createGraphics();

            int width = ((int) (mTreeImage.getWidth() - (target.getX() + target
                .getWidth()))) > 0 ? (int) target.getWidth()
                : (int) (mTreeImage.getWidth() - (target.getX()));
            int height = ((int) (mTreeImage.getHeight() - (target.getY() + target
                .getHeight()))) > 0 ? (int) target.getHeight()
                : (int) (mTreeImage.getHeight() - (target.getY()));

            if (width > 0 && height > 0) {
              g2b.drawImage(mTreeImage.getSubimage((int) target.getX(),
                  (int) target.getY(), width, height), 0, 0, null);
            }

            if (mCueLine.contains(location) && !reject) {
              Rectangle2D temp1 = mCueLine.createIntersection(target);
              double y = 0;

              if (changed) {
                y = mCueLine.getY() - target.getY();
                changed = false;
              }
              temp1.setRect(0, y, temp1.getWidth(), temp1.getHeight());

              Color c = new Color(255, 0, 0, 40);
              g2b.setColor(c);
              if (mCueLine.contains(mCueLine.createIntersection(target))) {
                g2b.fill(temp1);
              }
            }

            g2b.drawImage(mGhostImage, AffineTransform.getTranslateInstance(
                mGhostRect.getX() - target.getX(), mGhostRect.getY()
                    - target.getY()), null);
            g2b.dispose();

            g2.drawImage(bf, AffineTransform.getTranslateInstance(
                target.getX(), target.getY()), null);
          }
          mCurrentPoint = location;
View Full Code Here

        Document doc = XMLUtil.documentFromFile(xhtml);
        Graphics2DRenderer renderer = new Graphics2DRenderer();
        renderer.setDocument(doc, new File(xhtml).toURI().toURL().toString());

        BufferedImage buff = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
        Graphics2D g = (Graphics2D) buff.getGraphics();

        Dimension dim = new Dimension(width, height);
        renderer.layout(g, dim);
        renderer.render(g);
View Full Code Here

    return preferredSize;
  }

  public void draw(final Graphics2D g2, final Rectangle2D bounds)
  {
    final Graphics2D gr2 = (Graphics2D) g2.create();
    try
    {
      gr2.clip(bounds);
      barcode.draw(gr2, (int) bounds.getX(), (int) bounds.getY());
    }
    catch (OutputException e)
    {
      logger.error("Unable to draw barcode element", e);
    }
    finally
    {
      gr2.dispose();
    }

  }
View Full Code Here

    final float innerX = (float) pageFormat.getImageableX();
    final float innerY = (float) pageFormat.getImageableY();
    final float innerW = (float) pageFormat.getImageableWidth();
    final float innerH = (float) pageFormat.getImageableHeight();

    final Graphics2D g2 = (Graphics2D) graphics.create();
    //double paperBorder = paperBorderPixel * zoomFactor;

    /** Prepare background **/
    g2.transform(AffineTransform.getScaleInstance(getZoom(), getZoom()));
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

    /** Prepare background **/
    final Rectangle2D pageArea = new Rectangle2D.Float(0, 0, outerW, outerH);
    /**
     * The border around the printable area is painted when the corresponding property is
     * set to true.
     */
    final Rectangle2D printingArea = new Rectangle2D.Float(innerX, innerY, innerW, innerH);

    /** Paint Page Shadow */
    final Rectangle2D southborder = new Rectangle2D.Float
        (getShadowSize(), outerH,
            outerW, getShadowSize());
    final Rectangle2D eastborder = new Rectangle2D.Float
        (outerW, getShadowSize(), getShadowSize(), outerH);

    g2.setPaint(UIManager.getColor("controlShadow")); //$NON-NLS-1$

    g2.fill(southborder);
    g2.fill(eastborder);

    if (isBorderPainted())
    {
      g2.setPaint(Color.gray);
      g2.draw(printingArea);
    }

    g2.setPaint(Color.white);
    g2.fill(pageArea);

    final Graphics2D g22 = (Graphics2D) g2.create();
    backend.draw(g22, new Rectangle2D.Double
        (0, 0, pageFormat.getWidth(), pageFormat.getHeight()));
    g22.dispose();
   
    final Rectangle2D transPageArea = new Rectangle2D.Float(0, 0, outerW, outerH);
    g2.setPaint(Color.black);
    g2.draw(transPageArea);

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.