Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2016-02-11 23:50:47 +0000
committerAlexander Kurtakov2016-02-11 23:50:47 +0000
commit643731f5fac0d73886ec0a882195202f18994c6c (patch)
tree39eadf4943ba39cea94c610b0dc254635e64e4fc /examples
parent9482ddbdbe01c9ae8c0cdb66f1a9f789d7c5d867 (diff)
downloadeclipse.platform.swt-643731f5fac0d73886ec0a882195202f18994c6c.tar.gz
eclipse.platform.swt-643731f5fac0d73886ec0a882195202f18994c6c.tar.xz
eclipse.platform.swt-643731f5fac0d73886ec0a882195202f18994c6c.zip
Bug 485821 - Make examples/snippets use lambdas
Convert *Listener in snippets. (take 1) Change-Id: I3e8897a19ca2a6fb43a16af91cdbf915d2deb69f Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet10.java41
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet103.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet104.java9
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet106.java19
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet107.java33
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet110.java39
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet111.java117
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet112.java10
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet113.java15
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet114.java15
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet115.java29
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet116.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet117.java17
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet118.java29
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet119.java42
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet124.java92
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java43
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet127.java18
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java51
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet131.java36
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet134.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet135.java195
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet139.java44
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet14.java27
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet142.java15
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet143.java48
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java34
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet145.java25
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet147.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet150.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet152.java49
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet153.java30
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet156.java46
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java15
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java17
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet168.java39
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet169.java21
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet17.java31
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet173.java32
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet175.java21
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet180.java29
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet181.java30
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet183.java19
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19.java25
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java73
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet193.java30
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet197.java25
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet198.java23
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java56
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet200.java25
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java42
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet202.java29
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet203.java37
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet204.java75
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet205.java59
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet207.java128
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet21.java52
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet212.java101
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet214.java31
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet215.java62
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet216.java46
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet217.java59
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet218.java39
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet220.java44
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet221.java29
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet222.java43
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet224.java25
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java13
70 files changed, 1145 insertions, 1539 deletions
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
index 8a0755b6c3..d88a41aeca 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -10,12 +10,12 @@
*******************************************************************************/
package org.eclipse.swt.snippets;
-/*
+/*
* Draw using transformations, paths and alpha blending
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -35,25 +35,22 @@ public class Snippet10 {
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() {
- @Override
- 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.addListener(SWT.Paint, event -> {
+ GC gc1 = event.gc;
+ Transform tr = new Transform(display);
+ tr.translate(50, 120);
+ tr.rotate(-30);
+ gc1.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
+ gc1.setAlpha(100);
+ gc1.setTransform(tr);
+ Path path = new Path(display);
+ path.addString("SWT", 0, 0, font);
+ gc1.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
+ gc1.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
+ gc1.fillPath(path);
+ gc1.drawPath(path);
+ tr.dispose();
+ path.dispose();
});
shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
shell.open();
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
index f4bfc829ab..0c5b6febe2 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,7 +17,7 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet103 {
@@ -44,12 +44,9 @@ public static void main(String[] args) {
button.setText("Change");
button.pack();
button.setLocation(10, 180);
- button.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- for (int i = 0; i < 4; i++) {
- populateItem(items[i]);
- }
+ button.addListener(SWT.Selection, event -> {
+ for (int i = 0; i < 4; i++) {
+ populateItem(items[i]);
}
});
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
index bba164747b..3520e26769 100644
--- 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
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-
+
/*
* Shell example snippet: create a splash screen
*
@@ -60,12 +60,7 @@ public static void main(String[] args) {
for (int i1=0; i1<count[0]; i1++) {
shells [i1] = new Shell(display);
shells [i1].setSize (300, 300);
- shells [i1].addListener(SWT.Close, new Listener() {
- @Override
- public void handleEvent (Event e) {
- --count[0];
- }
- });
+ shells [i1].addListener(SWT.Close, e -> --count[0]);
bar.setSelection(i1+1);
try {Thread.sleep(1000);} catch (Throwable e) {}
}
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
index 4a7971783e..2764fbf4c3 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -43,17 +43,14 @@ public static void main (String [] args) {
Button button = new Button (shell, SWT.PUSH);
final int index = 1;
button.setText ("Insert Column " + index + "a");
- button.addListener (SWT.Selection, new Listener () {
- @Override
- 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 ();
+ button.addListener (SWT.Selection, 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 ();
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
index c2f5b452f8..d6405ead23 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,8 +17,8 @@ package org.eclipse.swt.snippets;
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet107 {
@@ -30,10 +30,10 @@ public static void main (String [] args) {
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);
@@ -47,27 +47,24 @@ public static void main (String [] args) {
sashData.top = new FormAttachment (0, 0);
sashData.bottom = new FormAttachment (100, 0);
sash.setLayoutData (sashData);
- sash.addListener (SWT.Selection, new Listener () {
- @Override
- 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 ();
- }
+ sash.addListener (SWT.Selection, 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 ()) {
@@ -75,4 +72,4 @@ public static void main (String [] args) {
}
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
index 7579fd56e7..0b25a04d2d 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,8 +17,8 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
public class Snippet110 {
@@ -47,27 +47,24 @@ public static void main (String [] args) {
Point size = table.computeSize (SWT.DEFAULT, 200);
table.setSize (size);
shell.pack ();
- table.addListener (SWT.MouseDown, new Listener () {
- @Override
- 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;
- }
+ table.addListener (SWT.MouseDown, event -> {
+ Rectangle clientArea1 = 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 (clientArea1)) {
+ visible = true;
}
- if (!visible) return;
- index++;
}
+ if (!visible) return;
+ index++;
}
});
shell.open ();
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
index 4c10df8464..1fc220088a 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,10 +17,10 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
+import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
-import org.eclipse.swt.custom.*;
+import org.eclipse.swt.widgets.*;
public class Snippet111 {
@@ -40,70 +40,61 @@ public static void main (String [] args) {
}
final TreeItem [] lastItem = new TreeItem [1];
final TreeEditor editor = new TreeEditor (tree);
- tree.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- final TreeItem item = (TreeItem) event.item;
- if (item != null && item == lastItem [0]) {
- boolean showBorder = true;
- final Composite composite = new Composite (tree, SWT.NONE);
- if (showBorder) composite.setBackground (black);
- final Text text = new Text (composite, SWT.NONE);
- final int inset = showBorder ? 1 : 0;
- composite.addListener (SWT.Resize, new Listener () {
- @Override
- 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 () {
- @Override
- public void handleEvent (final Event e) {
- switch (e.type) {
- case SWT.FocusOut:
+ tree.addListener (SWT.Selection, event -> {
+ final TreeItem item = (TreeItem) event.item;
+ if (item != null && item == lastItem [0]) {
+ boolean showBorder = true;
+ final Composite composite = new Composite (tree, SWT.NONE);
+ if (showBorder) composite.setBackground (black);
+ final Text text = new Text (composite, SWT.NONE);
+ final int inset = showBorder ? 1 : 0;
+ composite.addListener (SWT.Resize, e1 -> {
+ Rectangle rect1 = composite.getClientArea ();
+ text.setBounds (rect1.x + inset, rect1.y + inset, rect1.width - inset * 2, rect1.height - inset * 2);
+ });
+ Listener textListener = e2 -> {
+ switch (e2.type) {
+ case SWT.FocusOut:
+ item.setText (text.getText ());
+ composite.dispose ();
+ break;
+ case SWT.Verify:
+ String newText = text.getText ();
+ String leftText = newText.substring (0, e2.start);
+ String rightText = newText.substring (e2.end, newText.length ());
+ GC gc = new GC (text);
+ Point size = gc.textExtent (leftText + e2.text + rightText);
+ gc.dispose ();
+ size = text.computeSize (size.x, SWT.DEFAULT);
+ editor.horizontalAlignment = SWT.LEFT;
+ Rectangle itemRect = item.getBounds (), rect2 = tree.getClientArea ();
+ editor.minimumWidth = Math.max (size.x, itemRect.width) + inset * 2;
+ int left = itemRect.x, right = rect2.x + rect2.width;
+ editor.minimumWidth = Math.min (editor.minimumWidth, right - left);
+ editor.minimumHeight = size.y + inset * 2;
+ editor.layout ();
+ break;
+ case SWT.Traverse:
+ switch (e2.detail) {
+ case SWT.TRAVERSE_RETURN:
item.setText (text.getText ());
+ //FALL THROUGH
+ case SWT.TRAVERSE_ESCAPE:
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;
+ e2.doit = false;
}
- }
- };
- 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;
+ 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 ();
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
index 04aa5b50d3..56e2ff122f 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,7 +17,6 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/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.*;
@@ -39,12 +38,7 @@ public static void main (String [] args) {
group.setLayout (new FillLayout ());
group.setText ("a square");
Canvas canvas = new Canvas (group, SWT.NONE);
- canvas.addPaintListener (new PaintListener () {
- @Override
- public void paintControl (PaintEvent e) {
- e.gc.drawImage (image, 0, 0);
- }
- });
+ canvas.addPaintListener (e -> e.gc.drawImage (image, 0, 0));
shell.pack ();
shell.open ();
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
index 6d3f7dba3a..6bcd284bb0 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,7 +9,7 @@
* 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)
*
@@ -17,7 +17,7 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet113 {
@@ -32,12 +32,9 @@ public static void main (String [] args) {
}
Rectangle clientArea = shell.getClientArea ();
table.setBounds (clientArea.x, clientArea.y, 100, 100);
- table.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
- System.out.println (event.item + " " + string);
- }
+ table.addListener (SWT.Selection, event -> {
+ String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
+ System.out.println (event.item + " " + string);
});
shell.setSize (200, 200);
shell.open ();
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
index 425841c7dc..92c8a84966 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,7 +9,7 @@
* 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)
*
@@ -17,7 +17,7 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet114 {
@@ -32,12 +32,9 @@ public static void main (String [] args) {
}
Rectangle clientArea = shell.getClientArea ();
tree.setBounds (clientArea.x, clientArea.y, 100, 100);
- tree.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
- System.out.println (event.item + " " + string);
- }
+ tree.addListener (SWT.Selection, event -> {
+ String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
+ System.out.println (event.item + " " + string);
});
shell.setSize (200, 200);
shell.open ();
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
index 920bb4f9d8..8453590ddd 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,8 +17,8 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet115 {
@@ -31,23 +31,20 @@ public static void main (String [] args) {
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 () {
- @Override
- 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);
- }
+ Listener radioGroup = 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 button1 = (Button) child;
+ if ((button1.getStyle () & SWT.RADIO) != 0) button1.setSelection (false);
}
}
- Button button = (Button) event.widget;
- button.setSelection (true);
}
+ Button button2 = (Button) event.widget;
+ button2.setSelection (true);
};
for (int i=0; i<4; i++) {
Button button = new Button (c1, SWT.RADIO);
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
index b7af07d6ba..f410c540dd 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -35,13 +35,10 @@ public static void main(String[] args) {
System.out.println("Text default selected (overrides default button)");
}
});
- text.addTraverseListener(new TraverseListener() {
- @Override
- public void keyTraversed(TraverseEvent e) {
- if (e.detail == SWT.TRAVERSE_RETURN) {
- e.doit = false;
- e.detail = SWT.TRAVERSE_NONE;
- }
+ text.addTraverseListener(e -> {
+ if (e.detail == SWT.TRAVERSE_RETURN) {
+ e.doit = false;
+ e.detail = SWT.TRAVERSE_NONE;
}
});
Button button = new Button(shell, SWT.PUSH);
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
index 5648f59346..cfa07efbe2 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -35,22 +35,17 @@ public static void main(String[] args) {
editItem.setMenu (submenu);
MenuItem item = new MenuItem (submenu, SWT.PUSH);
- item.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event e) {
- t.selectAll();
- }
- });
+ item.addListener (SWT.Selection, e -> t.selectAll());
item.setText ("Select &All\tCtrl+A");
item.setAccelerator (SWT.MOD1 + 'A');
-
- // Note that as long as your application has not overridden
- // the global accelerators for copy, paste, and cut
+
+ // 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
+ // from the Selection callback for the accelerator when the
// text widget has focus.
shell.setSize(200, 200);
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
index bb7a95dfb5..c1b31c5c5b 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,13 +9,13 @@
* 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
@@ -33,19 +33,16 @@ public static void main (String [] args) {
button.setText("Change cursor");
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
button.setSize(size);
- button.addListener(SWT.Selection, new Listener() {
- @Override
- 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();
- }
+ button.addListener(SWT.Selection, 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()) {
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
index e104ee8da4..f651fa41ff 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,17 +9,16 @@
* 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
@@ -27,7 +26,7 @@ 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)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,
@@ -45,7 +44,7 @@ static byte[] srcData = {
};
static byte[] mskData = {
- (byte)0x03, (byte)0xc0,
+ (byte)0x03, (byte)0xc0,
(byte)0x1f, (byte)0xf8,
(byte)0x3f, (byte)0xfc,
(byte)0x7f, (byte)0xfe,
@@ -71,12 +70,12 @@ public static void main (String [] args) {
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 (black.getRGB(), white.getRGB(), yellow.getRGB(),
+ PaletteData palette = new PaletteData (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 (black.getRGB(), white.getRGB());
ImageData maskData = new ImageData (16, 16, 1, palette, 1, mskData);
@@ -95,24 +94,21 @@ public static void main (String [] args) {
Shell shell = new Shell(display);
final Image source = new Image (display,sourceData);
final Image mask = new Image (display, maskData);
- shell.addPaintListener(new PaintListener() {
- @Override
- 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.addPaintListener(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();
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
index cf5f6fa030..8ca5464b12 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-
+
/*
* TableEditor example snippet: edit a cell in a table (in place, fancy)
*
@@ -17,10 +17,10 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
+import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
-import org.eclipse.swt.custom.*;
+import org.eclipse.swt.widgets.*;
public class Snippet124 {
public static void main (String[] args) {
@@ -40,56 +40,50 @@ public static void main (String[] args) {
final TableEditor editor = new TableEditor (table);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
- table.addListener (SWT.MouseDown, new Listener () {
- @Override
- 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 () {
- @Override
- public void handleEvent (final Event e) {
- switch (e.type) {
- case SWT.FocusOut:
+ table.addListener (SWT.MouseDown, 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 = 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 ();
- 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;
+ e.doit = false;
}
- }
- };
- 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;
- }
+ 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++;
}
+ if (!visible) return;
+ index++;
}
});
shell.pack ();
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
index 244e037be5..6e415cbb4d 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -34,31 +34,28 @@ public static void main (String[] args) {
}
// Disable native tooltip
table.setToolTipText ("");
-
+
// Implement a "fake" tooltip
- final Listener labelListener = new Listener () {
- @Override
- 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);
- shell.dispose ();
- table.setFocus();
- break;
- case SWT.MouseExit:
- shell.dispose ();
- break;
- }
+ final Listener labelListener = event -> {
+ Label label = (Label)event.widget;
+ Shell shell1 = 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);
+ shell1.dispose ();
+ table.setFocus();
+ break;
+ case SWT.MouseExit:
+ shell1.dispose ();
+ break;
}
};
-
+
Listener tableListener = new Listener () {
Shell tip = null;
Label label = null;
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
index 97d10f6558..5e0d11a990 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,9 +17,8 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet127 {
public static void main (String [] args) {
@@ -28,14 +27,11 @@ public static void main (String [] args) {
shell.setLayout(new RowLayout ());
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("Can't Traverse");
- button1.addTraverseListener(new TraverseListener () {
- @Override
- public void keyTraversed(TraverseEvent e) {
- switch (e.detail) {
- case SWT.TRAVERSE_TAB_NEXT:
- case SWT.TRAVERSE_TAB_PREVIOUS: {
- e.doit = false;
- }
+ button1.addTraverseListener(e -> {
+ switch (e.detail) {
+ case SWT.TRAVERSE_TAB_NEXT:
+ case SWT.TRAVERSE_TAB_PREVIOUS: {
+ e.doit = false;
}
}
});
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
index 7760596fc9..16a4b267fd 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,13 +15,13 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
+import org.eclipse.swt.browser.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.browser.*;
public class Snippet128 {
public static void main(String [] args) {
@@ -41,14 +41,14 @@ public class Snippet128 {
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;
@@ -83,22 +83,19 @@ public class Snippet128 {
progressBar.setLayoutData(data);
/* event handling */
- Listener listener = new Listener() {
- @Override
- 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());
- }
- };
+ Listener listener = 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() {
@Override
public void changed(ProgressEvent event) {
- if (event.total == 0) return;
+ if (event.total == 0) return;
int ratio = event.current * 100 / event.total;
progressBar.setSelection(ratio);
}
@@ -107,12 +104,7 @@ public class Snippet128 {
progressBar.setSelection(0);
}
});
- browser.addStatusTextListener(new StatusTextListener() {
- @Override
- public void changed(StatusTextEvent event) {
- status.setText(event.text);
- }
- });
+ browser.addStatusTextListener(event -> status.setText(event.text));
browser.addLocationListener(new LocationListener() {
@Override
public void changed(LocationEvent event) {
@@ -127,16 +119,11 @@ public class Snippet128 {
itemStop.addListener(SWT.Selection, listener);
itemRefresh.addListener(SWT.Selection, listener);
itemGo.addListener(SWT.Selection, listener);
- location.addListener(SWT.DefaultSelection, new Listener() {
- @Override
- public void handleEvent(Event e) {
- browser.setUrl(location.getText());
- }
- });
-
+ location.addListener(SWT.DefaultSelection, e -> browser.setUrl(location.getText()));
+
shell.open();
browser.setUrl("http://eclipse.org");
-
+
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
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
index eb90104c51..a7cd59053b 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,13 +9,13 @@
* 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
@@ -25,26 +25,18 @@ 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 () {
- @Override
- 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 () {
- @Override
- 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 ();
- }
- while (display.readAndDispatch()); // needed, to get the selection event, which is fired AFTER the menu is hidden
- menu.dispose ();
+ shell.addListener (SWT.MenuDetect, event -> {
+ Menu menu = new Menu (shell, SWT.POP_UP);
+ MenuItem item = new MenuItem (menu, SWT.PUSH);
+ item.setText ("Menu Item");
+ item.addListener (SWT.Selection, 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 ();
}
+ while (display.readAndDispatch()); // needed, to get the selection event, which is fired AFTER the menu is hidden
+ menu.dispose ();
});
shell.pack ();
shell.open ();
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
index fc3ad03f76..9761ed3e7e 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,13 +9,13 @@
* 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
@@ -85,12 +85,7 @@ public static void main(String[] args) {
b.setText("close");
b.pack();
b.setLocation(10, 68);
- b.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event e) {
- shell.close();
- }
- });
+ b.addListener(SWT.Selection, e -> shell.close());
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
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
index f75f25e890..77504d9dd0 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,33 +9,41 @@
* 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
-import java.awt.EventQueue;
+import java.awt.*;
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.awt.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.*;
-import org.eclipse.swt.awt.SWT_AWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
public class Snippet135 {
- static class FileTableModel extends AbstractTableModel {
- File[] files;
+ static class FileTableModel extends AbstractTableModel {
+ File[] files;
String[] columnsName = {"Name", "Size", "Date Modified"};
-
+
public FileTableModel (File[] files) {
this.files = files;
}
@@ -71,49 +79,38 @@ public class Snippet135 {
final Shell shell = new Shell(display);
shell.setText("SWT and Swing/AWT Example");
- Listener exitListener = new Listener() {
- @Override
- 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() {
- @Override
- 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() {
- @Override
- 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();
- }
+ Listener exitListener = 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 = 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, 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);
@@ -172,15 +169,12 @@ public class Snippet135 {
statusFrame.add(statusLabel);
statusLabel.setText("Select a file");
- sash.addListener(SWT.Selection, new Listener() {
- @Override
- 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();
- }
+ sash.addListener(SWT.Selection, 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();
@@ -191,54 +185,45 @@ public class Snippet135 {
treeItem.setData(file);
new TreeItem(treeItem, SWT.NONE);
}
- fileTree.addListener(SWT.Expand, new Listener() {
- @Override
- 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.Expand, 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() {
- @Override
- public void handleEvent(Event e) {
- TreeItem item = (TreeItem)e.item;
- if (item == null) return;
- final File root = (File)item.getData();
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- statusLabel.setText(root.getAbsolutePath());
- locationText.setText(root.getAbsolutePath());
- fileTable.setModel(new FileTableModel(root.listFiles()));
- }
- });
- }
+ fileTree.addListener(SWT.Selection, e -> {
+ TreeItem item = (TreeItem)e.item;
+ if (item == null) return;
+ final File root = (File)item.getData();
+ EventQueue.invokeLater(() -> {
+ 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;
+ GridData data;
data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 4;
separator1.setLayoutData(data);
@@ -266,16 +251,16 @@ public class Snippet135 {
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);
+ comp.setLayout(layout);
data = new GridData(GridData.FILL_VERTICAL);
data.widthHint = 200;
- fileTree.setLayoutData(data);
+ fileTree.setLayoutData(data);
data = new GridData(GridData.FILL_VERTICAL);
- sash.setLayoutData(data);
+ sash.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
tableComp.setLayoutData(data);
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
index fed075d89d..9beaa89e40 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,9 +9,9 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-
+
/*
- * This snippet was adapted from org.eclipse.draw2d.ImageUtilities in
+ * 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.
*
@@ -21,11 +21,10 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
-public class Snippet139 {
+public class Snippet139 {
static ImageData rotate(ImageData srcData, int direction) {
int bytesPerPixel = srcData.bytesPerLine / srcData.width;
@@ -40,19 +39,19 @@ static ImageData rotate(ImageData srcData, int direction) {
destX = srcY;
destY = srcData.width - srcX - 1;
width = srcData.height;
- height = srcData.width;
+ height = srcData.width;
break;
case SWT.RIGHT: // right 90 degrees
destX = srcData.height - srcY - 1;
destY = srcX;
width = srcData.height;
- height = srcData.width;
+ 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;
+ height = srcData.height;
break;
}
destIndex = (destY * destBytesPerLine) + (destX * bytesPerPixel);
@@ -75,7 +74,7 @@ static ImageData flip(ImageData srcData, boolean vertical) {
destY = srcData.height - srcY - 1;
} else {
destX = srcData.width - srcX - 1;
- destY = srcY;
+ destY = srcY;
}
destIndex = (destY * destBytesPerLine) + (destX * bytesPerPixel);
srcIndex = (srcY * srcData.bytesPerLine) + (srcX * bytesPerPixel);
@@ -88,7 +87,7 @@ static ImageData flip(ImageData srcData, boolean vertical) {
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);
@@ -96,7 +95,7 @@ public static void main(String[] args) {
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));
@@ -107,19 +106,16 @@ public static void main(String[] args) {
Shell shell = new Shell(display);
// draw the results on the shell
- shell.addPaintListener(new PaintListener(){
- @Override
- 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.addPaintListener(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();
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
index 56aba4c414..21bc35e0cd 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-
+
/*
* Control example snippet: detect mouse enter, exit and hover events
*
@@ -25,28 +25,13 @@ 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 () {
- @Override
- public void handleEvent (Event e) {
- System.out.println ("ENTER");
- }
- });
- shell.addListener (SWT.MouseExit, new Listener () {
- @Override
- public void handleEvent (Event e) {
- System.out.println ("EXIT");
- }
- });
- shell.addListener (SWT.MouseHover, new Listener () {
- @Override
- public void handleEvent (Event e) {
- System.out.println ("HOVER");
- }
- });
+ shell.addListener (SWT.MouseEnter, e -> System.out.println ("ENTER"));
+ shell.addListener (SWT.MouseExit, e -> System.out.println ("EXIT"));
+ shell.addListener (SWT.MouseHover, 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/Snippet142.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet142.java
index 0205737323..8fa3e1565e 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,13 +9,13 @@
* 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
@@ -32,12 +32,7 @@ public static void main(String[] args) {
button.setText("Click");
shell.pack();
shell.open();
- button.addListener(SWT.MouseDown, new Listener() {
- @Override
- public void handleEvent(Event e){
- System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")");
- }
- });
+ button.addListener(SWT.MouseDown, 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;
@@ -62,7 +57,7 @@ public static void main(String[] args) {
} catch (InterruptedException e) {}
event.type = SWT.MouseUp;
display.post(event);
- }
+ }
}.start();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
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
index a7e1a3a04c..abf1f9c442 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,13 +9,13 @@
* 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
@@ -39,48 +39,18 @@ public static void main(String[] args) {
} else {
final TrayItem item = new TrayItem (tray, SWT.NONE);
item.setToolTipText("SWT TrayItem");
- item.addListener (SWT.Show, new Listener () {
- @Override
- public void handleEvent (Event event) {
- System.out.println("show");
- }
- });
- item.addListener (SWT.Hide, new Listener () {
- @Override
- public void handleEvent (Event event) {
- System.out.println("hide");
- }
- });
- item.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- System.out.println("selection");
- }
- });
- item.addListener (SWT.DefaultSelection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- System.out.println("default selection");
- }
- });
+ item.addListener (SWT.Show, event -> System.out.println("show"));
+ item.addListener (SWT.Hide, event -> System.out.println("hide"));
+ item.addListener (SWT.Selection, event -> System.out.println("selection"));
+ item.addListener (SWT.DefaultSelection, 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);
- mi.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- System.out.println("selection " + event.widget);
- }
- });
+ mi.addListener (SWT.Selection, event -> System.out.println("selection " + event.widget));
if (i == 0) menu.setDefaultItem(mi);
}
- item.addListener (SWT.MenuDetect, new Listener () {
- @Override
- public void handleEvent (Event event) {
- menu.setVisible (true);
- }
- });
+ item.addListener (SWT.MenuDetect, event -> menu.setVisible (true));
item.setImage (image2);
item.setHighlightImage (image);
}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java
index 12c22b6025..367468c024 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet144.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,12 +15,12 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet144 {
@@ -31,28 +31,22 @@ public static void main(String[] args) {
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 () {
- @Override
- 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.addListener (SWT.SetData, 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 () {
- @Override
- 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 ();
- }
+ button.addListener (SWT.Selection, 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 ();
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
index ecc85c3562..95a7a81751 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,46 +15,41 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
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() {
- @Override
- public void handleEvent (Event event) {
- layout.draw(event.gc, 10, 10);
- }
- });
- shell.open();
+ shell.addListener(SWT.Paint, event -> layout.draw(event.gc, 10, 10));
+ shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
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
index ed0d086977..fbeca0ed88 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -35,13 +35,10 @@ public static void main(String[] args) {
System.out.println("Combo default selected (overrides default button)");
}
});
- combo.addTraverseListener(new TraverseListener() {
- @Override
- public void keyTraversed(TraverseEvent e) {
- if (e.detail == SWT.TRAVERSE_RETURN) {
- e.doit = false;
- e.detail = SWT.TRAVERSE_NONE;
- }
+ combo.addTraverseListener(e -> {
+ if (e.detail == SWT.TRAVERSE_RETURN) {
+ e.doit = false;
+ e.detail = SWT.TRAVERSE_NONE;
}
});
Button button = new Button(shell, SWT.PUSH);
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
index dbe5989299..ad602360e3 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,13 +15,13 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet150 {
@@ -58,12 +58,7 @@ public static void main(String[] args) {
coolData.right = new FormAttachment(100);
coolData.top = new FormAttachment(0);
coolBar.setLayoutData(coolData);
- coolBar.addListener(SWT.Resize, new Listener() {
- @Override
- public void handleEvent(Event event) {
- shell.layout();
- }
- });
+ coolBar.addListener(SWT.Resize, event -> shell.layout());
FormData textData = new FormData();
textData.left = new FormAttachment(0);
textData.right = new FormAttachment(100);
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
index 1fa803be60..f805c0b70d 100644
--- 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
@@ -15,7 +15,7 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import java.util.*;
@@ -33,13 +33,10 @@ public static void main (String [] args) {
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() {
- @Override
- public void handleEvent(Event e) {
- TableItem item = (TableItem)e.item;
- int index = table.indexOf(item);
- item.setText("Item "+data[index]);
- }
+ table.addListener(SWT.SetData, e -> {
+ TableItem item = (TableItem)e.item;
+ int index = table.indexOf(item);
+ item.setText("Item "+data[index]);
});
Thread thread = new Thread() {
@Override
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
index 561fefd5e5..6c305f0b8a 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,13 +15,13 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet152 {
@@ -31,32 +31,23 @@ public static void main(String[] args) {
FormLayout layout = new FormLayout();
shell.setLayout(layout);
final Label label = new Label(shell, SWT.BORDER);
- Listener armListener = new Listener() {
- @Override
- public void handleEvent(Event event) {
- MenuItem item = (MenuItem) event.widget;
- label.setText(item.getText());
- label.update();
- }
- };
- Listener showListener = new Listener() {
- @Override
- 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() {
- @Override
- public void handleEvent(Event event) {
- label.setText("");
- label.update();
- }
- };
+ Listener armListener = event -> {
+ MenuItem item = (MenuItem) event.widget;
+ label.setText(item.getText());
+ label.update();
+ };
+ Listener showListener = event -> {
+ Menu menu = (Menu) event.widget;
+ MenuItem item = menu.getParentItem();
+ if (item != null) {
+ label.setText(item.getText());
+ label.update();
+ }
+ };
+ Listener hideListener = event -> {
+ label.setText("");
+ label.update();
+ };
FormData labelData = new FormData();
labelData.left = new FormAttachment(0);
labelData.right = new FormAttachment(100);
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
index c96ea59238..5190cc2bb1 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,12 +17,11 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/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();
@@ -35,20 +34,17 @@ public static void main(String[] args) {
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() {
- @Override
- 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;
- }
- }
- });
+ bar.addMouseMoveListener(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();
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
index a3de07c2ff..7e77b365b8 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -16,21 +16,18 @@ package org.eclipse.swt.snippets;
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/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 java.awt.*;
+import java.awt.image.*;
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.*;
public class Snippet156 {
-
+
static BufferedImage convertToAWT(ImageData data) {
ColorModel colorModel = null;
PaletteData palette = data.palette;
@@ -60,7 +57,7 @@ static BufferedImage convertToAWT(ImageData data) {
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];
@@ -83,14 +80,14 @@ static ImageData convertToSWT(BufferedImage bufferedImage) {
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
int rgb = bufferedImage.getRGB(x, y);
- int pixel = palette.getPixel(new RGB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF));
+ int pixel = palette.getPixel(new RGB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF));
data.setPixel(x, y, pixel);
if (colorModel.hasAlpha()) {
data.setAlpha(x, y, (rgb >> 24) & 0xFF);
}
}
}
- return data;
+ return data;
} else if (bufferedImage.getColorModel() instanceof IndexColorModel) {
IndexColorModel colorModel = (IndexColorModel)bufferedImage.getColorModel();
int size = colorModel.getMapSize();
@@ -151,17 +148,14 @@ public static void main(String[] args) {
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() {
- @Override
- 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);
- }
+ shell.addListener(SWT.Paint, 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() {
@@ -182,7 +176,7 @@ public static void main(String[] args) {
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);
+ frame.setVisible(true);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
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
index 88ed8ec37d..94e478e862 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,7 +15,7 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -37,12 +37,9 @@ public class Snippet159 {
display.dispose();
return;
}
- browser.addTitleListener(new TitleListener() {
- @Override
- public void changed(TitleEvent event) {
- System.out.println("TitleEvent: "+event.title);
- shell.setText(event.title);
- }
+ browser.addTitleListener(event -> {
+ System.out.println("TitleEvent: "+event.title);
+ shell.setText(event.title);
});
browser.addProgressListener(new ProgressListener() {
@Override
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
index c011cc95b8..3488a68b7d 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -18,7 +18,7 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -39,21 +39,16 @@ public class Snippet160 {
System.out.println("Could not instantiate Browser: " + e.getMessage());
return;
}
- browser.addStatusTextListener(new StatusTextListener() {
- @Override
- public void changed(StatusTextEvent event) {
- browser.setData("query", event.text);
- }
- });
+ browser.addStatusTextListener(event -> browser.setData("query", event.text));
browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
}
@Override
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.
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
index 2d634ca831..e865f505ac 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,7 +15,7 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -48,14 +48,11 @@ public class Snippet161 {
"document.bgColor='yellow';");
final Button button = new Button(comp, SWT.PUSH);
button.setText("Execute Script");
- button.addListener(SWT.Selection, new Listener() {
- @Override
- 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.");
- }
+ button.addListener(SWT.Selection, 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);
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
index 9b3c5a102f..2b9ae325a4 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,7 +15,7 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
@@ -28,25 +28,22 @@ 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() {
- @Override
- 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.addListener(SWT.Paint, 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 i1 = 0; i1 < caps.length; i1++) {
+ gc.setLineCap(caps[i1]);
+ gc.drawLine(x, y, x + w, y);
+ y += 20;
+ }
+ int[] joins = {SWT.JOIN_BEVEL, SWT.JOIN_MITER, SWT.JOIN_ROUND};
+ for (int i2 = 0; i2 < joins.length; i2++) {
+ gc.setLineJoin(joins[i2]);
+ gc.drawPolygon(new int[] {x, y, x + w/2, y + h, x + w, y});
+ y += h + 20;
}
});
shell.open();
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
index 61102d7fff..b8ef46e0df 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -18,26 +18,23 @@ package org.eclipse.swt.snippets;
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
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 () {
- @Override
- 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);
- }
+ Listener listener = 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);
}
+ ((Button) e.widget).setSelection (true);
};
for (int i=0; i<20; i++) {
Button button = new Button (shell, SWT.TOGGLE);
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
index 0d09bb4da6..867f938059 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,7 +17,7 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet17 {
@@ -28,21 +28,18 @@ public static void main (String [] args) {
Slider slider = new Slider (shell, SWT.HORIZONTAL);
Rectangle clientArea = shell.getClientArea ();
slider.setBounds (clientArea.x + 10, clientArea.y + 10, 200, 32);
- slider.addListener (SWT.Selection, new Listener () {
- @Override
- 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);
+ slider.addListener (SWT.Selection, 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()) {
@@ -50,4 +47,4 @@ public static void main (String [] args) {
}
display.dispose ();
}
-}
+}
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
index 69c54cf843..778f083718 100644
--- 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
@@ -12,10 +12,10 @@ package org.eclipse.swt.snippets;
/*
* Browser snippet: bring up a browser with pop-up blocker
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -54,16 +54,13 @@ public static void main(String[] args) {
/* register WindowEvent listeners */
static void initialize(final Display display, Browser browser) {
- browser.addOpenWindowListener(new OpenWindowListener() {
- @Override
- public void open(WindowEvent event) {
- Shell shell = new Shell(display);
- shell.setText("New Window");
- shell.setLayout(new FillLayout());
- Browser browser = new Browser(shell, BROWSER_STYLE);
- initialize(display, browser);
- event.browser = browser;
- }
+ browser.addOpenWindowListener(event -> {
+ Shell shell = new Shell(display);
+ shell.setText("New Window");
+ shell.setLayout(new FillLayout());
+ Browser browser1 = new Browser(shell, BROWSER_STYLE);
+ initialize(display, browser1);
+ event.browser = browser1;
});
browser.addVisibilityWindowListener(new VisibilityWindowListener() {
@Override
@@ -91,13 +88,10 @@ static void initialize(final Display display, Browser browser) {
shell.open();
}
});
- browser.addCloseWindowListener(new CloseWindowListener() {
- @Override
- public void close(WindowEvent event) {
- Browser browser = (Browser)event.widget;
- Shell shell = browser.getShell();
- shell.close();
- }
+ browser.addCloseWindowListener(event -> {
+ Browser browser1 = (Browser)event.widget;
+ Shell shell = browser1.getShell();
+ shell.close();
});
}
} \ No newline at end of file
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
index 6326c2cace..9d6b1d7374 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -16,10 +16,10 @@ import org.eclipse.swt.widgets.*;
/*
* Exclude a widget from a GridLayout
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
@@ -52,15 +52,12 @@ public static void main(String[] args) {
b = new Button(shell, SWT.CHECK);
b.setText("hide");
b.setSelection(true);
- b.addListener(SWT.Selection, new Listener() {
- @Override
- 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);
- }
+ b.addListener(SWT.Selection, e -> {
+ Button b1 = (Button) e.widget;
+ GridData data1 = (GridData) bHidden.getLayoutData();
+ data1.exclude = b1.getSelection();
+ bHidden.setVisible(!data1.exclude);
+ shell.layout(false);
});
shell.setSize(400, 400);
shell.open();
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
index 4f7b6a638a..830f20cfc8 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -13,14 +13,13 @@ package org.eclipse.swt.snippets;
/*
* Create a non-rectangular shell to simulate transparency
* (ESC to close shell)
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
@@ -32,7 +31,7 @@ public static void main(String[] args) {
//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
+ //define a region
Region region = new Region();
Rectangle pixel = new Rectangle(0, 0, 1, 1);
for (int y = 0; y < 200; y+=2) {
@@ -44,20 +43,14 @@ public static void main(String[] args) {
}
//define the shape of the shell using setRegion
shell.setRegion(region);
- shell.addPaintListener(new PaintListener() {
- @Override
- 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.addPaintListener(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.addListener(SWT.KeyDown, new Listener() {
- @Override
- public void handleEvent(Event e) {
- if (e.character == SWT.ESC) {
- shell.dispose();
- }
+ shell.addListener(SWT.KeyDown, e -> {
+ if (e.character == SWT.ESC) {
+ shell.dispose();
}
});
shell.open();
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
index cd82d1dc21..14c89490ba 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,10 +12,10 @@ package org.eclipse.swt.snippets;
/*
* Allow user to reorder columns by dragging or programmatically.
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -46,12 +46,7 @@ public class Snippet181 {
String[] text = new String[]{i+" 0", i+" 1", i+" 2", i+" 3", i+" 4"};
item.setText(text);
}
- Listener listener = new Listener() {
- @Override
- public void handleEvent(Event e) {
- System.out.println("Move "+e.widget);
- }
- };
+ Listener listener = e -> System.out.println("Move "+e.widget);
TableColumn[] columns = table.getColumns();
for (int i = 0; i < columns.length; i++) {
columns[i].pack();
@@ -60,17 +55,14 @@ public class Snippet181 {
}
Button b = new Button(shell, SWT.PUSH);
b.setText("invert column order");
- b.addListener(SWT.Selection, new Listener() {
- @Override
- 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);
+ b.addListener(SWT.Selection, 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();
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
index 523845cf9e..f471578c72 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,18 +12,18 @@ 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://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet183 {
-
+
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
@@ -32,12 +32,7 @@ public class Snippet183 {
link.setText(text);
Rectangle clientArea = shell.getClientArea();
link.setBounds(clientArea.x, clientArea.y, 400, 400);
- link.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent(Event event) {
- System.out.println("Selection: " + event.text);
- }
- });
+ link.addListener (SWT.Selection, event -> System.out.println("Selection: " + event.text));
shell.pack ();
shell.open();
while (!shell.isDisposed()) {
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
index d1cb78ff19..77d7b3b8c1 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,7 +17,7 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet19 {
@@ -28,17 +28,14 @@ public static void main (String [] args) {
Text text = new Text (shell, SWT.BORDER | SWT.V_SCROLL);
Rectangle clientArea = shell.getClientArea ();
text.setBounds ( clientArea.x + 10, clientArea.y + 10, 200, 200);
- text.addListener (SWT.Verify, new Listener () {
- @Override
- 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;
- }
+ text.addListener (SWT.Verify, 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;
}
}
});
@@ -48,4 +45,4 @@ public static void main (String [] args) {
}
display.dispose ();
}
-}
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java
index 28da3e04a0..be4d05b015 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet192.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -18,10 +18,10 @@ import org.eclipse.swt.widgets.*;
/*
* Show a sort indicator in the column header
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
@@ -48,47 +48,38 @@ public static void main(String[] args) {
final TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Value");
column2.setWidth(200);
- table.addListener(SWT.SetData, new Listener() {
- @Override
- public void handleEvent(Event e) {
- TableItem item = (TableItem) e.item;
- int index = table.indexOf(item);
- int[] datum = data[index];
- item.setText(new String[] {Integer.toString(datum[0]),
- Integer.toString(datum[1]) });
- }
+ table.addListener(SWT.SetData, e -> {
+ TableItem item = (TableItem) e.item;
+ int index = table.indexOf(item);
+ int[] datum = data[index];
+ item.setText(new String[] {Integer.toString(datum[0]),
+ Integer.toString(datum[1]) });
});
// Add sort indicator and sort data when column selected
- Listener sortListener = new Listener() {
- @Override
- public void handleEvent(Event e) {
- // determine new sort column and direction
- TableColumn sortColumn = table.getSortColumn();
- TableColumn currentColumn = (TableColumn) e.widget;
- int dir = table.getSortDirection();
- if (sortColumn == currentColumn) {
- dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
- } else {
- table.setSortColumn(currentColumn);
- dir = SWT.UP;
- }
- // sort the data based on column and direction
- final int index = currentColumn == column1 ? 0 : 1;
- final int direction = dir;
- Arrays.sort(data, new Comparator<int[]>() {
- @Override
- public int compare(int[] a, int[] b) {
- if (a[index] == b[index]) return 0;
- if (direction == SWT.UP) {
- return a[index] < b[index] ? -1 : 1;
- }
- return a[index] < b[index] ? 1 : -1;
- }
- });
- // update data displayed in table
- table.setSortDirection(dir);
- table.clearAll();
+ Listener sortListener = e -> {
+ // determine new sort column and direction
+ TableColumn sortColumn = table.getSortColumn();
+ TableColumn currentColumn = (TableColumn) e.widget;
+ int dir = table.getSortDirection();
+ if (sortColumn == currentColumn) {
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
+ } else {
+ table.setSortColumn(currentColumn);
+ dir = SWT.UP;
}
+ // sort the data based on column and direction
+ final int index = currentColumn == column1 ? 0 : 1;
+ final int direction = dir;
+ Arrays.sort(data, (a, b) -> {
+ if (a[index] == b[index]) return 0;
+ if (direction == SWT.UP) {
+ return a[index] < b[index] ? -1 : 1;
+ }
+ return a[index] < b[index] ? 1 : -1;
+ });
+ // update data displayed in table
+ table.setSortDirection(dir);
+ table.clearAll();
};
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet193.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet193.java
index df54fa7fff..5c33e2a3bf 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet193.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet193.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,10 +12,10 @@ package org.eclipse.swt.snippets;
/*
* Tree example snippet: allow user to reorder columns by dragging and programmatically.
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
import org.eclipse.swt.*;
@@ -56,12 +56,7 @@ public class Snippet193 {
}
}
}
- Listener listener = new Listener() {
- @Override
- public void handleEvent(Event e) {
- System.out.println("Move "+e.widget);
- }
- };
+ Listener listener = e -> System.out.println("Move "+e.widget);
TreeColumn[] columns = tree.getColumns();
for (int i = 0; i < columns.length; i++) {
columns[i].setWidth(100);
@@ -70,17 +65,14 @@ public class Snippet193 {
}
Button b = new Button(shell, SWT.PUSH);
b.setText("invert column order");
- b.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event e) {
- int[] order = tree.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;
- }
- tree.setColumnOrder(order);
+ b.addListener(SWT.Selection, e -> {
+ int[] order = tree.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;
}
+ tree.setColumnOrder(order);
});
shell.pack();
shell.open();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet197.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet197.java
index bad6101ad8..6c5fb01609 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet197.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet197.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,10 +12,10 @@ package org.eclipse.swt.snippets;
/*
* Draw wrapped text using TextLayout
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
*/
import org.eclipse.swt.*;
@@ -29,17 +29,14 @@ public static void main(String[] args) {
final Shell shell = new Shell(display);
final TextLayout layout = new TextLayout(display);
layout.setText(longString);
- Listener listener = new Listener() {
- @Override
- public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.Paint:
- layout.draw(event.gc, 10, 10);
- break;
- case SWT.Resize:
- layout.setWidth(shell.getSize().x - 20);
- break;
- }
+ Listener listener = event -> {
+ switch (event.type) {
+ case SWT.Paint:
+ layout.draw(event.gc, 10, 10);
+ break;
+ case SWT.Resize:
+ layout.setWidth(shell.getSize().x - 20);
+ break;
}
};
shell.addListener(SWT.Paint, listener);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet198.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet198.java
index 24fe3ca969..62bf0f0d44 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet198.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet198.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,10 +12,10 @@ package org.eclipse.swt.snippets;
/*
* Create a path from some text
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -34,22 +34,19 @@ public static void main(String[] args) {
path = new Path(display);
path.addString("SWT", 0, 0, font);
} catch (SWTException e) {
- //Advanced Graphics not supported.
+ //Advanced Graphics not supported.
//This new API requires the Cairo Vector engine on GTK and GDI+ on Windows.
System.out.println(e.getMessage());
display.dispose();
return;
}
Shell shell = new Shell(display);
- shell.addListener(SWT.Paint, new Listener() {
- @Override
- public void handleEvent(Event e) {
- GC gc = e.gc;
- gc.setBackground(green);
- gc.setForeground(blue);
- gc.fillPath(path);
- gc.drawPath(path);
- }
+ shell.addListener(SWT.Paint, e -> {
+ GC gc = e.gc;
+ gc.setBackground(green);
+ gc.setForeground(blue);
+ gc.fillPath(path);
+ gc.drawPath(path);
});
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java
index b76a438034..60d98e7685 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -10,19 +10,20 @@
*******************************************************************************/
package org.eclipse.swt.snippets;
+import java.text.*;
+import java.util.*;
+
/*
* Table example snippet: sort a table by column
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
-import java.text.*;
-import java.util.*;
+import org.eclipse.swt.widgets.*;
public class Snippet2 {
@@ -44,30 +45,27 @@ public static void main (String [] args) {
item.setText(new String[] {"c", "1"});
column1.setWidth(100);
column2.setWidth(100);
- Listener sortListener = new Listener() {
- @Override
- public void handleEvent(Event e) {
- TableItem[] items = table.getItems();
- Collator collator = Collator.getInstance(Locale.getDefault());
- TableColumn column = (TableColumn)e.widget;
- int index = column == column1 ? 0 : 1;
- for (int i = 1; i < items.length; i++) {
- String value1 = items[i].getText(index);
- for (int j = 0; j < i; j++){
- String value2 = items[j].getText(index);
- 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;
- }
- }
- }
- table.setSortColumn(column);
- }
- };
+ Listener sortListener = e -> {
+ TableItem[] items = table.getItems();
+ Collator collator = Collator.getInstance(Locale.getDefault());
+ TableColumn column = (TableColumn)e.widget;
+ int index = column == column1 ? 0 : 1;
+ for (int i = 1; i < items.length; i++) {
+ String value1 = items[i].getText(index);
+ for (int j = 0; j < i; j++){
+ String value2 = items[j].getText(index);
+ if (collator.compare(value1, value2) < 0) {
+ String[] values = {items[i].getText(0), items[i].getText(1)};
+ items[i].dispose();
+ TableItem item1 = new TableItem(table, SWT.NONE, j);
+ item1.setText(values);
+ items = table.getItems();
+ break;
+ }
+ }
+ }
+ table.setSortColumn(column);
+ };
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
table.setSortColumn(column1);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet200.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet200.java
index 6cf99c93ab..a6667b4907 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet200.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet200.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,10 +12,10 @@ package org.eclipse.swt.snippets;
/*
* Fill a shape with a predefined pattern
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.1
*/
import org.eclipse.swt.*;
@@ -39,30 +39,27 @@ public static void main(String[] args) {
gc.setForeground(blue);
gc.drawLine(i, 0, 500 + i, 1000);
gc.drawLine(500 + i, 0, i, 1000);
- }
+ }
gc.dispose();
final Pattern pattern;
try {
pattern = new Pattern(display, image);
} catch (SWTException e) {
- //Advanced Graphics not supported.
+ //Advanced Graphics not supported.
//This new API requires the Cairo Vector engine on GTK and GDI+ on Windows.
System.out.println(e.getMessage());
display.dispose();
return;
}
-
+
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Composite c = new Composite(shell, SWT.DOUBLE_BUFFERED);
- c.addListener(SWT.Paint, new Listener() {
- @Override
- public void handleEvent(Event event) {
- Rectangle r = ((Composite)event.widget).getClientArea();
- GC gc = event.gc;
- gc.setBackgroundPattern(pattern);
- gc.fillOval(5, 5, r.width - 10, r.height - 10);
- }
+ c.addListener(SWT.Paint, event -> {
+ Rectangle r = ((Composite)event.widget).getClientArea();
+ GC gc1 = event.gc;
+ gc1.setBackgroundPattern(pattern);
+ gc1.fillOval(5, 5, r.width - 10, r.height - 10);
});
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java
index f7a1c82dcc..d86fa130ff 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet201.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,12 +15,12 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.0
- */
+ */
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet201 {
@@ -32,32 +32,26 @@ public static void main(String[] args) {
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 () {
- @Override
- public void handleEvent (Event event) {
- TableItem item = (TableItem) event.item;
- int index = table.indexOf (item);
- int start = index / PAGE_SIZE * PAGE_SIZE;
- int end = Math.min (start + PAGE_SIZE, table.getItemCount ());
- for (int i = start; i < end; i++) {
- item = table.getItem (i);
- item.setText ("Item " + i);
- }
+ table.addListener (SWT.SetData, event -> {
+ TableItem item = (TableItem) event.item;
+ int index = table.indexOf (item);
+ int start = index / PAGE_SIZE * PAGE_SIZE;
+ int end = Math.min (start + PAGE_SIZE, table.getItemCount ());
+ for (int i = start; i < end; i++) {
+ item = table.getItem (i);
+ item.setText ("Item " + i);
}
});
table.setLayoutData (new RowData (200, 200));
Button button = new Button (shell, SWT.PUSH);
button.setText ("Add Items");
final Label label = new Label(shell, SWT.NONE);
- button.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- long t1 = System.currentTimeMillis ();
- table.setItemCount (COUNT);
- long t2 = System.currentTimeMillis ();
- label.setText ("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms) [page=" + PAGE_SIZE + "]");
- shell.layout ();
- }
+ button.addListener (SWT.Selection, event -> {
+ long t1 = System.currentTimeMillis ();
+ table.setItemCount (COUNT);
+ long t2 = System.currentTimeMillis ();
+ label.setText ("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms) [page=" + PAGE_SIZE + "]");
+ shell.layout ();
});
shell.pack ();
shell.open ();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet202.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet202.java
index a1cfcba116..411973ceeb 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet202.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet202.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,9 +15,9 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
- */
+ */
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
@@ -29,20 +29,17 @@ public static void main(String[] args) {
final Shell shell = new Shell(display);
shell.setLayout (new FillLayout());
final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER);
- tree.addListener(SWT.SetData, new Listener() {
- @Override
- public void handleEvent(Event event) {
- TreeItem item = (TreeItem)event.item;
- TreeItem parentItem = item.getParentItem();
- String text = null;
- if (parentItem == null) {
- text = "node "+tree.indexOf(item);
- } else {
- text = parentItem.getText()+" - "+parentItem.indexOf(item);
- }
- item.setText(text);
- item.setItemCount(10);
+ tree.addListener(SWT.SetData, event -> {
+ TreeItem item = (TreeItem)event.item;
+ TreeItem parentItem = item.getParentItem();
+ String text = null;
+ if (parentItem == null) {
+ text = "node "+tree.indexOf(item);
+ } else {
+ text = parentItem.getText()+" - "+parentItem.indexOf(item);
}
+ item.setText(text);
+ item.setItemCount(10);
});
tree.setItemCount(20);
shell.setSize(400, 300);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet203.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet203.java
index 7ada009657..ac6fb5ea7d 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet203.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet203.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -11,22 +11,22 @@
package org.eclipse.swt.snippets;
/*
- * TextLayout example snippet: using TextLayout justify, alignment and indent
+ * TextLayout example snippet: using TextLayout justify, alignment and indent
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
- */
+ */
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
public class Snippet203 {
-
+
public static void main(String[] args) {
Display display = new Display();
- final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
+ final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
shell.setText("Indent, Justify, Align");
String[] texts = {
"Plans do not materialize out of nowhere, nor are they entirely static. To ensure the planning process is transparent and open to the entire Eclipse community, we (the Eclipse PMC) post plans in an embryonic form and revise them throughout the release cycle.",
@@ -40,20 +40,17 @@ public static void main(String[] args) {
layout.setText(texts[i]);
layout.setIndent(30);
layout.setJustify(true);
- layout.setAlignment(alignments[i]);
+ layout.setAlignment(alignments[i]);
layouts[i] = layout;
}
- shell.addListener(SWT.Paint, new Listener() {
- @Override
- public void handleEvent(Event event) {
- Point point = new Point(10, 10);
- int width = shell.getClientArea().width - 2 * point.x;
- for (int i = 0; i < layouts.length; i++) {
- TextLayout layout = layouts[i];
- layout.setWidth(width);
- layout.draw(event.gc, point.x, point.y);
- point.y += layout.getBounds().height + 10;
- }
+ shell.addListener(SWT.Paint, event -> {
+ Point point = new Point(10, 10);
+ int width = shell.getClientArea().width - 2 * point.x;
+ for (int i = 0; i < layouts.length; i++) {
+ TextLayout layout = layouts[i];
+ layout.setWidth(width);
+ layout.draw(event.gc, point.x, point.y);
+ point.y += layout.getBounds().height + 10;
}
});
shell.open();
@@ -61,7 +58,7 @@ public static void main(String[] args) {
if (!display.readAndDispatch()) display.sleep();
}
for (int i = 0; i < layouts.length; i++) {
- layouts[i].dispose();
+ layouts[i].dispose();
}
display.dispose();
}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet204.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet204.java
index d8e3befac6..ae40105419 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet204.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet204.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,15 +15,15 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
- */
+ */
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
public class Snippet204 {
-
+
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
@@ -39,7 +39,7 @@ public static void main(String[] args) {
FontMetrics metrics = gc.getFontMetrics();
final int baseline = metrics.getAscent() + metrics.getLeading();
gc.dispose();
-
+
final TextLayout layout0 = new TextLayout(display);
layout0.setText("SubscriptScriptSuperscript");
layout0.setFont(font);
@@ -48,7 +48,7 @@ public static void main(String[] args) {
superscript0.rise = baseline - smallBaseline;
layout0.setStyle(subscript0, 0, 8);
layout0.setStyle(superscript0, 15, 25);
-
+
final TextLayout layout1 = new TextLayout(display);
layout1.setText("SubscriptScriptSuperscript");
layout1.setFont(font);
@@ -58,38 +58,35 @@ public static void main(String[] args) {
superscript1.rise = baseline;
layout1.setStyle(subscript1, 0, 8);
layout1.setStyle(superscript1, 15, 25);
-
- shell.addListener(SWT.Paint, new Listener() {
- @Override
- public void handleEvent(Event event) {
- Display display = event.display;
- GC gc = event.gc;
-
- Rectangle rect0 = layout0.getBounds();
- rect0.x += 10;
- rect0.y += 10;
- gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
- gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
- gc.fillRectangle(rect0);
- layout0.draw(gc, rect0.x, rect0.y);
- gc.setForeground(display.getSystemColor(SWT.COLOR_MAGENTA));
- gc.drawLine(rect0.x, rect0.y, rect0.x + rect0.width, rect0.y);
- gc.drawLine(rect0.x, rect0.y + baseline, rect0.x + rect0.width, rect0.y + baseline);
- gc.drawLine(rect0.x + rect0.width / 2, rect0.y, rect0.x + rect0.width / 2, rect0.y + rect0.height);
-
- Rectangle rect1 = layout1.getBounds();
- rect1.x += 10;
- rect1.y += 20 + rect0.height;
- gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
- gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
- gc.fillRectangle(rect1);
- layout1.draw(gc, rect1.x, rect1.y);
-
- gc.setForeground(display.getSystemColor(SWT.COLOR_MAGENTA));
- gc.drawLine(rect1.x, rect1.y + smallBaseline, rect1.x + rect1.width, rect1.y + smallBaseline);
- gc.drawLine(rect1.x, rect1.y + baseline + smallBaseline, rect1.x + rect1.width, rect1.y + baseline + smallBaseline);
- gc.drawLine(rect1.x + rect1.width / 2, rect1.y, rect1.x + rect1.width / 2, rect1.y + rect1.height);
- }
+
+ shell.addListener(SWT.Paint, event -> {
+ Display display1 = event.display;
+ GC gc1 = event.gc;
+
+ Rectangle rect0 = layout0.getBounds();
+ rect0.x += 10;
+ rect0.y += 10;
+ gc1.setBackground(display1.getSystemColor(SWT.COLOR_WHITE));
+ gc1.setForeground(display1.getSystemColor(SWT.COLOR_BLACK));
+ gc1.fillRectangle(rect0);
+ layout0.draw(gc1, rect0.x, rect0.y);
+ gc1.setForeground(display1.getSystemColor(SWT.COLOR_MAGENTA));
+ gc1.drawLine(rect0.x, rect0.y, rect0.x + rect0.width, rect0.y);
+ gc1.drawLine(rect0.x, rect0.y + baseline, rect0.x + rect0.width, rect0.y + baseline);
+ gc1.drawLine(rect0.x + rect0.width / 2, rect0.y, rect0.x + rect0.width / 2, rect0.y + rect0.height);
+
+ Rectangle rect1 = layout1.getBounds();
+ rect1.x += 10;
+ rect1.y += 20 + rect0.height;
+ gc1.setBackground(display1.getSystemColor(SWT.COLOR_WHITE));
+ gc1.setForeground(display1.getSystemColor(SWT.COLOR_BLACK));
+ gc1.fillRectangle(rect1);
+ layout1.draw(gc1, rect1.x, rect1.y);
+
+ gc1.setForeground(display1.getSystemColor(SWT.COLOR_MAGENTA));
+ gc1.drawLine(rect1.x, rect1.y + smallBaseline, rect1.x + rect1.width, rect1.y + smallBaseline);
+ gc1.drawLine(rect1.x, rect1.y + baseline + smallBaseline, rect1.x + rect1.width, rect1.y + baseline + smallBaseline);
+ gc1.drawLine(rect1.x + rect1.width / 2, rect1.y, rect1.x + rect1.width / 2, rect1.y + rect1.height);
});
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet205.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet205.java
index 54bc6cc401..419b3698da 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet205.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet205.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -11,21 +11,21 @@
package org.eclipse.swt.snippets;
/*
- * TextLayout example snippet: using the GlyphMetrics to embedded images in
- * a TextLayout.
+ * TextLayout example snippet: using the GlyphMetrics to embedded images in
+ * a TextLayout.
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
- */
+ */
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
public class Snippet205 {
-
+
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
@@ -38,7 +38,7 @@ public static void main(String[] args) {
gc.fillRectangle(images[i].getBounds());
gc.dispose();
}
-
+
final Button button = new Button(shell, SWT.PUSH);
button.setText("Button");
button.pack();
@@ -49,36 +49,33 @@ public static void main(String[] args) {
for (int i = 0; i < images.length; i++) {
Rectangle bounds = images[i].getBounds();
TextStyle imageStyle = new TextStyle(null, null, null);
- imageStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
+ imageStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
layout.setStyle(imageStyle, imageOffsets[i], imageOffsets[i]);
}
Rectangle bounds = button.getBounds();
TextStyle buttonStyle = new TextStyle(null, null, null);
- buttonStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
+ buttonStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
final int buttonOffset = text.length() - 2;
layout.setStyle(buttonStyle, buttonOffset, buttonOffset);
-
- shell.addListener(SWT.Paint, new Listener() {
- @Override
- public void handleEvent(Event event) {
- GC gc = event.gc;
- Point margin = new Point(10, 10);
- layout.setWidth(shell.getClientArea().width - 2 * margin.x);
- layout.draw(event.gc, margin.x, margin.y);
- for (int i = 0; i < images.length; i++) {
- int offset = imageOffsets[i];
- int lineIndex = layout.getLineIndex(offset);
- FontMetrics lineMetrics = layout.getLineMetrics(lineIndex);
- Point point = layout.getLocation(offset, false);
- GlyphMetrics glyphMetrics = layout.getStyle(offset).metrics;
- gc.drawImage(images[i], point.x + margin.x, point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent);
- }
- int lineIndex = layout.getLineIndex(buttonOffset);
- FontMetrics lineMetrics = layout.getLineMetrics(lineIndex);
- Point point = layout.getLocation(buttonOffset, false);
- GlyphMetrics glyphMetrics = layout.getStyle(buttonOffset).metrics;
- button.setLocation(point.x + margin.x, point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent);
+
+ shell.addListener(SWT.Paint, event -> {
+ GC gc = event.gc;
+ Point margin = new Point(10, 10);
+ layout.setWidth(shell.getClientArea().width - 2 * margin.x);
+ layout.draw(event.gc, margin.x, margin.y);
+ for (int i = 0; i < images.length; i++) {
+ int offset = imageOffsets[i];
+ int lineIndex1 = layout.getLineIndex(offset);
+ FontMetrics lineMetrics1 = layout.getLineMetrics(lineIndex1);
+ Point point1 = layout.getLocation(offset, false);
+ GlyphMetrics glyphMetrics1 = layout.getStyle(offset).metrics;
+ gc.drawImage(images[i], point1.x + margin.x, point1.y + margin.y + lineMetrics1.getAscent() - glyphMetrics1.ascent);
}
+ int lineIndex2 = layout.getLineIndex(buttonOffset);
+ FontMetrics lineMetrics2 = layout.getLineMetrics(lineIndex2);
+ Point point2 = layout.getLocation(buttonOffset, false);
+ GlyphMetrics glyphMetrics2 = layout.getStyle(buttonOffset).metrics;
+ button.setLocation(point2.x + margin.x, point2.y + margin.y + lineMetrics2.getAscent() - glyphMetrics2.ascent);
});
shell.open();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet207.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet207.java
index 860ea89b00..770f7a8847 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet207.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet207.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -17,15 +17,14 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/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 Snippet207 {
+public class Snippet207 {
public static void main(String[] args) {
final Display display = new Display();
-
+
final Image image = new Image(display, 110, 60);
GC gc = new GC(image);
Font font = new Font(display, "Times", 30, SWT.BOLD);
@@ -36,74 +35,71 @@ public class Snippet207 {
gc.drawText("SWT", 10, 10, true);
font.dispose();
gc.dispose();
-
+
final Rectangle rect = image.getBounds();
Shell shell = new Shell(display);
shell.setText("Matrix Tranformations");
shell.setLayout(new FillLayout());
final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
- canvas.addPaintListener(new PaintListener () {
- @Override
- public void paintControl(PaintEvent e) {
- GC gc = e.gc;
- gc.setAdvanced(true);
- if (!gc.getAdvanced()){
- gc.drawText("Advanced graphics not supported", 30, 30, true);
- return;
- }
-
- // Original image
- int x = 30, y = 30;
- gc.drawImage(image, x, y);
- x += rect.width + 30;
-
- Transform transform = new Transform(display);
-
- // Note that the tranform is applied to the whole GC therefore
- // the coordinates need to be adjusted too.
-
- // Reflect around the y axis.
- transform.setElements(-1, 0, 0, 1, 0 ,0);
- gc.setTransform(transform);
- gc.drawImage(image, -1*x-rect.width, y);
-
- x = 30; y += rect.height + 30;
-
- // Reflect around the x axis.
- transform.setElements(1, 0, 0, -1, 0, 0);
- gc.setTransform(transform);
- gc.drawImage(image, x, -1*y-rect.height);
-
- x += rect.width + 30;
-
- // Reflect around the x and y axes
- transform.setElements(-1, 0, 0, -1, 0, 0);
- gc.setTransform(transform);
- gc.drawImage(image, -1*x-rect.width, -1*y-rect.height);
-
- x = 30; y += rect.height + 30;
-
- // Shear in the x-direction
- transform.setElements(1, 0, -1, 1, 0, 0);
- gc.setTransform(transform);
- gc.drawImage(image, 300, y);
-
- // Shear in y-direction
- transform.setElements(1, -1, 0, 1, 0, 0);
- gc.setTransform(transform);
- gc.drawImage(image, 150, 475);
-
- // Rotate by 45 degrees
- float cos45 = (float)Math.cos(Math.PI/4);
- float sin45 = (float)Math.sin(Math.PI/4);
- transform.setElements(cos45, sin45, -sin45, cos45, 0, 0);
- gc.setTransform(transform);
- gc.drawImage(image, 400, 60);
-
- transform.dispose();
+ canvas.addPaintListener(e -> {
+ GC gc1 = e.gc;
+ gc1.setAdvanced(true);
+ if (!gc1.getAdvanced()){
+ gc1.drawText("Advanced graphics not supported", 30, 30, true);
+ return;
}
+
+ // Original image
+ int x = 30, y = 30;
+ gc1.drawImage(image, x, y);
+ x += rect.width + 30;
+
+ Transform transform = new Transform(display);
+
+ // Note that the tranform is applied to the whole GC therefore
+ // the coordinates need to be adjusted too.
+
+ // Reflect around the y axis.
+ transform.setElements(-1, 0, 0, 1, 0 ,0);
+ gc1.setTransform(transform);
+ gc1.drawImage(image, -1*x-rect.width, y);
+
+ x = 30; y += rect.height + 30;
+
+ // Reflect around the x axis.
+ transform.setElements(1, 0, 0, -1, 0, 0);
+ gc1.setTransform(transform);
+ gc1.drawImage(image, x, -1*y-rect.height);
+
+ x += rect.width + 30;
+
+ // Reflect around the x and y axes
+ transform.setElements(-1, 0, 0, -1, 0, 0);
+ gc1.setTransform(transform);
+ gc1.drawImage(image, -1*x-rect.width, -1*y-rect.height);
+
+ x = 30; y += rect.height + 30;
+
+ // Shear in the x-direction
+ transform.setElements(1, 0, -1, 1, 0, 0);
+ gc1.setTransform(transform);
+ gc1.drawImage(image, 300, y);
+
+ // Shear in y-direction
+ transform.setElements(1, -1, 0, 1, 0, 0);
+ gc1.setTransform(transform);
+ gc1.drawImage(image, 150, 475);
+
+ // Rotate by 45 degrees
+ float cos45 = (float)Math.cos(Math.PI/4);
+ float sin45 = (float)Math.sin(Math.PI/4);
+ transform.setElements(cos45, sin45, -sin45, cos45, 0, 0);
+ gc1.setTransform(transform);
+ gc1.drawImage(image, 400, 60);
+
+ transform.dispose();
});
-
+
shell.setSize(350, 550);
shell.open();
while (!shell.isDisposed()) {
@@ -114,7 +110,7 @@ public class Snippet207 {
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
index 8d86283c24..792c9c081e 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -34,46 +34,28 @@ public static void main (String [] args) {
shell.setDefaultButton (b);
final Canvas c = new Canvas (shell, SWT.BORDER);
c.setBounds (10, 50, 100, 32);
- c.addListener (SWT.Traverse, new Listener () {
- @Override
- 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 () {
- @Override
- public void handleEvent (Event e) {
- c.setBackground (red);
- }
- });
- c.addListener (SWT.FocusOut, new Listener () {
- @Override
- public void handleEvent (Event e) {
- c.setBackground (blue);
- }
- });
- c.addListener (SWT.KeyDown, new Listener () {
- @Override
- public void handleEvent (Event e) {
- System.out.println ("KEY");
+ c.addListener (SWT.Traverse, 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, e -> c.setBackground (red));
+ c.addListener (SWT.FocusOut, e -> c.setBackground (blue));
+ c.addListener (SWT.KeyDown, e -> System.out.println ("KEY"));
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 ();
@@ -82,4 +64,4 @@ public static void main (String [] args) {
}
display.dispose ();
}
-}
+}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet212.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet212.java
index eb9389695a..c301e4e78d 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet212.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet212.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -11,24 +11,23 @@
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.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.custom.*;
/**
* StyledText snippet: embed images
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
public class Snippet212 {
-
+
static StyledText styledText;
- static String text =
+ static String text =
"This snippet shows how to embed images in a StyledText.\n"+
"Here is one: \uFFFC, and here is another: \uFFFC."+
"Use the add button to add an image from your filesystem to the StyledText at the current caret offset.";
@@ -40,9 +39,9 @@ public class Snippet212 {
style.data = image;
Rectangle rect = image.getBounds();
style.metrics = new GlyphMetrics(rect.height, 0, rect.width);
- styledText.setStyleRange(style);
+ styledText.setStyleRange(style);
}
-
+
public static void main(String [] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
@@ -56,66 +55,54 @@ public class Snippet212 {
addImage(display.getSystemImage(SWT.ICON_INFORMATION), offset);
// use a verify listener to dispose the images
- styledText.addVerifyListener(new VerifyListener() {
- @Override
- public void verifyText(VerifyEvent event) {
- if (event.start == event.end) return;
- String text = styledText.getText(event.start, event.end - 1);
- int index = text.indexOf('\uFFFC');
- while (index != -1) {
- StyleRange style = styledText.getStyleRangeAtOffset(event.start + index);
- if (style != null) {
- Image image = (Image)style.data;
- if (image != null) image.dispose();
- }
- index = text.indexOf('\uFFFC', index + 1);
+ styledText.addVerifyListener(event -> {
+ if (event.start == event.end) return;
+ String text = styledText.getText(event.start, event.end - 1);
+ int index = text.indexOf('\uFFFC');
+ while (index != -1) {
+ StyleRange style = styledText.getStyleRangeAtOffset(event.start + index);
+ if (style != null) {
+ Image image = (Image)style.data;
+ if (image != null) image.dispose();
}
+ index = text.indexOf('\uFFFC', index + 1);
}
});
// draw images on paint event
- styledText.addPaintObjectListener(new PaintObjectListener() {
- @Override
- public void paintObject(PaintObjectEvent event) {
- StyleRange style = event.style;
- Image image = (Image)style.data;
- if (!image.isDisposed()) {
- int x = event.x;
- int y = event.y + event.ascent - style.metrics.ascent;
- event.gc.drawImage(image, x, y);
- }
+ styledText.addPaintObjectListener(event -> {
+ StyleRange style = event.style;
+ Image image = (Image)style.data;
+ if (!image.isDisposed()) {
+ int x = event.x;
+ int y = event.y + event.ascent - style.metrics.ascent;
+ event.gc.drawImage(image, x, y);
}
});
- styledText.addListener(SWT.Dispose, new Listener() {
- @Override
- public void handleEvent(Event event) {
- StyleRange[] styles = styledText.getStyleRanges();
- for (int i = 0; i < styles.length; i++) {
- StyleRange style = styles[i];
- if (style.data != null) {
- Image image = (Image)style.data;
- if (image != null) image.dispose();
- }
+ styledText.addListener(SWT.Dispose, event -> {
+ StyleRange[] styles = styledText.getStyleRanges();
+ for (int i = 0; i < styles.length; i++) {
+ StyleRange style = styles[i];
+ if (style.data != null) {
+ Image image = (Image)style.data;
+ if (image != null) image.dispose();
}
}
});
Button button = new Button (shell, SWT.PUSH);
button.setText("Add Image");
button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
- button.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- FileDialog dialog = new FileDialog(shell);
- String filename = dialog.open();
- if (filename != null) {
- try {
- Image image = new Image(display, filename);
- int offset = styledText.getCaretOffset();
- styledText.replaceTextRange(offset, 0, "\uFFFC");
- addImage(image, offset);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ button.addListener(SWT.Selection, event -> {
+ FileDialog dialog = new FileDialog(shell);
+ String filename = dialog.open();
+ if (filename != null) {
+ try {
+ Image image = new Image(display, filename);
+ int offset1 = styledText.getCaretOffset();
+ styledText.replaceTextRange(offset1, 0, "\uFFFC");
+ addImage(image, offset1);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
});
shell.setSize(400, 400);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet214.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet214.java
index 0a1abb74c5..9406beaa4d 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet214.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet214.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,10 +12,10 @@ package org.eclipse.swt.snippets;
/*
* Control example snippet: set a background image (a dynamic gradient)
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
import org.eclipse.swt.*;
@@ -41,20 +41,17 @@ public class Snippet214 {
Button button = new Button (group, SWT.RADIO);
button.setText ("Button " + i);
}
- shell.addListener (SWT.Resize, new Listener () {
- @Override
- public void handleEvent (Event event) {
- Rectangle rect = shell.getClientArea ();
- Image newImage = new Image (display, Math.max (1, rect.width), 1);
- GC gc = new GC (newImage);
- gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
- gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE));
- gc.fillGradientRectangle (rect.x, rect.y, rect.width, 1, false);
- gc.dispose ();
- shell.setBackgroundImage (newImage);
- if (oldImage != null) oldImage.dispose ();
- oldImage = newImage;
- }
+ shell.addListener (SWT.Resize, event -> {
+ Rectangle rect = shell.getClientArea ();
+ Image newImage = new Image (display, Math.max (1, rect.width), 1);
+ GC gc = new GC (newImage);
+ gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
+ gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE));
+ gc.fillGradientRectangle (rect.x, rect.y, rect.width, 1, false);
+ gc.dispose ();
+ shell.setBackgroundImage (newImage);
+ if (oldImage != null) oldImage.dispose ();
+ oldImage = newImage;
});
shell.pack ();
shell.open ();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet215.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet215.java
index 3253f9fb81..fcf1e905d8 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet215.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet215.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-
+
/*
* GC example snippet: take a screen shot with a GC
*
@@ -17,11 +17,10 @@ package org.eclipse.swt.snippets;
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
+import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
-import org.eclipse.swt.custom.*;
+import org.eclipse.swt.widgets.*;
public class Snippet215 {
@@ -31,39 +30,26 @@ public static void main(String[] args) {
shell.setLayout(new FillLayout());
Button button = new Button(shell, SWT.PUSH);
button.setText("Capture");
- button.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
-
- /* Take the screen shot */
- GC gc = new GC(display);
- final Image image = new Image(display, display.getBounds());
- gc.copyArea(image, 0, 0);
- gc.dispose();
-
- Shell popup = new Shell(shell, SWT.SHELL_TRIM);
- popup.setLayout(new FillLayout());
- popup.setText("Image");
- popup.setBounds(50, 50, 200, 200);
- popup.addListener(SWT.Close, new Listener() {
- @Override
- public void handleEvent(Event e) {
- image.dispose();
- }
- });
-
- ScrolledComposite sc = new ScrolledComposite (popup, SWT.V_SCROLL | SWT.H_SCROLL);
- Canvas canvas = new Canvas(sc, SWT.NONE);
- sc.setContent(canvas);
- canvas.setBounds(display.getBounds ());
- canvas.addPaintListener(new PaintListener() {
- @Override
- public void paintControl(PaintEvent e) {
- e.gc.drawImage(image, 0, 0);
- }
- });
- popup.open();
- }
+ button.addListener(SWT.Selection, event -> {
+
+ /* Take the screen shot */
+ GC gc = new GC(display);
+ final Image image = new Image(display, display.getBounds());
+ gc.copyArea(image, 0, 0);
+ gc.dispose();
+
+ Shell popup = new Shell(shell, SWT.SHELL_TRIM);
+ popup.setLayout(new FillLayout());
+ popup.setText("Image");
+ popup.setBounds(50, 50, 200, 200);
+ popup.addListener(SWT.Close, e -> image.dispose());
+
+ ScrolledComposite sc = new ScrolledComposite (popup, SWT.V_SCROLL | SWT.H_SCROLL);
+ Canvas canvas = new Canvas(sc, SWT.NONE);
+ sc.setContent(canvas);
+ canvas.setBounds(display.getBounds ());
+ canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));
+ popup.open();
});
shell.pack();
shell.open();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet216.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet216.java
index 7f0a57d701..74465410a5 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet216.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet216.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -34,37 +34,31 @@ public class Snippet216 {
new Rectangle (80, 80, 10, 10),
};
final Shell shell = new Shell (display);
- Listener mouseListener = new Listener () {
- @Override
- public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.MouseEnter:
- case SWT.MouseMove:
- for (int i=0; i<rects.length; i++) {
- if (rects [i].contains (event.x, event.y)) {
- String text = "ToolTip " + i;
- if (!(text.equals (shell.getToolTipText ()))) {
- shell.setToolTipText ("ToolTip " + i);
- }
- return;
+ Listener mouseListener = event -> {
+ switch (event.type) {
+ case SWT.MouseEnter:
+ case SWT.MouseMove:
+ for (int i=0; i<rects.length; i++) {
+ if (rects [i].contains (event.x, event.y)) {
+ String text = "ToolTip " + i;
+ if (!(text.equals (shell.getToolTipText ()))) {
+ shell.setToolTipText ("ToolTip " + i);
}
+ return;
}
- shell.setToolTipText (null);
- break;
}
- }
+ shell.setToolTipText (null);
+ break;
+ }
};
shell.addListener (SWT.MouseMove, mouseListener);
shell.addListener (SWT.MouseEnter, mouseListener);
- shell.addListener (SWT.Paint, new Listener () {
- @Override
- public void handleEvent (Event event) {
- GC gc = event.gc;
- for (int i=0; i<rects.length; i++) {
- gc.setBackground (colors [i]);
- gc.fillRectangle (rects [i]);
- gc.drawRectangle (rects [i]);
- }
+ shell.addListener (SWT.Paint, event -> {
+ GC gc = event.gc;
+ for (int i=0; i<rects.length; i++) {
+ gc.setBackground (colors [i]);
+ gc.fillRectangle (rects [i]);
+ gc.drawRectangle (rects [i]);
}
});
shell.setSize (200, 200);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet217.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet217.java
index 664b0d4b23..c43b23ff4c 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet217.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet217.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,7 +12,6 @@ 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.*;
@@ -22,17 +21,17 @@ import org.eclipse.swt.widgets.*;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
public class Snippet217 {
-
+
static StyledText styledText;
- static String text =
+ static String text =
"This snippet shows how to embed widgets in a StyledText.\n"+
"Here is one: \uFFFC, and here is another: \uFFFC.";
static int MARGIN = 5;
-
+
static void addControl(Control control, int offset) {
StyleRange style = new StyleRange ();
style.start = offset;
@@ -43,9 +42,9 @@ public class Snippet217 {
int ascent = 2*rect.height/3;
int descent = rect.height - ascent;
style.metrics = new GlyphMetrics(ascent + MARGIN, descent + MARGIN, rect.width + 2*MARGIN);
- styledText.setStyleRange(style);
+ styledText.setStyleRange(style);
}
-
+
public static void main(String [] args) {
final Display display = new Display();
Font font = new Font(display, "Tahoma", 16, SWT.NORMAL);
@@ -67,37 +66,31 @@ public class Snippet217 {
offset = text.indexOf('\uFFFC', offset + 1);
addControl(combo, offset);
combo.setLocation(styledText.getLocationAtOffset(offset));
-
+
// use a verify listener to dispose the controls
- styledText.addVerifyListener(new VerifyListener() {
- @Override
- public void verifyText(VerifyEvent event) {
- if (event.start == event.end) return;
- String text = styledText.getText(event.start, event.end - 1);
- int index = text.indexOf('\uFFFC');
- while (index != -1) {
- StyleRange style = styledText.getStyleRangeAtOffset(event.start + index);
- if (style != null) {
- Control control = (Control)style.data;
- if (control != null) control.dispose();
- }
- index = text.indexOf('\uFFFC', index + 1);
+ styledText.addVerifyListener(event -> {
+ if (event.start == event.end) return;
+ String text = styledText.getText(event.start, event.end - 1);
+ int index = text.indexOf('\uFFFC');
+ while (index != -1) {
+ StyleRange style = styledText.getStyleRangeAtOffset(event.start + index);
+ if (style != null) {
+ Control control = (Control)style.data;
+ if (control != null) control.dispose();
}
+ index = text.indexOf('\uFFFC', index + 1);
}
});
-
+
// reposition widgets on paint event
- styledText.addPaintObjectListener(new PaintObjectListener() {
- @Override
- public void paintObject(PaintObjectEvent event) {
- Control control = (Control)event.style.data;
- Point pt = control.getSize();
- int x = event.x + MARGIN;
- int y = event.y + event.ascent - 2*pt.y/3;
- control.setLocation(x, y);
- }
+ styledText.addPaintObjectListener(event -> {
+ Control control = (Control)event.style.data;
+ Point pt = control.getSize();
+ int x = event.x + MARGIN;
+ int y = event.y + event.ascent - 2*pt.y/3;
+ control.setLocation(x, y);
});
-
+
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet218.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet218.java
index 595b44ac13..a31288781c 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet218.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet218.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -12,17 +12,17 @@ package org.eclipse.swt.snippets;
/*
* SWT StyledText snippet: use gradient background.
- *
+ *
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet218 {
@@ -33,7 +33,7 @@ public class Snippet218 {
"operating environments, and release-to-release compatibility. These are all things that need to be clear for "+
"any release, even if no features were to change. \n";
static Image oldImage;
-
+
public static void main(String [] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
@@ -44,21 +44,18 @@ public class Snippet218 {
Font font = new Font(display, data.getName(), 16, SWT.BOLD);
styledText.setFont(font);
styledText.setForeground(display.getSystemColor (SWT.COLOR_BLUE));
- styledText.addListener (SWT.Resize, new Listener () {
- @Override
- public void handleEvent (Event event) {
- Rectangle rect = styledText.getClientArea ();
- Image newImage = new Image (display, 1, Math.max (1, rect.height));
- GC gc = new GC (newImage);
- gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
- gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
- gc.fillGradientRectangle (rect.x, rect.y, 1, rect.height, true);
- gc.dispose ();
- styledText.setBackgroundImage (newImage);
- if (oldImage != null) oldImage.dispose ();
- oldImage = newImage;
- }
- });
+ styledText.addListener (SWT.Resize, event -> {
+ Rectangle rect = styledText.getClientArea ();
+ Image newImage = new Image (display, 1, Math.max (1, rect.height));
+ GC gc = new GC (newImage);
+ gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
+ gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
+ gc.fillGradientRectangle (rect.x, rect.y, 1, rect.height, true);
+ gc.dispose ();
+ styledText.setBackgroundImage (newImage);
+ if (oldImage != null) oldImage.dispose ();
+ oldImage = newImage;
+ });
shell.setSize(700, 400);
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet220.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet220.java
index ee625c8f7a..2005149d32 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet220.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet220.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-/*
+/*
* Tree example snippet: Images on the right side of the TreeItem
*
* For a detailed explanation of this snippet see
@@ -17,7 +17,7 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
@@ -25,8 +25,8 @@ import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
-public class Snippet220 {
-
+public class Snippet220 {
+
public static void main(String [] args) {
Display display = new Display();
Shell shell = new Shell(display);
@@ -55,28 +55,22 @@ public static void main(String [] args) {
* NOTE: MeasureItem and PaintItem are called repeatedly. Therefore it is
* critical for performance that these methods be as efficient as possible.
*/
- tree.addListener(SWT.MeasureItem, new Listener() {
- @Override
- public void handleEvent(Event event) {
- TreeItem item = (TreeItem)event.item;
- Image trailingImage = (Image)item.getData();
- if (trailingImage != null) {
- event.width += trailingImage.getBounds().width + IMAGE_MARGIN;
- }
+ tree.addListener(SWT.MeasureItem, event -> {
+ TreeItem item1 = (TreeItem)event.item;
+ Image trailingImage = (Image)item1.getData();
+ if (trailingImage != null) {
+ event.width += trailingImage.getBounds().width + IMAGE_MARGIN;
}
});
- tree.addListener(SWT.PaintItem, new Listener() {
- @Override
- public void handleEvent(Event event) {
- TreeItem item = (TreeItem)event.item;
- Image trailingImage = (Image)item.getData();
- if (trailingImage != null) {
- int x = event.x + event.width + IMAGE_MARGIN;
- int itemHeight = tree.getItemHeight();
- int imageHeight = trailingImage.getBounds().height;
- int y = event.y + (itemHeight - imageHeight) / 2;
- event.gc.drawImage(trailingImage, x, y);
- }
+ tree.addListener(SWT.PaintItem, event -> {
+ TreeItem item1 = (TreeItem)event.item;
+ Image trailingImage = (Image)item1.getData();
+ if (trailingImage != null) {
+ int x = event.x + event.width + IMAGE_MARGIN;
+ int itemHeight = tree.getItemHeight();
+ int imageHeight = trailingImage.getBounds().height;
+ int y = event.y + (itemHeight - imageHeight) / 2;
+ event.gc.drawImage(trailingImage, x, y);
}
});
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet221.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet221.java
index 6ff46bc622..b26df34f48 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet221.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet221.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-/*
+/*
* example snippet: Scroll tree when mouse at top or bottom
*
* For a list of all SWT example snippets see
@@ -25,7 +25,7 @@ public class Snippet221 {
static Runnable Heartbeat;
static boolean Tracking;
static int ScrollSpeed = 40;
-
+
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
@@ -59,7 +59,7 @@ public static void main(String[] args) {
column0.pack();
column1.pack();
column2.pack();
-
+
Heartbeat = () -> {
if (!Tracking || tree.isDisposed()) return;
Point cursor = display.getCursorLocation();
@@ -67,21 +67,18 @@ public static void main(String[] args) {
Scroll(tree, cursor.x, cursor.y);
display.timerExec(ScrollSpeed, Heartbeat);
};
- Listener listener = new Listener() {
- @Override
- public void handleEvent(Event event) {
- switch (event.type) {
- case SWT.MouseEnter:
- Tracking = true;
- display.timerExec(0, Heartbeat);
- break;
- case SWT.MouseExit:
- Tracking = false;
- break;
- }
+ Listener listener = event -> {
+ switch (event.type) {
+ case SWT.MouseEnter:
+ Tracking = true;
+ display.timerExec(0, Heartbeat);
+ break;
+ case SWT.MouseExit:
+ Tracking = false;
+ break;
}
};
- tree.addListener(SWT.MouseEnter, listener);
+ tree.addListener(SWT.MouseEnter, listener);
tree.addListener(SWT.MouseExit, listener);
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet222.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet222.java
index 79ba44c8d6..2f4423eb78 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet222.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet222.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,24 +9,24 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-/*
+/*
* example snippet: StyledText bulleted list example
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet222 {
-
-public static void main(String[] args) {
+
+public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("StyledText Bullet Example");
@@ -40,9 +40,9 @@ public static void main(String[] args) {
for (int i = 0; i < 4; i++) text.append("Sub List Item " + i + "\n");
for (int i = 0; i < 2; i++) text.append("Numbered List Item " + (2 + i) + "\n");
text.append("\n");
- for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " + i + "\n");
+ for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " + i + "\n");
styledText.setText(text.toString());
-
+
StyleRange style0 = new StyleRange();
style0.metrics = new GlyphMetrics(0, 0, 40);
style0.foreground = display.getSystemColor(SWT.COLOR_RED);
@@ -67,21 +67,18 @@ public static void main(String[] args) {
styledText.setLineBullet(13, 2, bullet1);
styledText.setLineBullet(16, 4, bullet3);
- styledText.addPaintObjectListener(new PaintObjectListener() {
- @Override
- public void paintObject(PaintObjectEvent event) {
- Display display = event.display;
- StyleRange style = event.style;
- Font font = style.font;
- if (font == null) font = styledText.getFont();
- TextLayout layout = new TextLayout(display);
- layout.setAscent(event.ascent);
- layout.setDescent(event.descent);
- layout.setFont(font);
- layout.setText("\u2023 1." + event.bulletIndex + ")");
- layout.draw(event.gc, event.x + 10, event.y);
- layout.dispose();
- }
+ styledText.addPaintObjectListener(event -> {
+ Display display1 = event.display;
+ StyleRange style = event.style;
+ Font font = style.font;
+ if (font == null) font = styledText.getFont();
+ TextLayout layout = new TextLayout(display1);
+ layout.setAscent(event.ascent);
+ layout.setDescent(event.descent);
+ layout.setFont(font);
+ layout.setText("\u2023 1." + event.bulletIndex + ")");
+ layout.draw(event.gc, event.x + 10, event.y);
+ layout.dispose();
});
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet224.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet224.java
index 5511f26f2f..2f93319983 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet224.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet224.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -15,13 +15,13 @@ package org.eclipse.swt.snippets;
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet224 {
public static void main (String [] args) {
@@ -35,19 +35,16 @@ public static void main (String [] args) {
}
Button button = new Button (shell, SWT.PUSH);
button.setText ("Set Selection to B4");
- button.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- Control [] children = shell.getChildren ();
- Button newButton = (Button) children [4];
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child instanceof Button && (child.getStyle () & SWT.RADIO) != 0) {
- ((Button) child).setSelection (false);
- }
+ button.addListener (SWT.Selection, event -> {
+ Control [] children = shell.getChildren ();
+ Button newButton = (Button) children [4];
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (child instanceof Button && (child.getStyle () & SWT.RADIO) != 0) {
+ ((Button) child).setSelection (false);
}
- newButton.setSelection (true);
}
+ newButton.setSelection (true);
});
shell.pack ();
shell.open ();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java
index 8e48cd7cf6..87bbd14d6c 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet225.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 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
@@ -9,13 +9,13 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
-
+
/*
* Tooltip example snippet: create a balloon tooltip for a tray item
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
- *
+ *
* @since 3.2
*/
import org.eclipse.swt.*;
@@ -43,12 +43,7 @@ public static void main(String[] args) {
}
Button button = new Button (shell, SWT.PUSH);
button.setText("Press for balloon tip");
- button.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- tip.setVisible(true);
- }
- });
+ button.addListener(SWT.Selection, event -> tip.setVisible(true));
Rectangle clientArea = shell.getClientArea();
button.setLocation(clientArea.x, clientArea.y);
button.pack();

Back to the top