import jalview.api.AlignViewportI;
import jalview.io.FileFormatI;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
*
* @param action
*/
- public void setResponseAction(Object response, RunResponse action)
+ public void setResponseAction(Object response, Runnable action)
{
- dialog.addResponse(response, action);
+ dialog.setResponseHandler(response, action);
}
/**
import jalview.schemes.TCoffeeColourScheme;
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
}
AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
- RunResponse cancelAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
+ Runnable cancelAction = new Runnable()
{
@Override
public void run()
lastSaveSuccessful = false;
}
};
- RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
+ Runnable outputAction = new Runnable()
{
@Override
public void run()
FileFormatI fileFormat = FileFormats.getInstance()
.forName(fileFormatName);
AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
- RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
+ Runnable outputAction = new Runnable()
{
@Override
public void run()
MessageManager.getString("label.load_jalview_annotations"));
chooser.setToolTipText(
MessageManager.getString("label.load_jalview_annotations"));
- chooser.addResponse(0, new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
chooser.setToolTipText(
MessageManager.getString("label.load_tree_file"));
- chooser.addResponse(0,new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0,new Runnable()
{
@Override
public void run()
chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
final AlignFrame us = this;
- chooser.addResponse(0, new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
import jalview.structure.StructureSelectionManager;
import jalview.structure.VamsasSource;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.AutoCalcSetting;
* in reverse order)
*/
JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
- .addResponse(0, new RunResponse(0)
+ .setResponseHandler(0, new Runnable()
{
@Override
public void run()
{
addDataToAlignment(al);
}
- }).addResponse(1, new RunResponse(1)
+ }).setResponseHandler(1, new Runnable()
{
@Override
public void run()
{
us.openLinkedAlignmentAs(al, title, true);
}
- }).addResponse(2, new RunResponse(2)
+ }).setResponseHandler(2, new Runnable()
{
@Override
public void run()
import jalview.util.Comparison;
import jalview.util.MessageManager;
import jalview.util.Platform;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.Color;
import java.awt.Cursor;
annotation.description, name, description);
dialog.showDialog(ap.alignFrame, title,
- new RunResponse(JvOptionPane.OK_OPTION)
+ new Runnable()
{
@Override
public void run()
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.util.UrlConstants;
-import jalview.util.dialogrunner.RunResponse;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.ParamManager;
import jalview.ws.utils.UrlDownloadClient;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
-import java.util.StringTokenizer;
import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
MessageManager.getString("label.open_local_file"));
chooser.setToolTipText(MessageManager.getString("action.open"));
- chooser.addResponse(0, new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
Object[] options = new Object[] { MessageManager.getString("action.ok"),
MessageManager.getString("action.cancel") };
- RunResponse action = new RunResponse(JvOptionPane.OK_OPTION) {
+ Runnable action = new Runnable() {
@Override
public void run()
{
}};
String dialogOption = MessageManager
.getString("label.input_alignment_from_url");
- JvOptionPane.newOptionDialog(desktop).addResponse(0, action)
+ JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action)
.showInternalDialog(panel, dialogOption,
JvOptionPane.YES_NO_CANCEL_OPTION,
JvOptionPane.PLAIN_MESSAGE, null, options,
"Jalview Project");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
- chooser.addResponse(0, new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
package jalview.gui;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.FlowLayout;
import java.awt.Font;
* @param action
*/
public void showDialog(JComponent parent, String title,
- RunResponse action)
+ Runnable action)
{
Object[] options = new Object[] { MessageManager.getString("action.ok"),
MessageManager.getString("action.cancel") };
- JvOptionPane.newOptionDialog(parent).addResponse(0, action)
+ JvOptionPane.newOptionDialog(parent).setResponseHandler(0, action)
.showInternalDialog(panel, title,
JvOptionPane.YES_NO_CANCEL_OPTION,
JvOptionPane.PLAIN_MESSAGE, null, options,
import jalview.schemes.FeatureColour;
import jalview.util.ColorUtils;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.BorderLayout;
import java.awt.Color;
*/
public void showDialog()
{
- RunResponse okAction = forCreate ? getCreateAction() : getAmendAction();
- RunResponse cancelAction = getCancelAction();
+ Runnable okAction = forCreate ? getCreateAction() : getAmendAction();
+ Runnable cancelAction = getCancelAction();
/*
* set dialog action handlers for OK (create/Amend) and Cancel options
* also for Delete if applicable (when amending features)
*/
JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
- .addResponse(0, okAction).addResponse(2, cancelAction);
+ .setResponseHandler(0, okAction).setResponseHandler(2, cancelAction);
if (!forCreate)
{
- dialog.addResponse(1, getDeleteAction());
+ dialog.setResponseHandler(1, getDeleteAction());
}
String title = null;
*
* @return
*/
- protected RunResponse getCancelAction()
+ protected Runnable getCancelAction()
{
- RunResponse okAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
+ Runnable okAction = new Runnable()
{
@Override
public void run()
*
* @return
*/
- protected RunResponse getCreateAction()
+ protected Runnable getCreateAction()
{
- RunResponse okAction = new RunResponse(JvOptionPane.OK_OPTION)
+ Runnable okAction = new Runnable()
{
boolean useLastDefaults = features.get(0).getType() == null;
*
* @return
*/
- protected RunResponse getDeleteAction()
+ protected Runnable getDeleteAction()
{
- RunResponse deleteAction = new RunResponse(JvOptionPane.NO_OPTION)
+ Runnable deleteAction = new Runnable()
{
public void run()
{
*
* @return
*/
- protected RunResponse getAmendAction()
+ protected Runnable getAmendAction()
{
- RunResponse okAction = new RunResponse(JvOptionPane.OK_OPTION)
+ Runnable okAction = new Runnable()
{
boolean useLastDefaults = features.get(0).getType() == null;
import jalview.schemes.FeatureColour;
import jalview.util.MessageManager;
import jalview.util.Platform;
-import jalview.util.dialogrunner.RunResponse;
import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
import jalview.xml.binding.jalview.JalviewUserColours;
import jalview.xml.binding.jalview.JalviewUserColours.Colour;
chooser.setDialogTitle(
MessageManager.getString("label.load_feature_colours"));
chooser.setToolTipText(MessageManager.getString("action.load"));
- chooser.addResponse(0, new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
import jalview.util.ImageMaker;
import jalview.util.ImageMaker.TYPE;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.Component;
import java.awt.Graphics;
import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.swing.JOptionPane;
-
/**
* A class that marshals steps in exporting a view in image graphics format
* <ul>
&& !Jalview.isHeadlessMode())
{
final File chosenFile = file;
- RunResponse okAction = new RunResponse(JOptionPane.OK_OPTION)
+ Runnable okAction = new Runnable()
{
@Override
public void run()
};
LineartOptions epsOption = new LineartOptions(TYPE.EPS.getName(),
textSelected);
- epsOption.setResponseAction(1, new RunResponse(JOptionPane.NO_OPTION)
+ epsOption.setResponseAction(1, new Runnable()
{
@Override
public void run()
package jalview.gui;
import jalview.bin.Jalview;
-import jalview.util.dialogrunner.DialogRunner;
import jalview.util.dialogrunner.DialogRunnerI;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.Component;
import java.awt.HeadlessException;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.swing.Icon;
import javax.swing.JOptionPane;
private Component parentComponent;
- private DialogRunnerI runner = new DialogRunner();
+ private Map<Object, Runnable> callbacks = new HashMap<>();
/*
* JalviewJS reports user choice in the dialog as the selected
if (!isInteractiveMode())
{
- runner.handleResponse(getMockResponse());
+ handleResponse(getMockResponse());
}
// two uses:
//
*/
if (!Jalview.isJS())
{
- runner.handleResponse(response);
+ handleResponse(response);
}
}
{
if (!isInteractiveMode())
{
- runner.handleResponse(getMockResponse());
+ handleResponse(getMockResponse());
}
ourOptions = Arrays.asList(options);
}
if (!Jalview.isJS())
{
- runner.handleResponse(response);
+ handleResponse(response);
}
}
@Override
- public JvOptionPane addResponse(Object response, RunResponse action)
+ public JvOptionPane setResponseHandler(Object response, Runnable action)
{
- runner.addResponse(response, action);
+ callbacks.put(response, action);
return this;
}
int ourOption = ourOptions.indexOf(newValue);
if (ourOption >= 0)
{
- runner.handleResponse(ourOption);
+ handleResponse(ourOption);
}
else
{
// try our luck..
- runner.handleResponse(newValue);
+ handleResponse(newValue);
+ }
+ }
+
+ @Override
+ public void handleResponse(Object response)
+ {
+ /*
+ * this test is for NaN in Chrome
+ */
+ if (response != null && !response.equals(response))
+ {
+ return;
+ }
+ Runnable action = callbacks.get(response);
+ if (action != null)
+ {
+ action.run();
}
}
}
import jalview.bin.Cache;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
*
* @param action
*/
- public void setResponseAction(Object response, RunResponse action)
+ public void setResponseAction(Object response, Runnable action)
{
- dialog.addResponse(response, action);
+ dialog.setResponseHandler(response, action);
}
/**
import jalview.util.MessageManager;
import jalview.util.StringUtils;
import jalview.util.UrlLink;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
MessageManager.getString("label.group_description"));
dialog.showDialog(ap.alignFrame,
MessageManager.getString("label.edit_group_name_description"),
- new RunResponse(JvOptionPane.OK_OPTION)
+ new Runnable()
{
@Override
public void run()
dialog.showDialog(ap.alignFrame,
MessageManager.getString(
"label.edit_sequence_name_description"),
- new RunResponse(JvOptionPane.OK_OPTION)
+ new Runnable()
{
@Override
public void run()
null, MessageManager.getString("label.edit_sequence"), null);
dialog.showDialog(ap.alignFrame,
MessageManager.getString("label.edit_sequence"),
- new RunResponse(JvOptionPane.OK_OPTION)
+ new Runnable()
{
@Override
public void run()
import jalview.datamodel.SequenceGroup;
import jalview.gui.JalviewColourChooser.ColourChooserListener;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.BorderLayout;
import java.awt.Color;
MessageManager.getString("action.cancel") };
String title = MessageManager
.getString("label.adjust_foreground_text_colour_threshold");
- RunResponse action = new RunResponse(JvOptionPane.NO_OPTION) // = 1 Cancel
+ Runnable action = new Runnable() // response for 1 = Cancel
{
@Override
public void run()
restoreInitialSettings();
}
};
- JvOptionPane.newOptionDialog(alignPanel).addResponse(1, action)
+ JvOptionPane.newOptionDialog(alignPanel).setResponseHandler(1, action)
.showInternalDialog(bigpanel, title,
JvOptionPane.YES_NO_CANCEL_OPTION,
JvOptionPane.PLAIN_MESSAGE, null, options,
import jalview.util.ColorUtils;
import jalview.util.Format;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import jalview.xml.binding.jalview.JalviewUserColours;
import jalview.xml.binding.jalview.JalviewUserColours.Colour;
import jalview.xml.binding.jalview.ObjectFactory;
chooser.setDialogTitle(
MessageManager.getString("label.load_colour_scheme"));
chooser.setToolTipText(MessageManager.getString("action.load"));
- chooser.addResponse(0, new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
import jalview.gui.OOMWarning;
import jalview.math.AlignmentDimension;
import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.Graphics;
import java.awt.print.PrinterException;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.swing.JOptionPane;
-
import org.jfree.graphics2d.svg.SVGGraphics2D;
import org.jfree.graphics2d.svg.SVGHints;
/*
* configure the action to run on OK in the dialog
*/
- RunResponse okAction = new RunResponse(JOptionPane.OK_OPTION)
+ Runnable okAction = new Runnable()
{
@Override
public void run()
if (renderStyle.equalsIgnoreCase("Prompt each time") && !isHeadless())
{
LineartOptions svgOption = new LineartOptions("HTML", textOption);
- svgOption.setResponseAction(1, new RunResponse(JOptionPane.NO_OPTION)
+ svgOption.setResponseAction(1, new Runnable()
{
@Override
public void run()
package jalview.io;
import jalview.bin.Cache;
-import jalview.bin.Jalview;
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
import jalview.util.Platform;
-import jalview.util.dialogrunner.DialogRunner;
import jalview.util.dialogrunner.DialogRunnerI;
-import jalview.util.dialogrunner.RunResponse;
import java.awt.Component;
import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
{
private static final long serialVersionUID = 1L;
- private DialogRunnerI runner = new DialogRunner();
+ private Map<Object, Runnable> callbacks;
File selectedFile = null;
@Override
public int showOpenDialog(Component parent)
{
- // runner.resetResponses();
int value = super.showOpenDialog(this);
- if (!Jalview.isJS())
- {
- runner.handleResponse(value);
- }
+
+ /*
+ * code below here is not reached in JalviewJS, instead
+ * propertyChange() is called for dialog action
+ */
+ handleResponse(value);
return value;
}
}
@Override
- public DialogRunnerI addResponse(Object response, RunResponse action)
+ public DialogRunnerI setResponseHandler(Object response, Runnable action)
+ {
+ callbacks.put(response, action);
+ return this;
+ }
+
+ @Override
+ public void handleResponse(Object response)
{
- return runner.addResponse(response, action);
+ /*
+ * this test is for NaN in Chrome
+ */
+ if (response != null && !response.equals(response))
+ {
+ return;
+ }
+ Runnable action = callbacks.get(response);
+ if (action != null)
+ {
+ action.run();
+ }
}
/**
// TODO other properties need runners...
switch (evt.getPropertyName())
{
+ /*
+ * property name here matches that used in JFileChooser.js
+ */
case "SelectedFile":
- runner.handleResponse(APPROVE_OPTION);
+ handleResponse(APPROVE_OPTION);
break;
}
}
+++ /dev/null
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.util.dialogrunner;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A helper class that executes registered Runnable actions corresponding to
- * user responses in a dialog. This is to enable dialog execution in JalviewJS,
- * where everything must happen in a single thread of execution. That is, the
- * dialog has to 'know' all actions that follow a user choice, rather than
- * returning a response to allow a separate thread to decide the next action.
- *
- * @author jprocter
- */
-public class DialogRunner implements DialogRunnerI
-{
- private Map<Object, List<RunResponse>> callbacks = new HashMap<>();
-
- /**
- * Constructor
- */
- public DialogRunner()
- {
- }
-
- @Override
- public DialogRunnerI addResponse(Object response, RunResponse action)
- {
- List<RunResponse> actions = callbacks.get(response);
- if (actions == null)
- {
- actions = new ArrayList<>();
- callbacks.put(response, actions);
- }
- actions.add(action);
- return this;
- }
-
- /**
- * Handles a response by running the chain of registered actions (if any).
- * Answers the list of responses run (in order).
- *
- * @param response
- */
- @Override
- public List<RunResponse> handleResponse(Object response)
- {
- List<RunResponse> responsesRun = new ArrayList<RunResponse>();
-
- /*
- * this test is for NaN in Chrome
- */
- if (response != null && !response.equals(response))
- {
- return responsesRun;
- }
-
- runResponse(response, responsesRun);
- if (responsesRun.isEmpty())
- {
- System.err.println("Did nothing for " + response);
- }
-
- return responsesRun;
- }
-
- /**
- * Runs any response handlers registered for the given response. If any
- * response provides a return value, then the handler for that value is
- * run next recursively. Handlers are only run once.
- *
- * @param response
- * @param alreadyRun
- */
- private void runResponse(Object response, List<RunResponse> alreadyRun)
- {
- /*
- * this test is for NaN in Chrome
- */
- if (response != null && !response.equals(response))
- {
- return;
- }
-
- List<RunResponse> actions = response == null ? null : callbacks.get(response);
-
- if (actions == null)
- {
- System.err.println("Doing nothing for " + response);
- return;
- }
- for (RunResponse action : actions)
- {
- if (!alreadyRun.contains(action))
- {
- action.setReturnValue(null);
- action.run();
- alreadyRun.add(action);
- Object returnValue = action.getReturnValue();
- if (returnValue != null)
- {
- /*
- * RunResponse wants to chain another action
- */
- runResponse(returnValue, alreadyRun);
- }
- break;
- }
- }
- }
-}
*/
package jalview.util.dialogrunner;
-import java.util.List;
-
/**
- * functional pattern for blocking dialog response handling
+ * An interface for blocking dialog response handling. This is motivated by
+ * JalviewJS - when running as Javascript, there is only a single thread, and
+ * blocking dialogs have to be responsible for performing any actions required
+ * for user responses.
*
* @author jprocter
*
*/
-public interface DialogRunnerI
-{
+public interface DialogRunnerI {
- DialogRunnerI addResponse(Object response, RunResponse action);
+ /**
+ * Sets the action to be performed when the dialog returns the given response.
+ * Note this also handles <code>int</code>-valued responses, which will be
+ * converted to <code>Integer</code> when this method is invoked.
+ *
+ * @param response
+ * @param action
+ * @return
+ */
+ DialogRunnerI setResponseHandler(Object response, Runnable action);
- /**
- * Runs any registered handlers for the given response, and answers the list
- * of responses run (if any) in order run
- *
- * @param response
- * @return
- */
- default List<RunResponse> handleResponse(Object response)
- {
- return null;
- }
+ /**
+ * Runs the registered handler (if any) for the given response. The default
+ * action is to do nothing. Typically an action will be need on 'OK' or other
+ * positive selection in the dialog. An action might in some cases also be
+ * needed for a 'Cancel' response.
+ *
+ * @param response
+ * @return
+ */
+ default void handleResponse(Object response) {
+ }
}
+++ /dev/null
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.util.dialogrunner;
-
-/**
- * A Runnable that is kind of like a future, that allows a sequence of Runabbles
- * to be conditionally executed by DialogRunner
- *
- * @author jprocter
- *
- */
-public abstract class RunResponse implements Runnable
-{
- /**
- * Response that triggers the Run method
- */
- Object trigger;
-
- /**
- * set by run() on exit
- */
- protected Object returnValue = null;
-
- public RunResponse(Object onTrigger)
- {
- trigger = onTrigger;
- }
-
- public Object getTrigger()
- {
- return trigger;
- }
-
- public void reset()
- {
- returnValue = null;
- }
-
- @Override
- public String toString()
- {
- return "Runner for " + trigger;
- }
-
- public Object getReturnValue()
- {
- return returnValue;
- }
-
- public void setReturnValue(Object o)
- {
- returnValue = o;
- }
-}
package jalview.util.dialogrunner;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.testng.annotations.Test;
-
-import junit.extensions.PA;
-
public class DialogRunnerTest
-{
- public class MockDialog implements DialogRunnerI<MockDialog>
- {
- DialogRunnerI runner = new DialogRunner();
-
- @Override
- public DialogRunnerI addResponse(Object response, RunResponse action)
- {
- return runner.addResponse(response, action);
- }
-
- public List<RunResponse> doDialog(String resp)
- {
- return runner.handleResponse(resp);
- }
-
- @Override
- public List<RunResponse> handleResponse(Object response)
- {
- return null;
- }
- }
-
- MockDialog dialog = new MockDialog();
-
- @Test
- public void testDialogRunner()
- {
- RunResponse ok, cancel, help, ineed;
- final String ooh = "OOOOoooOOOOH!";
- final String r_ok = "OK";
- final String r_cancel = "CANCEL";
- final String r_done = "DONE";
- final String r_help = "HELP";
- final String r_ddoit = "DIDNT DOIT";
- final String r_needsb = "I NEED SOMEBODY";
-
- ok = new RunResponse("OK")
- {
- @Override
- public void run()
- {
- returnValue = "DONE";
- }
- };
- final RunResponse befok = new RunResponse("OK")
- {
- @Override
- public void run()
- {
- returnValue = "OK";
- }
- };
-
- cancel = new RunResponse("CANCEL")
- {
- @Override
- public void run()
- {
- returnValue = r_ddoit;
- }
- };
- help = new RunResponse("HELP")
- {
- @Override
- public void run()
- {
- returnValue = r_needsb;
- }
- };
- ineed = new RunResponse(r_needsb)
- {
- @Override
- public void run()
- {
- returnValue = ooh;
- }
- };
-
- assertFalse(isRegistered(dialog.runner, ok));
-
- dialog.addResponse("OK", ok).addResponse("CANCEL", cancel).
- addResponse("HELP", help).addResponse(r_needsb, ineed);
-
- assertTrue(isRegistered(dialog.runner, ok));
-
-// Assert.assertFalse(dialog.runner.firstRunWasCalled);
- List<RunResponse> actions = dialog.doDialog("OK");
- // OK called, nothing else.
- // Assert.assertTrue(dialog.runner.firstRunWasCalled);
- assertTrue(actions.contains(ok));//ok.wasRun);
- assertEquals(ok.returnValue, r_done);
- assertFalse(actions.contains(cancel));//cancel.wasRun);
- assertEquals(actions/*dialog.runner.responses*/.size(), 2);
-
- // do it again - check it doesn't trigger again
- //ok.wasRun = false;
- actions = dialog.doDialog("OK");
- assertFalse(actions.contains(ok));
-
- // reset - everything false/null
-// dialog.runner.resetResponses();
-// Assert.assertFalse(dialog.runner.firstRunWasCalled);
-// Assert.assertFalse(ok.wasRun);
-// Assert.assertNull(ok.returned);
-// Assert.assertEquals(dialog.runner.responses.size(), 0);
-
- // cancel called ..
- actions = dialog.doDialog("HELP");
-// Assert.assertTrue(dialog.runner.firstRunWasCalled);
- assertFalse(actions.contains(ok));//ok.wasRun);
- assertEquals(ineed.returnValue, ooh);
- assertEquals(actions/*dialog.runner.responses*/.size(), 3);
-
- // TODO: test prepend and chained execution of tasks for a response.
-// Assert.assertFalse(dialog.runner.isRegistered(befok));
- dialog.runner.addResponse("OK", befok); //setFirstResponse(befok);
-
- assertTrue(isRegistered(dialog.runner, befok));
- assertTrue(isRegistered(dialog.runner, ok));
-
-// dialog.runner.resetResponses();
-
- actions = dialog.doDialog("OK");
- assertTrue(actions.contains(befok));//befok.wasRun);
- assertTrue(actions.contains(ok)); //ok.wasRun);
- assertEquals(actions/*dialog.runner.responses*/.size(), 3);
- }
-
- private boolean isRegistered(DialogRunnerI runner, RunResponse action)
- {
- Map<Object, Collection<Object>> actions = (Map<Object, Collection<Object>>) PA.getValue(runner, "callbacks");
- Collection<Object> registered = actions.get(action.getTrigger());
- return registered != null && registered.contains(action);
- }
-}
+{}
+++ /dev/null
-package jalview.util.dialogrunner;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertNull;
-
-import org.testng.annotations.Test;
-
-public class RunResponseTest
-{
- @Test
- public void testRunResponse()
- {
- RunResponse rr = new RunResponse("OK")
- {
- @Override
- public void run()
- {
- returnValue = "DONE";
- }
- };
- assertEquals(rr.trigger, "OK");
- assertNotEquals(rr.trigger, "NOTOK");
- assertNull(rr.returnValue);
-
- assertEquals(rr.returnValue, "DONE");
- rr.reset();
- assertNull(rr.returnValue);
-
- assertEquals(rr.toString(), "Runner for " + "OK");
-
- // just test the other constructors
- RunResponse rr12 = new RunResponse(12)
- {
- @Override
- public void run()
- {
- returnValue = "DONE";
- }
- };
- RunResponse rrpi = new RunResponse(new Double(3.142))
- {
- @Override
- public void run()
- {
- returnValue = "DONE";
- }
- };
- assertEquals(rr12.trigger, Integer.valueOf(12));
- assertEquals(rrpi.trigger, Double.valueOf(3.142));
-}
-}
import java.io.File;
import java.text.DecimalFormat;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import javax.swing.ImageIcon;
{
public static void main(String[] args)
{
- new JalviewJSTest().doTest2();
+ new JalviewJSTest().doTest3();
}
+ void doTest3()
+ {
+ System.out.println("Mungo".toLowerCase(Locale.getDefault()));
+ System.out.println("Mungo".toLowerCase(Locale.ENGLISH));
+ System.out.println("Mungo".toLowerCase(Locale.ROOT));
+ }
+
void doTest2() {
Map<File, String> map = new HashMap<>();
File f1 = new File("/var/folders/y/xyz");