Mercurial > projects > dwt2
comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet132.d @ 28:69b1fa94a4a8
Added SWT snippets
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 22 Mar 2009 15:17:04 +0100 |
parents | |
children | 536e43f63c81 |
comparison
equal
deleted
inserted
replaced
27:1bf55a6eb092 | 28:69b1fa94a4a8 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2004 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * D Port: | |
11 * Adam Chrapkowski <adam DOT chrapkowski AT gmail DOT com> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet132; | |
14 | |
15 /* | |
16 * Printing example snippet: print "Hello World!" in black, outlined in red, to default printer | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 | |
22 // org.eclipse.swt | |
23 import org.eclipse.swt.SWT; | |
24 // org.eclipse.swt.widgets | |
25 import org.eclipse.swt.widgets.Display, | |
26 org.eclipse.swt.widgets.MessageBox, | |
27 org.eclipse.swt.widgets.Shell; | |
28 // org.eclipse.swt.graphics | |
29 import org.eclipse.swt.graphics.Color, | |
30 org.eclipse.swt.graphics.GC, | |
31 org.eclipse.swt.graphics.Rectangle; | |
32 // org.eclipse.swt.printing | |
33 import org.eclipse.swt.printing.PrintDialog, | |
34 org.eclipse.swt.printing.Printer, | |
35 org.eclipse.swt.printing.PrinterData; | |
36 // java | |
37 import java.lang.all; | |
38 | |
39 public void | |
40 main(String [] args){ | |
41 Display display = new Display(); | |
42 Shell shell = new Shell(display); | |
43 shell.open(); | |
44 PrinterData data = Printer.getDefaultPrinterData(); | |
45 if(data is null){ | |
46 MessageBox.showWarning("Warning: No default printer."); | |
47 return; | |
48 } | |
49 Printer printer = new Printer(data); | |
50 if(printer.startJob("SWT Printing Snippet")){ | |
51 Color black = printer.getSystemColor(SWT.COLOR_BLACK); | |
52 Color white = printer.getSystemColor(SWT.COLOR_WHITE); | |
53 Color red = printer.getSystemColor(SWT.COLOR_RED); | |
54 Rectangle trim = printer.computeTrim(0, 0, 0, 0); | |
55 Point dpi = printer.getDPI(); | |
56 int leftMargin = dpi.x + trim.x; // one inch from left side of paper | |
57 int topMargin = dpi.y / 2 + trim.y; // one-half inch from top edge of paper | |
58 GC gc = new GC(printer); | |
59 if(printer.startPage()){ | |
60 gc.setBackground(white); | |
61 gc.setForeground(black); | |
62 String testString = "Hello World!"; | |
63 Point extent = gc.stringExtent(testString); | |
64 gc.drawString(testString, leftMargin, topMargin); | |
65 gc.setForeground(red); | |
66 gc.drawRectangle(leftMargin, topMargin, extent.x, extent.y); | |
67 printer.endPage(); | |
68 } | |
69 gc.dispose(); | |
70 printer.endJob(); | |
71 } | |
72 printer.dispose(); | |
73 while(!shell.isDisposed()){ | |
74 if(!display.readAndDispatch()) display.sleep(); | |
75 } | |
76 display.dispose(); | |
77 } |