Package java.awt.print

Examples of java.awt.print.Paper


   
    public int print(Graphics graphics, PageFormat pageFormat, int page)
        throws PrinterException {
        if (page < numPages) {
            StyledDocument doc = (StyledDocument)getDocument();
            Paper paper = pageFormat.getPaper();

            // initialize the PRINT_PANE (need this so that wrapping
            // can take place)
            PRINT_PANE.setDocument(getDocument());

            PRINT_PANE.setFont(getFont());
            PRINT_SIZE.setSize(paper.getImageableWidth(),
                               getSize().getHeight());
            PRINT_PANE.setSize(PRINT_SIZE);

            // translate the graphics origin upwards so the area of the page we
            // want to print is in the origin; the clipping region auto set
            // will take care of the rest
            double y = -(page * paper.getImageableHeight()) + paper.getImageableY();
           
            ((Graphics2D)graphics).translate(paper.getImageableX(), y);
           
            // print the text with its own routines
            PRINT_PANE.print(graphics);
           
            // translate the graphics object back to reality in the y dimension
            // so we can print a page number
            ((Graphics2D)graphics).translate(0, -y);
            Rectangle rect = graphics.getClipBounds();
            graphics.setClip(rect.x, 0, rect.width, (int)paper.getHeight() + 100);
           
            // get the name of the pane (or user name) and the time for the header
            Calendar cal = Calendar.getInstance();
            String header = cal.getTime().toString().trim();
            String name = getName() == null ?
                System.getProperty("user.name").trim() : getName().trim();
            String pageStr = String.valueOf(page + 1);
           
            Font font = Font.decode("Monospaced 8");
            graphics.setFont(font);
            FontMetrics fm = graphics.getFontMetrics(font);
            int width = SwingUtilities.computeStringWidth(fm, header);
            ((Graphics2D)graphics).drawString(header,
                                              (float)(paper.getImageableWidth()/2 - width/2),
                                              (float)paper.getImageableY()/2 + fm.getHeight());
           
            ((Graphics2D)graphics).translate(0, paper.getImageableY() - fm.getHeight());
            double height = paper.getImageableHeight() + paper.getImageableY()/2;
            width = SwingUtilities.computeStringWidth(fm, name);
            ((Graphics2D)graphics).drawString(name,
                                              (float)(paper.getImageableWidth()/2 - width/2),
                                              (float)height - fm.getHeight()/2);
           
            ((Graphics2D)graphics).translate(0, fm.getHeight());
            width = SwingUtilities.computeStringWidth(fm, pageStr);
            ((Graphics2D)graphics).drawString(pageStr,
                                              (float)(paper.getImageableWidth()/2 - width/2),
                                              (float)height - fm.getHeight()/2);

            return Printable.PAGE_EXISTS;
        }
        return Printable.NO_SUCH_PAGE;
View Full Code Here


    public void printWorkingPage(){
        UIutils.processGUIActions();

        // Set the working page to be the size of the paper
        PrintOptionsDesc options = getPrintOptions();
        Paper paper = options.getPaper();

        int topMargin = TopMargin.get(workingPage);
        int leftMargin = LeftMargin.get(workingPage);
        int bottomMargin = BottomMargin.get(workingPage);
        int rightMargin = RightMargin.get(workingPage);

        // CraigM:06/06/2008 - The paper.getImageable values seem to be way too big.  I'm guessing with my defaultMargin value.
//      double x = (leftMargin != 0) ? PrintUtilities.milsToPoints(leftMargin) : paper.getImageableX();
//      double y = (topMargin != 0) ? PrintUtilities.milsToPoints(topMargin) : paper.getImageableY();
//      double width = (rightMargin != 0) ? options.getWidth() - PrintUtilities.milsToPoints(rightMargin) - x : paper.getImageableWidth();
//      double height = (bottomMargin != 0) ? options.getHeight() - PrintUtilities.milsToPoints(bottomMargin) - y : paper.getImageableHeight();
        double defaultMargin = 35;
        double x = (leftMargin != 0) ? PrintUtilities.milsToPoints(leftMargin) : defaultMargin;
        double y = (topMargin != 0) ? PrintUtilities.milsToPoints(topMargin) : defaultMargin;
        double width = (rightMargin != 0) ? options.getWidth() - PrintUtilities.milsToPoints(rightMargin) - x : options.getWidth() - (defaultMargin*2);
        double height = (bottomMargin != 0) ? options.getHeight() - PrintUtilities.milsToPoints(bottomMargin) - y : options.getHeight() - (defaultMargin*2);

        // If we are in landscape mode, then we need to swap the width and height around.
        if (options.getOrientation() == PageFormat.LANDSCAPE) {
          double tmpWidth = width;
          width = height;
          height = tmpWidth;
        }

        // CraigM:30/05/2008 - The working page is now scaled in the BookComponentPrintable so we shouldn't set the size
        // workingPage.setSize((int)width, (int)height);
       
        paper.setImageableArea(x, y, width, height);
        options.setPaper(paper);

        this.append(new BookComponentPrintable(workingPage), getPrintOptions());
    }
View Full Code Here

        if (defaultPrintOptions == null) {
          defaultPrintOptions = new PrintOptionsDesc();
        }
        PrinterJob pjob = PrinterJob.getPrinterJob();
        PageFormat defaultPage = pjob.defaultPage();
        Paper paper = new Paper();
        double imagableWidth = defaultPage.getPaper().getWidth() - (defaultPrintMargin * 2);
        double imagableHeight = defaultPage.getPaper().getHeight() - (defaultPrintMargin * 2);
       
        // Swap the width and height if in landscape mode
        if (defaultPrintOptions.getForteOrientation() == Constants.PO_LANDSCAPE) {
          double tmpWidth = imagableWidth;
          imagableWidth = imagableHeight;
          imagableHeight = tmpWidth;
        }
       
        paper.setSize(defaultPage.getPaper().getWidth(), defaultPage.getPaper().getHeight());
        paper.setImageableArea(defaultPrintMargin, defaultPrintMargin, imagableWidth, imagableHeight);
        defaultPrintOptions.setPaper(paper);
        return defaultPrintOptions;
    }
