org.eclipse.swt.printing.PrinterData Java Examples

The following examples show how to use org.eclipse.swt.printing.PrinterData. 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: GridPrintCellClippingExample.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Executes the GridPrintNoBreak example.
 * 
 * @param args
 *            the command line arguments.
 */
public static void main(String[] args) {
	final Display display = new Display();

	Shell shell = new Shell(display, SWT.SHELL_TRIM);
	shell.setLayout(new GridLayout());
	shell.setSize(600, 600);

	PrintJob job = new PrintJob("GridPrintNoBreakExample", createPrint());

	final PrintPreview preview = new PrintPreview(shell, SWT.BORDER);
	preview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	preview.setPrintJob(job);

	shell.open();

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	PaperClips.print(job, new PrinterData());
}
 
Example #2
Source File: GridLayerPrinter.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Expand the client area of the grid such that
 * all the contents fit in the viewport. This ensures that when the grid prints
 * we print the <i>entire</i> table.
 * @param printer
 */
private void setGridLayerSize(PrinterData printerData) {
	if (printerData.scope == PrinterData.SELECTION) {
		gridLayer.setClientAreaProvider(originalClientAreaProvider);
		return;
	}

	final Rectangle fullGridSize = getTotalGridArea();

	gridLayer.setClientAreaProvider(new IClientAreaProvider(){
		public Rectangle getClientArea() {
			return fullGridSize;
		}
	});

	gridLayer.doCommand(new PrintEntireGridCommand());
}
 
Example #3
Source File: GridLayerPrinter.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Expand the client area of the grid such that
 * all the contents fit in the viewport. This ensures that when the grid prints
 * we print the <i>entire</i> table.
 * @param printer
 */
private void setGridLayerSize(PrinterData printerData) {
	if (printerData.scope == PrinterData.SELECTION) {
		gridLayer.setClientAreaProvider(originalClientAreaProvider);
		return;
	}

	final Rectangle fullGridSize = getTotalGridArea();

	gridLayer.setClientAreaProvider(new IClientAreaProvider(){
		public Rectangle getClientArea() {
			return fullGridSize;
		}
	});

	gridLayer.doCommand(new PrintEntireGridCommand());
}
 
Example #4
Source File: GridLayerPrinter.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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 #5
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
protected void print() {
	if (mainfolder.getSelection() != null && mainfolder.getSelection().getControl() instanceof TabTextView) {
		PrintDialog dialog = new PrintDialog(shell);
		PrinterData data = dialog.open();

		if (data != null) {
			StyledTextPrintOptions options = new StyledTextPrintOptions();
			options.footer = "\t\t<page>";
			options.jobName = "RepDev - " + mainfolder.getSelection().getText();
			options.printLineBackground = false;
			options.printTextFontStyle = true;
			options.printTextForeground = true;
			options.printTextBackground = true;

			Runnable runnable = ((TabTextView) mainfolder.getSelection().getControl()).getStyledText().print(new Printer(data), options);
			runnable.run();
		}
	}
}
 
Example #6
Source File: PrinterPreferencePage.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean performOk(){
	CoreHub.localCfg.set("Drucker/Etiketten/Name", tEtiketten.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/Etiketten/Schacht", tEtikettenschacht.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/Etiketten/Choose", cEtiketten.getSelection()); //$NON-NLS-1$
	Object data = tEtiketten.getData();
	if (data instanceof PrinterData) {
		PrinterData pdata = (PrinterData) data;
		CoreHub.localCfg.set("Drucker/Etiketten/Driver", pdata.driver); //$NON-NLS-1$
	} else {
		CoreHub.localCfg.set("Drucker/Etiketten/Driver", StringTool.leer); //$NON-NLS-1$
	}
	
	CoreHub.localCfg.set("Drucker/A4ESR/Name", tA4ESR.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/A4ESR/Schacht", tA4ESRSchacht.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/A4/Name", tA4.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/A4/Schacht", tA4Schacht.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/A5/Name", tA5.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/A5/Schacht", tA5Schacht.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/Einzelblatt/Name", tEinzelblatt.getText()); //$NON-NLS-1$
	CoreHub.localCfg.set("Drucker/Einzelblatt/Schacht", tEinzelblattSchacht.getText()); //$NON-NLS-1$
	
	return super.performOk();
}
 
Example #7
Source File: TableControlPanel.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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 #8
Source File: ChartPrintJob.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
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 #9
Source File: ChartPrintJob.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
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 #10
Source File: ChartPrintJob.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
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 #11
Source File: GridLayerPrinter.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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 #12
Source File: TableControlPanel.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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 #13
Source File: TutorialExample2.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Prints a table of vital (haha) statistics about Matthew Hall.
 * 
 * @param args
 *            command-line parameters
 */
