Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2017-03-29 09:34:39 +0000
committerAlexander Kurtakov2017-03-30 11:25:37 +0000
commitc24a966f051c3a7a52ef30ecd08769714d0b86ee (patch)
tree9dce7626511ba7e7d3601e4905f7ea0ee7ef9778 /examples
parent421056971ab86c3fe5f5ba7b4494de4335069b2c (diff)
downloadeclipse.platform.swt-c24a966f051c3a7a52ef30ecd08769714d0b86ee.tar.gz
eclipse.platform.swt-c24a966f051c3a7a52ef30ecd08769714d0b86ee.tar.xz
eclipse.platform.swt-c24a966f051c3a7a52ef30ecd08769714d0b86ee.zip
Bug 509086 - Use lambda helper methods in org.eclipse.swt.examples -
Part 4 This change contains also renaming of several internal variables to avoid syntax errors because of redefinition of variables. Also changes SelectionAdapter type in FileViewer, Tab and TextEditor classes to SelectionListener Also several variable renames in /layoutexample/Tab Change-Id: Ie90714bd17f990a2d9e8c7c2a2dc02d1078478ce 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/clipboard/ClipboardExample.java445
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java330
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java71
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/Tab.java266
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java729
5 files changed, 704 insertions, 1137 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java
index ea1ad23b2b..a586739848 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.swt.examples.clipboard;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
@@ -20,8 +22,6 @@ import org.eclipse.swt.dnd.ImageTransfer;
import org.eclipse.swt.dnd.RTFTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
@@ -172,18 +172,15 @@ void createTextTransfer(Composite copyParent, Composite pasteParent) {
copyText.setLayoutData(data);
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String data = copyText.getText();
- if (data.length() > 0) {
- status.setText("");
- clipboard.setContents(new Object[] {data}, new Transfer[] {TextTransfer.getInstance()});
- } else {
- status.setText("No text to copy");
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ String textData = copyText.getText();
+ if (textData.length() > 0) {
+ status.setText("");
+ clipboard.setContents(new Object[] {textData}, new Transfer[] {TextTransfer.getInstance()});
+ } else {
+ status.setText("No text to copy");
}
- });
+ }));
l = new Label(pasteParent, SWT.NONE);
l.setText("TextTransfer:"); //$NON-NLS-1$
@@ -194,18 +191,15 @@ void createTextTransfer(Composite copyParent, Composite pasteParent) {
pasteText.setLayoutData(data);
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String data = (String)clipboard.getContents(TextTransfer.getInstance());
- if (data != null && data.length() > 0) {
- status.setText("");
- pasteText.setText("begin paste>"+data+"<end paste");
- } else {
- status.setText("No text to paste");
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ String textData = (String)clipboard.getContents(TextTransfer.getInstance());
+ if (textData != null && textData.length() > 0) {
+ status.setText("");
+ pasteText.setText("begin paste>"+textData+"<end paste");
+ } else {
+ status.setText("No text to paste");
}
- });
+ }));
}
void createRTFTransfer(Composite copyParent, Composite pasteParent){
// RTF Transfer
@@ -219,38 +213,35 @@ void createRTFTransfer(Composite copyParent, Composite pasteParent){
copyRtfText.setLayoutData(data);
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String data = copyRtfText.getText();
- if (data.length() > 0) {
- status.setText("");
- StringBuffer buffer = new StringBuffer();
- buffer.append("{\\rtf1\\ansi\\uc1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i ");
- for (int i = 0; i < data.length(); i++) {
- char ch = data.charAt(i);
- if (ch > 0xFF) {
- buffer.append("\\u");
- buffer.append(Integer.toString((short) ch));
- buffer.append('?');
- } else {
- if (ch == '}' || ch == '{' || ch == '\\') {
- buffer.append('\\');
- }
- buffer.append(ch);
- if (ch == '\n') buffer.append("\\par ");
- if (ch == '\r' && (i - 1 == data.length() || data.charAt(i + 1) != '\n')) {
- buffer.append("\\par ");
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ String textData = copyRtfText.getText();
+ if (textData.length() > 0) {
+ status.setText("");
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("{\\rtf1\\ansi\\uc1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i ");
+ for (int i = 0; i < textData.length(); i++) {
+ char ch = textData.charAt(i);
+ if (ch > 0xFF) {
+ buffer.append("\\u");
+ buffer.append(Integer.toString((short) ch));
+ buffer.append('?');
+ } else {
+ if (ch == '}' || ch == '{' || ch == '\\') {
+ buffer.append('\\');
+ }
+ buffer.append(ch);
+ if (ch == '\n') buffer.append("\\par ");
+ if (ch == '\r' && (i - 1 == textData.length() || textData.charAt(i + 1) != '\n')) {
+ buffer.append("\\par ");
}
}
- buffer.append("}");
- clipboard.setContents(new Object[] {buffer.toString()}, new Transfer[] {RTFTransfer.getInstance()});
- } else {
- status.setText("No RTF to copy");
}
+ buffer.append("}");
+ clipboard.setContents(new Object[] {buffer.toString()}, new Transfer[] {RTFTransfer.getInstance()});
+ } else {
+ status.setText("No RTF to copy");
}
- });
+ }));
l = new Label(pasteParent, SWT.NONE);
l.setText("RTFTransfer:"); //$NON-NLS-1$
@@ -261,18 +252,15 @@ void createRTFTransfer(Composite copyParent, Composite pasteParent){
pasteRtfText.setLayoutData(data);
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String data = (String)clipboard.getContents(RTFTransfer.getInstance());
- if (data != null && data.length() > 0) {
- status.setText("");
- pasteRtfText.setText("start paste>"+data+"<end paste");
- } else {
- status.setText("No RTF to paste");
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ String textData = (String)clipboard.getContents(RTFTransfer.getInstance());
+ if (textData != null && textData.length() > 0) {
+ status.setText("");
+ pasteRtfText.setText("start paste>"+textData+"<end paste");
+ } else {
+ status.setText("No RTF to paste");
}
- });
+ }));
}
void createHTMLTransfer(Composite copyParent, Composite pasteParent){
// HTML Transfer
@@ -286,18 +274,15 @@ void createHTMLTransfer(Composite copyParent, Composite pasteParent){
copyHtmlText.setLayoutData(data);
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String data = copyHtmlText.getText();
- if (data.length() > 0) {
- status.setText("");
- clipboard.setContents(new Object[] {data}, new Transfer[] {HTMLTransfer.getInstance()});
- } else {
- status.setText("No HTML to copy");
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ String textData = copyHtmlText.getText();
+ if (textData.length() > 0) {
+ status.setText("");
+ clipboard.setContents(new Object[] {textData}, new Transfer[] {HTMLTransfer.getInstance()});
+ } else {
+ status.setText("No HTML to copy");
}
- });
+ }));
l = new Label(pasteParent, SWT.NONE);
l.setText("HTMLTransfer:"); //$NON-NLS-1$
@@ -308,18 +293,15 @@ void createHTMLTransfer(Composite copyParent, Composite pasteParent){
pasteHtmlText.setLayoutData(data);
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String data = (String)clipboard.getContents(HTMLTransfer.getInstance());
- if (data != null && data.length() > 0) {
- status.setText("");
- pasteHtmlText.setText("start paste>"+data+"<end paste");
- } else {
- status.setText("No HTML to paste");
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ String textData = (String)clipboard.getContents(HTMLTransfer.getInstance());
+ if (textData != null && textData.length() > 0) {
+ status.setText("");
+ pasteHtmlText.setText("start paste>"+textData+"<end paste");
+ } else {
+ status.setText("No HTML to paste");
}
- });
+ }));
}
void createFileTransfer(Composite copyParent, Composite pasteParent){
//File Transfer
@@ -338,55 +320,46 @@ void createFileTransfer(Composite copyParent, Composite pasteParent){
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Select file(s)");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
- String result = dialog.open();
- if (result != null && result.length() > 0){
- String separator = System.getProperty("file.separator");
- String path = dialog.getFilterPath();
- String[] names = dialog.getFileNames();
- for (String name : names) {
- TableItem item = new TableItem(copyFileTable, SWT.NONE);
- item.setText(path+separator+name);
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
+ String result = dialog.open();
+ if (result != null && result.length() > 0){
+ String separator = System.getProperty("file.separator");
+ String path = dialog.getFilterPath();
+ String[] names = dialog.getFileNames();
+ for (String name : names) {
+ TableItem item = new TableItem(copyFileTable, SWT.NONE);
+ item.setText(path+separator+name);
}
}
- });
+ }));
b = new Button(copyParent, SWT.PUSH);
b.setText("Select directory");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
- String result = dialog.open();
- if (result != null && result.length() > 0){
- //copyFileTable.removeAll();
- TableItem item = new TableItem(copyFileTable, SWT.NONE);
- item.setText(result);
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
+ String result = dialog.open();
+ if (result != null && result.length() > 0){
+ //copyFileTable.removeAll();
+ TableItem item = new TableItem(copyFileTable, SWT.NONE);
+ item.setText(result);
}
- });
+ }));
b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- TableItem[] items = copyFileTable.getItems();
- if (items.length > 0){
- status.setText("");
- String[] data = new String[items.length];
- for (int i = 0; i < data.length; i++) {
- data[i] = items[i].getText();
- }
- clipboard.setContents(new Object[] {data}, new Transfer[] {FileTransfer.getInstance()});
- } else {
- status.setText("No file to copy");
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ TableItem[] items = copyFileTable.getItems();
+ if (items.length > 0){
+ status.setText("");
+ String[] itemsData = new String[items.length];
+ for (int i = 0; i < itemsData.length; i++) {
+ itemsData[i] = items[i].getText();
}
+ clipboard.setContents(new Object[] {itemsData}, new Transfer[] {FileTransfer.getInstance()});
+ } else {
+ status.setText("No file to copy");
}
- });
+ }));
l = new Label(pasteParent, SWT.NONE);
l.setText("FileTransfer:"); //$NON-NLS-1$
@@ -397,22 +370,19 @@ void createFileTransfer(Composite copyParent, Composite pasteParent){
pasteFileTable.setLayoutData(data);
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String[] data = (String[])clipboard.getContents(FileTransfer.getInstance());
- if (data != null && data.length > 0) {
- status.setText("");
- pasteFileTable.removeAll();
- for (String element : data) {
- TableItem item = new TableItem(pasteFileTable, SWT.NONE);
- item.setText(element);
- }
- } else {
- status.setText("No file to paste");
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ String[] textData = (String[])clipboard.getContents(FileTransfer.getInstance());
+ if (textData != null && textData.length > 0) {
+ status.setText("");
+ pasteFileTable.removeAll();
+ for (String element : textData) {
+ TableItem item = new TableItem(pasteFileTable, SWT.NONE);
+ item.setText(element);
}
+ } else {
+ status.setText("No file to paste");
}
- });
+ }));
}
void createImageTransfer(Composite copyParent, Composite pasteParent){
@@ -472,48 +442,42 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
});
Button openButton = new Button(copyParent, SWT.PUSH);
openButton.setText("Open Image");
- openButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- FileDialog dialog = new FileDialog (shell, SWT.OPEN);
- dialog.setText("Open an image file or cancel");
- String string = dialog.open ();
- if (string != null) {
- if (copyImage[0] != null) {
- System.out.println("CopyImage");
- copyImage[0].dispose();
- }
- copyImage[0] = new Image(e.display, string);
- copyVBar.setEnabled(true);
- copyHBar.setEnabled(true);
- copyOrigin.x = 0; copyOrigin.y = 0;
- Rectangle rect = copyImage[0].getBounds();
- Rectangle client = copyImageCanvas.getClientArea();
- copyHBar.setMaximum(rect.width);
- copyVBar.setMaximum(rect.height);
- copyHBar.setThumb(Math.min(rect.width, client.width));
- copyVBar.setThumb(Math.min(rect.height, client.height));
- copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
- copyVBar.setSelection(0);
- copyHBar.setSelection(0);
- copyImageCanvas.redraw();
+ openButton.addSelectionListener(widgetSelectedAdapter(e -> {
+ FileDialog dialog = new FileDialog (shell, SWT.OPEN);
+ dialog.setText("Open an image file or cancel");
+ String string = dialog.open ();
+ if (string != null) {
+ if (copyImage[0] != null) {
+ System.out.println("CopyImage");
+ copyImage[0].dispose();
}
+ copyImage[0] = new Image(e.display, string);
+ copyVBar.setEnabled(true);
+ copyHBar.setEnabled(true);
+ copyOrigin.x = 0; copyOrigin.y = 0;
+ Rectangle rect = copyImage[0].getBounds();
+ Rectangle client = copyImageCanvas.getClientArea();
+ copyHBar.setMaximum(rect.width);
+ copyVBar.setMaximum(rect.height);
+ copyHBar.setThumb(Math.min(rect.width, client.width));
+ copyVBar.setThumb(Math.min(rect.height, client.height));
+ copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
+ copyVBar.setSelection(0);
+ copyHBar.setSelection(0);
+ copyImageCanvas.redraw();
}
- });
+ }));
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (copyImage[0] != null) {
- status.setText("");
- // Fetch ImageData at current zoom and save in the clip-board.
- clipboard.setContents(new Object[] {copyImage[0].getImageDataAtCurrentZoom()}, new Transfer[] {ImageTransfer.getInstance()});
- } else {
- status.setText("No image to copy");
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ if (copyImage[0] != null) {
+ status.setText("");
+ // Fetch ImageData at current zoom and save in the clip-board.
+ clipboard.setContents(new Object[] {copyImage[0].getImageDataAtCurrentZoom()}, new Transfer[] {ImageTransfer.getInstance()});
+ } else {
+ status.setText("No image to copy");
}
- });
+ }));
final Image[] pasteImage = new Image[] {null};
l = new Label(pasteParent, SWT.NONE);
@@ -564,36 +528,33 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
});
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- ImageData data =(ImageData)clipboard.getContents(ImageTransfer.getInstance());
- if (data != null) {
- if (pasteImage[0] != null) {
- System.out.println("PasteImage");
- pasteImage[0].dispose();
- }
- status.setText("");
- // Consume the ImageData at current zoom as-is.
- pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(data));
- pasteVBar.setEnabled(true);
- pasteHBar.setEnabled(true);
- pasteOrigin.x = 0; pasteOrigin.y = 0;
- Rectangle rect = pasteImage[0].getBounds();
- Rectangle client = pasteImageCanvas.getClientArea();
- pasteHBar.setMaximum(rect.width);
- pasteVBar.setMaximum(rect.height);
- pasteHBar.setThumb(Math.min(rect.width, client.width));
- pasteVBar.setThumb(Math.min(rect.height, client.height));
- pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
- pasteVBar.setSelection(0);
- pasteHBar.setSelection(0);
- pasteImageCanvas.redraw();
- } else {
- status.setText("No image to paste");
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ ImageData imageData =(ImageData)clipboard.getContents(ImageTransfer.getInstance());
+ if (imageData != null) {
+ if (pasteImage[0] != null) {
+ System.out.println("PasteImage");
+ pasteImage[0].dispose();
}
+ status.setText("");
+ // Consume the ImageData at current zoom as-is.
+ pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData));
+ pasteVBar.setEnabled(true);
+ pasteHBar.setEnabled(true);
+ pasteOrigin.x = 0; pasteOrigin.y = 0;
+ Rectangle rect = pasteImage[0].getBounds();
+ Rectangle client = pasteImageCanvas.getClientArea();
+ pasteHBar.setMaximum(rect.width);
+ pasteVBar.setMaximum(rect.height);
+ pasteHBar.setThumb(Math.min(rect.width, client.width));
+ pasteVBar.setThumb(Math.min(rect.height, client.height));
+ pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
+ pasteVBar.setSelection(0);
+ pasteHBar.setSelection(0);
+ pasteImageCanvas.redraw();
+ } else {
+ status.setText("No image to paste");
}
- });
+ }));
}
void createMyTransfer(Composite copyParent, Composite pasteParent){
// MyType Transfer
@@ -605,28 +566,13 @@ void createControlTransfer(Composite parent){
l.setText("Text:");
Button b = new Button(parent, SWT.PUSH);
b.setText("Cut");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- text.cut();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> text.cut()));
b = new Button(parent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- text.copy();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> text.copy()));
b = new Button(parent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- text.paste();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> text.paste()));
text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = HSIZE;
@@ -637,28 +583,13 @@ void createControlTransfer(Composite parent){
l.setText("Combo:");
b = new Button(parent, SWT.PUSH);
b.setText("Cut");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- combo.cut();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> combo.cut()));
b = new Button(parent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- combo.copy();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> combo.copy()));
b = new Button(parent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- combo.paste();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> combo.paste()));
combo = new Combo(parent, SWT.NONE);
combo.setItems("Item 1", "Item 2", "Item 3", "A longer Item");
combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -667,28 +598,13 @@ void createControlTransfer(Composite parent){
l.setText("StyledText:");
b = new Button(parent, SWT.PUSH);
b.setText("Cut");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- styledText.cut();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> styledText.cut()));
b = new Button(parent, SWT.PUSH);
b.setText("Copy");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- styledText.copy();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> styledText.copy()));
b = new Button(parent, SWT.PUSH);
b.setText("Paste");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- styledText.paste();
- }
- });
+ b.addSelectionListener(widgetSelectedAdapter(e -> styledText.paste()));
styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = HSIZE;
@@ -702,15 +618,12 @@ void createAvailableTypes(Composite parent){
list.setLayoutData(data);
Button b = new Button(parent, SWT.PUSH);
b.setText("Get Available Types");
- b.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- list.removeAll();
- String[] names = clipboard.getAvailableTypeNames();
- for (String name : names) {
- list.add(name);
- }
+ b.addSelectionListener(widgetSelectedAdapter(e -> {
+ list.removeAll();
+ String[] names = clipboard.getAvailableTypeNames();
+ for (String name : names) {
+ list.add(name);
}
- });
+ }));
}
} \ No newline at end of file
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java
index 910988eb5d..3e89da63cf 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java
@@ -12,6 +12,9 @@
package org.eclipse.swt.examples.controlexample;
+import static org.eclipse.swt.events.SelectionListener.widgetDefaultSelectedAdapter;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import java.lang.reflect.Method;
import org.eclipse.swt.SWT;
@@ -313,24 +316,21 @@ abstract class Tab {
* both these operations but typically only do work when a RADIO
* button is selected.
*/
- SelectionListener selectionListener = new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- if ((event.widget.getStyle () & SWT.RADIO) != 0) {
- if (!((Button) event.widget).getSelection ()) return;
- }
- if (!handleTextDirection (event.widget)) {
- recreateExampleWidgets ();
- if (rtlSupport ()) {
- /* Reflect the base direction falls back to the default (i.e. orientation). */
- ltrDirectionButton.setSelection (false);
- rtlDirectionButton.setSelection (false);
- autoDirectionButton.setSelection (false);
- defaultDirectionButton.setSelection (true);
- }
+ SelectionListener selectionListener = widgetSelectedAdapter(event -> {
+ if ((event.widget.getStyle () & SWT.RADIO) != 0) {
+ if (!((Button) event.widget).getSelection ()) return;
+ }
+ if (!handleTextDirection (event.widget)) {
+ recreateExampleWidgets ();
+ if (rtlSupport ()) {
+ /* Reflect the base direction falls back to the default (i.e. orientation). */
+ ltrDirectionButton.setSelection (false);
+ rtlDirectionButton.setSelection (false);
+ autoDirectionButton.setSelection (false);
+ defaultDirectionButton.setSelection (true);
}
}
- };
+ });
Control [] children = styleGroup.getChildren ();
for (Control child : children) {
if (child instanceof Button) {
@@ -373,20 +373,17 @@ abstract class Tab {
final Button setGetButton = new Button (otherGroup, SWT.PUSH);
setGetButton.setText (ControlExample.getResourceString ("Set_Get"));
setGetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
- setGetButton.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected (SelectionEvent e) {
- if (getExampleWidgets().length > 0) {
- if (setGetDialog == null) {
- setGetDialog = createSetGetDialog(methodNames);
- }
- Point pt = setGetButton.getLocation();
- pt = display.map(setGetButton.getParent(), null, pt);
- setGetDialog.setLocation(pt.x, pt.y);
- setGetDialog.open();
+ setGetButton.addSelectionListener (widgetSelectedAdapter(e -> {
+ if (getExampleWidgets().length > 0) {
+ if (setGetDialog == null) {
+ setGetDialog = createSetGetDialog(methodNames);
}
+ Point pt = setGetButton.getLocation();
+ pt = display.map(setGetButton.getParent(), null, pt);
+ setGetDialog.setLocation(pt.x, pt.y);
+ setGetDialog.open();
}
- });
+ }));
}
}
@@ -429,24 +426,9 @@ abstract class Tab {
/* Add listeners to set/reset colors and fonts. */
colorDialog = new ColorDialog (shell);
fontDialog = new FontDialog (shell);
- colorAndFontTable.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetDefaultSelected(SelectionEvent event) {
- changeFontOrColor (colorAndFontTable.getSelectionIndex());
- }
- });
- changeButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- changeFontOrColor (colorAndFontTable.getSelectionIndex());
- }
- });
- defaultsButton.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- resetColorsAndFonts ();
- }
- });
+ colorAndFontTable.addSelectionListener(widgetDefaultSelectedAdapter(event -> changeFontOrColor (colorAndFontTable.getSelectionIndex())));
+ changeButton.addSelectionListener(widgetSelectedAdapter(event -> changeFontOrColor (colorAndFontTable.getSelectionIndex())));
+ defaultsButton.addSelectionListener(widgetSelectedAdapter(e -> resetColorsAndFonts ()));
shell.addDisposeListener(event -> {
if (foregroundColor != null) foregroundColor.dispose();
if (backgroundColor != null) backgroundColor.dispose();
@@ -537,30 +519,10 @@ abstract class Tab {
popupMenuButton.setText(ControlExample.getResourceString("PopupMenu"));
/* Add the listeners */
- enabledButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleWidgetEnabled ();
- }
- });
- visibleButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleWidgetVisibility ();
- }
- });
- backgroundImageButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleWidgetBackgroundImage ();
- }
- });
- popupMenuButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleWidgetPopupMenu ();
- }
- });
+ enabledButton.addSelectionListener (widgetSelectedAdapter(event -> setExampleWidgetEnabled ()));
+ visibleButton.addSelectionListener (widgetSelectedAdapter(event -> setExampleWidgetVisibility ()));
+ backgroundImageButton.addSelectionListener (widgetSelectedAdapter(event -> setExampleWidgetBackgroundImage ()));
+ popupMenuButton.addSelectionListener (widgetSelectedAdapter(event -> setExampleWidgetPopupMenu ()));
/* Set the default state */
enabledButton.setSelection(true);
@@ -588,24 +550,9 @@ abstract class Tab {
backgroundModeColorButton.setText(ControlExample.getResourceString("BackgroundColor"));
/* Add the listeners */
- backgroundModeCombo.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleGroupBackgroundMode ();
- }
- });
- backgroundModeImageButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleGroupBackgroundImage ();
- }
- });
- backgroundModeColorButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleGroupBackgroundColor ();
- }
- });
+ backgroundModeCombo.addSelectionListener (widgetSelectedAdapter(event -> setExampleGroupBackgroundMode ()));
+ backgroundModeImageButton.addSelectionListener (widgetSelectedAdapter(event -> setExampleGroupBackgroundImage ()));
+ backgroundModeColorButton.addSelectionListener (widgetSelectedAdapter(event -> setExampleGroupBackgroundColor ()));
/* Set the default state */
backgroundModeCombo.setText(backgroundModeCombo.getItem(0));
@@ -635,19 +582,16 @@ abstract class Tab {
doitCombo.setItems ("", "true", "false");
if ((setFieldsMask & DOIT) != 0) doitCombo.setText(Boolean.toString(setFieldsEvent.doit));
doitCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
- doitCombo.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String newValue = doitCombo.getText();
- if (newValue.length() == 0) {
- setFieldsMask &= ~DOIT;
- } else {
- setFieldsEvent.type = eventType;
- setFieldsEvent.doit = newValue.equals("true");
- setFieldsMask |= DOIT;
- }
+ doitCombo.addSelectionListener(widgetSelectedAdapter(e -> {
+ String newValue = doitCombo.getText();
+ if (newValue.length() == 0) {
+ setFieldsMask &= ~DOIT;
+ } else {
+ setFieldsEvent.type = eventType;
+ setFieldsEvent.doit = newValue.equals("true");
+ setFieldsMask |= DOIT;
}
- });
+ }));
}
if ((fields & DETAIL) != 0) {
@@ -659,24 +603,21 @@ abstract class Tab {
detailCombo.setVisibleItemCount(detailCombo.getItemCount());
if ((setFieldsMask & DETAIL) != 0) detailCombo.setText (DETAIL_CONSTANTS[detailType][setFieldsEvent.detail]);
detailCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
- detailCombo.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String newValue = detailCombo.getText();
- if (newValue.length() == 0) {
- setFieldsMask &= ~DETAIL;
- } else {
- setFieldsEvent.type = eventType;
- for (int i = 0; i < DETAIL_VALUES.length; i += 2) {
- if (newValue.equals (DETAIL_VALUES [i])) {
- setFieldsEvent.detail = ((Integer) DETAIL_VALUES [i + 1]).intValue();
- break;
- }
+ detailCombo.addSelectionListener(widgetSelectedAdapter(e -> {
+ String newValue = detailCombo.getText();
+ if (newValue.length() == 0) {
+ setFieldsMask &= ~DETAIL;
+ } else {
+ setFieldsEvent.type = eventType;
+ for (int i = 0; i < DETAIL_VALUES.length; i += 2) {
+ if (newValue.equals (DETAIL_VALUES [i])) {
+ setFieldsEvent.detail = ((Integer) DETAIL_VALUES [i + 1]).intValue();
+ break;
}
- setFieldsMask |= DETAIL;
}
+ setFieldsMask |= DETAIL;
}
- });
+ }));
}
if ((fields & TEXT) != 0) {
@@ -773,14 +714,11 @@ abstract class Tab {
GridData data = new GridData (70, SWT.DEFAULT);
data.horizontalAlignment = SWT.RIGHT;
ok.setLayoutData (data);
- ok.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- EVENT_INFO[index].setFields = setFieldsMask;
- EVENT_INFO[index].event = setFieldsEvent;
- dialog.dispose();
- }
- });
+ ok.addSelectionListener (widgetSelectedAdapter(e -> {
+ EVENT_INFO[index].setFields = setFieldsMask;
+ EVENT_INFO[index].event = setFieldsEvent;
+ dialog.dispose();
+ }));
dialog.setDefaultButton(ok);
dialog.pack();
@@ -854,47 +792,38 @@ abstract class Tab {
Button selectAll = new Button (dialog, SWT.PUSH);
selectAll.setText(ControlExample.getResourceString ("Select_All"));
selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
- selectAll.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- TableItem [] items = table.getItems();
- for (int i = 0; i < EVENT_INFO.length; i++) {
- items[i].setChecked(true);
- }
- for (int i = 0; i < customNames.length; i++) {
- items[EVENT_INFO.length + i].setChecked(true);
- }
+ selectAll.addSelectionListener (widgetSelectedAdapter(e -> {
+ TableItem [] items = table.getItems();
+ for (int i = 0; i < EVENT_INFO.length; i++) {
+ items[i].setChecked(true);
}
- });
+ for (int i = 0; i < customNames.length; i++) {
+ items[EVENT_INFO.length + i].setChecked(true);
+ }
+ }));
Button deselectAll = new Button (dialog, SWT.PUSH);
deselectAll.setText(ControlExample.getResourceString ("Deselect_All"));
deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
- deselectAll.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- TableItem [] items = table.getItems();
- for (int i = 0; i < EVENT_INFO.length; i++) {
- items[i].setChecked(false);
- }
- for (int i = 0; i < customNames.length; i++) {
- items[EVENT_INFO.length + i].setChecked(false);
- }
+ deselectAll.addSelectionListener (widgetSelectedAdapter(e -> {
+ TableItem [] items = table.getItems();
+ for (int i = 0; i < EVENT_INFO.length; i++) {
+ items[i].setChecked(false);
}
- });
+ for (int i = 0; i < customNames.length; i++) {
+ items[EVENT_INFO.length + i].setChecked(false);
+ }
+ }));
final Button editEvent = new Button (dialog, SWT.PUSH);
editEvent.setText (ControlExample.getResourceString ("Edit_Event"));
editEvent.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
- editEvent.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected (SelectionEvent e) {
- Point pt = editEvent.getLocation();
- pt = e.display.map(editEvent, null, pt);
- int index = table.getSelectionIndex();
- if (getExampleWidgets().length > 0 && index != -1) {
- createEditEventDialog(dialog, pt.x, pt.y, index);
- }
+ editEvent.addSelectionListener (widgetSelectedAdapter(e -> {
+ Point pt = editEvent.getLocation();
+ pt = e.display.map(editEvent, null, pt);
+ int index = table.getSelectionIndex();
+ if (getExampleWidgets().length > 0 && index != -1) {
+ createEditEventDialog(dialog, pt.x, pt.y, index);
}
- });
+ }));
editEvent.setEnabled(false);
table.addSelectionListener(new SelectionAdapter() {
@Override
@@ -924,19 +853,16 @@ abstract class Tab {
ok.setText(ControlExample.getResourceString ("OK"));
dialog.setDefaultButton(ok);
ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
- ok.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- TableItem [] items = table.getItems();
- for (int i = 0; i < EVENT_INFO.length; i++) {
- eventsFilter[i] = items[i].getChecked();
- }
- for (int i = 0; i < customNames.length; i++) {
- eventsFilter[EVENT_INFO.length + i] = items[EVENT_INFO.length + i].getChecked();
- }
- dialog.dispose();
+ ok.addSelectionListener (widgetSelectedAdapter(e -> {
+ TableItem [] items = table.getItems();
+ for (int i = 0; i < EVENT_INFO.length; i++) {
+ eventsFilter[i] = items[i].getChecked();
}
- });
+ for (int i = 0; i < customNames.length; i++) {
+ eventsFilter[EVENT_INFO.length + i] = items[EVENT_INFO.length + i].getChecked();
+ }
+ dialog.dispose();
+ }));
dialog.pack ();
/*
* If the preferred size of the dialog is too tall for the display,
@@ -970,38 +896,27 @@ abstract class Tab {
*/
Button listenersButton = new Button (listenersGroup, SWT.PUSH);
listenersButton.setText (ControlExample.getResourceString ("Select_Listeners"));
- listenersButton.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected (SelectionEvent e) {
- createListenerSelectionDialog ();
- recreateExampleWidgets ();
- }
- });
+ listenersButton.addSelectionListener (widgetSelectedAdapter(e -> {
+ createListenerSelectionDialog ();
+ recreateExampleWidgets ();
+ }));
/*
* Create the checkbox to specify whether typed or untyped events are displayed in the log.
*/
final Button untypedEventsCheckbox = new Button (listenersGroup, SWT.CHECK);
untypedEventsCheckbox.setText (ControlExample.getResourceString ("UntypedEvents"));
- untypedEventsCheckbox.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- untypedEvents = untypedEventsCheckbox.getSelection ();
- }
- });
+ untypedEventsCheckbox.addSelectionListener (widgetSelectedAdapter(e -> untypedEvents = untypedEventsCheckbox.getSelection ()));
/*
* Create the checkbox to add/remove listeners to/from the example widgets.
*/
final Button listenCheckbox = new Button (listenersGroup, SWT.CHECK);
listenCheckbox.setText (ControlExample.getResourceString ("Listen"));
- listenCheckbox.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- logging = listenCheckbox.getSelection ();
- recreateExampleWidgets ();
- }
- });
+ listenCheckbox.addSelectionListener (widgetSelectedAdapter(e -> {
+ logging = listenCheckbox.getSelection ();
+ recreateExampleWidgets ();
+ }));
/*
* Create the button to clear the text.
@@ -1009,12 +924,7 @@ abstract class Tab {
Button clearButton = new Button (listenersGroup, SWT.PUSH);
clearButton.setText (ControlExample.getResourceString ("Clear"));
clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
- clearButton.addSelectionListener (new SelectionAdapter() {
- @Override
- public void widgetSelected (SelectionEvent e) {
- eventConsole.setText ("");
- }
- });
+ clearButton.addSelectionListener (widgetSelectedAdapter(e -> eventConsole.setText ("")));
/* Initialize the eventsFilter to log all events. */
int customEventCount = getCustomEventNames ().length;
@@ -1058,34 +968,21 @@ abstract class Tab {
nameCombo.setText(methodNames[0]);
nameCombo.setVisibleItemCount(methodNames.length);
nameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
- nameCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- resetLabels();
- }
- });
+ nameCombo.addSelectionListener(widgetSelectedAdapter(e -> resetLabels()));
returnTypeLabel = new Label(dialog, SWT.NONE);
returnTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
setButton = new Button(dialog, SWT.PUSH);
setButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
- setButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- setValue();
- setText.selectAll();
- setText.setFocus();
- }
- });
+ setButton.addSelectionListener(widgetSelectedAdapter(e -> {
+ setValue();
+ setText.selectAll();
+ setText.setFocus();
+ }));
setText = new Text(dialog, SWT.SINGLE | SWT.BORDER);
setText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
getButton = new Button(dialog, SWT.PUSH);
getButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
- getButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- getValue();
- }
- });
+ getButton.addSelectionListener(widgetSelectedAdapter(e -> getValue()));
getText = new Text(dialog, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = 240;
@@ -1312,12 +1209,7 @@ abstract class Tab {
fillVButton.setText (ControlExample.getResourceString("Fill_Y"));
/* Add the listeners */
- SelectionAdapter selectionListener = new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- setExampleWidgetSize ();
- }
- };
+ SelectionListener selectionListener = widgetSelectedAdapter(event -> setExampleWidgetSize ());
preferredButton.addSelectionListener(selectionListener);
tooSmallButton.addSelectionListener(selectionListener);
smallButton.addSelectionListener(selectionListener);
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java
index 2245f907f7..c830f4f33c 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java
@@ -11,6 +11,8 @@
package org.eclipse.swt.examples.fileviewer;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -279,21 +281,11 @@ public class FileViewer {
final MenuItem simulateItem = new MenuItem(menu, SWT.CHECK);
simulateItem.setText(getResourceString("menu.File.SimulateOnly.text"));
simulateItem.setSelection(simulateOnly);
- simulateItem.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- simulateOnly = simulateItem.getSelection();
- }
- });
+ simulateItem.addSelectionListener(widgetSelectedAdapter(e -> simulateOnly = simulateItem.getSelection()));
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(getResourceString("menu.File.Close.text"));
- item.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- shell.close();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(e -> shell.close()));
}
/**
@@ -309,16 +301,13 @@ public class FileViewer {
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(getResourceString("menu.Help.About.text"));
- item.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
- box.setText(getResourceString("dialog.About.title"));
- box.setMessage(getResourceString("dialog.About.description",
- new Object[] { System.getProperty("os.name") }));
- box.open();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(e -> {
+ MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
+ box.setText(getResourceString("dialog.About.title"));
+ box.setMessage(getResourceString("dialog.About.description",
+ new Object[] { System.getProperty("os.name") }));
+ box.open();
+ }));
}
/**
@@ -334,30 +323,17 @@ public class FileViewer {
item = new ToolItem(toolBar, SWT.PUSH);
item.setImage(iconCache.stockImages[iconCache.cmdParent]);
item.setToolTipText(getResourceString("tool.Parent.tiptext"));
- item.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- doParent();
- }
- });
+ item.addSelectionListener(widgetSelectedAdapter(e -> doParent()));
item = new ToolItem(toolBar, SWT.PUSH);
item.setImage(iconCache.stockImages[iconCache.cmdRefresh]);
item.setToolTipText(getResourceString("tool.Refresh.tiptext"));
- item.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent e) {
- doRefresh();
- }
+ item.addSelectionListener(widgetSelectedAdapter(e -> doRefresh()));
+ SelectionListener unimplementedListener = widgetSelectedAdapter(e -> {
+ MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
+ box.setText(getResourceString("dialog.NotImplemented.title"));
+ box.setMessage(getResourceString("dialog.ActionNotImplemented.description"));
+ box.open();
});
- SelectionAdapter unimplementedListener = new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
- box.setText(getResourceString("dialog.NotImplemented.title"));
- box.setMessage(getResourceString("dialog.ActionNotImplemented.description"));
- box.open();
- }
- };
item = new ToolItem(toolBar, SWT.SEPARATOR);
item = new ToolItem(toolBar, SWT.PUSH);
@@ -1690,13 +1666,10 @@ public class FileViewer {
cancelButton = new Button(shell, SWT.PUSH);
cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_FILL));
cancelButton.setText(getResourceString("progressDialog.cancelButton.text"));
- cancelButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- isCancelled = true;
- cancelButton.setEnabled(false);
- }
- });
+ cancelButton.addSelectionListener(widgetSelectedAdapter(e -> {
+ isCancelled = true;
+ cancelButton.setEnabled(false);
+ }));
}
/**
* Sets the detail text to show the filename along with a string
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/Tab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/Tab.java
index 1bae1e76b4..20facd3e7b 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/Tab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/Tab.java
@@ -11,6 +11,8 @@
package org.eclipse.swt.examples.layoutexample;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import java.util.ArrayList;
import java.util.List;
@@ -19,8 +21,6 @@ import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.TableEditor;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Font;
@@ -100,12 +100,7 @@ abstract class Tab {
final LayoutExample instance;
/* Listeners */
- SelectionListener selectionListener = new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- resetEditors ();
- }
- };
+ SelectionListener selectionListener = widgetSelectedAdapter(e -> resetEditors ());
TraverseListener traverseListener = e -> {
if (e.detail == SWT.TRAVERSE_RETURN) {
@@ -136,155 +131,125 @@ abstract class Tab {
toolBar.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
add = new ToolItem(toolBar, SWT.DROP_DOWN);
add.setText(LayoutExample.getResourceString("Add"));
- add.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (event.detail == SWT.ARROW) {
- ToolItem item = (ToolItem)event.widget;
- ToolBar bar = item.getParent ();
- final Menu menu = new Menu (shell, SWT.POP_UP);
- for (int i = 0; i < OPTIONS.length; i++) {
- final MenuItem newItem = new MenuItem (menu, SWT.RADIO);
- newItem.setText (OPTIONS [i]);
- newItem.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent event) {
- MenuItem menuItem = (MenuItem)event.widget;
- if (menuItem.getSelection ()) {
- Menu menu = menuItem.getParent ();
- prevSelected = menu.indexOf (menuItem);
- String controlType = menuItem.getText ();
- String name = controlType.toLowerCase () + String.valueOf (table.getItemCount ());
- String [] insert = getInsertString (name, controlType);
- if (insert != null) {
- TableItem item = new TableItem (table, SWT.NONE);
- item.setText (insert);
- data.add (insert);
- }
- resetEditors ();
- }
+ add.addSelectionListener (widgetSelectedAdapter(event -> {
+ if (event.detail == SWT.ARROW) {
+ ToolItem item = (ToolItem)event.widget;
+ ToolBar bar = item.getParent ();
+ final Menu menu = new Menu (shell, SWT.POP_UP);
+ for (int i = 0; i < OPTIONS.length; i++) {
+ final MenuItem newItem = new MenuItem (menu, SWT.RADIO);
+ newItem.setText (OPTIONS [i]);
+ newItem.addSelectionListener (widgetSelectedAdapter(e -> {
+ MenuItem menuItem = (MenuItem)e.widget;
+ if (menuItem.getSelection ()) {
+ Menu menuParent = menuItem.getParent ();
+ prevSelected = menuParent.indexOf (menuItem);
+ String controlType = menuItem.getText ();
+ String name = controlType.toLowerCase () + String.valueOf (table.getItemCount ());
+ String [] insert = getInsertString (name, controlType);
+ if (insert != null) {
+ TableItem tableItem = new TableItem (table, SWT.NONE);
+ tableItem.setText (insert);
+ data.add (insert);
}
- });
- newItem.setSelection (i == prevSelected);
- }
- Point pt = display.map (bar, null, event.x, event.y);
- menu.setLocation (pt.x, pt.y);
- menu.setVisible (true);
-
- while (menu != null && !menu.isDisposed () && menu.isVisible ()) {
- if (!display.readAndDispatch ()) {
- display.sleep ();
+ resetEditors ();
}
+ }));
+ newItem.setSelection (i == prevSelected);
+ }
+ Point pt = display.map (bar, null, event.x, event.y);
+ menu.setLocation (pt.x, pt.y);
+ menu.setVisible (true);
+
+ while (menu != null && !menu.isDisposed () && menu.isVisible ()) {
+ if (!display.readAndDispatch ()) {
+ display.sleep ();
}
- menu.dispose ();
- } else {
- String controlType = OPTIONS [prevSelected];
- String name = controlType.toLowerCase () + String.valueOf (table.getItemCount ());
- String [] insert = getInsertString (name, controlType);
- if (insert != null) {
- TableItem item = new TableItem (table, 0);
- item.setText (insert);
- data.add (insert);
- }
- resetEditors ();
}
+ menu.dispose ();
+ } else {
+ String controlType = OPTIONS [prevSelected];
+ String name = controlType.toLowerCase () + String.valueOf (table.getItemCount ());
+ String [] insert = getInsertString (name, controlType);
+ if (insert != null) {
+ TableItem item = new TableItem (table, 0);
+ item.setText (insert);
+ data.add (insert);
+ }
+ resetEditors ();
}
- });
+ }));
new ToolItem(toolBar,SWT.SEPARATOR);
delete = new ToolItem(toolBar, SWT.PUSH);
delete.setText (LayoutExample.getResourceString ("Delete"));
- delete.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- resetEditors ();
- int [] selected = table.getSelectionIndices ();
- table.remove (selected);
- /* Refresh the control indices of the table */
- for (int i = 0; i < table.getItemCount(); i++) {
- TableItem item = table.getItem (i);
- item.setText (0, item.getText (0));
- }
- refreshLayoutComposite ();
- layoutComposite.layout (true);
- layoutGroup.layout (true);
+ delete.addSelectionListener (widgetSelectedAdapter(e -> {
+ resetEditors ();
+ int [] selected = table.getSelectionIndices ();
+ table.remove (selected);
+ /* Refresh the control indices of the table */
+ for (int i = 0; i < table.getItemCount(); i++) {
+ TableItem item = table.getItem (i);
+ item.setText (0, item.getText (0));
}
- });
+ refreshLayoutComposite ();
+ layoutComposite.layout (true);
+ layoutGroup.layout (true);
+ }));
new ToolItem(toolBar,SWT.SEPARATOR);
clear = new ToolItem(toolBar, SWT.PUSH);
clear.setText (LayoutExample.getResourceString ("Clear"));
- clear.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- resetEditors ();
- children = layoutComposite.getChildren ();
- for (Control child : children) {
- child.dispose ();
- }
- table.removeAll ();
- data.clear ();
- children = new Control [0];
- layoutGroup.layout (true);
+ clear.addSelectionListener (widgetSelectedAdapter(e -> {
+ resetEditors ();
+ children = layoutComposite.getChildren ();
+ for (Control child : children) {
+ child.dispose ();
}
- });
+ table.removeAll ();
+ data.clear ();
+ children = new Control [0];
+ layoutGroup.layout (true);
+ }));
toolBar.pack();
new ToolItem (toolBar,SWT.SEPARATOR);
code = new ToolItem (toolBar, SWT.PUSH);
code.setText (LayoutExample.getResourceString ("Generate_Code"));
- code.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- final Shell shell = new Shell();
- shell.setText(LayoutExample.getResourceString("Generated_Code"));
- shell.setLayout(new FillLayout());
- final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
- String layoutCode = generateCode().toString ();
- if (layoutCode.length() == 0) return;
- text.setText(layoutCode);
-
- Menu bar = new Menu(shell, SWT.BAR);
- shell.setMenuBar(bar);
- MenuItem editItem = new MenuItem(bar, SWT.CASCADE);
- editItem.setText(LayoutExample.getResourceString("Edit"));
- Menu menu = new Menu(bar);
- MenuItem select = new MenuItem(menu, SWT.PUSH);
- select.setText(LayoutExample.getResourceString("Select_All"));
- select.setAccelerator(SWT.MOD1 + 'A');
- select.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- text.selectAll();
- }
- });
- MenuItem copy = new MenuItem(menu, SWT.PUSH);
- copy.setText(LayoutExample.getResourceString("Copy"));
- copy.setAccelerator(SWT.MOD1 + 'C');
- copy.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- text.copy();
- }
- });
- MenuItem exit = new MenuItem(menu, SWT.PUSH);
- exit.setText(LayoutExample.getResourceString("Exit"));
- exit.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- shell.close();
- }
- });
- editItem.setMenu(menu);
-
- shell.pack();
- shell.setSize(500, 600);
- shell.open();
- while(!shell.isDisposed())
- if (!display.readAndDispatch()) display.sleep();
- }
- });
+ code.addSelectionListener(widgetSelectedAdapter(e -> {
+ final Shell shell = new Shell();
+ shell.setText(LayoutExample.getResourceString("Generated_Code"));
+ shell.setLayout(new FillLayout());
+ final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
+ String layoutCode = generateCode().toString ();
+ if (layoutCode.length() == 0) return;
+ text.setText(layoutCode);
+
+ Menu bar = new Menu(shell, SWT.BAR);
+ shell.setMenuBar(bar);
+ MenuItem editItem = new MenuItem(bar, SWT.CASCADE);
+ editItem.setText(LayoutExample.getResourceString("Edit"));
+ Menu menu = new Menu(bar);
+ MenuItem select = new MenuItem(menu, SWT.PUSH);
+ select.setText(LayoutExample.getResourceString("Select_All"));
+ select.setAccelerator(SWT.MOD1 + 'A');
+ select.addSelectionListener(widgetSelectedAdapter(event -> text.selectAll()));
+ MenuItem copy = new MenuItem(menu, SWT.PUSH);
+ copy.setText(LayoutExample.getResourceString("Copy"));
+ copy.setAccelerator(SWT.MOD1 + 'C');
+ copy.addSelectionListener(widgetSelectedAdapter(event -> text.copy()));
+ MenuItem exit = new MenuItem(menu, SWT.PUSH);
+ exit.setText(LayoutExample.getResourceString("Exit"));
+ exit.addSelectionListener(widgetSelectedAdapter(event -> shell.close()));
+ editItem.setMenu(menu);
+
+ shell.pack();
+ shell.setSize(500, 600);
+ shell.open();
+ while(!shell.isDisposed())
+ if (!display.readAndDispatch()) display.sleep();
+ }));
createChildWidgets();
}
@@ -360,23 +325,20 @@ abstract class Tab {
final Button preferredButton = new Button (controlGroup, SWT.CHECK);
preferredButton.setText (LayoutExample.getResourceString ("Preferred_Size"));
preferredButton.setSelection (false);
- preferredButton.addSelectionListener (new SelectionAdapter () {
- @Override
- public void widgetSelected (SelectionEvent e) {
- resetEditors ();
- GridData data = (GridData)layoutComposite.getLayoutData();
- if (preferredButton.getSelection ()) {
- data.heightHint = data.widthHint = SWT.DEFAULT;
- data.verticalAlignment = data.horizontalAlignment = 0;
- data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = false;
- } else {
- data.verticalAlignment = data.horizontalAlignment = SWT.FILL;
- data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = true;
- }
- layoutComposite.setLayoutData (data);
- layoutGroup.layout (true);
+ preferredButton.addSelectionListener (widgetSelectedAdapter(e -> {
+ resetEditors ();
+ GridData data = (GridData)layoutComposite.getLayoutData();
+ if (preferredButton.getSelection ()) {
+ data.heightHint = data.widthHint = SWT.DEFAULT;
+ data.verticalAlignment = data.horizontalAlignment = 0;
+ data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = false;
+ } else {
+ data.verticalAlignment = data.horizontalAlignment = SWT.FILL;
+ data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = true;
}
- });
+ layoutComposite.setLayoutData (data);
+ layoutGroup.layout (true);
+ }));
preferredButton.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false, 2, 1));
createControlWidgets ();
}
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java
index 6086d6ab82..e0584312d6 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.swt.examples.texteditor;
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileWriter;
@@ -32,8 +34,7 @@ import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
@@ -235,39 +236,31 @@ public class TextEditor {
MenuItem openItem = new MenuItem(fileMenu, SWT.PUSH);
openItem.setText(getResourceString("Open_menuitem")); //$NON-NLS-1$
- openItem.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent event) {
- FileDialog dialog = new FileDialog(shell, SWT.OPEN);
- dialog.setFilterNames(new String [] {getResourceString("Text_Documents")}); //$NON-NLS-1$
- dialog.setFilterExtensions (new String [] {"*.txt"}); //$NON-NLS-1$
- String name = dialog.open();
- if (name == null) return;
- fileName = name;
- FileInputStream file = null;
- try {
- file = new FileInputStream(name);
- styledText.setText(openFile(file));
- } catch (IOException e) {
- showError(getResourceString("Error"), e.getMessage()); //$NON-NLS-1$
- } finally {
- try {
- if (file != null) file.close();
- } catch (IOException e) {
- showError(getResourceString("Error"), e.getMessage()); //$NON-NLS-1$
- }
- }
- }
- });
+ openItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setFilterNames(new String [] {getResourceString("Text_Documents")}); //$NON-NLS-1$
+ dialog.setFilterExtensions (new String [] {"*.txt"}); //$NON-NLS-1$
+ String name = dialog.open();
+ if (name == null) return;
+ fileName = name;
+ FileInputStream file = null;
+ try {
+ file = new FileInputStream(name);
+ styledText.setText(openFile(file));
+ } catch (IOException e) {
+ showError(getResourceString("Error"), e.getMessage()); //$NON-NLS-1$
+ } finally {
+ try {
+ if (file != null) file.close();
+ } catch (IOException e) {
+ showError(getResourceString("Error"), e.getMessage()); //$NON-NLS-1$
+ }
+ }
+ }));
final MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH);
saveItem.setText(getResourceString("Save_menuitem")); //$NON-NLS-1$
- saveItem.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent event) {
- saveFile();
- }
- });
+ saveItem.addSelectionListener(widgetSelectedAdapter(event -> saveFile()));
fileMenu.addMenuListener(new MenuAdapter() {
@Override
@@ -278,31 +271,23 @@ public class TextEditor {
MenuItem saveAsItem = new MenuItem(fileMenu, SWT.PUSH);
saveAsItem.setText(getResourceString("SaveAs_menuitem")); //$NON-NLS-1$
- saveAsItem.addSelectionListener(new SelectionAdapter () {
- @Override
- public void widgetSelected(SelectionEvent event) {
- FileDialog dialog = new FileDialog (shell, SWT.SAVE);
- dialog.setFilterNames(new String [] {getResourceString("Text_Documents")}); //$NON-NLS-1$
- dialog.setFilterExtensions(new String [] {"*.txt"}); //$NON-NLS-1$
- if (fileName != null) dialog.setFileName(fileName);
- String name = dialog.open();
- if (name != null) {
- fileName = name;
- saveFile();
- }
+ saveAsItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ FileDialog dialog = new FileDialog (shell, SWT.SAVE);
+ dialog.setFilterNames(new String [] {getResourceString("Text_Documents")}); //$NON-NLS-1$
+ dialog.setFilterExtensions(new String [] {"*.txt"}); //$NON-NLS-1$
+ if (fileName != null) dialog.setFileName(fileName);
+ String name = dialog.open();
+ if (name != null) {
+ fileName = name;
+ saveFile();
}
- });
+ }));
new MenuItem(fileMenu, SWT.SEPARATOR);
MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
exitItem.setText(getResourceString("Exit_menuitem")); //$NON-NLS-1$
- exitItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- shell.dispose();
- }
- });
+ exitItem.addSelectionListener(widgetSelectedAdapter(event -> shell.dispose()));
MenuItem editItem = new MenuItem(menu, SWT.CASCADE);
final Menu editMenu = new Menu(shell, SWT.DROP_DOWN);
@@ -312,45 +297,25 @@ public class TextEditor {
cutItem.setText(getResourceString("Cut_menuitem")); //$NON-NLS-1$
cutItem.setImage(iCut);
cutItem.setAccelerator(SWT.MOD1 | 'x');
- cutItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.cut();
- }
- });
+ cutItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.cut()));
final MenuItem copyItem = new MenuItem(editMenu, SWT.PUSH);
copyItem.setText(getResourceString("Copy_menuitem")); //$NON-NLS-1$
copyItem.setImage(iCopy);
copyItem.setAccelerator(SWT.MOD1 | 'c');
- copyItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.copy();
- }
- });
+ copyItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.copy()));
MenuItem pasteItem = new MenuItem(editMenu, SWT.PUSH);
pasteItem.setText(getResourceString("Paste_menuitem")); //$NON-NLS-1$
pasteItem.setImage(iPaste);
pasteItem.setAccelerator(SWT.MOD1 | 'v');
- pasteItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.paste();
- }
- });
+ pasteItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.paste()));
new MenuItem(editMenu, SWT.SEPARATOR);
final MenuItem selectAllItem = new MenuItem(editMenu, SWT.PUSH);
selectAllItem.setText(getResourceString("SelectAll_menuitem")); //$NON-NLS-1$
selectAllItem.setAccelerator(SWT.MOD1 | 'a');
- selectAllItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.selectAll();
- }
- });
+ selectAllItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.selectAll()));
editMenu.addMenuListener(new MenuAdapter() {
@Override
@@ -364,51 +329,42 @@ public class TextEditor {
MenuItem wrapItem = new MenuItem(editMenu, SWT.CHECK);
wrapItem.setText(getResourceString("Wrap_menuitem")); //$NON-NLS-1$
- wrapItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- MenuItem item = (MenuItem) event.widget;
- boolean enabled = item.getSelection();
- styledText.setWordWrap(enabled);
- editMenu.getItem(6).setEnabled(enabled);
- editMenu.getItem(8).setEnabled(enabled);
- leftAlignmentItem.setEnabled(enabled);
- centerAlignmentItem.setEnabled(enabled);
- rightAlignmentItem.setEnabled(enabled);
- justifyAlignmentItem.setEnabled(enabled);
- blockSelectionItem.setEnabled(!enabled);
- }
- });
+ wrapItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ MenuItem item = (MenuItem) event.widget;
+ boolean enabled = item.getSelection();
+ styledText.setWordWrap(enabled);
+ editMenu.getItem(6).setEnabled(enabled);
+ editMenu.getItem(8).setEnabled(enabled);
+ leftAlignmentItem.setEnabled(enabled);
+ centerAlignmentItem.setEnabled(enabled);
+ rightAlignmentItem.setEnabled(enabled);
+ justifyAlignmentItem.setEnabled(enabled);
+ blockSelectionItem.setEnabled(!enabled);
+ }));
MenuItem justifyItem = new MenuItem(editMenu, SWT.CHECK);
justifyItem.setText(getResourceString("Justify_menuitem")); //$NON-NLS-1$
- justifyItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- MenuItem item = (MenuItem) event.widget;
- styledText.setJustify(item.getSelection());
- updateToolBar();
- }
- });
+ justifyItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ MenuItem item = (MenuItem) event.widget;
+ styledText.setJustify(item.getSelection());
+ updateToolBar();
+ }));
justifyItem.setEnabled(false);
MenuItem setFontItem = new MenuItem(editMenu, SWT.PUSH);
setFontItem.setText(getResourceString("SetFont_menuitem")); //$NON-NLS-1$
- setFontItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- FontDialog fontDialog = new FontDialog(shell);
- fontDialog.setFontList(styledText.getFont().getFontData());
- FontData data = fontDialog.open();
- if (data != null) {
- Font newFont = new Font(display, data);
- styledText.setFont(newFont);
- if (font != null) font.dispose();
- font = newFont;
- updateToolBar();
- }
+ setFontItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ FontDialog fontDialog = new FontDialog(shell);
+ fontDialog.setFontList(styledText.getFont().getFontData());
+ FontData data = fontDialog.open();
+ if (data != null) {
+ Font newFont = new Font(display, data);
+ styledText.setFont(newFont);
+ if (font != null) font.dispose();
+ font = newFont;
+ updateToolBar();
}
- });
+ }));
MenuItem alignmentItem = new MenuItem(editMenu, SWT.CASCADE);
alignmentItem.setText(getResourceString("Alignment_menuitem")); //$NON-NLS-1$
@@ -417,34 +373,25 @@ public class TextEditor {
final MenuItem leftAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
leftAlignmentItem.setText(getResourceString("Left_menuitem")); //$NON-NLS-1$
leftAlignmentItem.setSelection(true);
- leftAlignmentItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.setAlignment(SWT.LEFT);
- updateToolBar();
- }
- });
+ leftAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ styledText.setAlignment(SWT.LEFT);
+ updateToolBar();
+ }));
alignmentItem.setEnabled(false);
final MenuItem centerAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
centerAlignmentItem.setText(getResourceString("Center_menuitem")); //$NON-NLS-1$
- centerAlignmentItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.setAlignment(SWT.CENTER);
- updateToolBar();
- }
- });
+ centerAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ styledText.setAlignment(SWT.CENTER);
+ updateToolBar();
+ }));
MenuItem rightAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
rightAlignmentItem.setText(getResourceString("Right_menuitem")); //$NON-NLS-1$
- rightAlignmentItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.setAlignment(SWT.RIGHT);
- updateToolBar();
- }
- });
+ rightAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ styledText.setAlignment(SWT.RIGHT);
+ updateToolBar();
+ }));
MenuItem editOrientationItem = new MenuItem(editMenu, SWT.CASCADE);
editOrientationItem.setText(getResourceString("Orientation_menuitem")); //$NON-NLS-1$
@@ -453,22 +400,12 @@ public class TextEditor {
MenuItem leftToRightItem = new MenuItem(editOrientationMenu, SWT.RADIO);
leftToRightItem.setText(getResourceString("LeftToRight_menuitem")); //$NON-NLS-1$
- leftToRightItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event){
- styledText.setOrientation(SWT.LEFT_TO_RIGHT);
- }
- });
+ leftToRightItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.setOrientation(SWT.LEFT_TO_RIGHT)));
leftToRightItem.setSelection(true);
MenuItem rightToLeftItem = new MenuItem(editOrientationMenu, SWT.RADIO);
rightToLeftItem.setText(getResourceString("RightToLeft_menuitem")); //$NON-NLS-1$
- rightToLeftItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.setOrientation(SWT.RIGHT_TO_LEFT);
- }
- });
+ rightToLeftItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.setOrientation(SWT.RIGHT_TO_LEFT)));
new MenuItem(editMenu, SWT.SEPARATOR);
MenuItem insertObjectItem = new MenuItem(editMenu, SWT.CASCADE);
@@ -486,42 +423,33 @@ public class TextEditor {
MenuItem comboItem = new MenuItem(controlChoice, SWT.PUSH);
comboItem.setText(getResourceString("Combo_menuitem")); //$NON-NLS-1$
- buttonItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Button button = new Button(styledText, SWT.PUSH);
- button.setText(getResourceString("Button_menuitem")); //$NON-NLS-1$
- addControl(button);
- }
- });
+ buttonItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ Button button = new Button(styledText, SWT.PUSH);
+ button.setText(getResourceString("Button_menuitem")); //$NON-NLS-1$
+ addControl(button);
+ }));
- comboItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Combo combo = new Combo(styledText, SWT.NONE);
- combo.setText(getResourceString("Combo_menuitem")); //$NON-NLS-1$
- addControl(combo);
- }
- });
+ comboItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ Combo combo = new Combo(styledText, SWT.NONE);
+ combo.setText(getResourceString("Combo_menuitem")); //$NON-NLS-1$
+ addControl(combo);
+ }));
MenuItem insertImageItem = new MenuItem(insertObjectMenu, SWT.PUSH);
insertImageItem.setText(getResourceString("Image_menuitem")); //$NON-NLS-1$
- insertImageItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
- String fileName = fileDialog.open();
- if (fileName != null) {
- try {
- Image image = new Image(display, fileName);
- addImage(image);
- } catch (Exception e) {
- showError(getResourceString("Bad_image"), e.getMessage()); //$NON-NLS-1$
- }
+ insertImageItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
+ String fileName = fileDialog.open();
+ if (fileName != null) {
+ try {
+ Image image = new Image(display, fileName);
+ addImage(image);
+ } catch (Exception e) {
+ showError(getResourceString("Bad_image"), e.getMessage()); //$NON-NLS-1$
}
}
- });
+ }));
if (SAMPLE_TEXT) {
new MenuItem(editMenu, SWT.SEPARATOR);
@@ -529,13 +457,10 @@ public class TextEditor {
loadProfileItem.setText(getResourceString("LoadProfile_menuitem")); //$NON-NLS-1$
Menu loadProfileMenu = new Menu(shell, SWT.DROP_DOWN);
loadProfileItem.setMenu(loadProfileMenu);
- SelectionAdapter adapter = new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- int profile = Integer.parseInt((String) event.widget.getData());
- loadProfile(profile);
- }
- };
+ SelectionListener adapter = widgetSelectedAdapter(event -> {
+ int profile = Integer.parseInt((String) event.widget.getData());
+ loadProfile(profile);
+ });
MenuItem profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
profileItem.setText(getResourceString("Profile1_menuitem")); //$NON-NLS-1$
@@ -592,289 +517,226 @@ public class TextEditor {
boldControl = new ToolItem(styleToolBar, SWT.CHECK);
boldControl.setImage(iBold);
boldControl.setToolTipText(getResourceString("Bold")); //$NON-NLS-1$
- boldControl.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- setStyle(BOLD);
- }
- });
+ boldControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(BOLD)));
italicControl = new ToolItem(styleToolBar, SWT.CHECK);
italicControl.setImage(iItalic);
italicControl.setToolTipText(getResourceString("Italic")); //$NON-NLS-1$
- italicControl.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- setStyle(ITALIC);
- }
- });
+ italicControl.addSelectionListener(widgetSelectedAdapter(event -> setStyle(ITALIC)));
final Menu underlineMenu = new Menu(shell, SWT.POP_UP);
underlineSingleItem = new MenuItem(underlineMenu, SWT.RADIO);
underlineSingleItem.setText(getResourceString("Single_menuitem")); //$NON-NLS-1$
- underlineSingleItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (underlineSingleItem.getSelection()) {
- setStyle(UNDERLINE_SINGLE);
- }
+ underlineSingleItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (underlineSingleItem.getSelection()) {
+ setStyle(UNDERLINE_SINGLE);
}
- });
+ }));
underlineSingleItem.setSelection(true);
underlineDoubleItem = new MenuItem(underlineMenu, SWT.RADIO);
underlineDoubleItem.setText(getResourceString("Double_menuitem")); //$NON-NLS-1$
- underlineDoubleItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (underlineDoubleItem.getSelection()) {
- setStyle(UNDERLINE_DOUBLE);
- }
+ underlineDoubleItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (underlineDoubleItem.getSelection()) {
+ setStyle(UNDERLINE_DOUBLE);
}
- });
+ }));
underlineSquiggleItem = new MenuItem(underlineMenu, SWT.RADIO);
underlineSquiggleItem.setText(getResourceString("Squiggle_menuitem")); //$NON-NLS-1$
- underlineSquiggleItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (underlineSquiggleItem.getSelection()) {
- setStyle(UNDERLINE_SQUIGGLE);
- }
+ underlineSquiggleItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (underlineSquiggleItem.getSelection()) {
+ setStyle(UNDERLINE_SQUIGGLE);
}
- });
+ }));
underlineErrorItem = new MenuItem(underlineMenu, SWT.RADIO);
underlineErrorItem.setText(getResourceString("Error_menuitem")); //$NON-NLS-1$
- underlineErrorItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (underlineErrorItem.getSelection()) {
- setStyle(UNDERLINE_ERROR);
- }
+ underlineErrorItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (underlineErrorItem.getSelection()) {
+ setStyle(UNDERLINE_ERROR);
}
- });
+ }));
MenuItem underlineColorItem = new MenuItem(underlineMenu, SWT.PUSH);
underlineColorItem.setText(getResourceString("Color_menuitem")); //$NON-NLS-1$
- underlineColorItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- ColorDialog dialog = new ColorDialog(shell);
- RGB rgb = underlineColor != null ? underlineColor.getRGB() : null;
- dialog.setRGB(rgb);
- RGB newRgb = dialog.open();
- if (newRgb != null) {
- if (!newRgb.equals(rgb)) {
- disposeResource(underlineColor);
- underlineColor = new Color(display, newRgb);
- }
- if (underlineSingleItem.getSelection()) setStyle(UNDERLINE_SINGLE);
- else if (underlineDoubleItem.getSelection()) setStyle(UNDERLINE_DOUBLE);
- else if (underlineErrorItem.getSelection()) setStyle(UNDERLINE_ERROR);
- else if (underlineSquiggleItem.getSelection()) setStyle(UNDERLINE_SQUIGGLE);
+ underlineColorItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ ColorDialog dialog = new ColorDialog(shell);
+ RGB rgb = underlineColor != null ? underlineColor.getRGB() : null;
+ dialog.setRGB(rgb);
+ RGB newRgb = dialog.open();
+ if (newRgb != null) {
+ if (!newRgb.equals(rgb)) {
+ disposeResource(underlineColor);
+ underlineColor = new Color(display, newRgb);
}
+ if (underlineSingleItem.getSelection()) setStyle(UNDERLINE_SINGLE);
+ else if (underlineDoubleItem.getSelection()) setStyle(UNDERLINE_DOUBLE);
+ else if (underlineErrorItem.getSelection()) setStyle(UNDERLINE_ERROR);
+ else if (underlineSquiggleItem.getSelection()) setStyle(UNDERLINE_SQUIGGLE);
}
- });
+ }));
final ToolItem underlineControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
underlineControl.setImage(iUnderline);
underlineControl.setToolTipText(getResourceString("Underline")); //$NON-NLS-1$
- underlineControl.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (event.detail == SWT.ARROW) {
- Rectangle rect = underlineControl.getBounds();
- Point pt = new Point(rect.x, rect.y + rect.height);
- underlineMenu.setLocation(display.map(underlineControl.getParent(), null, pt));
- underlineMenu.setVisible(true);
- } else {
- if (underlineSingleItem.getSelection()) setStyle(UNDERLINE_SINGLE);
- else if (underlineDoubleItem.getSelection()) setStyle(UNDERLINE_DOUBLE);
- else if (underlineErrorItem.getSelection()) setStyle(UNDERLINE_ERROR);
- else if (underlineSquiggleItem.getSelection()) setStyle(UNDERLINE_SQUIGGLE);
- }
+ underlineControl.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (event.detail == SWT.ARROW) {
+ Rectangle rect = underlineControl.getBounds();
+ Point pt = new Point(rect.x, rect.y + rect.height);
+ underlineMenu.setLocation(display.map(underlineControl.getParent(), null, pt));
+ underlineMenu.setVisible(true);
+ } else {
+ if (underlineSingleItem.getSelection()) setStyle(UNDERLINE_SINGLE);
+ else if (underlineDoubleItem.getSelection()) setStyle(UNDERLINE_DOUBLE);
+ else if (underlineErrorItem.getSelection()) setStyle(UNDERLINE_ERROR);
+ else if (underlineSquiggleItem.getSelection()) setStyle(UNDERLINE_SQUIGGLE);
}
- });
+ }));
ToolItem strikeoutControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
strikeoutControl.setImage(iStrikeout);
strikeoutControl.setToolTipText(getResourceString("Strikeout")); //$NON-NLS-1$
- strikeoutControl.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (event.detail == SWT.ARROW) {
- ColorDialog dialog = new ColorDialog(shell);
- RGB rgb = strikeoutColor != null ? strikeoutColor.getRGB() : null;
- dialog.setRGB(rgb);
- RGB newRgb = dialog.open();
- if (newRgb == null) return;
- if (!newRgb.equals(rgb)) {
- disposeResource(strikeoutColor);
- strikeoutColor = new Color(display, newRgb);
- }
+ strikeoutControl.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (event.detail == SWT.ARROW) {
+ ColorDialog dialog = new ColorDialog(shell);
+ RGB rgb = strikeoutColor != null ? strikeoutColor.getRGB() : null;
+ dialog.setRGB(rgb);
+ RGB newRgb = dialog.open();
+ if (newRgb == null) return;
+ if (!newRgb.equals(rgb)) {
+ disposeResource(strikeoutColor);
+ strikeoutColor = new Color(display, newRgb);
}
- setStyle(STRIKEOUT);
}
- });
+ setStyle(STRIKEOUT);
+ }));
final Menu borderMenu = new Menu(shell, SWT.POP_UP);
borderSolidItem = new MenuItem(borderMenu, SWT.RADIO);
borderSolidItem.setText(getResourceString("Solid")); //$NON-NLS-1$
- borderSolidItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event){
- if (borderSolidItem.getSelection()) {
- setStyle(BORDER_SOLID);
- }
+ borderSolidItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (borderSolidItem.getSelection()) {
+ setStyle(BORDER_SOLID);
}
- });
+ }));
borderSolidItem.setSelection(true);
borderDashItem = new MenuItem(borderMenu, SWT.RADIO);
borderDashItem.setText(getResourceString("Dash")); //$NON-NLS-1$
- borderDashItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event){
- if (borderDashItem.getSelection()) {
- setStyle(BORDER_DASH);
- }
+ borderDashItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (borderDashItem.getSelection()) {
+ setStyle(BORDER_DASH);
}
- });
+ }));
borderDotItem = new MenuItem(borderMenu, SWT.RADIO);
borderDotItem.setText(getResourceString("Dot")); //$NON-NLS-1$
- borderDotItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event){
- if (borderDotItem.getSelection()) {
- setStyle(BORDER_DOT);
- }
+ borderDotItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (borderDotItem.getSelection()) {
+ setStyle(BORDER_DOT);
}
- });
+ }));
MenuItem borderColorItem = new MenuItem(borderMenu, SWT.PUSH);
borderColorItem.setText(getResourceString("Color_menuitem")); //$NON-NLS-1$
- borderColorItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event){
- ColorDialog dialog = new ColorDialog(shell);
- RGB rgb = borderColor != null ? borderColor.getRGB() : null;
- dialog.setRGB(rgb);
- RGB newRgb = dialog.open();
- if (newRgb != null) {
- if (!newRgb.equals(rgb)) {
- disposeResource(borderColor);
- borderColor = new Color(display, newRgb);
- }
- if (borderDashItem.getSelection()) setStyle(BORDER_DASH);
- else if (borderDotItem.getSelection()) setStyle(BORDER_DOT);
- else if (borderSolidItem.getSelection()) setStyle(BORDER_SOLID);
+ borderColorItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ ColorDialog dialog = new ColorDialog(shell);
+ RGB rgb = borderColor != null ? borderColor.getRGB() : null;
+ dialog.setRGB(rgb);
+ RGB newRgb = dialog.open();
+ if (newRgb != null) {
+ if (!newRgb.equals(rgb)) {
+ disposeResource(borderColor);
+ borderColor = new Color(display, newRgb);
}
+ if (borderDashItem.getSelection()) setStyle(BORDER_DASH);
+ else if (borderDotItem.getSelection()) setStyle(BORDER_DOT);
+ else if (borderSolidItem.getSelection()) setStyle(BORDER_SOLID);
}
- });
+ }));
final ToolItem borderControl = new ToolItem(styleToolBar, SWT.DROP_DOWN);
borderControl.setImage(iBorderStyle);
borderControl.setToolTipText(getResourceString("Box")); //$NON-NLS-1$
- borderControl.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (event.detail == SWT.ARROW) {
- Rectangle rect = borderControl.getBounds();
- Point pt = new Point(rect.x, rect.y + rect.height);
- borderMenu.setLocation(display.map(borderControl.getParent(), null, pt));
- borderMenu.setVisible(true);
- } else {
- if (borderDashItem.getSelection()) setStyle(BORDER_DASH);
- else if (borderDotItem.getSelection()) setStyle(BORDER_DOT);
- else if (borderSolidItem.getSelection()) setStyle(BORDER_SOLID);
- }
+ borderControl.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (event.detail == SWT.ARROW) {
+ Rectangle rect = borderControl.getBounds();
+ Point pt = new Point(rect.x, rect.y + rect.height);
+ borderMenu.setLocation(display.map(borderControl.getParent(), null, pt));
+ borderMenu.setVisible(true);
+ } else {
+ if (borderDashItem.getSelection()) setStyle(BORDER_DASH);
+ else if (borderDotItem.getSelection()) setStyle(BORDER_DOT);
+ else if (borderSolidItem.getSelection()) setStyle(BORDER_SOLID);
}
- });
+ }));
ToolItem foregroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN);
foregroundItem.setImage(iTextForeground);
foregroundItem.setToolTipText(getResourceString("TextForeground")); //$NON-NLS-1$
- foregroundItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (event.detail == SWT.ARROW || textForeground == null) {
- ColorDialog dialog = new ColorDialog(shell);
- RGB rgb = textForeground != null ? textForeground.getRGB() : null;
- dialog.setRGB(rgb);
- RGB newRgb = dialog.open();
- if (newRgb == null) return;
- if (!newRgb.equals(rgb)) {
- disposeResource(textForeground);
- textForeground = new Color(display, newRgb);
- }
+ foregroundItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (event.detail == SWT.ARROW || textForeground == null) {
+ ColorDialog dialog = new ColorDialog(shell);
+ RGB rgb = textForeground != null ? textForeground.getRGB() : null;
+ dialog.setRGB(rgb);
+ RGB newRgb = dialog.open();
+ if (newRgb == null) return;
+ if (!newRgb.equals(rgb)) {
+ disposeResource(textForeground);
+ textForeground = new Color(display, newRgb);
}
- setStyle(FOREGROUND);
}
- });
+ setStyle(FOREGROUND);
+ }));
ToolItem backgroundItem = new ToolItem(styleToolBar, SWT.DROP_DOWN);
backgroundItem.setImage(iTextBackground);
backgroundItem.setToolTipText(getResourceString("TextBackground")); //$NON-NLS-1$
- backgroundItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (event.detail == SWT.ARROW || textBackground == null) {
- ColorDialog dialog = new ColorDialog(shell);
- RGB rgb = textBackground != null ? textBackground.getRGB() : null;
- dialog.setRGB(rgb);
- RGB newRgb = dialog.open();
- if (newRgb == null) return;
- if (!newRgb.equals(rgb)) {
- disposeResource(textBackground);
- textBackground = new Color(display, newRgb);
- }
+ backgroundItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (event.detail == SWT.ARROW || textBackground == null) {
+ ColorDialog dialog = new ColorDialog(shell);
+ RGB rgb = textBackground != null ? textBackground.getRGB() : null;
+ dialog.setRGB(rgb);
+ RGB newRgb = dialog.open();
+ if (newRgb == null) return;
+ if (!newRgb.equals(rgb)) {
+ disposeResource(textBackground);
+ textBackground = new Color(display, newRgb);
}
- setStyle(BACKGROUND);
}
- });
+ setStyle(BACKGROUND);
+ }));
ToolItem baselineUpItem = new ToolItem(styleToolBar, SWT.PUSH);
baselineUpItem.setImage(iBaselineUp);
String tooltip = "IncreaseFont"; //$NON-NLS-1$
if (USE_BASELINE) tooltip = "IncreaseBaseline"; //$NON-NLS-1$
baselineUpItem.setToolTipText(getResourceString(tooltip));
- baselineUpItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (USE_BASELINE) {
- setStyle(BASELINE_UP);
- } else {
- adjustFontSize(1);
- }
+ baselineUpItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (USE_BASELINE) {
+ setStyle(BASELINE_UP);
+ } else {
+ adjustFontSize(1);
}
- });
+ }));
ToolItem baselineDownItem = new ToolItem(styleToolBar, SWT.PUSH);
baselineDownItem.setImage(iBaselineDown);
tooltip = "DecreaseFont"; //$NON-NLS-1$
if (USE_BASELINE) tooltip = "DecreaseBaseline"; //$NON-NLS-1$
baselineDownItem.setToolTipText(getResourceString(tooltip));
- baselineDownItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (USE_BASELINE) {
- setStyle(BASELINE_DOWN);
- } else {
- adjustFontSize(-1);
- }
+ baselineDownItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ if (USE_BASELINE) {
+ setStyle(BASELINE_DOWN);
+ } else {
+ adjustFontSize(-1);
}
- });
+ }));
ToolItem linkItem = new ToolItem(styleToolBar, SWT.PUSH);
linkItem.setImage(iLink);
linkItem.setToolTipText(getResourceString("Link")); //$NON-NLS-1$
- linkItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- setLink();
- }
- });
+ linkItem.addSelectionListener(widgetSelectedAdapter(event -> setLink()));
CoolItem coolItem = new CoolItem(coolBar, SWT.NONE);
coolItem.setControl(styleToolBar);
@@ -889,16 +751,13 @@ public class TextEditor {
fontSizeControl = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
fontSizeControl.setItems(FONT_SIZES);
fontSizeControl.setVisibleItemCount(8);
- SelectionAdapter adapter = new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- String name = fontNameControl.getText();
- int size = Integer.parseInt(fontSizeControl.getText());
- disposeResource(textFont);
- textFont = new Font(display, name, size, SWT.NORMAL);
- setStyle(FONT);
- }
- };
+ SelectionListener adapter = widgetSelectedAdapter(event -> {
+ String name = fontNameControl.getText();
+ int size = Integer.parseInt(fontSizeControl.getText());
+ disposeResource(textFont);
+ textFont = new Font(display, name, size, SWT.NORMAL);
+ setStyle(FONT);
+ });
fontSizeControl.addSelectionListener(adapter);
fontNameControl.addSelectionListener(adapter);
coolItem = new CoolItem(coolBar, SWT.NONE);
@@ -908,88 +767,62 @@ public class TextEditor {
blockSelectionItem = new ToolItem(alignmentToolBar, SWT.CHECK);
blockSelectionItem.setImage(iBlockSelection);
blockSelectionItem.setToolTipText(getResourceString("BlockSelection")); //$NON-NLS-1$
- blockSelectionItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- styledText.invokeAction(ST.TOGGLE_BLOCKSELECTION);
- }
- });
+ blockSelectionItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.invokeAction(ST.TOGGLE_BLOCKSELECTION)));
leftAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
leftAlignmentItem.setImage(iLeftAlignment);
leftAlignmentItem.setToolTipText(getResourceString("AlignLeft")); //$NON-NLS-1$
leftAlignmentItem.setSelection(true);
- leftAlignmentItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Point selection = styledText.getSelection();
- int lineStart = styledText.getLineAtOffset(selection.x);
- int lineEnd = styledText.getLineAtOffset(selection.y);
- styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.LEFT);
- }
- });
+ leftAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ Point selection = styledText.getSelection();
+ int lineStart = styledText.getLineAtOffset(selection.x);
+ int lineEnd = styledText.getLineAtOffset(selection.y);
+ styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.LEFT);
+ }));
leftAlignmentItem.setEnabled(false);
centerAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
centerAlignmentItem.setImage(iCenterAlignment);
centerAlignmentItem.setToolTipText(getResourceString("Center_menuitem")); //$NON-NLS-1$
- centerAlignmentItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Point selection = styledText.getSelection();
- int lineStart = styledText.getLineAtOffset(selection.x);
- int lineEnd = styledText.getLineAtOffset(selection.y);
- styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.CENTER);
- }
- });
+ centerAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ Point selection = styledText.getSelection();
+ int lineStart = styledText.getLineAtOffset(selection.x);
+ int lineEnd = styledText.getLineAtOffset(selection.y);
+ styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.CENTER);
+ }));
centerAlignmentItem.setEnabled(false);
rightAlignmentItem = new ToolItem(alignmentToolBar, SWT.RADIO);
rightAlignmentItem.setImage(iRightAlignment);
rightAlignmentItem.setToolTipText(getResourceString("AlignRight")); //$NON-NLS-1$
- rightAlignmentItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Point selection = styledText.getSelection();
- int lineStart = styledText.getLineAtOffset(selection.x);
- int lineEnd = styledText.getLineAtOffset(selection.y);
- styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.RIGHT);
- }
- });
+ rightAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ Point selection = styledText.getSelection();
+ int lineStart = styledText.getLineAtOffset(selection.x);
+ int lineEnd = styledText.getLineAtOffset(selection.y);
+ styledText.setLineAlignment(lineStart, lineEnd - lineStart + 1, SWT.RIGHT);
+ }));
rightAlignmentItem.setEnabled(false);
justifyAlignmentItem = new ToolItem(alignmentToolBar, SWT.CHECK);
justifyAlignmentItem.setImage(iJustifyAlignment);
justifyAlignmentItem.setToolTipText(getResourceString("Justify")); //$NON-NLS-1$
- justifyAlignmentItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Point selection = styledText.getSelection();
- int lineStart = styledText.getLineAtOffset(selection.x);
- int lineEnd = styledText.getLineAtOffset(selection.y);
- styledText.setLineJustify(lineStart, lineEnd - lineStart + 1, justifyAlignmentItem.getSelection());
- }
- });
+ justifyAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
+ Point selection = styledText.getSelection();
+ int lineStart = styledText.getLineAtOffset(selection.x);
+ int lineEnd = styledText.getLineAtOffset(selection.y);
+ styledText.setLineJustify(lineStart, lineEnd - lineStart + 1, justifyAlignmentItem.getSelection());
+ }));
justifyAlignmentItem.setEnabled(false);
ToolItem bulletListItem = new ToolItem(alignmentToolBar, SWT.PUSH);
bulletListItem.setImage(iBulletList);
bulletListItem.setToolTipText(getResourceString("BulletList")); //$NON-NLS-1$
- bulletListItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- setBullet(ST.BULLET_DOT);}
- });
+ bulletListItem.addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_DOT)));
ToolItem numberedListItem = new ToolItem(alignmentToolBar, SWT.PUSH);
numberedListItem.setImage(iNumberedList);
numberedListItem.setToolTipText(getResourceString("NumberedList")); //$NON-NLS-1$
- numberedListItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- setBullet(ST.BULLET_NUMBER | ST.BULLET_TEXT);
- }
- });
+ numberedListItem.addSelectionListener(widgetSelectedAdapter(event -> setBullet(ST.BULLET_NUMBER | ST.BULLET_TEXT)));
coolItem = new CoolItem(coolBar, SWT.NONE);
coolItem.setControl(alignmentToolBar);
@@ -1000,23 +833,17 @@ public class TextEditor {
Label label = new Label(composite, SWT.NONE);
label.setText(getResourceString("Indent")); //$NON-NLS-1$
Spinner indent = new Spinner(composite, SWT.BORDER);
- indent.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Spinner spinner = (Spinner) event.widget;
- styledText.setIndent(spinner.getSelection());
- }
- });
+ indent.addSelectionListener(widgetSelectedAdapter(event -> {
+ Spinner spinner = (Spinner) event.widget;
+ styledText.setIndent(spinner.getSelection());
+ }));
label = new Label(composite, SWT.NONE);
label.setText(getResourceString("Spacing")); //$NON-NLS-1$
Spinner spacing = new Spinner(composite, SWT.BORDER);
- spacing.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- Spinner spinner = (Spinner) event.widget;
- styledText.setLineSpacing(spinner.getSelection());
- }
- });
+ spacing.addSelectionListener(widgetSelectedAdapter(event -> {
+ Spinner spinner = (Spinner) event.widget;
+ styledText.setLineSpacing(spinner.getSelection());
+ }));
coolItem = new CoolItem(coolBar, SWT.NONE);
coolItem.setControl(composite);
@@ -1319,7 +1146,7 @@ public class TextEditor {
Image loadImage(Display display, String fileName) {
Image image = null;
try {
- InputStream sourceStream = getClass().getResourceAsStream(fileName + ".ico"); //$NON-NLS-1$ //$NON-NLS-2$
+ InputStream sourceStream = getClass().getResourceAsStream(fileName + ".ico"); //$NON-NLS-1$
ImageData source = new ImageData(sourceStream);
ImageData mask = source.getTransparencyMask();
image = new Image(display, source, mask);

Back to the top