/** * 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(); }
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(); }
public void print() { final Printer printer = SwtUtil.showPrintDialog(imageCanvas); if (printer == null) return; // Print was cancelled new Thread(new Runnable() { public void run() { printer.startJob(getPrintJobName()); printer.startPage(); Point dpi = printer.getDPI(); Image image = getImageCanvas().getImage(); int imageWidth = image.getImageData().width; int imageHeight = image.getImageData().height; int printedWidth = imageWidth * (dpi.x / 96); int printedHeight = imageHeight * (dpi.y / 96); GC gc = new GC(printer); gc.drawImage(image, 0, 0, imageWidth, imageHeight, 0, 0, printedWidth, printedHeight); printer.endPage(); printer.endJob(); gc.dispose(); printer.dispose(); } }).start(); }
/** * Display the Print dialog helper method. */ public static Printer showPrintDialog(Control control) { PrintDialog dialog = new PrintDialog(control.getShell()); PrinterData printerData = dialog.open(); if (printerData == null) return null; return new Printer(printerData); }
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(); } }
/** * @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); }
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(); } }
protected void processAction(TGActionContext context){ PrintStyles styles = context.getAttribute(ATTRIBUTE_STYLES); if( styles == null ) { this.configureStyles(context); return; } PrinterData printerData = context.getAttribute(ATTRIBUTE_DATA); if( printerData == null ) { this.configurePrinterData(context); return; } TGSongManager manager = new TGSongManager(new TGFactoryImpl()); TGSong sourceSong = context.getAttribute(TGDocumentContextAttributes.ATTRIBUTE_SONG); TGSong targetSong = sourceSong.clone(manager.getFactory()); Printer printer = new Printer(printerData); PrintController controller = new PrintController(targetSong, manager, new TGResourceFactoryImpl(printer)); PrintLayout printLayout = new PrintLayout(controller, styles); printLayout.loadStyles(getPrinterScale(printer), 1f); printLayout.updateSong(); printLayout.makeDocument(new PrintDocumentImpl(printLayout, printer, printerData, getPrinterArea(printer, 0.5f))); printLayout.getResourceBuffer().disposeAllResources(); }
/** * {@inheritDoc} */ @Override public void run() { GraphicalViewer viewer; viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class); final PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL); final PrinterData data = dialog.open(); if (data != null) { final Printer printer = new Printer(data); final PrintGraphicalViewerOperation op = new PrintERDiagramOperation(printer, viewer); op.run(getWorkbenchPart().getTitle()); } }
private void onPrint() { PrintDialog printDialog = new PrintDialog(shell); PrinterData printerData = printDialog.open(); if (printerData == null) { return; } Printer printer = new Printer(printerData); editText.print(printer).run(); printer.dispose(); }
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; }
private void printJobFile(JobMeta jobMeta) { JobGraph jobGraph = getActiveJobGraph(); if (jobGraph == null) return; PrintSpool ps = new PrintSpool(); Printer printer = ps.getPrinter(shell); // Create an image of the screen Point max = jobMeta.getMaximum(); Image img = jobGraph.getJobImage(printer, max.x, max.y, 1.0f); ps.printImage(shell, img); img.dispose(); ps.dispose(); }
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); }
private void printTransFile(TransMeta transMeta) { TransGraph transGraph = getActiveTransGraph(); if (transGraph == null) return; PrintSpool ps = new PrintSpool(); Printer printer = ps.getPrinter(shell); // Create an image of the screen Point max = transMeta.getMaximum(); Image img = transGraph.getTransformationImage(printer, max.x, max.y, 1.0f); ps.printImage(shell, img); img.dispose(); ps.dispose(); }
/** * {@inheritDoc} */ @Override public void run() { GraphicalViewer viewer; viewer = (GraphicalViewer) getWorkbenchPart().getAdapter( GraphicalViewer.class); PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL); PrinterData data = dialog.open(); if (data != null) { Printer printer = new Printer(data); PrintGraphicalViewerOperation op = new PrintERDiagramOperation( printer, viewer); op.run(getWorkbenchPart().getTitle()); } }
/** * @see org.eclipse.jface.action.Action#run() */ public void run() { GraphicalViewer viewer; viewer = (GraphicalViewer) getWorkbenchPart().getAdapter( GraphicalViewer.class); PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL); PrinterData data = dialog.open(); if (data != null) { PrintGraphicalViewerOperation op = new PrintGraphicalViewerOperation( new Printer(data), viewer); op.run(getWorkbenchPart().getTitle()); } }
private void printTransFile(TransMeta transMeta) { TransGraph transGraph = getActiveTransGraph(); if (transGraph == null) return; PrintSpool ps = new PrintSpool(); Printer printer = ps.getPrinter(shell); // Create an image of the screen Point max = transMeta.getMaximum(); Image img = transGraph.getTransformationImage(printer, max.x, max.y, false, 1.0f); ps.printImage(shell, img); img.dispose(); ps.dispose(); }
/** * @param args */ public static void main( String[] args ) { try { Chart chart = PrimitiveCharts.createBarChart(); Printer printer = createPrinter(); printChart( chart, printer ); } catch ( Exception e ) { e.printStackTrace(); } }
private void printQuery ( final AbstractQueryBuffer query ) { final List<ValueInformation> vis = query.getValueInformation (); final Map<String, List<Double>> values = query.getValues (); final PrintDialog dlg = new PrintDialog ( getWorkbenchWindow ().getShell () ); final PrinterData printerData = dlg.open (); if ( printerData == null ) { return; } printerData.orientation = PrinterData.LANDSCAPE; final Printer printer = new Printer ( printerData ); try { final PrintProcessor processor = new PrintProcessor ( vis, values ); processor.print ( printer ); } finally { printer.dispose (); } }
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(); } }
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(); } }
private void newline( Printer printer){ x = leftMargin; y += lineHeight; if (y + lineHeight > bottomMargin) { printer.endPage(); if (index + 1 < end) { y = topMargin; printer.startPage(); } } }
protected TGRectangle getPrinterArea(Printer printer, float margin) { Rectangle clientArea = printer.getClientArea(); Rectangle trim = printer.computeTrim(0, 0, 0, 0); Point dpi = printer.getDPI(); float x = (trim.x + (dpi.x * margin)); float y = (trim.y + (dpi.y * margin)); float width = ((clientArea.width + trim.width) - (dpi.x * margin)); float height = ((clientArea.height + trim.height) - (dpi.y * margin)); return new TGRectangle(x, y, width, height); }
protected float getPrinterScale(Printer printer) { Point dpi = printer.getDPI(); if( dpi != null ){ return ( dpi.x / 100.0f ); } return 1.0f; }
public PrintDocumentImpl(PrintLayout layout, Printer printer,PrinterData printerData, TGRectangle bounds){ this.layout = layout; this.printer = printer; this.printerData = printerData; this.bounds = bounds; this.painter = new TGPainterImpl(); }
/** * PrintGraphicalViewerOperation * @param p * @param g */ public PrintGraphicalViewerOperation(Printer p, GraphicalViewer g) { super(p, g); viewer = g; printer = p; previewBounds = ((DiagramRootEditPart)g.getRootEditPart()).getPrintPreviewFigure().getBounds(); }
public PrintAction(final Shell shell, final Scene scene) { super(Messages.Print, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_PRINT_EDIT)); this.shell = shell; this.scene = scene; // Skip printer check on GTK because of hangups: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=153936, // -Dorg.eclipse.swt.internal.gtk.disablePrinting if there are no printers, // https://github.com/ControlSystemStudio/cs-studio/issues/83 if (! SWT.getPlatform().equals("gtk")) { // Only enable if printing is supported. final PrinterData[] printers = Printer.getPrinterList(); if (printers != null) { logger.fine("Available printers:"); for (PrinterData p : printers) logger.fine("Printer: " + p.name + " (" + p.driver + ")"); setEnabled(printers.length > 0); } else { logger.fine("No available printers"); setEnabled(false); } } }
/** Initialize * @param shell Parent shell * @param graph Graph to print */ public PrintAction(final Shell shell, final RTTimePlot graph) { super(Messages.PrintSnapshot, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_PRINT_EDIT)); this.shell = shell; this.graph = graph; this.media_pool = new SWTMediaPool(shell); // Skip printer check on GTK because of hangups: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=153936, // -Dorg.eclipse.swt.internal.gtk.disablePrinting if there are no printers, // https://github.com/ControlSystemStudio/cs-studio/issues/83 if (! SWT.getPlatform().equals("gtk")) { // Only enable if printing is supported. final PrinterData[] printers = Printer.getPrinterList(); final Logger logger = Logger.getLogger(getClass().getName()); if (printers != null) { logger.fine("Available printers:"); for (PrinterData p : printers) logger.fine("Printer: " + p.name + " (" + p.driver + ")"); setEnabled(printers.length > 0); } else { logger.fine("No available printers"); setEnabled(false); } } }