當前位置: 首頁>>代碼示例>>Java>>正文


Java Paper.getWidth方法代碼示例

本文整理匯總了Java中java.awt.print.Paper.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java Paper.getWidth方法的具體用法?Java Paper.getWidth怎麽用?Java Paper.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.print.Paper的用法示例。


在下文中一共展示了Paper.getWidth方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateController

import java.awt.print.Paper; //導入方法依賴的package包/類
/**
 * Updates controller print attributes.
 */
public void updateController(PageSetupController controller)
{
	// Return an HomePrint instance matching returnedPageFormat
	HomePrint.PaperOrientation paperOrientation;
	switch (this.pageFormat.getOrientation())
	{
		case PageFormat.LANDSCAPE:
			paperOrientation = HomePrint.PaperOrientation.LANDSCAPE;
			break;
		case PageFormat.REVERSE_LANDSCAPE:
			paperOrientation = HomePrint.PaperOrientation.REVERSE_LANDSCAPE;
			break;
		default:
			paperOrientation = HomePrint.PaperOrientation.PORTRAIT;
			break;
	}
	Paper paper = this.pageFormat.getPaper();
	HomePrint homePrint = new HomePrint(paperOrientation, (float) paper.getWidth(), (float) paper.getHeight(),
			(float) paper.getImageableY(), (float) paper.getImageableX(),
			(float) (paper.getHeight() - paper.getImageableHeight() - paper.getImageableY()),
			(float) (paper.getWidth() - paper.getImageableWidth() - paper.getImageableX()),
			this.furniturePrintedCheckBox.isSelected(), this.planPrintedCheckBox.isSelected(),
			this.view3DPrintedCheckBox.isSelected(),
			this.userPlanScaleRadioButton.isSelected() && this.userPlanScaleSpinner.getValue() != null
					? 1f / ((Number) this.userPlanScaleSpinner.getValue()).intValue() : null,
			this.headerFormatTextField.getText().trim(), this.footerFormatTextField.getText().trim());
	controller.setPrint(homePrint);
}
 
開發者ID:valsr,項目名稱:SweetHome3D,代碼行數:32,代碼來源:PageSetupPanel.java

示例2: getPageFormatAsString

import java.awt.print.Paper; //導入方法依賴的package包/類
/**
 * @param pPageFormat
 * @return
 */
public static String getPageFormatAsString(Paper pPaper) {
	return pPaper.getWidth() + ";" + pPaper.getHeight() + ";"
			+ pPaper.getImageableX() + ";" + pPaper.getImageableY() + ";"
			+ pPaper.getImageableWidth() + ";"
			+ pPaper.getImageableHeight();
}
 
開發者ID:iwabuchiken,項目名稱:freemind_1.0.0_20140624_214725,代碼行數:11,代碼來源:Tools.java

示例3: validatePaper

import java.awt.print.Paper; //導入方法依賴的package包/類
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:50,代碼來源:RasterPrinterJob.java

示例4: getPhysicalPageWidth

import java.awt.print.Paper; //導入方法依賴的package包/類
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:4,代碼來源:PSPrinterJob.java

示例5: print