public static void main(String[] args) {
	// Show the print dialog
	Display display = new Display();
	Shell shell = new Shell(display);
	PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
	PrinterData printerData = dialog.open();
	shell.dispose();
	display.dispose();

	// Print the document to the printer the user selected.
	if (printerData != null) {
		PrintJob job = new PrintJob("TutorialExample2.java", createPrint());
		job.setMargins(72);
		PaperClips.print(job, printerData);
	}
}
 
Example #14
Source File: GridPrintExample.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Executes the GridPrint example.
 * 
 * @param args
 *            the command line arguments.
 */
public static void main(String[] args) {
	final Display display = new Display();

	Shell shell = new Shell(display, SWT.SHELL_TRIM);
	shell.setLayout(new FillLayout());
	shell.setSize(600, 600);

	final PrintViewer preview = new PrintViewer(shell, SWT.BORDER);
	preview.setPrint(createPrint());

	shell.open();

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	PaperClips.print(new PrintJob("GridPrintExample", createPrint()),
			new PrinterData());
}
 
Example #15
Source File: ChartPrintJob.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
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 #16
Source File: PrintImageAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@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());
    }
}
 
Example #17
Source File: TutorialExample1.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Prints the words, "Hello PaperClips!"
 * 
 * @param args
 *            command-line arguments.
 */
public static void main(String[] args) {
	// Create the document
	TextPrint text = new TextPrint("Hello PaperClips!");

	// Show the print dialog
	Display display = new Display();
	Shell shell = new Shell(display);
	PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
	PrinterData printerData = dialog.open();
	shell.dispose();
	display.dispose();

	// Print the document to the printer the user selected.
	if (printerData != null) {
		PrintJob job = new PrintJob("TutorialExample1.java", text);
		job.setMargins(72);
		PaperClips.print(job, printerData);
	}
}
 
Example #18
Source File: ColumnPrintExample.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Executes the ColumnPrint example.
 * 
 * @param args
 *            the command line arguments.
 */
public static void main(String[] args) {
	final Display display = new Display();

	Shell shell = new Shell(display, SWT.SHELL_TRIM);
	shell.setLayout(new FillLayout());
	shell.setSize(600, 600);

	final PrintViewer preview = new PrintViewer(shell, SWT.BORDER);
	preview.setPrint(createPrint());

	shell.open();

	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();

	PaperClips.print(
			new PrintJob("ColumnPrintExample.java", createPrint()),
			new PrinterData());
}
 
Example #19
Source File: PrintAction.java    From http4e with Apache License 2.0 6 votes vote down vote up
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 #20
Source File: GanttChartPrinter.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 #21
Source File: ChartPrintJob.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
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 #22
Source File: DiskExplorerTab.java    From AppleCommander with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #23
Source File: GridLayerPrinter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if a given page number should be printed.
 * Page is allowed to print if:
 * 	  User asked to print all pages or Page in a specified range
 */
private boolean shouldPrint(PrinterData printerData, int totalPageCount) {
	if(printerData.scope == PrinterData.PAGE_RANGE){
		return totalPageCount >= printerData.startPage && totalPageCount <= printerData.endPage;
	}
	return true;
}
 
Example #24
Source File: ChartPrintJob.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #25
Source File: JaretTablePrintDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public JaretTablePrintDialog(Shell parentShell, String printerName, JaretTablePrinter tablePrinter,
        JaretTablePrintConfiguration printConfiguration) {
    super(parentShell);
    _tablePrinter = tablePrinter;
    _configuration = printConfiguration;
    if (_configuration == null) {
        _configuration = new JaretTablePrintConfiguration("table", false, 1.0);
    }
    if (printerName == null && _printerData != null) {
        printerName = _printerData.name;
    }

    _pdatas = Printer.getPrinterList();
    _printers = new String[_pdatas.length];
    int stdIdx = -1;
    for (int i = 0; i < _pdatas.length; i++) {
        PrinterData pd = _pdatas[i];
        _printers[i] = pd.name;
        if (printerName != null && pd.name.equals(printerName)) {
            _pIdx = i;
        }
        if (pd.name.equals(Printer.getDefaultPrinterData().name)) {
            stdIdx = i;
        }
    }
    if (_pIdx == -1) {
        _printerData = Printer.getDefaultPrinterData();
        _pIdx = stdIdx;
    } else {
        _printerData = _pdatas[_pIdx];
    }
}
 
Example #26
Source File: PrinterPreferencePage.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e){
	PrintDialog pd = new PrintDialog(getShell());
	PrinterData pdata = pd.open();
	if (pdata != null) {
		Text tx = (Text) ((Button) e.getSource()).getData();
		tx.setText(pdata.name);
		tx.setData(pdata);
	}
}
 
Example #27
Source File: ChartPrintJob.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #28
Source File: SwtUtil.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: ChartPrintJob.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example #30
Source File: ChartPrintJob.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}