use of java.awt.print.Paper in project jgnash by ccavanaugh.
the class BaseDynamicJasperReport method assignPageFormat.
private void assignPageFormat(final DynamicReportBuilder builder) {
final PageFormat format = getPageFormat();
final Paper paper = format.getPaper();
final int orientation = format.getOrientation();
int topMargin;
int rightMargin;
int leftMargin;
int bottomMargin;
Page page;
if (orientation == PageFormat.PORTRAIT) {
page = new Page((int) paper.getHeight(), (int) paper.getWidth(), true);
leftMargin = (int) paper.getImageableX();
rightMargin = (int) paper.getWidth() - (int) paper.getImageableWidth() - leftMargin;
topMargin = (int) paper.getImageableY();
bottomMargin = (int) paper.getHeight() - (int) paper.getImageableHeight() - topMargin;
} else {
page = new Page((int) paper.getWidth(), (int) paper.getHeight(), false);
rightMargin = (int) paper.getImageableY();
leftMargin = (int) paper.getHeight() - (int) paper.getImageableHeight() - rightMargin;
topMargin = (int) paper.getImageableX();
bottomMargin = (int) paper.getWidth() - (int) paper.getImageableWidth() - topMargin;
}
builder.setPageSizeAndOrientation(page);
builder.setMargins(topMargin, bottomMargin, leftMargin, rightMargin);
}
use of java.awt.print.Paper in project jgnash by ccavanaugh.
the class PrintableCheckLayout method getPageFormat.
public PageFormat getPageFormat() {
PrintRequestAttributeSet printAttributes = checkLayout.getPrintAttributes();
if (pageFormat == null) {
// create a default pageFormat
PageFormat format = getPrinterJob().defaultPage();
Paper paper = format.getPaper();
MediaSizeName media = (MediaSizeName) printAttributes.get(Media.class);
MediaSize ms = MediaSize.getMediaSizeForName(media);
MediaPrintableArea ma = (MediaPrintableArea) printAttributes.get(MediaPrintableArea.class);
if (ma != null) {
int INCH = MediaPrintableArea.INCH;
paper.setImageableArea((ma.getX(INCH) * 72), (ma.getY(INCH) * 72), (ma.getWidth(INCH) * 72), (ma.getHeight(INCH) * 72));
}
if (ms != null) {
paper.setSize((ms.getX(Size2DSyntax.INCH) * 72), (ms.getY(Size2DSyntax.INCH) * 72));
}
format.setPaper(paper);
OrientationRequested or = (OrientationRequested) printAttributes.get(OrientationRequested.class);
if (or != null) {
if (or == OrientationRequested.LANDSCAPE) {
format.setOrientation(PageFormat.LANDSCAPE);
} else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
format.setOrientation(PageFormat.REVERSE_LANDSCAPE);
} else if (or == OrientationRequested.PORTRAIT) {
format.setOrientation(PageFormat.PORTRAIT);
} else if (or == OrientationRequested.REVERSE_PORTRAIT) {
format.setOrientation(PageFormat.PORTRAIT);
}
}
pageFormat = format;
}
return pageFormat;
}
use of java.awt.print.Paper in project groovy-core by groovy.
the class TextEditor method print.
public int print(Graphics graphics, PageFormat pageFormat, int page) throws PrinterException {
if (page < numPages) {
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;
}
use of java.awt.print.Paper in project groovy by apache.
the class TextEditor method print.
public int print(Graphics graphics, PageFormat pageFormat, int page) throws PrinterException {
if (page < numPages) {
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;
}
use of java.awt.print.Paper in project groovy by apache.
the class TextEditor method getNumberOfPages.
public int getNumberOfPages() {
Paper paper = PAGE_FORMAT.getPaper();
numPages = (int) Math.ceil(getSize().getHeight() / paper.getImageableHeight());
return numPages;
}
Aggregations