summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorVeronika Irvine <veronika>2005-08-10 16:24:06 +0000
committerVeronika Irvine <veronika>2005-08-10 16:24:06 +0000
commit033a6f796fd5ad78776f6457d4b7a42c4424ab29 (patch)
treef55b26d94ea9d3dd48d24b4ef166ee6952b9772e /examples
parent1892b96441d5df27eff3326846647872f369d7a2 (diff)
downloadeclipse.platform.swt-033a6f796fd5ad78776f6457d4b7a42c4424ab29.tar.gz
eclipse.platform.swt-033a6f796fd5ad78776f6457d4b7a42c4424ab29.tar.xz
eclipse.platform.swt-033a6f796fd5ad78776f6457d4b7a42c4424ab29.zip
*** empty log message ***
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java140
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java4
2 files changed, 72 insertions, 72 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java
index 7ff4b2d234..92b36c700d 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java
@@ -24,79 +24,79 @@ import org.eclipse.swt.widgets.*;
*/
public class Snippet192 {
- public static void main(String[] args) {
- // initialize data with keys and random values
- int size = 100;
- Random random = new Random();
- final int[][] data = new int[size][];
- for (int i = 0; i < data.length; i++) {
- data[i] = new int[] {i, random.nextInt()};
+public static void main(String[] args) {
+ // initialize data with keys and random values
+ int size = 100;
+ Random random = new Random();
+ final int[][] data = new int[size][];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = new int[] {i, random.nextInt()};
+ }
+ // create a virtual table to display data
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ final Table table = new Table(shell, SWT.VIRTUAL);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ table.setItemCount(size);
+ final TableColumn column1 = new TableColumn(table, SWT.NONE);
+ column1.setText("Key");
+ column1.setWidth(200);
+ final TableColumn column2 = new TableColumn(table, SWT.NONE);
+ column2.setText("Value");
+ column2.setWidth(200);
+ table.addListener(SWT.SetData, new Listener() {
+ public void handleEvent(Event e) {
+ TableItem item = (TableItem) e.item;
+ int index = table.indexOf(item);
+ int[] datum = data[index];
+ item.setText(new String[] {Integer.toString(datum[0]),
+ Integer.toString(datum[1]) });
}
- // create a virtual table to display data
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- final Table table = new Table(shell, SWT.VIRTUAL);
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
- table.setItemCount(size);
- final TableColumn column1 = new TableColumn(table, SWT.NONE);
- column1.setText("Key");
- column1.setWidth(200);
- final TableColumn column2 = new TableColumn(table, SWT.NONE);
- column2.setText("Value");
- column2.setWidth(200);
- table.addListener(SWT.SetData, new Listener() {
- public void handleEvent(Event e) {
- TableItem item = (TableItem) e.item;
- int index = table.indexOf(item);
- int[] datum = data[index];
- item.setText(new String[] {Integer.toString(datum[0]),
- Integer.toString(datum[1]) });
+ });
+ // Add sort indicator and sort data when column selected
+ Listener sortListener = new Listener() {
+ public void handleEvent(Event e) {
+ // determine new sort column and direction
+ TableColumn sortColumn = table.getSortColumn();
+ TableColumn currentColumn = (TableColumn) e.widget;
+ int dir = table.getSortDirection();
+ if (sortColumn == currentColumn) {
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
+ } else {
+ table.setSortColumn(currentColumn);
+ dir = SWT.UP;
}
- });
- // Add sort indicator and sort data when column selected
- Listener sortListener = new Listener() {
- public void handleEvent(Event e) {
- // determine new sort column and direction
- TableColumn sortColumn = table.getSortColumn();
- TableColumn currentColumn = (TableColumn) e.widget;
- int dir = table.getSortDirection();
- if (sortColumn == currentColumn) {
- dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
- } else {
- table.setSortColumn(currentColumn);
- dir = SWT.UP;
- }
- // sort the data based on column and direction
- final int index = currentColumn == column1 ? 0 : 1;
- final int direction = dir;
- Arrays.sort(data, new Comparator() {
- public int compare(Object arg0, Object arg1) {
- int[] a = (int[]) arg0;
- int[] b = (int[]) arg1;
- if (a[index] == b[index]) return 0;
- if (direction == SWT.UP) {
- return a[index] < b[index] ? -1 : 1;
- }
- return a[index] < b[index] ? 1 : -1;
+ // sort the data based on column and direction
+ final int index = currentColumn == column1 ? 0 : 1;
+ final int direction = dir;
+ Arrays.sort(data, new Comparator() {
+ public int compare(Object arg0, Object arg1) {
+ int[] a = (int[]) arg0;
+ int[] b = (int[]) arg1;
+ if (a[index] == b[index]) return 0;
+ if (direction == SWT.UP) {
+ return a[index] < b[index] ? -1 : 1;
}
- });
- // update data displayed in table
- table.setSortDirection(dir);
- table.clearAll();
- }
- };
- column1.addListener(SWT.Selection, sortListener);
- column2.addListener(SWT.Selection, sortListener);
- table.setSortColumn(column1);
- table.setSortDirection(SWT.UP);
- shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
+ return a[index] < b[index] ? 1 : -1;
+ }
+ });
+ // update data displayed in table
+ table.setSortDirection(dir);
+ table.clearAll();
}
- display.dispose();
+ };
+ column1.addListener(SWT.Selection, sortListener);
+ column2.addListener(SWT.Selection, sortListener);
+ table.setSortColumn(column1);
+ table.setSortDirection(SWT.UP);
+ shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
}
+ display.dispose();
+}
} \ No newline at end of file
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java
index 9f25acf2a6..87971421ca 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java
@@ -68,8 +68,8 @@ public static void main (String [] args) {
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
table.setSortColumn(column1);
- table.setSortDirection(SWT.UP);
- shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
+ table.setSortDirection(SWT.UP);
+ shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();