summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGrant Gayed <grant_gayed@ca.ibm.com>2011-10-12 11:38:08 -0400
committerGrant Gayed <grant_gayed@ca.ibm.com>2011-10-12 11:46:52 -0400
commit09b72196659899f2c5c7eae2a4ea584ca946e10d (patch)
treeac73b1a8d0b5de25a9f0537273463fecdfe4bbc7 /examples
parentbc93deb32426c47fda429126ee3cf2a8e0a1460f (diff)
downloadeclipse.platform.swt-09b72196659899f2c5c7eae2a4ea584ca946e10d.tar.gz
eclipse.platform.swt-09b72196659899f2c5c7eae2a4ea584ca946e10d.tar.xz
eclipse.platform.swt-09b72196659899f2c5c7eae2a4ea584ca946e10d.zip
initial
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet358.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet358.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet358.java
new file mode 100644
index 0000000000..d6abf68f31
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet358.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This Example Content is intended to demonstrate
+ * usage of Eclipse technology. It is provided to you under the terms and
+ * conditions of the Eclipse Distribution License v1.0 which is available
+ * at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.snippets;
+
+/*
+ * Tree example snippet: determine which TreeItems are visible in a Tree's viewport
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+
+public class Snippet358 {
+
+public static void main(String [] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout ());
+ final Tree tree = new Tree(shell, SWT.NONE);
+ tree.setLayoutData(new GridData(200, 200));
+ for (int i = 0; i < 9; i++) {
+ TreeItem item = new TreeItem(tree, SWT.NONE);
+ item.setText("root-level item " + i);
+ for (int j = 0; j < 9; j++) {
+ new TreeItem(item, SWT.NONE).setText("item " + i + "-" + j);
+ }
+ }
+
+ Button button = new Button(shell, SWT.PUSH);
+ button.setText("Print item visibilities");
+ button.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ Rectangle treeBounds = new Rectangle(0, 0, 0, 0);
+ Point treeSize = tree.getSize();
+ treeBounds.width = treeSize.x;
+ treeBounds.height = treeSize.y;
+ TreeItem[] rootItems = tree.getItems();
+ for (int i = 0; i < rootItems.length; i++) {
+ TreeItem rootItem = rootItems[i];
+ System.out.println(rootItem.getText() + " is at least partially visible? " + treeBounds.intersects(rootItem.getBounds()));
+ TreeItem[] childItems = rootItem.getItems();
+ for (int j = 0; j < childItems.length; j++) {
+ TreeItem childItem = childItems[j];
+ System.out.println(childItem.getText() + " is at least partially visible? " + treeBounds.intersects(childItem.getBounds()));
+ }
+ }
+ }
+ });
+
+ shell.pack();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+ display.dispose ();
+}
+
+}