Mercurial > projects > dwt-samples
annotate snippets/tree/Snippet220.d @ 120:1f0a7a472680
fix rm snippets from module statements.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 20 Jul 2008 19:17:23 +0200 |
parents | 4095b64d16f5 |
children |
rev | line source |
---|---|
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
1 /******************************************************************************* |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others. |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
7 * |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
8 * Contributors: |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
10 * D Port: |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
11 * Bill Baxter <wbaxter@gmail.com> |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
12 *******************************************************************************/ |
120
1f0a7a472680
fix rm snippets from module statements.
Frank Benoit <benoit@tionex.de>
parents:
86
diff
changeset
|
13 module tree.Snippet220; |
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
14 |
86
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
15 /* |
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
16 * Tree example snippet: Images on the right side of the TreeItem |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
17 * |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
18 * For a detailed explanation of this snippet see |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
19 * http://www.eclipse.org/articles/Article-CustomDrawingTableAndTreeItems/customDraw.htm#_example5 |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
20 * |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
21 * For a list of all SWT example snippets see |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
22 * http://www.eclipse.org/swt/snippets/ |
86
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
23 * |
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
24 * @since 3.2 |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
25 */ |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
26 |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
27 import dwt.DWT; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
28 import dwt.graphics.Image; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
29 import dwt.graphics.GC; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
30 import dwt.widgets.Display; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
31 import dwt.widgets.Shell; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
32 import dwt.widgets.Listener; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
33 import dwt.widgets.Event; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
34 import dwt.widgets.Tree; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
35 import dwt.widgets.TreeItem; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
36 |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
37 import tango.util.Convert; |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
38 |
85
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
39 version(JIVE){ |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
40 import jive.stacktrace; |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
41 } |
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
42 |
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
43 void main() { |
86
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
44 const int IMAGE_MARGIN = 2; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
45 void handleEventMeasureItem(Event event) { |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
46 TreeItem item = cast(TreeItem)event.item; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
47 Image trailingImage = cast(Image)item.getData(); |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
48 if (trailingImage !is null) { |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
49 int w1 = event.width; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
50 event.width += trailingImage.getBounds().width + IMAGE_MARGIN; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
51 int w2 = event.width; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
52 } |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
53 } |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
54 void handleEventPaintItem(Event event, Tree tree ) { |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
55 TreeItem item = cast(TreeItem)event.item; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
56 Image trailingImage = cast(Image)item.getData(); |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
57 if (trailingImage !is null) { |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
58 int x = event.x + event.width + IMAGE_MARGIN; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
59 int itemHeight = tree.getItemHeight(); |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
60 int imageHeight = trailingImage.getBounds().height; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
61 int y = event.y + (itemHeight - imageHeight) / 2; |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
62 event.gc.drawImage(trailingImage, x, y); |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
63 } |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
64 } |
85
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
65 Display display = new Display(); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
66 Shell shell = new Shell(display); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
67 shell.setBounds(10, 10, 350, 200); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
68 Image xImage = new Image (display, 16, 16); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
69 GC gc = new GC(xImage); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
70 gc.setForeground(display.getSystemColor(DWT.COLOR_RED)); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
71 gc.drawLine(1, 1, 14, 14); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
72 gc.drawLine(1, 14, 14, 1); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
73 gc.drawOval(2, 2, 11, 11); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
74 gc.dispose(); |
86
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
75 Tree tree = new Tree(shell, DWT.CHECK); |
85
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
76 tree.setBounds(10, 10, 300, 150); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
77 TreeItem item = new TreeItem(tree, DWT.NONE); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
78 item.setText("root item"); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
79 for (int i = 0; i < 4; i++) { |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
80 TreeItem newItem = new TreeItem(item, DWT.NONE); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
81 newItem.setText("descendent " ~ to!(char[])(i)); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
82 if (i % 2 == 0) newItem.setData(xImage); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
83 item.setExpanded(true); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
84 item = newItem; |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
85 } |
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
86 |
85
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
87 /* |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
88 * NOTE: MeasureItem and PaintItem are called repeatedly. Therefore it is |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
89 * critical for performance that these methods be as efficient as possible. |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
90 */ |
86
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
91 tree.addListener(DWT.MeasureItem, dgListener( &handleEventMeasureItem )); |
4095b64d16f5
Fixed in dwt-win, so removed the debugging outputs.
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
92 tree.addListener(DWT.PaintItem,dgListener( &handleEventPaintItem, tree )); |
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
93 |
85
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
94 shell.open(); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
95 while (!shell.isDisposed()) { |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
96 if (!display.readAndDispatch()) display.sleep(); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
97 } |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
98 xImage.dispose(); |
fa286c85e7b8
Fix Snippet111 and add jive to Snippet220
Frank Benoit <benoit@tionex.de>
parents:
84
diff
changeset
|
99 display.dispose(); |
84
398aa64a7243
Two new snippets -- don't quite work yet though.
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
100 } |