import java.awt.print.Paper; //導入方法依賴的package包/類
public int print(Graphics g, PageFormat pf, int page)
    throws PrinterException {

    if (page > 0) {
        return NO_SUCH_PAGE;
    }
    int ix = (int)pf.getImageableX();
    int iy = (int)pf.getImageableY();
    int iw = (int)pf.getImageableWidth();
    int ih = (int)pf.getImageableHeight();
    System.out.println("ix="+ix+" iy="+iy+" iw="+iw+" ih="+ih);
    if ((ix < 0) || (iy < 0)) {
        throw new RuntimeException("Imageable x or y is a negative value.");
    }


    Paper paper = pf.getPaper();
    int wid = (int)paper.getWidth();
    int hgt = (int)paper.getHeight();
    System.out.println("wid="+wid+" hgt="+hgt);
    /*
     * If imageable width/height is -ve, then print was done with 1" margin
     * e.g. ix=72 iy=72 iw=451 ih=697 and paper wid=595
     * but with fix, we get print with hardware margin e.g.
     * ix=12, iy=12, iw=571, ih=817
     */
    if ((wid - iw > 72) || (hgt - ih > 72)) {
        throw new RuntimeException("Imageable width or height is negative value");
    }
    if ((ix+iw > wid) || (iy+ih > hgt)) {
        throw new RuntimeException("Printable width or height "
                + "exceeds paper width or height.");
    }
    // runtime checking to see if the margins/printable area
    // correspond to the entire size of the paper, for now, make it pass
    // as for linux, the hwmargin is not taken into account - bug6574279
    if (ix == 0 && iy == 0 && (ix+iw == wid) && (iy+ih == hgt)) {
        return PAGE_EXISTS;
    }

    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(ix, iy);
    g2d.setColor(Color.black);
    g2d.drawRect(1, 1, iw-2, ih-2);

    return PAGE_EXISTS;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:48,代碼來源:Margins.java

示例6: saveAsPDF

import java.awt.print.Paper; //導入方法依賴的package包/類
/**
 * @param file The file to save to.
 * @return <code>true</code> on success.
 */
public boolean saveAsPDF(File file) {
    HashSet<Row> changed = expandAllContainers();
    try {
        PrintManager settings = mCharacter.getPageSettings();
        PageFormat format = settings != null ? settings.createPageFormat() : createDefaultPageFormat();
        Paper paper = format.getPaper();
        float width = (float) paper.getWidth();
        float height = (float) paper.getHeight();

        adjustToPageSetupChanges(true);
        setPrinting(true);

        com.lowagie.text.Document pdfDoc = new com.lowagie.text.Document(new com.lowagie.text.Rectangle(width, height));
        try (FileOutputStream out = new FileOutputStream(file)) {
            PdfWriter writer = PdfWriter.getInstance(pdfDoc, out);
            int pageNum = 0;
            PdfContentByte cb;

            pdfDoc.open();
            cb = writer.getDirectContent();
            while (true) {
                PdfTemplate template = cb.createTemplate(width, height);
                Graphics2D g2d = template.createGraphics(width, height, new DefaultFontMapper());

                if (print(g2d, format, pageNum) == NO_SUCH_PAGE) {
                    g2d.dispose();
                    break;
                }
                if (pageNum != 0) {
                    pdfDoc.newPage();
                }
                g2d.setClip(0, 0, (int) width, (int) height);
                print(g2d, format, pageNum++);
                g2d.dispose();
                cb.addTemplate(template, 0, 0);
            }
            pdfDoc.close();
        }
        return true;
    } catch (Exception exception) {
        return false;
    } finally {
        setPrinting(false);
        closeContainers(changed);
    }
}
 
開發者ID:richardwilkes,項目名稱:gcs,代碼行數:51,代碼來源:CharacterSheet.java

示例7: saveAsPNG

import java.awt.print.Paper; //導入方法依賴的package包/類
/**
 * @param file The file to save to.
 * @param createdFiles The files that were created.
 * @return <code>true</code> on success.
 */
public boolean saveAsPNG(File file, ArrayList<File> createdFiles) {
    HashSet<Row> changed = expandAllContainers();
    try {
        int dpi = OutputPreferences.getPNGResolution();
        PrintManager settings = mCharacter.getPageSettings();
        PageFormat format = settings != null ? settings.createPageFormat() : createDefaultPageFormat();
        Paper paper = format.getPaper();
        int width = (int) (paper.getWidth() / 72.0 * dpi);
        int height = (int) (paper.getHeight() / 72.0 * dpi);
        StdImage buffer = StdImage.create(width, height, Transparency.OPAQUE);
        int pageNum = 0;
        String name = PathUtils.getLeafName(file.getName(), false);

        file = file.getParentFile();

        adjustToPageSetupChanges(true);
        setPrinting(true);

        while (true) {
            File pngFile;

            Graphics2D gc = buffer.getGraphics();
            if (print(gc, format, pageNum) == NO_SUCH_PAGE) {
                gc.dispose();
                break;
            }
            gc.setClip(0, 0, width, height);
            gc.setBackground(Color.WHITE);
            gc.clearRect(0, 0, width, height);
            gc.scale(dpi / 72.0, dpi / 72.0);
            print(gc, format, pageNum++);
            gc.dispose();
            pngFile = new File(file, PathUtils.enforceExtension(name + (pageNum > 1 ? " " + pageNum : ""), FileType.PNG_EXTENSION)); //$NON-NLS-1$ //$NON-NLS-2$
            if (!StdImage.writePNG(pngFile, buffer, dpi)) {
                throw new IOException();
            }
            createdFiles.add(pngFile);
        }
        return true;
    } catch (Exception exception) {
        return false;
    } finally {
        setPrinting(false);
        closeContainers(changed);
    }
}
 
開發者ID:richardwilkes,項目名稱:gcs,代碼行數:52,代碼來源:CharacterSheet.java

示例8: spoolPage

import java.awt.print.Paper; //導入方法依賴的package包/類
/**
 * Spools a single page, returns NO_SUCH_PAGE unsuccessful,
 * PAGE_EXISTS if it was.
 */
public int spoolPage(PrintWriter out,
                     Printable printable,
                     PageFormat pageFormat,
                     int index) throws IOException, PrinterException
{
  out.println("%%BeginPageSetup");

  Paper p = pageFormat.getPaper();
  pageX = p.getWidth();
  pageY = p.getHeight();

  if( pageFormat.getOrientation() == PageFormat.PORTRAIT )
    out.println( "%%Orientation: Portrait" );
  else
    {
      out.println( "%%Orientation: Landscape" );
      double t = pageX;
      pageX = pageY;
      pageY = t;
    }

  setClip(0, 0, (int)pageX, (int)pageY);

  out.println("gsave % first save");

  // 595x842; 612x792 respectively
  out.println("<< /PageSize [" +pageX + " "+pageY+ "] >> setpagedevice");

  if( pageFormat.getOrientation() != PageFormat.LANDSCAPE )
    {
      pageTransform.translate(pageX, 0);
      pageTransform.scale(-1.0, 1.0);
    }

  // save the original CTM
  pushCTM();
  concatCTM(pageTransform);
  setTransform(new AffineTransform());

  out.println("%%EndPageSetup");

  out.println("gsave");

  if( printable.print(this, pageFormat, index) == Printable.NO_SUCH_PAGE )
    return Printable.NO_SUCH_PAGE;

  out.println("grestore");
  out.println("showpage");

  return Printable.PAGE_EXISTS;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:56,代碼來源:PostScriptGraphics2D.java

示例9: writePage

import java.awt.print.Paper; //導入方法依賴的package包/類
private void writePage(PrintWriter out, PageFormat pageFormat)
{
  out.println("%%BeginPageSetup");

  Paper p = pageFormat.getPaper();
  double pWidth = p.getWidth();
  double pHeight = p.getHeight();

  if( pageFormat.getOrientation() == PageFormat.PORTRAIT )
    out.println( "%%Orientation: Portrait" );
  else
    {
      out.println( "%%Orientation: Landscape" );
      double t = pWidth;
      pWidth = pHeight;
      pHeight = t;
    }

  out.println("gsave % first save");

  // 595x842; 612x792 respectively
  out.println("<< /PageSize [" +pWidth + " "+pHeight+ "] >> setpagedevice");

  // invert the Y axis so that we get screen-like coordinates instead.
  AffineTransform pageTransform = new AffineTransform();
  if( pageFormat.getOrientation() == PageFormat.REVERSE_LANDSCAPE )
    {
      pageTransform.translate(pWidth, pHeight);
      pageTransform.scale(-1.0, -1.0);
    }
  concatCTM(out, pageTransform);
  out.println("%%EndPageSetup");

  out.println("gsave");


  // Draw the image
  out.println(xSize+" "+ySize+" 8 [1 0 0 -1 0 "+ySize+" ]");
  out.println("{currentfile 3 string readhexstring pop} bind");
  out.println("false 3 colorimage");
  int[] pixels = new int[xSize * ySize];
  PixelGrabber pg = new PixelGrabber(image, 0, 0, xSize, ySize, pixels, 0, xSize);

  try {
    pg.grabPixels();
  } catch (InterruptedException e) {
    out.println("% Bug getting pixels!");
  }

  int n = 0;
  for (int j = 0; j < ySize; j++) {
    for (int i = 0; i < xSize; i++) {
      out.print( colorTripleHex(pixels[j * xSize + i]) );
      if(((++n)%11) == 0) out.println();
    }
  }

  out.println();
  out.println("%%EOF");
  out.println("grestore");
  out.println("showpage");
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:63,代碼來源:JavaPrinterGraphics.java

示例10: spoolPage

import java.awt.print.Paper; //導入方法依賴的package包/類
/**
  * Spools a single page, returns NO_SUCH_PAGE unsuccessful,
  * PAGE_EXISTS if it was.
  */
 public int spoolPage(PrintWriter out,
	       Printable printable, 
	       PageFormat pageFormat, 
	       int index) throws IOException, PrinterException
 {
   out.println("%%BeginPageSetup");

   Paper p = pageFormat.getPaper();
   pageX = p.getWidth();
   pageY = p.getHeight();

   if( pageFormat.getOrientation() == PageFormat.PORTRAIT )
     out.println( "%%Orientation: Portrait" );
   else
     {
out.println( "%%Orientation: Landscape" );
double t = pageX;
pageX = pageY;
pageY = t;
     }
     
   setClip(0, 0, (int)pageX, (int)pageY);

   out.println("gsave % first save");
   
   // 595x842; 612x792 respectively
   out.println("<< /PageSize [" +pageX + " "+pageY+ "] >> setpagedevice");

   if( pageFormat.getOrientation() != PageFormat.LANDSCAPE )
     {
pageTransform.translate(pageX, 0);
pageTransform.scale(-1.0, 1.0);
     }

   // save the original CTM
   pushCTM();
   concatCTM(pageTransform);
   setTransform(new AffineTransform());

   out.println("%%EndPageSetup");

   out.println("gsave");

   if( printable.print(this, pageFormat, index) == Printable.NO_SUCH_PAGE )
     return Printable.NO_SUCH_PAGE;
   
   out.println("grestore");
   out.println("showpage");

   return Printable.PAGE_EXISTS;
 }
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:56,代碼來源:PostScriptGraphics2D.java

示例11: writePage

import java.awt.print.Paper; //導入方法依賴的package包/類
private void writePage(PrintWriter out, PageFormat pageFormat)
 {
   out.println("%%BeginPageSetup");

   Paper p = pageFormat.getPaper();
   double pWidth = p.getWidth();
   double pHeight = p.getHeight();

   if( pageFormat.getOrientation() == PageFormat.PORTRAIT )
     out.println( "%%Orientation: Portrait" );
   else
     {
out.println( "%%Orientation: Landscape" );
double t = pWidth;
pWidth = pHeight;
pHeight = t;
     }
     
   out.println("gsave % first save");
   
   // 595x842; 612x792 respectively
   out.println("<< /PageSize [" +pWidth + " "+pHeight+ "] >> setpagedevice");

   // invert the Y axis so that we get screen-like coordinates instead.
   AffineTransform pageTransform = new AffineTransform();
   if( pageFormat.getOrientation() == PageFormat.REVERSE_LANDSCAPE )
     {
pageTransform.translate(pWidth, pHeight);
pageTransform.scale(-1.0, -1.0);
     }
   concatCTM(out, pageTransform);
   out.println("%%EndPageSetup");

   out.println("gsave");


   // Draw the image
   out.println(xSize+" "+ySize+" 8 [1 0 0 -1 0 "+ySize+" ]"); 
   out.println("{currentfile 3 string readhexstring pop} bind");
   out.println("false 3 colorimage");
   int[] pixels = new int[xSize * ySize];
   PixelGrabber pg = new PixelGrabber(image, 0, 0, xSize, ySize, pixels, 0, xSize);

   try {
     pg.grabPixels();
   } catch (InterruptedException e) {
     out.println("% Bug getting pixels!");
   }

   int n = 0;
   for (int j = 0; j < ySize; j++) {
     for (int i = 0; i < xSize; i++) {
out.print( colorTripleHex(pixels[j * xSize + i]) );
if(((++n)%11) == 0) out.println();
     }
   }
   
   out.println();
   out.println("%%EOF");
   out.println("grestore");
   out.println("showpage");
 }
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:63,代碼來源:JavaPrinterGraphics.java

示例12: getPageFormat

import java.awt.print.Paper; //導入方法依賴的package包/類
private PageFormat getPageFormat(final AttributeSet... attrSets) {
    final Paper paper = new Paper();
    final PageFormat format = new PageFormat();
    final DevmodeStructWrapper dm = service.getPrinterProps();
    final OrientationRequested o = dm.getOrientation();
    final MediaPrintableArea area = getAttribute(
                    MediaPrintableArea.class, attrSets);
    DevmodeStructWrapper.Paper p = dm.getPaper();

    if (p == null) {
        p = (DevmodeStructWrapper.Paper) service
                        .getDefaultAttributeValue(DevmodeStructWrapper.Paper.class);
        dm.setPaper(p);
    }

    paper.setSize(p.getSize().getX(Size2DSyntax.INCH) * 72.0, p
                    .getSize().getY(Size2DSyntax.INCH) * 72.0);
    format.setPaper(paper);

    if (OrientationRequested.LANDSCAPE.equals(o)
                    || OrientationRequested.REVERSE_LANDSCAPE.equals(o)) {
        format.setOrientation(PageFormat.LANDSCAPE);
    } else {
        format.setOrientation(PageFormat.PORTRAIT);
    }

    if (area != null) {
        paper.setImageableArea(area.getX(MediaPrintableArea.INCH) * 72,
                        area.getY(MediaPrintableArea.INCH) * 72,
                        area.getWidth(MediaPrintableArea.INCH) * 72,
                        area.getHeight(MediaPrintableArea.INCH) * 72);
    } else {
        final double x = paper.getWidth() / 10;
        final double y = paper.getHeight() / 10;

        paper.setImageableArea(x, y, (paper.getWidth() - 2 * x), (paper
                        .getHeight() - 2 * y));
    }

    return format;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:42,代碼來源:WinPrintJob.java


注:本文中的java.awt.print.Paper.getWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。