View Full Code Here

    PrinterJob printJob = PrinterJob.getPrinterJob();
    PrintService printService = getPrintService(property.getService());

    PageFormat format = new PageFormat();
    format.setOrientation(PageFormat.PORTRAIT);
    Paper paper = format.getPaper();
    paper.setImageableArea(0, 0, panel.getWidth(), panel.getHeight());
    format.setPaper(paper);

    printJob.setPrintable(new Printer(panel), format);

    int printCount = (int) JSpinnerAdet.getValue() / property.getSutun();
View Full Code Here

            printerJob.defaultPage();

        //
        // Set the page parameters from the hints
        //
        Paper paper = pageFormat.getPaper();

        Float pageWidth = (Float)hints.get(KEY_PAGE_WIDTH);
        Float pageHeight = (Float)hints.get(KEY_PAGE_HEIGHT);
        if(pageWidth != null){
            paper.setSize(pageWidth.floatValue(),
                          paper.getHeight());
        }
        if(pageHeight != null){
            paper.setSize(paper.getWidth(),
                          pageHeight.floatValue());
        }

        float x=0, y=0;
        float width=(float)paper.getWidth(), height=(float)paper.getHeight();

        Float leftMargin = (Float)hints.get(KEY_MARGIN_LEFT);
        Float topMargin = (Float)hints.get(KEY_MARGIN_TOP);
        Float rightMargin = (Float)hints.get(KEY_MARGIN_RIGHT);
        Float bottomMargin = (Float)hints.get(KEY_MARGIN_BOTTOM);

        if(leftMargin != null){
            x = leftMargin.floatValue();
            width -= leftMargin.floatValue();
        }
        if(topMargin != null){
            y = topMargin.floatValue();
            height -= topMargin.floatValue();
        }
        if(rightMargin != null){
            width -= rightMargin.floatValue();
        }
        if(bottomMargin != null){
            height -= bottomMargin.floatValue();
        }

        paper.setImageableArea(x, y, width, height);

        String pageOrientation = (String)hints.get(KEY_PAGE_ORIENTATION);
        if(VALUE_PAGE_ORIENTATION_PORTRAIT.equalsIgnoreCase(pageOrientation)){
            pageFormat.setOrientation(pageFormat.PORTRAIT);
        }
View Full Code Here

        PageFormat pageFormat = printerJob.defaultPage();

        //
        // Set the page parameters from the hints
        //
        Paper paper = pageFormat.getPaper();

        Float pageWidth = (Float)hints.get(KEY_PAGE_WIDTH);
        Float pageHeight = (Float)hints.get(KEY_PAGE_HEIGHT);
        if(pageWidth != null){
            paper.setSize(pageWidth.floatValue(),
                          paper.getHeight());
        }
        if(pageHeight != null){
            paper.setSize(paper.getWidth(),
                          pageHeight.floatValue());
        }

        float x=0, y=0;
        float width =(float)paper.getWidth();
        float height=(float)paper.getHeight();

        Float leftMargin   = (Float)hints.get(KEY_MARGIN_LEFT);
        Float topMargin    = (Float)hints.get(KEY_MARGIN_TOP);
        Float rightMargin  = (Float)hints.get(KEY_MARGIN_RIGHT);
        Float bottomMargin = (Float)hints.get(KEY_MARGIN_BOTTOM);

        if(leftMargin != null){
            x      = leftMargin.floatValue();
            width -= leftMargin.floatValue();
        }
        if(topMargin != null){
            y       = topMargin.floatValue();
            height -= topMargin.floatValue();
        }
        if(rightMargin != null){
            width -= rightMargin.floatValue();
        }
        if(bottomMargin != null){
            height -= bottomMargin.floatValue();
        }

        paper.setImageableArea(x, y, width, height);

        String pageOrientation = (String)hints.get(KEY_PAGE_ORIENTATION);
        if(VALUE_PAGE_ORIENTATION_PORTRAIT.equalsIgnoreCase(pageOrientation)){
            pageFormat.setOrientation(PageFormat.PORTRAIT);
        }
