diff options
author | Christian Mohr | 2016-11-08 19:32:20 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2016-11-17 12:53:02 +0000 |
commit | 6851932bc9a8259f0fb23f57b06c7e154fdca3bb (patch) | |
tree | 2e1859762f3c7eb7ab88680d93262cd9008335d6 /examples | |
parent | 556d2295e0f4634f277d34b687a7a92db7910b72 (diff) | |
download | eclipse.platform.swt-6851932bc9a8259f0fb23f57b06c7e154fdca3bb.tar.gz eclipse.platform.swt-6851932bc9a8259f0fb23f57b06c7e154fdca3bb.tar.xz eclipse.platform.swt-6851932bc9a8259f0fb23f57b06c7e154fdca3bb.zip |
Bug 506585 - [Snippets] Refactor registered listeneres to use lambda
expressions
Use SelectionListener.widget(Default)Selected in all snippets.
Fixes wrong indentation in the changed Snippets, too.
Change-Id: Ie77d41b69f1b8a542153883f3623898f7b5efe64
Signed-off-by: Christian Mohr <christian.mohr@cjt.de>
Diffstat (limited to 'examples')
10 files changed, 292 insertions, 358 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet295.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet295.java index 0ec1774894..c3ceaded40 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet295.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet295.java @@ -16,8 +16,9 @@ package org.eclipse.swt.snippets; * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ */ +import static org.eclipse.swt.events.SelectionListener.*; + import org.eclipse.swt.*; -import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; @@ -34,66 +35,57 @@ public static void main (String [] args) { Button open = new Button (shell, SWT.PUSH); open.setText ("Prompt for a String"); - open.addSelectionListener (new SelectionAdapter () { - @Override - public void widgetSelected (SelectionEvent e) { - final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); - dialog.setText("Dialog Shell"); - FormLayout formLayout = new FormLayout (); - formLayout.marginWidth = 10; - formLayout.marginHeight = 10; - formLayout.spacing = 10; - dialog.setLayout (formLayout); + open.addSelectionListener(widgetSelectedAdapter(e -> { + final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); + dialog.setText("Dialog Shell"); + FormLayout formLayout = new FormLayout (); + formLayout.marginWidth = 10; + formLayout.marginHeight = 10; + formLayout.spacing = 10; + dialog.setLayout (formLayout); - Label label = new Label (dialog, SWT.NONE); - label.setText ("Type a String:"); - FormData data = new FormData (); - label.setLayoutData (data); + Label label = new Label (dialog, SWT.NONE); + label.setText ("Type a String:"); + FormData data = new FormData (); + label.setLayoutData (data); - Button cancel = new Button (dialog, SWT.PUSH); - cancel.setText ("Cancel"); - data = new FormData (); - data.width = 60; - data.right = new FormAttachment (100, 0); - data.bottom = new FormAttachment (100, 0); - cancel.setLayoutData (data); - cancel.addSelectionListener (new SelectionAdapter () { - @Override - public void widgetSelected (SelectionEvent e) { - System.out.println("User cancelled dialog"); - dialog.close (); - } - }); + Button cancel = new Button (dialog, SWT.PUSH); + cancel.setText ("Cancel"); + data = new FormData (); + data.width = 60; + data.right = new FormAttachment (100, 0); + data.bottom = new FormAttachment (100, 0); + cancel.setLayoutData (data); + cancel.addSelectionListener (widgetSelectedAdapter(event -> { + System.out.println("User cancelled dialog"); + dialog.close (); + })); - final Text text = new Text (dialog, SWT.BORDER); - data = new FormData (); - data.width = 200; - data.left = new FormAttachment (label, 0, SWT.DEFAULT); - data.right = new FormAttachment (100, 0); - data.top = new FormAttachment (label, 0, SWT.CENTER); - data.bottom = new FormAttachment (cancel, 0, SWT.DEFAULT); - text.setLayoutData (data); + final Text text = new Text (dialog, SWT.BORDER); + data = new FormData (); + data.width = 200; + data.left = new FormAttachment (label, 0, SWT.DEFAULT); + data.right = new FormAttachment (100, 0); + data.top = new FormAttachment (label, 0, SWT.CENTER); + data.bottom = new FormAttachment (cancel, 0, SWT.DEFAULT); + text.setLayoutData (data); - Button ok = new Button (dialog, SWT.PUSH); - ok.setText ("OK"); - data = new FormData (); - data.width = 60; - data.right = new FormAttachment (cancel, 0, SWT.DEFAULT); - data.bottom = new FormAttachment (100, 0); - ok.setLayoutData (data); - ok.addSelectionListener (new SelectionAdapter () { - @Override - public void widgetSelected (SelectionEvent e) { - System.out.println ("User typed: " + text.getText ()); - dialog.close (); - } - }); + Button ok = new Button (dialog, SWT.PUSH); + ok.setText ("OK"); + data = new FormData (); + data.width = 60; + data.right = new FormAttachment (cancel, 0, SWT.DEFAULT); + data.bottom = new FormAttachment (100, 0); + ok.setLayoutData (data); + ok.addSelectionListener (widgetSelectedAdapter(event -> { + System.out.println ("User typed: " + text.getText ()); + dialog.close (); + })); - dialog.setDefaultButton (ok); - dialog.pack (); - dialog.open (); - } - }); + dialog.setDefaultButton (ok); + dialog.pack (); + dialog.open (); + })); shell.pack (); shell.open (); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet313.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet313.java index caaf3a1118..e40999d717 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet313.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet313.java @@ -18,8 +18,9 @@ package org.eclipse.swt.snippets; * * @since 3.5 */ +import static org.eclipse.swt.events.SelectionListener.*; + import org.eclipse.swt.*; -import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; @@ -49,19 +50,16 @@ public class Snippet313 { up.right = new FormAttachment (0); composite.setLayoutData (up); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (composite.getLayoutData() == up) { - composite.setLayoutData (down); - button.setText("<<"); - } else { - composite.setLayoutData (up); - button.setText(">>"); - } - shell.pack (); + button.addSelectionListener(widgetSelectedAdapter(e -> { + if (composite.getLayoutData() == up) { + composite.setLayoutData (down); + button.setText("<<"); + } else { + composite.setLayoutData (up); + button.setText(">>"); } - }); + shell.pack (); + })); shell.pack (); shell.open (); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet322.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet322.java index 03d32d67e5..9ddd4f4a1b 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet322.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet322.java @@ -18,6 +18,8 @@ package org.eclipse.swt.snippets; * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ */ +import static org.eclipse.swt.events.SelectionListener.*; + import org.eclipse.swt.*; import org.eclipse.swt.custom.*; import org.eclipse.swt.events.*; @@ -63,22 +65,19 @@ public static void main (String[] args) { * The following listener ensures that a newly-selected item * in the Tree is always visible. */ - tree.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - TreeItem [] selectedItems = tree.getSelection(); - if (selectedItems.length > 0) { - Rectangle itemRect = selectedItems[0].getBounds(); - Rectangle area = sc.getClientArea(); - Point origin = sc.getOrigin(); - if (itemRect.x < origin.x || itemRect.y < origin.y - || itemRect.x + itemRect.width > origin.x + area.width - || itemRect.y + itemRect.height > origin.y + area.height) { - sc.setOrigin(itemRect.x, itemRect.y); - } + tree.addSelectionListener(widgetSelectedAdapter(e -> { + TreeItem [] selectedItems = tree.getSelection(); + if (selectedItems.length > 0) { + Rectangle itemRect = selectedItems[0].getBounds(); + Rectangle area = sc.getClientArea(); + Point origin = sc.getOrigin(); + if (itemRect.x < origin.x || itemRect.y < origin.y + || itemRect.x + itemRect.width > origin.x + area.width + || itemRect.y + itemRect.height > origin.y + area.height) { + sc.setOrigin(itemRect.x, itemRect.y); } } - }); + })); /* * The following listener scrolls the Tree one item at a time * in response to MouseWheel events. diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java index 5f7a631be1..629d4f74cf 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java @@ -22,6 +22,7 @@ package org.eclipse.swt.snippets; * * @since 3.3 */ +import static org.eclipse.swt.events.SelectionListener.*; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.*; @@ -78,76 +79,70 @@ class DOMEditor { shell.open (); final TreeItem[] lastItem = new TreeItem[1]; final TreeEditor editor = new TreeEditor (tree); - tree.addSelectionListener (new SelectionAdapter () { - @Override - public void widgetDefaultSelected (SelectionEvent e) { - final TreeItem item = (TreeItem)e.item; - final nsIDOMNode node = (nsIDOMNode)item.getData (); - if (node == null) return; /* not editable */ - if (item != null && item == lastItem[0]) { - final Composite composite = new Composite (tree, SWT.NONE); - final Text text = new Text (composite, SWT.NONE); - final int inset = 1; - 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); + tree.addSelectionListener (widgetDefaultSelectedAdapter(e -> { + final TreeItem item = (TreeItem)e.item; + final nsIDOMNode node = (nsIDOMNode)item.getData (); + if (node == null) return; /* not editable */ + if (item != null && item == lastItem[0]) { + final Composite composite = new Composite (tree, SWT.NONE); + final Text text = new Text (composite, SWT.NONE); + final int inset = 1; + composite.addListener (SWT.Resize, 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: + String string = text.getText (); + node.setNodeValue (string); + item.setText ("Node Value: " + node.getNodeValue ()); + 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: + string = text.getText (); + node.setNodeValue (string); + item.setText ("Node Value: " + node.getNodeValue ()); + //FALL THROUGH + case SWT.TRAVERSE_ESCAPE: + composite.dispose (); + e.doit = false; + } + break; } - }); - Listener textListener = new Listener () { - @Override - public void handleEvent (final Event e) { - switch (e.type) { - case SWT.FocusOut: - String string = text.getText (); - node.setNodeValue (string); - item.setText ("Node Value: " + node.getNodeValue ()); - 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: - string = text.getText (); - node.setNodeValue (string); - item.setText ("Node Value: " + node.getNodeValue ()); - //FALL THROUGH - case SWT.TRAVERSE_ESCAPE: - composite.dispose (); - e.doit = false; - } - break; - } - } - }; - text.addListener (SWT.FocusOut, textListener); - text.addListener (SWT.Traverse, textListener); - text.addListener (SWT.Verify, textListener); - editor.setEditor (composite, item); - String nodeValue = node.getNodeValue (); - text.setText (nodeValue == null ? "null" : nodeValue); - text.selectAll (); - text.setFocus (); - } - lastItem [0] = item; + } + }; + text.addListener (SWT.FocusOut, textListener); + text.addListener (SWT.Traverse, textListener); + text.addListener (SWT.Verify, textListener); + editor.setEditor (composite, item); + String nodeValue = node.getNodeValue (); + text.setText (nodeValue == null ? "null" : nodeValue); + text.selectAll (); + text.setFocus (); } - }); + lastItem [0] = item; + })); } public void populate (nsIDOMElement element) { diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet333.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet333.java index 884df450b9..83977f1f4d 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet333.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet333.java @@ -18,10 +18,11 @@ package org.eclipse.swt.snippets; * * @since 3.6 */ +import static org.eclipse.swt.events.SelectionListener.*; + import java.util.*; import org.eclipse.swt.*; -import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; @@ -73,31 +74,22 @@ public class Snippet333 { buttonContainer.setLayout(new GridLayout(3, false)); Button reskin = new Button(buttonContainer, SWT.PUSH); reskin.setText("Reskin All"); - reskin.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("======="); - shell.reskin(SWT.ALL); - } - }); + reskin.addSelectionListener(widgetSelectedAdapter(e -> { + System.out.println("======="); + shell.reskin(SWT.ALL); + })); Button reskin2 = new Button(buttonContainer, SWT.PUSH); reskin2.setText("Reskin Shell"); - reskin2.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("======="); - shell.reskin(SWT.None); - } - }); + reskin2.addSelectionListener(widgetSelectedAdapter(e -> { + System.out.println("======="); + shell.reskin(SWT.None); + })); Button reskin3 = new Button(buttonContainer, SWT.PUSH); reskin3.setText("Reskin Right Composite"); - reskin3.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("======="); - child3.reskin(SWT.ALL); - } - }); + reskin3.addSelectionListener(widgetSelectedAdapter(e -> { + System.out.println("======="); + child3.reskin(SWT.ALL); + })); shell.pack(); shell.open(); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet344.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet344.java index 401c23673a..53c0356edb 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet344.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet344.java @@ -16,8 +16,9 @@ package org.eclipse.swt.snippets; * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ */ +import static org.eclipse.swt.events.SelectionListener.*; + import org.eclipse.swt.*; -import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; @@ -30,21 +31,18 @@ public class Snippet344 { Button button = new Button(shell, SWT.PUSH); button.setText("Click me"); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - Shell shell2 = new Shell(SWT.TOOL | SWT.RESIZE | SWT.CLOSE | SWT.MAX); - shell2.setLayout(new GridLayout(1, false)); - shell2.setText("Palette"); - Label l = new Label(shell2, SWT.LEFT); - l.setText("This is a SWT.TOOL Shell"); - Point origin = shell.getLocation(); - origin.x += 100; - origin.y += 100; - shell2.pack(); - shell2.open(); - } - }); + button.addSelectionListener(widgetSelectedAdapter(e -> { + Shell shell2 = new Shell(SWT.TOOL | SWT.RESIZE | SWT.CLOSE | SWT.MAX); + shell2.setLayout(new GridLayout(1, false)); + shell2.setText("Palette"); + Label l = new Label(shell2, SWT.LEFT); + l.setText("This is a SWT.TOOL Shell"); + Point origin = shell.getLocation(); + origin.x += 100; + origin.y += 100; + shell2.pack(); + shell2.open(); + })); shell.pack(); shell.open(); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet347.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet347.java index beb1363d72..44d61d3f3d 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet347.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet347.java @@ -18,8 +18,9 @@ package org.eclipse.swt.snippets; * * @since 3.7 */ +import static org.eclipse.swt.events.SelectionListener.*; + import org.eclipse.swt.*; -import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; @@ -39,12 +40,7 @@ public class Snippet347 { file.setMenu(dropdown); MenuItem exit = new MenuItem(dropdown, SWT.PUSH); exit.setText("Exit"); - exit.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - display.dispose(); - } - }); + exit.addSelectionListener(widgetSelectedAdapter(e -> display.dispose())); Button b = new Button(shell, SWT.PUSH); b.setText("Test"); shell.pack(); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet354.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet354.java index 96ec05a6c3..aa17c255f4 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet354.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet354.java @@ -18,6 +18,8 @@ package org.eclipse.swt.snippets; * * @since 3.7 */ +import static org.eclipse.swt.events.SelectionListener.*; + import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; @@ -49,12 +51,7 @@ public class Snippet354 { file.setMenu(dropdown); MenuItem exit = new MenuItem(dropdown, SWT.PUSH); exit.setText("Exit"); - exit.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - display.dispose(); - } - }); + exit.addSelectionListener(widgetSelectedAdapter(e -> display.dispose())); Listener keyDownFilter = event -> System.out.println("Key event!"); display.addFilter(SWT.KeyDown, keyDownFilter); @@ -78,58 +75,32 @@ public class Snippet354 { MenuItem sysItem = getItem(systemMenu, SWT.ID_QUIT); sysItem.addArmListener(armListener); - sysItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("Quit selected"); - } - }); + sysItem.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Quit selected"))); sysItem = getItem(systemMenu, SWT.ID_HIDE_OTHERS); sysItem.addArmListener(armListener); - sysItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("Hide others selected -- and blocked!"); - e.doit = false; - } - }); + sysItem.addSelectionListener(widgetSelectedAdapter(e -> { + System.out.println("Hide others selected -- and blocked!"); + e.doit = false; + })); sysItem = getItem(systemMenu, SWT.ID_HIDE); sysItem.addArmListener(armListener); - sysItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("Hide selected -- and blocked!"); - e.doit = false; - } - }); + sysItem.addSelectionListener(widgetSelectedAdapter(e -> { + System.out.println("Hide selected -- and blocked!"); + e.doit = false; + })); sysItem = getItem(systemMenu, SWT.ID_PREFERENCES); sysItem.addArmListener(armListener); - sysItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("Preferences selected"); - } - }); + sysItem.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Preferences selected"))); sysItem = getItem(systemMenu, SWT.ID_ABOUT); sysItem.addArmListener(armListener); - sysItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("About selected"); - } - }); + sysItem.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("About selected"))); int prefsIndex = systemMenu.indexOf(getItem(systemMenu, SWT.ID_PREFERENCES)); MenuItem newAppMenuItem = new MenuItem(systemMenu, SWT.CASCADE, prefsIndex + 1); newAppMenuItem.setText("SWT-added item"); newAppMenuItem.setAccelerator(SWT.MOD1 | 'i'); newAppMenuItem.addArmListener(armListener); - newAppMenuItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - System.out.println("SWT-added item selected"); - } - }); + newAppMenuItem.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("SWT-added item selected"))); Menu subMenu = new Menu(systemMenu); for (int i = 0; i < 4; i++) { diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java index 634fdcca68..0dfb2c2e93 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet361.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.swt.snippets; +import static org.eclipse.swt.events.SelectionListener.*; + import java.awt.*; import java.awt.Canvas; /* @@ -56,16 +58,13 @@ public class Snippet361 { Button fileButton = new Button(shell, SWT.PUSH); fileButton.setText("&Open Image File"); - fileButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - String filename = new FileDialog(shell).open(); - if (filename != null) { - image = Toolkit.getDefaultToolkit().getImage(filename); - canvas.repaint(); - } + fileButton.addSelectionListener(widgetSelectedAdapter(e -> { + String filename = new FileDialog(shell).open(); + if (filename != null) { + image = Toolkit.getDefaultToolkit().getImage(filename); + canvas.repaint(); } - }); + })); new Label(shell, SWT.NONE).setText("Translate &X by:"); final Combo translateXCombo = new Combo(shell, SWT.NONE); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java index 556ff40c64..c962cbc193 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java @@ -9,10 +9,10 @@ * IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
+import static org.eclipse.swt.events.SelectionListener.*;
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.*;
@@ -103,117 +103,111 @@ public class Snippet365 { buttonCheckBox.setText("SET TRANSPARENT");
buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
buttonCheckBox.setSelection(false);
- buttonCheckBox.addSelectionListener(new SelectionListener() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- boolean transparent = ((Button) e.getSource()).getSelection();
- if (transparent) {
- // ContainerGroup
- containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- for (TabItem item : tabFolder.getItems()) {
- item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- }
-
- // Native
- nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
-
- // Custom
- customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- for (Control control : sashForm.getChildren()) {
- control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
- }
- // Default
- push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
-
- // ItemGroup
- itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
- } else {
- // Native
- nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- toolBar.setBackground(null);
- coolBar.setBackground(null);
- label.setBackground(null);
- link.setBackground(null);
- scale.setBackground(null);
- RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB();
- radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255)));
- check.setBackgroundImage(getBackgroundImage(display));
- group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
- slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // ContainerGroup
- containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- for (TabItem item : tabFolder.getItems()) {
- item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- }
- // Custom
- customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- cLabel.setBackground((Color) null);
- styledText.setBackground((Color) null);
- sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- for (Control control : sashForm.getChildren()) {
- control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- }
- cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
-
- gradientCTab.setBackground(
- new Color[] { display.getSystemColor(SWT.COLOR_RED),
- display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true);
-
- // Default
- defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- dateTime.setBackground(null);
- progressBar.setBackground(null);
- expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
-
- // ItemGroup
- itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ buttonCheckBox.addSelectionListener(widgetSelectedAdapter( e-> {
+ boolean transparent = ((Button) e.getSource()).getSelection();
+ if (transparent) {
+ // ContainerGroup
+ containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ for (TabItem item : tabFolder.getItems()) {
+ item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
}
- }
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
+ // Native
+ nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+
+ // Custom
+ customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ for (Control control : sashForm.getChildren()) {
+ control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
+ }
+ // Default
+ push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+
+ // ItemGroup
+ itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ } else {
+ // Native
+ nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ toolBar.setBackground(null);
+ coolBar.setBackground(null);
+ label.setBackground(null);
+ link.setBackground(null);
+ scale.setBackground(null);
+ RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB();
+ radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255)));
+ check.setBackgroundImage(getBackgroundImage(display));
+ group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
+ slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // ContainerGroup
+ containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ for (TabItem item : tabFolder.getItems()) {
+ item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ }
+ // Custom
+ customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ cLabel.setBackground((Color) null);
+ styledText.setBackground((Color) null);
+ sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ for (Control control : sashForm.getChildren()) {
+ control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ }
+ cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+
+ gradientCTab.setBackground(
+ new Color[] { display.getSystemColor(SWT.COLOR_RED),
+ display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true);
+
+ // Default
+ defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ dateTime.setBackground(null);
+ progressBar.setBackground(null);
+ expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+
+ // ItemGroup
+ itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
}
- });
+
+ }));
// ContainerGroup
containerGroup = new Composite(shell, SWT.NONE);
|