From: Ben Soares Date: Thu, 25 May 2023 00:39:36 +0000 (+0100) Subject: JAL-4186 Turn JvOptionPane Callable handlers back into Runnable for jalviewjs... X-Git-Tag: Release_2_11_4_0~293^2^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dc78f37f49146f6339815e93598159d0c1ddc4c7;p=jalview.git JAL-4186 Turn JvOptionPane Callable handlers back into Runnable for jalviewjs (now working) --- diff --git a/src/jalview/gui/AlignExportOptions.java b/src/jalview/gui/AlignExportOptions.java index a23cbfa..c776d82 100644 --- a/src/jalview/gui/AlignExportOptions.java +++ b/src/jalview/gui/AlignExportOptions.java @@ -26,7 +26,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.util.concurrent.Callable; import javax.swing.JCheckBox; import javax.swing.JPanel; @@ -120,7 +119,7 @@ public class AlignExportOptions extends JPanel * * @param action */ - public void setResponseAction(Object response, Callable action) + public void setResponseAction(Object response, Runnable action) { dialog.setResponseHandler(response, action); } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 160ee1a..2365fd2 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -59,7 +59,6 @@ import java.util.Hashtable; import java.util.List; import java.util.Locale; import java.util.Vector; -import java.util.concurrent.Callable; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; @@ -1279,11 +1278,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } AlignExportSettingsI options = new AlignExportSettingsAdapter(false); - Callable cancelAction = () -> { + Runnable cancelAction = () -> { lastSaveSuccessful = false; - return null; }; - Callable outputAction = () -> { + Runnable outputAction = () -> { // todo defer this to inside formatSequences (or later) AlignmentExportData exportData = viewport.getAlignExportData(options); String output = new FormatAdapter(alignPanel, options) @@ -1361,7 +1359,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignFrame.this.getViewport().setSavedUpToDate(true); } } - return null; }; /* @@ -1379,7 +1376,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { try { - outputAction.call(); + outputAction.run(); } catch (Exception e) { // TODO Auto-generated catch block @@ -1401,7 +1398,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, FileFormatI fileFormat = FileFormats.getInstance() .forName(fileFormatName); AlignExportSettingsI options = new AlignExportSettingsAdapter(false); - Callable outputAction = () -> { + Runnable outputAction = () -> { // todo defer this to inside formatSequences (or later) AlignmentExportData exportData = viewport.getAlignExportData(options); CutAndPasteTransfer cap = new CutAndPasteTransfer(); @@ -1423,7 +1420,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, oom); cap.dispose(); } - return null; }; /* @@ -1440,7 +1436,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { try { - outputAction.call(); + outputAction.run(); } catch (Exception e) { e.printStackTrace(); @@ -1571,7 +1567,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, String choice = chooser.getSelectedFile().getPath(); Cache.setProperty("LAST_DIRECTORY", choice); loadJalviewDataFile(chooser.getSelectedFile(), null, null, null); - return null; }); chooser.showOpenDialog(this); @@ -2493,7 +2488,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - Callable okAction = () -> { + Runnable okAction = () -> { SequenceI[] cut = sg.getSequences() .toArray(new SequenceI[sg.getSize()]); @@ -2517,7 +2512,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { } } - return null; }; /* @@ -2543,7 +2537,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { try { - okAction.call(); + okAction.run(); } catch (Exception e) { e.printStackTrace(); @@ -4135,7 +4129,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .getString("label.possible_problem_with_tree_file"), JvOptionPane.WARNING_MESSAGE); } - return null; }); chooser.showOpenDialog(this); } @@ -5981,7 +5974,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Cache.setProperty("LAST_DIRECTORY", choice); SequenceI[] seqs = viewport.getAlignment().getSequencesArray(); new VCFLoader(choice).loadVCF(seqs, us); - return null; }); chooser.showOpenDialog(null); diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 3b7420f..3504560 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -809,13 +809,10 @@ public class AlignViewport extends AlignmentViewport JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop) .setResponseHandler(0, () -> { addDataToAlignment(al); - return null; }).setResponseHandler(1, () -> { us.openLinkedAlignmentAs(al, title, true); - return null; }).setResponseHandler(2, () -> { us.openLinkedAlignmentAs(al, title, false); - return null; }); dialog.showDialog(question, MessageManager.getString("label.open_split_window"), diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 52a6066..487c18b 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -36,7 +36,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.AffineTransform; -import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; @@ -51,19 +50,15 @@ import javax.swing.ToolTipManager; import jalview.analysis.AlignSeq; import jalview.analysis.AlignmentUtils; -import jalview.bin.Console; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; -import jalview.datamodel.ContactMatrixI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.io.FormatAdapter; -import jalview.io.NewickFile; import jalview.util.Comparison; import jalview.util.MessageManager; import jalview.util.Platform; @@ -312,7 +307,6 @@ public class AnnotationLabels extends JPanel ap.av.getAlignment().setAnnotationIndex(annotation, 0); } ap.refresh(true); - return null; }); } @@ -422,13 +416,14 @@ public class AnnotationLabels extends JPanel consclipbrd.addActionListener(this); pop.add(consclipbrd); } - if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP + if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP && PAEContactMatrix.PAEMATRIX .equals(aa[selectedRow].getCalcId())) { final PAEContactMatrix cm = (PAEContactMatrix) av .getContactMatrix(aa[selectedRow]); - if (cm!=null && cm.getNewick()!=null && cm.getNewick().length()>0) + if (cm != null && cm.getNewick() != null + && cm.getNewick().length() > 0) { item = new JMenuItem("Show Tree for Matrix"); item.addActionListener(new ActionListener() @@ -438,7 +433,7 @@ public class AnnotationLabels extends JPanel public void actionPerformed(ActionEvent e) { - ap.alignFrame.showContactMapTree(aa[selectedRow],cm); + ap.alignFrame.showContactMapTree(aa[selectedRow], cm); } }); @@ -1123,7 +1118,8 @@ public class AnnotationLabels extends JPanel } olY = y; // look ahead to next annotation - for (nexAA=i+1; nexAA action = () -> { + Runnable action = () -> { @SuppressWarnings("unchecked") String url = (history instanceof JTextField ? ((JTextField) history).getText() @@ -1357,8 +1355,7 @@ public class Desktop extends jalview.jbgui.GDesktop JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg, MessageManager.getString("label.url_not_found"), JvOptionPane.WARNING_MESSAGE); - - return null; // Void + return; } if (viewport != null) @@ -1371,7 +1368,6 @@ public class Desktop extends jalview.jbgui.GDesktop new FileLoader().LoadFile(url, DataSourceType.URL, format); } } - return null; // Void }; String dialogOption = MessageManager .getString("label.input_alignment_from_url"); @@ -1410,7 +1406,7 @@ public class Desktop extends jalview.jbgui.GDesktop public QuitHandler.QResponse desktopQuit(boolean ui, boolean disposeFlag) { - final Callable doDesktopQuit = () -> { + final Runnable doDesktopQuit = () -> { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Cache.setProperty("SCREENGEOMETRY_WIDTH", screen.width + ""); Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height + ""); @@ -1436,7 +1432,7 @@ public class Desktop extends jalview.jbgui.GDesktop if (QuitHandler.quitCancelled()) { jalview.bin.Console.debug("Desktop aborting quit"); - return null; + return; } if (dialogExecutor != null) @@ -1465,8 +1461,6 @@ public class Desktop extends jalview.jbgui.GDesktop // instance.dispose(); } instance.quit(); - - return null; // Void }; return QuitHandler.getQuitResponse(ui, doDesktopQuit, doDesktopQuit, @@ -1965,7 +1959,6 @@ public class Desktop extends jalview.jbgui.GDesktop } } }, "Project Loader").start(); - return null; }); chooser.showOpenDialog(this); diff --git a/src/jalview/gui/EditNameDialog.java b/src/jalview/gui/EditNameDialog.java index d61177c..4b8a1fd 100644 --- a/src/jalview/gui/EditNameDialog.java +++ b/src/jalview/gui/EditNameDialog.java @@ -22,9 +22,6 @@ package jalview.gui; import java.awt.FlowLayout; import java.awt.Font; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; import javax.swing.BoxLayout; import javax.swing.JButton; @@ -114,25 +111,24 @@ public class EditNameDialog * * @param action */ - public void showDialog(JComponent parent, String title, - Callable action) + public void showDialog(JComponent parent, String title, Runnable action) { String ok = MessageManager.getString("action.ok"); String cancel = MessageManager.getString("action.cancel"); String[] options = new String[] { ok, cancel }; - /* JvOptionPane.newOptionDialog(parent) .setResponseHandler(JvOptionPane.OK_OPTION, action) .showInternalDialog(panel, title, JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null, options, ok); - */ - List> actions = new ArrayList<>(); + /* + List actions = new ArrayList<>(); actions.add(action); actions.add(JvOptionPane.NULLCALLABLE); - + JvOptionPane.frameDialog(panel, title, JvOptionPane.PLAIN_MESSAGE, options, ok, actions, false); + */ } } diff --git a/src/jalview/gui/FeatureEditor.java b/src/jalview/gui/FeatureEditor.java index ba9da67..7117508 100644 --- a/src/jalview/gui/FeatureEditor.java +++ b/src/jalview/gui/FeatureEditor.java @@ -33,7 +33,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Callable; import javax.swing.JComboBox; import javax.swing.JLabel; @@ -428,9 +427,8 @@ public class FeatureEditor */ public void showDialog() { - Callable okAction = forCreate ? getCreateAction() - : getAmendAction(); - Callable cancelAction = getCancelAction(); + Runnable okAction = forCreate ? getCreateAction() : getAmendAction(); + Runnable cancelAction = getCancelAction(); /* * set dialog action handlers for OK (create/Amend) and Cancel options @@ -476,12 +474,11 @@ public class FeatureEditor * * @return */ - protected Callable getCancelAction() + protected Runnable getCancelAction() { - Callable okAction = () -> { + Runnable okAction = () -> { ap.highlightSearchResults(null); ap.paintAlignment(false, false); - return null; }; return okAction; } @@ -496,14 +493,14 @@ public class FeatureEditor * * @return */ - protected Callable getCreateAction() + protected Runnable getCreateAction() { - Callable okAction = new Callable() + Runnable okAction = new Runnable() { boolean useLastDefaults = features.get(0).getType() == null; @Override - public Void call() + public void run() { final String enteredType = name.getText().trim(); final String enteredGroup = group.getText().trim(); @@ -543,7 +540,6 @@ public class FeatureEditor repaintPanel(); } - return null; } }; return okAction; @@ -556,15 +552,14 @@ public class FeatureEditor * * @return */ - protected Callable getDeleteAction() + protected Runnable getDeleteAction() { - Callable deleteAction = () -> { + Runnable deleteAction = () -> { SequenceFeature sf = features.get(featureIndex); sequences.get(0).getDatasetSequence().deleteFeature(sf); fr.featuresAdded(); ap.getSeqPanel().seqCanvas.highlightSearchResults(null); ap.paintAlignment(true, true); - return null; }; return deleteAction; } @@ -655,9 +650,9 @@ public class FeatureEditor * * @return */ - protected Callable getAmendAction() + protected Runnable getAmendAction() { - Callable okAction = new Callable() + Runnable okAction = new Runnable() { boolean useLastDefaults = features.get(0).getType() == null; @@ -666,7 +661,7 @@ public class FeatureEditor String featureGroup = group.getText(); @Override - public Void call() + public void run() { final String enteredType = name.getText().trim(); final String enteredGroup = group.getText().trim(); @@ -729,7 +724,6 @@ public class FeatureEditor fr.featuresAdded(); } repaintPanel(); - return null; } }; return okAction; diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 2c8f47a..2e9731d 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -951,7 +951,6 @@ public class FeatureSettings extends JPanel chooser.setResponseHandler(0, () -> { File file = chooser.getSelectedFile(); load(file); - return null; }); chooser.showOpenDialog(this); } diff --git a/src/jalview/gui/ImageExporter.java b/src/jalview/gui/ImageExporter.java index 1d472f1..32704d6 100644 --- a/src/jalview/gui/ImageExporter.java +++ b/src/jalview/gui/ImageExporter.java @@ -23,7 +23,6 @@ package jalview.gui; import java.awt.Component; import java.awt.Graphics; import java.io.File; -import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import jalview.bin.Cache; @@ -165,23 +164,16 @@ public class ImageExporter && !Jalview.isHeadlessMode()) { final File chosenFile = file; - Callable okAction = () -> { + Runnable okAction = () -> { exportImage(chosenFile, !textSelected.get(), width, height, messageId, userBis); - return null; }; LineartOptions epsOption = new LineartOptions(TYPE.EPS.getName(), textSelected); - epsOption.setResponseAction(1, new Callable() - { - @Override - public Void call() - { - setStatus(MessageManager.formatMessage( - "status.cancelled_image_export_operation", - imageType.getName()), messageId); - return null; - } + epsOption.setResponseAction(1, () -> { + setStatus(MessageManager.formatMessage( + "status.cancelled_image_export_operation", + imageType.getName()), messageId); }); epsOption.setResponseAction(0, okAction); epsOption.showDialog(); diff --git a/src/jalview/gui/JvOptionPane.java b/src/jalview/gui/JvOptionPane.java index 9b0d098..c0efd4a 100644 --- a/src/jalview/gui/JvOptionPane.java +++ b/src/jalview/gui/JvOptionPane.java @@ -41,7 +41,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -73,8 +72,7 @@ public class JvOptionPane extends JOptionPane private static boolean interactiveMode = true; - public static final Callable NULLCALLABLE = () -> { - return null; + public static final Runnable NULLCALLABLE = () -> { }; private Component parentComponent; @@ -83,7 +81,7 @@ public class JvOptionPane extends JOptionPane private JDialog dialog = null; - private Map> callbacks = new HashMap<>(); + private Map callbacks = new HashMap<>(); /* * JalviewJS reports user choice in the dialog as the selected option (text); @@ -860,7 +858,7 @@ public class JvOptionPane extends JOptionPane initialValueButton = jb; int buttonAction = buttonActions[i]; - Callable action = callbacks.get(buttonAction); + Runnable action = callbacks.get(buttonAction); jb.setText((String) o); jb.addActionListener(new ActionListener() { @@ -889,7 +887,7 @@ public class JvOptionPane extends JOptionPane JOptionPane joptionpane = (JOptionPane) joptionpaneObject; joptionpane.setValue(buttonAction); if (action != null) - getExecutor().submit(action); + new Thread(action).start(); joptionpane.transferFocusBackward(); joptionpane.setVisible(false); // put focus and raise parent window if possible, unless cancel or @@ -985,7 +983,7 @@ public class JvOptionPane extends JOptionPane { Object o = options[i]; int buttonAction = buttonActions[i]; - Callable action = callbacks.get(buttonAction); + Runnable action = callbacks.get(buttonAction); JButton jb = new JButton(); jb.setText((String) o); jb.addActionListener(new ActionListener() @@ -996,7 +994,7 @@ public class JvOptionPane extends JOptionPane { joptionpane.setValue(buttonAction); if (action != null) - getExecutor().submit(action); + new Thread(action).start(); // joptionpane.transferFocusBackward(); joptionpane.transferFocusBackward(); joptionpane.setVisible(false); @@ -1153,8 +1151,7 @@ public class JvOptionPane extends JOptionPane * } */ @Override - public JvOptionPane setResponseHandler(Object response, - Callable action) + public JvOptionPane setResponseHandler(Object response, Runnable action) { if (action == null) { @@ -1164,18 +1161,6 @@ public class JvOptionPane extends JOptionPane return this; } - public ExecutorService getExecutor() - { - if (executor == null) - executor = Executors.newCachedThreadPool(); - return executor; - } - - public void setExecutor(ExecutorService es) - { - executor = es; - } - public void setDialog(JDialog d) { dialog = d; @@ -1319,12 +1304,12 @@ public class JvOptionPane extends JOptionPane { return; } - Callable action = callbacks.get(response); + Runnable action = callbacks.get(response); if (action != null) { try { - getExecutor().submit(action).get(); + new Thread(action).start(); // action.call(); } catch (Exception e) { @@ -1403,7 +1388,7 @@ public class JvOptionPane extends JOptionPane { Object o = options[i]; int buttonAction = buttonActions[i]; - Callable action = callbacks.get(buttonAction); + Runnable action = callbacks.get(buttonAction); JButton jb; if (buttons != null && buttons.length > i && buttons[i] != null) { @@ -1421,7 +1406,7 @@ public class JvOptionPane extends JOptionPane { joptionpane.setValue(buttonAction); if (action != null) - getExecutor().submit(action); + new Thread(action).start(); // joptionpane.transferFocusBackward(); joptionpane.transferFocusBackward(); joptionpane.setVisible(false); @@ -1562,7 +1547,7 @@ public class JvOptionPane extends JOptionPane public static JvOptionPane frameDialog(Object message, String title, int messageType, String[] buttonsTextS, String defaultButtonS, - List> handlers, boolean modal) + List handlers, boolean modal) { JFrame parent = new JFrame(); JvOptionPane jvop = JvOptionPane.newOptionDialog(); @@ -1620,10 +1605,10 @@ public class JvOptionPane extends JOptionPane } final int dt = dialogType; - jvop.getExecutor().execute(() -> { + new Thread(() -> { jvop.showDialog(message, title, dt, messageType, null, buttonsText, defaultButton, modal, buttons); - }); + }).start(); return jvop; } diff --git a/src/jalview/gui/LineartOptions.java b/src/jalview/gui/LineartOptions.java index ff4ff6a..2a96eb4 100644 --- a/src/jalview/gui/LineartOptions.java +++ b/src/jalview/gui/LineartOptions.java @@ -23,7 +23,6 @@ package jalview.gui; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.BorderFactory; @@ -96,7 +95,7 @@ public class LineartOptions extends JPanel * * @param action */ - public void setResponseAction(Object response, Callable action) + public void setResponseAction(Object response, Runnable action) { dialog.setResponseHandler(response, action); } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 562d0f5..be9293f 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1990,7 +1990,6 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sg.setName(dialog.getName()); sg.setDescription(dialog.getDescription()); refresh(); - return null; }); } @@ -2028,26 +2027,17 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { if (dialog.getName().indexOf(" ") > -1) { - if (!Platform.isJS()) - /** - * Java only - * - * @j2sIgnore - */ - { - String ok = MessageManager.getString("action.ok"); - String cancel = MessageManager - .getString("action.cancel"); - String message = MessageManager.getString( - "label.spaces_converted_to_underscores"); - String title = MessageManager.getString( - "label.no_spaces_allowed_sequence_name"); - Object[] options = new Object[] { ok, cancel }; - - JvOptionPane.frameDialog(message, title, - JvOptionPane.WARNING_MESSAGE, null, null, null, - false); - } + String ok = MessageManager.getString("action.ok"); + String cancel = MessageManager.getString("action.cancel"); + String message = MessageManager.getString( + "label.spaces_converted_to_underscores"); + String title = MessageManager.getString( + "label.no_spaces_allowed_sequence_name"); + Object[] options = new Object[] { ok, cancel }; + + JvOptionPane.frameDialog(message, title, + JvOptionPane.WARNING_MESSAGE, null, null, null, + false); } sequence.setName(dialog.getName().replace(' ', '_')); ap.paintAlignment(false, false); @@ -2055,7 +2045,6 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sequence.setDescription(dialog.getDescription()); ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences()); - return null; }); } @@ -2290,7 +2279,6 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener ap.alignFrame.addHistoryItem(editCommand); ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences()); - return null; }); } } diff --git a/src/jalview/gui/QuitHandler.java b/src/jalview/gui/QuitHandler.java index 9a44306..5d628ff 100644 --- a/src/jalview/gui/QuitHandler.java +++ b/src/jalview/gui/QuitHandler.java @@ -2,7 +2,6 @@ package jalview.gui; import java.io.File; import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -58,21 +57,18 @@ public class QuitHandler public static QResponse setQuitHandler() { FlatDesktop.setQuitHandler(response -> { - Callable performQuit = () -> { + Runnable performQuit = () -> { response.performQuit(); setResponse(QResponse.QUIT); - return null; }; - Callable performForceQuit = () -> { + Runnable performForceQuit = () -> { response.performQuit(); setResponse(QResponse.FORCE_QUIT); - return null; }; - Callable cancelQuit = () -> { + Runnable cancelQuit = () -> { response.cancelQuit(); // reset setResponse(QResponse.NULL); - return null; }; getQuitResponse(true, performQuit, performForceQuit, cancelQuit); }); @@ -93,25 +89,22 @@ public class QuitHandler return gotQuitResponse; } - public static final Callable defaultCancelQuit = () -> { + public static final Runnable defaultCancelQuit = () -> { Console.debug("QuitHandler: (default) Quit action CANCELLED by user"); // reset setResponse(QResponse.CANCEL_QUIT); - return null; }; - public static final Callable defaultOkQuit = () -> { + public static final Runnable defaultOkQuit = () -> { Console.debug("QuitHandler: (default) Quit action CONFIRMED by user"); setResponse(QResponse.QUIT); - return null; }; - public static final Callable defaultForceQuit = () -> { + public static final Runnable defaultForceQuit = () -> { Console.debug("QuitHandler: (default) Quit action FORCED by user"); // note that shutdown hook will not be run Runtime.getRuntime().halt(0); setResponse(QResponse.FORCE_QUIT); // this line never reached! - return null; }; public static QResponse getQuitResponse(boolean ui) @@ -120,8 +113,8 @@ public class QuitHandler defaultCancelQuit); } - public static QResponse getQuitResponse(boolean ui, Callable okQuit, - Callable forceQuit, Callable cancelQuit) + public static QResponse getQuitResponse(boolean ui, Runnable okQuit, + Runnable forceQuit, Runnable cancelQuit) { QResponse got = gotQuitResponse(); if (got != QResponse.NULL && got != QResponse.CANCEL_QUIT) @@ -169,7 +162,8 @@ public class QuitHandler qd.showDialogOnTopAsync( new StringBuilder( MessageManager.getString("label.quit_jalview")) - .append("\n").append(messageString).toString(), + .append("\n").append(messageString) + .toString(), MessageManager.getString("action.quit"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] @@ -239,7 +233,7 @@ public class QuitHandler } } - Callable next = null; + Runnable next = null; switch (gotQuitResponse()) { case QUIT: @@ -280,9 +274,8 @@ public class QuitHandler return gotQuitResponse(); } - private static QResponse waitQuit(boolean interactive, - Callable okQuit, Callable forceQuit, - Callable cancelQuit) + private static QResponse waitQuit(boolean interactive, Runnable okQuit, + Runnable forceQuit, Runnable cancelQuit) { // check for saves in progress if (!BackupFiles.hasSavesInProgress()) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 2b16495..1f39f3c 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -33,7 +33,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.concurrent.Callable; import java.util.concurrent.Executors; import javax.swing.JCheckBox; @@ -347,7 +346,7 @@ public class StructureChooser extends GStructureChooser }; // fetch db refs if OK pressed - final Callable discoverCanonicalDBrefs = () -> { + final Runnable discoverCanonicalDBrefs = () -> { btn_queryTDB.setEnabled(false); populateSeqsWithoutSourceDBRef(); @@ -369,14 +368,12 @@ public class StructureChooser extends GStructureChooser // call finished action directly afterDbRefFetch.finished(); } - return null; }; - final Callable revertview = () -> { + final Runnable revertview = () -> { if (lastSelected != null) { cmb_filterOption.setSelectedItem(lastSelected); } - return null; }; int threshold = Cache.getDefault("UNIPROT_AUTOFETCH_THRESHOLD", THRESHOLD_WARN_UNIPROT_FETCH_NEEDED); diff --git a/src/jalview/gui/TextColourChooser.java b/src/jalview/gui/TextColourChooser.java index e72a084..5bc6563 100644 --- a/src/jalview/gui/TextColourChooser.java +++ b/src/jalview/gui/TextColourChooser.java @@ -27,7 +27,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.Callable; import javax.swing.BorderFactory; import javax.swing.JLabel; @@ -152,10 +151,9 @@ public class TextColourChooser MessageManager.getString("action.cancel") }; String title = MessageManager .getString("label.adjust_foreground_text_colour_threshold"); - Callable action = () -> // response for 1 = Cancel + Runnable action = () -> // response for 1 = Cancel { restoreInitialSettings(); - return null; }; JvOptionPane.newOptionDialog(alignPanel.alignFrame) .setResponseHandler(1, action).showInternalDialog(bigpanel, diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 298b8b4..14f9adf 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -686,7 +686,6 @@ public class UserDefinedColours extends GUserDefinedColours } addNewColourScheme(choice.getPath()); - return null; }); chooser.showOpenDialog(this); diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index c5ce35b..7b661f3 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -26,7 +26,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Locale; -import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import org.jfree.graphics2d.svg.SVGGraphics2D; @@ -221,9 +220,8 @@ public class HtmlSvgOutput extends HTMLOutput /* * configure the action to run on OK in the dialog */ - Callable okAction = () -> { + Runnable okAction = () -> { doOutput(textOption.get()); - return null; }; /* @@ -237,7 +235,6 @@ public class HtmlSvgOutput extends HTMLOutput setProgressMessage(MessageManager.formatMessage( "status.cancelled_image_export_operation", getDescription())); - return null; }); svgOption.setResponseAction(0, okAction); svgOption.showDialog(); diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index 3b6e325..cb47610 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -21,12 +21,6 @@ ////////////////////////////////////////////////////////////////// package jalview.io; -import jalview.bin.Cache; -import jalview.gui.JvOptionPane; -import jalview.util.MessageManager; -import jalview.util.Platform; -import jalview.util.dialogrunner.DialogRunnerI; - import java.awt.Component; import java.awt.Dimension; import java.awt.EventQueue; @@ -44,7 +38,6 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.Vector; -import java.util.concurrent.Callable; import javax.swing.BoxLayout; import javax.swing.DefaultListCellRenderer; @@ -80,7 +73,7 @@ public class JalviewFileChooser extends JFileChooser { private static final long serialVersionUID = 1L; - private Map callbacks = new HashMap<>(); + private Map callbacks = new HashMap<>(); File selectedFile = null; @@ -628,7 +621,7 @@ public class JalviewFileChooser extends JFileChooser */ @Override - public DialogRunnerI setResponseHandler(Object response, Callable action) + public DialogRunnerI setResponseHandler(Object response, Runnable action) { callbacks.put(response, action); return this; @@ -644,12 +637,12 @@ public class JalviewFileChooser extends JFileChooser { return; } - Callable action = callbacks.get(response); + Runnable action = callbacks.get(response); if (action != null) { try { - action.call(); + action.run(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/jalview/util/dialogrunner/DialogRunnerI.java b/src/jalview/util/dialogrunner/DialogRunnerI.java index 1fc41e7..ce96bad 100644 --- a/src/jalview/util/dialogrunner/DialogRunnerI.java +++ b/src/jalview/util/dialogrunner/DialogRunnerI.java @@ -20,8 +20,6 @@ */ package jalview.util.dialogrunner; -import java.util.concurrent.Callable; - /** * An interface for blocking dialog response handling. This is motivated by * JalviewJS - when running as Javascript, there is only a single thread, and @@ -43,7 +41,7 @@ public interface DialogRunnerI * @param action * @return */ - DialogRunnerI setResponseHandler(Object response, Callable action); + DialogRunnerI setResponseHandler(Object response, Runnable action); // DialogRunnerI setResponseHandler(Object response, Runnable action);