org.eclipse.swt.printing.Printer Java Examples
The following examples show how to use
org.eclipse.swt.printing.Printer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChartPrintJob.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
protected void startPrintJob(Composite elementToPrint, PrinterData printerData) { Printer printer = new Printer(printerData); try { printer.startJob(jobName); GC gc = new GC(printer); try { Rectangle printArea = getPrintableArea(printer, BORDER); printer.startPage(); printComposite(elementToPrint, gc, printArea); printer.endPage(); } finally { gc.dispose(); } printer.endJob(); } finally { printer.dispose(); } }
Example #2
Source File: ChartPrintJob.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * @param printer * @param safetyBorder * @return the rectangle in pixels to print on (and which is also supported * by the printer hardware) */ private Rectangle getPrintableArea(Printer printer, double safetyBorder) { int safetyBorderWidth = (int) (safetyBorder * printer.getDPI().x); int safetyBorderHeight = (int) (safetyBorder * printer.getDPI().y); Rectangle trim = printer.computeTrim(0, 0, 0, 0); int trimLeft = -trim.x; int trimTop = -trim.y; int trimRight = trim.x + trim.width; int trimBottom = trim.y + trim.height; int marginLeft = Math.max(trimLeft, safetyBorderWidth); int marginRight = Math.max(trimRight, safetyBorderWidth); int marginTop = Math.max(trimTop, safetyBorderHeight); int marginBottom = Math.max(trimBottom, safetyBorderHeight); int availWidth = printer.getClientArea().width - marginLeft - marginRight; int availHeight = printer.getClientArea().height - marginTop - marginBottom; return new Rectangle(marginLeft, marginTop, availWidth, availHeight); }
Example #3
Source File: GanttChartPrinter.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Opens the PrintDialog to let the user specify the printer and print configurations to use. * @param shell The Shell which should be the parent for the PrintDialog * @return The selected printer with the print configuration made by the user. */ protected Printer setupPrinter(final Shell shell) { //Calculate the number of pages by using the full image //This is because on setup we want to show how many pages the full print would be Printer defaultPrinter = new Printer(); Point pageCount = getFullPageCount(defaultPrinter); defaultPrinter.dispose(); final PrintDialog printDialog = new PrintDialog(shell); PrinterData data = new PrinterData(); data.orientation = PrinterData.LANDSCAPE; data.startPage = 1; data.endPage = pageCount.x * pageCount.y; data.scope = PrinterData.ALL_PAGES; printDialog.setPrinterData(data); PrinterData printerData = printDialog.open(); if (printerData == null){ return null; } return new Printer(printerData); }
Example #4
Source File: SnippetBenchmarks.java From nebula with Eclipse Public License 2.0 | 6 votes |
private static void benchmarkSnippet8() { final Printer printer = new Printer(); printer.startJob("benchmarkSnippet8"); final PrintJob job = new PrintJob("Snippet8", Snippet8.createPrint()); final GC gc = new GC(printer); new Benchmark().setName("getPageEnumeration").setRunCount(10).execute( new Runnable() { public void run() { PaperClips.getPageEnumeration(job, printer, gc) .nextPage(); } }); gc.dispose(); new Benchmark().setName("getPages").setRunCount(10).execute( new Runnable() { public void run() { PaperClips.getPages(job, printer); } }); printer.cancelJob(); printer.dispose(); }
Example #5
Source File: GridLayerPrinter.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
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); }
Example #6
Source File: PaperClips.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Ends a dummy job on the given Printer if the platform requires a dummy * job. * * @param printer * the Printer hosting the dummy print job. */ public static void endDummyJob(Printer printer) { if (isGTK()) { // Linux GTK // Printer.cancelJob() is not implemented in SWT since GTK has no // API for cancelling a print job. For now we must use endJob(), // even though it spits out an empty page. // printer.cancelJob(); // Not implemented in SWT on GTK printer.endJob(); // See also: // http://bugzilla.gnome.org/show_bug.cgi?id=339323 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=212594 } else if (isCarbon()) // Mac OSX // 2007-04-30: A bug in SWT on Mac OSX prior to 3.3 renders Printer // instances useless after a call to cancelJob(). // Therefore on Mac OSX we call endJob() instead of cancelJob(). if (SWT.getVersion() < 3346) { // Version 3.3 printer.endJob(); } else { printer.cancelJob(); } }
Example #7
Source File: PaperClips.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Prints the print job to the given printer. * * @param printJob * the print job. * @param printer * the printer device. */ public static void print(PrintJob printJob, Printer printer) { // Bug in SWT on OSX: If Printer.startJob() is not called first, the GC // will be disposed by // default. startJob(printer, printJob.getName()); boolean completed = false; try { GC gc = createAndConfigureGC(printer); try { print(printJob, printer, gc); } finally { gc.dispose(); } printer.endJob(); completed = true; } finally { if (!completed) cancelJob(printer); } }
Example #8
Source File: TableControlPanel.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
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(); }
Example #9
Source File: RiskRenderer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public RiskRenderer(Printer printer) { super(printer); if (printer != null) { _yellow = printer.getSystemColor(SWT.COLOR_YELLOW); _green = printer.getSystemColor(SWT.COLOR_GREEN); _red = printer.getSystemColor(SWT.COLOR_RED); _black = printer.getSystemColor(SWT.COLOR_BLACK); _redInactive = new Color(printer, INACTIVE_RED); _yellowInactive = new Color(printer, INACTIVE_YELLOW); _greenInactive = new Color(printer, INACTIVE_GREEN); } Color[][] inactiveColors = { { _yellowInactive, _redInactive, _redInactive }, { _greenInactive, _yellowInactive, _redInactive }, { _greenInactive, _greenInactive, _yellowInactive } }; _inactiveColors = inactiveColors; Color[][] colors = { { _yellow, _red, _red }, { _green, _yellow, _red }, { _green, _green, _yellow } }; _colors = colors; }
Example #10
Source File: StyledTextAdapter.java From AppleCommander with GNU General Public License v2.0 | 6 votes |
public void print() { final Printer printer = SwtUtil.showPrintDialog(styledText); if (printer == null) return; // Print was cancelled StyledTextPrintOptions options = new StyledTextPrintOptions(); options.jobName = printJobName; options.printLineBackground = true; options.printTextBackground = true; options.printTextFontStyle = true; options.printTextForeground = true; options.footer = "\t<page>"; //$NON-NLS-1$ (for StyledText widget!) options.header = "\t" + printJobName; //$NON-NLS-1$ final Runnable runnable = styledText.print(printer, options); new Thread(new Runnable() { public void run() { runnable.run(); printer.dispose(); } }).start(); }
Example #11
Source File: PrintAction.java From http4e with Apache License 2.0 | 6 votes |
void print( Shell shell){ PrintDialog printDialog = new PrintDialog(shell, SWT.NONE); printDialog.setText("Print Http Packets"); PrinterData printerData = printDialog.open(); if (!(printerData == null)) { final Printer printer = new Printer(printerData); Thread printingThread = new Thread("Printing") { public void run(){ try { new PrinterFacade(getTextToPrint(), printer).print(); } catch (Exception e) { ExceptionHandler.handle(e); } finally { printer.dispose(); } } }; printingThread.start(); } }
Example #12
Source File: DiskExplorerTab.java From AppleCommander with GNU General Public License v2.0 | 6 votes |
/** * Print the file listing for this disk. */ protected void print() { PrintDialog printDialog = new PrintDialog(shell); PrinterData printerData = printDialog.open(); if (printerData == null) { // cancelled return; } final Printer printer = new Printer(printerData); new Thread() { public void run() { new Printing(printer).run(); printer.dispose(); } }.start(); }
Example #13
Source File: SmileyCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public SmileyCellRenderer(Printer printer) { super(printer); if (printer != null) { _neutral = printer.getSystemColor(SWT.COLOR_YELLOW); _positive = printer.getSystemColor(SWT.COLOR_GREEN); _negative = printer.getSystemColor(SWT.COLOR_RED); _black = printer.getSystemColor(SWT.COLOR_BLACK); } }
Example #14
Source File: JaretTablePrintDialog.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
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)); }
Example #15
Source File: RendererBase.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * May be constructed without printer (supplying null). * * @param printer or <code>null</code> */ public RendererBase(Printer printer) { _printer = printer; if (_printer != null) { Point dpi = _printer.getDPI(); _scaleX = (double) dpi.x / SCREEN_DPI_X; _scaleY = (double) dpi.y / SCREEN_DPI_Y; } }
Example #16
Source File: BarCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Constructor for BarCellRenderer. * * @param printer Printer or <code>null</code> */ public BarCellRenderer(Printer printer) { super(printer); if (printer != null) { _barColor = printer.getSystemColor(SWT.COLOR_DARK_RED); } }
Example #17
Source File: SWTPrinterPage.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public SWTPrinterPage(Printer printer) { super(printer); if( this.getControl().startPage() ) { this.painter = new SWTPainter(new GC(this.getControl())); } }
Example #18
Source File: SmileyCellRenderer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public SmileyCellRenderer(Printer printer) { super(printer); if (printer != null) { _neutral = printer.getSystemColor(SWT.COLOR_YELLOW); _positive = printer.getSystemColor(SWT.COLOR_GREEN); _negative = printer.getSystemColor(SWT.COLOR_RED); _black = printer.getSystemColor(SWT.COLOR_BLACK); } }
Example #19
Source File: PrinterFacade.java From http4e with Apache License 2.0 | 5 votes |
private void newline( Printer printer){ x = leftMargin; y += lineHeight; if (y + lineHeight > bottomMargin) { printer.endPage(); if (index + 1 < end) { y = topMargin; printer.startPage(); } } }
Example #20
Source File: PrinterFacade.java From http4e with Apache License 2.0 | 5 votes |
private void printText( Printer printer){ printer.startPage(); wordBuffer = new StringBuilder(); x = leftMargin; y = topMargin; index = 0; end = textToPrint.length(); while (index < end) { char c = textToPrint.charAt(index); index++; if (c != 0) { if (c == 0x0a || c == 0x0d) { if (c == 0x0d && index < end && textToPrint.charAt(index) == 0x0a) { index++; // if this is cr-lf, skip the lf } printWordBuffer(printer); newline(printer); } else { if (c != '\t') { wordBuffer.append(c); } if (Character.isWhitespace(c)) { printWordBuffer(printer); if (c == '\t') { x += tabWidth; } } } } } if (y + lineHeight <= bottomMargin) { printer.endPage(); } }
Example #21
Source File: PrinterFacade.java From http4e with Apache License 2.0 | 5 votes |
private void printWordBuffer( Printer printer){ if (wordBuffer.length() > 0) { String word = wordBuffer.toString(); int wordWidth = gc.stringExtent(word).x; if (x + wordWidth > rightMargin) { /* word doesn't fit on current line, so wrap */ newline(printer); } gc.drawString(word, x, y, false); x += wordWidth; wordBuffer = new StringBuilder(); } }
Example #22
Source File: BarCellRenderer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Constructor for BarCellRenderer. * * @param printer Printer or <code>null</code> */ public BarCellRenderer(Printer printer) { super(printer); if (printer != null) { _barColor = printer.getSystemColor(SWT.COLOR_DARK_RED); } }
Example #23
Source File: ObjectImageRenderer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public ICellRenderer createPrintRenderer(Printer printer) { ObjectImageRenderer renderer = new ObjectImageRenderer(printer); for (Object o : _keyMap.keySet()) { String key = _keyMap.get(o); ImageDescriptor imageDesc = getImageRegistry().getDescriptor(key); renderer.addObjectImageDescriptorMapping(o, key, imageDesc); } return renderer; }
Example #24
Source File: PrintSpool.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public PrintSpool() { printerdata = Printer.getDefaultPrinterData(); if ( printerdata != null ) { // Fail silently instead of crashing. printer = new Printer( printerdata ); } }
Example #25
Source File: ClassImageRenderer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public ICellRenderer createPrintRenderer(Printer printer) { ClassImageRenderer renderer = new ClassImageRenderer(printer); for (Class<?> clazz : _keyMap.keySet()) { String key = _keyMap.get(clazz); ImageDescriptor imageDesc = getImageRegistry().getDescriptor(key); renderer.addClassImageDescriptorMapping(clazz, key, imageDesc); } return renderer; }
Example #26
Source File: TableHierarchyRenderer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public ICellRenderer createPrintRenderer(Printer printer) { TableHierarchyRenderer r = new TableHierarchyRenderer(printer); r.setDrawIcons(_drawIcons); r.setDrawLabels(_drawLabels); r.setLevelWidth(_levelWidth); r.setLabelProvider(_labelProvider); return r; }
Example #27
Source File: CompoundGanttChartPrinter.java From nebula with Eclipse Public License 2.0 | 5 votes |
@Override protected Point getFullPageCount(Printer printer) { Point result = new Point(0, 0); for (GanttChart ganttChart : this.ganttCharts) { Image chartImage = ganttChart.getGanttComposite().getFullImage(); Point imgPoint = PrintUtils.getPageCount(printer, chartImage); result.x += imgPoint.x; result.y += imgPoint.y; chartImage.dispose(); } return result; }
Example #28
Source File: CompoundGanttChartPrinter.java From nebula with Eclipse Public License 2.0 | 5 votes |
@Override public void print() { if (!this.ganttCharts.isEmpty()) { final Printer printer = setupPrinter(Display.getCurrent().getActiveShell()); if (printer == null) { return; } String name = (this.jobName != null && this.jobName.length() > 0) ? this.jobName : this.ganttCharts.get(0).getLanguageManger().getPrintJobText(); Display.getDefault().asyncExec(new GanttChartPrintJob( printer, name, ganttCharts.toArray(new GanttChart[] {}))); } }
Example #29
Source File: PrintUtils.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Calculate number of horizontal and vertical pages needed * to print the given image of the chart. * @param printer The printer that will be used to print the chart * @param image The image of the chart that should be printed. * @return The number of horizontal and vertical pages that will be * printed. */ public static Point getPageCount(Printer printer, Image image){ Rectangle ganttArea = getVisibleGanttChartArea(image); Rectangle printArea = PrintUtils.computePrintArea(printer); Point scaleFactor = PrintUtils.computeScaleFactor(printer); int numOfHorizontalPages = ganttArea.width / (printArea.width / scaleFactor.x); int numOfVerticalPages = ganttArea.height / (printArea.height / scaleFactor.y); // Adjusting for 0 index return new Point(numOfHorizontalPages + 1, numOfVerticalPages + 1); }
Example #30
Source File: PrintUtils.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * * @param printer The printer that will be used to print the chart * @return Amount to scale the screen resolution by, to match the printer * resolution. */ public static Point computeScaleFactor(Printer printer) { Point screenDPI = Display.getDefault().getDPI(); Point printerDPI = printer.getDPI(); int scaleFactorX = printerDPI.x / screenDPI.x; int scaleFactorY = printerDPI.y / screenDPI.y; return new Point(scaleFactorX, scaleFactorY); }