Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet165.d @ 125:c43718956f21 default tip
Updated the snippets status.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 11 Aug 2011 19:55:14 +0200 |
parents | 9f4c18c268b2 |
children |
rev | line source |
---|---|
28 | 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 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet165; | |
14 | |
15 /* | |
16 * Create a CTabFolder with min and max buttons, as well as close button and | |
17 * image only on selected tab. | |
18 * | |
19 * For a list of all SWT example snippets see | |
20 * http://www.eclipse.org/swt/snippets/ | |
21 * | |
22 * @since 3.0 | |
23 */ | |
24 import org.eclipse.swt.SWT; | |
25 import org.eclipse.swt.custom.CTabFolder; | |
26 import org.eclipse.swt.custom.CTabFolder2Adapter ; | |
27 import org.eclipse.swt.custom.CTabFolderEvent ; | |
28 import org.eclipse.swt.custom.CTabItem; | |
29 import org.eclipse.swt.graphics.GC; | |
30 import org.eclipse.swt.graphics.Image; | |
31 import org.eclipse.swt.layout.GridLayout; | |
32 import org.eclipse.swt.layout.GridData; | |
33 import org.eclipse.swt.widgets.Display; | |
34 import org.eclipse.swt.widgets.Shell; | |
35 import org.eclipse.swt.widgets.Text; | |
112 | 36 import java.lang.all; |
28 | 37 |
112 | 38 version(Tango){ |
39 import tango.util.Convert; | |
40 } else { // Phobos | |
41 import std.conv; | |
42 } | |
28 | 43 |
44 void main () { | |
45 auto display = new Display (); | |
46 auto image = new Image(display, 16, 16); | |
47 auto gc = new GC(image); | |
48 gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); | |
49 gc.fillRectangle(0, 0, 16, 16); | |
50 gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); | |
51 gc.fillRectangle(3, 3, 10, 10); | |
52 gc.dispose(); | |
53 auto shell = new Shell (display); | |
54 shell.setLayout(new GridLayout()); | |
55 auto folder = new CTabFolder(shell, SWT.BORDER); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
56 folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
28 | 57 folder.setSimple(false); |
58 folder.setUnselectedImageVisible(false); | |
59 folder.setUnselectedCloseVisible(false); | |
60 for (int i = 0; i < 8; i++) { | |
61 CTabItem item = new CTabItem(folder, SWT.CLOSE); | |
112 | 62 item.setText("Item " ~ to!(String)(i)); |
28 | 63 item.setImage(image); |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
64 Text text = new Text(folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); |
112 | 65 text.setText("Text for item " ~ to!(String)(i) ~ |
28 | 66 "\n\none, two, three\n\nabcdefghijklmnop"); |
67 item.setControl(text); | |
68 } | |
69 folder.setMinimizeVisible(true); | |
70 folder.setMaximizeVisible(true); | |
71 folder.addCTabFolder2Listener(new class CTabFolder2Adapter { | |
72 public void minimize(CTabFolderEvent event) { | |
73 folder.setMinimized(true); | |
74 shell.layout(true); | |
75 } | |
76 public void maximize(CTabFolderEvent event) { | |
77 folder.setMaximized(true); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
78 folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
28 | 79 shell.layout(true); |
80 } | |
81 public void restore(CTabFolderEvent event) { | |
82 folder.setMinimized(false); | |
83 folder.setMaximized(false); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
84 folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
28 | 85 shell.layout(true); |
86 } | |
87 }); | |
88 shell.setSize(300, 300); | |
89 shell.open (); | |
90 while (!shell.isDisposed ()) { | |
91 if (!display.readAndDispatch ()) display.sleep (); | |
92 } | |
93 image.dispose(); | |
94 display.dispose (); | |
95 } |