1 /*******************************************************************************
2 * Copyright (c) 2000, 2013 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.snippets;
15
16 /*
17 * Create a CTabFolder with min and max buttons, as well as close button and
18 * image only on selected tab.
19 *
20 * For a list of all SWT example snippets see
21 * http://www.eclipse.org/swt/snippets/
22 *
23 * @since 3.0
24 */
25 import org.eclipse.swt.*;
26 import org.eclipse.swt.custom.*;
27 import org.eclipse.swt.graphics.*;
28 import org.eclipse.swt.layout.*;
29 import org.eclipse.swt.widgets.*;
30
31 public class Snippet165 {
32
main(String [] args)33 public static void main (String [] args) {
34 Display display = new Display ();
35 Image image = new Image(display, 16, 16);
36 GC gc = new GC(image);
37 gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
38 gc.fillRectangle(0, 0, 16, 16);
39 gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
40 gc.fillRectangle(3, 3, 10, 10);
41 gc.dispose();
42 final Shell shell = new Shell (display);
43 shell.setText("Snippet 165");
44 shell.setLayout(new GridLayout());
45 final CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
46 folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
47 folder.setSimple(false);
48 folder.setUnselectedImageVisible(false);
49 folder.setUnselectedCloseVisible(false);
50 for (int i = 0; i < 8; i++) {
51 CTabItem item = new CTabItem(folder, SWT.CLOSE);
52 item.setText("Item "+i);
53 item.setImage(image);
54 Text text = new Text(folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
55 text.setText("Text for item "+i+"\n\none, two, three\n\nabcdefghijklmnop");
56 item.setControl(text);
57 }
58 folder.setMinimizeVisible(true);
59 folder.setMaximizeVisible(true);
60 folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
61 @Override
62 public void minimize(CTabFolderEvent event) {
63 folder.setMinimized(true);
64 folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
65 shell.layout(true);
66 }
67 @Override
68 public void maximize(CTabFolderEvent event) {
69 folder.setMaximized(true);
70 folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
71 shell.layout(true);
72 }
73 @Override
74 public void restore(CTabFolderEvent event) {
75 folder.setMinimized(false);
76 folder.setMaximized(false);
77 folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
78 shell.layout(true);
79 }
80 });
81 shell.setSize(300, 300);
82 shell.open ();
83 while (!shell.isDisposed ()) {
84 if (!display.readAndDispatch ()) display.sleep ();
85 }
86 image.dispose();
87 display.dispose ();
88 }
89 }
90