Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-03-06 08:00:36 +0000
committerAlexander Kurtakov2017-03-06 08:00:36 +0000
commite2dd37f1570efadcd26501d23f25e1eedc988dba (patch)
tree7af19329f2f5a9d5aa0674f9a6e2c9177b50168e /examples
parentaefdc013eac1d0d62e7f23640f6591de4b693444 (diff)
downloadeclipse.platform.swt-e2dd37f1570efadcd26501d23f25e1eedc988dba.tar.gz
eclipse.platform.swt-e2dd37f1570efadcd26501d23f25e1eedc988dba.tar.xz
eclipse.platform.swt-e2dd37f1570efadcd26501d23f25e1eedc988dba.zip
Bug 513037 - [api] Provide helper methods to use lambda expressions for
MouseListener methods Convert examples/snippets to use the new lamnda. Also converted some SelectionAdapters to lambdas while at it. Change-Id: Id7f8b5a53c3cb4cd6cac6e195760b192ce155941 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/accessibility/AccessibleActionExample.java16
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/BarChart.java40
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/Shape.java16
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java14
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java17
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FillLayoutTab.java62
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FormLayoutTab.java345
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java315
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/RowLayoutTab.java141
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/StackLayoutTab.java80
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet233.java42
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet259.java48
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet334.java11
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.java53
14 files changed, 578 insertions, 622 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleActionExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleActionExample.java
index b23b62e667..7ee6e2e70d 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleActionExample.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/AccessibleActionExample.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 IBM Corporation and others.
+ * Copyright (c) 2008, 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.accessibility.AccessibleControlEvent;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
@@ -80,13 +79,10 @@ public class AccessibleActionExample {
int y = clientArea.y + (clientArea.height - stringExtent.y) / 2;
e.gc.drawString(buttonText, x, y);
});
- customButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- int actionIndex = (e.button == 1) ? 0 : 1;
- customButtonAction(actionIndex);
- }
- });
+ customButton.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ int actionIndex = (e.button == 1) ? 0 : 1;
+ customButtonAction(actionIndex);
+ }));
customButton.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/BarChart.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/BarChart.java
index 4d01a5c0fb..446eb804ff 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/BarChart.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/BarChart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 IBM Corporation and others.
+ * Copyright (c) 2008, 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
@@ -25,8 +25,7 @@ import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
@@ -128,28 +127,25 @@ public class BarChart extends Canvas {
}
});
- addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- if (getClientArea().contains(e.x, e.y)) {
- setFocus();
- int item = -1;
- int count = data.size();
- for (int i = 0; i < count; i++) {
- if (itemBounds(i).contains(e.x, e.y)) {
- item = i;
- break;
- }
- }
- if (item != selectedItem) {
- selectedItem = item;
- redraw();
- getAccessible().setFocus(item);
- getAccessible().selectionChanged();
+ addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ if (getClientArea().contains(e.x, e.y)) {
+ setFocus();
+ int item = -1;
+ int count = data.size();
+ for (int i = 0; i < count; i++) {
+ if (itemBounds(i).contains(e.x, e.y)) {
+ item = i;
+ break;
}
}
+ if (item != selectedItem) {
+ selectedItem = item;
+ redraw();
+ getAccessible().setFocus(item);
+ getAccessible().selectionChanged();
+ }
}
- });
+ }));
addKeyListener(new KeyAdapter() {
@Override
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/Shape.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/Shape.java
index 6e1e047159..a43b0ef3de 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/Shape.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/Shape.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 IBM Corporation and others.
+ * Copyright (c) 2008, 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
@@ -23,8 +23,7 @@ import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
@@ -85,14 +84,11 @@ public class Shape extends Canvas {
}
});
- addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- if (getClientArea().contains(e.x, e.y)) {
- setFocus();
- }
+ addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ if (getClientArea().contains(e.x, e.y)) {
+ setFocus();
}
- });
+ }));
addKeyListener(new KeyAdapter() {
@Override
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java
index 0d5b1839d0..63be90ca9d 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.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
@@ -18,8 +18,8 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
@@ -271,12 +271,10 @@ public class HoverHelp {
/*
* Get out of the way if we attempt to activate the control underneath the tooltip
*/
- control.addMouseListener(new MouseAdapter () {
- @Override
- public void mouseDown (MouseEvent e) {
- if (tipShell.isVisible()) tipShell.setVisible(false);
- }
- });
+ control.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ if (tipShell.isVisible())
+ tipShell.setVisible(false);
+ }));
/*
* Trap hover events to pop-up tooltip
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 da9ba0794e..fa695d24fd 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
@@ -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
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.swt.examples.imageanalyzer;
-
import java.io.InputStream;
import java.net.URL;
import java.text.MessageFormat;
@@ -27,8 +26,7 @@ import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -700,14 +698,11 @@ public class ImageAnalyzer {
gridData.heightHint = 128;
gridData.grabExcessVerticalSpace = true;
dataText.setLayoutData(gridData);
- dataText.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent event) {
- if (image != null && event.button == 1) {
- showColorForData();
- }
+ dataText.addMouseListener(MouseListener.mouseDownAdapter(event -> {
+ if (image != null && event.button == 1) {
+ showColorForData();
}
- });
+ }));
dataText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FillLayoutTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FillLayoutTab.java
index 9f187d6750..4985353b7d 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FillLayoutTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FillLayoutTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 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,20 @@
*******************************************************************************/
package org.eclipse.swt.examples.layoutexample;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Spinner;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
class FillLayoutTab extends Tab {
/* Controls for setting layout parameters */
@@ -48,28 +56,26 @@ class FillLayoutTab extends Tab {
/* Add TableEditors */
comboEditor = new TableEditor (table);
nameEditor = new TableEditor (table);
- table.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- resetEditors ();
- index = table.getSelectionIndex ();
- if (index == -1) return;
- TableItem oldItem = comboEditor.getItem ();
- newItem = table.getItem (index);
- if (newItem == oldItem || newItem != lastSelected) {
- lastSelected = newItem;
- return;
- }
- table.showSelection ();
-
- combo = new CCombo (table, SWT.READ_ONLY);
- createComboEditor (combo, comboEditor);
-
- nameText = new Text(table, SWT.SINGLE);
- nameText.setText(data.get(index)[NAME_COL]);
- createTextEditor(nameText, nameEditor, NAME_COL);
+ table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ resetEditors();
+ index = table.getSelectionIndex();
+ if (index == -1)
+ return;
+ TableItem oldItem = comboEditor.getItem();
+ newItem = table.getItem(index);
+ if (newItem == oldItem || newItem != lastSelected) {
+ lastSelected = newItem;
+ return;
}
- });
+ table.showSelection();
+
+ combo = new CCombo(table, SWT.READ_ONLY);
+ createComboEditor(combo, comboEditor);
+
+ nameText = new Text(table, SWT.SINGLE);
+ nameText.setText(data.get(index)[NAME_COL]);
+ createTextEditor(nameText, nameEditor, NAME_COL);
+ }));
}
/**
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FormLayoutTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FormLayoutTab.java
index 50d67dd3e8..b8e4394d0b 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FormLayoutTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FormLayoutTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 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,10 +14,8 @@ package org.eclipse.swt.examples.layoutexample;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.TableEditor;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
@@ -134,136 +132,124 @@ class FormLayoutTab extends Tab {
rightEditor = new TableEditor (table);
topEditor = new TableEditor (table);
bottomEditor = new TableEditor (table);
- table.addMouseListener (new MouseAdapter () {
- @Override
- public void mouseDown(MouseEvent e) {
+ table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ resetEditors();
+ index = table.getSelectionIndex();
+ Point pt = new Point(e.x, e.y);
+ newItem = table.getItem(pt);
+ if (newItem == null)
+ return;
+ TableItem oldItem = comboEditor.getItem();
+ if (newItem == oldItem || newItem != lastSelected) {
+ lastSelected = newItem;
+ return;
+ }
+ table.showSelection();
+
+ combo = new CCombo(table, SWT.READ_ONLY);
+ createComboEditor(combo, comboEditor);
+
+ nameText = new Text(table, SWT.SINGLE);
+ nameText.setText(data.get(index)[NAME_COL]);
+ createTextEditor(nameText, nameEditor, NAME_COL);
+
+ widthText = new Text(table, SWT.SINGLE);
+ widthText.setText(data.get(index)[WIDTH_COL]);
+ createTextEditor(widthText, widthEditor, WIDTH_COL);
+
+ heightText = new Text(table, SWT.SINGLE);
+ heightText.setText(data.get(index)[HEIGHT_COL]);
+ createTextEditor(heightText, heightEditor, HEIGHT_COL);
+
+ leftAttach = new Button(table, SWT.PUSH);
+ leftAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
+ leftEditor.horizontalAlignment = SWT.LEFT;
+ leftEditor.grabHorizontal = true;
+ leftEditor.minimumWidth = leftAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ leftEditor.setEditor(leftAttach, newItem, LEFT_COL);
+ leftAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
+ Shell shell = tabFolderPage.getShell();
+ AttachDialog dialog = new AttachDialog(shell);
+ dialog.setText(LayoutExample.getResourceString("Left_Attachment"));
+ dialog.setColumn(LEFT_COL);
+ String attach = dialog.open();
+ newItem.setText(LEFT_COL, attach);
resetEditors();
- index = table.getSelectionIndex ();
- Point pt = new Point (e.x, e.y);
- newItem = table.getItem (pt);
- if (newItem == null) return;
- TableItem oldItem = comboEditor.getItem ();
- if (newItem == oldItem || newItem != lastSelected) {
- lastSelected = newItem;
- return;
- }
- table.showSelection ();
-
- combo = new CCombo (table, SWT.READ_ONLY);
- createComboEditor (combo, comboEditor);
-
- nameText = new Text (table, SWT.SINGLE);
- nameText.setText (data.get(index)[NAME_COL]);
- createTextEditor(nameText, nameEditor, NAME_COL);
-
- widthText = new Text (table, SWT.SINGLE);
- widthText.setText (data.get (index) [WIDTH_COL]);
- createTextEditor (widthText, widthEditor, WIDTH_COL);
-
- heightText = new Text (table, SWT.SINGLE);
- heightText.setText (data.get (index) [HEIGHT_COL]);
- createTextEditor (heightText, heightEditor, HEIGHT_COL);
-
- leftAttach = new Button (table, SWT.PUSH);
- leftAttach.setText (LayoutExample.getResourceString ("Attach_Edit"));
- leftEditor.horizontalAlignment = SWT.LEFT;
- leftEditor.grabHorizontal = true;
- leftEditor.minimumWidth = leftAttach.computeSize (SWT.DEFAULT, SWT.DEFAULT).x;
- leftEditor.setEditor (leftAttach, newItem, LEFT_COL);
- leftAttach.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- Shell shell = tabFolderPage.getShell ();
- AttachDialog dialog = new AttachDialog (shell);
- dialog.setText (LayoutExample.getResourceString ("Left_Attachment"));
- dialog.setColumn (LEFT_COL);
- String attach = dialog.open ();
- newItem.setText (LEFT_COL, attach);
- resetEditors ();
- }
- });
-
- rightAttach = new Button (table, SWT.PUSH);
- rightAttach.setText (LayoutExample.getResourceString ("Attach_Edit"));
- rightEditor.horizontalAlignment = SWT.LEFT;
- rightEditor.grabHorizontal = true;
- rightEditor.minimumWidth = rightAttach.computeSize (SWT.DEFAULT, SWT.DEFAULT).x;
- rightEditor.setEditor (rightAttach, newItem, RIGHT_COL);
- rightAttach.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- Shell shell = tabFolderPage.getShell ();
- AttachDialog dialog = new AttachDialog (shell);
- dialog.setText (LayoutExample.getResourceString ("Right_Attachment"));
- dialog.setColumn (RIGHT_COL);
- String attach = dialog.open ();
- newItem.setText (RIGHT_COL, attach);
- if (newItem.getText (LEFT_COL).endsWith (")")) newItem.setText (LEFT_COL, "");
- resetEditors ();
- }
- });
-
- topAttach = new Button (table, SWT.PUSH);
- topAttach.setText (LayoutExample.getResourceString ("Attach_Edit"));
- topEditor.horizontalAlignment = SWT.LEFT;
- topEditor.grabHorizontal = true;
- topEditor.minimumWidth = topAttach.computeSize (SWT.DEFAULT, SWT.DEFAULT).x;
- topEditor.setEditor (topAttach, newItem, TOP_COL);
- topAttach.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- Shell shell = tabFolderPage.getShell ();
- AttachDialog dialog = new AttachDialog (shell);
- dialog.setText (LayoutExample.getResourceString ("Top_Attachment"));
- dialog.setColumn (TOP_COL);
- String attach = dialog.open ();
- newItem.setText (TOP_COL, attach);
- resetEditors ();
- }
- });
- bottomAttach = new Button (table, SWT.PUSH);
- bottomAttach.setText (LayoutExample.getResourceString ("Attach_Edit"));
- bottomEditor.horizontalAlignment = SWT.LEFT;
- bottomEditor.grabHorizontal = true;
- bottomEditor.minimumWidth = bottomAttach.computeSize (SWT.DEFAULT, SWT.DEFAULT).x;
- bottomEditor.setEditor (bottomAttach, newItem, BOTTOM_COL);
- bottomAttach.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- Shell shell = tabFolderPage.getShell ();
- AttachDialog dialog = new AttachDialog (shell);
- dialog.setText (LayoutExample.getResourceString ("Bottom_Attachment"));
- dialog.setColumn (BOTTOM_COL);
- String attach = dialog.open ();
- newItem.setText (BOTTOM_COL, attach);
- if (newItem.getText (TOP_COL).endsWith (")")) newItem.setText (TOP_COL, "");
- resetEditors ();
+ }));
+
+ rightAttach = new Button(table, SWT.PUSH);
+ rightAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
+ rightEditor.horizontalAlignment = SWT.LEFT;
+ rightEditor.grabHorizontal = true;
+ rightEditor.minimumWidth = rightAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ rightEditor.setEditor(rightAttach, newItem, RIGHT_COL);
+ rightAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
+ Shell shell = tabFolderPage.getShell();
+ AttachDialog dialog = new AttachDialog(shell);
+ dialog.setText(LayoutExample.getResourceString("Right_Attachment"));
+ dialog.setColumn(RIGHT_COL);
+ String attach = dialog.open();
+ newItem.setText(RIGHT_COL, attach);
+ if (newItem.getText(LEFT_COL).endsWith(")"))
+ newItem.setText(LEFT_COL, "");
+ resetEditors();
+ }));
+
+ topAttach = new Button(table, SWT.PUSH);
+ topAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
+ topEditor.horizontalAlignment = SWT.LEFT;
+ topEditor.grabHorizontal = true;
+ topEditor.minimumWidth = topAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ topEditor.setEditor(topAttach, newItem, TOP_COL);
+ topAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
+ Shell shell = tabFolderPage.getShell();
+ AttachDialog dialog = new AttachDialog(shell);
+ dialog.setText(LayoutExample.getResourceString("Top_Attachment"));
+ dialog.setColumn(TOP_COL);
+ String attach = dialog.open();
+ newItem.setText(TOP_COL, attach);
+ resetEditors();
+ }));
+ bottomAttach = new Button(table, SWT.PUSH);
+ bottomAttach.setText(LayoutExample.getResourceString("Attach_Edit"));
+ bottomEditor.horizontalAlignment = SWT.LEFT;
+ bottomEditor.grabHorizontal = true;
+ bottomEditor.minimumWidth = bottomAttach.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ bottomEditor.setEditor(bottomAttach, newItem, BOTTOM_COL);
+ bottomAttach.addSelectionListener(SelectionListener.widgetSelectedAdapter(e1 -> {
+ Shell shell = tabFolderPage.getShell();
+ AttachDialog dialog = new AttachDialog(shell);
+ dialog.setText(LayoutExample.getResourceString("Bottom_Attachment"));
+ dialog.setColumn(BOTTOM_COL);
+ String attach = dialog.open();
+ newItem.setText(BOTTOM_COL, attach);
+ if (newItem.getText(TOP_COL).endsWith(")"))
+ newItem.setText(TOP_COL, "");
+ resetEditors();
+ }));
+
+ for (int i = 0; i < table.getColumnCount(); i++) {
+ Rectangle rect = newItem.getBounds(i);
+ if (rect.contains(pt)) {
+ switch (i) {
+ case 0:
+ resetEditors();
+ break;
+ case COMBO_COL:
+ combo.setFocus();
+ break;
+ case WIDTH_COL:
+ widthText.setFocus();
+ break;
+ case HEIGHT_COL:
+ heightText.setFocus();
+ break;
+ default:
+ break;
}
- });
-
- for (int i=0; i<table.getColumnCount (); i++) {
- Rectangle rect = newItem.getBounds (i);
- if (rect.contains (pt)) {
- switch (i) {
- case 0:
- resetEditors ();
- break;
- case COMBO_COL :
- combo.setFocus ();
- break;
- case WIDTH_COL :
- widthText.setFocus ();
- break;
- case HEIGHT_COL :
- heightText.setFocus ();
- break;
- default :
- break;
- }
- }
- }
+ }
}
- });
+ }));
}
/**
@@ -729,72 +715,57 @@ class FormLayoutTab extends Tab {
offset.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false, 2, 1));
/* Add listeners for choosing between position and control */
- posButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- position.setEnabled (true);
- control.setEnabled (false);
- alignment.setEnabled (false);
- }
- });
- contButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- position.setEnabled (false);
- control.setEnabled (true);
- alignment.setEnabled (true);
- }
- });
+ posButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
+ position.setEnabled(true);
+ control.setEnabled(false);
+ alignment.setEnabled(false);
+ }));
+ contButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
+ position.setEnabled(false);
+ control.setEnabled(true);
+ alignment.setEnabled(true);
+ }));
Button clear = new Button (shell, SWT.PUSH);
clear.setText (LayoutExample.getResourceString ("Clear"));
clear.setLayoutData (new GridData (SWT.END, SWT.CENTER, false, false));
- clear.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- result = "";
- shell.close ();
- }
- });
+ clear.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
+ result = "";
+ shell.close();
+ }));
/* OK button sets data into table */
Button ok = new Button (shell, SWT.PUSH);
ok.setText (LayoutExample.getResourceString ("OK"));
ok.setLayoutData (new GridData (SWT.CENTER, SWT.CENTER, false, false));
- ok.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- controlInput = control.getText ();
- alignmentInput = alignment.getText ().substring (4);
- positionInput = position.getText ();
- if (positionInput.length () == 0) positionInput = "0";
- try {
- new Integer (positionInput).intValue ();
- } catch (NumberFormatException except) {
- positionInput = "0";
- }
- offsetInput = offset.getText ();
- if (offsetInput.length () == 0) offsetInput = "0";
- try {
- new Integer (offsetInput).intValue ();
- } catch (NumberFormatException except) {
- offsetInput = "0";
- }
- if (posButton.getSelection() || controlInput.length () == 0) {
- result = positionInput + "," + offsetInput;
- } else {
- result = controlInput + "," + offsetInput + ":" + alignmentInput;
- }
- shell.close ();
+ ok.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
+ controlInput = control.getText();
+ alignmentInput = alignment.getText().substring(4);
+ positionInput = position.getText();
+ if (positionInput.length() == 0)
+ positionInput = "0";
+ try {
+ new Integer(positionInput).intValue();
+ } catch (NumberFormatException except) {
+ positionInput = "0";
+ }
+ offsetInput = offset.getText();
+ if (offsetInput.length() == 0)
+ offsetInput = "0";
+ try {
+ new Integer(offsetInput).intValue();
+ } catch (NumberFormatException except) {
+ offsetInput = "0";
}
- });
+ if (posButton.getSelection() || controlInput.length() == 0) {
+ result = positionInput + "," + offsetInput;
+ } else {
+ result = controlInput + "," + offsetInput + ":" + alignmentInput;
+ }
+ shell.close();
+ }));
Button cancel = new Button (shell, SWT.PUSH);
cancel.setText (LayoutExample.getResourceString ("Cancel"));
- cancel.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- shell.close ();
- }
- });
+ cancel.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> shell.close()));
shell.setDefaultButton (ok);
shell.pack ();
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java
index 1e45a7d78b..f275a6997e 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.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.layoutexample;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.TableEditor;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
@@ -112,164 +111,162 @@ class GridLayoutTab extends Tab {
minWidthEditor = new TableEditor (table);
minHeightEditor = new TableEditor (table);
excludeEditor = new TableEditor (table);
- table.addMouseListener (new MouseAdapter () {
- @Override
- public void mouseDown(MouseEvent e) {
- resetEditors();
- index = table.getSelectionIndex ();
- Point pt = new Point (e.x, e.y);
- newItem = table.getItem (pt);
- if (newItem == null) return;
- TableItem oldItem = comboEditor.getItem ();
- if (newItem == oldItem || newItem != lastSelected) {
- lastSelected = newItem;
- return;
+ table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ resetEditors();
+ index = table.getSelectionIndex();
+ Point pt = new Point(e.x, e.y);
+ newItem = table.getItem(pt);
+ if (newItem == null)
+ return;
+ TableItem oldItem = comboEditor.getItem();
+ if (newItem == oldItem || newItem != lastSelected) {
+ lastSelected = newItem;
+ return;
+ }
+ table.showSelection();
+
+ nameText = new Text(table, SWT.SINGLE);
+ nameText.setText(data.get(index)[NAME_COL]);
+ createTextEditor(nameText, nameEditor, NAME_COL);
+
+ combo = new CCombo(table, SWT.READ_ONLY);
+ createComboEditor(combo, comboEditor);
+
+ widthText = new Text(table, SWT.SINGLE);
+ widthText.setText(data.get(index)[WIDTH_COL]);
+ createTextEditor(widthText, widthEditor, WIDTH_COL);
+
+ heightText = new Text(table, SWT.SINGLE);
+ heightText.setText(data.get(index)[HEIGHT_COL]);
+ createTextEditor(heightText, heightEditor, HEIGHT_COL);
+
+ String[] alignValues = new String[] { "BEGINNING", "CENTER", "END", "FILL" };
+ hAlign = new CCombo(table, SWT.NONE);
+ hAlign.setItems(alignValues);
+ hAlign.setText(newItem.getText(HALIGN_COL));
+ hAlignEditor.horizontalAlignment = SWT.LEFT;
+ hAlignEditor.grabHorizontal = true;
+ hAlignEditor.minimumWidth = 50;
+ hAlignEditor.setEditor(hAlign, newItem, HALIGN_COL);
+ hAlign.addTraverseListener(traverseListener);
+
+ vAlign = new CCombo(table, SWT.NONE);
+ vAlign.setItems(alignValues);
+ vAlign.setText(newItem.getText(VALIGN_COL));
+ vAlignEditor.horizontalAlignment = SWT.LEFT;
+ vAlignEditor.grabHorizontal = true;
+ vAlignEditor.minimumWidth = 50;
+ vAlignEditor.setEditor(vAlign, newItem, VALIGN_COL);
+ vAlign.addTraverseListener(traverseListener);
+
+ String[] boolValues = new String[] { "false", "true" };
+ hGrab = new CCombo(table, SWT.NONE);
+ hGrab.setItems(boolValues);
+ hGrab.setText(newItem.getText(HGRAB_COL));
+ hGrabEditor.horizontalAlignment = SWT.LEFT;
+ hGrabEditor.grabHorizontal = true;
+ hGrabEditor.minimumWidth = 50;
+ hGrabEditor.setEditor(hGrab, newItem, HGRAB_COL);
+ hGrab.addTraverseListener(traverseListener);
+
+ vGrab = new CCombo(table, SWT.NONE);
+ vGrab.setItems(boolValues);
+ vGrab.setText(newItem.getText(VGRAB_COL));
+ vGrabEditor.horizontalAlignment = SWT.LEFT;
+ vGrabEditor.grabHorizontal = true;
+ vGrabEditor.minimumWidth = 50;
+ vGrabEditor.setEditor(vGrab, newItem, VGRAB_COL);
+ vGrab.addTraverseListener(traverseListener);
+
+ hSpan = new Text(table, SWT.SINGLE);
+ hSpan.setText(data.get(index)[HSPAN_COL]);
+ createTextEditor(hSpan, hSpanEditor, HSPAN_COL);
+
+ vSpan = new Text(table, SWT.SINGLE);
+ vSpan.setText(data.get(index)[VSPAN_COL]);
+ createTextEditor(vSpan, vSpanEditor, VSPAN_COL);
+
+ hIndent = new Text(table, SWT.SINGLE);
+ hIndent.setText(data.get(index)[HINDENT_COL]);
+ createTextEditor(hIndent, hIndentEditor, HINDENT_COL);
+
+ vIndent = new Text(table, SWT.SINGLE);
+ vIndent.setText(data.get(index)[VINDENT_COL]);
+ createTextEditor(vIndent, vIndentEditor, VINDENT_COL);
+
+ minWidthText = new Text(table, SWT.SINGLE);
+ minWidthText.setText(data.get(index)[MINWIDTH_COL]);
+ createTextEditor(minWidthText, minWidthEditor, MINWIDTH_COL);
+
+ minHeightText = new Text(table, SWT.SINGLE);
+ minHeightText.setText(data.get(index)[MINHEIGHT_COL]);
+ createTextEditor(minHeightText, minHeightEditor, MINHEIGHT_COL);
+
+ exclude = new CCombo(table, SWT.NONE);
+ exclude.setItems(boolValues);
+ exclude.setText(newItem.getText(EXCLUDE_COL));
+ excludeEditor.horizontalAlignment = SWT.LEFT;
+ excludeEditor.grabHorizontal = true;
+ excludeEditor.minimumWidth = 50;
+ excludeEditor.setEditor(exclude, newItem, EXCLUDE_COL);
+ exclude.addTraverseListener(traverseListener);
+
+ for (int i = 0; i < table.getColumnCount(); i++) {
+ Rectangle rect = newItem.getBounds(i);
+ if (rect.contains(pt)) {
+ switch (i) {
+ case NAME_COL:
+ nameText.setFocus();
+ break;
+ case COMBO_COL:
+ combo.setFocus();
+ break;
+ case WIDTH_COL:
+ widthText.setFocus();
+ break;
+ case HEIGHT_COL:
+ heightText.setFocus();
+ break;
+ case HALIGN_COL:
+ hAlign.setFocus();
+ break;
+ case VALIGN_COL:
+ vAlign.setFocus();
+ break;
+ case HGRAB_COL:
+ hGrab.setFocus();
+ break;
+ case VGRAB_COL:
+ vGrab.setFocus();
+ break;
+ case HSPAN_COL:
+ hSpan.setFocus();
+ break;
+ case VSPAN_COL:
+ vSpan.setFocus();
+ break;
+ case HINDENT_COL:
+ hIndent.setFocus();
+ break;
+ case VINDENT_COL:
+ vIndent.setFocus();
+ break;
+ case MINWIDTH_COL:
+ minWidthText.setFocus();
+ break;
+ case MINHEIGHT_COL:
+ minHeightText.setFocus();
+ break;
+ case EXCLUDE_COL:
+ exclude.setFocus();
+ break;
+ default:
+ resetEditors();
+ break;
+ }
}
- table.showSelection ();
-
- nameText = new Text (table, SWT.SINGLE);
- nameText.setText (data.get (index) [NAME_COL]);
- createTextEditor (nameText, nameEditor, NAME_COL);
-
- combo = new CCombo (table, SWT.READ_ONLY);
- createComboEditor (combo, comboEditor);
-
- widthText = new Text (table, SWT.SINGLE);
- widthText.setText (data.get (index) [WIDTH_COL]);
- createTextEditor (widthText, widthEditor, WIDTH_COL);
-
- heightText = new Text (table, SWT.SINGLE);
- heightText.setText (data.get (index) [HEIGHT_COL]);
- createTextEditor (heightText, heightEditor, HEIGHT_COL);
-
- String [] alignValues = new String [] {"BEGINNING","CENTER","END","FILL"};
- hAlign = new CCombo (table, SWT.NONE);
- hAlign.setItems (alignValues);
- hAlign.setText (newItem.getText (HALIGN_COL));
- hAlignEditor.horizontalAlignment = SWT.LEFT;
- hAlignEditor.grabHorizontal = true;
- hAlignEditor.minimumWidth = 50;
- hAlignEditor.setEditor (hAlign, newItem, HALIGN_COL);
- hAlign.addTraverseListener (traverseListener);
-
- vAlign = new CCombo (table, SWT.NONE);
- vAlign.setItems (alignValues);
- vAlign.setText (newItem.getText (VALIGN_COL));
- vAlignEditor.horizontalAlignment = SWT.LEFT;
- vAlignEditor.grabHorizontal = true;
- vAlignEditor.minimumWidth = 50;
- vAlignEditor.setEditor (vAlign, newItem, VALIGN_COL);
- vAlign.addTraverseListener (traverseListener);
-
- String [] boolValues = new String [] {"false", "true"};
- hGrab = new CCombo (table, SWT.NONE);
- hGrab.setItems (boolValues);
- hGrab.setText (newItem.getText (HGRAB_COL));
- hGrabEditor.horizontalAlignment = SWT.LEFT;
- hGrabEditor.grabHorizontal = true;
- hGrabEditor.minimumWidth = 50;
- hGrabEditor.setEditor (hGrab, newItem, HGRAB_COL);
- hGrab.addTraverseListener (traverseListener);
-
- vGrab = new CCombo (table, SWT.NONE);
- vGrab.setItems (boolValues);
- vGrab.setText (newItem.getText (VGRAB_COL));
- vGrabEditor.horizontalAlignment = SWT.LEFT;
- vGrabEditor.grabHorizontal = true;
- vGrabEditor.minimumWidth = 50;
- vGrabEditor.setEditor (vGrab, newItem, VGRAB_COL);
- vGrab.addTraverseListener (traverseListener);
-
- hSpan = new Text (table, SWT.SINGLE);
- hSpan.setText (data.get (index) [HSPAN_COL]);
- createTextEditor (hSpan, hSpanEditor, HSPAN_COL);
-
- vSpan = new Text (table, SWT.SINGLE);
- vSpan.setText (data.get (index) [VSPAN_COL]);
- createTextEditor (vSpan, vSpanEditor, VSPAN_COL);
-
- hIndent = new Text (table, SWT.SINGLE);
- hIndent.setText (data.get (index) [HINDENT_COL]);
- createTextEditor (hIndent, hIndentEditor, HINDENT_COL);
-
- vIndent = new Text (table, SWT.SINGLE);
- vIndent.setText (data.get (index) [VINDENT_COL]);
- createTextEditor (vIndent, vIndentEditor, VINDENT_COL);
-
- minWidthText = new Text (table, SWT.SINGLE);
- minWidthText.setText (data.get (index) [MINWIDTH_COL]);
- createTextEditor (minWidthText, minWidthEditor, MINWIDTH_COL);
-
- minHeightText = new Text (table, SWT.SINGLE);
- minHeightText.setText (data.get (index) [MINHEIGHT_COL]);
- createTextEditor (minHeightText, minHeightEditor, MINHEIGHT_COL);
-
- exclude = new CCombo (table, SWT.NONE);
- exclude.setItems (boolValues);
- exclude.setText (newItem.getText (EXCLUDE_COL));
- excludeEditor.horizontalAlignment = SWT.LEFT;
- excludeEditor.grabHorizontal = true;
- excludeEditor.minimumWidth = 50;
- excludeEditor.setEditor (exclude, newItem, EXCLUDE_COL);
- exclude.addTraverseListener (traverseListener);
-
- for (int i=0; i<table.getColumnCount (); i++) {
- Rectangle rect = newItem.getBounds (i);
- if (rect.contains (pt)) {
- switch (i) {
- case NAME_COL:
- nameText.setFocus ();
- break;
- case COMBO_COL :
- combo.setFocus ();
- break;
- case WIDTH_COL :
- widthText.setFocus ();
- break;
- case HEIGHT_COL :
- heightText.setFocus ();
- break;
- case HALIGN_COL :
- hAlign.setFocus ();
- break;
- case VALIGN_COL :
- vAlign.setFocus ();
- break;
- case HGRAB_COL :
- hGrab.setFocus ();
- break;
- case VGRAB_COL :
- vGrab.setFocus ();
- break;
- case HSPAN_COL :
- hSpan.setFocus ();
- break;
- case VSPAN_COL :
- vSpan.setFocus ();
- break;
- case HINDENT_COL :
- hIndent.setFocus ();
- break;
- case VINDENT_COL :
- vIndent.setFocus ();
- break;
- case MINWIDTH_COL :
- minWidthText.setFocus ();
- break;
- case MINHEIGHT_COL :
- minHeightText.setFocus ();
- break;
- case EXCLUDE_COL :
- exclude.setFocus ();
- break;
- default :
- resetEditors ();
- break;
- }
- }
- }
}
- });
+ }));
}
/**
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/RowLayoutTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/RowLayoutTab.java
index dde53d0614..49b11139ce 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/RowLayoutTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/RowLayoutTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 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,12 +11,23 @@
package org.eclipse.swt.examples.layoutexample;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.custom.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Spinner;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
class RowLayoutTab extends Tab {
/* Controls for setting layout parameters */
@@ -59,72 +70,70 @@ class RowLayoutTab extends Tab {
widthEditor = new TableEditor (table);
heightEditor = new TableEditor (table);
excludeEditor = new TableEditor (table);
- table.addMouseListener (new MouseAdapter () {
- @Override
- public void mouseDown(MouseEvent e) {
- resetEditors();
- index = table.getSelectionIndex ();
- Point pt = new Point (e.x, e.y);
- newItem = table.getItem (pt);
- if (newItem == null) return;
- TableItem oldItem = comboEditor.getItem ();
- if (newItem == oldItem || newItem != lastSelected) {
- lastSelected = newItem;
- return;
- }
- table.showSelection ();
+ table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ resetEditors();
+ index = table.getSelectionIndex();
+ Point pt = new Point(e.x, e.y);
+ newItem = table.getItem(pt);
+ if (newItem == null)
+ return;
+ TableItem oldItem = comboEditor.getItem();
+ if (newItem == oldItem || newItem != lastSelected) {
+ lastSelected = newItem;
+ return;
+ }
+ table.showSelection();
- combo = new CCombo (table, SWT.READ_ONLY);
- createComboEditor (combo, comboEditor);
+ combo = new CCombo(table, SWT.READ_ONLY);
+ createComboEditor(combo, comboEditor);
- nameText = new Text(table, SWT.SINGLE);
- nameText.setText(data.get(index)[NAME_COL]);
- createTextEditor(nameText, nameEditor, NAME_COL);
+ nameText = new Text(table, SWT.SINGLE);
+ nameText.setText(data.get(index)[NAME_COL]);
+ createTextEditor(nameText, nameEditor, NAME_COL);
- widthText = new Text(table, SWT.SINGLE);
- widthText.setText(data.get(index)[WIDTH_COL]);
- createTextEditor(widthText, widthEditor, WIDTH_COL);
+ widthText = new Text(table, SWT.SINGLE);
+ widthText.setText(data.get(index)[WIDTH_COL]);
+ createTextEditor(widthText, widthEditor, WIDTH_COL);
- heightText = new Text(table, SWT.SINGLE);
- heightText.setText (data.get (index) [HEIGHT_COL]);
- createTextEditor (heightText, heightEditor, HEIGHT_COL);
+ heightText = new Text(table, SWT.SINGLE);
+ heightText.setText(data.get(index)[HEIGHT_COL]);
+ createTextEditor(heightText, heightEditor, HEIGHT_COL);
- String [] boolValues = new String [] {"false", "true"};
- exclude = new CCombo (table, SWT.NONE);
- exclude.setItems (boolValues);
- exclude.setText (newItem.getText (EXCLUDE_COL));
- excludeEditor.horizontalAlignment = SWT.LEFT;
- excludeEditor.grabHorizontal = true;
- excludeEditor.minimumWidth = 50;
- excludeEditor.setEditor (exclude, newItem, EXCLUDE_COL);
- exclude.addTraverseListener (traverseListener);
+ String[] boolValues = new String[] { "false", "true" };
+ exclude = new CCombo(table, SWT.NONE);
+ exclude.setItems(boolValues);
+ exclude.setText(newItem.getText(EXCLUDE_COL));
+ excludeEditor.horizontalAlignment = SWT.LEFT;
+ excludeEditor.grabHorizontal = true;
+ excludeEditor.minimumWidth = 50;
+ excludeEditor.setEditor(exclude, newItem, EXCLUDE_COL);
+ exclude.addTraverseListener(traverseListener);
- for (int i=0; i<table.getColumnCount (); i++) {
- Rectangle rect = newItem.getBounds (i);
- if (rect.contains (pt)) {
- switch (i) {
- case NAME_COL :
- nameText.setFocus ();
- case COMBO_COL :
- combo.setFocus ();
- break;
- case WIDTH_COL :
- widthText.setFocus ();
- break;
- case HEIGHT_COL :
- heightText.setFocus ();
- break;
- case EXCLUDE_COL :
- exclude.setFocus ();
- break;
- default :
- resetEditors ();
- break;
- }
- }
- }
+ for (int i = 0; i < table.getColumnCount(); i++) {
+ Rectangle rect = newItem.getBounds(i);
+ if (rect.contains(pt)) {
+ switch (i) {
+ case NAME_COL:
+ nameText.setFocus();
+ case COMBO_COL:
+ combo.setFocus();
+ break;
+ case WIDTH_COL:
+ widthText.setFocus();
+ break;
+ case HEIGHT_COL:
+ heightText.setFocus();
+ break;
+ case EXCLUDE_COL:
+ exclude.setFocus();
+ break;
+ default:
+ resetEditors();
+ break;
+ }
+ }
}
- });
+ }));
}
/**
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/StackLayoutTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/StackLayoutTab.java
index c6eba0c91f..732ccc5295 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/StackLayoutTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/StackLayoutTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 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,11 +10,22 @@
*******************************************************************************/
package org.eclipse.swt.examples.layoutexample;
-import org.eclipse.swt.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.MouseListener;
+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.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Spinner;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
class StackLayoutTab extends Tab {
/* Controls for setting layout parameters */
@@ -49,30 +60,28 @@ class StackLayoutTab extends Tab {
/* Add TableEditors */
comboEditor = new TableEditor(table);
nameEditor = new TableEditor(table);
- table.addMouseListener (new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- resetEditors();
- index = table.getSelectionIndex();
- if (index == -1) return;
- //set top layer of stack to the selected item
- setTopControl (index);
+ table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ resetEditors();
+ index = table.getSelectionIndex();
+ if (index == -1)
+ return;
+ // set top layer of stack to the selected item
+ setTopControl(index);
- TableItem oldItem = comboEditor.getItem();
- newItem = table.getItem(index);
- if (newItem == oldItem || newItem != lastSelected) {
- lastSelected = newItem;
- return;
- }
- table.showSelection();
- combo = new CCombo(table, SWT.READ_ONLY);
- createComboEditor(combo, comboEditor);
-
- nameText = new Text(table, SWT.SINGLE);
- nameText.setText(data.get(index)[NAME_COL]);
- createTextEditor(nameText, nameEditor, NAME_COL);
+ TableItem oldItem = comboEditor.getItem();
+ newItem = table.getItem(index);
+ if (newItem == oldItem || newItem != lastSelected) {
+ lastSelected = newItem;
+ return;
}
- });
+ table.showSelection();
+ combo = new CCombo(table, SWT.READ_ONLY);
+ createComboEditor(combo, comboEditor);
+
+ nameText = new Text(table, SWT.SINGLE);
+ nameText.setText(data.get(index)[NAME_COL]);
+ createTextEditor(nameText, nameEditor, NAME_COL);
+ }));
}
/**
@@ -89,23 +98,14 @@ class StackLayoutTab extends Tab {
backButton.setText("<<");
backButton.setEnabled(false);
backButton.setLayoutData(new GridData (SWT.END, SWT.CENTER, false, false));
- backButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- setTopControl (currentLayer - 1);
- }
- });
+ backButton.addSelectionListener(SelectionListener.widgetSelectedAdapter( e ->setTopControl (currentLayer - 1)));
topControl = new Label (columnGroup, SWT.BORDER);
topControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
advanceButton = new Button(columnGroup, SWT.PUSH);
advanceButton.setText(">>");
advanceButton.setEnabled(false);
- advanceButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- setTopControl (currentLayer + 1);
- }
- });
+ advanceButton
+ .addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> setTopControl(currentLayer + 1)));
/* Controls the margins of the StackLayout */
Group marginGroup = new Group(controlGroup, SWT.NONE);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet233.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet233.java
index a872d79895..d2e9c41f97 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet233.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet233.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,31 +17,31 @@ package org.eclipse.swt.snippets;
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
+import static org.eclipse.swt.events.MouseListener.*;
+
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.events.*;
public class Snippet233 {
- public static void main (String [] args) {
- final Display display = new Display ();
- final Shell shell = new Shell (display);
- shell.setText ("Parent Shell");
- shell.addMouseListener (new MouseAdapter() {
- @Override
- public void mouseDown (MouseEvent e) {
- Shell dialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
- Point pt = display.getCursorLocation ();
- dialog.setLocation (pt.x, pt.y);
- dialog.setText ("Dialog Shell");
- dialog.setSize (100, 100);
- dialog.open ();
- }});
- shell.setSize (400, 400);
- shell.open ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
+ public static void main(String[] args) {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ shell.setText("Parent Shell");
+ shell.addMouseListener(mouseDownAdapter(e -> {
+ Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ Point pt = display.getCursorLocation();
+ dialog.setLocation(pt.x, pt.y);
+ dialog.setText("Dialog Shell");
+ dialog.setSize(100, 100);
+ dialog.open();
+ }));
+ shell.setSize(400, 400);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
}
- display.dispose ();
+ display.dispose();
}
}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet259.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet259.java
index fb2a858293..7578d68d38 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet259.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet259.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2016 IBM Corporation and others.
+ * Copyright (c) 2007, 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
@@ -18,8 +18,9 @@ package org.eclipse.swt.snippets;
*
* @since 3.3
*/
+import static org.eclipse.swt.events.MouseListener.*;
+
import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
@@ -41,30 +42,29 @@ static int checkStyle (int style) {
public MyList (Composite parent, int style) {
super (parent, checkStyle (style));
super.setDragDetect (false);
- addMouseListener (new MouseAdapter () {
- @Override
- public void mouseDown (MouseEvent event) {
- GC gc = new GC (MyList.this);
- Rectangle client = getClientArea();
- int index = 0, x = client.x + INSET_X, y = client.y + INSET_Y;
- while (index < items.length) {
- Point pt = gc.stringExtent(items [index]);
- Rectangle item = new Rectangle (x, y, pt.x, pt.y);
- if (item.contains (event.x, event.y)) break;
- y += pt.y;
- if (!client.contains (x, y)) return;
- index++;
- }
- gc.dispose ();
- if (index == items.length || !client.contains (x, y)) {
+ addMouseListener(mouseDownAdapter(event -> {
+ GC gc = new GC(MyList.this);
+ Rectangle client = getClientArea();
+ int index = 0, x = client.x + INSET_X, y = client.y + INSET_Y;
+ while (index < items.length) {
+ Point pt = gc.stringExtent(items[index]);
+ Rectangle item = new Rectangle(x, y, pt.x, pt.y);
+ if (item.contains(event.x, event.y))
+ break;
+ y += pt.y;
+ if (!client.contains(x, y))
return;
- }
- selection = index;
- redraw ();
- update ();
- dragDetect (event);
+ index++;
}
- });
+ gc.dispose();
+ if (index == items.length || !client.contains(x, y)) {
+ return;
+ }
+ selection = index;
+ redraw();
+ update();
+ dragDetect(event);
+ }));
addPaintListener (event -> {
GC gc = event.gc;
Color foreground = event.display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet334.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet334.java
index e4fa5b918d..c02b684c2b 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet334.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet334.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
@@ -22,10 +22,10 @@ package org.eclipse.swt.snippets;
import static org.eclipse.swt.events.FocusListener.*;
import static org.eclipse.swt.events.KeyListener.*;
+import static org.eclipse.swt.events.MouseListener.*;
import org.eclipse.swt.*;
import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
@@ -67,12 +67,7 @@ public static void main(String[] arg) {
canvas.addFocusListener(focusGainedAdapter(event-> canvas.redraw()));
canvas.addFocusListener(focusLostAdapter(event-> canvas.redraw()));
- canvas.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- canvas.setFocus();
- }
- });
+ canvas.addMouseListener(mouseDownAdapter(e ->canvas.setFocus()));
Accessible acc = canvas.getAccessible();
acc.addRelation(ACC.RELATION_LABELLED_BY, label.getAccessible());
acc.addAccessibleControlListener(new AccessibleControlAdapter() {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.java
index ee2d39bba1..0c3c7967b4 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet96.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
@@ -105,33 +105,30 @@ public static void main(String[] args) {
}));
// When the user double clicks in the TableCursor, pop up a text editor so that
// they can change the text of the cell.
- cursor.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- final Text text = new Text(cursor, SWT.NONE);
- TableItem row = cursor.getRow();
- int column = cursor.getColumn();
- text.setText(row.getText(column));
- text.addKeyListener(keyPressedAdapter(event -> {
- // close the text editor and copy the data over
- // when the user hits "ENTER"
- if (event.character == SWT.CR) {
- TableItem localRow = cursor.getRow();
- int localColumn = cursor.getColumn();
- localRow.setText(localColumn, text.getText());
- text.dispose();
- }
- // close the text editor when the user hits "ESC"
- if (event.character == SWT.ESC) {
- text.dispose();
- }
- }));
- // close the text editor when the user clicks away
- text.addFocusListener(focusLostAdapter(event-> text.dispose()));
- editor.setEditor(text);
- text.setFocus();
- }
- });
+ cursor.addMouseListener(MouseListener.mouseDownAdapter(e -> {
+ final Text text = new Text(cursor, SWT.NONE);
+ TableItem row = cursor.getRow();
+ int column = cursor.getColumn();
+ text.setText(row.getText(column));
+ text.addKeyListener(keyPressedAdapter(event -> {
+ // close the text editor and copy the data over
+ // when the user hits "ENTER"
+ if (event.character == SWT.CR) {
+ TableItem localRow = cursor.getRow();
+ int localColumn = cursor.getColumn();
+ localRow.setText(localColumn, text.getText());
+ text.dispose();
+ }
+ // close the text editor when the user hits "ESC"
+ if (event.character == SWT.ESC) {
+ text.dispose();
+ }
+ }));
+ // close the text editor when the user clicks away
+ text.addFocusListener(focusLostAdapter(event -> text.dispose()));
+ editor.setEditor(text);
+ text.setFocus();
+ }));
// Show the TableCursor when the user releases the "SHIFT" or "CTRL" key.
// This signals the end of the multiple selection task.

Back to the top