summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Northover <steve>2005-10-20 01:04:21 +0000
committerSteve Northover <steve>2005-10-20 01:04:21 +0000
commitb78b6b04270a187e8d56fc63fa9a145125f8535e (patch)
tree3a214297781d87d25856967a26480e506b0d9c7e
parent068cfa0a5eeab22523547e6324d2916c3eb036d4 (diff)
downloadeclipse.platform.swt-b78b6b04270a187e8d56fc63fa9a145125f8535e.tar.gz
eclipse.platform.swt-b78b6b04270a187e8d56fc63fa9a145125f8535e.tar.xz
eclipse.platform.swt-b78b6b04270a187e8d56fc63fa9a145125f8535e.zip
*** empty log message ***
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java2
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java65
2 files changed, 66 insertions, 1 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java
index c7447ab507..1d7c727deb 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java
@@ -11,7 +11,7 @@
package org.eclipse.swt.snippets;
/*
- * Virtual Table example snippet: create a table with 1,000,000 items
+ * Virtual Table example snippet: create a table with 1,000,000 items (lazy)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java
new file mode 100644
index 0000000000..c3aa9d7525
--- /dev/null
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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;
+
+/*
+ * Virtual Table example snippet: create a table with 1,000,000 items (lazy, page size 64)
+ *
+ * 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.layout.*;
+
+public class Snippet201 {
+
+static final int PAGE_SIZE = 64;
+static final int COUNT = 100000;
+
+public static void main(String[] args) {
+ Display display = new Display ();
+ final Shell shell = new Shell (display);
+ shell.setLayout (new RowLayout (SWT.VERTICAL));
+ final Table table = new Table (shell, SWT.VIRTUAL | SWT.BORDER);
+ table.addListener (SWT.SetData, new Listener () {
+ public void handleEvent (Event event) {
+ TableItem item = (TableItem) event.item;
+ int index = table.indexOf (item);
+ int start = Math.max (0, index - PAGE_SIZE + 1);
+ int end = Math.min (table.getItemCount (), index + PAGE_SIZE);
+ for (int i=start; i<end; i++) {
+ item = table.getItem (i);
+ item.setText ("Item " + i);
+ }
+ }
+ });
+ table.setLayoutData (new RowData (200, 200));
+ Button button = new Button (shell, SWT.PUSH);
+ button.setText ("Add Items");
+ final Label label = new Label(shell, SWT.NONE);
+ button.addListener (SWT.Selection, new Listener () {
+ public void handleEvent (Event event) {
+ long t1 = System.currentTimeMillis ();
+ table.setItemCount (COUNT);
+ long t2 = System.currentTimeMillis ();
+ label.setText ("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms) [page=" + PAGE_SIZE + "]");
+ shell.layout ();
+ }
+ });
+ shell.pack ();
+ shell.open ();
+ while (!shell.isDisposed ()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+ display.dispose ();
+}
+} \ No newline at end of file