Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-10 03:15:50 -0400
committerAlexander Kurtakov2017-08-10 03:15:50 -0400
commita6ea6a1498989e3e2c7bef97b2099bb1ee718619 (patch)
tree579fc82629cd0d6a12bdb9f1d662fc3ba7aad31c /examples
parentfe4627a9d6e65c5ba9046b8ea50e9aacd64eb7a3 (diff)
downloadeclipse.platform.swt-a6ea6a1498989e3e2c7bef97b2099bb1ee718619.tar.gz
eclipse.platform.swt-a6ea6a1498989e3e2c7bef97b2099bb1ee718619.tar.xz
eclipse.platform.swt-a6ea6a1498989e3e2c7bef97b2099bb1ee718619.zip
Bug 512342 - [api] Provide helper methods to use lambda expressions for
ControlListener Use the new helper methods through out the swt codebase. Change-Id: Ide620b5e33829fd7aaa772f78427aa0e69bca094 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java10
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java26
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ComboTab.java23
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashTab.java27
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SpinnerTab.java23
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/StyledTextTab.java12
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TextTab.java23
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ToolTipTab.java12
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/helloworld/HelloWorld3.java19
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java9
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java12
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java16
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java13
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java11
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java59
15 files changed, 120 insertions, 175 deletions
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 2f90c64ee2..f30c836431 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
@@ -27,8 +27,7 @@ import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.browser.VisibilityWindowListener;
import org.eclipse.swt.browser.WindowEvent;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -188,12 +187,7 @@ class BrowserTab extends Tab {
* its preferred size, and then resizes the shell, we
* recalculate the preferred size correctly.
*/
- tabFolderPage.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- setExampleWidgetSize ();
- }
- });
+ tabFolderPage.addControlListener(ControlListener.controlResizedAdapter(e-> setExampleWidgetSize ()));
/*
* Add a selection listener to the tabFolder to bring up a
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java
index e5efc996e5..a2407f12f5 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and 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,8 +14,7 @@ package org.eclipse.swt.examples.controlexample;
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
@@ -136,14 +135,12 @@ class CanvasTab extends Tab {
Point extent = gc.textExtent(canvasString);
gc.drawString(canvasString, cx + (size.x - extent.x) / 2, cy - extent.y + (size.y - 10) / 2, true);
});
- canvas.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent event) {
- Point size = canvas.getSize ();
- maxX = size.x * 3 / 2; maxY = size.y * 3 / 2;
- resizeScrollBars ();
- }
- });
+ canvas.addControlListener(ControlListener.controlResizedAdapter(e -> {
+ Point size = canvas.getSize();
+ maxX = size.x * 3 / 2;
+ maxY = size.y * 3 / 2;
+ resizeScrollBars();
+ }));
ScrollBar bar = canvas.getHorizontalBar();
if (bar != null) {
hookListeners (bar);
@@ -200,12 +197,7 @@ class CanvasTab extends Tab {
* its preferred size, and then resizes the shell, we
* recalculate the preferred size correctly.
*/
- tabFolderPage.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- setExampleWidgetSize ();
- }
- });
+ tabFolderPage.addControlListener(ControlListener.controlResizedAdapter(e -> setExampleWidgetSize ()));
return tabFolderPage;
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ComboTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ComboTab.java
index 9b71ffbb21..6c86e52b34 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ComboTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ComboTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,10 +11,16 @@
package org.eclipse.swt.examples.controlexample;
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.layout.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.layout.GridData;
+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.Group;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.Widget;
class ComboTab extends Tab {
@@ -92,12 +98,7 @@ class ComboTab extends Tab {
* its preferred size, and then resizes the shell, we
* recalculate the preferred size correctly.
*/
- tabFolderPage.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- setExampleWidgetSize ();
- }
- });
+ tabFolderPage.addControlListener(ControlListener.controlResizedAdapter(e -> setExampleWidgetSize ()));
return tabFolderPage;
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashTab.java
index 1ddaf306d6..465136130f 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,14 +10,20 @@
*******************************************************************************/
package org.eclipse.swt.examples.controlexample;
-
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.events.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Sash;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
class SashTab extends Tab {
/* Example widgets and groups that contain them */
@@ -117,12 +123,7 @@ class SashTab extends Tab {
layout ();
}
}));
- sashComp.addControlListener (new ControlAdapter () {
- @Override
- public void controlResized (ControlEvent event) {
- resized ();
- }
- });
+ sashComp.addControlListener (ControlListener.controlResizedAdapter(e -> resized ()));
}
/**
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SpinnerTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SpinnerTab.java
index 3d457bb36f..445ee6f9dc 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SpinnerTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SpinnerTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,10 +13,16 @@ package org.eclipse.swt.examples.controlexample;
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.layout.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlListener;
+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.Group;
+import org.eclipse.swt.widgets.Spinner;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.Widget;
class SpinnerTab extends RangeTab {
@@ -166,12 +172,7 @@ class SpinnerTab extends RangeTab {
* its preferred size, and then resizes the shell, we
* recalculate the preferred size correctly.
*/
- tabFolderPage.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- setExampleWidgetSize ();
- }
- });
+ tabFolderPage.addControlListener(ControlListener.controlResizedAdapter(e -> setExampleWidgetSize ()));
return tabFolderPage;
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/StyledTextTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/StyledTextTab.java
index 673f773e2c..a5ddef0493 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/StyledTextTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/StyledTextTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,8 +24,7 @@ import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.TextChangeListener;
import org.eclipse.swt.custom.TextChangedEvent;
import org.eclipse.swt.custom.TextChangingEvent;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
@@ -296,12 +295,7 @@ class StyledTextTab extends ScrollableTab {
* its preferred size, and then resizes the shell, we
* recalculate the preferred size correctly.
*/
- tabFolderPage.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- setExampleWidgetSize ();
- }
- });
+ tabFolderPage.addControlListener(ControlListener.controlResizedAdapter(e -> setExampleWidgetSize ()));
return tabFolderPage;
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TextTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TextTab.java
index f2ce80320e..7079618eef 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TextTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/TextTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,10 +11,16 @@
package org.eclipse.swt.examples.controlexample;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlListener;
+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.Group;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
class TextTab extends ScrollableTab {
/* Example widgets and groups that contain them */
@@ -124,12 +130,7 @@ class TextTab extends ScrollableTab {
* its preferred size, and then resizes the shell, we
* recalculate the preferred size correctly.
*/
- tabFolderPage.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- setExampleWidgetSize ();
- }
- });
+ tabFolderPage.addControlListener(ControlListener.controlResizedAdapter(e -> setExampleWidgetSize ()));
return tabFolderPage;
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ToolTipTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ToolTipTab.java
index a25256703c..71306d0ba4 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ToolTipTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ToolTipTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and 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,8 +14,7 @@ package org.eclipse.swt.examples.controlexample;
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -101,12 +100,7 @@ class ToolTipTab extends Tab {
* its preferred size, and then resizes the shell, we
* recalculate the preferred size correctly.
*/
- tabFolderPage.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- setExampleWidgetSize ();
- }
- });
+ tabFolderPage.addControlListener(ControlListener.controlResizedAdapter(e -> setExampleWidgetSize ()));
return tabFolderPage;
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/helloworld/HelloWorld3.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/helloworld/HelloWorld3.java
index 9ceea4f7dc..5e3803b4d2 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/helloworld/HelloWorld3.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/helloworld/HelloWorld3.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,12 +10,14 @@
*******************************************************************************/
package org.eclipse.swt.examples.helloworld;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.events.*;
import java.util.ResourceBundle;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
/*
* This example builds on HelloWorld2 and demonstrates how to resize the
* Label when the Shell resizes using a Listener mechanism.
@@ -37,12 +39,7 @@ public Shell open (Display display) {
final Label label = new Label (shell, SWT.CENTER);
label.setText (resHello.getString("Hello_world"));
label.pack();
- shell.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- label.setBounds (shell.getClientArea ());
- }
- });
+ shell.addControlListener(ControlListener.controlResizedAdapter(e -> label.setBounds (shell.getClientArea ())));
shell.pack();
shell.open ();
return shell;
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
index 3a595c8286..7feb5d6f13 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
@@ -24,8 +24,8 @@ import org.eclipse.swt.SWTError;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseListener;
@@ -203,12 +203,7 @@ public class ImageAnalyzer {
shell.setText(bundle.getString("Image_analyzer"));
// Hook resize and dispose listeners.
- shell.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent event) {
- resizeShell(event);
- }
- });
+ shell.addControlListener(ControlListener.controlResizedAdapter(e-> resizeShell(e)));
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java
index 3cdb40d3aa..64efa8f7ad 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,8 +12,7 @@ package org.eclipse.swt.examples.paint;
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
@@ -157,12 +156,7 @@ public class PaintSurface {
event.x, event.y, event.width, event.height);
}
});
- paintCanvas.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent event) {
- handleResize();
- }
- });
+ paintCanvas.addControlListener(ControlListener.controlResizedAdapter(e -> handleResize()));
/* Set up the paint canvas scroll bars */
ScrollBar horizontal = paintCanvas.getHorizontalBar();
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 40346b6fdf..1a7b25e15d 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
@@ -29,8 +29,8 @@ import org.eclipse.swt.custom.PaintObjectEvent;
import org.eclipse.swt.custom.ST;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.ModifyEvent;
@@ -856,12 +856,7 @@ public class TextEditor {
item.setPreferredSize(size);
item.setSize(size);
}
- coolBar.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent event) {
- handleResize(event);
- }
- });
+ coolBar.addControlListener(ControlListener.controlResizedAdapter(event -> handleResize(event)));
}
void disposeRanges(StyleRange[] ranges) {
@@ -1135,12 +1130,7 @@ public class TextEditor {
}
}
});
- shell.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent event) {
- handleResize(event);
- }
- });
+ shell.addControlListener(ControlListener.controlResizedAdapter(event -> handleResize(event)));
}
Image loadImage(Display display, String fileName) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java
index 6a60d6ed97..60132839c3 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet166.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -52,13 +52,10 @@ public static void main(String[] args) {
scrollComposite.setContent(parent);
scrollComposite.setExpandVertical(true);
scrollComposite.setExpandHorizontal(true);
- scrollComposite.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- Rectangle r = scrollComposite.getClientArea();
- scrollComposite.setMinSize(parent.computeSize(r.width, SWT.DEFAULT));
- }
- });
+ scrollComposite.addControlListener(ControlListener.controlResizedAdapter(e -> {
+ Rectangle r = scrollComposite.getClientArea();
+ scrollComposite.setMinSize(parent.computeSize(r.width, SWT.DEFAULT));
+ }));
shell.open();
while (!shell.isDisposed()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java
index 1f6b2547f4..2f31442164 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet174.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -49,12 +49,9 @@ public static void main(String[] args) {
GLData data = new GLData();
data.doubleBuffer = true;
final GLCanvas canvas = new GLCanvas(shell, SWT.NO_BACKGROUND, data);
- canvas.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- resize(canvas);
- }
- });
+ canvas.addControlListener(ControlListener.controlResizedAdapter(e -> {
+ resize(canvas);
+ }));
init(canvas);
new Runnable() {
@Override
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java
index 6556847fbd..a4d8463fcb 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and 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,37 +41,34 @@ public static void main(String[] args) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] {"item 0" + i, "item 1"+i});
}
- comp.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- Rectangle area = comp.getClientArea();
- Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- ScrollBar vBar = table.getVerticalBar();
- int width = area.width - table.computeTrim(0,0,0,0).width - vBar.getSize().x;
- if (size.y > area.height + table.getHeaderHeight()) {
- // Subtract the scrollbar width from the total column width
- // if a vertical scrollbar will be required
- Point vBarSize = vBar.getSize();
- width -= vBarSize.x;
- }
- Point oldSize = table.getSize();
- if (oldSize.x > area.width) {
- // table is getting smaller so make the columns
- // smaller first and then resize the table to
- // match the client area width
- column1.setWidth(width/3);
- column2.setWidth(width - column1.getWidth());
- table.setSize(area.width, area.height);
- } else {
- // table is getting bigger so make the table
- // bigger first and then make the columns wider
- // to match the client area width
- table.setSize(area.width, area.height);
- column1.setWidth(width/3);
- column2.setWidth(width - column1.getWidth());
- }
+ comp.addControlListener(ControlListener.controlResizedAdapter(e -> {
+ Rectangle area = comp.getClientArea();
+ Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ ScrollBar vBar = table.getVerticalBar();
+ int width = area.width - table.computeTrim(0, 0, 0, 0).width - vBar.getSize().x;
+ if (size.y > area.height + table.getHeaderHeight()) {
+ // Subtract the scrollbar width from the total column width
+ // if a vertical scrollbar will be required
+ Point vBarSize = vBar.getSize();
+ width -= vBarSize.x;
}
- });
+ Point oldSize = table.getSize();
+ if (oldSize.x > area.width) {
+ // table is getting smaller so make the columns
+ // smaller first and then resize the table to
+ // match the client area width
+ column1.setWidth(width / 3);
+ column2.setWidth(width - column1.getWidth());
+ table.setSize(area.width, area.height);
+ } else {
+ // table is getting bigger so make the table
+ // bigger first and then make the columns wider
+ // to match the client area width
+ table.setSize(area.width, area.height);
+ column1.setWidth(width / 3);
+ column2.setWidth(width - column1.getWidth());
+ }
+ }));
shell.open();
while (!shell.isDisposed()) {

Back to the top