diff options
author | Alexander Kurtakov | 2016-01-15 08:26:03 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2016-01-15 08:26:03 +0000 |
commit | 6f85200655d0d84b24fd6a5b181f0292638ef94a (patch) | |
tree | d10481ca1869019948f5764338c8473a3e8a1cdc /examples | |
parent | 3cb12b795b3443d0928c28de8b885864798a15e4 (diff) | |
download | eclipse.platform.swt-6f85200655d0d84b24fd6a5b181f0292638ef94a.tar.gz eclipse.platform.swt-6f85200655d0d84b24fd6a5b181f0292638ef94a.tar.xz eclipse.platform.swt-6f85200655d0d84b24fd6a5b181f0292638ef94a.zip |
Bug 485821 - Make examples/snippets use lambdas
Convert examples Listener cases.
Change-Id: I472cc59015a95e108dd273db0f1f635395a9dda0
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'examples')
34 files changed, 418 insertions, 819 deletions
diff --git a/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/EditorTab.java b/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/EditorTab.java index ff47fceedf..dc6996f884 100644 --- a/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/EditorTab.java +++ b/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/EditorTab.java @@ -22,7 +22,6 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Sash; @@ -86,18 +85,15 @@ public class EditorTab { 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 rect = sash.getBounds(); - Rectangle parentRect = sash.getParent().getClientArea(); - int right = parentRect.width - rect.width - 20; - e.x = Math.max(Math.min(e.x, right), 20); - if (e.x != rect.x) { - sashData.left = new FormAttachment(0, e.x); - parent.layout(); - } - } + sash.addListener(SWT.Selection, e -> { + Rectangle rect = sash.getBounds(); + Rectangle parentRect = sash.getParent().getClientArea(); + int right = parentRect.width - rect.width - 20; + e.x = Math.max(Math.min(e.x, right), 20); + if (e.x != rect.x) { + sashData.left = new FormAttachment(0, e.x); + parent.layout(); + } }); data = new FormData(); data.left = new FormAttachment(sash, 0); @@ -149,13 +145,10 @@ public class EditorTab { scriptText.setText(script); parent.layout(); - Listener listener = new Listener() { - @Override - public void handleEvent(Event e) { - Widget w = e.widget; - if (w == htmlButton) browser.setText(htmlText.getText()); - if (w == scriptButton) browser.execute(scriptText.getText()); - } + Listener listener = e -> { + Widget w = e.widget; + if (w == htmlButton) browser.setText(htmlText.getText()); + if (w == scriptButton) browser.execute(scriptText.getText()); }; htmlButton.addListener(SWT.Selection, listener); diff --git a/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/PawnTab.java b/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/PawnTab.java index 8ad7c9156d..4914044894 100644 --- a/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/PawnTab.java +++ b/examples/org.eclipse.swt.examples.browser.demos/src/org/eclipse/swt/examples/browser/demos/views/PawnTab.java @@ -19,8 +19,6 @@ import org.eclipse.swt.browser.LocationListener; import org.eclipse.swt.examples.browser.demos.BrowserDemoPlugin; import org.eclipse.swt.examples.browser.demos.Pawns; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.TabItem; @@ -77,15 +75,12 @@ public class PawnTab { menu = new Menu(browser.getShell(), SWT.POP_UP); MenuItem item2 = new MenuItem(menu, SWT.PUSH); item2.setText("End Game"); - item2.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - game = null; - isWhite = true; - cntWhite = 0; cntBlack = 0; - ttr = null; - browser.setUrl(URL_WELCOME); - } + item2.addListener(SWT.Selection, e -> { + game = null; + isWhite = true; + cntWhite = 0; cntBlack = 0; + ttr = null; + browser.setUrl(URL_WELCOME); }); browser.setMenu(menu); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java index 43c7f4b635..1c9de87da0 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java @@ -193,12 +193,7 @@ public CTable (Composite parent, int style) { arrowBounds = getArrowDownImage ().getBounds (); clientArea = getClientArea (); - Listener listener = new Listener () { - @Override - public void handleEvent (Event event) { - handleEvents (event); - } - }; + Listener listener = event -> handleEvents (event); addListener (SWT.Paint, listener); addListener (SWT.MouseDown, listener); addListener (SWT.MouseUp, listener); @@ -224,19 +219,16 @@ public CTable (Composite parent, int style) { header.addListener (SWT.MouseExit, listener); header.addListener (SWT.MenuDetect, listener); - toolTipListener = new Listener () { - @Override - public void handleEvent (Event event) { - switch (event.type) { - case SWT.MouseHover: - case SWT.MouseMove: - if (headerUpdateToolTip (event.x)) break; - // FALL THROUGH - case SWT.MouseExit: - case SWT.MouseDown: - headerHideToolTip (); - break; - } + toolTipListener = event -> { + switch (event.type) { + case SWT.MouseHover: + case SWT.MouseMove: + if (headerUpdateToolTip (event.x)) break; + // FALL THROUGH + case SWT.MouseExit: + case SWT.MouseDown: + headerHideToolTip (); + break; } }; diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java index b6939c9090..252740b965 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java @@ -42,7 +42,6 @@ import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.ProgressBar; @@ -184,16 +183,13 @@ public class BrowserExample { itemBack.setEnabled(browser.isBackEnabled()); itemForward.setEnabled(browser.isForwardEnabled()); - Listener listener = new Listener() { - @Override - public void handleEvent(Event event) { - ToolItem item = (ToolItem)event.widget; - if (item == itemBack) browser.back(); - else if (item == itemForward) browser.forward(); - else if (item == itemStop) browser.stop(); - else if (item == itemRefresh) browser.refresh(); - else if (item == itemGo) browser.setUrl(locationBar.getText()); - } + Listener listener = event -> { + ToolItem item = (ToolItem)event.widget; + if (item == itemBack) browser.back(); + else if (item == itemForward) browser.forward(); + else if (item == itemStop) browser.stop(); + else if (item == itemRefresh) browser.refresh(); + else if (item == itemGo) browser.setUrl(locationBar.getText()); }; itemBack.addListener(SWT.Selection, listener); itemForward.addListener(SWT.Selection, listener); @@ -210,19 +206,11 @@ public class BrowserExample { canvas.setLayoutData(data); final Rectangle rect = images[0].getBounds(); - canvas.addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event e) { - Point pt = ((Canvas)e.widget).getSize(); - e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y); - } - }); - canvas.addListener(SWT.MouseDown, new Listener() { - @Override - public void handleEvent(Event e) { - browser.setUrl(getResourceString("Startup")); - } + canvas.addListener(SWT.Paint, e -> { + Point pt = ((Canvas)e.widget).getSize(); + e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y); }); + canvas.addListener(SWT.MouseDown, e -> browser.setUrl(getResourceString("Startup"))); final Display display = parent.getDisplay(); display.asyncExec(new Runnable() { @@ -251,12 +239,7 @@ public class BrowserExample { data.right = new FormAttachment(100, 0); } locationBar.setLayoutData(data); - locationBar.addListener(SWT.DefaultSelection, new Listener() { - @Override - public void handleEvent(Event e) { - browser.setUrl(locationBar.getText()); - } - }); + locationBar.addListener(SWT.DefaultSelection, e -> browser.setUrl(locationBar.getText())); } if (statusBar) { status = new Label(parent, SWT.NONE); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java index 37ce175192..414d353a4c 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java @@ -36,12 +36,10 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; @@ -401,50 +399,41 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){ final Point copyOrigin = new Point(0, 0); final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar(); copyHBar.setEnabled(false); - copyHBar.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (copyImage[0] != null) { - int hSelection = copyHBar.getSelection(); - int destX = -hSelection - copyOrigin.x; - Rectangle rect = copyImage[0].getBounds(); - copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); - copyOrigin.x = -hSelection; - } + copyHBar.addListener(SWT.Selection, e -> { + if (copyImage[0] != null) { + int hSelection = copyHBar.getSelection(); + int destX = -hSelection - copyOrigin.x; + Rectangle rect = copyImage[0].getBounds(); + copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); + copyOrigin.x = -hSelection; } }); final ScrollBar copyVBar = copyImageCanvas.getVerticalBar(); copyVBar.setEnabled(false); - copyVBar.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent (Event e) { - if (copyImage[0] != null) { - int vSelection = copyVBar.getSelection(); - int destY = -vSelection - copyOrigin.y; - Rectangle rect = copyImage[0].getBounds(); - copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); - copyOrigin.y = -vSelection; - } + copyVBar.addListener(SWT.Selection, e -> { + if (copyImage[0] != null) { + int vSelection = copyVBar.getSelection(); + int destY = -vSelection - copyOrigin.y; + Rectangle rect = copyImage[0].getBounds(); + copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); + copyOrigin.y = -vSelection; } }); - copyImageCanvas.addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event e) { - if(copyImage[0] != null) { - GC gc = e.gc; - gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y); - Rectangle rect = copyImage[0].getBounds(); - Rectangle client = copyImageCanvas.getClientArea (); - int marginWidth = client.width - rect.width; - if (marginWidth > 0) { - gc.fillRectangle (rect.width, 0, marginWidth, client.height); - } - int marginHeight = client.height - rect.height; - if (marginHeight > 0) { - gc.fillRectangle(0, rect.height, client.width, marginHeight); - } - gc.dispose(); + copyImageCanvas.addListener(SWT.Paint, e -> { + if(copyImage[0] != null) { + GC gc = e.gc; + gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y); + Rectangle rect = copyImage[0].getBounds(); + Rectangle client = copyImageCanvas.getClientArea (); + int marginWidth = client.width - rect.width; + if (marginWidth > 0) { + gc.fillRectangle (rect.width, 0, marginWidth, client.height); } + int marginHeight = client.height - rect.height; + if (marginHeight > 0) { + gc.fillRectangle(0, rect.height, client.width, marginHeight); + } + gc.dispose(); } }); Button openButton = new Button(copyParent, SWT.PUSH); @@ -502,48 +491,39 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){ final Point pasteOrigin = new Point(0, 0); final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar(); pasteHBar.setEnabled(false); - pasteHBar.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (pasteImage[0] != null) { - int hSelection = pasteHBar.getSelection(); - int destX = -hSelection - pasteOrigin.x; - Rectangle rect = pasteImage[0].getBounds(); - pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); - pasteOrigin.x = -hSelection; - } + pasteHBar.addListener(SWT.Selection, e -> { + if (pasteImage[0] != null) { + int hSelection = pasteHBar.getSelection(); + int destX = -hSelection - pasteOrigin.x; + Rectangle rect = pasteImage[0].getBounds(); + pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); + pasteOrigin.x = -hSelection; } }); final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar(); pasteVBar.setEnabled(false); - pasteVBar.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (pasteImage[0] != null) { - int vSelection = pasteVBar.getSelection(); - int destY = -vSelection - pasteOrigin.y; - Rectangle rect = pasteImage[0].getBounds(); - pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); - pasteOrigin.y = -vSelection; - } + pasteVBar.addListener(SWT.Selection, e -> { + if (pasteImage[0] != null) { + int vSelection = pasteVBar.getSelection(); + int destY = -vSelection - pasteOrigin.y; + Rectangle rect = pasteImage[0].getBounds(); + pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); + pasteOrigin.y = -vSelection; } }); - pasteImageCanvas.addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event e) { - if(pasteImage[0] != null) { - GC gc = e.gc; - gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y); - Rectangle rect = pasteImage[0].getBounds(); - Rectangle client = pasteImageCanvas.getClientArea (); - int marginWidth = client.width - rect.width; - if (marginWidth > 0) { - gc.fillRectangle(rect.width, 0, marginWidth, client.height); - } - int marginHeight = client.height - rect.height; - if (marginHeight > 0) { - gc.fillRectangle(0, rect.height, client.width, marginHeight); - } + pasteImageCanvas.addListener(SWT.Paint, e -> { + if(pasteImage[0] != null) { + GC gc = e.gc; + gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y); + Rectangle rect = pasteImage[0].getBounds(); + Rectangle client = pasteImageCanvas.getClientArea (); + int marginWidth = client.width - rect.width; + if (marginWidth > 0) { + gc.fillRectangle(rect.width, 0, marginWidth, client.height); + } + int marginHeight = client.height - rect.height; + if (marginHeight > 0) { + gc.fillRectangle(0, rect.height, client.width, marginHeight); } } }); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java index 578576a846..ac729b7dc3 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 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 @@ -41,9 +41,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.Widget; @@ -179,20 +177,10 @@ class BrowserTab extends Tab { /* Create the extra widgets */ mozillaButton = new Button (styleGroup, SWT.CHECK); mozillaButton.setText ("SWT.MOZILLA"); - mozillaButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - webKitButton.setSelection(false); - } - }); + mozillaButton.addListener(SWT.Selection, event -> webKitButton.setSelection(false)); webKitButton = new Button (styleGroup, SWT.CHECK); webKitButton.setText ("SWT.WEBKIT"); - webKitButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - mozillaButton.setSelection(false); - } - }); + webKitButton.addListener(SWT.Selection, event -> mozillaButton.setSelection(false)); borderButton = new Button (styleGroup, SWT.CHECK); borderButton.setText ("SWT.BORDER"); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java index c4c15d71e9..187369965d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 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 @@ -28,10 +28,8 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.ToolBar; @@ -269,12 +267,7 @@ class CTabFolderTab extends Tab { text.setText(ControlExample.getResourceString("CTabItem_content") + ": " + i); item.setControl(text); } - tabFolder1.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - lastSelectedTab = tabFolder1.getSelectionIndex(); - } - }); + tabFolder1.addListener(SWT.Selection, event -> lastSelectedTab = tabFolder1.getSelectionIndex()); /* If we have saved state, restore it */ tabFolder1.setSelection(lastSelectedTab); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java index 5d87e29e94..bde6ee7b2c 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 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 @@ -25,10 +25,8 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.CoolBar; import org.eclipse.swt.widgets.CoolItem; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Text; @@ -231,12 +229,7 @@ class CoolBarTab extends Tab { } /* Add a listener to resize the group box to match the coolbar */ - coolBar.addListener(SWT.Resize, new Listener() { - @Override - public void handleEvent(Event event) { - exampleGroup.layout(); - } - }); + coolBar.addListener(SWT.Resize, event -> exampleGroup.layout()); } /** diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ShellTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ShellTab.java index bccee6a1fa..866abfd8a1 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ShellTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ShellTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 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,8 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Widget; @@ -113,12 +111,7 @@ class ShellTab extends Tab { Button close = new Button(currentShell, SWT.PUSH); close.setBounds(160, 20, 120, 30); close.setText(ControlExample.getResourceString("Close")); - close.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - currentShell.dispose(); - } - }); + close.addListener(SWT.Selection, event1 -> currentShell.dispose()); /* Set the size, title, and image, and open the shell */ currentShell.setSize (300, 100); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java index 93e91ceade..db83f4d57f 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.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 @@ -798,37 +798,17 @@ abstract class Tab { MenuItem cut = new MenuItem (popup, SWT.PUSH); cut.setText (ControlExample.getResourceString("MenuItem_Cut")); - cut.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - eventConsole.cut (); - } - }); + cut.addListener (SWT.Selection, event -> eventConsole.cut ()); MenuItem copy = new MenuItem (popup, SWT.PUSH); copy.setText (ControlExample.getResourceString("MenuItem_Copy")); - copy.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - eventConsole.copy (); - } - }); + copy.addListener (SWT.Selection, event -> eventConsole.copy ()); MenuItem paste = new MenuItem (popup, SWT.PUSH); paste.setText (ControlExample.getResourceString("MenuItem_Paste")); - paste.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - eventConsole.paste (); - } - }); + paste.addListener (SWT.Selection, event -> eventConsole.paste ()); new MenuItem (popup, SWT.SEPARATOR); MenuItem selectAll = new MenuItem (popup, SWT.PUSH); selectAll.setText(ControlExample.getResourceString("MenuItem_SelectAll")); - selectAll.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - eventConsole.selectAll (); - } - }); + selectAll.addListener (SWT.Selection, event -> eventConsole.selectAll ()); } /** @@ -1383,22 +1363,19 @@ abstract class Tab { void setExampleWidgetPopupMenu() { Control[] controls = getExampleControls(); for (final Control control : controls) { - control.addListener(SWT.MenuDetect, new Listener() { - @Override - public void handleEvent(Event event) { - Menu menu = control.getMenu(); - if (menu != null && samplePopup) { - menu.dispose(); - menu = null; - } - if (menu == null && popupMenuButton.getSelection()) { - menu = new Menu(shell, SWT.POP_UP | (control.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT))); - MenuItem item = new MenuItem(menu, SWT.PUSH); - item.setText("Sample popup menu item"); - specialPopupMenuItems(menu, event); - control.setMenu(menu); - samplePopup = true; - } + control.addListener(SWT.MenuDetect, event -> { + Menu menu = control.getMenu(); + if (menu != null && samplePopup) { + menu.dispose(); + menu = null; + } + if (menu == null && popupMenuButton.getSelection()) { + menu = new Menu(shell, SWT.POP_UP | (control.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT))); + MenuItem item = new MenuItem(menu, SWT.PUSH); + item.setText("Sample popup menu item"); + specialPopupMenuItems(menu, event); + control.setMenu(menu); + samplePopup = true; } }); } @@ -1593,12 +1570,7 @@ abstract class Tab { */ void hookListeners (Widget widget) { if (logging) { - Listener listener = new Listener() { - @Override - public void handleEvent (Event event) { - log (event); - } - }; + Listener listener = event -> log (event); for (int i = 0; i < EVENT_INFO.length; i++) { if (eventsFilter [i]) { widget.addListener (EVENT_INFO[i].type, listener); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AdvancedGraphics.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AdvancedGraphics.java index f20d3295a3..f63bfbb1cd 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AdvancedGraphics.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AdvancedGraphics.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 @@ -31,8 +31,6 @@ import org.eclipse.swt.graphics.Path; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Transform; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; @@ -73,36 +71,30 @@ public class AdvancedGraphics { final Font font = new Font(display, fd.getName(), 96, SWT.BOLD | SWT.ITALIC); final Image image = loadImage(display, AdvancedGraphics.class, "irmaos.jpg"); final Rectangle rect = image.getBounds(); - shell.addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event event) { - GC gc = event.gc; - Transform tr = new Transform(display); - tr.translate(rect.width / 4, rect.height / 2); - tr.rotate(-30); - if (image != null) { - gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width, rect.height); - } - 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 gc = event.gc; + Transform tr = new Transform(display); + tr.translate(rect.width / 4, rect.height / 2); + tr.rotate(-30); + if (image != null) { + gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width, rect.height); + } + gc.setAlpha(100); + gc.setTransform(tr); + Path path = new Path(display); + path.addString("SWT", 0, 0, font); + gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); + gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); + gc.fillPath(path); + gc.drawPath(path); + tr.dispose(); + path.dispose(); }); shell.setSize(shell.computeSize(rect.width, rect.height)); shell.open(); - shell.addListener(SWT.Dispose, new Listener() { - @Override - public void handleEvent(Event event) { - if (image != null) image.dispose(); - font.dispose(); - } + shell.addListener(SWT.Dispose, event -> { + if (image != null) image.dispose(); + font.dispose(); }); return shell; } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AnimatedGraphicsTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AnimatedGraphicsTab.java index 7746efa3eb..00b0469b12 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AnimatedGraphicsTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/AnimatedGraphicsTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 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,7 +16,6 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Spinner; @@ -64,23 +63,20 @@ public abstract class AnimatedGraphicsTab extends GraphicsTab { final Display display = parent.getDisplay(); toolBar = new ToolBar(parent, SWT.FLAT); - Listener toolBarListener = new Listener() { - @Override - public void handleEvent(Event event) { - switch (event.type) { - case SWT.Selection: { - if (event.widget == playItem) { - animate = true; - playItem.setEnabled(!animate); - pauseItem.setEnabled(animate); - } else if (event.widget == pauseItem) { - animate = false; - playItem.setEnabled(!animate); - pauseItem.setEnabled(animate); - } + Listener toolBarListener = event -> { + switch (event.type) { + case SWT.Selection: { + if (event.widget == playItem) { + animate = true; + playItem.setEnabled(!animate); + pauseItem.setEnabled(animate); + } else if (event.widget == pauseItem) { + animate = false; + playItem.setEnabled(!animate); + pauseItem.setEnabled(animate); } - break; } + break; } }; diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CountDownTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CountDownTab.java index 02f387d2e6..c2bdd3be1e 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CountDownTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CountDownTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -68,12 +68,9 @@ public class CountDownTab extends AnimatedGraphicsTab { // add selection listener to reset nextNumber after // the sequence has completed - playItem.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - if (nextNumber < 1) - nextNumber = startNumber; - } + playItem.addListener(SWT.Selection, event -> { + if (nextNumber < 1) + nextNumber = startNumber; }); Composite comp; @@ -88,12 +85,9 @@ public class CountDownTab extends AnimatedGraphicsTab { lineWidthSpinner.setSelection(20); lineWidthSpinner.setMinimum(1); lineWidthSpinner.setMaximum(100); - lineWidthSpinner.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - if (!pauseItem.isEnabled()) { - example.redraw(); - } + lineWidthSpinner.addListener(SWT.Selection, event -> { + if (!pauseItem.isEnabled()) { + example.redraw(); } }); @@ -108,13 +102,10 @@ public class CountDownTab extends AnimatedGraphicsTab { aliasCombo.add("ON"); aliasCombo.select(0); antialias = aliasValues[0]; - aliasCombo.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - antialias = aliasValues[aliasCombo.getSelectionIndex()]; - if (!pauseItem.isEnabled()) { - example.redraw(); - } + aliasCombo.addListener(SWT.Selection, event -> { + antialias = aliasValues[aliasCombo.getSelectionIndex()]; + if (!pauseItem.isEnabled()) { + example.redraw(); } }); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomAlphaTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomAlphaTab.java index d0cca251ec..c93f50ec35 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomAlphaTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomAlphaTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -22,9 +22,7 @@ import org.eclipse.swt.graphics.Transform; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Spinner; @@ -86,12 +84,7 @@ public void createControlPanel(Composite parent) { alphaSpinner.setMinimum(0); alphaSpinner.setMaximum(255); alphaSpinner.setSelection(127); - alphaSpinner.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + alphaSpinner.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); @@ -116,16 +109,13 @@ public void createControlPanel(Composite parent) { colorButton.setText(GraphicsExample .getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(background.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomFontTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomFontTab.java index 7fa47a2b1c..e1df179412 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomFontTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/CustomFontTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -115,12 +115,7 @@ public void createControlPanel(Composite parent) { fontFaceCb.add(name); } fontFaceCb.select(0); - fontFaceCb.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent (Event event) { - example.redraw(); - } - }); + fontFaceCb.addListener(SWT.Selection, event -> example.redraw()); // create combo for font style comp = new Composite(mainComp, SWT.NONE); @@ -132,12 +127,7 @@ public void createControlPanel(Composite parent) { fontStyleCb.add(fontStyle); } fontStyleCb.select(0); - fontStyleCb.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent (Event event) { - example.redraw(); - } - }); + fontStyleCb.addListener(SWT.Selection, event -> example.redraw()); // create spinner for font size (points) comp = new Composite(mainComp, SWT.NONE); @@ -148,12 +138,7 @@ public void createControlPanel(Composite parent) { fontPointSpinner.setMinimum(1); fontPointSpinner.setMaximum(1000); fontPointSpinner.setSelection(200); - fontPointSpinner.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + fontPointSpinner.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setColorItems(true); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java index e1ced08eaa..c339151d1d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -81,17 +81,14 @@ public class GradientDialog extends Dialog { // create the controls in the dialog createDialogControls(dialog); - dialog.addListener(SWT.Close, new Listener() { - @Override - public void handleEvent(Event event) { - for (int i = 0; i < resources.size(); i++) { - Object obj = resources.get(i); - if (obj != null && obj instanceof Resource) { - ((Resource) obj).dispose(); - } + dialog.addListener(SWT.Close, event -> { + for (int i = 0; i < resources.size(); i++) { + Object obj = resources.get(i); + if (obj != null && obj instanceof Resource) { + ((Resource) obj).dispose(); } - dialog.dispose(); } + dialog.dispose(); }); dialog.setDefaultButton (okButton); @@ -146,21 +143,18 @@ public class GradientDialog extends Dialog { gridData.widthHint = 200; gridData.heightHint = 100; canvas.setLayoutData(gridData); - canvas.addListener (SWT.Paint, new Listener () { - @Override - public void handleEvent (Event e) { - Image preview = null; - Point size = canvas.getSize(); - Color color1 = new Color(display, rgb1); - Color color2 = new Color(display, rgb2); - preview = GraphicsExample.createImage(display, color1, color2, size.x, size.y); - if (preview != null) { - e.gc.drawImage (preview, 0, 0); - } - preview.dispose(); - color1.dispose(); - color2.dispose(); + canvas.addListener (SWT.Paint, e -> { + Image preview = null; + Point size = canvas.getSize(); + Color color1 = new Color(display, rgb1); + Color color2 = new Color(display, rgb2); + preview = GraphicsExample.createImage(display, color1, color2, size.x, size.y); + if (preview != null) { + e.gc.drawImage (preview, 0, 0); } + preview.dispose(); + color1.dispose(); + color2.dispose(); }); // composite used for both color buttons @@ -222,16 +216,13 @@ public class GradientDialog extends Dialog { if (canvas != null) canvas.redraw(); } }); - colorButton2.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu2.setLocation(point.x, point.y + bounds.height); - menu2.setVisible(true); - } + colorButton2.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu2.setLocation(point.x, point.y + bounds.height); + menu2.setVisible(true); }); // composite used for ok and cancel buttons @@ -251,23 +242,15 @@ public class GradientDialog extends Dialog { // OK button okButton = new Button (okCancelComp, SWT.PUSH); okButton.setText("&OK"); - okButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - returnVal = SWT.OK; - parent.close(); - } + okButton.addListener(SWT.Selection, event -> { + returnVal = SWT.OK; + parent.close(); }); // cancel button cancelButton = new Button (okCancelComp, SWT.PUSH); cancelButton.setText("&Cancel"); - cancelButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - parent.close(); - } - }); + cancelButton.addListener(SWT.Selection, event -> parent.close()); } /** diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientTab.java index 0e9425368a..e97298d61d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GradientTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -22,8 +22,6 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; @@ -101,16 +99,13 @@ public void createControlPanel(final Composite parent) { colorItem1 = new ToolItem(toolBar, SWT.PUSH); colorItem1.setText(GraphicsExample.getResourceString("GradientTabItem1")); colorItem1.setImage(colorGB1.getThumbNail()); - colorItem1.addListener(SWT.Selection, new Listener(){ - @Override - public void handleEvent(Event event) { - final ToolItem toolItem = (ToolItem) event.widget; - final ToolBar toolBar = toolItem.getParent(); - Rectangle toolItemBounds = toolItem.getBounds(); - Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); - menu1.setLocation(point.x, point.y + toolItemBounds.height); - menu1.setVisible(true); - } + colorItem1.addListener(SWT.Selection, event -> { + final ToolItem toolItem = (ToolItem) event.widget; + final ToolBar toolBar = toolItem.getParent(); + Rectangle toolItemBounds = toolItem.getBounds(); + Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); + menu1.setLocation(point.x, point.y + toolItemBounds.height); + menu1.setVisible(true); }); // menu for colorItem2 @@ -130,32 +125,26 @@ public void createControlPanel(final Composite parent) { colorItem2 = new ToolItem(toolBar, SWT.PUSH); colorItem2.setText(GraphicsExample.getResourceString("GradientTabItem2")); colorItem2.setImage(colorGB2.getThumbNail()); - colorItem2.addListener(SWT.Selection, new Listener(){ - @Override - public void handleEvent(Event event) { - final ToolItem toolItem = (ToolItem) event.widget; - final ToolBar toolBar = toolItem.getParent(); - Rectangle toolItemBounds = toolItem.getBounds(); - Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); - menu2.setLocation(point.x, point.y + toolItemBounds.height); - menu2.setVisible(true); - } + colorItem2.addListener(SWT.Selection, event -> { + final ToolItem toolItem = (ToolItem) event.widget; + final ToolBar toolBar = toolItem.getParent(); + Rectangle toolItemBounds = toolItem.getBounds(); + Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); + menu2.setLocation(point.x, point.y + toolItemBounds.height); + menu2.setVisible(true); }); // toolbar item for swapping colors ToolItem swapItem = new ToolItem(toolBar, SWT.PUSH); swapItem.setText(GraphicsExample.getResourceString("SwapColors")); //$NON-NLS-1$ swapItem.setImage(example.loadImage(display, "swap.gif")); - swapItem.addListener(SWT.Selection, new Listener(){ - @Override - public void handleEvent(Event event) { - GraphicsBackground tmp = colorGB1; - colorGB1 = colorGB2; - colorGB2 = tmp; - colorItem1.setImage(colorGB1.getThumbNail()); - colorItem2.setImage(colorGB2.getThumbNail()); - example.redraw(); - } + swapItem.addListener(SWT.Selection, event -> { + GraphicsBackground tmp = colorGB1; + colorGB1 = colorGB2; + colorGB2 = tmp; + colorItem1.setImage(colorGB1.getThumbNail()); + colorItem2.setImage(colorGB2.getThumbNail()); + example.redraw(); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicAntialiasTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicAntialiasTab.java index aedb82013a..e592eb500b 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicAntialiasTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicAntialiasTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -21,9 +21,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; /** @@ -83,12 +81,7 @@ public void createControlPanel(Composite parent) { aliasCombo.add("DEFAULT"); aliasCombo.add("ON"); aliasCombo.select(0); - aliasCombo.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + aliasCombo.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setColorItems(true); @@ -112,16 +105,13 @@ public void createControlPanel(Composite parent) { colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(ovalColorGB.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.java index 91499e0a9e..088dc0262d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.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 @@ -177,31 +177,25 @@ void createControls(final Composite parent) { data.bottom = new FormAttachment(100, -MARGIN); tabControlPanel.setLayoutData(data); - vSash.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - Rectangle rect = hSash.getParent().getClientArea(); - event.x = Math.min (Math.max (event.x, 60), rect.width - 60); - if (event.detail != SWT.DRAG) { - FormData data = (FormData)vSash.getLayoutData(); - data.left.offset = event.x; - vSash.requestLayout(); - animate = true; - } else { - animate = false; - } + vSash.addListener(SWT.Selection, event -> { + Rectangle rect = hSash.getParent().getClientArea(); + event.x = Math.min (Math.max (event.x, 60), rect.width - 60); + if (event.detail != SWT.DRAG) { + FormData data1 = (FormData)vSash.getLayoutData(); + data1.left.offset = event.x; + vSash.requestLayout(); + animate = true; + } else { + animate = false; } }); - hSash.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - Rectangle rect = vSash.getParent().getClientArea(); - event.y = Math.min (Math.max (event.y, tabList.getLocation().y + 60), rect.height - 60); - if (event.detail != SWT.DRAG) { - FormData data = (FormData)hSash.getLayoutData(); - data.top.offset = event.y; - hSash.requestLayout(); - } + hSash.addListener (SWT.Selection, event -> { + Rectangle rect = vSash.getParent().getClientArea(); + event.y = Math.min (Math.max (event.y, tabList.getLocation().y + 60), rect.height - 60); + if (event.detail != SWT.DRAG) { + FormData data1 = (FormData)hSash.getLayoutData(); + data1.top.offset = event.y; + hSash.requestLayout(); } }); } @@ -210,32 +204,29 @@ void createCanvas(Composite parent) { int style = SWT.NO_BACKGROUND; if (dbItem.getSelection()) style |= SWT.DOUBLE_BUFFERED; canvas = new Canvas(parent, style); - canvas.addListener(SWT.Paint, new Listener() { - @Override - public void handleEvent(Event event) { - GC gc = event.gc; - Rectangle rect = canvas.getClientArea(); - Device device = gc.getDevice(); - Pattern pattern = null; - if (background.getBgColor1() != null) { - if (background.getBgColor2() != null) { // gradient - pattern = new Pattern(device, 0, 0, rect.width, - rect.height, - background.getBgColor1(), - background.getBgColor2()); - gc.setBackgroundPattern(pattern); - } else { // solid color - gc.setBackground(background.getBgColor1()); - } - } else if (background.getBgImage() != null) { // image - pattern = new Pattern(device, background.getBgImage()); + canvas.addListener(SWT.Paint, event -> { + GC gc = event.gc; + Rectangle rect = canvas.getClientArea(); + Device device = gc.getDevice(); + Pattern pattern = null; + if (background.getBgColor1() != null) { + if (background.getBgColor2() != null) { // gradient + pattern = new Pattern(device, 0, 0, rect.width, + rect.height, + background.getBgColor1(), + background.getBgColor2()); gc.setBackgroundPattern(pattern); + } else { // solid color + gc.setBackground(background.getBgColor1()); } - gc.fillRectangle(rect); - GraphicsTab tab = getTab(); - if (tab != null) tab.paint(gc, rect.width, rect.height); - if (pattern != null) pattern.dispose(); + } else if (background.getBgImage() != null) { // image + pattern = new Pattern(device, background.getBgImage()); + gc.setBackgroundPattern(pattern); } + gc.fillRectangle(rect); + GraphicsTab tab = getTab(); + if (tab != null) tab.paint(gc, rect.width, rect.height); + if (pattern != null) pattern.dispose(); }); } @@ -268,25 +259,19 @@ void createToolBar(final Composite parent) { back.setText(getResourceString("Back")); //$NON-NLS-1$ back.setImage(loadImage(display, "back.gif")); //$NON-NLS-1$ - back.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - int index = tabs_in_order.indexOf(tab) - 1; - if (index < 0) - index = tabs_in_order.size() - 1; - setTab(tabs_in_order.get(index)); - } + back.addListener(SWT.Selection, event -> { + int index = tabs_in_order.indexOf(tab) - 1; + if (index < 0) + index = tabs_in_order.size() - 1; + setTab(tabs_in_order.get(index)); }); ToolItem next = new ToolItem(toolBar, SWT.PUSH); next.setText(getResourceString("Next")); //$NON-NLS-1$ next.setImage(loadImage(display, "next.gif")); //$NON-NLS-1$ - next.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - int index = (tabs_in_order.indexOf(tab) + 1)%tabs_in_order.size(); - setTab(tabs_in_order.get(index)); - } + next.addListener(SWT.Selection, event -> { + int index = (tabs_in_order.indexOf(tab) + 1)%tabs_in_order.size(); + setTab(tabs_in_order.get(index)); }); ColorMenu colorMenu = new ColorMenu(); @@ -439,15 +424,12 @@ void createTabList(Composite parent) { } } } - tabList.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - TreeItem item = (TreeItem)event.item; - if (item != null) { - GraphicsTab gt = (GraphicsTab)item.getData(); - if (gt == tab) return; - setTab((GraphicsTab)item.getData()); - } + tabList.addListener(SWT.Selection, event -> { + TreeItem item = (TreeItem)event.item; + if (item != null) { + GraphicsTab gt = (GraphicsTab)item.getData(); + if (gt == tab) return; + setTab((GraphicsTab)item.getData()); } }); } @@ -581,12 +563,7 @@ public Shell open(final Display display) { Shell shell = new Shell(display); shell.setText(getResourceString("GraphicsExample")); //$NON-NLS-1$ final GraphicsExample example = new GraphicsExample(shell); - shell.addListener(SWT.Close, new Listener() { - @Override - public void handleEvent(Event event) { - example.dispose(); - } - }); + shell.addListener(SWT.Close, event -> example.dispose()); shell.open(); return shell; } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java index ce977a1f4b..46031d3c8f 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -21,9 +21,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Spinner; /** @@ -85,12 +83,7 @@ public void createControlPanel(Composite parent) { rotateSpinner.setMinimum(-720); rotateSpinner.setMaximum(720); rotateSpinner.setIncrement(30); - rotateSpinner.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + rotateSpinner.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for translating along the x axis comp = new Composite(parent, SWT.NONE); @@ -103,12 +96,7 @@ public void createControlPanel(Composite parent) { translateSpinnerX.setMaximum(500); translateSpinnerX.setSelection(0); translateSpinnerX.setIncrement(10); - translateSpinnerX.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + translateSpinnerX.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for translating along the y axis comp = new Composite(parent, SWT.NONE); @@ -121,12 +109,7 @@ public void createControlPanel(Composite parent) { translateSpinnerY.setMaximum(500); translateSpinnerY.setSelection(0); translateSpinnerY.setIncrement(10); - translateSpinnerY.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + translateSpinnerY.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for scaling along the x axis comp = new Composite(parent, SWT.NONE); @@ -140,12 +123,7 @@ public void createControlPanel(Composite parent) { scaleSpinnerX.setMaximum(400); scaleSpinnerX.setSelection(100); scaleSpinnerX.setIncrement(10); - scaleSpinnerX.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + scaleSpinnerX.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for scaling along the y axis comp = new Composite(parent, SWT.NONE); @@ -159,24 +137,14 @@ public void createControlPanel(Composite parent) { scaleSpinnerY.setMaximum(400); scaleSpinnerY.setSelection(100); scaleSpinnerY.setIncrement(10); - scaleSpinnerY.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + scaleSpinnerY.addListener(SWT.Selection, event -> example.redraw()); // create a button for inverting the transform matrix comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); invertButton = new Button(comp, SWT.TOGGLE); invertButton.setText(GraphicsExample.getResourceString("Invert")); //$NON-NLS-1$ - invertButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + invertButton.addListener(SWT.Selection, event -> example.redraw()); } /* (non-Javadoc) diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/InterpolationTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/InterpolationTab.java index f756e1c8fa..805b9a36c4 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/InterpolationTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/InterpolationTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -22,9 +22,7 @@ import org.eclipse.swt.graphics.Transform; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; /** * This tab shows the effects of applying various interpolation algorithms to @@ -73,12 +71,7 @@ public void createControlPanel(Composite parent) { imageCb.add(GraphicsExample.getResourceString("SWT")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Ovals")); //$NON-NLS-1$ imageCb.select(0); - imageCb.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + imageCb.addListener(SWT.Selection, event -> example.redraw()); } @Override diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineCapTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineCapTab.java index 4f64d08011..af45d23433 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineCapTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineCapTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -21,8 +21,6 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; /** @@ -89,16 +87,13 @@ public void createControlPanel(Composite parent) { colorButton.setText(GraphicsExample .getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(foreground.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineJoinTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineJoinTab.java index e7f2aa56f3..d1f8cd1b02 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineJoinTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineJoinTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -22,9 +22,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; /** @@ -83,12 +81,7 @@ public void createControlPanel(Composite parent) { joinCb.add(GraphicsExample .getResourceString("round")); //$NON-NLS-1$ joinCb.select(1); - joinCb.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + joinCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); @@ -113,16 +106,13 @@ public void createControlPanel(Composite parent) { colorButton.setText(GraphicsExample .getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(shapeColor.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineStyleTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineStyleTab.java index 712d6b62bc..2314589692 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineStyleTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/LineStyleTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -21,9 +21,7 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Spinner; @@ -79,12 +77,7 @@ public void createControlPanel(Composite parent) { lineWidthSpinner.setSelection(10); lineWidthSpinner.setMinimum(1); lineWidthSpinner.setMaximum(30); - lineWidthSpinner.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + lineWidthSpinner.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); @@ -109,16 +102,13 @@ public void createControlPanel(Composite parent) { colorButton.setText(GraphicsExample .getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(lineColor.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/MazeTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/MazeTab.java index c6e8fed311..6cac112063 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/MazeTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/MazeTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -20,8 +20,6 @@ import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; /** * This tab shows three circles, each following a different path in a maze. @@ -136,13 +134,10 @@ public void createControlPanel(Composite parent) { // add selection listener to reset nextNumber after // the sequence has completed - playItem.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - if (isDone){ - nextIndex = nextIndex2 = nextIndex3 = 0; - isDone = isDone2 = isDone3 = false; - } + playItem.addListener(SWT.Selection, event -> { + if (isDone){ + nextIndex = nextIndex2 = nextIndex3 = 0; + isDone = isDone2 = isDone3 = false; } }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingAnimTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingAnimTab.java index 9563df100d..cb9670f8d6 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingAnimTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingAnimTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -21,8 +21,6 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; /** @@ -96,16 +94,13 @@ public class PathClippingAnimTab extends AnimatedGraphicsTab { colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(background.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingTab.java index 4c9a7f40b0..15c4458f99 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathClippingTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -23,9 +23,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; /** @@ -87,12 +85,7 @@ public void createControlPanel(Composite parent) { clippingCb.add(GraphicsExample.getResourceString("Triangles")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Default")); //$NON-NLS-1$ clippingCb.select(0); - clippingCb.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + clippingCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); @@ -117,16 +110,13 @@ public void createControlPanel(Composite parent) { colorButton.setText(GraphicsExample .getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(background.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } @Override diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathTab.java index cc6bc29122..3ce8f002d4 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/PathTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -74,12 +74,7 @@ public void createControlPanel(Composite parent) { drawButton = new Button(comp, SWT.TOGGLE); drawButton.setText(GraphicsExample.getResourceString("DrawPath")); //$NON-NLS-1$ - drawButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + drawButton.addListener(SWT.Selection, event -> example.redraw()); drawButton.setSelection(true); // create fill button @@ -88,12 +83,7 @@ public void createControlPanel(Composite parent) { fillButton = new Button(comp, SWT.TOGGLE); fillButton.setText(GraphicsExample.getResourceString("FillPath")); //$NON-NLS-1$ - fillButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + fillButton.addListener(SWT.Selection, event -> example.redraw()); // create close button comp = new Composite(parent, SWT.NONE); @@ -101,12 +91,7 @@ public void createControlPanel(Composite parent) { closeButton = new Button(comp, SWT.TOGGLE); closeButton.setText(GraphicsExample.getResourceString("ClosePath")); //$NON-NLS-1$ - closeButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + closeButton.addListener(SWT.Selection, event -> example.redraw()); // create color button comp = new Composite(parent, SWT.NONE); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/RegionClippingTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/RegionClippingTab.java index 345a983614..1e8a3dd766 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/RegionClippingTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/RegionClippingTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -21,9 +21,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; /** @@ -86,12 +84,7 @@ public void createControlPanel(Composite parent) { clippingCb.add(GraphicsExample.getResourceString("Sub")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Inter")); //$NON-NLS-1$ clippingCb.select(0); - clippingCb.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + clippingCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); @@ -125,16 +118,13 @@ public void createControlPanel(Composite parent) { colorButton1.setText(GraphicsExample .getResourceString("Color1")); //$NON-NLS-1$ colorButton1.setImage(colorGB1.getThumbNail()); - colorButton1.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu1.setLocation(point.x, point.y + bounds.height); - menu1.setVisible(true); - } + colorButton1.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu1.setLocation(point.x, point.y + bounds.height); + menu1.setVisible(true); }); // color button 2 @@ -145,16 +135,13 @@ public void createControlPanel(Composite parent) { colorButton2.setText(GraphicsExample .getResourceString("Color2")); //$NON-NLS-1$ colorButton2.setImage(colorGB2.getThumbNail()); - colorButton2.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu2.setLocation(point.x, point.y + bounds.height); - menu2.setVisible(true); - } + colorButton2.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu2.setLocation(point.x, point.y + bounds.height); + menu2.setVisible(true); }); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/SpiralTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/SpiralTab.java index ce319ef667..484c2f148d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/SpiralTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/SpiralTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -71,12 +71,7 @@ public void createControlPanel(Composite parent) { petalSpinner.setSelection(8); petalSpinner.setMinimum(3); petalSpinner.setMaximum(20); - petalSpinner.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent (Event event) { - example.redraw(); - } - }); + petalSpinner.addListener(SWT.Selection, event -> example.redraw()); // create color button comp = new Composite(parent, SWT.NONE); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/StarPolyTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/StarPolyTab.java index b8af4caa71..829ab5499f 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/StarPolyTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/StarPolyTab.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 @@ -14,9 +14,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; public class StarPolyTab extends GraphicsTab { int[] radial; @@ -36,12 +34,7 @@ public void createControlPanel(Composite parent) { fillRuleCb.add("FILL_EVEN_ODD"); fillRuleCb.add("FILL_WINDING"); fillRuleCb.select(0); - fillRuleCb.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent (Event event) { - example.redraw(); - } - }); + fillRuleCb.addListener(SWT.Selection, event -> example.redraw()); } @Override diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/TextAntialiasTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/TextAntialiasTab.java index e58b0f1037..8eb9e7f39d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/TextAntialiasTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/TextAntialiasTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -21,9 +21,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; /** @@ -84,12 +82,7 @@ public void createControlPanel(Composite parent) { aliasCombo.add("DEFAULT"); aliasCombo.add("ON"); aliasCombo.select(0); - aliasCombo.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - example.redraw(); - } - }); + aliasCombo.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setColorItems(true); @@ -113,22 +106,16 @@ public void createControlPanel(Composite parent) { colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(textColor.getThumbNail()); - colorButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - final Button button = (Button) event.widget; - final Composite parent = button.getParent(); - Rectangle bounds = button.getBounds(); - Point point = parent.toDisplay(new Point(bounds.x, bounds.y)); - menu.setLocation(point.x, point.y + bounds.height); - menu.setVisible(true); - } + colorButton.addListener(SWT.Selection, event -> { + final Button button = (Button) event.widget; + final Composite parent1 = button.getParent(); + Rectangle bounds = button.getBounds(); + Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); + menu.setLocation(point.x, point.y + bounds.height); + menu.setVisible(true); }); } -/* (non-Javadoc) - * @see org.eclipse.swt.examples.graphics.GraphicsTab#paint(org.eclipse.swt.graphics.GC, int, int) - */ @Override public void paint(GC gc, int width, int height) { if (!example.checkAdvancedGraphics()) return; diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.java index d038417814..09bdcc37cc 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintExample.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 @@ -289,20 +289,17 @@ public class PaintExample { return paintColors[Math.min(Math.max(row * numPaletteCols + col, 0), paintColors.length - 1)]; } }); - Listener refreshListener = new Listener() { - @Override - public void handleEvent(Event e) { - if (e.gc == null) return; - Rectangle bounds = paletteCanvas.getClientArea(); - for (int row = 0; row < numPaletteRows; ++row) { - for (int col = 0; col < numPaletteCols; ++col) { - final int x = bounds.width * col / numPaletteCols; - final int y = bounds.height * row / numPaletteRows; - final int width = Math.max(bounds.width * (col + 1) / numPaletteCols - x, 1); - final int height = Math.max(bounds.height * (row + 1) / numPaletteRows - y, 1); - e.gc.setBackground(paintColors[row * numPaletteCols + col]); - e.gc.fillRectangle(bounds.x + x, bounds.y + y, width, height); - } + Listener refreshListener = e -> { + if (e.gc == null) return; + Rectangle bounds = paletteCanvas.getClientArea(); + for (int row = 0; row < numPaletteRows; ++row) { + for (int col = 0; col < numPaletteCols; ++col) { + final int x = bounds.width * col / numPaletteCols; + final int y = bounds.height * row / numPaletteRows; + final int width = Math.max(bounds.width * (col + 1) / numPaletteCols - x, 1); + final int height = Math.max(bounds.height * (row + 1) / numPaletteRows - y, 1); + e.gc.setBackground(paintColors[row * numPaletteCols + col]); + e.gc.fillRectangle(bounds.x + x, bounds.y + y, width, height); } } }; diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java index c23a89f64f..c9c7d1cffe 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2000, 2008 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 @@ -566,39 +566,19 @@ public class TextEditor { final MenuItem cutItem = new MenuItem (menu, SWT.PUSH); cutItem.setText (getResourceString("Cut_menuitem")); //$NON-NLS-1$ cutItem.setImage(iCut); - cutItem.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - styledText.cut(); - } - }); + cutItem.addListener (SWT.Selection, event -> styledText.cut()); final MenuItem copyItem = new MenuItem (menu, SWT.PUSH); copyItem.setText (getResourceString("Copy_menuitem")); //$NON-NLS-1$ copyItem.setImage(iCopy); - copyItem.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - styledText.copy(); - } - }); + copyItem.addListener (SWT.Selection, event -> styledText.copy()); final MenuItem pasteItem = new MenuItem (menu, SWT.PUSH); pasteItem.setText (getResourceString("Paste_menuitem")); //$NON-NLS-1$ pasteItem.setImage(iPaste); - pasteItem.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - styledText.paste(); - } - }); + pasteItem.addListener (SWT.Selection, event -> styledText.paste()); new MenuItem (menu, SWT.SEPARATOR); final MenuItem selectAllItem = new MenuItem (menu, SWT.PUSH); selectAllItem.setText (getResourceString("SelectAll_menuitem")); //$NON-NLS-1$ - selectAllItem.addListener (SWT.Selection, new Listener () { - @Override - public void handleEvent (Event event) { - styledText.selectAll(); - } - }); + selectAllItem.addListener (SWT.Selection, event -> styledText.selectAll()); menu.addMenuListener(new MenuAdapter() { @Override public void menuShown(MenuEvent event) { @@ -1325,18 +1305,8 @@ public class TextEditor { updateToolBar(); } }); - styledText.addListener(SWT.MouseUp, new Listener() { - @Override - public void handleEvent(Event event) { - handleMouseUp(event); - } - }); - styledText.addListener(SWT.KeyDown, new Listener() { - @Override - public void handleEvent(Event event) { - handleKeyDown(event); - } - }); + styledText.addListener(SWT.MouseUp, event -> handleMouseUp(event)); + styledText.addListener(SWT.KeyDown, event -> handleKeyDown(event)); styledText.addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent event) { @@ -1355,16 +1325,13 @@ public class TextEditor { handlePaintObject(event); } }); - styledText.addListener(SWT.Dispose, new Listener() { - @Override - public void handleEvent(Event event) { - StyleRange[] styles = styledText.getStyleRanges(0, styledText.getCharCount(), false); - for (int i = 0; i < styles.length; i++) { - Object data = styles[i].data; - if (data != null) { - if (data instanceof Image) ((Image)data).dispose(); - if (data instanceof Control) ((Control)data).dispose(); - } + styledText.addListener(SWT.Dispose, event -> { + StyleRange[] styles = styledText.getStyleRanges(0, styledText.getCharCount(), false); + for (int i = 0; i < styles.length; i++) { + Object data = styles[i].data; + if (data != null) { + if (data instanceof Image) ((Image)data).dispose(); + if (data instanceof Control) ((Control)data).dispose(); } } }); @@ -1540,15 +1507,12 @@ public class TextEditor { okButton.setText(getResourceString("Ok")); //$NON-NLS-1$ final Button cancelButton = new Button(dialog, SWT.PUSH); cancelButton.setText(getResourceString("Cancel")); //$NON-NLS-1$ - Listener listener = new Listener() { - @Override - public void handleEvent(Event event) { - if (event.widget == okButton) { - link = text.getText(); - setStyle(UNDERLINE_LINK); - } - dialog.dispose(); + Listener listener = event -> { + if (event.widget == okButton) { + link = text.getText(); + setStyle(UNDERLINE_LINK); } + dialog.dispose(); }; okButton.addListener(SWT.Selection, listener); cancelButton.addListener(SWT.Selection, listener); |