summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Northover <steve>2008-02-06 19:44:21 +0000
committerSteve Northover <steve>2008-02-06 19:44:21 +0000
commit7ddfed07c906ad1c848732e3e8e47aff42496157 (patch)
tree8e12c46c4e6ecfae981455d35510f05b3c803214
parent3859d259a86e111754088929d54710598b8599cc (diff)
downloadeclipse.platform.swt-7ddfed07c906ad1c848732e3e8e47aff42496157.tar.gz
eclipse.platform.swt-7ddfed07c906ad1c848732e3e8e47aff42496157.tar.xz
eclipse.platform.swt-7ddfed07c906ad1c848732e3e8e47aff42496157.zip
*** empty log message ***
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java
new file mode 100644
index 0000000000..0436d6cce1
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.snippets;
+
+/*
+ * Take a snapshot of a control
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+
+public class Snippet292 {
+ public static void main(String[] args) {
+ final Display display = new Display();
+ Shell shell = new Shell(display);
+ final Tree tree = new Tree(shell, SWT.BORDER);
+ for (int i = 0; i < 5; i++) {
+ TreeItem treeItem = new TreeItem (tree, SWT.NULL);
+ treeItem.setText ("TreeItem " + i);
+ for (int j = 0; j < 3; j++) {
+ TreeItem subItem = new TreeItem(treeItem, SWT.NONE);
+ subItem.setText("SubItem " + i + "-" + j);
+ }
+ if (i % 3 == 0) treeItem.setExpanded (true);
+ }
+ final Label label = new Label (shell, SWT.NONE);
+ label.addListener (SWT.Dispose, new Listener () {
+ public void handleEvent (Event e) {
+ Image image = label.getImage ();
+ if (image != null) image.dispose ();
+ }
+ });
+ Button button = new Button (shell, SWT.PUSH);
+ button.setText ("Snapshot");
+ button.addListener (SWT.Selection, new Listener () {
+ public void handleEvent (Event e) {
+ Image image = label.getImage ();
+ if (image != null) image.dispose ();
+ image = new Image (display, tree.getBounds ());
+ GC gc = new GC (image);
+ tree.print (gc);
+ gc.dispose ();
+ label.setImage (image);
+ }
+ });
+ GridLayout layout = new GridLayout (2, true);
+ shell.setLayout(layout);
+ tree.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
+ label.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
+ button.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true, 2, 1));
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+ display.dispose();
+ }
+} \ No newline at end of file