use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.
the class JaretTablePrintDialog method createParameterArea.
protected void createParameterArea(Composite parent) {
GridLayout gl = new GridLayout();
gl.numColumns = 2;
parent.setLayout(gl);
_repeatHeader = new Button(parent, SWT.CHECK);
_repeatHeader.setSelection(_configuration.getRepeatHeader());
_repeatHeader.setText("Repeat header");
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
_repeatHeader.setLayoutData(gd);
final Label scaleText = new Label(parent, SWT.RIGHT);
scaleText.setText(getScaleText());
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
scaleText.setLayoutData(gd);
final Scale scale = new Scale(parent, SWT.HORIZONTAL);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
scale.setLayoutData(gd);
scale.setMaximum(1000);
scale.setMinimum(10);
scale.setSelection((int) (_configuration.getScale() * 100));
scale.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent ev) {
int val = scale.getSelection();
double s = (double) val / 100.0;
_configuration.setScale(s);
scaleText.setText(getScaleText());
updateConf();
}
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
_pagesLabel = new Label(parent, SWT.RIGHT);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
_pagesLabel.setLayoutData(gd);
_printerData = _pdatas[_printerCombo.getSelectionIndex()];
Printer printer = new Printer(_printerData);
_tablePrinter.setPrinter(printer);
Point pages = _tablePrinter.calculatePageCount(_configuration);
printer.dispose();
_pagesLabel.setText(getPagesText(pages));
}
use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.
the class JaretTablePrintDialog method updateConf.
private void updateConf() {
_configuration.setRepeatHeader(_repeatHeader.getSelection());
Printer printer = new Printer(_printerData);
_tablePrinter.setPrinter(printer);
Point pages = _tablePrinter.calculatePageCount(_configuration);
printer.dispose();
_pagesLabel.setText(getPagesText(pages));
}
use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.
the class TableControlPanel method print.
public void print() {
JaretTablePrinter jtp = new JaretTablePrinter(null, _table);
JaretTablePrintDialog pDialog = new JaretTablePrintDialog(Display.getCurrent().getActiveShell(), null, jtp, null);
pDialog.open();
if (pDialog.getReturnCode() == Dialog.OK) {
PrinterData pdata = pDialog.getPrinterData();
JaretTablePrintConfiguration conf = pDialog.getConfiguration();
Printer printer = new Printer(pdata);
jtp.setPrinter(printer);
jtp.print(conf);
printer.dispose();
}
jtp.dispose();
}
use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.
the class GridLayerPrinter method setupPrinter.
private Printer setupPrinter(final Shell shell) {
Printer defaultPrinter = new Printer();
Point pageCount = getPageCount(defaultPrinter);
defaultPrinter.dispose();
final PrintDialog printDialog = new PrintDialog(shell);
printDialog.setStartPage(1);
printDialog.setEndPage(pageCount.x * pageCount.y);
printDialog.setScope(PrinterData.ALL_PAGES);
PrinterData printerData = printDialog.open();
if (printerData == null) {
return null;
}
return new Printer(printerData);
}
use of org.eclipse.swt.printing.Printer in project translationstudio8 by heartsome.
the class GridLayerPrinter method print.
public void print(final Shell shell) {
final Printer printer = setupPrinter(shell);
if (printer == null) {
return;
}
setGridLayerSize(printer.getPrinterData());
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (printer.startJob("NatTable")) {
final Rectangle printerClientArea = computePrintArea(printer);
final Point scaleFactor = computeScaleFactor(printer);
final Point pageCount = getPageCount(printer);
GC gc = new GC(printer);
// Print pages Left to Right and then Top to Down
int currentPage = 1;
for (int verticalPageNumber = 0; verticalPageNumber < pageCount.y; verticalPageNumber++) {
for (int horizontalPageNumber = 0; horizontalPageNumber < pageCount.x; horizontalPageNumber++) {
// Calculate bounds for the next page
Rectangle printBounds = new Rectangle((printerClientArea.width / scaleFactor.x) * horizontalPageNumber, ((printerClientArea.height - FOOTER_HEIGHT_IN_PRINTER_DPI) / scaleFactor.y) * verticalPageNumber, printerClientArea.width / scaleFactor.x, (printerClientArea.height - FOOTER_HEIGHT_IN_PRINTER_DPI) / scaleFactor.y);
if (shouldPrint(printer.getPrinterData(), currentPage)) {
printer.startPage();
Transform printerTransform = new Transform(printer);
// Adjust for DPI difference between display and printer
printerTransform.scale(scaleFactor.x, scaleFactor.y);
// Adjust for margins
printerTransform.translate(printerClientArea.x / scaleFactor.x, printerClientArea.y / scaleFactor.y);
// Grid will nor automatically print the pages at the left margin.
// Example: page 1 will print at x = 0, page 2 at x = 100, page 3 at x = 300
// Adjust to print from the left page margin. i.e x = 0
printerTransform.translate(-1 * printBounds.x, -1 * printBounds.y);
gc.setTransform(printerTransform);
printGrid(gc, printBounds);
printFooter(gc, currentPage, printBounds);
printer.endPage();
printerTransform.dispose();
}
currentPage++;
}
}
printer.endJob();
gc.dispose();
printer.dispose();
}
restoreGridLayerState();
}
private void printGrid(GC gc, Rectangle printBounds) {
gridLayer.getLayerPainter().paintLayer(gridLayer, gc, 0, 0, printBounds, configRegistry);
}
private void printFooter(GC gc, int totalPageCount, Rectangle printBounds) {
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
gc.drawLine(printBounds.x, printBounds.y + printBounds.height + 10, printBounds.x + printBounds.width, printBounds.y + printBounds.height + 10);
gc.drawText("Page " + totalPageCount, printBounds.x, printBounds.y + printBounds.height + 15);
// Approximate width of the date string: 140
gc.drawText(footerDate, printBounds.x + printBounds.width - 140, printBounds.y + printBounds.height + 15);
}
});
}
Aggregations