Mercurial > projects > dwt-samples
comparison snippets/printing/Snippet132.d @ 165:513c72ba21f1
added
snippets\priniting\Snippet132.d
snippets\priniting\Snippet133.d
changed
snippets\dsss.conf
author | Adam Chrapkowski <adam.chrapkowski@gmail.com> |
---|---|
date | Wed, 03 Sep 2008 19:27:24 +0200 |
parents | |
children | 9824a8aba726 |
comparison
equal
deleted
inserted
replaced
164:0beffa2869ad | 165:513c72ba21f1 |
---|---|
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 printing.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 // dwt | |
23 import dwt.DWT; | |
24 // dwt.widgets | |
25 import dwt.widgets.Display, | |
26 dwt.widgets.MessageBox, | |
27 dwt.widgets.Shell; | |
28 // dwt.graphics | |
29 import dwt.graphics.Color, | |
30 dwt.graphics.GC, | |
31 dwt.graphics.Rectangle; | |
32 // dwt.printing | |
33 import dwt.printing.PrintDialog, | |
34 dwt.printing.Printer, | |
35 dwt.printing.PrinterData; | |
36 // dwthelper | |
37 import dwt.dwthelper.utils; | |
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("DWT Printing Snippet")){ | |
51 Color black = printer.getSystemColor(DWT.COLOR_BLACK); | |
52 Color white = printer.getSystemColor(DWT.COLOR_WHITE); | |
53 Color red = printer.getSystemColor(DWT.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 } |