comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet165.d @ 28:69b1fa94a4a8

Added SWT snippets
author Frank Benoit <benoit@tionex.de>
date Sun, 22 Mar 2009 15:17:04 +0100
parents
children 4e5843b771cc
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 * 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;
36
37 import tango.util.Convert;
38
39 void main () {
40 auto display = new Display ();
41 auto image = new Image(display, 16, 16);
42 auto gc = new GC(image);
43 gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
44 gc.fillRectangle(0, 0, 16, 16);
45 gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
46 gc.fillRectangle(3, 3, 10, 10);
47 gc.dispose();
48 auto shell = new Shell (display);
49 shell.setLayout(new GridLayout());
50 auto folder = new CTabFolder(shell, SWT.BORDER);
51 folder.setLayoutData(new GridData(SWT.FILL, DWT.FILL, true, false));
52 folder.setSimple(false);
53 folder.setUnselectedImageVisible(false);
54 folder.setUnselectedCloseVisible(false);
55 for (int i = 0; i < 8; i++) {
56 CTabItem item = new CTabItem(folder, SWT.CLOSE);
57 item.setText("Item " ~ to!(char[])(i));
58 item.setImage(image);
59 Text text = new Text(folder, SWT.MULTI | DWT.V_SCROLL | DWT.H_SCROLL);
60 text.setText("Text for item " ~ to!(char[])(i) ~
61 "\n\none, two, three\n\nabcdefghijklmnop");
62 item.setControl(text);
63 }
64 folder.setMinimizeVisible(true);
65 folder.setMaximizeVisible(true);
66 folder.addCTabFolder2Listener(new class CTabFolder2Adapter {
67 public void minimize(CTabFolderEvent event) {
68 folder.setMinimized(true);
69 shell.layout(true);
70 }
71 public void maximize(CTabFolderEvent event) {
72 folder.setMaximized(true);
73 folder.setLayoutData(new GridData(SWT.FILL, DWT.FILL, true, true));
74 shell.layout(true);
75 }
76 public void restore(CTabFolderEvent event) {
77 folder.setMinimized(false);
78 folder.setMaximized(false);
79 folder.setLayoutData(new GridData(SWT.FILL, DWT.FILL, true, false));
80 shell.layout(true);
81 }
82 });
83 shell.setSize(300, 300);
84 shell.open ();
85 while (!shell.isDisposed ()) {
86 if (!display.readAndDispatch ()) display.sleep ();
87 }
88 image.dispose();
89 display.dispose ();
90 }