View Full Code Here

            printerJob.defaultPage();

        //
        // Set the page parameters from the hints
        //
        Paper paper = pageFormat.getPaper();

        Float pageWidth = (Float)hints.get(KEY_PAGE_WIDTH);
        Float pageHeight = (Float)hints.get(KEY_PAGE_HEIGHT);
        if(pageWidth != null){
            paper.setSize(pageWidth.floatValue(),
                          paper.getHeight());
        }
        if(pageHeight != null){
            paper.setSize(paper.getWidth(),
                          pageHeight.floatValue());
        }

        float x=0, y=0;
        float width=(float)paper.getWidth(), height=(float)paper.getHeight();

        Float leftMargin = (Float)hints.get(KEY_MARGIN_LEFT);
        Float topMargin = (Float)hints.get(KEY_MARGIN_TOP);
        Float rightMargin = (Float)hints.get(KEY_MARGIN_RIGHT);
        Float bottomMargin = (Float)hints.get(KEY_MARGIN_BOTTOM);

        if(leftMargin != null){
            x = leftMargin.floatValue();
            width -= leftMargin.floatValue();
        }
        if(topMargin != null){
            y = topMargin.floatValue();
            height -= topMargin.floatValue();
        }
        if(rightMargin != null){
            width -= rightMargin.floatValue();
        }
        if(bottomMargin != null){
            height -= bottomMargin.floatValue();
        }

        paper.setImageableArea(x, y, width, height);

        String pageOrientation = (String)hints.get(KEY_PAGE_ORIENTATION);
        if(VALUE_PAGE_ORIENTATION_PORTRAIT.equalsIgnoreCase(pageOrientation)){
            pageFormat.setOrientation(PageFormat.PORTRAIT);
        }
View Full Code Here

                return null;
            }
   
            PageFormat pageFormat = new PageFormat();
   
            Paper paper = new Paper();
   
            Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
            double width = dim.getWidth();
            double height = dim.getHeight();
   
            // if the width is greater than the height assume lanscape mode
            // and swap the width and height values in the paper format
            if (width > height) {
                paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
                paper.setSize(height / 1000d, width / 1000d);
                pageFormat.setOrientation(PageFormat.LANDSCAPE);
            } else {
                paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
                paper.setSize(width / 1000d, height / 1000d);
                pageFormat.setOrientation(PageFormat.PORTRAIT);
            }
            pageFormat.setPaper(paper);
            return pageFormat;
        } catch (FOPException fopEx) {
View Full Code Here

                return null;
            }
   
            PageFormat pageFormat = new PageFormat();
   
            Paper paper = new Paper();
   
            Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
            double width = dim.getWidth();
            double height = dim.getHeight();
   
            // if the width is greater than the height assume lanscape mode
            // and swap the width and height values in the paper format
            if (width > height) {
                paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
                paper.setSize(height / 1000d, width / 1000d);
                pageFormat.setOrientation(PageFormat.LANDSCAPE);
            } else {
                paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
                paper.setSize(width / 1000d, height / 1000d);
                pageFormat.setOrientation(PageFormat.PORTRAIT);
            }
            pageFormat.setPaper(paper);
            return pageFormat;
        } catch (FOPException fopEx) {
View Full Code Here

    final double marginBottom = CSSValueResolverUtility.convertLengthToDouble
        (rule.getPropertyCSSValue(BoxStyleKeys.MARGIN_BOTTOM));

    if (width < height)
    {
      final Paper p = new Paper();
      p.setSize(width, height);
      p.setImageableArea(marginLeft, marginRight,
          width - marginLeft - marginRight,
          height - marginTop - marginBottom);
      final PageFormat pageFormat = new PageFormat();
      pageFormat.setPaper(p);
      pageFormat.setOrientation(PageFormat.PORTRAIT);
      return pageFormat;
    }
    else
    {
      final Paper p = new Paper();
      p.setSize(height, width);
      p.setImageableArea(marginLeft, marginRight,
          width - marginLeft - marginRight,
          height - marginTop - marginBottom);
      final PageFormat pageFormat = new PageFormat();
      pageFormat.setPaper(p);
      pageFormat.setOrientation(PageFormat.LANDSCAPE);
View Full Code Here

TOP

Related Classes of java.awt.print.Paper

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.