Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2017-03-29 05:24:42 -0400
committerLars Vogel2017-03-29 05:24:42 -0400
commita7bb0a86848de6345182bddf7a0fc9fd88126e14 (patch)
treeb5ca1d8e0befdc4e39fbfbb176277e0f8a1faca2 /examples
parentad5dd193ddc783d8fdcafdbcea87064bf604e9b2 (diff)
downloadeclipse.platform.swt-a7bb0a86848de6345182bddf7a0fc9fd88126e14.tar.gz
eclipse.platform.swt-a7bb0a86848de6345182bddf7a0fc9fd88126e14.tar.xz
eclipse.platform.swt-a7bb0a86848de6345182bddf7a0fc9fd88126e14.zip
Bug 509086 - Use lambda helper methods in org.eclipse.swt.examples -
Part 1 Change-Id: I7850d35cbc41a93fc0078d610ba8d77c848c6c34 Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/AlignableTab.java13
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java18
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ButtonTab.java13
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CTabFolderTab.java59
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CanvasTab.java24
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java17
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java16
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DialogTab.java24
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java9
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java341
10 files changed, 150 insertions, 384 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/AlignableTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/AlignableTab.java
index 6a713055a1..f292f7a990 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/AlignableTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/AlignableTab.java
@@ -11,6 +11,8 @@
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.layout.*;
@@ -59,13 +61,10 @@ abstract class AlignableTab extends Tab {
rightButton.setText (ControlExample.getResourceString("Right"));
/* Add the listeners */
- SelectionListener selectionListener = new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (!((Button) event.widget).getSelection ()) return;
- setExampleWidgetAlignment ();
- }
- };
+ SelectionListener selectionListener = widgetSelectedAdapter(event -> {
+ if (!((Button) event.widget).getSelection ()) return;
+ setExampleWidgetAlignment ();
+ });
leftButton.addSelectionListener (selectionListener);
centerButton.addSelectionListener (selectionListener);
rightButton.addSelectionListener (selectionListener);
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 68ee7abe99..c2c7db334e 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
@@ -11,6 +11,8 @@
package org.eclipse.swt.examples.controlexample;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -27,7 +29,6 @@ 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.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -204,16 +205,13 @@ class BrowserTab extends Tab {
* Add a selection listener to the tabFolder to bring up a
* dialog if this platform does not support the Browser.
*/
- tabFolder.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (errorMessage != null && tabFolder.getSelection()[0].getText().equals(getTabText())) {
- MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
- dialog.setMessage(ControlExample.getResourceString("BrowserNotFound", errorMessage));
- dialog.open();
- }
+ tabFolder.addSelectionListener(widgetSelectedAdapter(e -> {
+ if (errorMessage != null && tabFolder.getSelection()[0].getText().equals(getTabText())) {
+ MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
+ dialog.setMessage(ControlExample.getResourceString("BrowserNotFound", errorMessage));
+ dialog.open();
}
- });
+ }));
return tabFolderPage;
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ButtonTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ButtonTab.java
index 38821cc1a7..a17ac1165d 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ButtonTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ButtonTab.java
@@ -11,6 +11,8 @@
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.layout.*;
@@ -53,13 +55,10 @@ class ButtonTab extends AlignableTab {
downButton.setText (ControlExample.getResourceString("Down"));
/* Add the listeners */
- SelectionListener selectionListener = new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (!((Button) event.widget).getSelection()) return;
- setExampleWidgetAlignment ();
- }
- };
+ SelectionListener selectionListener = widgetSelectedAdapter(event -> {
+ if (!((Button) event.widget).getSelection()) return;
+ setExampleWidgetAlignment ();
+ });
upButton.addSelectionListener(selectionListener);
downButton.addSelectionListener(selectionListener);
}
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 bfed02a92f..ad4c14debb 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
@@ -11,12 +11,13 @@
package org.eclipse.swt.examples.controlexample;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabFolder2Listener;
import org.eclipse.swt.custom.CTabFolderEvent;
import org.eclipse.swt.custom.CTabItem;
-import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
@@ -149,80 +150,40 @@ class CTabFolderTab extends Tab {
simpleTabButton = new Button (otherGroup, SWT.CHECK);
simpleTabButton.setText (ControlExample.getResourceString("Set_Simple_Tabs"));
simpleTabButton.setSelection(true);
- simpleTabButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setSimpleTabs();
- }
- });
+ simpleTabButton.addSelectionListener (widgetSelectedAdapter(event -> setSimpleTabs()));
singleTabButton = new Button (otherGroup, SWT.CHECK);
singleTabButton.setText (ControlExample.getResourceString("Set_Single_Tabs"));
singleTabButton.setSelection(false);
- singleTabButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setSingleTabs();
- }
- });
+ singleTabButton.addSelectionListener (widgetSelectedAdapter(event -> setSingleTabs()));
showMinButton = new Button (otherGroup, SWT.CHECK);
showMinButton.setText (ControlExample.getResourceString("Set_Min_Visible"));
showMinButton.setSelection(false);
- showMinButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setMinimizeVisible();
- }
- });
+ showMinButton.addSelectionListener (widgetSelectedAdapter(event -> setMinimizeVisible()));
showMaxButton = new Button (otherGroup, SWT.CHECK);
showMaxButton.setText (ControlExample.getResourceString("Set_Max_Visible"));
showMaxButton.setSelection(false);
- showMaxButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setMaximizeVisible();
- }
- });
+ showMaxButton.addSelectionListener (widgetSelectedAdapter(event -> setMaximizeVisible()));
topRightButton = new Button (otherGroup, SWT.CHECK);
topRightButton.setText (ControlExample.getResourceString("Set_Top_Right"));
topRightButton.setSelection(false);
- topRightButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setTopRight();
- }
- });
+ topRightButton.addSelectionListener (widgetSelectedAdapter(event -> setTopRight()));
imageButton = new Button (otherGroup, SWT.CHECK);
imageButton.setText (ControlExample.getResourceString("Set_Image"));
- imageButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setImages();
- }
- });
+ imageButton.addSelectionListener (widgetSelectedAdapter(event -> setImages()));
unselectedImageButton = new Button (otherGroup, SWT.CHECK);
unselectedImageButton.setText (ControlExample.getResourceString("Set_Unselected_Image_Visible"));
unselectedImageButton.setSelection(true);
- unselectedImageButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setUnselectedImageVisible();
- }
- });
+ unselectedImageButton.addSelectionListener (widgetSelectedAdapter(event -> setUnselectedImageVisible()));
unselectedCloseButton = new Button (otherGroup, SWT.CHECK);
unselectedCloseButton.setText (ControlExample.getResourceString("Set_Unselected_Close_Visible"));
unselectedCloseButton.setSelection(true);
- unselectedCloseButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setUnselectedCloseVisible();
- }
- });
+ unselectedCloseButton.addSelectionListener (widgetSelectedAdapter(event -> setUnselectedCloseVisible()));
}
/**
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 e916b65b5f..c519917f67 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
@@ -11,10 +11,11 @@
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.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
@@ -85,12 +86,7 @@ class CanvasTab extends Tab {
fillDamageButton.setText (ControlExample.getResourceString("FillDamage"));
/* Add the listeners */
- caretButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setCaret ();
- }
- });
+ caretButton.addSelectionListener (widgetSelectedAdapter(event -> setCaret ()));
}
/**
@@ -152,22 +148,12 @@ class CanvasTab extends Tab {
ScrollBar bar = canvas.getHorizontalBar();
if (bar != null) {
hookListeners (bar);
- bar.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- scrollHorizontal ((ScrollBar)event.widget);
- }
- });
+ bar.addSelectionListener(widgetSelectedAdapter(event -> scrollHorizontal ((ScrollBar)event.widget)));
}
bar = canvas.getVerticalBar();
if (bar != null) {
hookListeners (bar);
- bar.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- scrollVertical ((ScrollBar)event.widget);
- }
- });
+ bar.addSelectionListener(widgetSelectedAdapter(event -> scrollVertical ((ScrollBar)event.widget)));
}
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java
index 4d5f8a039a..da792cdfde 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ColorTab.java
@@ -12,10 +12,11 @@
package org.eclipse.swt.examples.controlexample;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import java.util.HashMap;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
@@ -169,13 +170,10 @@ class ColorTab extends Tab {
packColumnsButton = new Button (sizeGroup, SWT.PUSH);
packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns"));
- packColumnsButton.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
+ packColumnsButton.addSelectionListener(widgetSelectedAdapter(event -> {
packColumns ();
setExampleWidgetSize ();
- }
- });
+ }));
}
void packColumns () {
@@ -214,17 +212,14 @@ class ColorTab extends Tab {
createSizeGroup ();
createOrientationGroup ();
- SelectionListener selectionListener = new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
+ SelectionListener selectionListener = widgetSelectedAdapter(event -> {
if ((event.widget.getStyle () & SWT.RADIO) != 0) {
if (!((Button) event.widget).getSelection ()) return;
}
if (!handleTextDirection (event.widget)) {
recreateExampleWidgets ();
}
- }
- };
+ });
// attach listeners to the Orientation buttons
rtlButton.addSelectionListener (selectionListener);
ltrButton.addSelectionListener (selectionListener);
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 3a15a2eacf..0dd151baea 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
@@ -11,6 +11,8 @@
package org.eclipse.swt.examples.controlexample;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
@@ -70,12 +72,7 @@ class CoolBarTab extends Tab {
lockedButton.setText (ControlExample.getResourceString("Locked"));
/* Add the listeners */
- lockedButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setWidgetLocked ();
- }
- });
+ lockedButton.addSelectionListener (widgetSelectedAdapter(event -> setWidgetLocked ()));
}
/**
@@ -364,12 +361,7 @@ class CoolBarTab extends Tab {
* Add a menu selection listener so that the menu is hidden
* when the user selects an item from the drop down menu.
*/
- menuItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- setMenuVisible(false);
- }
- });
+ menuItem.addSelectionListener(widgetSelectedAdapter(e -> setMenuVisible(false)));
} else {
new MenuItem(menu, SWT.SEPARATOR);
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DialogTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DialogTab.java
index aa7cbd7065..f4fd1417e9 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DialogTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DialogTab.java
@@ -11,8 +11,9 @@
package org.eclipse.swt.examples.controlexample;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.FontData;
@@ -441,24 +442,9 @@ class DialogTab extends Tab {
effectsVisibleButton.setText("FontDialog.setEffectsVisible");
/* Add the listeners */
- dialogCombo.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- dialogSelected (event);
- }
- });
- createButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- createButtonSelected (event);
- }
- });
- SelectionListener buttonStyleListener = new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- buttonStyleSelected (event);
- }
- };
+ dialogCombo.addSelectionListener (widgetSelectedAdapter(event -> dialogSelected (event)));
+ createButton.addSelectionListener (widgetSelectedAdapter(event -> createButtonSelected (event)));
+ SelectionListener buttonStyleListener = widgetSelectedAdapter(event -> buttonStyleSelected (event));
okButton.addSelectionListener (buttonStyleListener);
cancelButton.addSelectionListener (buttonStyleListener);
yesButton.addSelectionListener (buttonStyleListener);
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java
index 7931cbb24c..291c66bb33 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java
@@ -11,6 +11,8 @@
package org.eclipse.swt.examples.controlexample;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
@@ -45,12 +47,7 @@ class GroupTab extends Tab {
titleButton.setText (ControlExample.getResourceString("Title_Text"));
/* Add the listeners */
- titleButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setTitleText ();
- }
- });
+ titleButton.addSelectionListener (widgetSelectedAdapter(event -> setTitleText ()));
}
/**
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 fa695d24fd..b58ccd2084 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
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.swt.examples.imageanalyzer;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import java.io.InputStream;
import java.net.URL;
import java.text.MessageFormat;
@@ -28,7 +30,6 @@ import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellAdapter;
@@ -166,24 +167,16 @@ public class ImageAnalyzer {
data = new GridData();
data.widthHint = 75;
ok.setLayoutData(data);
- ok.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- result = text.getText();
- dialog.dispose();
- }
- });
+ ok.addSelectionListener(widgetSelectedAdapter(e -> {
+ result = text.getText();
+ dialog.dispose();
+ }));
Button cancel = new Button(buttons, SWT.PUSH);
cancel.setText(bundle.getString("Cancel"));
data = new GridData();
data.widthHint = 75;
cancel.setLayoutData(data);
- cancel.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- dialog.dispose();
- }
- });
+ cancel.addSelectionListener(widgetSelectedAdapter(e -> dialog.dispose()));
dialog.setDefaultButton(ok);
dialog.pack();
dialog.open();
@@ -295,12 +288,7 @@ public class ImageAnalyzer {
bundle.getString("Green"),
bundle.getString("Blue"));
backgroundCombo.select(backgroundCombo.indexOf(bundle.getString("White")));
- backgroundCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- changeBackground();
- }
- });
+ backgroundCombo.addSelectionListener(widgetSelectedAdapter(event -> changeBackground()));
// Combo to change the compression ratio.
group = new Group(controls, SWT.NONE);
@@ -312,41 +300,38 @@ public class ImageAnalyzer {
imageTypeCombo.add(type);
}
imageTypeCombo.select(imageTypeCombo.indexOf("JPEG"));
- imageTypeCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- int index = imageTypeCombo.getSelectionIndex();
- switch(index) {
- case 0:
- compressionCombo.setEnabled(true);
- compressionRatioLabel.setEnabled(true);
- if (compressionCombo.getItemCount() == 100) break;
- compressionCombo.removeAll();
- for (int i = 0; i < 100; i++) {
- compressionCombo.add(String.valueOf(i + 1));
- }
- compressionCombo.select(compressionCombo.indexOf("75"));
- break;
- case 1:
- compressionCombo.setEnabled(true);
- compressionRatioLabel.setEnabled(true);
- if (compressionCombo.getItemCount() == 10) break;
- compressionCombo.removeAll();
- for (int i = 0; i < 4; i++) {
- compressionCombo.add(String.valueOf(i));
- }
- compressionCombo.select(0);
- break;
- case 2:
- case 3:
- case 4:
- case 5:
- compressionCombo.setEnabled(false);
- compressionRatioLabel.setEnabled(false);
- break;
+ imageTypeCombo.addSelectionListener(widgetSelectedAdapter(event -> {
+ int index = imageTypeCombo.getSelectionIndex();
+ switch(index) {
+ case 0:
+ compressionCombo.setEnabled(true);
+ compressionRatioLabel.setEnabled(true);
+ if (compressionCombo.getItemCount() == 100) break;
+ compressionCombo.removeAll();
+ for (int i = 0; i < 100; i++) {
+ compressionCombo.add(String.valueOf(i + 1));
}
+ compressionCombo.select(compressionCombo.indexOf("75"));
+ break;
+ case 1:
+ compressionCombo.setEnabled(true);
+ compressionRatioLabel.setEnabled(true);
+ if (compressionCombo.getItemCount() == 10) break;
+ compressionCombo.removeAll();
+ for (int i = 0; i < 4; i++) {
+ compressionCombo.add(String.valueOf(i));
+ }
+ compressionCombo.select(0);
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ compressionCombo.setEnabled(false);
+ compressionRatioLabel.setEnabled(false);
+ break;
}
- });
+ }));
imageTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
compressionRatioLabel = new Label(group, SWT.NONE);
compressionRatioLabel.setText(bundle.getString("Compression"));
@@ -370,12 +355,7 @@ public class ImageAnalyzer {
scaleXCombo.add(value);
}
scaleXCombo.select(scaleXCombo.indexOf("1"));
- scaleXCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- scaleX();
- }
- });
+ scaleXCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleX()));
// Combo to change the y scale.
group = new Group(controls, SWT.NONE);
@@ -386,12 +366,7 @@ public class ImageAnalyzer {
scaleYCombo.add(value);
}
scaleYCombo.select(scaleYCombo.indexOf("1"));
- scaleYCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- scaleY();
- }
- });
+ scaleYCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleY()));
// Combo to change the alpha value.
group = new Group(controls, SWT.NONE);
@@ -402,12 +377,7 @@ public class ImageAnalyzer {
alphaCombo.add(String.valueOf(i));
}
alphaCombo.select(alphaCombo.indexOf("255"));
- alphaCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- alpha();
- }
- });
+ alphaCombo.addSelectionListener(widgetSelectedAdapter(event -> alpha()));
// Check box to request incremental display.
group = new Group(controls, SWT.NONE);
@@ -416,51 +386,35 @@ public class ImageAnalyzer {
incrementalCheck = new Button(group, SWT.CHECK);
incrementalCheck.setText(bundle.getString("Incremental"));
incrementalCheck.setSelection(incremental);
- incrementalCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- incremental = ((Button)event.widget).getSelection();
- }
- });
+ incrementalCheck.addSelectionListener(widgetSelectedAdapter(event -> incremental = ((Button)event.widget).getSelection()));
// Check box to request transparent display.
transparentCheck = new Button(group, SWT.CHECK);
transparentCheck.setText(bundle.getString("Transparent"));
transparentCheck.setSelection(transparent);
- transparentCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- transparent = ((Button)event.widget).getSelection();
- if (image != null) {
- imageCanvas.redraw();
- }
+ transparentCheck.addSelectionListener(widgetSelectedAdapter(event -> {
+ transparent = ((Button)event.widget).getSelection();
+ if (image != null) {
+ imageCanvas.redraw();
}
- });
+ }));
// Check box to request mask display.
maskCheck = new Button(group, SWT.CHECK);
maskCheck.setText(bundle.getString("Mask"));
maskCheck.setSelection(showMask);
- maskCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- showMask = ((Button)event.widget).getSelection();
- if (image != null) {
- imageCanvas.redraw();
- }
+ maskCheck.addSelectionListener(widgetSelectedAdapter(event -> {
+ showMask = ((Button)event.widget).getSelection();
+ if (image != null) {
+ imageCanvas.redraw();
}
- });
+ }));
// Check box to request background display.
backgroundCheck = new Button(group, SWT.CHECK);
backgroundCheck.setText(bundle.getString("Background"));
backgroundCheck.setSelection(showBackground);
- backgroundCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- showBackground = ((Button)event.widget).getSelection();
- }
- });
+ backgroundCheck.addSelectionListener(widgetSelectedAdapter(event -> showBackground = ((Button)event.widget).getSelection()));
// Group the animation buttons.
group = new Group(controls, SWT.NONE);
@@ -471,34 +425,19 @@ public class ImageAnalyzer {
previousButton = new Button(group, SWT.PUSH);
previousButton.setText(bundle.getString("Previous"));
previousButton.setEnabled(false);
- previousButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- previous();
- }
- });
+ previousButton.addSelectionListener(widgetSelectedAdapter(event -> previous()));
// Push button to display the next image in a multi-image file.
nextButton = new Button(group, SWT.PUSH);
nextButton.setText(bundle.getString("Next"));
nextButton.setEnabled(false);
- nextButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- next();
- }
- });
+ nextButton.addSelectionListener(widgetSelectedAdapter(event -> next()));
// Push button to toggle animation of a multi-image file.
animateButton = new Button(group, SWT.PUSH);
animateButton.setText(bundle.getString("Animate"));
animateButton.setEnabled(false);
- animateButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- animate();
- }
- });
+ animateButton.addSelectionListener(widgetSelectedAdapter(event -> animate()));
// Label to show the image file type.
typeLabel = new Label(shell, SWT.NONE);
@@ -535,22 +474,12 @@ public class ImageAnalyzer {
horizontal.setVisible(true);
horizontal.setMinimum(0);
horizontal.setEnabled(false);
- horizontal.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- scrollHorizontally((ScrollBar)event.widget);
- }
- });
+ horizontal.addSelectionListener(widgetSelectedAdapter(event -> scrollHorizontally((ScrollBar)event.widget)));
ScrollBar vertical = imageCanvas.getVerticalBar();
vertical.setVisible(true);
vertical.setMinimum(0);
vertical.setEnabled(false);
- vertical.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- scrollVertically((ScrollBar)event.widget);
- }
- });
+ vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollVertically((ScrollBar)event.widget)));
// Label to show the image size.
sizeLabel = new Label(shell, SWT.NONE);
@@ -639,12 +568,7 @@ public class ImageAnalyzer {
vertical.setMinimum(0);
vertical.setIncrement(10);
vertical.setEnabled(false);
- vertical.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- scrollPalette((ScrollBar)event.widget);
- }
- });
+ vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollPalette((ScrollBar)event.widget)));
// Sash to see more of image or image data.
sash = new Sash(shell, SWT.HORIZONTAL);
@@ -652,32 +576,29 @@ public class ImageAnalyzer {
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
sash.setLayoutData(gridData);
- sash.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- if (event.detail != SWT.DRAG) {
- ((GridData)paletteCanvas.getLayoutData()).heightHint = SWT.DEFAULT;
- Rectangle paletteCanvasBounds = paletteCanvas.getBounds();
- int minY = paletteCanvasBounds.y + 20;
- Rectangle dataLabelBounds = dataLabel.getBounds();
- int maxY = statusLabel.getBounds().y - dataLabelBounds.height - 20;
- if (event.y > minY && event.y < maxY) {
- Rectangle oldSash = sash.getBounds();
- sash.setBounds(event.x, event.y, event.width, event.height);
- int diff = event.y - oldSash.y;
- Rectangle bounds = imageCanvas.getBounds();
- imageCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
- bounds = paletteCanvasBounds;
- paletteCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
- bounds = dataLabelBounds;
- dataLabel.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height);
- bounds = dataText.getBounds();
- dataText.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height - diff);
- //shell.layout(true);
- }
+ sash.addSelectionListener (widgetSelectedAdapter(event -> {
+ if (event.detail != SWT.DRAG) {
+ ((GridData)paletteCanvas.getLayoutData()).heightHint = SWT.DEFAULT;
+ Rectangle paletteCanvasBounds = paletteCanvas.getBounds();
+ int minY = paletteCanvasBounds.y + 20;
+ Rectangle dataLabelBounds = dataLabel.getBounds();
+ int maxY = statusLabel.getBounds().y - dataLabelBounds.height - 20;
+ if (event.y > minY && event.y < maxY) {
+ Rectangle oldSash = sash.getBounds();
+ sash.setBounds(event.x, event.y, event.width, event.height);
+ int diff = event.y - oldSash.y;
+ Rectangle bounds = imageCanvas.getBounds();
+ imageCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
+ bounds = paletteCanvasBounds;
+ paletteCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
+ bounds = dataLabelBounds;
+ dataLabel.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height);
+ bounds = dataText.getBounds();
+ dataText.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height - diff);
+ //shell.layout(true);
}
}
- });
+ }));
// Label to show data-specific fields.
dataLabel = new Label(shell, SWT.NONE);
@@ -741,33 +662,18 @@ public class ImageAnalyzer {
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("OpenFile"));
item.setAccelerator(SWT.MOD1 + 'O');
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuOpenFile();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuOpenFile()));
// File -> Open URL...
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("OpenURL"));
item.setAccelerator(SWT.MOD1 + 'U');
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuOpenURL();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuOpenURL()));
// File -> Reopen
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("Reopen"));
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuReopen();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuReopen()));
new MenuItem(fileMenu, SWT.SEPARATOR);
@@ -775,12 +681,7 @@ public class ImageAnalyzer {
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("LoadFile"));
item.setAccelerator(SWT.MOD1 + 'L');
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuLoad();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuLoad()));
new MenuItem(fileMenu, SWT.SEPARATOR);
@@ -788,32 +689,17 @@ public class ImageAnalyzer {
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("Save"));
item.setAccelerator(SWT.MOD1 + 'S');
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuSave();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuSave()));
// File -> Save As...
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("Save_as"));
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuSaveAs();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuSaveAs()));
// File -> Save Mask As...
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("Save_mask_as"));
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuSaveMaskAs();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuSaveMaskAs()));
new MenuItem(fileMenu, SWT.SEPARATOR);
@@ -821,24 +707,14 @@ public class ImageAnalyzer {
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("Print"));
item.setAccelerator(SWT.MOD1 + 'P');
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuPrint();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuPrint()));
new MenuItem(fileMenu, SWT.SEPARATOR);
// File -> Exit
item = new MenuItem(fileMenu, SWT.PUSH);
item.setText(bundle.getString("Exit"));
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- shell.close();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> shell.close()));
}
@@ -852,32 +728,17 @@ public class ImageAnalyzer {
// Alpha -> K
item = new MenuItem(alphaMenu, SWT.PUSH);
item.setText("K");
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuComposeAlpha(ALPHA_CONSTANT);
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuComposeAlpha(ALPHA_CONSTANT)));
// Alpha -> (K + x) % 256
item = new MenuItem(alphaMenu, SWT.PUSH);
item.setText("(K + x) % 256");
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuComposeAlpha(ALPHA_X);
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuComposeAlpha(ALPHA_X)));
// Alpha -> (K + y) % 256
item = new MenuItem(alphaMenu, SWT.PUSH);
item.setText("(K + y) % 256");
- item.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- menuComposeAlpha(ALPHA_Y);
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(event -> menuComposeAlpha(ALPHA_Y)));
}
void menuComposeAlpha(int alpha_op) {
@@ -2288,13 +2149,10 @@ public class ImageAnalyzer {
int showBMPDialog() {
final int [] bmpType = new int[1];
bmpType[0] = SWT.IMAGE_BMP;
- SelectionListener radioSelected = new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- Button radio = (Button) event.widget;
- if (radio.getSelection()) bmpType[0] = ((Integer)radio.getData()).intValue();
- }
- };
+ SelectionListener radioSelected = widgetSelectedAdapter(event -> {
+ Button radio = (Button) event.widget;
+ if (radio.getSelection()) bmpType[0] = ((Integer)radio.getData()).intValue();
+ });
// need to externalize strings
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
@@ -2329,12 +2187,7 @@ public class ImageAnalyzer {
data.horizontalAlignment = SWT.CENTER;
data.widthHint = 75;
ok.setLayoutData(data);
- ok.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- dialog.close();
- }
- });
+ ok.addSelectionListener(widgetSelectedAdapter(e -> dialog.close()));
dialog.pack();
dialog.open();

Back to the top