X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Futil%2FDropDownMenu.java;h=0e6b90ac3b29ba4c3a6d1a4cc6b3161b78c59e31;hb=5995c2c9f891ae852a40b4c4736b090d514e7c0a;hp=ffa18575d660f022905832fa9a38b8b6d22f3207;hpb=7d05144c25daa53e60fc9ed9fd503546a86567f8;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java index ffa18575..0e6b90ac 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/DropDownMenu.java @@ -1,14 +1,10 @@ package net.mograsim.plugin.util; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; @@ -29,34 +25,17 @@ public class DropDownMenu for (DropDownEntry entry : entries) { MenuItem item = new MenuItem(menu, SWT.PUSH); - item.addSelectionListener(new SelectionListener() - { - @Override - public void widgetSelected(SelectionEvent e) - { - entry.listener.widgetSelected(e); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) - { - widgetSelected(e); - } - }); + item.addListener(SWT.Selection, e -> entry.onSelected.run()); item.setText(entry.title); } - button.addListener(SWT.Selection, new Listener() + button.addListener(SWT.Selection, e -> { - @Override - public void handleEvent(Event event) - { - Rectangle rect = button.getBounds(); - Point pt = new Point(rect.x, rect.y + rect.height); - pt = button.getParent().toDisplay(pt); - menu.setLocation(pt.x, pt.y); - menu.setVisible(true); - } + Rectangle rect = button.getBounds(); + Point pt = new Point(rect.x, rect.y + rect.height); + pt = button.getParent().toDisplay(pt); + menu.setLocation(pt.x, pt.y); + menu.setVisible(true); }); } @@ -68,19 +47,12 @@ public class DropDownMenu public static class DropDownEntry { public final String title; - public final EntrySelectedListener listener; + public final Runnable onSelected; - public DropDownEntry(String title, EntrySelectedListener listener) + public DropDownEntry(String title, Runnable onSelected) { - super(); this.title = title; - this.listener = listener; + this.onSelected = onSelected; } } - - @FunctionalInterface - public static interface EntrySelectedListener - { - public void widgetSelected(SelectionEvent e); - } }