diff options
Diffstat (limited to 'examples/org.eclipse.swt.snippets/src/org')
193 files changed, 0 insertions, 13739 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java deleted file mode 100644 index 0b0fa40819..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: Hello World - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet1 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell(display); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet10.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet10.java deleted file mode 100644 index 073b040665..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet10.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Drawing with transformations, paths and alpha blending - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet10 { - public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setText("Advanced Graphics"); - FontData fd = shell.getFont().getFontData()[0]; - final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC); - final Image image = new Image(display, 640, 480); - final Rectangle rect = image.getBounds(); - GC gc = new GC(image); - gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); - gc.fillOval(rect.x, rect.y, rect.width, rect.height); - gc.dispose(); - shell.addListener(SWT.Paint, new Listener() { - public void handleEvent(Event event) { - GC gc = event.gc; - Transform tr = new Transform(display); - tr.translate(50, 120); - tr.rotate(-30); - gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2); - gc.setAlpha(100); - gc.setTransform(tr); - Path path = new Path(display); - path.addString("SWT", 0, 0, font); - gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); - gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); - gc.fillPath(path); - gc.drawPath(path); - tr.dispose(); - path.dispose(); - } - }); - shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2)); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - image.dispose(); - font.dispose(); - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet100.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet100.java deleted file mode 100644 index 7c44afa1f6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet100.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Font example snippet: create a large font for use by a text widget - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet100 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setBounds(10, 10, 200, 200); - Text text = new Text(shell, SWT.MULTI); - text.setBounds(10, 10, 150, 150); - Font initialFont = text.getFont(); - FontData[] fontData = initialFont.getFontData(); - for (int i = 0; i < fontData.length; i++) { - fontData[i].setHeight(24); - } - Font newFont = new Font(display, fontData); - text.setFont(newFont); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - newFont.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet101.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet101.java deleted file mode 100644 index 81f1b5f0a8..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet101.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: insert a table item (at an index) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet101 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Table table = new Table (shell, SWT.BORDER | SWT.MULTI); - table.setSize (200, 200); - for (int i=0; i<12; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("Item " + i); - } - TableItem item = new TableItem (table, SWT.NONE, 1); - item.setText ("*** New Item " + table.indexOf (item) + " ***"); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} - diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet102.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet102.java deleted file mode 100644 index d60b369382..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet102.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tree example snippet: insert a tree item (at an index) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet102 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Tree tree = new Tree (shell, SWT.BORDER | SWT.MULTI); - tree.setSize (200, 200); - for (int i=0; i<12; i++) { - TreeItem item = new TreeItem (tree, SWT.NONE); - item.setText ("Item " + i); - } - TreeItem item = new TreeItem (tree, SWT.NONE, 1); - TreeItem [] items = tree.getItems (); - int index = 0; - while (index < items.length && items [index] != item) index++; - item.setText ("*** New Item " + index + " ***"); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet103.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet103.java deleted file mode 100644 index 99e615a068..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet103.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: update table item text - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet103 { - -static char content = 'a'; -public static void main(String[] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - shell.setBounds(10, 10, 200, 240); - Table table = new Table(shell, SWT.NONE); - table.setBounds(10, 10, 160, 160); - - final TableItem[] items = new TableItem[4]; - for (int i = 0; i < 4; i++) { - new TableColumn(table, SWT.NONE).setWidth(40); - } - for (int i = 0; i < 4; i++) { - items[i] = new TableItem(table, SWT.NONE); - populateItem(items[i]); - } - - Button button = new Button(shell, SWT.PUSH); - button.setBounds(10, 180, 50, 30); - button.setText("Change"); - button.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - for (int i = 0; i < 4; i++) { - populateItem(items[i]); - } - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} - -static void populateItem(TableItem item) { - String stringContent = String.valueOf(content); - item.setText( - new String[] { - stringContent, - stringContent, - stringContent, - stringContent }); - content++; - if (content > 'z') content = 'a'; -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet104.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet104.java deleted file mode 100644 index 66d2443b52..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet104.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: create a splash screen - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet104 { - -public static void main(String[] args) { - final Display display = new Display(); - final int [] count = new int [] {4}; - final Image image = new Image(display, 300, 300); - final Shell splash = new Shell(SWT.ON_TOP); - final ProgressBar bar = new ProgressBar(splash, SWT.NONE); - bar.setMaximum(count[0]); - Label label = new Label(splash, SWT.NONE); - label.setImage(image); - FormLayout layout = new FormLayout(); - splash.setLayout(layout); - FormData labelData = new FormData (); - labelData.right = new FormAttachment (100, 0); - labelData.bottom = new FormAttachment (100, 0); - label.setLayoutData(labelData); - FormData progressData = new FormData (); - progressData.left = new FormAttachment (0, 5); - progressData.right = new FormAttachment (100, -5); - progressData.bottom = new FormAttachment (100, -5); - bar.setLayoutData(progressData); - splash.pack(); - Rectangle splashRect = splash.getBounds(); - Rectangle displayRect = display.getBounds(); - int x = (displayRect.width - splashRect.width) / 2; - int y = (displayRect.height - splashRect.height) / 2; - splash.setLocation(x, y); - splash.open(); - display.asyncExec(new Runnable() { - public void run() { - Shell [] shells = new Shell[count[0]]; - for (int i=0; i<count[0]; i++) { - shells [i] = new Shell(display); - shells [i].setSize (300, 300); - shells [i].addListener(SWT.Close, new Listener() { - public void handleEvent (Event e) { - --count[0]; - } - }); - bar.setSelection(i+1); - try {Thread.sleep(1000);} catch (Throwable e) {} - } - splash.close(); - image.dispose(); - for (int i=0; i<count[0]; i++) { - shells [i].open(); - } - } - }); - while (count [0] != 0) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose(); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet105.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet105.java deleted file mode 100644 index 9dcc8f1080..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet105.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Program example snippet: invoke an external batch file - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.program.*; -import org.eclipse.swt.widgets.*; - -public class Snippet105 { - -public static void main(String[] args) { - Display display = new Display (); - Program.launch("c:\\cygwin\\cygwin.bat"); - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet106.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet106.java deleted file mode 100644 index 36da51f301..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet106.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: insert a table column (at an index) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet106 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new RowLayout (SWT.VERTICAL)); - final Table table = new Table (shell, SWT.BORDER | SWT.MULTI); - table.setHeaderVisible (true); - for (int i=0; i<4; i++) { - TableColumn column = new TableColumn (table, SWT.NONE); - column.setText ("Column " + i); - } - final TableColumn [] columns = table.getColumns (); - for (int i=0; i<12; i++) { - TableItem item = new TableItem (table, SWT.NONE); - for (int j=0; j<columns.length; j++) { - item.setText (j, "Item " + i); - } - } - for (int i=0; i<columns.length; i++) columns [i].pack (); - Button button = new Button (shell, SWT.PUSH); - final int index = 1; - button.setText ("Insert Column " + index + "a"); - button.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - TableColumn column = new TableColumn (table, SWT.NONE, index); - column.setText ("Column " + index + "a"); - TableItem [] items = table.getItems (); - for (int i=0; i<items.length; i++) { - items [i].setText (index, "Item " + i + "a"); - } - column.pack (); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet107.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet107.java deleted file mode 100644 index 5e4e65ec40..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet107.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; -/* - * Sash example snippet: implement a simple splitter (with a 20 pixel limit) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet107 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - Button button1 = new Button (shell, SWT.PUSH); - button1.setText ("Button 1"); - final Sash sash = new Sash (shell, SWT.VERTICAL); - Button button2 = new Button (shell, SWT.PUSH); - button2.setText ("Button 2"); - - final FormLayout form = new FormLayout (); - shell.setLayout (form); - - FormData button1Data = new FormData (); - button1Data.left = new FormAttachment (0, 0); - button1Data.right = new FormAttachment (sash, 0); - button1Data.top = new FormAttachment (0, 0); - button1Data.bottom = new FormAttachment (100, 0); - button1.setLayoutData (button1Data); - - final int limit = 20, percent = 50; - final FormData sashData = new FormData (); - sashData.left = new FormAttachment (percent, 0); - sashData.top = new FormAttachment (0, 0); - sashData.bottom = new FormAttachment (100, 0); - sash.setLayoutData (sashData); - sash.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - Rectangle sashRect = sash.getBounds (); - Rectangle shellRect = shell.getClientArea (); - int right = shellRect.width - sashRect.width - limit; - e.x = Math.max (Math.min (e.x, right), limit); - if (e.x != sashRect.x) { - sashData.left = new FormAttachment (0, e.x); - shell.layout (); - } - } - }); - - FormData button2Data = new FormData (); - button2Data.left = new FormAttachment (sash, 0); - button2Data.right = new FormAttachment (100, 0); - button2Data.top = new FormAttachment (0, 0); - button2Data.bottom = new FormAttachment (100, 0); - button2.setLayoutData (button2Data); - - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet108.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet108.java deleted file mode 100644 index c45b2a5e19..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet108.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Button example snippet: set the default button - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet108 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Label label = new Label (shell, SWT.NONE); - label.setText ("Enter your name:"); - Text text = new Text (shell, SWT.BORDER); - text.setLayoutData (new RowData (100, SWT.DEFAULT)); - Button ok = new Button (shell, SWT.PUSH); - ok.setText ("Ok"); - Button cancel = new Button (shell, SWT.PUSH); - cancel.setText ("Cancel"); - shell.setDefaultButton (cancel); - shell.setLayout (new RowLayout ()); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet109.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet109.java deleted file mode 100644 index 9ee934dd96..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet109.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * SashForm example snippet: create a sash form with three children - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet109 { - -public static void main (String [] args) { - final Display display = new Display (); - Shell shell = new Shell(display); - shell.setLayout (new FillLayout()); - - SashForm form = new SashForm(shell,SWT.HORIZONTAL); - form.setLayout(new FillLayout()); - - Composite child1 = new Composite(form,SWT.NONE); - child1.setLayout(new FillLayout()); - new Label(child1,SWT.NONE).setText("Label in pane 1"); - - Composite child2 = new Composite(form,SWT.NONE); - child2.setLayout(new FillLayout()); - new Button(child2,SWT.PUSH).setText("Button in pane2"); - - Composite child3 = new Composite(form,SWT.NONE); - child3.setLayout(new FillLayout()); - new Label(child3,SWT.PUSH).setText("Label in pane3"); - - form.setWeights(new int[] {30,40,30}); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet11.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet11.java deleted file mode 100644 index 15ee235e48..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet11.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: set the selection (i-beam) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet11 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Text text = new Text (shell, SWT.BORDER | SWT.V_SCROLL); - text.setBounds (10, 10, 100, 100); - for (int i=0; i<16; i++) { - text.append ("Line " + i + "\n"); - } - shell.open (); - text.setSelection (30); - System.out.println (text.getCaretLocation ()); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet110.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet110.java deleted file mode 100644 index 14d36c2afb..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet110.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: find a table cell from mouse down (works for any table style) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; - -public class Snippet110 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Table table = new Table (shell, SWT.BORDER | SWT.V_SCROLL); - table.setHeaderVisible (true); - table.setLinesVisible (true); - final int rowCount = 64, columnCount = 4; - for (int i=0; i < columnCount; i++) { - TableColumn column = new TableColumn (table, SWT.NONE); - column.setText ("Column " + i); - } - for (int i=0; i < rowCount; i++) { - TableItem item = new TableItem (table, SWT.NONE); - for (int j=0; j < columnCount; j++) { - item.setText (j, "Item " + i + "-" + j); - } - } - for (int i=0; i < columnCount; i++) { - table.getColumn (i).pack (); - } - Point size = table.computeSize (SWT.DEFAULT, 200); - table.setSize (size); - shell.pack (); - table.addListener (SWT.MouseDown, new Listener () { - public void handleEvent (Event event) { - Rectangle clientArea = table.getClientArea (); - Point pt = new Point (event.x, event.y); - int index = table.getTopIndex (); - while (index < table.getItemCount ()) { - boolean visible = false; - TableItem item = table.getItem (index); - for (int i=0; i < columnCount; i++) { - Rectangle rect = item.getBounds (i); - if (rect.contains (pt)) { - System.out.println ("Item " + index + "-" + i); - } - if (!visible && rect.intersects (clientArea)) { - visible = true; - } - } - if (!visible) return; - index++; - } - } - }); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet111.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet111.java deleted file mode 100644 index ec9a671559..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet111.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * TreeEditor example snippet: edit the text of a tree item (in place, fancy) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.custom.*; - -public class Snippet111 { - -public static void main (String [] args) { - final Display display = new Display (); - final Color black = display.getSystemColor (SWT.COLOR_BLACK); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - final Tree tree = new Tree (shell, SWT.BORDER); - for (int i=0; i<16; i++) { - TreeItem itemI = new TreeItem (tree, SWT.NONE); - itemI.setText ("Item " + i); - for (int j=0; j<16; j++) { - TreeItem itemJ = new TreeItem (itemI, SWT.NONE); - itemJ.setText ("Item " + j); - } - } - final TreeItem [] lastItem = new TreeItem [1]; - final TreeEditor editor = new TreeEditor (tree); - tree.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - final TreeItem item = (TreeItem) event.item; - if (item != null && item == lastItem [0]) { - boolean isCarbon = SWT.getPlatform ().equals ("carbon"); - final Composite composite = new Composite (tree, SWT.NONE); - if (!isCarbon) composite.setBackground (black); - final Text text = new Text (composite, SWT.NONE); - final int inset = isCarbon ? 0 : 1; - composite.addListener (SWT.Resize, new Listener () { - public void handleEvent (Event e) { - Rectangle rect = composite.getClientArea (); - text.setBounds (rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2); - } - }); - Listener textListener = new Listener () { - public void handleEvent (final Event e) { - switch (e.type) { - case SWT.FocusOut: - item.setText (text.getText ()); - composite.dispose (); - break; - case SWT.Verify: - String newText = text.getText (); - String leftText = newText.substring (0, e.start); - String rightText = newText.substring (e.end, newText.length ()); - GC gc = new GC (text); - Point size = gc.textExtent (leftText + e.text + rightText); - gc.dispose (); - size = text.computeSize (size.x, SWT.DEFAULT); - editor.horizontalAlignment = SWT.LEFT; - Rectangle itemRect = item.getBounds (), rect = tree.getClientArea (); - editor.minimumWidth = Math.max (size.x, itemRect.width) + inset * 2; - int left = itemRect.x, right = rect.x + rect.width; - editor.minimumWidth = Math.min (editor.minimumWidth, right - left); - editor.minimumHeight = size.y + inset * 2; - editor.layout (); - break; - case SWT.Traverse: - switch (e.detail) { - case SWT.TRAVERSE_RETURN: - item.setText (text.getText ()); - //FALL THROUGH - case SWT.TRAVERSE_ESCAPE: - composite.dispose (); - e.doit = false; - } - break; - } - } - }; - text.addListener (SWT.FocusOut, textListener); - text.addListener (SWT.Traverse, textListener); - text.addListener (SWT.Verify, textListener); - editor.setEditor (composite, item); - text.setText (item.getText ()); - text.selectAll (); - text.setFocus (); - } - lastItem [0] = item; - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet112.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet112.java deleted file mode 100644 index 864feafec2..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet112.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Image example snippet: display an image in a group - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet112 { - -public static void main (String [] args) { - Display display = new Display (); - final Image image = new Image (display, 20, 20); - Color color = display.getSystemColor (SWT.COLOR_RED); - GC gc = new GC (image); - gc.setBackground (color); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); - color.dispose (); - - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - Group group = new Group (shell, SWT.NONE); - group.setLayout (new FillLayout ()); - group.setText ("a square"); - Canvas canvas = new Canvas (group, SWT.NONE); - canvas.addPaintListener (new PaintListener () { - public void paintControl (PaintEvent e) { - e.gc.drawImage (image, 0, 0); - } - }); - - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) - display.sleep (); - } - image.dispose (); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet113.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet113.java deleted file mode 100644 index 4fe45df8c3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet113.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: detect a selection or check event in a table (SWT.CHECK) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet113 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Table table = new Table (shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - for (int i=0; i<12; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("Item " + i); - } - table.setSize (100, 100); - table.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - String string = event.detail == SWT.CHECK ? "Checked" : "Selected"; - System.out.println (event.item + " " + string); - } - }); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet114.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet114.java deleted file mode 100644 index 6159794675..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet114.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tree example snippet: detect a selection or check event in a tree (SWT.CHECK) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet114 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Tree tree = new Tree (shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - for (int i=0; i<12; i++) { - TreeItem item = new TreeItem (tree, SWT.NONE); - item.setText ("Item " + i); - } - tree.setSize (100, 100); - tree.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - String string = event.detail == SWT.CHECK ? "Checked" : "Selected"; - System.out.println (event.item + " " + string); - } - }); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet115.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet115.java deleted file mode 100644 index 4d353f7390..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet115.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Composite example snippet: force radio behavior on two different composites - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet115 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new RowLayout (SWT.VERTICAL)); - Composite c1 = new Composite (shell, SWT.BORDER | SWT.NO_RADIO_GROUP); - c1.setLayout (new RowLayout ()); - Composite c2 = new Composite (shell, SWT.BORDER | SWT.NO_RADIO_GROUP); - c2.setLayout (new RowLayout ()); - final Composite [] composites = new Composite [] {c1, c2}; - Listener radioGroup = new Listener () { - public void handleEvent (Event event) { - for (int i=0; i<composites.length; i++) { - Composite composite = composites [i]; - Control [] children = composite.getChildren (); - for (int j=0; j<children.length; j++) { - Control child = children [j]; - if (child instanceof Button) { - Button button = (Button) child; - if ((button.getStyle () & SWT.RADIO) != 0) button.setSelection (false); - } - } - } - Button button = (Button) event.widget; - button.setSelection (true); - } - }; - for (int i=0; i<4; i++) { - Button button = new Button (c1, SWT.RADIO); - button.setText ("Button " + i); - button.addListener (SWT.Selection, radioGroup); - } - for (int i=0; i<4; i++) { - Button button = new Button (c2, SWT.RADIO); - button.setText ("Button " + (i + 4)); - button.addListener (SWT.Selection, radioGroup); - } - shell.pack (); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet116.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet116.java deleted file mode 100644 index 9a3dbf2d16..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet116.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: stop CR from going to the default button - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet116 { -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - text.setText("Here is some text"); - text.addSelectionListener(new SelectionAdapter() { - public void widgetDefaultSelected(SelectionEvent e) { - System.out.println("Text default selected (overrides default button)"); - } - }); - text.addTraverseListener(new TraverseListener() { - public void keyTraversed(TraverseEvent e) { - if (e.detail == SWT.TRAVERSE_RETURN) { - e.doit = false; - e.detail = SWT.TRAVERSE_NONE; - } - } - }); - Button button = new Button(shell, SWT.PUSH); - button.setText("Ok"); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - System.out.println("Button selected"); - } - }); - shell.setDefaultButton(button); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet117.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet117.java deleted file mode 100644 index 8e454d9694..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet117.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: add a select all menu item to the control - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet117 { -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Text t = new Text(shell, SWT.BORDER | SWT.MULTI); - - Menu bar = new Menu (shell, SWT.BAR); - shell.setMenuBar (bar); - MenuItem editItem = new MenuItem (bar, SWT.CASCADE); - editItem.setText ("Edit"); - Menu submenu = new Menu (shell, SWT.DROP_DOWN); - editItem.setMenu (submenu); - - MenuItem item = new MenuItem (submenu, SWT.PUSH); - item.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - t.selectAll(); - } - }); - item.setText ("Select &All\tCtrl+A"); - item.setAccelerator (SWT.CTRL + 'A'); - - // Note that as long as your application has not overridden - // the global accelerators for copy, paste, and cut - //(CTRL+C or CTRL+INSERT, CTRL+V or SHIFT+INSERT, and CTRL+X or SHIFT+DELETE) - // these behaviours are already available by default. - // If your application overrides these accelerators, - // you will need to call Text.copy(), Text.paste() and Text.cut() - // from the Selection callback for the accelerator when the - // text widget has focus. - - shell.setSize(200, 200); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet118.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet118.java deleted file mode 100644 index 17c0a91137..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet118.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Cursor example snippet: create a color cursor from an image file - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet118 { - -public static void main (String [] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setSize(150, 150); - final Cursor[] cursor = new Cursor[1]; - Button button = new Button(shell, SWT.PUSH); - button.setText("Change cursor"); - Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); - button.setSize(size); - button.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - FileDialog dialog = new FileDialog(shell); - dialog.setFilterExtensions(new String[] {"*.ico", "*.gif", "*.*"}); - String name = dialog.open(); - if (name == null) return; - ImageData image = new ImageData(name); - Cursor oldCursor = cursor[0]; - cursor[0] = new Cursor(display, image, 0, 0); - shell.setCursor(cursor[0]); - if (oldCursor != null) oldCursor.dispose(); - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - if (cursor[0] != null) cursor[0].dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet119.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet119.java deleted file mode 100644 index 8216bad547..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet119.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Cursor example snippet: create a color cursor from a source and a mask - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet119 { - -static byte[] srcData = { - (byte)0x11, (byte)0x11, (byte)0x11, (byte)0x00, (byte)0x00, (byte)0x11, (byte)0x11, (byte)0x11, - (byte)0x11, (byte)0x10, (byte)0x00, (byte)0x01, (byte)0x10, (byte)0x00, (byte)0x01, (byte)0x11, - (byte)0x11, (byte)0x00, (byte)0x22, (byte)0x01, (byte)0x10, (byte)0x33, (byte)0x00, (byte)0x11, - (byte)0x10, (byte)0x02, (byte)0x22, (byte)0x01, (byte)0x10, (byte)0x33, (byte)0x30, (byte)0x01, - (byte)0x10, (byte)0x22, (byte)0x22, (byte)0x01, (byte)0x10, (byte)0x33, (byte)0x33, (byte)0x01, - (byte)0x10, (byte)0x22, (byte)0x22, (byte)0x01, (byte)0x10, (byte)0x33, (byte)0x33, (byte)0x01, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x01, (byte)0x11, (byte)0x11, (byte)0x01, (byte)0x10, (byte)0x11, (byte)0x11, (byte)0x10, - (byte)0x01, (byte)0x11, (byte)0x11, (byte)0x01, (byte)0x10, (byte)0x11, (byte)0x11, (byte)0x10, - (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, - (byte)0x10, (byte)0x44, (byte)0x44, (byte)0x01, (byte)0x10, (byte)0x55, (byte)0x55, (byte)0x01, - (byte)0x10, (byte)0x44, (byte)0x44, (byte)0x01, (byte)0x10, (byte)0x55, (byte)0x55, (byte)0x01, - (byte)0x10, (byte)0x04, (byte)0x44, (byte)0x01, (byte)0x10, (byte)0x55, (byte)0x50, (byte)0x01, - (byte)0x11, (byte)0x00, (byte)0x44, (byte)0x01, (byte)0x10, (byte)0x55, (byte)0x00, (byte)0x11, - (byte)0x11, (byte)0x10, (byte)0x00, (byte)0x01, (byte)0x10, (byte)0x00, (byte)0x01, (byte)0x11, - (byte)0x11, (byte)0x11, (byte)0x11, (byte)0x00, (byte)0x00, (byte)0x11, (byte)0x11, (byte)0x11, -}; - -static byte[] mskData = { - (byte)0x03, (byte)0xc0, - (byte)0x1f, (byte)0xf8, - (byte)0x3f, (byte)0xfc, - (byte)0x7f, (byte)0xfe, - (byte)0x7f, (byte)0xfe, - (byte)0x7f, (byte)0xfe, - (byte)0xff, (byte)0xff, - (byte)0xfe, (byte)0x7f, - (byte)0xfe, (byte)0x7f, - (byte)0xff, (byte)0xff, - (byte)0x7f, (byte)0xfe, - (byte)0x7f, (byte)0xfe, - (byte)0x7f, (byte)0xfe, - (byte)0x3f, (byte)0xfc, - (byte)0x1f, (byte)0xf8, - (byte)0x03, (byte)0xc0 -}; - -public static void main (String [] args) { - Display display = new Display(); - Color white = display.getSystemColor (SWT.COLOR_WHITE); - Color black = display.getSystemColor (SWT.COLOR_BLACK); - Color yellow = display.getSystemColor (SWT.COLOR_YELLOW); - Color red = display.getSystemColor (SWT.COLOR_RED); - Color green = display.getSystemColor (SWT.COLOR_GREEN); - Color blue = display.getSystemColor (SWT.COLOR_BLUE); - - //Create a source ImageData of depth 4 - PaletteData palette = new PaletteData (new RGB[] { - black.getRGB(), white.getRGB(), yellow.getRGB(), - red.getRGB(), blue.getRGB(), green.getRGB()}); - ImageData sourceData = new ImageData (16, 16, 4, palette, 1, srcData); - - //Create a mask ImageData of depth 1 (monochrome) - palette = new PaletteData (new RGB [] {black.getRGB(), white.getRGB(),}); - ImageData maskData = new ImageData (16, 16, 1, palette, 1, mskData); - - //Set mask - sourceData.maskData = maskData.data; - sourceData.maskPad = maskData.scanlinePad; - - //Create cursor - Cursor cursor = new Cursor(display, sourceData, 10, 10); - - //Remove mask to draw them separately just to show what they look like - sourceData.maskData = null; - sourceData.maskPad = -1; - - Shell shell = new Shell(display); - final Image source = new Image (display,sourceData); - final Image mask = new Image (display, maskData); - shell.addPaintListener(new PaintListener() { - public void paintControl(PaintEvent e) { - GC gc = e.gc; - int x = 10, y = 10; - String stringSource = "source: "; - String stringMask = "mask: "; - gc.drawString(stringSource, x, y); - gc.drawString(stringMask, x, y + 30); - x += Math.max(gc.stringExtent(stringSource).x, gc.stringExtent(stringMask).x); - gc.drawImage(source, x, y); - gc.drawImage(mask, x, y + 30); - } - }); - shell.setSize(150, 150); - shell.open(); - shell.setCursor(cursor); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - cursor.dispose(); - source.dispose(); - mask.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet12.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet12.java deleted file mode 100644 index 3c7b720910..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet12.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: set the selection (start, end) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet12 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Text text = new Text (shell, SWT.BORDER | SWT.V_SCROLL); - text.setBounds (10, 10, 100, 100); - for (int i=0; i<16; i++) { - text.append ("Line " + i + "\n"); - } - shell.open (); - text.setSelection (30, 38); - System.out.println (text.getCaretLocation ()); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet120.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet120.java deleted file mode 100644 index f96dc0f4db..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet120.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Monitor example snippet: center a shell on the primary monitor - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet120 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setSize (200, 200); - Monitor primary = display.getPrimaryMonitor (); - Rectangle bounds = primary.getBounds (); - Rectangle rect = shell.getBounds (); - int x = bounds.x + (bounds.width - rect.width) / 2; - int y = bounds.y + (bounds.height - rect.height) / 2; - shell.setLocation (x, y); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet121.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet121.java deleted file mode 100644 index b7e2b138cb..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet121.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: prompt for a password (set the echo character) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet121 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - Text text = new Text (shell, SWT.SINGLE | SWT.BORDER); - text.setEchoChar ('*'); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet122.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet122.java deleted file mode 100644 index 1de9da6c0e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet122.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Clipboard example snippet: enable/disable menu depending on clipboard content availability - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet122 { - -public static void main(String[] args) { - Display display = new Display(); - final Clipboard cb = new Clipboard(display); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP); - Menu menu = new Menu(shell, SWT.POP_UP); - final MenuItem copyItem = new MenuItem(menu, SWT.PUSH); - copyItem.setText("Copy"); - copyItem.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - String selection = text.getSelectionText(); - if (selection.length() == 0) return; - Object[] data = new Object[]{selection}; - Transfer[] types = new Transfer[] {TextTransfer.getInstance()}; - cb.setContents(data, types); - } - }); - final MenuItem pasteItem = new MenuItem(menu, SWT.PUSH); - pasteItem.setText ("Paste"); - pasteItem.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - String string = (String)(cb.getContents(TextTransfer.getInstance())); - if (string != null) text.insert(string); - } - }); - menu.addMenuListener(new MenuAdapter() { - public void menuShown(MenuEvent e) { - // is copy valid? - String selection = text.getSelectionText(); - copyItem.setEnabled(selection.length() > 0); - // is paste valid? - TransferData[] available = cb.getAvailableTypes(); - boolean enabled = false; - for (int i = 0; i < available.length; i++) { - if (TextTransfer.getInstance().isSupportedType(available[i])) { - enabled = true; - break; - } - } - pasteItem.setEnabled(enabled); - } - }); - text.setMenu (menu); - - shell.setSize(200, 200); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - cb.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet123.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet123.java deleted file mode 100644 index 0544ace0b6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet123.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * OLE and ActiveX example snippet: get events from IE control - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.ole.win32.*; -import org.eclipse.swt.internal.ole.win32.*; - -public class Snippet123 { - -public static void main(String[] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - OleControlSite controlSite; - try { - OleFrame frame = new OleFrame(shell, SWT.NONE); - controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); - controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); - } catch (SWTError e) { - System.out.println("Unable to open activeX control"); - return; - } - shell.open(); - - // IWebBrowser - final OleAutomation webBrowser = new OleAutomation(controlSite); - - // When a new document is loaded, access the document object for the new page. - int DownloadComplete = 104; - controlSite.addEventListener(DownloadComplete, new OleListener() { - public void handleEvent(OleEvent event) { - int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[]{"Document"}); - if (htmlDocumentID == null) return; - Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]); - if (pVarResult == null || pVarResult.getType() == 0) return; - //IHTMLDocument2 - OleAutomation htmlDocument = pVarResult.getAutomation(); - - // Request to be notified of click, double click and key down events - EventDispatch myDispatch = new EventDispatch(EventDispatch.onclick); - IDispatch idispatch = new IDispatch(myDispatch.getAddress()); - Variant dispatch = new Variant(idispatch); - htmlDocument.setProperty(EventDispatch.onclick, dispatch); - - myDispatch = new EventDispatch(EventDispatch.ondblclick); - idispatch = new IDispatch(myDispatch.getAddress()); - dispatch = new Variant(idispatch); - htmlDocument.setProperty(EventDispatch.ondblclick, dispatch); - - myDispatch = new EventDispatch(EventDispatch.onkeydown); - idispatch = new IDispatch(myDispatch.getAddress()); - dispatch = new Variant(idispatch); - htmlDocument.setProperty(EventDispatch.onkeydown, dispatch); - - //Remember to release OleAutomation Object - htmlDocument.dispose(); - } - }); - - // Navigate to a web site - int[] ids = webBrowser.getIDsOfNames(new String[]{"Navigate", "URL"}); - Variant[] rgvarg = new Variant[] {new Variant("http://www.google.com")}; - int[] rgdispidNamedArgs = new int[]{ids[1]}; - webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - //Remember to release OleAutomation Object - webBrowser.dispose(); - display.dispose(); - -} -} -// EventDispatch implements a simple IDispatch interface which will be called -// when the event is fired. -class EventDispatch { - private COMObject iDispatch; - private int refCount = 0; - private int eventID; - - final static int onhelp = 0x8001177d; - final static int onclick = 0x80011778; - final static int ondblclick = 0x80011779; - final static int onkeyup = 0x80011776; - final static int onkeydown = 0x80011775; - final static int onkeypress = 0x80011777; - final static int onmouseup = 0x80011773; - final static int onmousedown = 0x80011772; - final static int onmousemove = 0x80011774; - final static int onmouseout = 0x80011771; - final static int onmouseover = 0x80011770; - final static int onreadystatechange = 0x80011789; - final static int onafterupdate = 0x80011786; - final static int onrowexit= 0x80011782; - final static int onrowenter = 0x80011783; - final static int ondragstart = 0x80011793; - final static int onselectstart = 0x80011795; - - EventDispatch(int eventID) { - this.eventID = eventID; - createCOMInterfaces(); - } - int getAddress() { - return iDispatch.getAddress(); - } - private void createCOMInterfaces() { - iDispatch = new COMObject(new int[]{2, 0, 0, 1, 3, 4, 8}){ - public int method0(int[] args) {return QueryInterface(args[0], args[1]);} - public int method1(int[] args) {return AddRef();} - public int method2(int[] args) {return Release();} - // method3 GetTypeInfoCount - not implemented - // method4 GetTypeInfo - not implemented - // method5 GetIDsOfNames - not implemented - public int method6(int[] args) {return Invoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);} - }; - } - private void disposeCOMInterfaces() { - if (iDispatch != null) - iDispatch.dispose(); - iDispatch = null; - - } - private int AddRef() { - refCount++; - return refCount; - } - private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags, int pDispParams, int pVarResult, int pExcepInfo, int pArgErr) { - switch (eventID) { - case onhelp: System.out.println("onhelp"); break; - case onclick: System.out.println("onclick"); break; - case ondblclick: System.out.println("ondblclick"); break; - case onkeyup: System.out.println("onkeyup"); break; - case onkeydown: System.out.println("onkeydown"); break; - case onkeypress: System.out.println("onkeypress"); break; - case onmouseup: System.out.println("onmouseup"); break; - case onmousedown: System.out.println("onmousedown"); break; - case onmousemove: System.out.println("onmousemove"); break; - case onmouseout: System.out.println("onmouseout"); break; - case onmouseover: System.out.println("onmouseover"); break; - case onreadystatechange: System.out.println("onreadystatechange"); break; - case onafterupdate: System.out.println("onafterupdate"); break; - case onrowexit: System.out.println("onrowexit"); break; - case onrowenter: System.out.println("onrowenter"); break; - case ondragstart: System.out.println("ondragstart"); break; - case onselectstart: System.out.println("onselectstart"); break; - } - return COM.S_OK; - } - private int QueryInterface(int riid, int ppvObject) { - if (riid == 0 || ppvObject == 0) return COM.E_INVALIDARG; - GUID guid = new GUID(); - COM.MoveMemory(guid, riid, GUID.sizeof); - - if ( COM.IsEqualGUID(guid, COM.IIDIUnknown) || COM.IsEqualGUID(guid, COM.IIDIDispatch)) { - COM.MoveMemory(ppvObject, new int[] {iDispatch.getAddress()}, 4); - AddRef(); - return COM.S_OK; - } - COM.MoveMemory(ppvObject, new int[] {0}, 4); - return COM.E_NOINTERFACE; - } - int Release() { - refCount--; - if (refCount == 0) { - disposeCOMInterfaces(); - } - return refCount; - } -} - diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet124.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet124.java deleted file mode 100644 index 9229a72bb9..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet124.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * TableEditor example snippet: edit a cell in a table (in place, fancy) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.custom.*; - -public class Snippet124 { -public static void main (String[] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - final Table table = new Table(shell, SWT.BORDER | SWT.MULTI); - table.setLinesVisible (true); - for (int i=0; i<3; i++) { - TableColumn column = new TableColumn (table, SWT.NONE); - column.setWidth(100); - } - for (int i=0; i<3; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText(new String [] {"" + i, "" + i , "" + i}); - } - final TableEditor editor = new TableEditor (table); - editor.horizontalAlignment = SWT.LEFT; - editor.grabHorizontal = true; - table.addListener (SWT.MouseDown, new Listener () { - public void handleEvent (Event event) { - Rectangle clientArea = table.getClientArea (); - Point pt = new Point (event.x, event.y); - int index = table.getTopIndex (); - while (index < table.getItemCount ()) { - boolean visible = false; - final TableItem item = table.getItem (index); - for (int i=0; i<table.getColumnCount (); i++) { - Rectangle rect = item.getBounds (i); - if (rect.contains (pt)) { - final int column = i; - final Text text = new Text (table, SWT.NONE); - Listener textListener = new Listener () { - public void handleEvent (final Event e) { - switch (e.type) { - case SWT.FocusOut: - item.setText (column, text.getText ()); - text.dispose (); - break; - case SWT.Traverse: - switch (e.detail) { - case SWT.TRAVERSE_RETURN: - item.setText (column, text.getText ()); - //FALL THROUGH - case SWT.TRAVERSE_ESCAPE: - text.dispose (); - e.doit = false; - } - break; - } - } - }; - text.addListener (SWT.FocusOut, textListener); - text.addListener (SWT.Traverse, textListener); - editor.setEditor (text, item, i); - text.setText (item.getText (i)); - text.selectAll (); - text.setFocus (); - return; - } - if (!visible && rect.intersects (clientArea)) { - visible = true; - } - } - if (!visible) return; - index++; - } - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java deleted file mode 100644 index 3e645e75d4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Tool Tips example snippet: create fake tool tips for items in a table - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet125 { - -public static void main (String[] args) { - final Display display = new Display (); - final Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - final Table table = new Table (shell, SWT.BORDER); - for (int i = 0; i < 20; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("item " + i); - } - // Disable native tooltip - table.setToolTipText (""); - - // Implement a "fake" tooltip - final Listener labelListener = new Listener () { - public void handleEvent (Event event) { - Label label = (Label)event.widget; - Shell shell = label.getShell (); - switch (event.type) { - case SWT.MouseDown: - Event e = new Event (); - e.item = (TableItem) label.getData ("_TABLEITEM"); - // Assuming table is single select, set the selection as if - // the mouse down event went through to the table - table.setSelection (new TableItem [] {(TableItem) e.item}); - table.notifyListeners (SWT.Selection, e); - // fall through - case SWT.MouseExit: - shell.dispose (); - break; - } - } - }; - - Listener tableListener = new Listener () { - Shell tip = null; - Label label = null; - public void handleEvent (Event event) { - switch (event.type) { - case SWT.Dispose: - case SWT.KeyDown: - case SWT.MouseMove: { - if (tip == null) break; - tip.dispose (); - tip = null; - label = null; - break; - } - case SWT.MouseHover: { - TableItem item = table.getItem (new Point (event.x, event.y)); - if (item != null) { - if (tip != null && !tip.isDisposed ()) tip.dispose (); - tip = new Shell (shell, SWT.ON_TOP | SWT.TOOL); - tip.setLayout (new FillLayout ()); - label = new Label (tip, SWT.NONE); - label.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND)); - label.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND)); - label.setData ("_TABLEITEM", item); - label.setText ("tooltip "+item.getText ()); - label.addListener (SWT.MouseExit, labelListener); - label.addListener (SWT.MouseDown, labelListener); - Point size = tip.computeSize (SWT.DEFAULT, SWT.DEFAULT); - Rectangle rect = item.getBounds (0); - Point pt = table.toDisplay (rect.x, rect.y); - tip.setBounds (pt.x, pt.y, size.x, size.y); - tip.setVisible (true); - } - } - } - } - }; - table.addListener (SWT.Dispose, tableListener); - table.addListener (SWT.KeyDown, tableListener); - table.addListener (SWT.MouseMove, tableListener); - table.addListener (SWT.MouseHover, tableListener); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet126.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet126.java deleted file mode 100644 index 6d6a481ba3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet126.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: place arbitrary controls in a table - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.custom.*; - -public class Snippet126 { -public static void main(String[] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - Table table = new Table (shell, SWT.BORDER | SWT.MULTI); - table.setLinesVisible (true); - for (int i=0; i<3; i++) { - TableColumn column = new TableColumn(table, SWT.NONE); - column.setWidth (100); - } - for (int i=0; i<12; i++) { - new TableItem (table, SWT.NONE); - } - TableItem [] items = table.getItems (); - for (int i=0; i<items.length; i++) { - TableEditor editor = new TableEditor (table); - CCombo combo = new CCombo (table, SWT.NONE); - editor.grabHorizontal = true; - editor.setEditor(combo, items[i], 0); - editor = new TableEditor (table); - Text text = new Text (table, SWT.NONE); - editor.grabHorizontal = true; - editor.setEditor(text, items[i], 1); - editor = new TableEditor (table); - Button button = new Button (table, SWT.CHECK); - button.pack (); - editor.minimumWidth = button.getSize ().x; - editor.horizontalAlignment = SWT.LEFT; - editor.setEditor (button, items[i], 2); - } - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet127.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet127.java deleted file mode 100644 index 149a8bd04d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet127.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Control example snippet: prevent Tab from traversing out of a control - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.widgets.*; - -public class Snippet127 { -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Button button1 = new Button(shell, SWT.PUSH); - button1.setBounds(10,10,80,30); - button1.setText("no traverse"); - button1.addTraverseListener(new TraverseListener () { - public void keyTraversed(TraverseEvent e) { - switch (e.detail) { - case SWT.TRAVERSE_TAB_NEXT: - case SWT.TRAVERSE_TAB_PREVIOUS: { - e.doit = false; - } - } - } - }); - Button button2 = new Button (shell, SWT.PUSH); - button2.setBounds(100,10,80,30); - button2.setText("can traverse"); - shell.pack (); - shell.open(); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java deleted file mode 100644 index e10a19ba0c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Browser example snippet: bring up a browser - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.browser.*; - -public class Snippet128 { - public static void main(String [] args) { - Display display = new Display(); - final Shell shell = new Shell(display); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - shell.setLayout(gridLayout); - ToolBar toolbar = new ToolBar(shell, SWT.NONE); - ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH); - itemBack.setText("Back"); - ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH); - itemForward.setText("Forward"); - ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH); - itemStop.setText("Stop"); - ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH); - itemRefresh.setText("Refresh"); - ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH); - itemGo.setText("Go"); - - GridData data = new GridData(); - data.horizontalSpan = 3; - toolbar.setLayoutData(data); - - Label labelAddress = new Label(shell, SWT.NONE); - labelAddress.setText("Address"); - - final Text location = new Text(shell, SWT.BORDER); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - data.grabExcessHorizontalSpace = true; - location.setLayoutData(data); - - final Browser browser = new Browser(shell, SWT.NONE); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.FILL; - data.horizontalSpan = 3; - data.grabExcessHorizontalSpace = true; - data.grabExcessVerticalSpace = true; - browser.setLayoutData(data); - - final Label status = new Label(shell, SWT.NONE); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - status.setLayoutData(data); - - final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE); - data = new GridData(); - data.horizontalAlignment = GridData.END; - progressBar.setLayoutData(data); - - /* event handling */ - Listener listener = new Listener() { - public void handleEvent(Event event) { - ToolItem item = (ToolItem)event.widget; - String string = item.getText(); - if (string.equals("Back")) browser.back(); - else if (string.equals("Forward")) browser.forward(); - else if (string.equals("Stop")) browser.stop(); - else if (string.equals("Refresh")) browser.refresh(); - else if (string.equals("Go")) browser.setUrl(location.getText()); - } - }; - browser.addProgressListener(new ProgressListener() { - public void changed(ProgressEvent event) { - if (event.total == 0) return; - int ratio = event.current * 100 / event.total; - progressBar.setSelection(ratio); - } - public void completed(ProgressEvent event) { - progressBar.setSelection(0); - } - }); - browser.addStatusTextListener(new StatusTextListener() { - public void changed(StatusTextEvent event) { - status.setText(event.text); - } - }); - browser.addLocationListener(new LocationListener() { - public void changed(LocationEvent event) { - if (event.top) location.setText(event.location); - } - public void changing(LocationEvent event) { - } - }); - itemBack.addListener(SWT.Selection, listener); - itemForward.addListener(SWT.Selection, listener); - itemStop.addListener(SWT.Selection, listener); - itemRefresh.addListener(SWT.Selection, listener); - itemGo.addListener(SWT.Selection, listener); - location.addListener(SWT.DefaultSelection, new Listener() { - public void handleEvent(Event e) { - browser.setUrl(location.getText()); - } - }); - - shell.open(); - browser.setUrl("http://eclipse.org"); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet129.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet129.java deleted file mode 100644 index edd35a2a63..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet129.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: color cells and rows in table - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet129 { - -public static void main(String[] args) { - Display display = new Display(); - Color red = display.getSystemColor(SWT.COLOR_RED); - Color blue = display.getSystemColor(SWT.COLOR_BLUE); - Color white = display.getSystemColor(SWT.COLOR_WHITE); - Color gray = display.getSystemColor(SWT.COLOR_GRAY); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Table table = new Table(shell, SWT.BORDER); - table.setBackground(gray); - TableColumn column1 = new TableColumn(table, SWT.NONE); - TableColumn column2 = new TableColumn(table, SWT.NONE); - TableColumn column3 = new TableColumn(table, SWT.NONE); - TableItem item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"entire","row","red foreground"}); - item.setForeground(red); - item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"entire","row","red background"}); - item.setBackground(red); - item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"entire","row","white fore/red back"}); - item.setForeground(white); - item.setBackground(red); - item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"normal","blue foreground","red foreground"}); - item.setForeground(1, blue); - item.setForeground(2, red); - item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"normal","blue background","red background"}); - item.setBackground(1, blue); - item.setBackground(2, red); - item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"white fore/blue back","normal","white fore/red back"}); - item.setForeground(0, white); - item.setBackground(0, blue); - item.setForeground(2, white); - item.setBackground(2, red); - - column1.pack(); - column2.pack(); - column3.pack(); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet13.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet13.java deleted file mode 100644 index 28c8e9a773..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet13.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * GC example snippet: draw a thick line - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet13 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.open (); - GC gc = new GC (shell); - gc.setLineWidth (4); - gc.drawRectangle (20, 20, 100, 100); - gc.dispose (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet130.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet130.java deleted file mode 100644 index 5b7deba5b7..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet130.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * BusyIndicator example snippet: display busy cursor during long running task - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet130 { - - public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - final Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); - text.setLayoutData(new GridData(GridData.FILL_BOTH)); - final int[] nextId = new int[1]; - Button b = new Button(shell, SWT.PUSH); - b.setText("invoke long running job"); - b.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - Runnable longJob = new Runnable() { - boolean done = false; - int id; - public void run() { - Thread thread = new Thread(new Runnable() { - public void run() { - id = nextId[0]++; - display.syncExec(new Runnable() { - public void run() { - if (text.isDisposed()) return; - text.append("\nStart long running task "+id); - } - }); - for (int i = 0; i < 100000; i++) { - if (display.isDisposed()) return; - System.out.println("do task that takes a long time in a separate thread "+id); - } - if (display.isDisposed()) return; - display.syncExec(new Runnable() { - public void run() { - if (text.isDisposed()) return; - text.append("\nCompleted long running task "+id); - } - }); - done = true; - display.wake(); - } - }); - thread.start(); - while (!done && !shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } - }; - BusyIndicator.showWhile(display, longJob); - } - }); - shell.setSize(250, 150); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet131.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet131.java deleted file mode 100644 index 4e87ac361d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet131.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Menu example snippet: show a popup menu (wait for it to close) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet131 { -public static void main (String [] args) { - final Display display = new Display (); - final Shell shell = new Shell (display); - shell.addListener (SWT.MenuDetect, new Listener () { - public void handleEvent (Event event) { - Menu menu = new Menu (shell, SWT.POP_UP); - MenuItem item = new MenuItem (menu, SWT.PUSH); - item.setText ("Menu Item"); - item.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - System.out.println ("Item Selected"); - } - }); - menu.setLocation (event.x, event.y); - menu.setVisible (true); - while (!menu.isDisposed () && menu.isVisible ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - menu.dispose (); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet132.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet132.java deleted file mode 100644 index 018f0aedfe..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet132.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Printing example snippet: print "Hello World!" in black, outlined in red, to default printer - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.printing.*; - -public class Snippet132 { - -public static void main (String [] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.open (); - PrinterData data = Printer.getDefaultPrinterData(); - if (data == null) { - System.out.println("Warning: No default printer."); - return; - } - Printer printer = new Printer(data); - if (printer.startJob("SWT Printing Snippet")) { - Color black = printer.getSystemColor(SWT.COLOR_BLACK); - Color white = printer.getSystemColor(SWT.COLOR_WHITE); - Color red = printer.getSystemColor(SWT.COLOR_RED); - Rectangle trim = printer.computeTrim(0, 0, 0, 0); - Point dpi = printer.getDPI(); - int leftMargin = dpi.x + trim.x; // one inch from left side of paper - int topMargin = dpi.y / 2 + trim.y; // one-half inch from top edge of paper - GC gc = new GC(printer); - Font font = gc.getFont(); // example just uses printer's default font - if (printer.startPage()) { - gc.setBackground(white); - gc.setForeground(black); - String testString = "Hello World!"; - Point extent = gc.stringExtent(testString); - gc.drawString(testString, leftMargin, topMargin + font.getFontData()[0].getHeight()); - gc.setForeground(red); - gc.drawRectangle(leftMargin, topMargin, extent.x, extent.y); - printer.endPage(); - } - gc.dispose(); - printer.endJob(); - } - printer.dispose(); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java deleted file mode 100644 index 30003801ce..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java +++ /dev/null @@ -1,323 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Printing example snippet: print text to printer, with word wrap and pagination - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.io.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.printing.*; - -public class Snippet133 { - Display display; - Shell shell; - Text text; - Font font; - Color foregroundColor, backgroundColor; - - Printer printer; - GC gc; - Font printerFont; - Color printerForegroundColor, printerBackgroundColor; - - int lineHeight = 0; - int tabWidth = 0; - int leftMargin, rightMargin, topMargin, bottomMargin; - int x, y; - int index, end; - String textToPrint; - String tabs; - StringBuffer wordBuffer; - - public static void main(String[] args) { - new Snippet133().open(); - } - - void open() { - display = new Display(); - font = new Font(display, "Courier", 10, SWT.NORMAL); - foregroundColor = display.getSystemColor(SWT.COLOR_BLACK); - backgroundColor = display.getSystemColor(SWT.COLOR_WHITE); - shell = new Shell(display); - shell.setLayout(new FillLayout()); - shell.setText("Print Text"); - shell.setMaximized(true); - text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); - text.setFont(font); - text.setForeground(foregroundColor); - text.setBackground(backgroundColor); - - Menu menuBar = new Menu(shell, SWT.BAR); - shell.setMenuBar(menuBar); - MenuItem item = new MenuItem(menuBar, SWT.CASCADE); - item.setText("&File"); - Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); - item.setMenu(fileMenu); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("&Open..."); - item.setAccelerator(SWT.CTRL + 'O'); - item.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - menuOpen(); - } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("Font..."); - item.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - menuFont(); - } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("Foreground Color..."); - item.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - menuForegroundColor(); - } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("Background Color..."); - item.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - menuBackgroundColor(); - } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("&Print..."); - item.setAccelerator(SWT.CTRL + 'P'); - item.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - menuPrint(); - } - }); - new MenuItem(fileMenu, SWT.SEPARATOR); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("E&xit"); - item.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - System.exit(0); - } - }); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - if (font != null) font.dispose(); - if (foregroundColor != null) foregroundColor.dispose(); - if (backgroundColor != null) backgroundColor.dispose(); - } - - void menuOpen() { - final String textString; - FileDialog dialog = new FileDialog(shell, SWT.OPEN); - dialog.setFilterExtensions(new String[] {"*.java", "*.*"}); - String name = dialog.open(); - if ((name == null) || (name.length() == 0)) return; - - try { - File file = new File(name); - FileInputStream stream= new FileInputStream(file.getPath()); - try { - Reader in = new BufferedReader(new InputStreamReader(stream)); - char[] readBuffer= new char[2048]; - StringBuffer buffer= new StringBuffer((int) file.length()); - int n; - while ((n = in.read(readBuffer)) > 0) { - buffer.append(readBuffer, 0, n); - } - textString = buffer.toString(); - stream.close(); - } catch (IOException e) { - MessageBox box = new MessageBox(shell, SWT.ICON_ERROR); - box.setMessage("Error reading file:\n" + name); - box.open(); - return; - } - } catch (FileNotFoundException e) { - MessageBox box = new MessageBox(shell, SWT.ICON_ERROR); - box.setMessage("File not found:\n" + name); - box.open(); - return; - } - text.setText(textString); - } - - void menuFont() { - FontDialog fontDialog = new FontDialog(shell); - fontDialog.setFontList(font.getFontData()); - FontData fontData = fontDialog.open(); - if (fontData != null) { - if (font != null) font.dispose(); - font = new Font(display, fontData); - text.setFont(font); - } - } - - void menuForegroundColor() { - ColorDialog colorDialog = new ColorDialog(shell); - colorDialog.setRGB(foregroundColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb != null) { - if (foregroundColor != null) foregroundColor.dispose(); - foregroundColor = new Color(display, rgb); - text.setForeground(foregroundColor); - } - } - - void menuBackgroundColor() { - ColorDialog colorDialog = new ColorDialog(shell); - colorDialog.setRGB(backgroundColor.getRGB()); - RGB rgb = colorDialog.open(); - if (rgb != null) { - if (backgroundColor != null) backgroundColor.dispose(); - backgroundColor = new Color(display, rgb); - text.setBackground(backgroundColor); - } - } - - void menuPrint() { - PrintDialog dialog = new PrintDialog(shell, SWT.NONE); - PrinterData data = dialog.open(); - if (data == null) return; - if (data.printToFile) { - data.fileName = "print.out"; // you probably want to ask the user for a filename - } - - /* Get the text to print from the Text widget (you could get it from anywhere, i.e. your java model) */ - textToPrint = text.getText(); - - /* Do the printing in a background thread so that spooling does not freeze the UI. */ - printer = new Printer(data); - Thread printingThread = new Thread("Printing") { - public void run() { - print(printer); - printer.dispose(); - } - }; - printingThread.start(); - } - - void print(Printer printer) { - if (printer.startJob("Text")) { // the string is the job name - shows up in the printer's job list - Rectangle clientArea = printer.getClientArea(); - Rectangle trim = printer.computeTrim(0, 0, 0, 0); - Point dpi = printer.getDPI(); - leftMargin = dpi.x + trim.x; // one inch from left side of paper - rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch from right side of paper - topMargin = dpi.y + trim.y; // one inch from top edge of paper - bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one inch from bottom edge of paper - - /* Create a buffer for computing tab width. */ - int tabSize = 4; // is tab width a user setting in your UI? - StringBuffer tabBuffer = new StringBuffer(tabSize); - for (int i = 0; i < tabSize; i++) tabBuffer.append(' '); - tabs = tabBuffer.toString(); - - /* Create printer GC, and create and set the printer font & foreground color. */ - gc = new GC(printer); - - FontData fontData = font.getFontData()[0]; - printerFont = new Font(printer, fontData.getName(), fontData.getHeight(), fontData.getStyle()); - gc.setFont(printerFont); - tabWidth = gc.stringExtent(tabs).x; - lineHeight = gc.getFontMetrics().getHeight(); - - RGB rgb = foregroundColor.getRGB(); - printerForegroundColor = new Color(printer, rgb); - gc.setForeground(printerForegroundColor); - - rgb = backgroundColor.getRGB(); - printerBackgroundColor = new Color(printer, rgb); - gc.setBackground(printerBackgroundColor); - - /* Print text to current gc using word wrap */ - printText(); - printer.endJob(); - - /* Cleanup graphics resources used in printing */ - printerFont.dispose(); - printerForegroundColor.dispose(); - printerBackgroundColor.dispose(); - gc.dispose(); - } - } - - void printText() { - printer.startPage(); - wordBuffer = new StringBuffer(); - x = leftMargin; - y = topMargin; - index = 0; - end = textToPrint.length(); - while (index < end) { - char c = textToPrint.charAt(index); - index++; - if (c != 0) { - if (c == 0x0a || c == 0x0d) { - if (c == 0x0d && index < end && textToPrint.charAt(index) == 0x0a) { - index++; // if this is cr-lf, skip the lf - } - printWordBuffer(); - newline(); - } else { - if (c != '\t') { - wordBuffer.append(c); - } - if (Character.isWhitespace(c)) { - printWordBuffer(); - if (c == '\t') { - x += tabWidth; - } - } - } - } - } - if (y + lineHeight <= bottomMargin) { - printer.endPage(); - } - } - - void printWordBuffer() { - if (wordBuffer.length() > 0) { - String word = wordBuffer.toString(); - int wordWidth = gc.stringExtent(word).x; - if (x + wordWidth > rightMargin) { - /* word doesn't fit on current line, so wrap */ - newline(); - } - gc.drawString(word, x, y, false); - x += wordWidth; - wordBuffer = new StringBuffer(); - } - } - - void newline() { - x = leftMargin; - y += lineHeight; - if (y + lineHeight > bottomMargin) { - printer.endPage(); - if (index + 1 < end) { - y = topMargin; - printer.startPage(); - } - } - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet134.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet134.java deleted file mode 100644 index 8d6e4cef26..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet134.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: create a non-rectangular window - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet134 { - -static int[] circle(int r, int offsetX, int offsetY) { - int[] polygon = new int[8 * r + 4]; - //x^2 + y^2 = r^2 - for (int i = 0; i < 2 * r + 1; i++) { - int x = i - r; - int y = (int)Math.sqrt(r*r - x*x); - polygon[2*i] = offsetX + x; - polygon[2*i+1] = offsetY + y; - polygon[8*r - 2*i - 2] = offsetX + x; - polygon[8*r - 2*i - 1] = offsetY - y; - } - return polygon; -} - -public static void main(String[] args) { - final Display display = new Display(); - //Shell must be created with style SWT.NO_TRIM - final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); - shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); - //define a region that looks like a key hole - Region region = new Region(); - region.add(circle(67, 67, 67)); - region.subtract(circle(20, 67, 50)); - region.subtract(new int[]{67, 50, 55, 105, 79, 105}); - //define the shape of the shell using setRegion - shell.setRegion(region); - Rectangle size = region.getBounds(); - shell.setSize(size.width, size.height); - //add ability to move shell around - Listener l = new Listener() { - Point origin; - public void handleEvent(Event e) { - switch (e.type) { - case SWT.MouseDown: - origin = new Point(e.x, e.y); - break; - case SWT.MouseUp: - origin = null; - break; - case SWT.MouseMove: - if (origin != null) { - Point p = display.map(shell, null, e.x, e.y); - shell.setLocation(p.x - origin.x, p.y - origin.y); - } - break; - } - } - }; - shell.addListener(SWT.MouseDown, l); - shell.addListener(SWT.MouseUp, l); - shell.addListener(SWT.MouseMove, l); - //add ability to close shell - Button b = new Button(shell, SWT.PUSH); - b.setBackground(shell.getBackground()); - b.setText("close"); - b.pack(); - b.setLocation(10, 68); - b.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - shell.close(); - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - region.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet135.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet135.java deleted file mode 100644 index f0ff5619a1..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet135.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: embed Swing/AWT in SWT - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.awt.EventQueue; -import java.io.*; -import java.util.*; -import javax.swing.*; -import javax.swing.table.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.awt.SWT_AWT; - -public class Snippet135 { - - static class FileTableModel extends AbstractTableModel { - File[] files; - String[] columnsName = {"Name", "Size", "Date Modified"}; - - public FileTableModel (File[] files) { - this.files = files; - } - public int getColumnCount () { - return columnsName.length; - } - public Class getColumnClass (int col) { - if (col == 1) return Long.class; - if (col == 2) return Date.class; - return String.class; - } - public int getRowCount () { - return files == null ? 0 : files.length; - } - public Object getValueAt (int row, int col) { - if (col == 0) return files[row].getName(); - if (col == 1) return new Long(files[row].length()); - if (col == 2) return new Date(files[row].lastModified()); - return ""; - } - public String getColumnName (int col) { - return columnsName[col]; - } - } - - public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setText("SWT and Swing/AWT Example"); - - Listener exitListener = new Listener() { - public void handleEvent(Event e) { - MessageBox dialog = new MessageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION); - dialog.setText("Question"); - dialog.setMessage("Exit?"); - if (e.type == SWT.Close) e.doit = false; - if (dialog.open() != SWT.OK) return; - shell.dispose(); - } - }; - Listener aboutListener = new Listener() { - public void handleEvent(Event e) { - final Shell s = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); - s.setText("About"); - GridLayout layout = new GridLayout(1, false); - layout.verticalSpacing = 20; - layout.marginHeight = layout.marginWidth = 10; - s.setLayout(layout); - Label label = new Label(s, SWT.NONE); - label.setText("SWT and AWT Example."); - Button button = new Button(s, SWT.PUSH); - button.setText("OK"); - GridData data = new GridData(); - data.horizontalAlignment = GridData.CENTER; - button.setLayoutData(data); - button.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - s.dispose(); - } - }); - s.pack(); - Rectangle parentBounds = shell.getBounds(); - Rectangle bounds = s.getBounds(); - int x = parentBounds.x + (parentBounds.width - bounds.width) / 2; - int y = parentBounds.y + (parentBounds.height - bounds.height) / 2; - s.setLocation(x, y); - s.open(); - while (!s.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - } - }; - shell.addListener(SWT.Close, exitListener); - Menu mb = new Menu(shell, SWT.BAR); - MenuItem fileItem = new MenuItem(mb, SWT.CASCADE); - fileItem.setText("&File"); - Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); - fileItem.setMenu(fileMenu); - MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH); - exitItem.setText("&Exit\tCtrl+X"); - exitItem.setAccelerator(SWT.CONTROL + 'X'); - exitItem.addListener(SWT.Selection, exitListener); - MenuItem aboutItem = new MenuItem(fileMenu, SWT.PUSH); - aboutItem.setText("&About\tCtrl+A"); - aboutItem.setAccelerator(SWT.CONTROL + 'A'); - aboutItem.addListener(SWT.Selection, aboutListener); - shell.setMenuBar(mb); - - RGB color = shell.getBackground().getRGB(); - Label separator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); - Label locationLb = new Label(shell, SWT.NONE); - locationLb.setText("Location:"); - Composite locationComp = new Composite(shell, SWT.EMBEDDED); - ToolBar toolBar = new ToolBar(shell, SWT.FLAT); - ToolItem exitToolItem = new ToolItem(toolBar, SWT.PUSH); - exitToolItem.setText("&Exit"); - exitToolItem.addListener(SWT.Selection, exitListener); - ToolItem aboutToolItem = new ToolItem(toolBar, SWT.PUSH); - aboutToolItem.setText("&About"); - aboutToolItem.addListener(SWT.Selection, aboutListener); - Label separator2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); - final Composite comp = new Composite(shell, SWT.NONE); - final Tree fileTree = new Tree(comp, SWT.SINGLE | SWT.BORDER); - Sash sash = new Sash(comp, SWT.VERTICAL); - Composite tableComp = new Composite(comp, SWT.EMBEDDED); - Label separator3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); - Composite statusComp = new Composite(shell, SWT.EMBEDDED); - - java.awt.Frame locationFrame = SWT_AWT.new_Frame(locationComp); - final java.awt.TextField locationText = new java.awt.TextField(); - locationFrame.add(locationText); - - java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(tableComp); - java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout()); - fileTableFrame.add(panel); - final JTable fileTable = new JTable(new FileTableModel(null)); - fileTable.setDoubleBuffered(true); - fileTable.setShowGrid(false); - fileTable.createDefaultColumnsFromModel(); - JScrollPane scrollPane = new JScrollPane(fileTable); - panel.add(scrollPane); - - java.awt.Frame statusFrame = SWT_AWT.new_Frame(statusComp); - statusFrame.setBackground(new java.awt.Color(color.red, color.green, color.blue)); - final java.awt.Label statusLabel = new java.awt.Label(); - statusFrame.add(statusLabel); - statusLabel.setText("Select a file"); - - sash.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - if (e.detail == SWT.DRAG) return; - GridData data = (GridData)fileTree.getLayoutData(); - Rectangle trim = fileTree.computeTrim(0, 0, 0, 0); - data.widthHint = e.x - trim.width; - comp.layout(); - } - }); - - File[] roots = File.listRoots(); - for (int i = 0; i < roots.length; i++) { - File file = roots[i]; - TreeItem treeItem = new TreeItem(fileTree, SWT.NONE); - treeItem.setText(file.getAbsolutePath()); - treeItem.setData(file); - new TreeItem(treeItem, SWT.NONE); - } - fileTree.addListener(SWT.Expand, new Listener() { - public void handleEvent(Event e) { - TreeItem item = (TreeItem)e.item; - if (item == null) return; - if (item.getItemCount() == 1) { - TreeItem firstItem = item.getItems()[0]; - if (firstItem.getData() != null) return; - firstItem.dispose(); - } else { - return; - } - File root = (File)item.getData(); - File[] files = root.listFiles(); - if (files == null) return; - for (int i = 0; i < files.length; i++) { - File file = files[i]; - if (file.isDirectory()) { - TreeItem treeItem = new TreeItem(item, SWT.NONE); - treeItem.setText(file.getName()); - treeItem.setData(file); - new TreeItem(treeItem, SWT.NONE); - } - } - } - }); - fileTree.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - TreeItem item = (TreeItem)e.item; - if (item == null) return; - final File root = (File)item.getData(); - EventQueue.invokeLater(new Runnable() { - public void run() { - statusLabel.setText(root.getAbsolutePath()); - locationText.setText(root.getAbsolutePath()); - fileTable.setModel(new FileTableModel(root.listFiles())); - } - }); - } - }); - - GridLayout layout = new GridLayout(4, false); - layout.marginWidth = layout.marginHeight = 0; - layout.horizontalSpacing = layout.verticalSpacing = 1; - shell.setLayout(layout); - GridData data; - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 4; - separator1.setLayoutData(data); - data = new GridData(); - data.horizontalSpan = 1; - data.horizontalIndent = 10; - locationLb.setLayoutData(data); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - data.heightHint = locationText.getPreferredSize().height; - locationComp.setLayoutData(data); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 1; - toolBar.setLayoutData(data); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 4; - separator2.setLayoutData(data); - data = new GridData(GridData.FILL_BOTH); - data.horizontalSpan = 4; - comp.setLayoutData(data); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 4; - separator3.setLayoutData(data); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 4; - data.heightHint = statusLabel.getPreferredSize().height; - statusComp.setLayoutData(data); - - layout = new GridLayout(3, false); - layout.marginWidth = layout.marginHeight = 0; - layout.horizontalSpacing = layout.verticalSpacing = 1; - comp.setLayout(layout); - data = new GridData(GridData.FILL_VERTICAL); - data.widthHint = 200; - fileTree.setLayoutData(data); - data = new GridData(GridData.FILL_VERTICAL); - sash.setLayoutData(data); - data = new GridData(GridData.FILL_BOTH); - tableComp.setLayoutData(data); - - shell.open(); - while(!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet136.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet136.java deleted file mode 100644 index 238dad3d20..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet136.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Browser example snippet: render HTML from memory - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.browser.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet136 { - public static void main(String [] args) { - String html = "<HTML><HEAD><TITLE>HTML Test</TITLE></HEAD><BODY>"; - for (int i = 0; i < 100; i++) html += "<P>This is line "+i+"</P>"; - html += "</BODY></HTML>"; - - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Browser browser = new Browser(shell, SWT.NONE); - browser.setText(html); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} - - diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet137.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet137.java deleted file mode 100644 index 49f553ec9a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet137.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Browser example snippet: render HTML that includes relative links from memory - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.browser.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet137 { - -public static void main(String [] args) { - /* Relative links: use the HTML base tag */ - String html = "<html><head>"+ - "<base href=\"http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/\" >"+ - "<title>HTML Test</title></head>"+ - "<body><a href=\"dev.html\">local link</a></body></html>"; - - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Browser browser = new Browser(shell, SWT.NONE); - browser.setText(html); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet138.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet138.java deleted file mode 100644 index 8111bb2934..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet138.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: set icons with different resolutions - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet138 { - public static void main(String[] args) { - Display display = new Display(); - - Image small = new Image(display, 16, 16); - GC gc = new GC(small); - gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); - gc.fillArc(0, 0, 16, 16, 45, 270); - gc.dispose(); - - Image large = new Image(display, 32, 32); - gc = new GC(large); - gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); - gc.fillArc(0, 0, 32, 32, 45, 270); - gc.dispose(); - - /* Provide different resolutions for icons to get - * high quality rendering wherever the OS needs - * large icons. For example, the ALT+TAB window - * on certain systems uses a larger icon. - */ - Shell shell = new Shell(display); - shell.setText("Small and Large icons"); - shell.setImages(new Image[] {small, large}); - - /* No large icon: the OS will scale up the - * small icon when it needs a large one. - */ - Shell shell2 = new Shell(display); - shell2.setText("Small icon"); - shell2.setImage(small); - - shell.open(); - shell2.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet139.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet139.java deleted file mode 100644 index 710d5c1fcd..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet139.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * This snippet was adapted from org.eclipse.draw2d.ImageUtilities in - * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.draw2d/?cvsroot=Tools_Project - * by Pratik Shah. - * - * example snippet: rotate and flip an image - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet139 { - -static ImageData rotate(ImageData srcData, int direction) { - int bytesPerPixel = srcData.bytesPerLine / srcData.width; - int destBytesPerLine = (direction == SWT.DOWN)? srcData.width * bytesPerPixel : srcData.height * bytesPerPixel; - byte[] newData = new byte[srcData.data.length]; - int width = 0, height = 0; - for (int srcY = 0; srcY < srcData.height; srcY++) { - for (int srcX = 0; srcX < srcData.width; srcX++) { - int destX = 0, destY = 0, destIndex = 0, srcIndex = 0; - switch (direction){ - case SWT.LEFT: // left 90 degrees - destX = srcY; - destY = srcData.width - srcX - 1; - width = srcData.height; - height = srcData.width; - break; - case SWT.RIGHT: // right 90 degrees - destX = srcData.height - srcY - 1; - destY = srcX; - width = srcData.height; - height = srcData.width; - break; - case SWT.DOWN: // 180 degrees - destX = srcData.width - srcX - 1; - destY = srcData.height - srcY - 1; - width = srcData.width; - height = srcData.height; - break; - } - destIndex = (destY * destBytesPerLine) + (destX * bytesPerPixel); - srcIndex = (srcY * srcData.bytesPerLine) + (srcX * bytesPerPixel); - System.arraycopy(srcData.data, srcIndex, newData, destIndex, bytesPerPixel); - } - } - // destBytesPerLine is used as scanlinePad to ensure that no padding is required - return new ImageData(width, height, srcData.depth, srcData.palette, destBytesPerLine, newData); -} -static ImageData flip(ImageData srcData, boolean vertical) { - int bytesPerPixel = srcData.bytesPerLine / srcData.width; - int destBytesPerLine = srcData.width * bytesPerPixel; - byte[] newData = new byte[srcData.data.length]; - for (int srcY = 0; srcY < srcData.height; srcY++) { - for (int srcX = 0; srcX < srcData.width; srcX++) { - int destX = 0, destY = 0, destIndex = 0, srcIndex = 0; - if (vertical){ - destX = srcX; - destY = srcData.height - srcY - 1; - } else { - destX = srcData.width - srcX - 1; - destY = srcY; - } - destIndex = (destY * destBytesPerLine) + (destX * bytesPerPixel); - srcIndex = (srcY * srcData.bytesPerLine) + (srcX * bytesPerPixel); - System.arraycopy(srcData.data, srcIndex, newData, destIndex, bytesPerPixel); - } - } - // destBytesPerLine is used as scanlinePad to ensure that no padding is required - return new ImageData(srcData.width, srcData.height, srcData.depth, srcData.palette, destBytesPerLine, newData); -} - -public static void main(String[] args) { - Display display = new Display(); - - // create an image with the word "hello" on it - final Image image0 = new Image(display, 50, 30); - GC gc = new GC(image0); - gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); - gc.fillRectangle(image0.getBounds()); - gc.drawString("hello", 5, 5, true); - gc.dispose(); - - ImageData data = image0.getImageData(); - // rotate and flip this image - final Image image1 = new Image(display, rotate(data, SWT.LEFT)); - final Image image2 = new Image(display, rotate(data, SWT.RIGHT)); - final Image image3 = new Image(display, rotate(data, SWT.DOWN)); - final Image image4 = new Image(display, flip(data, true)); - final Image image5 = new Image(display, flip(data, false)); - - Shell shell = new Shell(display); - // draw the results on the shell - shell.addPaintListener(new PaintListener(){ - public void paintControl(PaintEvent e) { - e.gc.drawText("Original Image:", 10, 10, true); - e.gc.drawImage(image0, 10, 40); - e.gc.drawText("Left, Right, 180:", 10, 80, true); - e.gc.drawImage(image1, 10, 110); - e.gc.drawImage(image2, 50, 110); - e.gc.drawImage(image3, 90, 110); - e.gc.drawText("Flipped Vertical, Horizontal:", 10, 170, true); - e.gc.drawImage(image4, 10, 200); - e.gc.drawImage(image5, 70, 200); - } - }); - shell.setSize(300, 300); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - image0.dispose(); - image1.dispose(); - image2.dispose(); - image3.dispose(); - image4.dispose(); - image5.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet14.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet14.java deleted file mode 100644 index 7349e4ece1..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet14.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Control example snippet: detect mouse enter, exit and hover events - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet14 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setSize (100, 100); - shell.addListener (SWT.MouseEnter, new Listener () { - public void handleEvent (Event e) { - System.out.println ("ENTER"); - } - }); - shell.addListener (SWT.MouseExit, new Listener () { - public void handleEvent (Event e) { - System.out.println ("EXIT"); - } - }); - shell.addListener (SWT.MouseHover, new Listener () { - public void handleEvent (Event e) { - System.out.println ("HOVER"); - } - }); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet140.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet140.java deleted file mode 100644 index 247bf717f3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet140.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * CoolBar example snippet: drop-down a chevron menu containing hidden tool items - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; - -public class Snippet140 { - static Display display; - static Shell shell; - static CoolBar coolBar; - static Menu chevronMenu = null; - -public static void main (String [] args) { - display = new Display (); - shell = new Shell (display); - shell.setLayout(new GridLayout()); - coolBar = new CoolBar(shell, SWT.FLAT | SWT.BORDER); - coolBar.setLayoutData(new GridData(GridData.FILL_BOTH)); - ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT | SWT.WRAP); - int minWidth = 0; - for (int j = 0; j < 5; j++) { - int width = 0; - ToolItem item = new ToolItem(toolBar, SWT.PUSH); - item.setText("B" + j); - width = item.getWidth(); - /* find the width of the widest tool */ - if (width > minWidth) minWidth = width; - } - CoolItem coolItem = new CoolItem(coolBar, SWT.DROP_DOWN); - coolItem.setControl(toolBar); - Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); - Point coolSize = coolItem.computeSize (size.x, size.y); - coolItem.setMinimumSize(minWidth, coolSize.y); - coolItem.setPreferredSize(coolSize); - coolItem.setSize(coolSize); - coolItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - if (event.detail == SWT.ARROW) { - CoolItem item = (CoolItem) event.widget; - Rectangle itemBounds = item.getBounds (); - Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y)); - itemBounds.x = pt.x; - itemBounds.y = pt.y; - ToolBar bar = (ToolBar) item.getControl (); - ToolItem[] tools = bar.getItems (); - - int i = 0; - while (i < tools.length) { - Rectangle toolBounds = tools[i].getBounds (); - pt = bar.toDisplay(new Point(toolBounds.x, toolBounds.y)); - toolBounds.x = pt.x; - toolBounds.y = pt.y; - - /* Figure out the visible portion of the tool by looking at the - * intersection of the tool bounds with the cool item bounds. */ - Rectangle intersection = itemBounds.intersection (toolBounds); - - /* If the tool is not completely within the cool item bounds, then it - * is partially hidden, and all remaining tools are completely hidden. */ - if (!intersection.equals (toolBounds)) break; - i++; - } - - /* Create a menu with items for each of the completely hidden buttons. */ - if (chevronMenu != null) chevronMenu.dispose(); - chevronMenu = new Menu (coolBar); - for (int j = i; j < tools.length; j++) { - MenuItem menuItem = new MenuItem (chevronMenu, SWT.PUSH); - menuItem.setText (tools[j].getText()); - } - - /* Drop down the menu below the chevron, with the left edges aligned. */ - pt = coolBar.toDisplay(new Point(event.x, event.y)); - chevronMenu.setLocation (pt.x, pt.y); - chevronMenu.setVisible (true); - } - } - }); - - shell.pack(); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet141.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet141.java deleted file mode 100644 index 0117aecd59..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet141.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Image example snippet: display an animated GIF - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet141 { - static Display display; - static Shell shell; - static GC shellGC; - static Color shellBackground; - static ImageLoader loader; - static ImageData[] imageDataArray; - static Thread animateThread; - static Image image; - static final boolean useGIFBackground = false; - - public static void main(String[] args) { - display = new Display(); - shell = new Shell(display); - shell.setSize(300, 300); - shell.open(); - shellGC = new GC(shell); - shellBackground = shell.getBackground(); - - FileDialog dialog = new FileDialog(shell); - dialog.setFilterExtensions(new String[] {"*.gif"}); - String fileName = dialog.open(); - if (fileName != null) { - loader = new ImageLoader(); - try { - imageDataArray = loader.load(fileName); - if (imageDataArray.length > 1) { - animateThread = new Thread("Animation") { - public void run() { - /* Create an off-screen image to draw on, and fill it with the shell background. */ - Image offScreenImage = new Image(display, loader.logicalScreenWidth, loader.logicalScreenHeight); - GC offScreenImageGC = new GC(offScreenImage); - offScreenImageGC.setBackground(shellBackground); - offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight); - - try { - /* Create the first image and draw it on the off-screen image. */ - int imageDataIndex = 0; - ImageData imageData = imageDataArray[imageDataIndex]; - if (image != null && !image.isDisposed()) image.dispose(); - image = new Image(display, imageData); - offScreenImageGC.drawImage( - image, - 0, - 0, - imageData.width, - imageData.height, - imageData.x, - imageData.y, - imageData.width, - imageData.height); - - /* Now loop through the images, creating and drawing each one - * on the off-screen image before drawing it on the shell. */ - int repeatCount = loader.repeatCount; - while (loader.repeatCount == 0 || repeatCount > 0) { - switch (imageData.disposalMethod) { - case SWT.DM_FILL_BACKGROUND: - /* Fill with the background color before drawing. */ - Color bgColor = null; - if (useGIFBackground && loader.backgroundPixel != -1) { - bgColor = new Color(display, imageData.palette.getRGB(loader.backgroundPixel)); - } - offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground); - offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height); - if (bgColor != null) bgColor.dispose(); - break; - case SWT.DM_FILL_PREVIOUS: - /* Restore the previous image before drawing. */ - offScreenImageGC.drawImage( - image, - 0, - 0, - imageData.width, - imageData.height, - imageData.x, - imageData.y, - imageData.width, - imageData.height); - break; - } - - imageDataIndex = (imageDataIndex + 1) % imageDataArray.length; - imageData = imageDataArray[imageDataIndex]; - image.dispose(); - image = new Image(display, imageData); - offScreenImageGC.drawImage( - image, - 0, - 0, - imageData.width, - imageData.height, - imageData.x, - imageData.y, - imageData.width, - imageData.height); - - /* Draw the off-screen image to the shell. */ - shellGC.drawImage(offScreenImage, 0, 0); - - /* Sleep for the specified delay time (adding commonly-used slow-down fudge factors). */ - try { - int ms = imageData.delayTime * 10; - if (ms < 20) ms += 30; - if (ms < 30) ms += 10; - Thread.sleep(ms); - } catch (InterruptedException e) { - } - - /* If we have just drawn the last image, decrement the repeat count and start again. */ - if (imageDataIndex == imageDataArray.length - 1) repeatCount--; - } - } catch (SWTException ex) { - System.out.println("There was an error animating the GIF"); - } finally { - if (offScreenImage != null && !offScreenImage.isDisposed()) offScreenImage.dispose(); - if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) offScreenImageGC.dispose(); - if (image != null && !image.isDisposed()) image.dispose(); - } - } - }; - animateThread.setDaemon(true); - animateThread.start(); - } - } catch (SWTException ex) { - System.out.println("There was an error loading the GIF"); - } - } - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet142.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet142.java deleted file mode 100644 index 6bc53aab7d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet142.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * UI Automation (for testing tools) snippet: post mouse events - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet142 { - -public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - final Button button = new Button(shell,SWT.NONE); - button.setSize(100,100); - button.setText("Click"); - shell.pack(); - shell.open(); - button.addListener(SWT.MouseDown, new Listener() { - public void handleEvent(Event e){ - System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")"); - } - }); - final Point pt = display.map(shell, null, 50, 50); - new Thread(){ - Event event; - public void run(){ - try { - Thread.sleep(300); - } catch (InterruptedException e) {} - event = new Event(); - event.type = SWT.MouseMove; - event.x = pt.x; - event.y = pt.y; - display.post(event); - try { - Thread.sleep(300); - } catch (InterruptedException e) {} - event.type = SWT.MouseDown; - event.button = 1; - display.post(event); - try { - Thread.sleep(300); - } catch (InterruptedException e) {} - event.type = SWT.MouseUp; - display.post(event); - } - }.start(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet143.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet143.java deleted file mode 100644 index c5debe75f0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet143.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Tray example snippet: place an icon with a popup menu on the system tray - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet143 { - -public static void main(String[] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Image image = new Image (display, 16, 16); - final Tray tray = display.getSystemTray (); - if (tray == null) { - System.out.println ("The system tray is not available"); - } else { - final TrayItem item = new TrayItem (tray, SWT.NONE); - item.setToolTipText("SWT TrayItem"); - item.addListener (SWT.Show, new Listener () { - public void handleEvent (Event event) { - System.out.println("show"); - } - }); - item.addListener (SWT.Hide, new Listener () { - public void handleEvent (Event event) { - System.out.println("hide"); - } - }); - item.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - System.out.println("selection"); - } - }); - item.addListener (SWT.DefaultSelection, new Listener () { - public void handleEvent (Event event) { - System.out.println("default selection"); - } - }); - final Menu menu = new Menu (shell, SWT.POP_UP); - for (int i = 0; i < 8; i++) { - MenuItem mi = new MenuItem (menu, SWT.PUSH); - mi.setText ("Item" + i); - } - item.addListener (SWT.MenuDetect, new Listener () { - public void handleEvent (Event event) { - menu.setVisible (true); - } - }); - item.setImage (image); - } - shell.setBounds(50, 50, 300, 200); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - display.dispose (); -} -} 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 deleted file mode 100644 index 30d13a59c2..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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 - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet144 { - -static final int COUNT = 1000000; - -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); - item.setText ("Item " + index); - System.out.println (item.getText ()); - } - }); - 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)"); - shell.layout (); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet145.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet145.java deleted file mode 100644 index d32c7c6fc3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet145.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * TextLayout example snippet: draw internationalized styled text on a shell - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; - -public class Snippet145 { - - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell (display); - - Font font1 = new Font(display, "Tahoma", 14, SWT.BOLD); - Font font2 = new Font(display, "MS Mincho", 20, SWT.ITALIC); - Font font3 = new Font(display, "Arabic Transparent", 18, SWT.NORMAL); - - Color blue = display.getSystemColor(SWT.COLOR_BLUE); - Color green = display.getSystemColor(SWT.COLOR_GREEN); - Color yellow = display.getSystemColor(SWT.COLOR_YELLOW); - Color gray = display.getSystemColor(SWT.COLOR_GRAY); - - final TextLayout layout = new TextLayout(display); - TextStyle style1 = new TextStyle(font1, yellow, blue); - TextStyle style2 = new TextStyle(font2, green, null); - TextStyle style3 = new TextStyle(font3, blue, gray); - - layout.setText("English \u65E5\u672C\u8A9E \u0627\u0644\u0639\u0631\u0628\u064A\u0651\u0629"); - layout.setStyle(style1, 0, 6); - layout.setStyle(style2, 8, 10); - layout.setStyle(style3, 13, 21); - - shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); - shell.addListener(SWT.Paint, new Listener() { - public void handleEvent (Event event) { - layout.draw(event.gc, 10, 10); - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - font1.dispose(); - font2.dispose(); - font3.dispose(); - layout.dispose(); - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet146.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet146.java deleted file mode 100644 index 44ca4de06d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet146.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * UI Automation (for testing tools) snippet: post key events - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet146 { - -public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - final Text text = new Text(shell, SWT.BORDER); - text.setSize(text.computeSize(150, SWT.DEFAULT)); - shell.pack(); - shell.open(); - new Thread(){ - public void run(){ - String string = "Love the method."; - for (int i = 0; i < string.length(); i++) { - char ch = string.charAt(i); - boolean shift = Character.isUpperCase(ch); - ch = Character.toLowerCase(ch); - if (shift) { - Event event = new Event(); - event.type = SWT.KeyDown; - event.keyCode = SWT.SHIFT; - display.post(event); - } - Event event = new Event(); - event.type = SWT.KeyDown; - event.character = ch; - display.post(event); - try { - Thread.sleep(10); - } catch (InterruptedException e) {} - event.type = SWT.KeyUp; - display.post(event); - try { - Thread.sleep(100); - } catch (InterruptedException e) {} - if (shift) { - event = new Event(); - event.type = SWT.KeyUp; - event.keyCode = SWT.SHIFT; - display.post(event); - } - } - } - }.start(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet147.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet147.java deleted file mode 100644 index 54039d3691..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet147.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: stop CR from going to the default button - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet147 { -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - Combo combo = new Combo(shell, SWT.NONE); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - combo.setText("Here is some text"); - combo.addSelectionListener(new SelectionAdapter() { - public void widgetDefaultSelected(SelectionEvent e) { - System.out.println("Combo default selected (overrides default button)"); - } - }); - combo.addTraverseListener(new TraverseListener() { - public void keyTraversed(TraverseEvent e) { - if (e.detail == SWT.TRAVERSE_RETURN) { - e.doit = false; - e.detail = SWT.TRAVERSE_NONE; - } - } - }); - Button button = new Button(shell, SWT.PUSH); - button.setText("Ok"); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - System.out.println("Button selected"); - } - }); - shell.setDefaultButton(button); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet148.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet148.java deleted file mode 100644 index 15a4f2a1a6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet148.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: check if the browser is available or not - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.browser.*; - -public class Snippet148 { - - public static void main(String[] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Browser browser = null; - try { - browser = new Browser(shell, SWT.NONE); - } catch (SWTError e) { - /* The Browser widget throws an SWTError if it fails to - * instantiate properly. Application code should catch - * this SWTError and disable any feature requiring the - * Browser widget. - * Platform requirements for the SWT Browser widget are available - * from the SWT FAQ website. - */ - } - if (browser != null) { - /* The Browser widget can be used */ - browser.setUrl("http://www.eclipse.org"); - } - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} - - diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet149.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet149.java deleted file mode 100644 index f79a81981a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet149.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * TableEditor example snippet: place a progress bar in a table - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.custom.*; - -public class Snippet149 { - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout (new FillLayout ()); - Table table = new Table (shell, SWT.BORDER); - table.setHeaderVisible (true); - table.setLinesVisible(true); - for (int i=0; i<2; i++) { - new TableColumn (table, SWT.NONE); - } - table.getColumn (0).setText ("Task"); - table.getColumn (1).setText ("Progress"); - for (int i=0; i<40; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("Task " + i); - if ( i % 5 == 0) { - ProgressBar bar = new ProgressBar (table, SWT.NONE); - bar.setSelection (i); - TableEditor editor = new TableEditor (table); - editor.grabHorizontal = editor.grabVertical = true; - editor.setEditor (bar, item, 1); - } - } - table.getColumn (0).pack (); - table.getColumn (1).setWidth (128); - shell.pack (); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet15.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet15.java deleted file mode 100644 index be9ce6ab8c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet15.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tree example snippet: create a tree - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet15 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Tree tree = new Tree (shell, SWT.BORDER); - tree.setSize (100, 100); - shell.setSize (200, 200); - for (int i=0; i<4; i++) { - TreeItem iItem = new TreeItem (tree, 0); - iItem.setText ("TreeItem (0) -" + i); - for (int j=0; j<4; j++) { - TreeItem jItem = new TreeItem (iItem, 0); - jItem.setText ("TreeItem (1) -" + j); - for (int k=0; k<4; k++) { - TreeItem kItem = new TreeItem (jItem, 0); - kItem.setText ("TreeItem (2) -" + k); - for (int l=0; l<4; l++) { - TreeItem lItem = new TreeItem (kItem, 0); - lItem.setText ("TreeItem (3) -" + l); - } - } - } - } - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet150.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet150.java deleted file mode 100644 index 42e5611a09..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet150.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * CoolBar example snippet: create a coolbar (relayout when resized) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet150 { - -static int itemCount; -static CoolItem createItem(CoolBar coolBar, int count) { - ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); - for (int i = 0; i < count; i++) { - ToolItem item = new ToolItem(toolBar, SWT.PUSH); - item.setText(itemCount++ +""); - } - toolBar.pack(); - Point size = toolBar.getSize(); - CoolItem item = new CoolItem(coolBar, SWT.NONE); - item.setControl(toolBar); - Point preferred = item.computeSize(size.x, size.y); - item.setPreferredSize(preferred); - return item; -} - -public static void main(String[] args) { - Display display = new Display(); - final Shell shell = new Shell(display); - CoolBar coolBar = new CoolBar(shell, SWT.NONE); - createItem(coolBar, 3); - createItem(coolBar, 2); - createItem(coolBar, 3); - createItem(coolBar, 4); - int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL; - Text text = new Text(shell, style); - FormLayout layout = new FormLayout(); - shell.setLayout(layout); - FormData coolData = new FormData(); - coolData.left = new FormAttachment(0); - coolData.right = new FormAttachment(100); - coolData.top = new FormAttachment(0); - coolBar.setLayoutData(coolData); - coolBar.addListener(SWT.Resize, new Listener() { - public void handleEvent(Event event) { - shell.layout(); - } - }); - FormData textData = new FormData(); - textData.left = new FormAttachment(0); - textData.right = new FormAttachment(100); - textData.top = new FormAttachment(coolBar); - textData.bottom = new FormAttachment(100); - text.setLayoutData(textData); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java deleted file mode 100644 index a764cc07d7..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Create a virtual table and add 1000 entries to it every 500 ms. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.util.*; -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet151 { - -static int[] data = new int[0]; - -public static void main (String [] args) { - final Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL); - table.addListener(SWT.SetData, new Listener() { - public void handleEvent(Event e) { - TableItem item = (TableItem)e.item; - int index = table.indexOf(item); - item.setText("Item "+data[index]); - } - }); - Thread thread = new Thread() { - public void run() { - int count = 0; - Random random = new Random(); - while (count++ < 500) { - if (table.isDisposed()) return; - // add 10 random numbers to array and sort - int grow = 10; - int[] newData = new int[data.length + grow]; - System.arraycopy(data, 0, newData, 0, data.length); - int index = data.length; - data = newData; - for (int j = 0; j < grow; j++) { - data[index++] = random.nextInt(); - } - Arrays.sort(data); - display.syncExec(new Runnable() { - public void run() { - if (table.isDisposed()) return; - table.setItemCount(data.length); - table.clearAll(); - } - }); - try {Thread.sleep(500);} catch (Throwable t) {} - } - } - }; - thread.start(); - shell.open (); - while (!shell.isDisposed() || thread.isAlive()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet152.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet152.java deleted file mode 100644 index ab32590a5d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet152.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Control example snippet: update a status line when an item is armed - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet152 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - FormLayout layout = new FormLayout(); - shell.setLayout(layout); - final Label label = new Label(shell, SWT.BORDER); - Listener armListener = new Listener() { - public void handleEvent(Event event) { - MenuItem item = (MenuItem) event.widget; - label.setText(item.getText()); - label.update(); - } - }; - Listener showListener = new Listener() { - public void handleEvent(Event event) { - Menu menu = (Menu) event.widget; - MenuItem item = menu.getParentItem(); - if (item != null) { - label.setText(item.getText()); - label.update(); - } - } - }; - Listener hideListener = new Listener() { - public void handleEvent(Event event) { - label.setText(""); - label.update(); - } - }; - FormData labelData = new FormData(); - labelData.left = new FormAttachment(0); - labelData.right = new FormAttachment(100); - labelData.bottom = new FormAttachment(100); - label.setLayoutData(labelData); - Menu menuBar = new Menu(shell, SWT.BAR); - shell.setMenuBar(menuBar); - MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE); - fileItem.setText("File"); - fileItem.addListener(SWT.Arm, armListener); - MenuItem editItem = new MenuItem(menuBar, SWT.CASCADE); - editItem.setText("Edit"); - editItem.addListener(SWT.Arm, armListener); - Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); - fileMenu.addListener(SWT.Hide, hideListener); - fileMenu.addListener(SWT.Show, showListener); - fileItem.setMenu(fileMenu); - String[] fileStrings = { "New", "Close", "Exit" }; - for (int i = 0; i < fileStrings.length; i++) { - MenuItem item = new MenuItem(fileMenu, SWT.PUSH); - item.setText(fileStrings[i]); - item.addListener(SWT.Arm, armListener); - } - Menu editMenu = new Menu(shell, SWT.DROP_DOWN); - editMenu.addListener(SWT.Hide, hideListener); - editMenu.addListener(SWT.Show, showListener); - String[] editStrings = { "Cut", "Copy", "Paste" }; - editItem.setMenu(editMenu); - for (int i = 0; i < editStrings.length; i++) { - MenuItem item = new MenuItem(editMenu, SWT.PUSH); - item.setText(editStrings[i]); - item.addListener(SWT.Arm, armListener); - } - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet153.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet153.java deleted file mode 100644 index 8226971560..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet153.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ToolBar example snippet: update a status line when the pointer enters a ToolItem - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet153 { - -static String statusText = ""; -public static void main(String[] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - shell.setBounds(10, 10, 200, 200); - final ToolBar bar = new ToolBar(shell, SWT.BORDER); - bar.setBounds(10, 10, 150, 50); - final Label statusLine = new Label(shell, SWT.BORDER); - statusLine.setBounds(10, 90, 150, 30); - new ToolItem(bar, SWT.NONE).setText("item 1"); - new ToolItem(bar, SWT.NONE).setText("item 2"); - new ToolItem(bar, SWT.NONE).setText("item 3"); - bar.addMouseMoveListener(new MouseMoveListener() { - public void mouseMove(MouseEvent e) { - ToolItem item = bar.getItem(new Point(e.x, e.y)); - String name = ""; - if (item != null) { - name = item.getText(); - } - if (!statusText.equals(name)) { - statusLine.setText(name); - statusText = name; - } - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet154.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet154.java deleted file mode 100644 index 2877315f74..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet154.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: embed a JTable in SWT (no flicker) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.awt.BorderLayout; -import java.awt.Frame; -import java.awt.Panel; -import javax.swing.*; -import java.util.Vector; - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.awt.SWT_AWT; - -public class Snippet154 { - - public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - - Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED); - - /* - * Set a Windows specific AWT property that prevents heavyweight - * components from erasing their background. Note that this - * is a global property and cannot be scoped. It might not be - * suitable for your application. - */ - try { - System.setProperty("sun.awt.noerasebackground","true"); - } catch (NoSuchMethodError error) {} - - /* Create and setting up frame */ - Frame frame = SWT_AWT.new_Frame(composite); - Panel panel = new Panel(new BorderLayout()) { - public void update(java.awt.Graphics g) { - /* Do not erase the background */ - paint(g); - } - }; - frame.add(panel); - JRootPane root = new JRootPane(); - panel.add(root); - java.awt.Container contentPane = root.getContentPane(); - - /* Creating components */ - int nrows = 1000, ncolumns = 10; - Vector rows = new Vector(); - for (int i = 0; i < nrows; i++) { - Vector row = new Vector(); - for (int j = 0; j < ncolumns; j++) { - row.addElement("Item " + i + "-" + j); - } - rows.addElement(row); - } - Vector columns = new Vector(); - for (int i = 0; i < ncolumns; i++) { - columns.addElement("Column " + i); - } - JTable table = new JTable(rows, columns); - table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - table.createDefaultColumnsFromModel(); - JScrollPane scrollPane = new JScrollPane(table); - contentPane.setLayout(new BorderLayout()); - contentPane.add(scrollPane); - - shell.open(); - while(!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet155.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet155.java deleted file mode 100644 index 86ef14316a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet155.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: draw an X using AWT Graphics - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.awt.Frame; -import java.awt.Canvas; -import java.awt.Graphics; -import java.awt.Dimension; - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.awt.SWT_AWT; - -public class Snippet155 { - - public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Composite composite = new Composite(shell, SWT.EMBEDDED); - - /* Draw an X using AWT */ - Frame frame = SWT_AWT.new_Frame(composite); - Canvas canvas = new Canvas() { - public void paint (Graphics g) { - Dimension d = getSize(); - g.drawLine(0, 0, d.width, d.height); - g.drawLine(d.width, 0, 0, d.height); - } - }; - frame.add(canvas); - - shell.open(); - while(!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet156.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet156.java deleted file mode 100644 index 7ae4922cd6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet156.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: convert between SWT Image and AWT BufferedImage - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.awt.Frame; -import java.awt.Graphics; -import java.awt.Insets; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.DirectColorModel; -import java.awt.image.IndexColorModel; -import java.awt.image.WritableRaster; - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; - -public class Snippet156 { - -static BufferedImage convertToAWT(ImageData data) { - ColorModel colorModel = null; - PaletteData palette = data.palette; - if (palette.isDirect) { - colorModel = new DirectColorModel(data.depth, palette.redMask, palette.greenMask, palette.blueMask); - BufferedImage bufferedImage = new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(data.width, data.height), false, null); - WritableRaster raster = bufferedImage.getRaster(); - int[] pixelArray = new int[3]; - for (int y = 0; y < data.height; y++) { - for (int x = 0; x < data.width; x++) { - int pixel = data.getPixel(x, y); - RGB rgb = palette.getRGB(pixel); - pixelArray[0] = rgb.red; - pixelArray[1] = rgb.green; - pixelArray[2] = rgb.blue; - raster.setPixels(x, y, 1, 1, pixelArray); - } - } - return bufferedImage; - } else { - RGB[] rgbs = palette.getRGBs(); - byte[] red = new byte[rgbs.length]; - byte[] green = new byte[rgbs.length]; - byte[] blue = new byte[rgbs.length]; - for (int i = 0; i < rgbs.length; i++) { - RGB rgb = rgbs[i]; - red[i] = (byte)rgb.red; - green[i] = (byte)rgb.green; - blue[i] = (byte)rgb.blue; - } - if (data.transparentPixel != -1) { - colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue, data.transparentPixel); - } else { - colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue); - } - BufferedImage bufferedImage = new BufferedImage(colorModel, colorModel.createCompatibleWritableRaster(data.width, data.height), false, null); - WritableRaster raster = bufferedImage.getRaster(); - int[] pixelArray = new int[1]; - for (int y = 0; y < data.height; y++) { - for (int x = 0; x < data.width; x++) { - int pixel = data.getPixel(x, y); - pixelArray[0] = pixel; - raster.setPixel(x, y, pixelArray); - } - } - return bufferedImage; - } -} - -static ImageData convertToSWT(BufferedImage bufferedImage) { - if (bufferedImage.getColorModel() instanceof DirectColorModel) { - DirectColorModel colorModel = (DirectColorModel)bufferedImage.getColorModel(); - PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(), colorModel.getBlueMask()); - ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette); - WritableRaster raster = bufferedImage.getRaster(); - int[] pixelArray = new int[3]; - for (int y = 0; y < data.height; y++) { - for (int x = 0; x < data.width; x++) { - raster.getPixel(x, y, pixelArray); - int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2])); - data.setPixel(x, y, pixel); - } - } - return data; - } else if (bufferedImage.getColorModel() instanceof IndexColorModel) { - IndexColorModel colorModel = (IndexColorModel)bufferedImage.getColorModel(); - int size = colorModel.getMapSize(); - byte[] reds = new byte[size]; - byte[] greens = new byte[size]; - byte[] blues = new byte[size]; - colorModel.getReds(reds); - colorModel.getGreens(greens); - colorModel.getBlues(blues); - RGB[] rgbs = new RGB[size]; - for (int i = 0; i < rgbs.length; i++) { - rgbs[i] = new RGB(reds[i] & 0xFF, greens[i] & 0xFF, blues[i] & 0xFF); - } - PaletteData palette = new PaletteData(rgbs); - ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette); - data.transparentPixel = colorModel.getTransparentPixel(); - WritableRaster raster = bufferedImage.getRaster(); - int[] pixelArray = new int[1]; - for (int y = 0; y < data.height; y++) { - for (int x = 0; x < data.width; x++) { - raster.getPixel(x, y, pixelArray); - data.setPixel(x, y, pixelArray[0]); - } - } - return data; - } - return null; -} - -static ImageData createSampleImage(Display display) { - Image image = new Image(display, 100, 100); - Rectangle bounds = image.getBounds(); - GC gc = new GC(image); - gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); - gc.fillRectangle(bounds); - gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); - gc.fillOval(0, 0, bounds.width, bounds.height); - gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); - gc.drawLine(0, 0, bounds.width, bounds.height); - gc.drawLine(bounds.width, 0, 0, bounds.height); - gc.dispose(); - ImageData data = image.getImageData(); - image.dispose(); - return data; -} - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setText("SWT Image"); - ImageData data; - if (args.length > 0) { - String fileName = args[0]; - data = new ImageData(fileName); - } else { - data = createSampleImage(display); - } - final Image swtImage = new Image(display, data); - final BufferedImage awtImage = convertToAWT(data); - final Image swtImage2 = new Image(display, convertToSWT(awtImage)); - shell.addListener(SWT.Paint, new Listener() { - public void handleEvent(Event e) { - int y = 10; - if (swtImage != null) { - e.gc.drawImage(swtImage, 10, y); - y += swtImage.getBounds().height + 10; - } - if (swtImage2 != null) { - e.gc.drawImage(swtImage2, 10, y); - } - } - }); - Frame frame = new Frame() { - public void paint(Graphics g) { - Insets insets = getInsets(); - if (awtImage != null) { - g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null); - } - } - }; - frame.setTitle("AWT Image"); - shell.setLocation(50, 50); - Rectangle bounds = swtImage.getBounds(); - shell.setSize(bounds.width + 50, bounds.height * 2 + 100); - Point size = shell.getSize(); - Point location = shell.getLocation(); - Insets insets = frame.getInsets(); - frame.setLocation(location.x + size.x + 10, location.y); - frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom)); - frame.setVisible(true); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - if (swtImage != null) swtImage.dispose(); - if (swtImage2 != null) swtImage.dispose(); - frame.dispose(); - System.exit(0); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet157.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet157.java deleted file mode 100644 index 760a0489dc..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet157.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: Embed Word in an applet - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -import java.applet.*; - -public class Snippet157 extends Applet { - - org.eclipse.swt.widgets.Display display; - org.eclipse.swt.widgets.Shell swtParent; - java.awt.Canvas awtParent; - -public void init () { - Thread thread = new Thread (new Runnable () { - public void run () { - setLayout(new java.awt.GridLayout (1, 1)); - awtParent = new java.awt.Canvas (); - add (awtParent); - display = new org.eclipse.swt.widgets.Display (); - swtParent = org.eclipse.swt.awt.SWT_AWT.new_Shell (display, awtParent); - swtParent.setLayout (new org.eclipse.swt.layout.FillLayout ()); - org.eclipse.swt.ole.win32.OleFrame frame = new org.eclipse.swt.ole.win32.OleFrame (swtParent, org.eclipse.swt.SWT.NONE); - org.eclipse.swt.ole.win32.OleClientSite site; - try { - site = new org.eclipse.swt.ole.win32.OleClientSite (frame, org.eclipse.swt.SWT.NONE, "Word.Document"); - } catch (org.eclipse.swt.SWTException e) { - String str = "Create OleClientSite Error" + e.toString (); - System.out.println (str); - return; - } - setSize (500, 500); - validate (); - site.doVerb (org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW); - - while (swtParent != null && !swtParent.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - } - }); - thread.start (); -} - public void stop (){ - if (display != null && !display.isDisposed ()){ - display.syncExec(new Runnable () { - public void run () { - if (swtParent != null && !swtParent.isDisposed ()) swtParent.dispose (); - swtParent = null; - display.dispose (); - display = null; - } - }); - remove (awtParent); - awtParent = null; - } - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet158.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet158.java deleted file mode 100644 index 63b1ce340e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet158.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Drag and Drop example snippet: determine native data types available (motif only) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet158 extends ByteArrayTransfer { - -private static Snippet158 _instance = new Snippet158(); -private int[] ids; -private String[] names; - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Table control = new Table(shell, SWT.NONE); - TableItem item = new TableItem(control, SWT.NONE); - item.setText("Drag data over this site to see the native transfer type."); - DropTarget target = new DropTarget(control, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE); - target.setTransfer(new Transfer[] {Snippet158.getInstance()}); - target.addDropListener(new DropTargetAdapter() { - public void dragEnter(DropTargetEvent event) { - String ops = ""; - if ((event.operations & DND.DROP_COPY) != 0) ops += "Copy;"; - if ((event.operations & DND.DROP_MOVE) != 0) ops += "Move;"; - if ((event.operations & DND.DROP_LINK) != 0) ops += "Link;"; - control.removeAll(); - TableItem item1 = new TableItem(control,SWT.NONE); - item1.setText("Allowed Operations are "+ops); - - if (event.detail == DND.DROP_DEFAULT) { - if ((event.operations & DND.DROP_COPY) != 0) { - event.detail = DND.DROP_COPY; - } else if ((event.operations & DND.DROP_LINK) != 0) { - event.detail = DND.DROP_LINK; - } else if ((event.operations & DND.DROP_MOVE) != 0) { - event.detail = DND.DROP_MOVE; - } - } - - TransferData[] data = event.dataTypes; - for (int i = 0; i < data.length; i++) { - int id = data[i].type; - String name = getNameFromId(id); - TableItem item2 = new TableItem(control,SWT.NONE); - item2.setText("Data type is "+id+" "+name); - } - } - }); - - shell.setSize(400, 400); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} - -public static Snippet158 getInstance () { - return _instance; -} -Snippet158() { -} -public void javaToNative (Object object, TransferData transferData) { -} -public Object nativeToJava(TransferData transferData){ - return "Hello World"; -} -protected String[] getTypeNames(){ - return names; -} -static int shellHandle; -protected int[] getTypeIds(){ - if (ids == null) { - Display display = Display.getCurrent(); - int widgetClass = OS.topLevelShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (null, null, widgetClass, display.xDisplay, null, 0); - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtRealizeWidget (shellHandle); - - ids = new int[840]; - names = new String[840]; - for (int i = 0; i < ids.length; i++) { - ids[i] = i+i; - names[i] = getNameFromId(i+1); - } - } - return ids; -} -static String getNameFromId(int id) { - int xDisplay = OS.XtDisplay (shellHandle); - int ptr = 0; - try { - ptr = OS.XmGetAtomName(xDisplay, id); - } catch (Throwable t) { - } - if (ptr == 0) return "invalid "+id; - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - OS.XFree(ptr); - return new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java deleted file mode 100644 index 59f6f1f43c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Browser example snippet: modify HTML title tag - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.browser.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet159 { - public static void main(String [] args) { - final String newTitle = "New Value for Title"; - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Browser browser = new Browser(shell, SWT.NONE); - browser.addTitleListener(new TitleListener() { - public void changed(TitleEvent event) { - System.out.println("TitleEvent: "+event.title); - shell.setText(event.title); - } - }); - browser.addProgressListener(new ProgressListener() { - public void changed(ProgressEvent event) { - } - public void completed(ProgressEvent event) { - /* Set HTML title tag using JavaScript and DOM when page has been loaded */ - boolean result = browser.execute("document.title='"+newTitle+"'"); - if (!result) { - /* Script may fail or may not be supported on certain platforms. */ - System.out.println("Script was not executed."); - } - } - }); - /* Load an HTML document */ - browser.setUrl("http://www.eclipse.org"); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} - - diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet16.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet16.java deleted file mode 100644 index 08a2eee6cb..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet16.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Display example snippet: create one repeating timer (every 500 ms) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet16 { - -public static void main (String [] args) { - final Display display = new Display (); - final Shell shell = new Shell (display); - final int time = 500; - Runnable timer = new Runnable () { - public void run () { - Point point = display.getCursorLocation (); - Rectangle rect = shell.getBounds (); - if (rect.contains (point)) { - System.out.println ("In"); - } else { - System.out.println ("Out"); - } - display.timerExec (time, this); - } - }; - display.timerExec (time, timer); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java deleted file mode 100644 index c602e4add7..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Browser example snippet: query DOM node value - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.browser.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet160 { - public static void main(String [] args) { - final String html = "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>"; - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Browser browser = new Browser(shell, SWT.NONE); - browser.addStatusTextListener(new StatusTextListener() { - public void changed(StatusTextEvent event) { - browser.setData("query", event.text); - } - }); - browser.addProgressListener(new ProgressListener() { - public void changed(ProgressEvent event) { - } - public void completed(ProgressEvent event) { - /* - * Use JavaScript to query the desired node content through the Document Object Model - * - * Assign result to the window property status to pass the result to the StatusTextListener - * This trick is required since <code>execute</code> does not return the <code>String</code> - * directly. - */ - boolean result = browser.execute("window.status=document.getElementById('myid').childNodes[0].nodeValue;"); - if (!result) { - /* Script may fail or may not be supported on certain platforms. */ - System.out.println("Script was not executed."); - return; - } - String value = (String)browser.getData("query"); - System.out.println("Node value: "+value); - } - }); - /* Load an HTML document */ - browser.setText(html); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} - - diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java deleted file mode 100644 index 3d66acf562..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Browser example snippet: modify DOM (executing javascript) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.browser.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet161 { - public static void main(String [] args) { - final String html = "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>"; - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Browser browser = new Browser(shell, SWT.BORDER); - Composite comp = new Composite(shell, SWT.NONE); - comp.setLayout(new FillLayout(SWT.VERTICAL)); - final Text text = new Text(comp, SWT.MULTI); - text.setText("var newNode = document.createElement('P'); \r\n"+ - "var text = document.createTextNode('At least when I am around');\r\n"+ - "newNode.appendChild(text);\r\n"+ - "document.getElementById('myid').appendChild(newNode);\r\n"+ - "\r\n"+ - "document.bgColor='yellow';"); - final Button button = new Button(comp, SWT.PUSH); - button.setText("Execute Script"); - button.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - boolean result = browser.execute(text.getText()); - if (!result) { - /* Script may fail or may not be supported on certain platforms. */ - System.out.println("Script was not executed."); - } - } - }); - browser.setText(html); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} - - diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet162.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet162.java deleted file mode 100644 index 38df25ab14..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet162.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Adding an accessible listener to provide state information - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.accessibility.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet162 { - -final static String STATE = "CheckedIndices"; - -public static void main (String [] args) { - final Display display = new Display (); - Image checkedImage = getCheckedImage (display); - Image uncheckedImage = getUncheckedImage (display); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - final Table table = new Table (shell, SWT.BORDER); - TableColumn column1 = new TableColumn (table, SWT.NONE); - TableColumn column2 = new TableColumn (table, SWT.NONE); - TableColumn column3 = new TableColumn (table, SWT.NONE); - TableItem item1 = new TableItem (table, SWT.NONE); - item1.setText (new String [] {"first item", "a", "b"}); - item1.setImage (1, uncheckedImage); - item1.setImage (2, uncheckedImage); - item1.setData (STATE, null); - TableItem item2 = new TableItem (table, SWT.NONE); - item2.setText (new String [] {"second item", "c", "d"}); - item2.setImage (1, uncheckedImage); - item2.setImage (2, checkedImage); - item2.setData (STATE, new int [] {2}); - TableItem item3 = new TableItem (table, SWT.NONE); - item3.setText (new String [] {"third", "e", "f"}); - item3.setImage (1, checkedImage); - item3.setImage (2, checkedImage); - item3.setData (STATE, new int [] {1, 2}); - column1.pack (); - column2.pack (); - column3.pack (); - Accessible accessible = table.getAccessible (); - accessible.addAccessibleListener (new AccessibleAdapter () { - public void getName (AccessibleEvent e) { - super.getName (e); - if (e.childID >= 0 && e.childID < table.getItemCount ()) { - TableItem item = table.getItem (e.childID); - Point pt = display.getCursorLocation (); - pt = display.map (null, table, pt); - for (int i = 0; i < table.getColumnCount (); i++) { - if (item.getBounds (i).contains (pt)) { - int [] data = (int []) item.getData (STATE); - boolean checked = false; - if (data != null) { - for (int j = 0; j < data.length; j++) { - if (data [j] == i) { - checked = true; - break; - } - } - } - e.result = item.getText (i) + " " + (checked ? "checked" : "unchecked"); - break; - } - } - } - } - }); - accessible.addAccessibleControlListener (new AccessibleControlAdapter () { - public void getState (AccessibleControlEvent e) { - super.getState (e); - if (e.childID >= 0 && e.childID < table.getItemCount ()) { - TableItem item = table.getItem (e.childID); - int [] data = (int []) item.getData (STATE); - if (data != null) { - Point pt = display.getCursorLocation (); - pt = display.map (null, table, pt); - for (int i = 0; i < data.length; i++) { - if (item.getBounds (data [i]).contains (pt)) { - e.detail |= ACC.STATE_CHECKED; - break; - } - } - } - } - } - }); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - checkedImage.dispose (); - uncheckedImage.dispose (); - display.dispose (); -} - -static Image getCheckedImage (Display display) { - Image image = new Image (display, 16, 16); - GC gc = new GC (image); - gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW)); - gc.fillOval (0, 0, 16, 16); - gc.setForeground (display.getSystemColor (SWT.COLOR_DARK_GREEN)); - gc.drawLine (0, 0, 16, 16); - gc.drawLine (16, 0, 0, 16); - gc.dispose (); - return image; -} - -static Image getUncheckedImage (Display display) { - Image image = new Image (display, 16, 16); - GC gc = new GC (image); - gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW)); - gc.fillOval (0, 0, 16, 16); - gc.dispose (); - return image; -} -}
\ No newline at end of file diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet163.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet163.java deleted file mode 100644 index 2c6e996847..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet163.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Setting the font style, foreground and background colors of StyledText - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet163 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - StyledText text = new StyledText (shell, SWT.BORDER); - text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); - // make 0123456789 appear bold - StyleRange style1 = new StyleRange(); - style1.start = 0; - style1.length = 10; - style1.fontStyle = SWT.BOLD; - text.setStyleRange(style1); - // make ABCDEFGHIJKLM have a red font - StyleRange style2 = new StyleRange(); - style2.start = 11; - style2.length = 13; - style2.foreground = display.getSystemColor(SWT.COLOR_RED); - text.setStyleRange(style2); - // make NOPQRSTUVWXYZ have a blue background - StyleRange style3 = new StyleRange(); - style3.start = 25; - style3.length = 13; - style3.background = display.getSystemColor(SWT.COLOR_BLUE); - text.setStyleRange(style3); - - shell.pack(); - 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/Snippet164.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet164.java deleted file mode 100644 index 85f8df0a04..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet164.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Override the text that is spoken for a native Button. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.accessibility.*; -import org.eclipse.swt.widgets.*; - -public class Snippet164 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setBounds(10, 10, 200, 200); - - Button button1 = new Button (shell, SWT.PUSH); - button1.setText("&Typical button"); - button1.setBounds(10,10,180,30); - Button button2 = new Button (shell, SWT.PUSH); - button2.setText("&Overidden button"); - button2.setBounds(10,50,180,30); - button2.getAccessible().addAccessibleListener(new AccessibleAdapter() { - public void getName(AccessibleEvent e) { - e.result = "Speak this instead of the button text"; - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet165.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet165.java deleted file mode 100644 index 147da88dc0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet165.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Create a CTabFolder with min and max buttons, as well as close button and - * image only on selected tab. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet165 { - -public static void main (String [] args) { - Display display = new Display (); - Image image = new Image(display, 16, 16); - GC gc = new GC(image); - gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); - gc.fillRectangle(0, 0, 16, 16); - gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); - gc.fillRectangle(3, 3, 10, 10); - gc.dispose(); - final Shell shell = new Shell (display); - shell.setLayout(new GridLayout()); - final CTabFolder folder = new CTabFolder(shell, SWT.BORDER); - folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - folder.setSimple(false); - folder.setUnselectedImageVisible(false); - folder.setUnselectedCloseVisible(false); - for (int i = 0; i < 8; i++) { - CTabItem item = new CTabItem(folder, SWT.CLOSE); - item.setText("Item "+i); - item.setImage(image); - Text text = new Text(folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); - text.setText("Text for item "+i+"\n\none, two, three\n\nabcdefghijklmnop"); - item.setControl(text); - } - folder.setMinimizeVisible(true); - folder.setMaximizeVisible(true); - folder.addCTabFolder2Listener(new CTabFolder2Adapter() { - public void minimize(CTabFolderEvent event) { - folder.setMinimized(true); - shell.layout(true); - } - public void maximize(CTabFolderEvent event) { - folder.setMaximized(true); - folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - shell.layout(true); - } - public void restore(CTabFolderEvent event) { - folder.setMinimized(false); - folder.setMaximized(false); - folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - shell.layout(true); - } - }); - shell.setSize(300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose(); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java deleted file mode 100644 index f906bd50b0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Create a ScrolledComposite with wrapping content. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet166 { - -public static void main(String[] args) { - Display display = new Display(); - Image image1 = display.getSystemImage(SWT.ICON_WORKING); - Image image2 = display.getSystemImage(SWT.ICON_QUESTION); - Image image3 = display.getSystemImage(SWT.ICON_ERROR); - - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - - final ScrolledComposite scrollComposite = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER); - - final Composite parent = new Composite(scrollComposite, SWT.NONE); - for(int i = 0; i <= 50; i++) { - Label label = new Label(parent, SWT.NONE); - if (i % 3 == 0) label.setImage(image1); - if (i % 3 == 1) label.setImage(image2); - if (i % 3 == 2) label.setImage(image3); - } - RowLayout layout = new RowLayout(SWT.HORIZONTAL); - layout.wrap = true; - parent.setLayout(layout); - - scrollComposite.setContent(parent); - scrollComposite.setExpandVertical(true); - scrollComposite.setExpandHorizontal(true); - scrollComposite.addControlListener(new ControlAdapter() { - public void controlResized(ControlEvent e) { - Rectangle r = scrollComposite.getClientArea(); - scrollComposite.setMinSize(parent.computeSize(r.width, SWT.DEFAULT)); - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet167.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet167.java deleted file mode 100644 index b179565896..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet167.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Create two ScrolledComposites that scroll in tandem. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet167 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - - final ScrolledComposite sc1 = new ScrolledComposite (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - Button button1 = new Button (sc1, SWT.PUSH); - button1.setText ("Button 1"); - button1.setSize (400, 300); - sc1.setContent (button1); - - final ScrolledComposite sc2 = new ScrolledComposite (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - Button button2 = new Button(sc2, SWT.PUSH); - button2.setText ("Button 2"); - button2.setSize (300, 400); - sc2.setContent (button2); - - final ScrollBar vBar1 = sc1.getVerticalBar (); - final ScrollBar vBar2 = sc2.getVerticalBar (); - final ScrollBar hBar1 = sc1.getHorizontalBar (); - final ScrollBar hBar2 = sc2.getHorizontalBar (); - SelectionListener listener1 = new SelectionAdapter () { - public void widgetSelected (SelectionEvent e) { - int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); - int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); - sc2.setOrigin (x, y); - } - }; - SelectionListener listener2 = new SelectionAdapter () { - public void widgetSelected (SelectionEvent e) { - int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); - int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); - sc1.setOrigin (x, y); - } - }; - vBar1.addSelectionListener (listener1); - hBar1.addSelectionListener (listener1); - vBar2.addSelectionListener (listener2); - hBar2.addSelectionListener (listener2); - - shell.setSize (400, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet168.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet168.java deleted file mode 100644 index 4824250f12..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet168.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Draw lines and polygons with different cap and join styles - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet168 { - -public static void main(String[] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - shell.addListener(SWT.Paint, new Listener() { - public void handleEvent(Event event) { - int x = 20, y = 20, w = 120, h = 60; - GC gc = event.gc; - gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); - gc.setLineWidth(10); - int[] caps = {SWT.CAP_FLAT, SWT.CAP_ROUND, SWT.CAP_SQUARE}; - for (int i = 0; i < caps.length; i++) { - gc.setLineCap(caps[i]); - gc.drawLine(x, y, x + w, y); - y += 20; - } - int[] joins = {SWT.JOIN_BEVEL, SWT.JOIN_MITER, SWT.JOIN_ROUND}; - for (int i = 0; i < joins.length; i++) { - gc.setLineJoin(joins[i]); - gc.drawPolygon(new int[] {x, y, x + w/2, y + h, x + w, y}); - y += h + 20; - } - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet169.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet169.java deleted file mode 100644 index 1b32fc5625..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet169.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Make a toggle button have radio behavior - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet169 { -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - Listener listener = new Listener () { - public void handleEvent (Event e) { - Control [] children = shell.getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (e.widget != child && child instanceof Button && (child.getStyle () & SWT.TOGGLE) != 0) { - ((Button) child).setSelection (false); - } - } - ((Button) e.widget).setSelection (true); - } - }; - for (int i=0; i<20; i++) { - Button button = new Button (shell, SWT.TOGGLE); - button.setText ("B" + i); - button.addListener (SWT.Selection, listener); - if (i == 0) button.setSelection (true); - } - shell.pack (); - 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/Snippet17.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet17.java deleted file mode 100644 index 49e04e943e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet17.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Slider example snippet: print scroll event details - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet17 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Slider slider = new Slider (shell, SWT.HORIZONTAL); - slider.setBounds (10, 10, 200, 32); - slider.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - String string = "SWT.NONE"; - switch (event.detail) { - case SWT.DRAG: string = "SWT.DRAG"; break; - case SWT.HOME: string = "SWT.HOME"; break; - case SWT.END: string = "SWT.END"; break; - case SWT.ARROW_DOWN: string = "SWT.ARROW_DOWN"; break; - case SWT.ARROW_UP: string = "SWT.ARROW_UP"; break; - case SWT.PAGE_DOWN: string = "SWT.PAGE_DOWN"; break; - case SWT.PAGE_UP: string = "SWT.PAGE_UP"; break; - } - System.out.println ("Scroll detail -> " + string); - } - }); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet170.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet170.java deleted file mode 100644 index dc8fc04977..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet170.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Create a Tree with columns - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet170 { - public static void main(String[] args) { - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Tree tree = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - tree.setHeaderVisible(true); - TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); - column1.setText("Column 1"); - column1.setWidth(200); - TreeColumn column2 = new TreeColumn(tree, SWT.CENTER); - column2.setText("Column 2"); - column2.setWidth(200); - TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT); - column3.setText("Column 3"); - column3.setWidth(200); - for (int i = 0; i < 4; i++) { - TreeItem item = new TreeItem(tree, SWT.NONE); - item.setText(new String[] { "item " + i, "abc", "defghi" }); - for (int j = 0; j < 4; j++) { - TreeItem subItem = new TreeItem(item, SWT.NONE); - subItem.setText(new String[] { "subitem " + j, "jklmnop", "qrs" }); - for (int k = 0; k < 4; k++) { - TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); - subsubItem.setText(new String[] { "subsubitem " + k, "tuv", "wxyz" }); - } - } - } - shell.pack(); - 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/Snippet171.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet171.java deleted file mode 100644 index ed055d4329..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet171.java +++ /dev/null @@ -1,288 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Drag and Drop example snippet: define data transfer types that subclass each - * other - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.io.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet171 { - -/* - * The data being transferred is an <bold>array of type MyType</bold> where - * MyType is define as: - */ -static class MyType { - String fileName; - long fileLength; - long lastModified; -} - -static class MyTransfer extends ByteArrayTransfer { - - private static final String MYTYPENAME = "MytypeTransfer"; - private static final int MYTYPEID = registerType(MYTYPENAME); - private static MyTransfer _instance = new MyTransfer(); - - public static Transfer getInstance() { - return _instance; - } - - byte[] javaToByteArray(Object object) { - MyType data = (MyType) object; - try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DataOutputStream writeOut = new DataOutputStream(out); - byte[] buffer = data.fileName.getBytes(); - writeOut.writeInt(buffer.length); - writeOut.write(buffer); - writeOut.writeLong(data.fileLength); - writeOut.writeLong(data.lastModified); - buffer = out.toByteArray(); - writeOut.close(); - return buffer; - } catch (IOException e) { - } - return null; - } - - Object byteArrayToJava(byte[] bytes) { - MyType data = new MyType(); - try { - ByteArrayInputStream in = new ByteArrayInputStream(bytes); - DataInputStream readIn = new DataInputStream(in); - int size = readIn.readInt(); - byte[] buffer = new byte[size]; - readIn.read(buffer); - data.fileName = new String(buffer); - data.fileLength = readIn.readLong(); - data.lastModified = readIn.readLong(); - readIn.close(); - } catch (IOException ex) { - return null; - } - return data; - } - - public void javaToNative(Object object, TransferData transferData) { - if (!checkMyType(object) || !isSupportedType(transferData)) { - DND.error(DND.ERROR_INVALID_DATA); - } - byte[] buffer = javaToByteArray(object); - super.javaToNative(buffer, transferData); - } - - public Object nativeToJava(TransferData transferData) { - if (isSupportedType(transferData)) { - byte[] buffer = (byte[]) super.nativeToJava(transferData); - if (buffer == null) - return null; - return byteArrayToJava(buffer); - } - return null; - } - - protected String[] getTypeNames() { - return new String[] { MYTYPENAME }; - } - - protected int[] getTypeIds() { - return new int[] { MYTYPEID }; - } - - boolean checkMyType(Object object) { - return object != null && object instanceof MyType; - } - - protected boolean validate(Object object) { - return checkMyType(object); - } -} - -/* - * The data being transferred is an <bold>array of type MyType2</bold> - * where MyType2 is define as: - */ -static class MyType2 extends MyType { - String version; -} - -static class MyTransfer2 extends MyTransfer { - - private static final String MYTYPE2NAME = "Mytype2Transfer"; - private static final int MYTYPE2ID = registerType(MYTYPE2NAME); - private static MyTransfer _instance = new MyTransfer2(); - - public static Transfer getInstance() { - return _instance; - } - - protected String[] getTypeNames() { - return new String[] { MYTYPE2NAME }; - } - - protected int[] getTypeIds() { - return new int[] { MYTYPE2ID }; - } - - byte[] javaToByteArray(Object object) { - MyType2 data = (MyType2) object; - try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DataOutputStream writeOut = new DataOutputStream(out); - byte[] buffer = data.fileName.getBytes(); - writeOut.writeInt(buffer.length); - writeOut.write(buffer); - writeOut.writeLong(data.fileLength); - writeOut.writeLong(data.lastModified); - buffer = data.version.getBytes(); - writeOut.writeInt(buffer.length); - writeOut.write(buffer); - buffer = out.toByteArray(); - writeOut.close(); - return buffer; - } catch (IOException e) { - } - return null; - } - - Object byteArrayToJava(byte[] bytes) { - MyType2 data = new MyType2(); - try { - ByteArrayInputStream in = new ByteArrayInputStream(bytes); - DataInputStream readIn = new DataInputStream(in); - int size = readIn.readInt(); - byte[] buffer = new byte[size]; - readIn.read(buffer); - data.fileName = new String(buffer); - data.fileLength = readIn.readLong(); - data.lastModified = readIn.readLong(); - size = readIn.readInt(); - buffer = new byte[size]; - readIn.read(buffer); - data.version = new String(buffer); - readIn.close(); - } catch (IOException ex) { - return null; - } - return data; - } - - public void javaToNative(Object object, TransferData transferData) { - if (!checkMyType2(object)) { - DND.error(DND.ERROR_INVALID_DATA); - } - super.javaToNative(object, transferData); - } - - boolean checkMyType2(Object object) { - if (!checkMyType(object)) - return false; - return object != null && object instanceof MyType2; - } - - protected boolean validate(Object object) { - return checkMyType2(object); - } -} - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Label label1 = new Label(shell, SWT.BORDER | SWT.WRAP); - label1.setText("Drag Source for MyData and MyData2"); - final Label label2 = new Label(shell, SWT.BORDER | SWT.WRAP); - label2.setText("Drop Target for MyData"); - final Label label3 = new Label(shell, SWT.BORDER | SWT.WRAP); - label3.setText("Drop Target for MyData2"); - - DragSource source = new DragSource(label1, DND.DROP_COPY); - source.setTransfer(new Transfer[] { MyTransfer.getInstance(), - MyTransfer2.getInstance() }); - source.addDragListener(new DragSourceAdapter() { - public void dragSetData(DragSourceEvent event) { - MyType2 myType = new MyType2(); - myType.fileName = "C:\\abc.txt"; - myType.fileLength = 1000; - myType.lastModified = 12312313; - myType.version = "version 2"; - event.data = myType; - } - }); - DropTarget targetMyType = new DropTarget(label2, DND.DROP_COPY | DND.DROP_DEFAULT); - targetMyType.setTransfer(new Transfer[] { MyTransfer.getInstance() }); - targetMyType.addDropListener(new DropTargetAdapter() { - public void dragEnter(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) - event.detail = DND.DROP_COPY; - } - - public void dragOperationChanged(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) - event.detail = DND.DROP_COPY; - } - - public void drop(DropTargetEvent event) { - if (event.data != null) { - MyType myType = (MyType) event.data; - if (myType != null) { - String string = "MyType: " + myType.fileName; - label2.setText(string); - } - } - } - - }); - DropTarget targetMyType2 = new DropTarget(label3, DND.DROP_COPY | DND.DROP_DEFAULT); - targetMyType2.setTransfer(new Transfer[] { MyTransfer2.getInstance() }); - targetMyType2.addDropListener(new DropTargetAdapter() { - public void dragEnter(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) - event.detail = DND.DROP_COPY; - } - - public void dragOperationChanged(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) - event.detail = DND.DROP_COPY; - } - - public void drop(DropTargetEvent event) { - if (event.data != null) { - MyType2 myType = (MyType2) event.data; - if (myType != null) { - String string = "MyType2: " + myType.fileName + ":" - + myType.version; - label3.setText(string); - } - } - } - - }); - shell.setSize(300, 200); - 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/Snippet172.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet172.java deleted file mode 100644 index b37b3181ab..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet172.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * GridLayout snippet: align widgets in a GridLayout - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet172 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - GridLayout layout = new GridLayout(4, false); - shell.setLayout(layout); - - Button b = new Button(shell, SWT.PUSH); - b.setText("LEFT, TOP"); - b.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("LEFT, CENTER"); - b.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("LEFT, BOTTOM"); - b.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("LEFT, FILL"); - b.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("CENTER, TOP"); - b.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("CENTER, CENTER"); - b.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("CENTER, BOTTOM"); - b.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("CENTER, FILL"); - b.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("RIGHT, TOP"); - b.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("RIGHT, CENTER"); - b.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("RIGHT, BOTTOM"); - b.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("RIGHT, FILL"); - b.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("FILL, TOP"); - b.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("FILL, CENTER"); - b.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("FILL, BOTTOM"); - b.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, true, 1, 1)); - b = new Button(shell, SWT.PUSH); - b.setText("FILL, FILL"); - b.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); - - 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/Snippet173.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet173.java deleted file mode 100644 index 87f466a11c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet173.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Browser snippet: bring up a browser (pop-up blocker) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.browser.*; - -public class Snippet173 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setText("Main Window"); - shell.setLayout(new FillLayout()); - Browser browser = new Browser(shell, SWT.NONE); - initialize(display, browser); - shell.open(); - /* any website with popups */ - browser.setUrl("http://www.cnn.com"); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } - -/* register WindowEvent listeners */ -static void initialize(final Display display, Browser browser) { - browser.addOpenWindowListener(new OpenWindowListener() { - public void open(WindowEvent event) { - Shell shell = new Shell(display); - shell.setText("New Window"); - shell.setLayout(new FillLayout()); - Browser browser = new Browser(shell, SWT.NONE); - initialize(display, browser); - event.browser = browser; - } - }); - browser.addVisibilityWindowListener(new VisibilityWindowListener() { - public void hide(WindowEvent event) { - Browser browser = (Browser)event.widget; - Shell shell = browser.getShell(); - shell.setVisible(false); - } - public void show(WindowEvent event) { - Browser browser = (Browser)event.widget; - final Shell shell = browser.getShell(); - /* popup blocker - ignore windows with no style */ - if (!event.addressBar && !event.menuBar && !event.statusBar && !event.toolBar) { - System.out.println("Popup blocked."); - event.display.asyncExec(new Runnable() { - public void run() { - shell.close(); - } - }); - return; - } - if (event.location != null) shell.setLocation(event.location); - if (event.size != null) { - Point size = event.size; - shell.setSize(shell.computeSize(size.x, size.y)); - } - shell.open(); - } - }); - browser.addCloseWindowListener(new CloseWindowListener() { - public void close(WindowEvent event) { - Browser browser = (Browser)event.widget; - Shell shell = browser.getShell(); - shell.close(); - } - }); -} -}
\ No newline at end of file diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java deleted file mode 100644 index 51888d1b18..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * 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: - * Sebastian Davids - initial implementation - * IBM Corporation - *******************************************************************************/ -package org.eclipse.swt.snippets; - -/* - * SWT OpenGL snippet: draw a square - * - * This snippet requires the experimental org.eclipse.swt.opengl plugin, which - * is not included in swt by default. For information on this plugin see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/opengl/opengl.html - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.opengl.*; -import org.eclipse.swt.widgets.*; - -public class Snippet174 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setText("OpenGL in SWT"); - shell.setLayout(new FillLayout()); - final Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND); - canvas.addControlListener(new ControlAdapter() { - public void controlResized(ControlEvent e) { - resize(canvas); - } - }); - final GLContext context = init(canvas); - shell.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - context.dispose(); - } - }); - new Runnable() { - public void run() { - if (canvas.isDisposed()) return; - render(); - context.swapBuffers(); - canvas.getDisplay().timerExec(50, this); - } - }.run(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} - -static GLContext init(Canvas canvas) { - GLContext context = new GLContext(canvas); - context.setCurrent(); - resize(canvas); - GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - GL.glColor3f(0.0f, 0.0f, 0.0f); - GL.glClearDepth(1.0f); - GL.glEnable(GL.GL_DEPTH_TEST); - GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); - return context; -} - -static void render() { - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glLoadIdentity(); - GL.glTranslatef(0.0f, 0.0f, -6.0f); - GL.glBegin(GL.GL_QUADS); - GL.glVertex3f(-1.0f, 1.0f, 0.0f); - GL.glVertex3f(1.0f, 1.0f, 0.0f); - GL.glVertex3f(1.0f, -1.0f, 0.0f); - GL.glVertex3f(-1.0f, -1.0f, 0.0f); - GL.glEnd(); -} - -static void resize(Canvas canvas) { - Rectangle rect = canvas.getClientArea(); - int width = rect.width; - int height = Math.max(rect.height, 1); - GL.glViewport(0, 0, width, height); - GL.glMatrixMode(GL.GL_PROJECTION); - GL.glLoadIdentity(); - float aspect = (float) width / (float) height; - GLU.gluPerspective(45.0f, aspect, 0.5f, 400.0f); - GL.glMatrixMode(GL.GL_MODELVIEW); - GL.glLoadIdentity(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet175.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet175.java deleted file mode 100644 index 0830d4df0f..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet175.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -/* - * Exclude a widget from a GridLayout - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -public class Snippet175 { - -public static void main(String[] args) { - - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new GridLayout(3, false)); - - Button b = new Button(shell, SWT.PUSH); - b.setText("Button 0"); - - final Button bHidden = new Button(shell, SWT.PUSH); - bHidden.setText("Button 1"); - GridData data = new GridData(); - data.exclude = true; - data.horizontalSpan = 2; - data.horizontalAlignment = SWT.FILL; - bHidden.setLayoutData(data); - - b = new Button(shell, SWT.PUSH); - b.setText("Button 2"); - b = new Button(shell, SWT.PUSH); - b.setText("Button 3"); - b = new Button(shell, SWT.PUSH); - b.setText("Button 4"); - - b = new Button(shell, SWT.CHECK); - b.setText("hide"); - b.setSelection(true); - b.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - Button b = (Button) e.widget; - GridData data = (GridData) bHidden.getLayoutData(); - data.exclude = b.getSelection(); - bHidden.setVisible(!data.exclude); - shell.layout(false); - } - }); - shell.setSize(400, 400); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet176.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet176.java deleted file mode 100644 index 09ec5cca53..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet176.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * GridLayout snippet: align widgets in a horizontal row - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet176 { - - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - RowLayout layout = new RowLayout(SWT.HORIZONTAL); - layout.wrap = true; - layout.fill = false; - layout.justify = true; - shell.setLayout(layout); - - Button b = new Button(shell, SWT.PUSH); - b.setText("Button 1"); - b = new Button(shell, SWT.PUSH); - - b.setText("Button 2"); - - b = new Button(shell, SWT.PUSH); - b.setText("Button 3"); - - b = new Button(shell, SWT.PUSH); - b.setText("Not shown"); - b.setVisible(false); - RowData data = new RowData(); - data.exclude = true; - b.setLayoutData(data); - - b = new Button(shell, SWT.PUSH); - b.setText("Button 200 high"); - data = new RowData(); - data.height = 200; - b.setLayoutData(data); - - b = new Button(shell, SWT.PUSH); - b.setText("Button 200 wide"); - data = new RowData(); - data.width = 200; - b.setLayoutData(data); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet177.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet177.java deleted file mode 100644 index a571043ed7..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet177.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * GridLayout snippet: align widgets in a vertical column - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet177 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - RowLayout layout = new RowLayout(SWT.VERTICAL); - layout.wrap = true; - layout.fill = true; - layout.justify = false; - shell.setLayout(layout); - - Button b = new Button(shell, SWT.PUSH); - b.setText("Button 1"); - b = new Button(shell, SWT.PUSH); - - b.setText("Button 2"); - - b = new Button(shell, SWT.PUSH); - b.setText("Button 3"); - - b = new Button(shell, SWT.PUSH); - b.setText("Not shown"); - b.setVisible(false); - RowData data = new RowData(); - data.exclude = true; - b.setLayoutData(data); - - b = new Button(shell, SWT.PUSH); - b.setText("Button 200 high"); - data = new RowData(); - data.height = 200; - b.setLayoutData(data); - - b = new Button(shell, SWT.PUSH); - b.setText("Button 200 wide"); - data = new RowData(); - data.width = 200; - b.setLayoutData(data); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet178.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet178.java deleted file mode 100644 index 926d59b8ec..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet178.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * How to access About, Preferences and Quit menus on carbon. - * NOTE: This snippet uses internal SWT packages that are - * subject to change without notice. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.carbon.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet178 { - - private static final int kHICommandPreferences = ('p' << 24) + ('r' << 16) - + ('e' << 8) + 'f'; - - private static final int kHICommandAbout = ('a' << 24) + ('b' << 16) - + ('o' << 8) + 'u'; - - private static final int kHICommandServices = ('s' << 24) + ('e' << 16) - + ('r' << 8) + 'v'; - -public static void main(String[] arg) { - Display.setAppName("AppMenu"); // sets name in Dock - Display display = new Display(); - hookApplicationMenu(display, "About AppMenu"); - Shell shell = new Shell(display); - shell.setText("Main Window"); - shell.open(); - while (!shell.isDisposed()) - if (!display.readAndDispatch()) - display.sleep(); - - display.dispose(); -} - -static void hookApplicationMenu(Display display, final String aboutName) { - // Callback target - Object target = new Object() { - int commandProc(int nextHandler, int theEvent, int userData) { - if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) { - HICommand command = new HICommand(); - OS.GetEventParameter(theEvent, OS.kEventParamDirectObject, - OS.typeHICommand, null, HICommand.sizeof, null, - command); - switch (command.commandID) { - case kHICommandPreferences: - return handleCommand("Preferences"); //$NON-NLS-1$ - case kHICommandAbout: - return handleCommand(aboutName); - default: - break; - } - } - return OS.eventNotHandledErr; - } - - int handleCommand(String command) { - Shell shell = new Shell(); - MessageBox preferences = new MessageBox(shell, SWT.ICON_WARNING); - preferences.setText(command); - preferences.open(); - shell.dispose(); - return OS.noErr; - } - }; - - final Callback commandCallback = new Callback(target, "commandProc", 3); //$NON-NLS-1$ - int commandProc = commandCallback.getAddress(); - if (commandProc == 0) { - commandCallback.dispose(); - return; // give up - } - - // Install event handler for commands - int[] mask = new int[] { OS.kEventClassCommand, OS.kEventProcessCommand }; - OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc, - mask.length / 2, mask, 0, null); - - // create About ... menu command - int[] outMenu = new int[1]; - short[] outIndex = new short[1]; - if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1, - outMenu, outIndex) == OS.noErr - && outMenu[0] != 0) { - int menu = outMenu[0]; - - int l = aboutName.length(); - char buffer[] = new char[l]; - aboutName.getChars(0, l, buffer, 0); - int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, - buffer, l); - OS.InsertMenuItemTextWithCFString(menu, str, (short) 0, 0, - kHICommandAbout); - OS.CFRelease(str); - - // add separator between About & Preferences - OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1, - OS.kMenuItemAttrSeparator, 0); - - // enable pref menu - OS.EnableMenuCommand(menu, kHICommandPreferences); - - // disable services menu - OS.DisableMenuCommand(menu, kHICommandServices); - } - - // schedule disposal of callback object - display.disposeExec(new Runnable() { - public void run() { - commandCallback.dispose(); - } - }); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet179.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet179.java deleted file mode 100644 index a53e86c1e0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet179.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Text example snippet: verify input (format for date) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.util.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet179 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - final Text text = new Text(shell, SWT.BORDER); - text.setText("YYYY/MM/DD");; - final Calendar calendar = Calendar.getInstance(); - text.addListener(SWT.Verify, new Listener() { - boolean ignore; - public void handleEvent(Event e) { - if (ignore) return; - e.doit = false; - StringBuffer buffer = new StringBuffer(e.text); - char[] chars = new char[buffer.length()]; - buffer.getChars(0, chars.length, chars, 0); - if (e.character == '\b') { - for (int i = e.start; i < e.end; i++) { - switch (i) { - case 0: /* [Y]YYY */ - case 1: /* Y[Y]YY */ - case 2: /* YY[Y]Y */ - case 3: /* YYY[Y] */ { - buffer.append('Y'); break; - } - case 5: /* [M]M*/ - case 6: /* M[M] */{ - buffer.append('M'); break; - } - case 8: /* [D]D */ - case 9: /* D[D] */ { - buffer.append('D'); break; - } - case 4: /* YYYY[/]MM */ - case 7: /* MM[/]DD */ { - buffer.append('/'); break; - } - default: - return; - } - } - text.setSelection(e.start, e.start + buffer.length()); - ignore = true; - text.insert(buffer.toString()); - ignore = false; - text.setSelection(e.start, e.start); - return; - } - - int start = e.start; - if (start > 9) return; - int index = 0; - for (int i = 0; i < chars.length; i++) { - if (start + index == 4 || start + index == 7) { - if (chars[i] == '/') { - index++; - continue; - } - buffer.insert(index++, '/'); - } - if (chars[i] < '0' || '9' < chars[i]) return; - if (start + index == 5 && '1' < chars[i]) return; /* [M]M */ - if (start + index == 8 && '3' < chars[i]) return; /* [D]D */ - index++; - } - String newText = buffer.toString(); - int length = newText.length(); - StringBuffer date = new StringBuffer(text.getText()); - date.replace(e.start, e.start + length, newText); - calendar.set(Calendar.YEAR, 1901); - calendar.set(Calendar.MONTH, Calendar.JANUARY); - calendar.set(Calendar.DATE, 1); - String yyyy = date.substring(0, 4); - if (yyyy.indexOf('Y') == -1) { - int year = Integer.parseInt(yyyy); - calendar.set(Calendar.YEAR, year); - } - String mm = date.substring(5, 7); - if (mm.indexOf('M') == -1) { - int month = Integer.parseInt(mm) - 1; - int maxMonth = calendar.getActualMaximum(Calendar.MONTH); - if (0 > month || month > maxMonth) return; - calendar.set(Calendar.MONTH, month); - } - String dd = date.substring(8,10); - if (dd.indexOf('D') == -1) { - int day = Integer.parseInt(dd); - int maxDay = calendar.getActualMaximum(Calendar.DATE); - if (1 > day || day > maxDay) return; - calendar.set(Calendar.DATE, day); - } else { - if (calendar.get(Calendar.MONTH) == Calendar.FEBRUARY) { - char firstChar = date.charAt(8); - if (firstChar != 'D' && '2' < firstChar) return; - } - } - text.setSelection(e.start, e.start + length); - ignore = true; - text.insert(newText); - ignore = false; - } - }); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet18.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet18.java deleted file mode 100644 index df4f564ba0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet18.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ToolBar example snippet: create a tool bar (text) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet18 { - -public static void main (String [] args) { - Shell shell = new Shell (); - ToolBar bar = new ToolBar (shell, SWT.BORDER); - for (int i=0; i<8; i++) { - ToolItem item = new ToolItem (bar, SWT.PUSH); - item.setText ("Item " + i); - } - bar.pack (); - shell.open (); - Display display = shell.getDisplay (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet180.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet180.java deleted file mode 100644 index 1cff4402a6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet180.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Create a non-rectangular shell to simulate transparency - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet180 { - -public static void main(String[] args) { - Display display = new Display(); - final Image image = display.getSystemImage(SWT.ICON_WARNING); - //Shell must be created with style SWT.NO_TRIM - final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); - shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); - //define a region - Region region = new Region(); - Rectangle pixel = new Rectangle(0, 0, 1, 1); - for (int y = 0; y < 200; y+=2) { - for (int x = 0; x < 200; x+=2) { - pixel.x = x; - pixel.y = y; - region.add(pixel); - } - } - //define the shape of the shell using setRegion - shell.setRegion(region); - Rectangle size = region.getBounds(); - shell.setSize(size.width, size.height); - shell.addPaintListener(new PaintListener() { - public void paintControl(PaintEvent e) { - Rectangle bounds = image.getBounds(); - Point size = shell.getSize(); - e.gc.drawImage(image, 0, 0, bounds.width, bounds.height, 10, 10, size.x-20, size.y-20); - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - region.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet181.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet181.java deleted file mode 100644 index 3f861f71c4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet181.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Allow user to reorder columns and reorder columns programmatically. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet181 { - - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new RowLayout(SWT.HORIZONTAL)); - final Table table = new Table(shell, SWT.BORDER | SWT.CHECK); - table.setLayoutData(new RowData(-1, 300)); - table.setHeaderVisible(true); - TableColumn column = new TableColumn(table, SWT.LEFT); - column.setText("Column 0"); - column = new TableColumn(table, SWT.CENTER); - column.setText("Column 1"); - column = new TableColumn(table, SWT.CENTER); - column.setText("Column 2"); - column = new TableColumn(table, SWT.CENTER); - column.setText("Column 3"); - column = new TableColumn(table, SWT.CENTER); - column.setText("Column 4"); - for (int i = 0; i < 100; i++) { - TableItem item = new TableItem(table, SWT.NONE); - String[] text = new String[]{i+" 0", i+" 1", i+" 2", i+" 3", i+" 4"}; - item.setText(text); - } - Listener listener = new Listener() { - public void handleEvent(Event e) { - System.out.println("Move "+e.widget); - } - }; - TableColumn[] columns = table.getColumns(); - for (int i = 0; i < columns.length; i++) { - columns[i].pack(); - columns[i].setMoveable(true); - columns[i].addListener(SWT.Move, listener); - } - Button b = new Button(shell, SWT.PUSH); - b.setText("invert column order"); - b.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - int[] order = table.getColumnOrder(); - for (int i = 0; i < order.length / 2; i++) { - int temp = order[i]; - order[i] = order[order.length - i - 1]; - order[order.length - i - 1] = temp; - } - table.setColumnOrder(order); - } - }); - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet182.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet182.java deleted file mode 100644 index 1ca3387f0e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet182.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Link example snippet: create a link widget - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet182 { - - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - Link link = new Link(shell, SWT.BORDER); - link.setText("This a very simple <A>link</A> widget."); - link.setSize(140, 40); - shell.pack (); - 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/Snippet183.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet183.java deleted file mode 100644 index 4117be2021..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet183.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Link example snippet: detect selection events in a link widget - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.*; - -public class Snippet183 { - - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - Link link = new Link(shell, SWT.NONE); - String text = "The SWT component is designed to provide <a>efficient</a>, <a>portable</a> <a href=\"native\">access to the user-interface facilities of the operating systems</a> on which it is implemented."; - link.setText(text); - link.setSize(400, 400); - link.addListener (SWT.Selection, new Listener () { - public void handleEvent(Event event) { - System.out.println("Selection: " + event.text); - } - }); - shell.pack (); - 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/Snippet184.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet184.java deleted file mode 100644 index 26a7e469b4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet184.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Spinner example snippet: create and initialize a spinner widget - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet184 { - - public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - Spinner spinner = new Spinner (shell, SWT.BORDER); - spinner.setMinimum(0); - spinner.setMaximum(1000); - spinner.setSelection(500); - spinner.setIncrement(1); - spinner.setPageIncrement(100); - spinner.pack(); - shell.pack(); - 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/Snippet185.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet185.java deleted file mode 100644 index 653bd0893c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet185.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Dropped data type depends on target item in table - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.io.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet185 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - Label label1 = new Label(shell, SWT.BORDER); - label1.setText("Drag Source"); - final Table table = new Table(shell, SWT.BORDER); - for (int i = 0; i < 4; i++) { - TableItem item = new TableItem(table, SWT.NONE); - if (i % 2 == 0) item.setText("Drop a file"); - if (i % 2 == 1) item.setText("Drop text"); - } - DragSource dragSource = new DragSource(label1, DND.DROP_COPY); - dragSource.setTransfer(new Transfer[] {TextTransfer.getInstance(), FileTransfer.getInstance()}); - dragSource.addDragListener(new DragSourceAdapter() { - public void dragSetData(DragSourceEvent event) { - if (FileTransfer.getInstance().isSupportedType(event.dataType)) { - File file = new File("temp"); - event.data = new String[] {file.getAbsolutePath()}; - } - if (TextTransfer.getInstance().isSupportedType(event.dataType)) { - event.data = "once upon a time"; - } - } - }); - DropTarget dropTarget = new DropTarget(table, DND.DROP_COPY | DND.DROP_DEFAULT); - dropTarget.setTransfer(new Transfer[] {TextTransfer.getInstance(), FileTransfer.getInstance()}); - dropTarget.addDropListener(new DropTargetAdapter() { - FileTransfer fileTransfer = FileTransfer.getInstance(); - TextTransfer textTransfer = TextTransfer.getInstance(); - public void dragEnter(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; - } - public void dragOperationChanged(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; - } - public void dragOver(DropTargetEvent event) { - event.detail = DND.DROP_NONE; - TableItem item = (TableItem)event.item; - if (item == null) return; - int itemIndex = table.indexOf(item); - if (itemIndex % 2 == 0) { - int index = 0; - while (index < event.dataTypes.length) { - if (fileTransfer.isSupportedType(event.dataTypes[index])) break; - index++; - } - if (index < event.dataTypes.length) { - event.currentDataType = event.dataTypes[index]; - event.detail = DND.DROP_COPY; - return; - } - } else { - int index = 0; - while (index < event.dataTypes.length) { - if (textTransfer.isSupportedType(event.dataTypes[index])) break; - index++; - } - if (index < event.dataTypes.length) { - event.currentDataType = event.dataTypes[index]; - event.detail = DND.DROP_COPY; - return; - } - } - } - - public void drop(DropTargetEvent event) { - TableItem item = (TableItem)event.item; - if (item == null) { - event.detail = DND.DROP_NONE; - return; - } - if (fileTransfer.isSupportedType(event.currentDataType)) { - String[] files = (String[])event.data; - if (files != null && files.length > 0) { - item.setText(files[0]); - } - } - if (textTransfer.isSupportedType(event.currentDataType)) { - String text = (String)event.data; - if (text != null) { - item.setText(text); - } - } - } - - }); - shell.setSize(300, 150); - 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/Snippet186.html b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet186.html deleted file mode 100644 index d9f880333b..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet186.html +++ /dev/null @@ -1,16 +0,0 @@ -<HTML> - <HEAD> - <TITLE>Post</TITLE> - <p>Test for Posting Data in IE</p> - - </HEAD> - - <BODY> - <FORM METHOD="post" - ACTION="http://host/cgi-bin/mas_form"> - <INPUT TYPE="text" NAME="name" - SIZE=20 VALUE="Try it (post)"> - </FORM> - - </BODY> -</HTML> diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet186.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet186.java deleted file mode 100644 index 40d4097975..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet186.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * 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; - -/* - * Reading and writing to a SAFEARRAY - * - * This example reads from a PostData object in a BeforeNavigate2 event and - * creates a PostData object in a call to Navigate. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.internal.win32.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.ole.win32.*; -import org.eclipse.swt.widgets.*; - -public class Snippet186 { - -static int CodePage = OS.GetACP(); - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new GridLayout(2, false)); - - final Text text = new Text(shell, SWT.BORDER); - text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - Button go = new Button(shell, SWT.PUSH); - go.setText("Go"); - OleFrame oleFrame = new OleFrame(shell, SWT.NONE); - oleFrame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - OleControlSite controlSite; - OleAutomation automation; - try { - controlSite = new OleControlSite(oleFrame, SWT.NONE, "Shell.Explorer"); - automation = new OleAutomation(controlSite); - controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); - } catch (SWTException ex) { - return; - } - - final OleAutomation auto = automation; - go.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - String url = text.getText(); - int[] rgdispid = auto.getIDsOfNames(new String[]{"Navigate", "URL"}); - int dispIdMember = rgdispid[0]; - Variant[] rgvarg = new Variant[1]; - rgvarg[0] = new Variant(url); - int[] rgdispidNamedArgs = new int[1]; - rgdispidNamedArgs[0] = rgdispid[1]; - auto.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); - } - }); - - - // Read PostData whenever we navigate to a site that uses it - int BeforeNavigate2 = 0xfa; - controlSite.addEventListener(BeforeNavigate2, new OleListener() { - public void handleEvent(OleEvent event) { - Variant url = event.arguments[1]; - Variant postData = event.arguments[4]; - if (postData != null) { - System.out.println("PostData = "+readSafeArray(postData)+", URL = "+url.getString()); - } - } - }); - - // Navigate to this web site which uses post data to fill in the text field - // and put the string "hello world" into the text box - text.setText("file://"+Snippet186.class.getResource("Snippet186.html").getFile()); - int[] rgdispid = automation.getIDsOfNames(new String[]{"Navigate", "URL", "PostData"}); - int dispIdMember = rgdispid[0]; - Variant[] rgvarg = new Variant[2]; - rgvarg[0] = new Variant(text.getText()); - rgvarg[1] = writeSafeArray("hello world"); - int[] rgdispidNamedArgs = new int[2]; - rgdispidNamedArgs[0] = rgdispid[1]; - rgdispidNamedArgs[1] = rgdispid[2]; - automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); - - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -// The following structs are accessed in the readSafeArray and writeSafeArray -// functions: -// -// VARIANT: -// short vt -// short wReserved1 -// short wReserved2 -// short wReserved3 -// int parray -// -// SAFEARRAY: -// short cDims // Count of dimensions in this array -// short fFeatures // Flags used by the SafeArray -// int cbElements // Size of an element of the array -// int cLocks // Number of times the array has been locked without corresponding unlock -// int pvData // Pointer to the data -// SAFEARRAYBOUND[] rgsabound // One bound for each dimension -// -// SAFEARRAYBOUND: -// int cElements // the number of elements in the dimension -// int lLbound // the lower bound of the dimension - -static String readSafeArray(Variant variantByRef) { - // Read a safearray that contains data of - // type VT_UI1 (unsigned shorts) which contains - // a text stream. - int pPostData = variantByRef.getByRef(); - short[] vt_type = new short[1]; - OS.MoveMemory(vt_type, pPostData, 2); - String result = null; - if (vt_type[0] == (short)(OLE.VT_BYREF | OLE.VT_VARIANT)) { - int[] pVariant = new int[1]; - OS.MoveMemory(pVariant, pPostData + 8, 4); - vt_type = new short[1]; - OS.MoveMemory(vt_type, pVariant[0], 2); - if (vt_type[0] == (short)(OLE.VT_ARRAY | OLE.VT_UI1)) { - int[] pSafearray = new int[1]; - OS.MoveMemory(pSafearray, pVariant[0] + 8, 4); - short[] cDims = new short[1]; - OS.MoveMemory(cDims, pSafearray[0], 2); - int[] pvData = new int[1]; - OS.MoveMemory(pvData, pSafearray[0] + 12, 4); - int safearrayboundOffset = 0; - for (int i = 0; i < cDims[0]; i++) { - int[] cElements = new int[1]; - OS.MoveMemory(cElements, pSafearray[0] + 16 + safearrayboundOffset, 4); - safearrayboundOffset += 8; - int cchWideChar = OS.MultiByteToWideChar (CodePage, OS.MB_PRECOMPOSED, pvData[0], -1, null, 0); - if (cchWideChar == 0) return null; - char[] lpWideCharStr = new char [cchWideChar - 1]; - OS.MultiByteToWideChar (CodePage, OS.MB_PRECOMPOSED, pvData[0], -1, lpWideCharStr, lpWideCharStr.length); - result = new String(lpWideCharStr); - } - } - } - return result; -} - -static Variant writeSafeArray (String string) { - // Create a one dimensional safearray containing two VT_UI1 values - // where VT_UI1 is an unsigned char - - // Define cDims, fFeatures and cbElements - short cDims = 1; - short FADF_FIXEDSIZE = 0x10; - short FADF_HAVEVARTYPE = 0x80; - short fFeatures = (short)(FADF_FIXEDSIZE | FADF_HAVEVARTYPE); - int cbElements = 1; - // Create a pointer and copy the data into it - int count = string.length(); - char[] chars = new char[count + 1]; - string.getChars(0, count, chars, 0); - int cchMultiByte = OS.WideCharToMultiByte(CodePage, 0, chars, -1, null, 0, null, null); - if (cchMultiByte == 0) return null; - int pvData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, cchMultiByte); - OS.WideCharToMultiByte(CodePage, 0, chars, -1, pvData, cchMultiByte, null, null); - int cElements1 = cchMultiByte; - int lLbound1 = 0; - // Create a safearray in memory - // 12 bytes for cDims, fFeatures and cbElements + 4 bytes for pvData + number of dimensions * (size of safearraybound) - int sizeofSafeArray = 12 + 4 + 1*8; - int pSafeArray = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, sizeofSafeArray); - // Copy the data into the safe array - int offset = 0; - OS.MoveMemory(pSafeArray + offset, new short[] {cDims}, 2); offset += 2; - OS.MoveMemory(pSafeArray + offset, new short[] {fFeatures}, 2); offset += 2; - OS.MoveMemory(pSafeArray + offset, new int[] {cbElements}, 4); offset += 4; - OS.MoveMemory(pSafeArray + offset, new int[] {0}, 4); offset += 4; - OS.MoveMemory(pSafeArray + offset, new int[] {pvData}, 4); offset += 4; - OS.MoveMemory(pSafeArray + offset, new int[] {cElements1}, 4); offset += 4; - OS.MoveMemory(pSafeArray + offset, new int[] {lLbound1}, 4); offset += 4; - // Create a variant in memory to hold the safearray - int pVariant = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof); - short vt = (short)(OLE.VT_ARRAY | OLE.VT_UI1); - OS.MoveMemory(pVariant, new short[] {vt}, 2); - OS.MoveMemory(pVariant + 8, new int[]{pSafeArray}, 4); - // Create a by ref variant - Variant variantByRef = new Variant(pVariant, (short)(OLE.VT_BYREF | OLE.VT_VARIANT)); - return variantByRef; -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html deleted file mode 100644 index c9b2762044..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html +++ /dev/null @@ -1,16 +0,0 @@ -<HTML> - <HEAD> - <TITLE>Evaluate</TITLE> - <p>Test for IE Script</p> - <SCRIPT> - function evaluate(x) - { - alert("hello") - return eval(x) - } - </SCRIPT> - </HEAD> - - <BODY> - </BODY> -</HTML> diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.java deleted file mode 100644 index 69fffa0ab0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.ole.win32.*; -import org.eclipse.swt.widgets.*; - -/* - * Running a script within IE. - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -public class Snippet187 { - -public static void main(String[] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - OleControlSite controlSite; - try { - OleFrame frame = new OleFrame(shell, SWT.NONE); - controlSite = new OleControlSite(frame, SWT.NONE, "Shell.Explorer"); - controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); - } catch (SWTError e) { - System.out.println("Unable to open activeX control"); - return; - } - - // IWebBrowser - final OleAutomation webBrowser = new OleAutomation(controlSite); - - // When the document is loaded, access the document object for the new page - // and evalute expression using Script. - int DownloadComplete = 104; - controlSite.addEventListener(DownloadComplete, new OleListener() { - public void handleEvent(OleEvent event) { - int[] htmlDocumentID = webBrowser.getIDsOfNames(new String[]{"Document"}); - if (htmlDocumentID == null) return; - Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]); - if (pVarResult == null || pVarResult.getType() == 0) return; - //IHTMLDocument2 - OleAutomation htmlDocument = null; - try { - htmlDocument = pVarResult.getAutomation(); - pVarResult.dispose(); - - int[] scriptID = htmlDocument.getIDsOfNames(new String[]{"Script"}); - if (scriptID == null) return; - pVarResult = htmlDocument.getProperty(scriptID[0]); - if (pVarResult == null || pVarResult.getType() == 0) return; - OleAutomation htmlWindow = null; - try { - //IHTMLWindow2 - htmlWindow = pVarResult.getAutomation(); - pVarResult.dispose(); - int[] evaluateID = htmlWindow.getIDsOfNames(new String[] {"evaluate"}); - if (evaluateID == null) return; - String expression = "5+Math.sin(9)"; - Variant[] rgvarg = new Variant[] {new Variant(expression)}; - pVarResult = htmlWindow.invoke(evaluateID[0], rgvarg, null); - if (pVarResult == null || pVarResult.getType() == 0) return; - System.out.println(expression+" ="+pVarResult.getString()); - } finally { - htmlWindow.dispose(); - } - } finally { - htmlDocument.dispose(); - } - } - }); - - // Navigate to a web site - int[] ids = webBrowser.getIDsOfNames(new String[]{"Navigate", "URL"}); - Variant[] rgvarg = new Variant[] {new Variant("http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet187.html")}; - int[] rgdispidNamedArgs = new int[]{ids[1]}; - webBrowser.invoke(ids[0], rgvarg, rgdispidNamedArgs); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - //Remember to release OleAutomation Object - webBrowser.dispose(); - display.dispose(); - -} -}
\ No newline at end of file diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet188.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet188.java deleted file mode 100644 index 6a51feae6c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet188.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -/* - * Scroll widgets into view when they get focus - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -public class Snippet188 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new GridLayout()); - Button b1 = new Button(shell, SWT.PUSH); - b1.setText("top"); - b1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); - final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); - Composite c = new Composite(sc, SWT.NONE); - c.setLayout(new GridLayout(10, true)); - for (int i = 0 ; i < 300; i++) { - Button b = new Button(c, SWT.PUSH); - b.setText("Button "+i); - } - Button b2 = new Button(shell, SWT.PUSH); - b2.setText("bottom"); - b2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); - - sc.setContent(c); - sc.setExpandHorizontal(true); - sc.setExpandVertical(true); - sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - - Listener listener = new Listener() { - public void handleEvent(Event e) { - Control child = (Control)e.widget; - Rectangle bounds = child.getBounds(); - Rectangle area = sc.getClientArea(); - Point origin = sc.getOrigin(); - if (origin.x > bounds.x) origin.x = Math.max(0, bounds.x); - if (origin.y > bounds.y) origin.y = Math.max(0, bounds.y); - if (origin.x + area.width < bounds.x + bounds.width) origin.x = Math.max(0, bounds.x + bounds.width - area.width); - if (origin.y + area.height < bounds.y + bounds.height) origin.y = Math.max(0, bounds.y + bounds.height - area.height); - sc.setOrigin(origin); - } - }; - Control[] controls = c.getChildren(); - for (int i = 0; i < controls.length; i++) { - controls[i].addListener(SWT.Activate, listener); - } - shell.setSize(300, 500); - 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/Snippet189.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet189.java deleted file mode 100644 index d2f35cd4c4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet189.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -/* - * Text with underline and strike through - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -public class Snippet189 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setText("StyledText with underline and strike through"); - shell.setLayout(new FillLayout()); - StyledText text = new StyledText (shell, SWT.BORDER); - text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ"); - // make 0123456789 appear underlined - StyleRange style1 = new StyleRange(); - style1.start = 0; - style1.length = 10; - style1.underline = true; - text.setStyleRange(style1); - // make ABCDEFGHIJKLM have a strike through - StyleRange style2 = new StyleRange(); - style2.start = 11; - style2.length = 13; - style2.strikeout = true; - text.setStyleRange(style2); - // make NOPQRSTUVWXYZ appear underlined and have a strike through - StyleRange style3 = new StyleRange(); - style3.start = 25; - style3.length = 13; - style3.underline = true; - style3.strikeout = true; - text.setStyleRange(style3); - shell.pack(); - 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/Snippet19.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java deleted file mode 100644 index a757505408..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: verify input (only allow digits) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet19 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Text text = new Text (shell, SWT.BORDER | SWT.V_SCROLL); - text.setBounds (10, 10, 200, 200); - text.addListener (SWT.Verify, new Listener () { - public void handleEvent (Event e) { - String string = e.text; - char [] chars = new char [string.length ()]; - string.getChars (0, chars.length, chars, 0); - for (int i=0; i<chars.length; i++) { - if (!('0' <= chars [i] && chars [i] <= '9')) { - e.doit = false; - return; - } - } - } - }); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet190.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet190.java deleted file mode 100644 index 4232779e7a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet190.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -/* - * Floating point values in Spinner - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -public class Snippet190 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setText("Spinner with float values"); - shell.setLayout(new GridLayout()); - final Spinner spinner = new Spinner(shell, SWT.NONE); - // allow 3 decimal places - spinner.setDigits(3); - // set the minimum value to 0.001 - spinner.setMinimum(1); - // set the maximum value to 20 - spinner.setMaximum(20000); - // set the increment value to 0.010 - spinner.setIncrement(10); - // set the seletion to 3.456 - spinner.setSelection(3456); - spinner.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - int selection = spinner.getSelection(); - int digits = spinner.getDigits(); - System.out.println("Selection is "+(selection / Math.pow(10, digits))); - } - }); - shell.setSize(200, 200); - 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/Snippet191.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet191.java deleted file mode 100644 index 28c93d6b9d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet191.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -/* - * Detect when the user scrolls a text control - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ - -public class Snippet191 { -public static void main(String[] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - final Text text = new Text (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - for (int i=0; i<32; i++) { - text.append (i + "-This is a line of text in a widget-" + i + "\n"); - } - text.setSelection (0); - Listener listener = new Listener () { - int lastIndex = text.getTopIndex (); - public void handleEvent (Event e) { - int index = text.getTopIndex (); - if (index != lastIndex) { - lastIndex = index; - System.out.println ("Scrolled, topIndex=" + index); - } - } - }; - /* NOTE: Only detects scrolling by the user */ - text.addListener (SWT.MouseDown, listener); - text.addListener (SWT.MouseMove, listener); - text.addListener (SWT.MouseUp, listener); - text.addListener (SWT.KeyDown, listener); - text.addListener (SWT.KeyUp, listener); - text.addListener (SWT.Resize, listener); - ScrollBar hBar = text.getHorizontalBar(); - if (hBar != null) { - hBar.addListener (SWT.Selection, listener); - } - ScrollBar vBar = text.getVerticalBar(); - if (vBar != null) { - vBar.addListener (SWT.Selection, listener); - } - shell.pack (); - Point size = shell.computeSize (SWT.DEFAULT, SWT.DEFAULT); - shell.setSize (size. x - 32, size.y / 2); - 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 deleted file mode 100644 index 106ae6c0fe..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: sort a table by column - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; -import java.text.*; -import java.util.*; - -public class Snippet2 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - final Table table = new Table(shell, SWT.BORDER); - table.setHeaderVisible(true); - TableColumn column1 = new TableColumn(table, SWT.NONE); - column1.setText("Column 1"); - TableColumn column2 = new TableColumn(table, SWT.NONE); - column2.setText("Column 2"); - TableItem item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"a", "3"}); - item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"b", "2"}); - item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"c", "1"}); - column1.pack(); - column2.pack(); - column1.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - // sort column 1 - TableItem[] items = table.getItems(); - Collator collator = Collator.getInstance(Locale.getDefault()); - for (int i = 1; i < items.length; i++) { - String value1 = items[i].getText(0); - for (int j = 0; j < i; j++){ - String value2 = items[j].getText(0); - if (collator.compare(value1, value2) < 0) { - String[] values = {items[i].getText(0), items[i].getText(1)}; - items[i].dispose(); - TableItem item = new TableItem(table, SWT.NONE, j); - item.setText(values); - items = table.getItems(); - break; - } - } - } - } - }); - column2.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - // sort column 2 - TableItem[] items = table.getItems(); - Collator collator = Collator.getInstance(Locale.getDefault()); - for (int i = 1; i < items.length; i++) { - String value1 = items[i].getText(1); - for (int j = 0; j < i; j++){ - String value2 = items[j].getText(1); - if (collator.compare(value1, value2) < 0) { - String[] values = {items[i].getText(0), items[i].getText(1)}; - items[i].dispose(); - TableItem item = new TableItem(table, SWT.NONE, j); - item.setText(values); - items = table.getItems(); - break; - } - } - } - } - }); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet20.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet20.java deleted file mode 100644 index c98c78ec0c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet20.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * CoolBar example snippet: create a cool bar - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet20 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - CoolBar bar = new CoolBar (shell, SWT.BORDER); - for (int i=0; i<2; i++) { - CoolItem item = new CoolItem (bar, SWT.NONE); - Button button = new Button (bar, SWT.PUSH); - button.setText ("Button " + i); - Point size = button.computeSize (SWT.DEFAULT, SWT.DEFAULT); - item.setPreferredSize (item.computeSize (size.x, size.y)); - item.setControl (button); - } - bar.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet21.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet21.java deleted file mode 100644 index e4c662b516..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet21.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Canvas example snippet: implement tab traversal (behave like a tab group) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet21 { - -public static void main (String [] args) { - Display display = new Display (); - final Color red = display.getSystemColor (SWT.COLOR_RED); - final Color blue = display.getSystemColor (SWT.COLOR_BLUE); - Shell shell = new Shell (display); - Button b = new Button (shell, SWT.PUSH); - b.setBounds (10, 10, 100, 32); - b.setText ("Button"); - shell.setDefaultButton (b); - final Canvas c = new Canvas (shell, SWT.BORDER); - c.setBounds (10, 50, 100, 32); - c.addListener (SWT.Traverse, new Listener () { - public void handleEvent (Event e) { - switch (e.detail) { - /* Do tab group traversal */ - case SWT.TRAVERSE_ESCAPE: - case SWT.TRAVERSE_RETURN: - case SWT.TRAVERSE_TAB_NEXT: - case SWT.TRAVERSE_TAB_PREVIOUS: - case SWT.TRAVERSE_PAGE_NEXT: - case SWT.TRAVERSE_PAGE_PREVIOUS: - e.doit = true; - break; - } - } - }); - c.addListener (SWT.FocusIn, new Listener () { - public void handleEvent (Event e) { - c.setBackground (red); - } - }); - c.addListener (SWT.FocusOut, new Listener () { - public void handleEvent (Event e) { - c.setBackground (blue); - } - }); - c.addListener (SWT.KeyDown, new Listener () { - public void handleEvent (Event e) { - System.out.println ("KEY"); - for (int i=0; i<64; i++) { - Color c1 = red, c2 = blue; - if (c.isFocusControl ()) { - c1 = blue; c2 = red; - } - c.setBackground (c1); - c.update (); - c.setBackground (c2); - } - } - }); - Text t = new Text (shell, SWT.SINGLE | SWT.BORDER); - t.setBounds (10, 85, 100, 32); - - Text r = new Text (shell, SWT.MULTI | SWT.BORDER); - r.setBounds (10, 120, 100, 32); - - c.setFocus (); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet22.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet22.java deleted file mode 100644 index 3469244100..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet22.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: select all the text in the control - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet22 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Text text = new Text (shell, 0); - text.setText ("ASDF"); - text.setSize (64, 32); - text.selectAll (); - shell.pack (); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet23.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet23.java deleted file mode 100644 index 67bed14f60..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet23.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tracker example snippet: create a tracker (drag on mouse down) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet23 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - shell.open (); - shell.addListener (SWT.MouseDown, new Listener () { - public void handleEvent (Event e) { - Tracker tracker = new Tracker (shell, SWT.NONE); - tracker.setRectangles (new Rectangle [] { - new Rectangle (e.x, e.y, 100, 100), - }); - tracker.open (); - } - }); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet24.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet24.java deleted file mode 100644 index 8887c768df..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet24.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: detect CR in a text or combo control (default selelection) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet24 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new RowLayout ()); - Combo combo = new Combo (shell, SWT.NONE); - combo.setItems (new String [] {"A-1", "B-1", "C-1"}); - Text text = new Text (shell, SWT.SINGLE | SWT.BORDER); - text.setText ("some text"); - combo.addListener (SWT.DefaultSelection, new Listener () { - public void handleEvent (Event e) { - System.out.println (e.widget + " - Default Selection"); - } - }); - text.addListener (SWT.DefaultSelection, new Listener () { - public void handleEvent (Event e) { - System.out.println (e.widget + " - Default Selection"); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet25.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet25.java deleted file mode 100644 index d9180a37a3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet25.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Control example snippet: print key state, code and character - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet25 { - -static String stateMask (int stateMask) { - String string = ""; - if ((stateMask & SWT.CTRL) != 0) string += " CTRL"; - if ((stateMask & SWT.ALT) != 0) string += " ALT"; - if ((stateMask & SWT.SHIFT) != 0) string += " SHIFT"; - if ((stateMask & SWT.COMMAND) != 0) string += " COMMAND"; - return string; -} - -static String character (char character) { - switch (character) { - case 0: return "'\\0'"; - case SWT.BS: return "'\\b'"; - case SWT.CR: return "'\\r'"; - case SWT.DEL: return "DEL"; - case SWT.ESC: return "ESC"; - case SWT.LF: return "'\\n'"; - case SWT.TAB: return "'\\t'"; - } - return "'" + character +"'"; -} - -static String keyCode (int keyCode) { - switch (keyCode) { - - /* Keyboard and Mouse Masks */ - case SWT.ALT: return "ALT"; - case SWT.SHIFT: return "SHIFT"; - case SWT.CONTROL: return "CONTROL"; - case SWT.COMMAND: return "COMMAND"; - - /* Non-Numeric Keypad Keys */ - case SWT.ARROW_UP: return "ARROW_UP"; - case SWT.ARROW_DOWN: return "ARROW_DOWN"; - case SWT.ARROW_LEFT: return "ARROW_LEFT"; - case SWT.ARROW_RIGHT: return "ARROW_RIGHT"; - case SWT.PAGE_UP: return "PAGE_UP"; - case SWT.PAGE_DOWN: return "PAGE_DOWN"; - case SWT.HOME: return "HOME"; - case SWT.END: return "END"; - case SWT.INSERT: return "INSERT"; - - /* Virtual and Ascii Keys */ - case SWT.BS: return "BS"; - case SWT.CR: return "CR"; - case SWT.DEL: return "DEL"; - case SWT.ESC: return "ESC"; - case SWT.LF: return "LF"; - case SWT.TAB: return "TAB"; - - /* Functions Keys */ - case SWT.F1: return "F1"; - case SWT.F2: return "F2"; - case SWT.F3: return "F3"; - case SWT.F4: return "F4"; - case SWT.F5: return "F5"; - case SWT.F6: return "F6"; - case SWT.F7: return "F7"; - case SWT.F8: return "F8"; - case SWT.F9: return "F9"; - case SWT.F10: return "F10"; - case SWT.F11: return "F11"; - case SWT.F12: return "F12"; - case SWT.F13: return "F13"; - case SWT.F14: return "F14"; - case SWT.F15: return "F15"; - - /* Numeric Keypad Keys */ - case SWT.KEYPAD_ADD: return "KEYPAD_ADD"; - case SWT.KEYPAD_SUBTRACT: return "KEYPAD_SUBTRACT"; - case SWT.KEYPAD_MULTIPLY: return "KEYPAD_MULTIPLY"; - case SWT.KEYPAD_DIVIDE: return "KEYPAD_DIVIDE"; - case SWT.KEYPAD_DECIMAL: return "KEYPAD_DECIMAL"; - case SWT.KEYPAD_CR: return "KEYPAD_CR"; - case SWT.KEYPAD_0: return "KEYPAD_0"; - case SWT.KEYPAD_1: return "KEYPAD_1"; - case SWT.KEYPAD_2: return "KEYPAD_2"; - case SWT.KEYPAD_3: return "KEYPAD_3"; - case SWT.KEYPAD_4: return "KEYPAD_4"; - case SWT.KEYPAD_5: return "KEYPAD_5"; - case SWT.KEYPAD_6: return "KEYPAD_6"; - case SWT.KEYPAD_7: return "KEYPAD_7"; - case SWT.KEYPAD_8: return "KEYPAD_8"; - case SWT.KEYPAD_9: return "KEYPAD_9"; - case SWT.KEYPAD_EQUAL: return "KEYPAD_EQUAL"; - - /* Other keys */ - case SWT.CAPS_LOCK: return "CAPS_LOCK"; - case SWT.NUM_LOCK: return "NUM_LOCK"; - case SWT.SCROLL_LOCK: return "SCROLL_LOCK"; - case SWT.PAUSE: return "PAUSE"; - case SWT.BREAK: return "BREAK"; - case SWT.PRINT_SCREEN: return "PRINT_SCREEN"; - case SWT.HELP: return "HELP"; - } - return character ((char) keyCode); -} - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Listener listener = new Listener () { - public void handleEvent (Event e) { - String string = e.type == SWT.KeyDown ? "DOWN:" : "UP :"; - string += " stateMask=0x" + Integer.toHexString (e.stateMask) + stateMask (e.stateMask) + ","; - string += " keyCode=0x" + Integer.toHexString (e.keyCode) + " " + keyCode (e.keyCode) + ","; - string += " character=0x" + Integer.toHexString (e.character) + " " + character (e.character); - System.out.println (string); - } - }; - shell.addListener (SWT.KeyDown, listener); - shell.addListener (SWT.KeyUp, listener); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet26.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet26.java deleted file mode 100644 index 3b8181e38b..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet26.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Combo example snippet: create a combo box (non-editable) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet26 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Combo combo = new Combo (shell, SWT.READ_ONLY); - combo.setItems (new String [] {"A", "B", "C"}); - combo.setSize (200, 200); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet27.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet27.java deleted file mode 100644 index c5cdb3d94d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet27.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: open a shell minimized (iconified) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet27 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setMinimized (true); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet28.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet28.java deleted file mode 100644 index 62d819d145..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet28.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: open a shell maximized (full screen) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet28 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setMaximized (true); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet29.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet29.java deleted file mode 100644 index 4fe589fbfb..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet29.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Menu example snippet: create a bar and pull down menu (accelerators, mnemonics) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet29 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Menu bar = new Menu (shell, SWT.BAR); - shell.setMenuBar (bar); - MenuItem fileItem = new MenuItem (bar, SWT.CASCADE); - fileItem.setText ("File"); - Menu submenu = new Menu (shell, SWT.DROP_DOWN); - fileItem.setMenu (submenu); - MenuItem item = new MenuItem (submenu, SWT.PUSH); - item.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - System.out.println ("Select All"); - } - }); - item.setText ("Select &All\tCtrl+A"); - item.setAccelerator (SWT.CTRL + 'A'); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet3.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet3.java deleted file mode 100644 index 7466de2035..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet3.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: find a table cell from mouse down (SWT.FULL_SELECTION) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.graphics.*; - -public class Snippet3 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Table table = new Table (shell, SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION); - table.setHeaderVisible (true); - table.setLinesVisible (true); - final int rowCount = 64, columnCount = 4; - for (int i=0; i < columnCount; i++) { - TableColumn column = new TableColumn (table, SWT.NONE); - column.setText ("Column " + i); - } - for (int i=0; i < rowCount; i++) { - TableItem item = new TableItem (table, SWT.NONE); - for (int j=0; j < columnCount; j++) { - item.setText (j, "Item " + i + "-" + j); - } - } - for (int i=0; i < columnCount; i++) { - table.getColumn (i).pack (); - } - Point size = table.computeSize (SWT.DEFAULT, 200); - table.setSize (size); - shell.pack (); - table.addListener (SWT.MouseDown, new Listener () { - public void handleEvent (Event event) { - Point pt = new Point (event.x, event.y); - TableItem item = table.getItem (pt); - if (item == null) return; - for (int i=0; i < columnCount; i++) { - Rectangle rect = item.getBounds (i); - if (rect.contains (pt)) { - int index = table.indexOf (item); - System.out.println ("Item " + index + "-" + i); - } - } - } - }); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet30.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet30.java deleted file mode 100644 index 92a82fee7c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet30.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Program example snippet: invoke the system text editor on autoexec.bat - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.program.*; -import org.eclipse.swt.widgets.*; - -public class Snippet30 { - -public static void main (String [] args) { - Display display = new Display (); - Program p = Program.findProgram (".txt"); - if (p != null) p.execute ("c:\\autoexec.bat"); - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet31.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet31.java deleted file mode 100644 index e5dd03c536..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet31.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tracker example snippet: create a tracker (drag when "torn off") - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet31 { - -public static void main (String [] args) { - final Display display = new Display (); - final Shell shell = new Shell (display); - shell.setSize (200, 200); - shell.open (); - Listener listener = new Listener () { - Point point = null; - static final int JITTER = 8; - public void handleEvent (Event event) { - switch (event.type) { - case SWT.MouseDown: - point = new Point (event.x, event.y); - break; - case SWT.MouseMove: - if (point == null) return; - int deltaX = point.x - event.x, deltaY = point.y - event.y; - if (Math.abs (deltaX) < JITTER && Math.abs (deltaY) < JITTER) { - return; - } - Tracker tracker = new Tracker (display, SWT.NONE); - Rectangle rect = display.map (shell, null, shell.getClientArea ()); - rect.x -= deltaX; - rect.y -= deltaY; - tracker.setRectangles (new Rectangle [] {rect}); - tracker.open (); - //FALL THROUGH - case SWT.MouseUp: - point = null; - break; - } - } - }; - shell.addListener (SWT.MouseDown, listener); - shell.addListener (SWT.MouseMove, listener); - shell.addListener (SWT.MouseUp, listener); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet32.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet32.java deleted file mode 100644 index 5bae2ef8cd..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet32.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Program example snippet: find the icon of the program that edits .bmp files - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.program.*; - -public class Snippet32 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Label label = new Label (shell, SWT.NONE); - label.setText ("Can't find icon for .bmp"); - Image image = null; - Program p = Program.findProgram (".bmp"); - if (p != null) { - ImageData data = p.getImageData (); - if (data != null) { - image = new Image (display, data); - label.setImage (image); - } - } - label.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - if (image != null) image.dispose (); - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet33.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet33.java deleted file mode 100644 index d1ebe3ec06..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet33.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * DirectoryDialog example snippet: prompt for a directory - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet33 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.open (); - DirectoryDialog dialog = new DirectoryDialog (shell); - dialog.setFilterPath ("c:\\"); //Windows specific - System.out.println ("RESULT=" + dialog.open ()); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet34.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet34.java deleted file mode 100644 index 30b28ffa72..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet34.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Label example snippet: create a label (with an image) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet34 { - -public static void main (String[] args) { - Display display = new Display(); - Image image = new Image (display, 16, 16); - Color color = display.getSystemColor (SWT.COLOR_RED); - GC gc = new GC (image); - gc.setBackground (color); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); - Shell shell = new Shell (display); - Label label = new Label (shell, SWT.BORDER); - label.setImage (image); - label.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet35.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet35.java deleted file mode 100644 index 2b0859f7eb..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet35.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: create a table (no columns, no headers) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet35 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Table table = new Table (shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - for (int i=0; i<12; i++) { - TableItem item = new TableItem (table, 0); - item.setText ("Item " + i); - } - table.setSize (100, 100); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet36.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet36.java deleted file mode 100644 index c1f1140e1b..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet36.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ToolBar example snippet: create a flat tool bar (images) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet36 { - -public static void main (String [] args) { - Display display = new Display(); - Image image = new Image (display, 16, 16); - Color color = display.getSystemColor (SWT.COLOR_RED); - GC gc = new GC (image); - gc.setBackground (color); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); - Shell shell = new Shell (display); - ToolBar toolBar = new ToolBar (shell, SWT.FLAT | SWT.BORDER); - for (int i=0; i<12; i++) { - ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN); - item.setImage (image); - } - toolBar.pack (); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet37.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet37.java deleted file mode 100644 index 39206850d2..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet37.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Label example snippet: create a label (a separator) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet37 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - new Label (shell, SWT.SEPARATOR | SWT.HORIZONTAL); - new Label (shell, SWT.SEPARATOR | SWT.VERTICAL); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet38.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet38.java deleted file mode 100644 index d264c97ba4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet38.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: create a table (columns, headers, lines) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet38 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Table table = new Table (shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); - table.setLinesVisible (true); - table.setHeaderVisible (true); - String[] titles = {" ", "C", "!", "Description", "Resource", "In Folder", "Location"}; - for (int i=0; i<titles.length; i++) { - TableColumn column = new TableColumn (table, SWT.NONE); - column.setText (titles [i]); - } - int count = 128; - for (int i=0; i<count; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText (0, "x"); - item.setText (1, "y"); - item.setText (2, "!"); - item.setText (3, "this stuff behaves the way I expect"); - item.setText (4, "almost everywhere"); - item.setText (5, "some.folder"); - item.setText (6, "line " + i + " in nowhere"); - } - for (int i=0; i<titles.length; i++) { - table.getColumn (i).pack (); - } - table.setSize (table.computeSize (SWT.DEFAULT, 200)); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet39.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet39.java deleted file mode 100644 index a5c42a5ee6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet39.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -public class Snippet39 { - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet4.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet4.java deleted file mode 100644 index b22ad88956..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet4.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: prevent escape from closing a dialog - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.widgets.*; - -public class Snippet4 { - - public static void main(String[] args) { - Display display = new Display(); - final Shell shell = new Shell(display); - Button b = new Button(shell, SWT.PUSH); - b.setText("Open Dialog ..."); - b.pack(); - b.setLocation(10, 10); - b.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent se) { - Shell dialog = new Shell(shell, SWT.DIALOG_TRIM); - dialog.addListener(SWT.Traverse, new Listener() { - public void handleEvent(Event e) { - if (e.detail == SWT.TRAVERSE_ESCAPE) { - e.doit = false; - } - } - }); - dialog.open(); - } - }); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); - } - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet40.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet40.java deleted file mode 100644 index fa7aad2321..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet40.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Menu example snippet: create a popup menu (set in multiple controls) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet40 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Composite c1 = new Composite (shell, SWT.BORDER); - c1.setSize (100, 100); - Composite c2 = new Composite (shell, SWT.BORDER); - c2.setBounds (100, 0, 100, 100); - Menu menu = new Menu (shell, SWT.POP_UP); - MenuItem item = new MenuItem (menu, SWT.PUSH); - item.setText ("Popup"); - c1.setMenu (menu); - c2.setMenu (menu); - shell.setMenu (menu); - shell.setSize (300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet41.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet41.java deleted file mode 100644 index f87ced128f..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet41.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tool Tips example snippet: create tool tips for a tab folder, tool bar and control - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet41 { - -public static void main (String [] args) { - String string = "This is a string\nwith a new line."; - Display display = new Display (); - Shell shell = new Shell (display); - shell.open (); - TabFolder folder = new TabFolder (shell, SWT.BORDER); - folder.setSize (200, 200); - TabItem item0 = new TabItem (folder, 0); - item0.setToolTipText (string); - ToolBar bar = new ToolBar (shell, SWT.BORDER); - bar.setBounds (0, 200, 200, 64); - ToolItem item1 = new ToolItem (bar, 0); - item1.setToolTipText (string); - shell.setToolTipText (string); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet42.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet42.java deleted file mode 100644 index f5b395dbb3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet42.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Display example snippet: get the bounds and client area of a display - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet42 { - -public static void main (String [] args) { - Display display = new Display (); - System.out.println ("BOUNDS=" + display.getBounds () + " CLIENT=" + display.getClientArea ()); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet43.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet43.java deleted file mode 100644 index 47d7df7011..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet43.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Caret example snippet: create a caret (using an image) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet43 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.open (); - Caret caret = new Caret (shell, SWT.NONE); - Color white = display.getSystemColor (SWT.COLOR_WHITE); - Color black = display.getSystemColor (SWT.COLOR_BLACK); - Image image = new Image (display, 20, 20); - GC gc = new GC (image); - gc.setBackground (black); - gc.fillRectangle (0, 0, 20, 20); - gc.setForeground (white); - gc.drawLine (0, 0, 19, 19); - gc.drawLine (19, 0, 0, 19); - gc.dispose (); - caret.setLocation (10, 10); - caret.setImage (image); - gc = new GC (shell); - gc.drawImage (image, 10, 64); - caret.setVisible (false); - gc.drawString ("Test", 12, 12); - caret.setVisible (true); - gc.dispose (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet44.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet44.java deleted file mode 100644 index 3179f283e2..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet44.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Cursor example snippet: set the hand cursor into a control - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet44 { - -public static void main (String [] args) { - Display display = new Display (); - final Cursor cursor = new Cursor (display, SWT.CURSOR_HAND); - Shell shell = new Shell (display); - shell.open (); - final Button b = new Button (shell, 0); - b.setBounds (10, 10, 200, 200); - b.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - b.setCursor (cursor); - } - }); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - cursor.dispose (); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet45.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet45.java deleted file mode 100644 index 47fb20264c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet45.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Scale example snippet: create a scale (maximum 40, page increment 5) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet45 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Scale scale = new Scale (shell, SWT.BORDER); - scale.setSize (200, 64); - scale.setMaximum (40); - scale.setPageIncrement (5); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet46.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet46.java deleted file mode 100644 index 1b3feed72a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet46.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Composite example snippet: intercept mouse events (drag a button with the mouse) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet46 { -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - final Composite composite = new Composite (shell, SWT.NONE); - composite.setEnabled (false); - composite.setLayout (new FillLayout ()); - Button button = new Button (composite, SWT.PUSH); - button.setText ("Button"); - composite.pack (); - composite.setLocation (10, 10); - final Point [] offset = new Point [1]; - Listener listener = new Listener () { - public void handleEvent (Event event) { - switch (event.type) { - case SWT.MouseDown: - Rectangle rect = composite.getBounds (); - if (rect.contains (event.x, event.y)) { - Point pt1 = composite.toDisplay (0, 0); - Point pt2 = shell.toDisplay (event.x, event.y); - offset [0] = new Point (pt2.x - pt1.x, pt2.y - pt1.y); - } - break; - case SWT.MouseMove: - if (offset [0] != null) { - Point pt = offset [0]; - composite.setLocation (event.x - pt.x, event.y - pt.y); - } - break; - case SWT.MouseUp: - offset [0] = null; - break; - } - } - }; - shell.addListener (SWT.MouseDown, listener); - shell.addListener (SWT.MouseUp, listener); - shell.addListener (SWT.MouseMove, listener); - shell.setSize (300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet47.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet47.java deleted file mode 100644 index 7f50affedd..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet47.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ToolBar example snippet: create tool bar (normal, hot and disabled images) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet47 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - - Image image = new Image (display, 20, 20); - Color color = display.getSystemColor (SWT.COLOR_BLUE); - GC gc = new GC (image); - gc.setBackground (color); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); - - Image disabledImage = new Image (display, 20, 20); - color = display.getSystemColor (SWT.COLOR_GREEN); - gc = new GC (disabledImage); - gc.setBackground (color); - gc.fillRectangle (disabledImage.getBounds ()); - gc.dispose (); - - Image hotImage = new Image (display, 20, 20); - color = display.getSystemColor (SWT.COLOR_RED); - gc = new GC (hotImage); - gc.setBackground (color); - gc.fillRectangle (hotImage.getBounds ()); - gc.dispose (); - - ToolBar bar = new ToolBar (shell, SWT.BORDER | SWT.FLAT); - bar.setSize (200, 32); - for (int i=0; i<12; i++) { - ToolItem item = new ToolItem (bar, 0); - item.setImage (image); - item.setDisabledImage (disabledImage); - item.setHotImage (hotImage); - if (i % 3 == 0) item.setEnabled (false); - } - - shell.open (); - bar.getItems () [1].setImage (disabledImage); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - disabledImage.dispose (); - hotImage.dispose (); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java deleted file mode 100644 index 16aba2aa68..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Canvas example snippet: scroll an image (flicker free, no double buffering) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet48 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display, - SWT.SHELL_TRIM | SWT.NO_BACKGROUND | - SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); - Image originalImage = null; - FileDialog dialog = new FileDialog (shell, SWT.OPEN); - dialog.setText ("Open an image file or cancel"); - String string = dialog.open (); - if (string != null) { - originalImage = new Image (display, string); - } - if (originalImage == null) { - int width = 150, height = 200; - originalImage = new Image (display, width, height); - GC gc = new GC (originalImage); - gc.fillRectangle (0, 0, width, height); - gc.drawLine (0, 0, width, height); - gc.drawLine (0, height, width, 0); - gc.drawText ("Default Image", 10, 10); - gc.dispose (); - } - final Image image = originalImage; - final Point origin = new Point (0, 0); - final ScrollBar hBar = shell.getHorizontalBar (); - hBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - int hSelection = hBar.getSelection (); - int destX = -hSelection - origin.x; - Rectangle rect = image.getBounds (); - shell.scroll (destX, 0, 0, 0, rect.width, rect.height, false); - origin.x = -hSelection; - } - }); - final ScrollBar vBar = shell.getVerticalBar (); - vBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - int vSelection = vBar.getSelection (); - int destY = -vSelection - origin.y; - Rectangle rect = image.getBounds (); - shell.scroll (0, destY, 0, 0, rect.width, rect.height, false); - origin.y = -vSelection; - } - }); - shell.addListener (SWT.Resize, new Listener () { - public void handleEvent (Event e) { - Rectangle rect = image.getBounds (); - Rectangle client = shell.getClientArea (); - hBar.setMaximum (rect.width); - vBar.setMaximum (rect.height); - hBar.setThumb (Math.min (rect.width, client.width)); - vBar.setThumb (Math.min (rect.height, client.height)); - int hPage = rect.width - client.width; - int vPage = rect.height - client.height; - int hSelection = hBar.getSelection (); - int vSelection = vBar.getSelection (); - if (hSelection >= hPage) { - if (hPage <= 0) hSelection = 0; - origin.x = -hSelection; - } - if (vSelection >= vPage) { - if (vPage <= 0) vSelection = 0; - origin.y = -vSelection; - } - shell.redraw (); - } - }); - shell.addListener (SWT.Paint, new Listener () { - public void handleEvent (Event e) { - GC gc = e.gc; - gc.drawImage (image, origin.x, origin.y); - Rectangle rect = image.getBounds (); - Rectangle client = shell.getClientArea (); - int marginWidth = client.width - rect.width; - if (marginWidth > 0) { - gc.fillRectangle (rect.width, 0, marginWidth, client.height); - } - int marginHeight = client.height - rect.height; - if (marginHeight > 0) { - gc.fillRectangle (0, rect.height, client.width, marginHeight); - } - } - }); - shell.setSize (200, 150); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet49.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet49.java deleted file mode 100644 index 4304c104a6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet49.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ToolBar example snippet: create tool bar (wrap on resize) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet49 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - final ToolBar toolBar = new ToolBar (shell, SWT.WRAP); - for (int i=0; i<12; i++) { - ToolItem item = new ToolItem (toolBar, SWT.PUSH); - item.setText ("Item " + i); - } - shell.addListener (SWT.Resize, new Listener () { - public void handleEvent (Event e) { - Rectangle rect = shell.getClientArea (); - Point size = toolBar.computeSize (rect.width, SWT.DEFAULT); - toolBar.setSize (size); - } - }); - toolBar.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet5.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet5.java deleted file mode 100644 index df0962fc44..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet5.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ScrolledComposite example snippet: scroll a control in a scrolled composite - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.custom.*; - -public class Snippet5 { - -public static void main (String [] args) -{ - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - - // this button is always 400 x 400. Scrollbars appear if the window is resized to be - // too small to show part of the button - ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - Button b1 = new Button(c1, SWT.PUSH); - b1.setText("fixed size button"); - b1.setSize(400, 400); - c1.setContent(b1); - - // this button has a minimum size of 400 x 400. If the window is resized to be big - // enough to show more than 400 x 400, the button will grow in size. If the window - // is made too small to show 400 x 400, scrollbars will appear. - ScrolledComposite c2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - Button b2 = new Button(c2, SWT.PUSH); - b2.setText("expanding button"); - c2.setContent(b2); - c2.setExpandHorizontal(true); - c2.setExpandVertical(true); - c2.setMinWidth(400); - c2.setMinHeight(400); - - shell.setSize(600, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet50.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet50.java deleted file mode 100644 index d0ae34cb7d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet50.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: create a dialog shell - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet50 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setText ("Shell"); - shell.setSize (200, 200); - shell.open (); - Shell dialog = new Shell (shell); - dialog.setText ("Dialog"); - dialog.setSize (200, 200); - dialog.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet51.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet51.java deleted file mode 100644 index a4d763ad26..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet51.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: scroll a table (set the top index) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet51 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Table table = new Table (shell, SWT.BORDER | SWT.MULTI); - table.setSize (200, 200); - for (int i=0; i<128; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("Item " + i); - } - table.setTopIndex (95); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet52.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet52.java deleted file mode 100644 index e2a2a32a8a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet52.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: select an index (select and scroll) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet52 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Table table = new Table (shell, SWT.BORDER | SWT.MULTI); - table.setSize (200, 200); - for (int i=0; i<128; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("Item " + i); - } - table.setSelection (95); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet53.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet53.java deleted file mode 100644 index 933f32588e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet53.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: remove selected items - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet53 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Table table = new Table (shell, SWT.BORDER | SWT.MULTI); - table.setSize (200, 200); - for (int i=0; i<128; i++) { - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("Item " + i); - } - Menu menu = new Menu (shell, SWT.POP_UP); - table.setMenu (menu); - MenuItem item = new MenuItem (menu, SWT.PUSH); - item.setText ("Delete Selection"); - item.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - table.remove (table.getSelectionIndices ()); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet54.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet54.java deleted file mode 100644 index 38caabf85b..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet54.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Sash example snippet: create a sash (allow it to be moved) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet54 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Sash sash = new Sash (shell, SWT.BORDER | SWT.VERTICAL); - sash.setBounds (10, 10, 32, 100); - sash.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - sash.setBounds (e.x, e.y, e.width, e.height); - } - }); - shell.open (); - sash.setFocus (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet55.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet55.java deleted file mode 100644 index b656d807b4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet55.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Text example snippet: resize a text control (show about 10 characters) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet55 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Text text = new Text (shell, SWT.BORDER); - int columns = 10; - GC gc = new GC (text); - FontMetrics fm = gc.getFontMetrics (); - int width = columns * fm.getAverageCharWidth (); - int height = fm.getHeight (); - gc.dispose (); - text.setSize (text.computeSize (width, height)); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet56.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet56.java deleted file mode 100644 index ce067be4aa..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet56.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ProgressBar example snippet: update a progress bar (from another thread) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet56 { - - public static void main(String[] args) { - final Display display = new Display(); - Shell shell = new Shell(display); - final ProgressBar bar = new ProgressBar(shell, SWT.SMOOTH); - bar.setBounds(10, 10, 200, 32); - shell.open(); - final int maximum = bar.getMaximum(); - new Thread() { - public void run() { - for (final int[] i = new int[1]; i[0] <= maximum; i[0]++) { - try {Thread.sleep (100);} catch (Throwable th) {} - if (display.isDisposed()) return; - display.asyncExec(new Runnable() { - public void run() { - if (bar.isDisposed ()) return; - bar.setSelection(i[0]); - } - }); - } - } - }.start(); - 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/Snippet57.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet57.java deleted file mode 100644 index b9d161cae4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet57.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ProgressBar example snippet: update a progress bar (from the UI thread) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet57 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - ProgressBar bar = new ProgressBar (shell, SWT.SMOOTH); - bar.setBounds (10, 10, 200, 32); - shell.open (); - for (int i=0; i<=bar.getMaximum (); i++) { - try {Thread.sleep (100);} catch (Throwable th) {} - bar.setSelection (i); - } - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet58.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet58.java deleted file mode 100644 index 6ad0bbc7bc..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet58.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ToolBar example snippet: place a combo box in a tool bar - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet58 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - ToolBar bar = new ToolBar (shell, SWT.BORDER); - for (int i=0; i<4; i++) { - ToolItem item = new ToolItem (bar, 0); - item.setText ("Item " + i); - } - ToolItem sep = new ToolItem (bar, SWT.SEPARATOR); - int start = bar.getItemCount (); - for (int i=start; i<start+4; i++) { - ToolItem item = new ToolItem (bar, 0); - item.setText ("Item " + i); - } - Combo combo = new Combo (bar, SWT.READ_ONLY); - for (int i=0; i<4; i++) { - combo.add ("Item " + i); - } - combo.pack (); - sep.setWidth (combo.getSize ().x); - sep.setControl (combo); - bar.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet59.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet59.java deleted file mode 100644 index 76605d763e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet59.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * List example snippet: print selected items in a list - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet59 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final List list = new List (shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - for (int i=0; i<128; i++) list.add ("Item " + i); - list.setBounds (0, 0, 100, 100); - list.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - String string = ""; - int [] selection = list.getSelectionIndices (); - for (int i=0; i<selection.length; i++) string += selection [i] + " "; - System.out.println ("Selection={" + string + "}"); - } - }); - list.addListener (SWT.DefaultSelection, new Listener () { - public void handleEvent (Event e) { - String string = ""; - int [] selection = list.getSelectionIndices (); - for (int i=0; i<selection.length; i++) string += selection [i] + " "; - System.out.println ("DefaultSelection={" + string + "}"); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet6.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet6.java deleted file mode 100644 index 6d906ea4c1..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet6.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * GridLayout example snippet: insert widgets into a grid layout - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet6 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - shell.setLayout(new GridLayout()); - final Composite c = new Composite(shell, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - c.setLayout(layout); - for (int i = 0; i < 10; i++) { - Button b = new Button(c, SWT.PUSH); - b.setText("Button "+i); - } - - Button b = new Button(shell, SWT.PUSH); - b.setText("add a new button at row 2 column 1"); - final int[] index = new int[1]; - b.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - Button s = new Button(c, SWT.PUSH); - s.setText("Special "+index[0]); - index[0]++; - Control[] children = c.getChildren(); - s.moveAbove(children[3]); - shell.layout(new Control[] {s}); - } - }); - - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet60.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet60.java deleted file mode 100644 index a9e28d4ebc..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet60.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Display example snippet: create two one shot timers (5000 ms, 2000 ms) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.widgets.*; - -public class Snippet60 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setSize (200, 200); - shell.open (); - display.timerExec (5000, new Runnable () { - public void run () { - System.out.println ("5000"); - } - }); - display.timerExec (2000, new Runnable () { - public void run () { - System.out.println ("2000"); - } - }); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet61.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet61.java deleted file mode 100644 index cd3b2c41eb..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet61.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tree example snippet: print selected items in a tree - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet61 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Tree tree = new Tree (shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - for (int i=0; i<4; i++) { - TreeItem item0 = new TreeItem (tree, 0); - item0.setText ("Item " + i); - for (int j=0; j<4; j++) { - TreeItem item1 = new TreeItem (item0, 0); - item1.setText ("SubItem " + i + " " + j); - for (int k=0; k<4; k++) { - TreeItem item2 = new TreeItem (item1, 0); - item2.setText ("SubItem " + i + " " + j + " " + k); - } - } - } - tree.setBounds (0, 0, 100, 100); - tree.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - String string = ""; - TreeItem [] selection = tree.getSelection (); - for (int i=0; i<selection.length; i++) string += selection [i] + " "; - System.out.println ("Selection={" + string + "}"); - } - }); - tree.addListener (SWT.DefaultSelection, new Listener () { - public void handleEvent (Event e) { - String string = ""; - TreeItem [] selection = tree.getSelection (); - for (int i=0; i<selection.length; i++) string += selection [i] + " "; - System.out.println ("DefaultSelection={" + string + "}"); - } - }); - tree.addListener (SWT.Expand, new Listener () { - public void handleEvent (Event e) { - System.out.println ("Expand={" + e.item + "}"); - } - }); - tree.addListener (SWT.Collapse, new Listener () { - public void handleEvent (Event e) { - System.out.println ("Collapse={" + e.item + "}"); - } - }); - tree.getItems () [0].setExpanded (true); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java deleted file mode 100644 index 9efeb357ed..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Control example snippet: print mouse state and button (down, move, up) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet62 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - Listener listener = new Listener () { - public void handleEvent (Event e) { - String string = "Unknown"; - switch (e.type) { - case SWT.MouseDown: string = "DOWN"; break; - case SWT.MouseMove: string = "MOVE"; break; - case SWT.MouseUp: string = "UP"; break; - } - string +=": button: " + e.button + ", "; - string += "stateMask=0x" + Integer.toHexString (e.stateMask); - if ((e.stateMask & SWT.BUTTON1) != 0) string += " BUTTON1"; - if ((e.stateMask & SWT.BUTTON2) != 0) string += " BUTTON2"; - if ((e.stateMask & SWT.BUTTON3) != 0) string += " BUTTON3"; - if ((e.stateMask & SWT.BUTTON4) != 0) string += " BUTTON4"; - if ((e.stateMask & SWT.BUTTON5) != 0) string += " BUTTON5"; - System.out.println (string); - } - }; - shell.addListener (SWT.MouseDown, listener); - shell.addListener (SWT.MouseMove, listener); - shell.addListener (SWT.MouseUp, listener); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet63.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet63.java deleted file mode 100644 index aa492be4b0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet63.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: create a dialog shell (prompt for a value) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet63 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.pack (); - shell.open (); - final boolean [] result = new boolean [1]; - final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); - dialog.setLayout (new RowLayout ()); - final Button ok = new Button (dialog, SWT.PUSH); - ok.setText ("Ok"); - Button cancel = new Button (dialog, SWT.PUSH); - cancel.setText ("Cancel"); - Listener listener =new Listener () { - public void handleEvent (Event event) { - result [0] = event.widget == ok; - dialog.close (); - } - }; - ok.addListener (SWT.Selection, listener); - cancel.addListener (SWT.Selection, listener); - dialog.pack (); - dialog.open (); - System.out.println ("Prompt ..."); - while (!dialog.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - System.out.println ("Result: " + result [0]); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet64.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet64.java deleted file mode 100644 index 618e6f92c9..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet64.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: print selected items in a table - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet64 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Table table = new Table (shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - for (int i=0; i<16; i++) { - TableItem item = new TableItem (table, 0); - item.setText ("Item " + i); - } - table.setBounds (0, 0, 100, 100); - table.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - String string = ""; - TableItem [] selection = table.getSelection (); - for (int i=0; i<selection.length; i++) string += selection [i] + " "; - System.out.println ("Selection={" + string + "}"); - } - }); - table.addListener (SWT.DefaultSelection, new Listener () { - public void handleEvent (Event e) { - String string = ""; - TableItem [] selection = table.getSelection (); - for (int i=0; i<selection.length; i++) string += selection [i] + " "; - System.out.println ("DefaultSelection={" + string + "}"); - } - }); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet65.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet65.java deleted file mode 100644 index 273fc7a42a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet65.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * FormLayout example snippet: create a simple dialog using form layout - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet65 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - Label label = new Label (shell, SWT.WRAP); - label.setText ("This is a long text string that will wrap when the dialog is resized."); - List list = new List (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - list.setItems (new String [] {"Item 1", "Item2"}); - Button button1 = new Button (shell, SWT.PUSH); - button1.setText ("Ok"); - Button button2 = new Button (shell, SWT.PUSH); - button2.setText ("Cancel"); - - final int insetX = 4, insetY = 4; - FormLayout formLayout = new FormLayout (); - formLayout.marginWidth = insetX; - formLayout.marginHeight = insetY; - shell.setLayout (formLayout); - - Point size = label.computeSize (SWT.DEFAULT, SWT.DEFAULT); - final FormData labelData = new FormData (size.x, SWT.DEFAULT); - labelData.left = new FormAttachment (0, 0); - labelData.right = new FormAttachment (100, 0); - label.setLayoutData (labelData); - shell.addListener (SWT.Resize, new Listener () { - public void handleEvent (Event e) { - Rectangle rect = shell.getClientArea (); - labelData.width = rect.width - insetX * 2; - shell.layout (); - } - }); - - FormData button2Data = new FormData (); - button2Data.right = new FormAttachment (100, -insetX); - button2Data.bottom = new FormAttachment (100, 0); - button2.setLayoutData (button2Data); - - FormData button1Data = new FormData (); - button1Data.right = new FormAttachment (button2, -insetX); - button1Data.bottom = new FormAttachment (100, 0); - button1.setLayoutData (button1Data); - - FormData listData = new FormData (); - listData.left = new FormAttachment (0, 0); - listData.right = new FormAttachment (100, 0); - listData.top = new FormAttachment (label, insetY); - listData.bottom = new FormAttachment (button2, -insetY); - list.setLayoutData (listData); - - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet66.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet66.java deleted file mode 100644 index 8ea29712d1..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet66.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * GC example snippet: implement a simple scribble program - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet66 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - Listener listener = new Listener () { - int lastX = 0, lastY = 0; - public void handleEvent (Event event) { - switch (event.type) { - case SWT.MouseMove: - if ((event.stateMask & SWT.BUTTON1) == 0) break; - GC gc = new GC (shell); - gc.drawLine (lastX, lastY, event.x, event.y); - gc.dispose (); - //FALL THROUGH - case SWT.MouseDown: - lastX = event.x; - lastY = event.y; - break; - } - } - }; - shell.addListener (SWT.MouseDown, listener); - shell.addListener (SWT.MouseMove, listener); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet67.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet67.java deleted file mode 100644 index 974a7fa18a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet67.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * ToolBar example snippet: place a drop down menu in a tool bar - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet67 { - -public static void main (String [] args) { - final Display display = new Display (); - final Shell shell = new Shell (display); - final ToolBar toolBar = new ToolBar (shell, SWT.NONE); - final Menu menu = new Menu (shell, SWT.POP_UP); - for (int i=0; i<8; i++) { - MenuItem item = new MenuItem (menu, SWT.PUSH); - item.setText ("Item " + i); - } - final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN); - item.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - if (event.detail == SWT.ARROW) { - Rectangle rect = item.getBounds (); - Point pt = new Point (rect.x, rect.y + rect.height); - pt = toolBar.toDisplay (pt); - menu.setLocation (pt.x, pt.y); - menu.setVisible (true); - } - } - }); - toolBar.pack (); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - menu.dispose (); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet68.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet68.java deleted file mode 100644 index 12e023ff00..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet68.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Display example snippet: stop a repeating timer when a button is pressed - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet68 { - -public static void main (String [] args) { - final Display display = new Display (); - final Color red = display.getSystemColor (SWT.COLOR_RED); - final Color blue = display.getSystemColor (SWT.COLOR_BLUE); - Shell shell = new Shell (display); - shell.setLayout (new RowLayout ()); - Button button = new Button (shell, SWT.PUSH); - button.setText ("Stop Timer"); - final Label label = new Label (shell, SWT.BORDER); - label.setBackground (red); - final int time = 500; - final Runnable timer = new Runnable () { - public void run () { - if (label.isDisposed ()) return; - Color color = label.getBackground ().equals (red) ? blue : red; - label.setBackground (color); - display.timerExec (time, this); - } - }; - display.timerExec (time, timer); - button.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event event) { - display.timerExec (-1, timer); - } - }); - button.pack (); - label.setLayoutData (new RowData (button.getSize ())); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet69.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet69.java deleted file mode 100644 index a5d63de58c..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet69.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * FormLayout example snippet: center a label and single line text using a form layout - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet69 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Label label = new Label (shell, SWT.NONE | SWT.BORDER); - label.setText ("Name"); - Text text = new Text (shell, SWT.NONE); - - FormLayout layout = new FormLayout (); - layout.marginWidth = layout.marginHeight = 5; - shell.setLayout (layout); - - GC gc = new GC (text); - FontMetrics fm = gc.getFontMetrics (); - int charWidth = fm.getAverageCharWidth (); - int width = text.computeSize (charWidth * 8, SWT.DEFAULT).x; - gc.dispose (); - FormData data = new FormData (width, SWT.DEFAULT); - text.setLayoutData (data); - data.left = new FormAttachment (label, 5); - data.top = new FormAttachment (label, 0, SWT.CENTER); - - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet7.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet7.java deleted file mode 100644 index 65ee9f9ae1..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet7.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * example snippet: create a table (lazy) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet7 { - -public static void main (String [] args) { - final Display display = new Display (); - final Image image = new Image (display, 16, 16); - GC gc = new GC (image); - gc.setBackground (display.getSystemColor (SWT.COLOR_RED)); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); - final Shell shell = new Shell (display); - shell.setText ("Lazy Table"); - shell.setLayout (new FillLayout ()); - final Table table = new Table (shell, SWT.BORDER | SWT.MULTI); - table.setSize (200, 200); - Thread thread = new Thread () { - public void run () { - for (int i=0; i<20000; i++) { - if (table.isDisposed ()) return; - final int [] index = new int [] {i}; - display.syncExec (new Runnable () { - public void run () { - if (table.isDisposed ()) return; - TableItem item = new TableItem (table, SWT.NONE); - item.setText ("Table Item " + index [0]); - item.setImage (image); - } - }); - } - } - }; - thread.start (); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - image.dispose (); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet70.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet70.java deleted file mode 100644 index 20b12c120d..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet70.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * GC example snippet: create an icon (in memory) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet70 { - -public static void main (String [] args) { - Display display = new Display (); - Color red = display.getSystemColor (SWT.COLOR_RED); - Color white = display.getSystemColor (SWT.COLOR_WHITE); - Color black = display.getSystemColor (SWT.COLOR_BLACK); - - Image image = new Image (display, 20, 20); - GC gc = new GC (image); - gc.setBackground (red); - gc.fillRectangle (5, 5, 10, 10); - gc.dispose (); - ImageData imageData = image.getImageData (); - - PaletteData palette = new PaletteData ( - new RGB [] { - new RGB (0, 0, 0), - new RGB (0xFF, 0xFF, 0xFF), - }); - ImageData maskData = new ImageData (20, 20, 1, palette); - Image mask = new Image (display, maskData); - gc = new GC (mask); - gc.setBackground (black); - gc.fillRectangle (0, 0, 20, 20); - gc.setBackground (white); - gc.fillRectangle (5, 5, 10, 10); - gc.dispose (); - maskData = mask.getImageData (); - - Image icon = new Image (display, imageData, maskData); - Shell shell = new Shell (display); - Button button = new Button (shell, SWT.PUSH); - button.setImage (icon); - button.setSize (60, 60); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - icon.dispose (); - image.dispose (); - mask.dispose (); - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet71.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet71.java deleted file mode 100644 index 75bc19d10f..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet71.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * FormLayout example snippet: create a simple OK/CANCEL dialog using form layout - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet71 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.pack (); - shell.open (); - Shell dialog = new Shell (shell, SWT.DIALOG_TRIM); - Label label = new Label (dialog, SWT.NONE); - label.setText ("Exit the application?"); - Button okButton = new Button (dialog, SWT.PUSH); - okButton.setText ("&OK"); - Button cancelButton = new Button (dialog, SWT.PUSH); - cancelButton.setText ("&Cancel"); - - FormLayout form = new FormLayout (); - form.marginWidth = form.marginHeight = 8; - dialog.setLayout (form); - FormData okData = new FormData (); - okData.top = new FormAttachment (label, 8); - okButton.setLayoutData (okData); - FormData cancelData = new FormData (); - cancelData.left = new FormAttachment (okButton, 8); - cancelData.top = new FormAttachment (okButton, 0, SWT.TOP); - cancelButton.setLayoutData (cancelData); - - dialog.setDefaultButton (okButton); - dialog.pack (); - dialog.open (); - - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet72.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet72.java deleted file mode 100644 index b862fd0cf3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet72.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * FileDialog example snippet: prompt for a file name (to save) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet72 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.open (); - FileDialog dialog = new FileDialog (shell, SWT.SAVE); - dialog.setFilterNames (new String [] {"Batch Files", "All Files (*.*)"}); - dialog.setFilterExtensions (new String [] {"*.bat", "*.*"}); //Windows wild cards - dialog.setFilterPath ("c:\\"); //Windows path - dialog.setFileName ("fred.bat"); - System.out.println ("Save to: " + dialog.open ()); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet73.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet73.java deleted file mode 100644 index 08453c84c1..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet73.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Menu example snippet: enable menu items dynamically (when menu shown) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet73 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Tree tree = new Tree (shell, SWT.BORDER | SWT.MULTI); - final Menu menu = new Menu (shell, SWT.POP_UP); - tree.setMenu (menu); - for (int i=0; i<12; i++) { - TreeItem treeItem = new TreeItem (tree, SWT.NONE); - treeItem.setText ("Item " + i); - MenuItem menuItem = new MenuItem (menu, SWT.PUSH); - menuItem.setText (treeItem.getText ()); - } - menu.addListener (SWT.Show, new Listener () { - public void handleEvent (Event event) { - MenuItem [] menuItems = menu.getItems (); - TreeItem [] treeItems = tree.getSelection (); - for (int i=0; i<menuItems.length; i++) { - String text = menuItems [i].getText (); - int index = 0; - while (index<treeItems.length) { - if (treeItems [index].getText ().equals (text)) break; - index++; - } - menuItems [i].setEnabled (index != treeItems.length); - } - } - }); - tree.setSize (200, 200); - shell.setSize (300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet74.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet74.java deleted file mode 100644 index 84a312f0c4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet74.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Caret example snippet: create a caret - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet74 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Caret caret = new Caret (shell, SWT.NONE); - caret.setBounds (10, 10, 2, 32); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet75.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet75.java deleted file mode 100644 index 06ece3b0a8..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet75.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Composite example snippet: set the tab traversal order of children - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet75 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new RowLayout ()); - - Composite c1 = new Composite (shell, SWT.BORDER); - c1.setLayout (new RowLayout ()); - Button b1 = new Button (c1, SWT.PUSH); - b1.setText ("B1"); - Button [] radios = new Button [3]; - for (int i=0; i<radios.length; i++) { - radios [i] = new Button (c1, SWT.RADIO); - radios [i].setText ("R" + (i ==1 ? "&" : "") + i); - } - Button b2 = new Button (c1, SWT.PUSH); - b2.setText ("B2"); - List l1 = new List (c1, SWT.SINGLE | SWT.BORDER); - l1.setItems (new String [] {"L1"}); - Button b3 = new Button (c1, SWT.PUSH); - b3.setText ("B&3"); - Button b3_1 = new Button (c1, SWT.PUSH); - b3_1.setText ("B3_1"); - - Composite c2 = new Composite (shell, SWT.BORDER); - c2.setLayout (new RowLayout ()); - Button b4 = new Button (c2, SWT.PUSH); - b4.setText ("B&4"); - Button b5 = new Button (c2, SWT.PUSH); - b5.setText ("B&5"); - - List l2 = new List (shell, SWT.SINGLE | SWT.BORDER); - l2.setItems (new String [] {"L2"}); - - ToolBar tb1 = new ToolBar (shell, SWT.FLAT | SWT.BORDER); - ToolItem i1 = new ToolItem (tb1, SWT.RADIO); - i1.setText ("I1"); - ToolItem i2 = new ToolItem (tb1, SWT.RADIO); - i2.setText ("I&2"); - Combo combo1 = new Combo (tb1, SWT.READ_ONLY | SWT.BORDER); - combo1.setItems (new String [] {"C1"}); - combo1.setText ("C1"); - combo1.pack (); - ToolItem i3 = new ToolItem (tb1, SWT.SEPARATOR); - i3.setWidth (combo1.getSize ().x); - i3.setControl (combo1); - i3.setText ("I3"); - ToolItem i4 = new ToolItem (tb1, SWT.PUSH); - i4.setText ("I4"); - ToolItem i5 = new ToolItem (tb1, SWT.CHECK); - i5.setText ("I5"); - - Button b6 = new Button (shell, SWT.PUSH); - b6.setText ("B&6"); - - Composite c4 = new Composite (shell, SWT.BORDER); - c4.setSize (32, 32); - Composite c5 = new Composite (c4, SWT.BORDER); - c5.setSize (20, 20); - - Control [] list1 = new Control [] {b2, b1, b3_1, b3}; - c1.setTabList (list1); - Control [] list2 = new Control [] {c1, b6, tb1, c4, c2, l2}; - shell.setTabList (list2); - - shell.pack (); - shell.open (); - - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet76.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet76.java deleted file mode 100644 index 84f4b7a9f2..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet76.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * TabFolder example snippet: create a tab folder (six pages) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet76 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - final TabFolder tabFolder = new TabFolder (shell, SWT.BORDER); - for (int i=0; i<6; i++) { - TabItem item = new TabItem (tabFolder, SWT.NONE); - item.setText ("TabItem " + i); - Button button = new Button (tabFolder, SWT.PUSH); - button.setText ("Page " + i); - item.setControl (button); - } - tabFolder.setSize (400, 200); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java deleted file mode 100644 index 3489bea71e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Table example snippet: resize columns as table resizes - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet77 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - - final Composite comp = new Composite(shell, SWT.NONE); - final Table table = new Table(comp, SWT.BORDER | SWT.V_SCROLL); - table.setHeaderVisible(true); - table.setLinesVisible(true); - final TableColumn column1 = new TableColumn(table, SWT.NONE); - column1.setText("Column 1"); - final TableColumn column2 = new TableColumn(table, SWT.NONE); - column2.setText("Column 2"); - for (int i = 0; i < 10; i++) { - TableItem item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"item 0" + i, "item 1"+i}); - } - comp.addControlListener(new ControlAdapter() { - public void controlResized(ControlEvent e) { - Rectangle area = comp.getClientArea(); - Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); - int width = area.width - 2*table.getBorderWidth(); - if (preferredSize.y > area.height + table.getHeaderHeight()) { - // Subtract the scrollbar width from the total column width - // if a vertical scrollbar will be required - Point vBarSize = table.getVerticalBar().getSize(); - width -= vBarSize.x; - } - Point oldSize = table.getSize(); - if (oldSize.x > area.width) { - // table is getting smaller so make the columns - // smaller first and then resize the table to - // match the client area width - column1.setWidth(width/3); - column2.setWidth(width - column1.getWidth()); - table.setSize(area.width, area.height); - } else { - // table is getting bigger so make the table - // bigger first and then make the columns wider - // to match the client area width - table.setSize(area.width, area.height); - column1.setWidth(width/3); - column2.setWidth(width - column1.getWidth()); - } - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet78.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet78.java deleted file mode 100644 index a57722f8f2..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet78.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Drag and Drop example snippet: drag text between two labels - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet78 { - -public static void main (String [] args) { - - Display display = Display.getDefault (); - final Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - final Label label1 = new Label (shell, SWT.BORDER); - label1.setText ("TEXT"); - final Label label2 = new Label (shell, SWT.BORDER); - setDragDrop (label1); - setDragDrop (label2); - shell.setSize (200, 200); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -public static void setDragDrop (final Label label) { - - Transfer[] types = new Transfer[] {TextTransfer.getInstance()}; - int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; - - final DragSource source = new DragSource (label, operations); - source.setTransfer(types); - source.addDragListener (new DragSourceListener () { - public void dragStart(DragSourceEvent event) { - event.doit = (label.getText ().length () != 0); - } - public void dragSetData (DragSourceEvent event) { - event.data = label.getText (); - } - public void dragFinished(DragSourceEvent event) { - if (event.detail == DND.DROP_MOVE) - label.setText (""); - } - }); - - DropTarget target = new DropTarget(label, operations); - target.setTransfer(types); - target.addDropListener (new DropTargetAdapter() { - public void drop(DropTargetEvent event) { - if (event.data == null) { - event.detail = DND.DROP_NONE; - return; - } - label.setText ((String) event.data); - } - }); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet79.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet79.java deleted file mode 100644 index f500c0a4f4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet79.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Drag and Drop example snippet: define my own data transfer type - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import java.io.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet79 { - -/* The data being transferred is an <bold>array of type MyType</bold> where MyType is define as: */ -static class MyType { - String fileName; - long fileLength; - long lastModified; -} - -static class MyTransfer extends ByteArrayTransfer { - - private static final String MYTYPENAME = "name_for_my_type"; - private static final int MYTYPEID = registerType (MYTYPENAME); - private static MyTransfer _instance = new MyTransfer (); - -public static MyTransfer getInstance () { - return _instance; -} - -public void javaToNative (Object object, TransferData transferData) { - if (!checkMyType(object) || !isSupportedType (transferData)) { - DND.error(DND.ERROR_INVALID_DATA); - } - MyType [] myTypes = (MyType []) object; - try { - // write data to a byte array and then ask super to convert to pMedium - ByteArrayOutputStream out = new ByteArrayOutputStream (); - DataOutputStream writeOut = new DataOutputStream (out); - for (int i = 0, length = myTypes.length; i < length; i++) { - byte [] buffer = myTypes [i].fileName.getBytes (); - writeOut.writeInt (buffer.length); - writeOut.write (buffer); - writeOut.writeLong (myTypes [i].fileLength); - writeOut.writeLong (myTypes [i].lastModified); - } - byte [] buffer = out.toByteArray (); - writeOut.close (); - super.javaToNative (buffer, transferData); - } - catch (IOException e) {} -} - -public Object nativeToJava (TransferData transferData) { - if (isSupportedType (transferData)) { - byte [] buffer = (byte []) super.nativeToJava (transferData); - if (buffer == null) return null; - - MyType [] myData = new MyType [0]; - try { - ByteArrayInputStream in = new ByteArrayInputStream (buffer); - DataInputStream readIn = new DataInputStream (in); - while (readIn.available () > 20) { - MyType datum = new MyType (); - int size = readIn.readInt (); - byte [] name = new byte [size]; - readIn.read (name); - datum.fileName = new String (name); - datum.fileLength = readIn.readLong (); - datum.lastModified = readIn.readLong (); - MyType [] newMyData = new MyType [myData.length + 1]; - System.arraycopy (myData, 0, newMyData, 0, myData.length); - newMyData [myData.length] = datum; - myData = newMyData; - } - readIn.close (); - } - catch (IOException ex) { - return null; - } - return myData; - } - - return null; -} - -protected String [] getTypeNames () { - return new String [] {MYTYPENAME}; -} - -protected int [] getTypeIds () { - return new int [] {MYTYPEID}; -} - -boolean checkMyType(Object object) { - if (object == null || - !(object instanceof MyType[]) || - ((MyType[])object).length == 0) { - return false; - } - MyType[] myTypes = (MyType[])object; - for (int i = 0; i < myTypes.length; i++) { - if (myTypes[i] == null || - myTypes[i].fileName == null || - myTypes[i].fileName.length() == 0) { - return false; - } - } - return true; -} - -protected boolean validate(Object object) { - return checkMyType(object); -} -} - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new FillLayout ()); - final Label label1 = new Label (shell, SWT.BORDER | SWT.WRAP); - label1.setText ("Drag Source for MyData[]"); - final Label label2 = new Label (shell, SWT.BORDER | SWT.WRAP); - label2.setText ("Drop Target for MyData[]"); - - DragSource source = new DragSource (label1, DND.DROP_COPY); - source.setTransfer (new Transfer [] {MyTransfer.getInstance ()}); - source.addDragListener (new DragSourceAdapter () { - public void dragSetData (DragSourceEvent event) { - MyType myType1 = new MyType (); - myType1.fileName = "C:\\abc.txt"; - myType1.fileLength = 1000; - myType1.lastModified = 12312313; - MyType myType2 = new MyType (); - myType2.fileName = "C:\\xyz.txt"; - myType2.fileLength = 500; - myType2.lastModified = 12312323; - event.data = new MyType [] {myType1, myType2}; - } - }); - DropTarget target = new DropTarget (label2, DND.DROP_COPY | DND.DROP_DEFAULT); - target.setTransfer (new Transfer [] {MyTransfer.getInstance ()}); - target.addDropListener (new DropTargetAdapter () { - public void dragEnter (DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) { - event.detail = DND.DROP_COPY; - } - } - - public void dragOperationChanged (DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) { - event.detail = DND.DROP_COPY; - } - } - - public void drop (DropTargetEvent event) { - if (event.data != null) { - MyType [] myTypes = (MyType []) event.data; - if (myTypes != null) { - String string = ""; - for (int i = 0; i < myTypes.length; i++) { - string += myTypes [i].fileName + " "; - } - label2.setText (string); - } - } - } - - }); - shell.setSize (200, 200); - 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/Snippet8.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet8.java deleted file mode 100644 index b38064c9c6..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet8.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tree example snippet: create a tree (lazy) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -import java.io.*; - -public class Snippet8 { - -public static void main (String [] args) { - final Display display = new Display (); - final Shell shell = new Shell (display); - shell.setText ("Lazy Tree"); - shell.setLayout (new FillLayout ()); - final Tree tree = new Tree (shell, SWT.BORDER); - File [] roots = File.listRoots (); - for (int i=0; i<roots.length; i++) { - TreeItem root = new TreeItem (tree, 0); - root.setText (roots [i].toString ()); - root.setData (roots [i]); - new TreeItem (root, 0); - } - tree.addListener (SWT.Expand, new Listener () { - public void handleEvent (final Event event) { - final TreeItem root = (TreeItem) event.item; - TreeItem [] items = root.getItems (); - for (int i= 0; i<items.length; i++) { - if (items [i].getData () != null) return; - items [i].dispose (); - } - File file = (File) root.getData (); - File [] files = file.listFiles (); - if (files == null) return; - for (int i= 0; i<files.length; i++) { - TreeItem item = new TreeItem (root, 0); - item.setText (files [i].getName ()); - item.setData (files [i]); - if (files [i].isDirectory()) { - new TreeItem (item, 0); - } - } - } - }); - Point size = tree.computeSize (300, SWT.DEFAULT); - int width = Math.max (300, size.x); - int height = Math.max (300, size.y); - shell.setSize (shell.computeSize (width, height)); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet80.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet80.java deleted file mode 100644 index 14531222db..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet80.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tree example snippet: limit selection to items that match a pattern - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet80 { - -public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); - for (int i = 0; i < 2; i++) { - TreeItem item = new TreeItem(tree, SWT.NONE); - item.setText("item " + i); - for (int j = 0; j < 2; j++) { - TreeItem subItem = new TreeItem(item, SWT.NONE); - subItem.setText("item " + j); - for (int k = 0; k < 2; k++) { - TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); - subsubItem.setText("item " + k); - } - } - } - - tree.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - TreeItem[] selection = tree.getSelection(); - TreeItem[] revisedSelection = new TreeItem[0]; - for (int i = 0; i < selection.length; i++) { - String text = selection[i].getText(); - if (text.indexOf("1") > 0) { - TreeItem[] newSelection = new TreeItem[revisedSelection.length + 1]; - System.arraycopy(revisedSelection, 0, newSelection, 0, revisedSelection.length); - newSelection[revisedSelection.length] = selection[i]; - revisedSelection = newSelection; - } - } - tree.setSelection(revisedSelection); - } - }); - - shell.setSize(300, 300); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.java deleted file mode 100644 index 5eccabd377..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * OLE and ActiveX example snippet: browse the typelibinfo for a program id - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.internal.ole.win32.*; -import org.eclipse.swt.ole.win32.*; -import org.eclipse.swt.widgets.*; - -public class Snippet81 { - -public static void main(String[] args) { - - if (args.length == 0) { - System.out.println("Usage: java Main <program id>"); - return; - } - - String progID = args[0]; - - Shell shell = new Shell(); - - OleFrame frame = new OleFrame(shell, SWT.NONE); - OleControlSite site = null; - OleAutomation auto = null; - try { - site = new OleControlSite(frame, SWT.NONE, progID); - auto = new OleAutomation(site); - } catch (SWTException ex) { - System.out.println("Unable to open type library for "+progID); - return; - } - - TYPEATTR typeattr = auto.getTypeInfoAttributes(); - if (typeattr != null) { - if (typeattr.cFuncs > 0) System.out.println("Functions for "+progID+" :\n"); - for (int i = 0; i < typeattr.cFuncs; i++) { - OleFunctionDescription data = auto.getFunctionDescription(i); - String argList = ""; - int firstOptionalArgIndex = data.args.length - data.optionalArgCount; - for (int j = 0; j < data.args.length; j++) { - argList += "["; - if (j >= firstOptionalArgIndex) argList += "optional, "; - argList += getDirection(data.args[j].flags)+"] "+getTypeName(data.args[j].type)+" "+data.args[j].name; - if ( j < data.args.length - 1) argList += ", "; - } - System.out.println(getInvokeKind(data.invokeKind)+" (id = "+data.id+") : " - +"\n\tSignature : "+getTypeName(data.returnType)+" "+data.name+"("+argList+")" - +"\n\tDescription : "+data.documentation - +"\n\tHelp File : "+data.helpFile+"\n"); - } - - if (typeattr.cVars > 0) System.out.println("\n\nVariables for "+progID+" :\n"); - for (int i = 0; i < typeattr.cVars; i++) { - OlePropertyDescription data = auto.getPropertyDescription(i); - System.out.println("PROPERTY (id = "+data.id+") :" - +"\n\tName : "+data.name - +"\n\tType : "+getTypeName(data.type)+"\n"); - } - } - - auto.dispose(); - shell.dispose(); - -} -private static String getTypeName(int type) { - switch (type) { - case OLE.VT_BOOL : return "boolean"; - case OLE.VT_R4 : return "float"; - case OLE.VT_R8 : return "double"; - case OLE.VT_I4 : return "int"; - case OLE.VT_DISPATCH : return "IDispatch"; - case OLE.VT_UNKNOWN : return "IUnknown"; - case OLE.VT_I2 : return "short"; - case OLE.VT_BSTR : return "String"; - case OLE.VT_VARIANT : return "Variant"; - case OLE.VT_CY : return "Currency"; - case OLE.VT_DATE : return "Date"; - case OLE.VT_UI1 : return "unsigned char"; - case OLE.VT_UI4 : return "unsigned int"; - case OLE.VT_USERDEFINED : return "UserDefined"; - case OLE.VT_HRESULT : return "int"; - case OLE.VT_VOID : return "void"; - - case OLE.VT_BYREF | OLE.VT_BOOL : return "boolean *"; - case OLE.VT_BYREF | OLE.VT_R4 : return "float *"; - case OLE.VT_BYREF | OLE.VT_R8 : return "double *"; - case OLE.VT_BYREF | OLE.VT_I4 : return "int *"; - case OLE.VT_BYREF | OLE.VT_DISPATCH : return "IDispatch *"; - case OLE.VT_BYREF | OLE.VT_UNKNOWN : return "IUnknown *"; - case OLE.VT_BYREF | OLE.VT_I2 : return "short *"; - case OLE.VT_BYREF | OLE.VT_BSTR : return "String *"; - case OLE.VT_BYREF | OLE.VT_VARIANT : return "Variant *"; - case OLE.VT_BYREF | OLE.VT_CY : return "Currency *"; - case OLE.VT_BYREF | OLE.VT_DATE : return "Date *"; - case OLE.VT_BYREF | OLE.VT_UI1 : return "unsigned char *"; - case OLE.VT_BYREF | OLE.VT_UI4 : return "unsigned int *"; - case OLE.VT_BYREF | OLE.VT_USERDEFINED : return "UserDefined *"; - } - return "unknown "+ type; -} -private static String getDirection(int direction){ - String dirString = ""; - boolean comma = false; - if ((direction & OLE.IDLFLAG_FIN) != 0) { - dirString += "in"; - comma = true; - } - if ((direction & OLE.IDLFLAG_FOUT) != 0){ - if (comma) dirString += ", "; - dirString += "out"; - comma = true; - } - if ((direction & OLE.IDLFLAG_FLCID) != 0){ - if (comma) dirString += ", "; - dirString += "lcid"; - comma = true; - } - if ((direction & OLE.IDLFLAG_FRETVAL) != 0){ - if (comma) dirString += ", "; - dirString += "retval"; - } - - return dirString; -} -private static String getInvokeKind(int invKind) { - switch (invKind) { - case OLE.INVOKE_FUNC : return "METHOD"; - case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET"; - case OLE.INVOKE_PROPERTYPUT : return "PROPERTY PUT"; - case OLE.INVOKE_PROPERTYPUTREF : return "PROPERTY PUT BY REF"; - } - return "unknown "+invKind; -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet82.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet82.java deleted file mode 100644 index da767e2cac..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet82.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * CTabFolder example snippet: prevent an item from closing - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet82 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - CTabFolder folder = new CTabFolder(shell, SWT.BORDER); - for (int i = 0; i < 4; i++) { - CTabItem item = new CTabItem(folder, SWT.CLOSE); - item.setText("Item "+i); - Text text = new Text(folder, SWT.MULTI); - text.setText("Content for Item "+i); - item.setControl(text); - } - - final CTabItem specialItem = new CTabItem(folder, SWT.CLOSE); - specialItem.setText("Don't Close Me"); - Text text = new Text(folder, SWT.MULTI); - text.setText("This tab can never be closed"); - specialItem.setControl(text); - - folder.addCTabFolder2Listener(new CTabFolder2Adapter() { - public void close(CTabFolderEvent event) { - if (event.item.equals(specialItem)) { - event.doit = false; - } - } - }); - - final CTabItem noCloseItem = new CTabItem(folder, SWT.NONE); - noCloseItem.setText("No Close Button"); - Text text2 = new Text(folder, SWT.MULTI); - text2.setText("This tab does not have a close button"); - noCloseItem.setControl(text2); - - shell.pack(); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet83.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet83.java deleted file mode 100644 index 86fc783234..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet83.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Drag and Drop example snippet: determine data types available (win32 only) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.internal.ole.win32.*; -import org.eclipse.swt.internal.win32.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet83 extends ByteArrayTransfer { - -private static Snippet83 _instance = new Snippet83(); -private int[] ids; -private String[] names; - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Table control = new Table(shell, SWT.NONE); - TableItem item = new TableItem(control, SWT.NONE); - item.setText("Drag data over this site to see the native transfer type."); - DropTarget target = new DropTarget(control, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE); - target.setTransfer(new Transfer[] {Snippet83.getInstance()}); - target.addDropListener(new DropTargetAdapter() { - public void dragEnter(DropTargetEvent event) { - String ops = ""; - if ((event.operations & DND.DROP_COPY) != 0) ops += "Copy;"; - if ((event.operations & DND.DROP_MOVE) != 0) ops += "Move;"; - if ((event.operations & DND.DROP_LINK) != 0) ops += "Link;"; - control.removeAll(); - TableItem item1 = new TableItem(control,SWT.NONE); - item1.setText("Allowed Operations are "+ops); - - if (event.detail == DND.DROP_DEFAULT) { - if ((event.operations & DND.DROP_COPY) != 0) { - event.detail = DND.DROP_COPY; - } else if ((event.operations & DND.DROP_LINK) != 0) { - event.detail = DND.DROP_LINK; - } else if ((event.operations & DND.DROP_MOVE) != 0) { - event.detail = DND.DROP_MOVE; - } - } - - TransferData[] data = event.dataTypes; - for (int i = 0; i < data.length; i++) { - int id = data[i].type; - String name = getNameFromId(id); - TableItem item2 = new TableItem(control,SWT.NONE); - item2.setText("Data type is "+id+" "+name); - } - } - }); - - shell.setSize(400, 400); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} - -public static Snippet83 getInstance () { - return _instance; -} -Snippet83() { - ids = new int[80000]; - names = new String[80000]; - for (int i = 0; i < ids.length; i++) { - ids[i] = i; - names[i] = getNameFromId(i); - } -} -public void javaToNative (Object object, TransferData transferData) { -} -public Object nativeToJava(TransferData transferData){ - return "Hello World"; -} -protected String[] getTypeNames(){ - return names; -} -protected int[] getTypeIds(){ - return ids; -} -static String getNameFromId(int id) { - String name = null; - int maxSize = 128; - TCHAR buffer = new TCHAR(0, maxSize); - int size = COM.GetClipboardFormatName(id, buffer, maxSize); - String type = null; - if (size != 0) { - name = buffer.toString(0, size); - } else { - switch (id) { - case COM.CF_HDROP: - name = "CF_HDROP"; - break; - case COM.CF_TEXT: - name = "CF_TEXT"; - break; - case COM.CF_BITMAP: - name = "CF_BITMAP"; - break; - case COM.CF_METAFILEPICT: - name = "CF_METAFILEPICT"; - break; - case COM.CF_SYLK: - name = "CF_SYLK"; - break; - case COM.CF_DIF: - name = "CF_DIF"; - break; - case COM.CF_TIFF: - name = "CF_TIFF"; - break; - case COM.CF_OEMTEXT: - name = "CF_OEMTEXT"; - break; - case COM.CF_DIB: - name = "CF_DIB"; - break; - case COM.CF_PALETTE: - name = "CF_PALETTE"; - break; - case COM.CF_PENDATA: - name = "CF_PENDATA"; - break; - case COM.CF_RIFF: - name = "CF_RIFF"; - break; - case COM.CF_WAVE: - name = "CF_WAVE"; - break; - case COM.CF_UNICODETEXT: - name = "CF_UNICODETEXT"; - break; - case COM.CF_ENHMETAFILE: - name = "CF_ENHMETAFILE"; - break; - case COM.CF_LOCALE: - name = "CF_LOCALE"; - break; - case COM.CF_MAX: - name = "CF_MAX"; - break; - } - - } - return name; -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet84.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet84.java deleted file mode 100644 index 9b9cef0a67..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet84.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Drag and Drop example snippet: define a default operation (in this example, Copy) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet84 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - - final Label label = new Label(shell, SWT.BORDER); - label.setText("Drag Source"); - DragSource source = new DragSource(label, DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK); - source.setTransfer(new Transfer[] {TextTransfer.getInstance()}); - source.addDragListener(new DragSourceAdapter() { - public void dragSetData(DragSourceEvent event) { - event.data = "Text Transferred"; - } - public void dragFinished(DragSourceEvent event) { - if (event.doit) { - String operation = null; - switch (event.detail) { - case DND.DROP_MOVE: - operation = "moved"; break; - case DND.DROP_COPY: - operation = "copied"; break; - case DND.DROP_LINK: - operation = "linked"; break; - case DND.DROP_NONE: - operation = "disallowed"; break; - default: - operation = "unknown"; break; - } - label.setText("Drag Source (data "+operation+")"); - } else { - label.setText("Drag Source (drag cancelled)"); - } - } - }); - - final Text text = new Text(shell, SWT.BORDER | SWT.MULTI); - text.setText("Drop Target"); - DropTarget target = new DropTarget(text, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK); - target.setTransfer(new Transfer[] {TextTransfer.getInstance()}); - target.addDropListener(new DropTargetAdapter() { - public void dragEnter(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; - } - public void dragOperationChanged(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; - } - public void drop(DropTargetEvent event) { - String operation = null; - switch (event.detail) { - case DND.DROP_MOVE: - operation = "moved"; break; - case DND.DROP_COPY: - operation = "copied"; break; - case DND.DROP_LINK: - operation = "linked"; break; - case DND.DROP_NONE: - operation = "disallowed"; break; - default: - operation = "unknown"; break; - } - text.append("\n"+operation+(String)event.data); - } - }); - - shell.setSize(400, 400); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet85.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet85.java deleted file mode 100644 index dde87d5377..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet85.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * PocketPC example snippet: Hello World - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet85 { - -public static void main(String[] args) { - Display display = new Display(); - - /* - * Create a Shell with the default style - * i.e. full screen, no decoration on PocketPC. - */ - Shell shell = new Shell(display); - - /* - * Set a text so that the top level Shell - * also appears in the PocketPC task list - */ - shell.setText("Main"); - - /* - * Set a menubar to follow UI guidelines - * on PocketPC - */ - Menu mb = new Menu(shell, SWT.BAR); - shell.setMenuBar(mb); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet86.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet86.java deleted file mode 100644 index 9c521fa47e..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet86.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * PocketPC Shell example snippet: 'Ok' button - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet86 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display, SWT.CLOSE); - shell.setText("Main"); - Menu mb = new Menu(shell, SWT.BAR); - shell.setMenuBar(mb); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet87.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet87.java deleted file mode 100644 index 32dc0e970b..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet87.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * PocketPC Shell example snippet: resize automatically as SIP is on or off - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet87 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display, SWT.RESIZE); - shell.setText("Main"); - Menu mb = new Menu(shell, SWT.BAR); - shell.setMenuBar(mb); - /* Add a button to make the resize more visual */ - FillLayout layout = new FillLayout(); - shell.setLayout(layout); - Button button = new Button(shell, SWT.PUSH); - button.setText("Main"); - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet88.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet88.java deleted file mode 100644 index 6590892042..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet88.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * TableEditor example snippet: edit the text of a table item (in place) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet88 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Table table = new Table(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION); - TableColumn column1 = new TableColumn(table, SWT.NONE); - TableColumn column2 = new TableColumn(table, SWT.NONE); - for (int i = 0; i < 10; i++) { - TableItem item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"item " + i, "edit this value"}); - } - column1.pack(); - column2.pack(); - - final TableEditor editor = new TableEditor(table); - //The editor must have the same size as the cell and must - //not be any smaller than 50 pixels. - editor.horizontalAlignment = SWT.LEFT; - editor.grabHorizontal = true; - editor.minimumWidth = 50; - // editing the second column - final int EDITABLECOLUMN = 1; - - table.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - // Clean up any previous editor control - Control oldEditor = editor.getEditor(); - if (oldEditor != null) oldEditor.dispose(); - - // Identify the selected row - TableItem item = (TableItem)e.item; - if (item == null) return; - - // The control that will be the editor must be a child of the Table - Text newEditor = new Text(table, SWT.NONE); - newEditor.setText(item.getText(EDITABLECOLUMN)); - newEditor.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent me) { - Text text = (Text)editor.getEditor(); - editor.getItem().setText(EDITABLECOLUMN, text.getText()); - } - }); - newEditor.selectAll(); - newEditor.setFocus(); - editor.setEditor(newEditor, item, EDITABLECOLUMN); - } - }); - shell.setSize(300, 300); - shell.open(); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet89.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet89.java deleted file mode 100644 index 923e07d993..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet89.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Menu example snippet: create a menu with radio items - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.events.*; - -public class Snippet89 { -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - Menu menu = new Menu (shell, SWT.POP_UP); - for (int i=0; i<4; i++) { - MenuItem item = new MenuItem (menu, SWT.RADIO); - item.setText ("Item " + i); - item.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - MenuItem item = (MenuItem)e.widget; - if (item.getSelection ()) { - System.out.println (item + " selected"); - } else { - System.out.println (item + " unselected"); - } - } - }); - } - shell.setMenu (menu); - shell.setSize (300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet9.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet9.java deleted file mode 100644 index cb0f2f43de..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet9.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Composite example snippet: scroll a child control automatically - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet9 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL); - final Composite composite = new Composite (shell, SWT.BORDER); - composite.setSize (200, 400); - final ScrollBar hBar = shell.getHorizontalBar (); - hBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - Point location = composite.getLocation (); - location.x = -hBar.getSelection (); - composite.setLocation (location); - } - }); - final ScrollBar vBar = shell.getVerticalBar (); - vBar.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - Point location = composite.getLocation (); - location.y = -vBar.getSelection (); - composite.setLocation (location); - } - }); - shell.addListener (SWT.Resize, new Listener () { - public void handleEvent (Event e) { - Point size = composite.getSize (); - Rectangle rect = shell.getClientArea (); - hBar.setMaximum (size.x); - vBar.setMaximum (size.y); - hBar.setThumb (Math.min (size.x, rect.width)); - vBar.setThumb (Math.min (size.y, rect.height)); - int hPage = size.x - rect.width; - int vPage = size.y - rect.height; - int hSelection = hBar.getSelection (); - int vSelection = vBar.getSelection (); - Point location = composite.getLocation (); - if (hSelection >= hPage) { - if (hPage <= 0) hSelection = 0; - location.x = -hSelection; - } - if (vSelection >= vPage) { - if (vPage <= 0) vSelection = 0; - location.y = -vSelection; - } - composite.setLocation (location); - } - }); - shell.open (); - while (!shell.isDisposed()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet90.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet90.java deleted file mode 100644 index 469da8cae0..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet90.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Tree example snippet: detect mouse down in a tree item - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet90 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - final Tree tree = new Tree (shell, SWT.BORDER | SWT.MULTI); - for (int i=0; i<12; i++) { - TreeItem treeItem = new TreeItem (tree, SWT.NONE); - treeItem.setText ("Item " + i); - } - tree.addListener (SWT.MouseDown, new Listener () { - public void handleEvent (Event event) { - Point point = new Point (event.x, event.y); - TreeItem item = tree.getItem (point); - if (item != null) { - System.out.println ("Mouse down: " + item); - } - } - }); - tree.setSize (200, 200); - shell.setSize (300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} - -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet91.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet91.java deleted file mode 100644 index fd524a4bb4..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet91.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Drag and Drop example snippet: drag leaf items in a tree - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet91 { - -public static void main (String [] args) { - - final Display display = Display.getDefault (); - final Shell shell = new Shell (display); - shell.setLayout(new FillLayout()); - final Tree tree = new Tree(shell, SWT.BORDER); - for (int i = 0; i < 3; i++) { - TreeItem item = new TreeItem(tree, SWT.NONE); - item.setText("item "+i); - for (int j = 0; j < 3; j++) { - TreeItem subItem = new TreeItem(item, SWT.NONE); - subItem.setText("item "+i+" "+j); - for (int k = 0; k < 3; k++) { - TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); - subsubItem.setText("item "+i+" "+j+" "+k); - } - } - } - - Transfer[] types = new Transfer[] {TextTransfer.getInstance()}; - int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; - - final DragSource source = new DragSource (tree, operations); - source.setTransfer(types); - final TreeItem[] dragSourceItem = new TreeItem[1]; - source.addDragListener (new DragSourceListener () { - public void dragStart(DragSourceEvent event) { - TreeItem[] selection = tree.getSelection(); - if (selection.length > 0 && selection[0].getItemCount() == 0) { - event.doit = true; - dragSourceItem[0] = selection[0]; - } else { - event.doit = false; - } - }; - public void dragSetData (DragSourceEvent event) { - event.data = dragSourceItem[0].getText(); - } - public void dragFinished(DragSourceEvent event) { - if (event.detail == DND.DROP_MOVE) - dragSourceItem[0].dispose(); - dragSourceItem[0] = null; - } - }); - - DropTarget target = new DropTarget(tree, operations); - target.setTransfer(types); - target.addDropListener (new DropTargetAdapter() { - public void dragOver(DropTargetEvent event) { - event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; - if (event.item != null) { - TreeItem item = (TreeItem)event.item; - Point pt = display.map(null, tree, event.x, event.y); - Rectangle bounds = item.getBounds(); - if (pt.y < bounds.y + bounds.height/3) { - event.feedback |= DND.FEEDBACK_INSERT_BEFORE; - } else if (pt.y > bounds.y + 2*bounds.height/3) { - event.feedback |= DND.FEEDBACK_INSERT_AFTER; - } else { - event.feedback |= DND.FEEDBACK_SELECT; - } - } - } - public void drop(DropTargetEvent event) { - if (event.data == null) { - event.detail = DND.DROP_NONE; - return; - } - String text = (String)event.data; - if (event.item == null) { - TreeItem item = new TreeItem(tree, SWT.NONE); - item.setText(text); - } else { - TreeItem item = (TreeItem)event.item; - Point pt = display.map(null, tree, event.x, event.y); - Rectangle bounds = item.getBounds(); - TreeItem parent = item.getParentItem(); - if (parent != null) { - TreeItem[] items = parent.getItems(); - int index = 0; - for (int i = 0; i < items.length; i++) { - if (items[i] == item) { - index = i; - break; - } - } - if (pt.y < bounds.y + bounds.height/3) { - TreeItem newItem = new TreeItem(parent, SWT.NONE, index); - newItem.setText(text); - } else if (pt.y > bounds.y + 2*bounds.height/3) { - TreeItem newItem = new TreeItem(parent, SWT.NONE, index+1); - newItem.setText(text); - } else { - TreeItem newItem = new TreeItem(item, SWT.NONE); - newItem.setText(text); - } - - } else { - TreeItem[] items = tree.getItems(); - int index = 0; - for (int i = 0; i < items.length; i++) { - if (items[i] == item) { - index = i; - break; - } - } - if (pt.y < bounds.y + bounds.height/3) { - TreeItem newItem = new TreeItem(tree, SWT.NONE, index); - newItem.setText(text); - } else if (pt.y > bounds.y + 2*bounds.height/3) { - TreeItem newItem = new TreeItem(tree, SWT.NONE, index+1); - newItem.setText(text); - } else { - TreeItem newItem = new TreeItem(item, SWT.NONE); - newItem.setText(text); - } - } - - - } - } - }); - - shell.setSize (400, 400); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet92.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet92.java deleted file mode 100644 index 4e12cc1ea1..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet92.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Cursor example snippet: create a cursor from a source and a mask - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet92 { - -public static void main (String [] args) { - Display display = new Display(); - Color white = display.getSystemColor (SWT.COLOR_WHITE); - Color black = display.getSystemColor (SWT.COLOR_BLACK); - - //Create a source ImageData of depth 1 (monochrome) - PaletteData palette = new PaletteData (new RGB [] {white.getRGB(), black.getRGB(),}); - ImageData sourceData = new ImageData (20, 20, 1, palette); - for (int i = 0; i < 10; i ++) { - for (int j = 0; j < 20; j++) { - sourceData.setPixel(i, j, 1); - } - } - - //Create a mask ImageData of depth 1 (monochrome) - palette = new PaletteData (new RGB [] {white.getRGB(), black.getRGB(),}); - ImageData maskData = new ImageData (20, 20, 1, palette); - for (int i = 0; i < 20; i ++) { - for (int j = 0; j < 10; j++) { - maskData.setPixel(i, j, 1); - } - } - //Create cursor - Cursor cursor = new Cursor(display, sourceData, maskData, 10, 10); - - Shell shell = new Shell(display); - final Image source = new Image (display,sourceData); - final Image mask = new Image (display, maskData); - //Draw source and mask just to show what they look like - shell.addPaintListener(new PaintListener() { - public void paintControl(PaintEvent e) { - GC gc = e.gc; - gc.drawString("source: ", 10, 10); - gc.drawImage(source, 0, 0, 20, 20, 50, 10, 20, 20); - gc.drawString("mask: ",10, 40); - gc.drawImage(mask, 0, 0, 20, 20, 50, 40, 20, 20); - } - }); - shell.setSize(150, 150); - shell.open(); - shell.setCursor(cursor); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - cursor.dispose(); - source.dispose(); - mask.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet93.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet93.java deleted file mode 100644 index 488ec50c9f..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet93.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * GC example snippet: measure a string - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.layout.*; - -public class Snippet93 { - -public static void main (String [] args) { - Display display = new Display (); - Shell shell = new Shell (display); - shell.setLayout (new RowLayout ()); - Label label = new Label (shell, SWT.NONE); - GC gc = new GC (label); - Point size = gc.textExtent ("Hello"); - gc.dispose (); - label.setText ("Hello -> " + size); - shell.pack (); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet94.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet94.java deleted file mode 100644 index bb4f8243ec..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet94.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Clipboard example snippet: copy and paste data with the clipboard - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet94 { - -public static void main( String[] args) { - Display display = Display.getDefault (); - final Clipboard cb = new Clipboard(display); - final Shell shell = new Shell (display); - shell.setLayout(new FormLayout()); - final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); - - Button copy = new Button(shell, SWT.PUSH); - copy.setText("Copy"); - copy.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - String textData = text.getSelectionText(); - TextTransfer textTransfer = TextTransfer.getInstance(); - cb.setContents(new Object[]{textData}, new Transfer[]{textTransfer}); - } - }); - - Button paste = new Button(shell, SWT.PUSH); - paste.setText("Paste"); - paste.addListener (SWT.Selection, new Listener () { - public void handleEvent (Event e) { - TextTransfer transfer = TextTransfer.getInstance(); - String data = (String)cb.getContents(transfer); - if (data != null) { - text.insert(data); - } - } - }); - - FormData data = new FormData(); - data.right = new FormAttachment(100, -5); - data.top = new FormAttachment(0, 5); - copy.setLayoutData(data); - - data = new FormData(); - data.right = new FormAttachment(100, -5); - data.top = new FormAttachment(copy, 5); - paste.setLayoutData(data); - - data = new FormData(); - data.left = new FormAttachment(0, 5); - data.top = new FormAttachment(0, 5); - data.right = new FormAttachment(copy, -5); - data.bottom = new FormAttachment(100, -5); - text.setLayoutData(data); - - shell.setSize(200, 200); - shell.open(); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - cb.dispose(); - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet95.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet95.java deleted file mode 100644 index 080f35dc90..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet95.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * GC example snippet: capture a widget image with a GC - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -public class Snippet95 { - -public static void main(String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setText("Widget"); - shell.setBounds(10, 10, 200, 200); - - final Table table = new Table(shell, SWT.MULTI); - table.setLinesVisible(true); - table.setBounds(10, 10, 100, 100); - for (int i = 0; i < 9; i++) { - new TableItem(table, SWT.NONE).setText("item" + i); - } - - Button button = new Button(shell, SWT.PUSH); - button.setText("Capture"); - button.setBounds(10, 140, 50, 20); - button.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - Point tableSize = table.getSize(); - GC gc = new GC(table); - final Image image = - new Image(display, tableSize.x, tableSize.y); - gc.copyArea(image, 0, 0); - gc.dispose(); - - Shell popup = new Shell(shell); - popup.setText("Image"); - popup.setBounds(50, 50, 200, 200); - popup.addListener(SWT.Close, new Listener() { - public void handleEvent(Event e) { - image.dispose(); - } - }); - - Canvas canvas = new Canvas(popup, SWT.NONE); - canvas.setBounds(10, 10, 150, 150); - canvas.addPaintListener(new PaintListener() { - public void paintControl(PaintEvent e) { - e.gc.drawImage(image, 0, 0); - } - }); - popup.open(); - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.java deleted file mode 100644 index ca533be16a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * TableCursor example snippet: navigate a table cells with arrow keys. - * Edit when user hits Return key. Exit edit mode by hitting Escape (cancels edit) - * or Return (applies edit to table). - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.custom.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet96 { - -public static void main(String[] args) { - Display display = new Display(); - Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - - // create a a table with 3 columns and fill with data - final Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - TableColumn column1 = new TableColumn(table, SWT.NONE); - TableColumn column2 = new TableColumn(table, SWT.NONE); - TableColumn column3 = new TableColumn(table, SWT.NONE); - for (int i = 0; i < 100; i++) { - TableItem item = new TableItem(table, SWT.NONE); - item.setText(new String[] {"cell " + i + " 0", "cell " + i + " 1", "cell " + i + " 2" }); - } - column1.pack(); - column2.pack(); - column3.pack(); - - // create a TableCursor to navigate around the table - final TableCursor cursor = new TableCursor(table, SWT.NONE); - // create an editor to edit the cell when the user hits "ENTER" - // while over a cell in the table - final ControlEditor editor = new ControlEditor(cursor); - editor.grabHorizontal = true; - editor.grabVertical = true; - - cursor.addSelectionListener(new SelectionAdapter() { - // when the TableEditor is over a cell, select the corresponding row in - // the table - public void widgetSelected(SelectionEvent e) { - table.setSelection(new TableItem[] { cursor.getRow()}); - } - // when the user hits "ENTER" in the TableCursor, pop up a text editor so that - // they can change the text of the cell - public void widgetDefaultSelected(SelectionEvent e) { - final Text text = new Text(cursor, SWT.NONE); - TableItem row = cursor.getRow(); - int column = cursor.getColumn(); - text.setText(row.getText(column)); - text.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - // close the text editor and copy the data over - // when the user hits "ENTER" - if (e.character == SWT.CR) { - TableItem row = cursor.getRow(); - int column = cursor.getColumn(); - row.setText(column, text.getText()); - text.dispose(); - } - // close the text editor when the user hits "ESC" - if (e.character == SWT.ESC) { - text.dispose(); - } - } - }); - editor.setEditor(text); - text.setFocus(); - } - }); - // Hide the TableCursor when the user hits the "CTRL" or "SHIFT" key. - // This alows the user to select multiple items in the table. - cursor.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.CTRL - || e.keyCode == SWT.SHIFT - || (e.stateMask & SWT.CONTROL) != 0 - || (e.stateMask & SWT.SHIFT) != 0) { - cursor.setVisible(false); - } - } - }); - // Show the TableCursor when the user releases the "SHIFT" or "CTRL" key. - // This signals the end of the multiple selection task. - table.addKeyListener(new KeyAdapter() { - public void keyReleased(KeyEvent e) { - if (e.keyCode == SWT.CONTROL && (e.stateMask & SWT.SHIFT) != 0) - return; - if (e.keyCode == SWT.SHIFT && (e.stateMask & SWT.CONTROL) != 0) - return; - if (e.keyCode != SWT.CONTROL - && (e.stateMask & SWT.CONTROL) != 0) - return; - if (e.keyCode != SWT.SHIFT && (e.stateMask & SWT.SHIFT) != 0) - return; - - TableItem[] selection = table.getSelection(); - TableItem row = (selection.length == 0) ? table.getItem(table.getTopIndex()) : selection[0]; - table.showItem(row); - cursor.setSelection(row, 0); - cursor.setVisible(true); - cursor.setFocus(); - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet97.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet97.java deleted file mode 100644 index 553f39f1cd..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet97.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Menu example snippet: fill a menu dynamically (when menu shown) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet97 { - -public static void main (String [] args) { - final Display display = new Display (); - Shell shell = new Shell (display); - final Tree tree = new Tree (shell, SWT.BORDER | SWT.MULTI); - final Menu menu = new Menu (shell, SWT.POP_UP); - tree.setMenu (menu); - for (int i=0; i<12; i++) { - TreeItem item = new TreeItem (tree, SWT.NONE); - item.setText ("Item " + i); - } - menu.addListener (SWT.Show, new Listener () { - public void handleEvent (Event event) { - MenuItem [] menuItems = menu.getItems (); - for (int i=0; i<menuItems.length; i++) { - menuItems [i].dispose (); - } - TreeItem [] treeItems = tree.getSelection (); - for (int i=0; i<treeItems.length; i++) { - MenuItem menuItem = new MenuItem (menu, SWT.PUSH); - menuItem.setText (treeItems [i].getText ()); - } - } - }); - tree.setSize (200, 200); - shell.setSize (300, 300); - shell.open (); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet98.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet98.java deleted file mode 100644 index 245354aed3..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet98.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Composite example snippet: create and dispose children of a composite - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; - -public class Snippet98 { - -static int pageNum = 0; -static Composite pageComposite; - -public static void main(String args[]) { - Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new GridLayout()); - Button button = new Button(shell, SWT.PUSH); - button.setText("Push"); - pageComposite = new Composite(shell, SWT.NONE); - pageComposite.setLayout(new GridLayout()); - pageComposite.setLayoutData(new GridData()); - - button.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - if ((pageComposite != null) && (!pageComposite.isDisposed())) { - pageComposite.dispose(); - } - pageComposite = new Composite(shell, SWT.NONE); - pageComposite.setLayout(new GridLayout()); - pageComposite.setLayoutData(new GridData()); - if (pageNum++ % 2 == 0) { - Table table = new Table(pageComposite, SWT.BORDER); - table.setLayoutData(new GridData()); - for (int i = 0; i < 5; i++) { - new TableItem(table, SWT.NONE).setText("table item " + i); - } - } else { - new Button(pageComposite, SWT.RADIO).setText("radio"); - } - shell.layout(true); - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - display.dispose(); -} -} diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet99.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet99.java deleted file mode 100644 index 055a833a9a..0000000000 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet99.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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; - -/* - * Shell example snippet: prevent a shell from closing (prompt the user) - * - * For a list of all SWT example snippets see - * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets - */ -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; - -public class Snippet99 { - -public static void main (String [] args) { - Display display = new Display (); - final Shell shell = new Shell (display); - shell.addListener (SWT.Close, new Listener () { - public void handleEvent (Event event) { - int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO; - MessageBox messageBox = new MessageBox (shell, style); - messageBox.setText ("Information"); - messageBox.setMessage ("Close the shell?"); - event.doit = messageBox.open () == SWT.YES; - } - }); - shell.pack (); - shell.open(); - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - display.dispose (); -} -} |