Mercurial > projects > dwt-samples
annotate examples/sleak/SleakExample.d @ 161:eb84f9418bbf
Change module names to this not have examples in the FQN.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 01 Sep 2008 22:24:27 +0200 |
parents | 4a04b6759f98 |
children |
rev | line source |
---|---|
78 | 1 /* |
2 * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. | |
3 * This file is made available under the terms of the Common Public License v1.0 | |
4 * which accompanies this distribution, and is available at | |
5 * http://www.eclipse.org/legal/cpl-v10.html | |
6 * | |
7 * Port to the D programming language | |
8 * Frank Benoit <benoit@tionex.de> | |
9 */ | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
10 module sleak.SleakExample; |
78 | 11 |
12 import dwt.DWT; | |
13 import dwt.graphics.DeviceData; | |
14 import dwt.widgets.Display; | |
15 import dwt.widgets.Shell; | |
16 import dwt.widgets.Canvas; | |
17 import dwt.widgets.List; | |
18 import dwt.program.Program; | |
19 import dwt.graphics.ImageData; | |
20 import dwt.graphics.Image; | |
21 import dwt.layout.FillLayout; | |
22 import dwt.events.PaintListener; | |
23 import dwt.events.PaintEvent; | |
24 import dwt.events.SelectionAdapter; | |
25 import dwt.events.SelectionEvent; | |
26 | |
27 import dwtx.sleak.Sleak; | |
28 | |
29 import tango.io.Stdout; | |
30 version(JIVE){ | |
31 import jive.stacktrace; | |
32 } | |
33 | |
34 void main() { | |
35 Display display; | |
36 Shell shell; | |
37 List list; | |
38 Canvas canvas; | |
39 Image image; | |
40 | |
41 version( all ){ | |
42 DeviceData data = new DeviceData(); | |
43 data.tracking = true; | |
44 display = new Display(data); | |
45 Sleak sleak = new Sleak(); | |
46 sleak.open(); | |
47 } | |
48 else{ | |
49 display = new Display(); | |
50 } | |
51 | |
52 shell = new Shell(display); | |
53 shell.setLayout(new FillLayout()); | |
54 list = new List(shell, DWT.BORDER | DWT.SINGLE | DWT.V_SCROLL | DWT.H_SCROLL); | |
55 list.setItems(Program.getExtensions()); | |
56 canvas = new Canvas(shell, DWT.BORDER); | |
57 canvas.addPaintListener(new class() PaintListener { | |
58 public void paintControl(PaintEvent e) { | |
59 if (image !is null) { | |
60 e.gc.drawImage(image, 0, 0); | |
61 } | |
62 } | |
63 }); | |
64 list.addSelectionListener(new class() SelectionAdapter { | |
65 public void widgetSelected(SelectionEvent e) { | |
66 image = null; // potentially leak one image | |
67 char[][] selection = list.getSelection(); | |
68 if (selection.length !is 0) { | |
69 Program program = Program.findProgram(selection[0]); | |
70 if (program !is null) { | |
71 ImageData imageData = program.getImageData(); | |
72 if (imageData !is null) { | |
73 if (image !is null) image.dispose(); | |
74 image = new Image(display, imageData); | |
75 } | |
76 } | |
77 } | |
78 canvas.redraw(); | |
79 } | |
80 }); | |
81 shell.setSize(shell.computeSize(DWT.DEFAULT, 200)); | |
82 shell.open(); | |
83 while (!shell.isDisposed()) { | |
84 if (!display.readAndDispatch()) | |
85 display.sleep(); | |
86 } | |
87 } |