Search in sources :

Example 1 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project translationstudio8 by heartsome.

the class JaretTablePrintDialog method createPrinterSelection.

private void createPrinterSelection(Composite parent) {
    Composite area = new Composite(parent, SWT.NULL);
    area.setLayout(new RowLayout());
    // area.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
    _printerCombo = new CCombo(area, SWT.BORDER | SWT.READ_ONLY);
    _printerCombo.setItems(_printers);
    _printerCombo.select(_pIdx);
    Button select = new Button(area, SWT.PUSH);
    select.setText("Configure");
    select.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            PrintDialog pd = new PrintDialog(Display.getCurrent().getActiveShell());
            PrinterData pdata = pd.open();
            if (pdata != null) {
                _printerData = pdata;
                select(_printerData);
            }
        }

        private void select(PrinterData printerData) {
            for (int i = 0; i < _pdatas.length; i++) {
                PrinterData pd = _pdatas[i];
                if (pd.name.equals(printerData.name)) {
                    _printerCombo.select(i);
                    break;
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog 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);
}
Also used : PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Point(org.eclipse.swt.graphics.Point) Printer(org.eclipse.swt.printing.Printer)

Example 3 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project eclipse.platform.swt by eclipse.

the class DialogTab method createButtonSelected.

/**
 * Handle the create button selection event.
 *
 * @param event org.eclipse.swt.events.SelectionEvent
 */
void createButtonSelected(SelectionEvent event) {
    /* Compute the appropriate dialog style */
    int style = getDefaultStyle();
    if (okButton.getEnabled() && okButton.getSelection())
        style |= SWT.OK;
    if (cancelButton.getEnabled() && cancelButton.getSelection())
        style |= SWT.CANCEL;
    if (yesButton.getEnabled() && yesButton.getSelection())
        style |= SWT.YES;
    if (noButton.getEnabled() && noButton.getSelection())
        style |= SWT.NO;
    if (retryButton.getEnabled() && retryButton.getSelection())
        style |= SWT.RETRY;
    if (abortButton.getEnabled() && abortButton.getSelection())
        style |= SWT.ABORT;
    if (ignoreButton.getEnabled() && ignoreButton.getSelection())
        style |= SWT.IGNORE;
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection())
        style |= SWT.ICON_ERROR;
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection())
        style |= SWT.ICON_INFORMATION;
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection())
        style |= SWT.ICON_QUESTION;
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection())
        style |= SWT.ICON_WARNING;
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection())
        style |= SWT.ICON_WORKING;
    if (primaryModalButton.getEnabled() && primaryModalButton.getSelection())
        style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getEnabled() && applicationModalButton.getSelection())
        style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getEnabled() && systemModalButton.getSelection())
        style |= SWT.SYSTEM_MODAL;
    if (sheetButton.getSelection())
        style |= SWT.SHEET;
    if (saveButton.getEnabled() && saveButton.getSelection())
        style |= SWT.SAVE;
    if (openButton.getEnabled() && openButton.getSelection())
        style |= SWT.OPEN;
    if (multiButton.getEnabled() && multiButton.getSelection())
        style |= SWT.MULTI;
    /* Open the appropriate dialog type */
    String name = dialogCombo.getText();
    if (name.equals(ControlExample.getResourceString("ColorDialog"))) {
        ColorDialog dialog = new ColorDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setRGB(colorDialogResult);
            dialog.setRGBs(colorDialogCustomColors);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        RGB result = dialog.open();
        textWidget.append(ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER);
        textWidget.append("getRGBs() =" + Text.DELIMITER);
        RGB[] rgbs = dialog.getRGBs();
        if (rgbs != null) {
            for (RGB rgbColor : rgbs) {
                textWidget.append("\t" + rgbColor + Text.DELIMITER);
            }
        }
        textWidget.append(Text.DELIMITER);
        colorDialogResult = result;
        colorDialogCustomColors = rgbs;
        return;
    }
    if (name.equals(ControlExample.getResourceString("DirectoryDialog"))) {
        DirectoryDialog dialog = new DirectoryDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFilterPath(directoryDialogResult);
        }
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER + Text.DELIMITER);
        directoryDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("FileDialog"))) {
        FileDialog dialog = new FileDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFileName(fileDialogResult);
            dialog.setFilterIndex(fileDialogIndexResult);
        }
        dialog.setFilterNames(FilterNames);
        dialog.setFilterExtensions(FilterExtensions);
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFilterIndex() =" + dialog.getFilterIndex() + Text.DELIMITER);
        textWidget.append("getFilterPath() =" + dialog.getFilterPath() + Text.DELIMITER);
        textWidget.append("getFileName() =" + dialog.getFileName() + Text.DELIMITER);
        textWidget.append("getFileNames() =" + Text.DELIMITER);
        String[] files = dialog.getFileNames();
        for (String file : files) {
            textWidget.append("\t" + file + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        fileDialogResult = result;
        fileDialogIndexResult = dialog.getFilterIndex();
        return;
    }
    if (name.equals(ControlExample.getResourceString("FontDialog"))) {
        FontDialog dialog = new FontDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFontList(fontDialogFontListResult);
            dialog.setRGB(fontDialogColorResult);
        }
        dialog.setEffectsVisible(effectsVisibleButton.getSelection());
        dialog.setText(ControlExample.getResourceString("Title"));
        FontData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFontList() =" + Text.DELIMITER);
        FontData[] fonts = dialog.getFontList();
        if (fonts != null) {
            for (FontData font : fonts) {
                textWidget.append("\t" + font + Text.DELIMITER);
            }
        }
        textWidget.append("getEffectsVisible() = " + dialog.getEffectsVisible() + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
        fontDialogFontListResult = dialog.getFontList();
        fontDialogColorResult = dialog.getRGB();
        return;
    }
    if (name.equals(ControlExample.getResourceString("PrintDialog"))) {
        PrintDialog dialog = new PrintDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setPrinterData(printDialogResult);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        PrinterData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        if (result != null) {
            textWidget.append("printerData.scope = " + (result.scope == PrinterData.PAGE_RANGE ? "PAGE_RANGE" : result.scope == PrinterData.SELECTION ? "SELECTION" : "ALL_PAGES") + Text.DELIMITER);
            textWidget.append("printerData.startPage = " + result.startPage + Text.DELIMITER);
            textWidget.append("printerData.endPage = " + result.endPage + Text.DELIMITER);
            textWidget.append("printerData.printToFile = " + result.printToFile + Text.DELIMITER);
            textWidget.append("printerData.fileName = " + result.fileName + Text.DELIMITER);
            textWidget.append("printerData.orientation = " + (result.orientation == PrinterData.LANDSCAPE ? "LANDSCAPE" : "PORTRAIT") + Text.DELIMITER);
            textWidget.append("printerData.copyCount = " + result.copyCount + Text.DELIMITER);
            textWidget.append("printerData.collate = " + result.collate + Text.DELIMITER);
            textWidget.append("printerData.duplex = " + (result.duplex == PrinterData.DUPLEX_LONG_EDGE ? "DUPLEX_LONG_EDGE" : result.duplex == PrinterData.DUPLEX_SHORT_EDGE ? "DUPLEX_SHORT_EDGE" : "NONE") + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        printDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("MessageBox"))) {
        MessageBox dialog = new MessageBox(shell, style);
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        int result = dialog.open();
        textWidget.append(ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
        /*
			 * The resulting integer depends on the original
			 * dialog style.  Decode the result and display it.
			 */
        switch(result) {
            case SWT.OK:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.OK"));
                break;
            case SWT.YES:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.YES"));
                break;
            case SWT.NO:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.NO"));
                break;
            case SWT.CANCEL:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.CANCEL"));
                break;
            case SWT.ABORT:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.ABORT"));
                break;
            case SWT.RETRY:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.RETRY"));
                break;
            case SWT.IGNORE:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.IGNORE"));
                break;
            default:
                textWidget.append(ControlExample.getResourceString("Result", "" + result));
                break;
        }
        textWidget.append(Text.DELIMITER + Text.DELIMITER);
    }
}
Also used : FontDialog(org.eclipse.swt.widgets.FontDialog) PrintDialog(org.eclipse.swt.printing.PrintDialog) FontData(org.eclipse.swt.graphics.FontData) RGB(org.eclipse.swt.graphics.RGB) MessageBox(org.eclipse.swt.widgets.MessageBox) ColorDialog(org.eclipse.swt.widgets.ColorDialog) PrinterData(org.eclipse.swt.printing.PrinterData) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 4 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project dbeaver by dbeaver.

the class ERDEditorPart method printDiagram.

public void printDiagram() {
    GraphicalViewer viewer = getGraphicalViewer();
    PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
    PrinterData data = dialog.open();
    if (data != null) {
        IFigure rootFigure = rootPart.getLayer(ScalableFreeformRootEditPart.PRINTABLE_LAYERS);
        // EntityDiagramFigure diagramFigure = findFigure(rootFigure, EntityDiagramFigure.class);
        if (rootFigure != null) {
            PrintFigureOperation printOp = new PrintFigureOperation(new Printer(data), rootFigure);
            // Set print preferences
            IPreferenceStore store = ERDActivator.getDefault().getPreferenceStore();
            printOp.setPrintMode(store.getInt(ERDConstants.PREF_PRINT_PAGE_MODE));
            printOp.setPrintMargin(new Insets(store.getInt(ERDConstants.PREF_PRINT_MARGIN_TOP), store.getInt(ERDConstants.PREF_PRINT_MARGIN_LEFT), store.getInt(ERDConstants.PREF_PRINT_MARGIN_BOTTOM), store.getInt(ERDConstants.PREF_PRINT_MARGIN_RIGHT)));
            // Run print
            printOp.run("Print ER diagram");
        }
    }
// new PrintAction(this).run();
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) PrintFigureOperation(org.eclipse.draw2d.PrintFigureOperation) IFigure(org.eclipse.draw2d.IFigure)

Example 5 with PrintDialog

use of org.eclipse.swt.printing.PrintDialog in project yamcs-studio by yamcs.

the class PrintDisplayAction method run.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
@Override
public void run() {
    final GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
    viewer.getControl().getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            final ImageLoader loader = new ImageLoader();
            ImageData[] imageData;
            try {
                imageData = loader.load(ResourceUtil.getScreenshotFile(viewer));
                if (imageData.length > 0) {
                    PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
                    final PrinterData data = dialog.open();
                    if (data != null) {
                        Printer printer = new Printer(data);
                        // Calculate the scale factor between the screen resolution
                        // and printer
                        // resolution in order to correctly size the image for the
                        // printer
                        Point screenDPI = viewer.getControl().getDisplay().getDPI();
                        Point printerDPI = printer.getDPI();
                        int scaleFactor = printerDPI.x / screenDPI.x;
                        // Determine the bounds of the entire area of the printer
                        Rectangle trim = printer.computeTrim(0, 0, 0, 0);
                        Image printerImage = new Image(printer, imageData[0]);
                        if (printer.startJob("Printing OPI")) {
                            if (printer.startPage()) {
                                GC gc = new GC(printer);
                                Rectangle printArea = printer.getClientArea();
                                if (imageData[0].width * scaleFactor <= printArea.width) {
                                    printArea.width = imageData[0].width * scaleFactor;
                                    printArea.height = imageData[0].height * scaleFactor;
                                } else {
                                    printArea.height = printArea.width * imageData[0].height / imageData[0].width;
                                }
                                gc.drawImage(printerImage, 0, 0, imageData[0].width, imageData[0].height, -trim.x, -trim.y, printArea.width, printArea.height);
                                gc.dispose();
                                printer.endPage();
                            }
                        }
                        printer.endJob();
                        printer.dispose();
                        printerImage.dispose();
                    }
                }
            } catch (Exception e) {
                ErrorHandlerUtil.handleError("Failed to print OPI", e);
                return;
            }
        }
    });
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Printer(org.eclipse.swt.printing.Printer) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Aggregations

PrintDialog (org.eclipse.swt.printing.PrintDialog)24 PrinterData (org.eclipse.swt.printing.PrinterData)21 Printer (org.eclipse.swt.printing.Printer)19 Point (org.eclipse.swt.graphics.Point)6 Shell (org.eclipse.swt.widgets.Shell)6 Insets (org.eclipse.draw2d.geometry.Insets)4 StyledTextPrintOptions (org.eclipse.swt.custom.StyledTextPrintOptions)4 GC (org.eclipse.swt.graphics.GC)4 Image (org.eclipse.swt.graphics.Image)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 IFigure (org.eclipse.draw2d.IFigure)3 PrintFigureOperation (org.eclipse.draw2d.PrintFigureOperation)3 GraphicalViewer (org.eclipse.gef.GraphicalViewer)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 PrintGraphicalViewerOperation (org.eclipse.gef.print.PrintGraphicalViewerOperation)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 FontData (org.eclipse.swt.graphics.FontData)2 ImageLoader (org.eclipse.swt.graphics.ImageLoader)2