label.pca_calculating = Calculating PCA
label.select_foreground_colour = Choose foreground colour
label.select_colour_for_text = Select Colour for Text
-label.adjunst_foreground_text_colour_threshold = Adjust Foreground Text Colour Threshold
+label.adjust_foreground_text_colour_threshold = Adjust Foreground Text Colour Threshold
label.select_subtree_colour = Select Sub-Tree Colour
label.create_new_sequence_features = Create New Sequence Feature(s)
label.amend_delete_features = Amend/Delete Features for {0}
label.pca_calculating = Calculando ACP
label.select_foreground_colour = Escoger color del primer plano
label.select_colour_for_text = Seleccione el color del texto
-label.adjunst_foreground_text_colour_threshold = Ajustar el umbral del color del texto en primer plano
+label.adjust_foreground_text_colour_threshold = Ajustar el umbral del color del texto en primer plano
label.select_subtree_colour = Seleccioanr el color del sub-árbol
label.create_new_sequence_features = Crear nueva(s) característica(s) de secuencia
label.amend_delete_features = Arrelgar/Borrar características de {0}
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(RunResponse action)
+ public void setResponseAction(Object response, Runnable action)
{
- dialog.addResponse(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()
{
AlignExportOptions choices = new AlignExportOptions(
alignPanel.getAlignViewport(), format, options);
- choices.setResponseAction(outputAction);
- choices.setResponseAction(cancelAction);
+ choices.setResponseAction(0, outputAction);
+ choices.setResponseAction(1, cancelAction);
choices.showDialog();
}
else
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()
{
AlignExportOptions choices = new AlignExportOptions(
alignPanel.getAlignViewport(), fileFormat, options);
- choices.setResponseAction(outputAction);
+ choices.setResponseAction(0, outputAction);
choices.showDialog();
}
else
MessageManager.getString("label.load_jalview_annotations"));
chooser.setToolTipText(
MessageManager.getString("label.load_jalview_annotations"));
- chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
-
@Override
public void run()
{
jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
}
-
});
chooser.showOpenDialog(this);
chooser.setToolTipText(
MessageManager.getString("label.load_tree_file"));
- chooser.addResponse(new jalview.util.dialogrunner.RunResponse(
- JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0,new Runnable()
{
@Override
public void run()
JvOptionPane.WARNING_MESSAGE);
}
}
- }).showOpenDialog(this);
+ });
+ chooser.showOpenDialog(this);
}
public TreePanel showNewickTree(NewickFile nf, String treeTitle)
chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
final AlignFrame us = this;
- chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
@Override
public void run()
{
-
- {
- String choice = chooser.getSelectedFile().getPath();
- Cache.setProperty("LAST_DIRECTORY", choice);
- SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
- new VCFLoader(choice).loadVCF(seqs, us);
- }
-
+ String choice = chooser.getSelectedFile().getPath();
+ Cache.setProperty("LAST_DIRECTORY", choice);
+ SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
+ new VCFLoader(choice).loadVCF(seqs, us);
};
- }).showOpenDialog(null);
+ });
+ chooser.showOpenDialog(null);
}
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(new RunResponse(0)
+ .setResponseHandler(0, new Runnable()
{
@Override
public void run()
{
addDataToAlignment(al);
}
- }).addResponse(new RunResponse(1)
+ }).setResponseHandler(1, new Runnable()
{
@Override
public void run()
{
us.openLinkedAlignmentAs(al, title, true);
}
- }).addResponse(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(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+ chooser.setResponseHandler(0, new Runnable()
{
-
@Override
public void run()
{
new FileLoader().LoadFile(viewport, selectedFile,
DataSourceType.FILE, format);
}
- }).showOpenDialog(this);
+ });
+ chooser.showOpenDialog(this);
}
/**
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(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(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;
}
/**
- * Shows the dialog, and runs the response action if OK is selected. Note the
- * RunResponse should be constructed to act on dialog return value
- * JvOptionPane.OK_OPTION.
+ * Shows the dialog, and runs the response action if OK is selected
*
* @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(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(okAction).addResponse(cancelAction);
+ .setResponseHandler(0, okAction).setResponseHandler(2, cancelAction);
if (!forCreate)
{
- dialog.addResponse(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(new RunResponse(JalviewFileChooser.APPROVE_OPTION){
-
- @Override
- public void run() {
- File file = chooser.getSelectedFile();
- load(file);
- }});
+ chooser.setResponseHandler(0, new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ File file = chooser.getSelectedFile();
+ load(file);
+ }
+ });
chooser.showOpenDialog(this);
}
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(new RunResponse(JOptionPane.NO_OPTION)
+ epsOption.setResponseAction(1, new Runnable()
{
@Override
public void run()
imageType.getName()), messageId);
}
});
- epsOption.setResponseAction(okAction);
+ epsOption.setResponseAction(0, okAction);
epsOption.showDialog();
/* no code here - JalviewJS cannot execute it */
}
package jalview.gui;
-import jalview.util.dialogrunner.DialogRunner;
+import jalview.bin.Jalview;
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;
import javax.swing.JPanel;
-public class JvOptionPane extends JOptionPane
- implements DialogRunnerI, PropertyChangeListener
+public class JvOptionPane extends JOptionPane implements DialogRunnerI,
+ PropertyChangeListener
{
- // BH 2018 no changes needed here.
-
private static final long serialVersionUID = -3019167117756785229L;
private static Object mockResponse = JvOptionPane.CANCEL_OPTION;
private Component parentComponent;
- public JvOptionPane(final Component parentComponent)
+ private Map<Object, Runnable> callbacks = new HashMap<>();
+
+ /*
+ * JalviewJS reports user choice in the dialog as the selected
+ * option (text); this list allows conversion to index (int)
+ */
+ List<Object> ourOptions;
+
+ public JvOptionPane(final Component parent)
{
-
- this.parentComponent = parentComponent;
+ this.parentComponent = Jalview.isJS() ? this : parent;
}
public static int showConfirmDialog(Component parentComponent,
return interactiveMode;
}
- public static void setInteractiveMode(boolean interactiveMode)
+ public static void setInteractiveMode(boolean interactive)
{
- JvOptionPane.interactiveMode = interactiveMode;
+ JvOptionPane.interactiveMode = interactive;
}
- @SuppressWarnings("unused")
private static String getPrefix(int messageType)
{
- String prefix = ""; // JavaScript only
-
- if (/** @j2sNative true || */
- false)
+ String prefix = "";
+
+ // JavaScript only
+ if (Jalview.isJS())
{
switch (messageType)
{
return prefix;
}
- DialogRunner<JvOptionPane> runner = new DialogRunner(this);
-
- private List<Object> ourOptions;
/**
* create a new option dialog that can be used to register responses - along
* lines of showOptionDialog
if (!isInteractiveMode())
{
- runner.firstRun((int) getMockResponse());
+ handleResponse(getMockResponse());
}
// two uses:
//
//
// 2) UserDefinedColors warning about saving over a name already defined
//
- Component parent;
- /**
- * @j2sNative
- * parent = this;
- */
- {
- parent = parentComponent;
- }
- ;
+
ourOptions = Arrays.asList(options);
- int response = JOptionPane.showOptionDialog(parent, message, title,
+
+ int response = JOptionPane.showOptionDialog(parentComponent, message, title,
optionType, messageType, icon, options, initialValue);
- /**
- * @j2sNative
+
+ /*
+ * In Java, the response is returned to this thread and handled here;
+ * (for Javascript, see propertyChange)
*/
+ if (!Jalview.isJS())
{
- runner.firstRun(response);
+ handleResponse(response);
}
-
}
public void showInternalDialog(JPanel mainPanel, String title,
{
if (!isInteractiveMode())
{
- runner.firstRun((int) getMockResponse());
+ handleResponse(getMockResponse());
}
- Component parent;
- /**
- * @j2sNative parent = this;
- */
- {
- parent = parentComponent;
- }
- ourOptions = Arrays.asList(options);
+ ourOptions = Arrays.asList(options);
int response;
- if (parent!=this) {
-
- response = JOptionPane.showInternalOptionDialog(parent, mainPanel,
+ if (parentComponent != this)
+ {
+ response = JOptionPane.showInternalOptionDialog(parentComponent, mainPanel,
title, yesNoCancelOption, questionMessage, icon, options,
initresponse);
}
else
{
- response = JOptionPane.showOptionDialog(parent, mainPanel, title,
+ response = JOptionPane.showOptionDialog(parentComponent, mainPanel, title,
yesNoCancelOption, questionMessage, icon, options,
initresponse);
}
- /**
- * @j2sNative
- */
+ if (!Jalview.isJS())
{
- runner.firstRun(response);
+ handleResponse(response);
}
-
}
+
@Override
- public JvOptionPane addResponse(RunResponse action)
+ public JvOptionPane setResponseHandler(Object response, Runnable action)
{
-
- runner.addResponse(action);
- return this;
- }
-
- public JvOptionPane defaultResponse(Runnable runnable)
- {
- runner.setDefaultResponse(runnable);
+ callbacks.put(response, action);
return this;
}
+ /**
+ * JalviewJS signals option selection by a property change event
+ * for the option e.g. "OK". This methods responds to that by
+ * running the response action that corresponds to that option.
+ *
+ * @param evt
+ */
@Override
public void propertyChange(PropertyChangeEvent evt)
{
- int ourOption = ourOptions.indexOf(evt.getNewValue());
- if (ourOption == -1)
+ Object newValue = evt.getNewValue();
+ int ourOption = ourOptions.indexOf(newValue);
+ if (ourOption >= 0)
{
- // try our luck..
- runner.run(evt.getNewValue());
+ handleResponse(ourOption);
}
else
{
- runner.run(ourOption);
+ // try our luck..
+ 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(RunResponse action)
+ public void setResponseAction(Object response, Runnable action)
{
- dialog.addResponse(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;
Object[] options = new Object[] { MessageManager.getString("action.ok"),
MessageManager.getString("action.cancel") };
String title = MessageManager
- .getString("label.adjunst_foreground_text_colour_threshold");
- RunResponse action = new RunResponse(JvOptionPane.NO_OPTION) // Cancel
+ .getString("label.adjust_foreground_text_colour_threshold");
+ Runnable action = new Runnable() // response for 1 = Cancel
{
@Override
public void run()
restoreInitialSettings();
}
};
- JvOptionPane.newOptionDialog(alignPanel).addResponse(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(new RunResponse(JalviewFileChooser.APPROVE_OPTION) {
- @Override
- public void run() {
- File choice = chooser.getSelectedFile();
- Cache.setProperty(LAST_DIRECTORY, choice.getParent());
-
- UserColourScheme ucs = ColourSchemeLoader
- .loadColourScheme(choice.getAbsolutePath());
- Color[] colors = ucs.getColours();
- schemeName.setText(ucs.getSchemeName());
-
- if (ucs.getLowerCaseColours() != null)
- {
- caseSensitive.setSelected(true);
- lcaseColour.setEnabled(true);
- resetButtonPanel(true);
- for (int i = 0; i < lowerCaseButtons.size(); i++)
- {
- JButton button = lowerCaseButtons.get(i);
- button.setBackground(ucs.getLowerCaseColours()[i]);
- }
- }
- else
- {
- caseSensitive.setSelected(false);
- lcaseColour.setEnabled(false);
- resetButtonPanel(false);
- }
-
- for (int i = 0; i < upperCaseButtons.size(); i++)
- {
- JButton button = upperCaseButtons.get(i);
- button.setBackground(colors[i]);
- }
-
- addNewColourScheme(choice.getPath());
- }});
+ chooser.setResponseHandler(0, new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ File choice = chooser.getSelectedFile();
+ Cache.setProperty(LAST_DIRECTORY, choice.getParent());
+
+ UserColourScheme ucs = ColourSchemeLoader
+ .loadColourScheme(choice.getAbsolutePath());
+ Color[] colors = ucs.getColours();
+ schemeName.setText(ucs.getSchemeName());
+
+ if (ucs.getLowerCaseColours() != null)
+ {
+ caseSensitive.setSelected(true);
+ lcaseColour.setEnabled(true);
+ resetButtonPanel(true);
+ for (int i = 0; i < lowerCaseButtons.size(); i++)
+ {
+ JButton button = lowerCaseButtons.get(i);
+ button.setBackground(ucs.getLowerCaseColours()[i]);
+ }
+ }
+ else
+ {
+ caseSensitive.setSelected(false);
+ lcaseColour.setEnabled(false);
+ resetButtonPanel(false);
+ }
+
+ for (int i = 0; i < upperCaseButtons.size(); i++)
+ {
+ JButton button = upperCaseButtons.get(i);
+ button.setBackground(colors[i]);
+ }
+
+ addNewColourScheme(choice.getPath());
+ }
+ });
chooser.showOpenDialog(this);
}
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(new RunResponse(JOptionPane.NO_OPTION)
+ svgOption.setResponseAction(1, new Runnable()
{
@Override
public void run()
getDescription()));
}
});
- svgOption.setResponseAction(okAction);
+ svgOption.setResponseAction(0, okAction);
svgOption.showDialog();
/* no code here - JalviewJS cannot execute it */
}
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.Response;
-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;
* @author AMW
*
*/
-public class JalviewFileChooser extends JFileChooser
- implements PropertyChangeListener, DialogRunnerI<JalviewFileChooser>
+public class JalviewFileChooser extends JFileChooser implements DialogRunnerI,
+ PropertyChangeListener
{
- DialogRunner<JalviewFileChooser> runner = new DialogRunner<>(this);
+ private static final long serialVersionUID = 1L;
+
+ private Map<Object, Runnable> callbacks;
+ File selectedFile = null;
+
/**
* Factory method to return a file chooser that offers readable alignment file
* formats
}
JalviewFileChooser(String dir, String[] extensions, String[] descs,
- String selected, boolean allFiles)
+ String selected, boolean acceptAny)
{
super(safePath(dir));
if (extensions.length == descs.length)
{
formats.add(new String[] { extensions[i], descs[i] });
}
- init(formats, selected, allFiles);
+ init(formats, selected, acceptAny);
}
else
{
}
}
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- // TODO other properties need runners...
- switch (evt.getPropertyName())
- {
- case "SelectedFile":
- runner.run(APPROVE_OPTION);
- break;
- }
- }
-
private static File safePath(String dir)
{
if (dir == null)
@Override
public int showOpenDialog(Component parent)
{
- runner.resetResponses();
int value = super.showOpenDialog(this);
- /**
- * @j2sNative
+
+ /*
+ * code below here is not reached in JalviewJS, instead
+ * propertyChange() is called for dialog action
*/
- {
- runner.firstRun(value);
- }
+ handleResponse(value);
return value;
}
* @param formats
* a list of {extensions, description} for each file format
* @param selected
- * @param allFiles
+ * @param acceptAny
* if true, 'any format' option is included
*/
- void init(List<String[]> formats, String selected, boolean allFiles)
+ void init(List<String[]> formats, String selected, boolean acceptAny)
{
JalviewFileFilter chosen = null;
// SelectAllFilter needs to be set first before adding further
// file filters to fix bug on Mac OSX
- setAcceptAllFileFilterUsed(allFiles);
+ setAcceptAllFileFilterUsed(acceptAny);
for (String[] format : formats)
{
}
return null;
}
-
- File ourselectedFile = null;
@Override
public File getSelectedFile()
{
- File selfile = super.getSelectedFile();
- if (selfile == null && ourselectedFile != null)
- {
- return ourselectedFile;
- }
- return selfile;
+ File f = super.getSelectedFile();
+ return f == null ? selectedFile : f;
}
@Override
return;
}
- ourselectedFile = getSelectedFile();
+ selectedFile = getSelectedFile();
- if (ourselectedFile == null)
+ if (selectedFile == null)
{
// Workaround for Java 9,10 on OSX - no selected file, but there is a
// filename typed in
String filename = ((BasicFileChooserUI) getUI()).getFileName();
if (filename != null && filename.length() > 0)
{
- ourselectedFile = new File(getCurrentDirectory(), filename);
+ selectedFile = new File(getCurrentDirectory(), filename);
}
} catch (Throwable x)
{
// THE
// USER PROMPTED FOR A NEW FILENAME
}
- if (ourselectedFile == null)
+
+ if (selectedFile == null)
{
return;
}
{
JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();
- if (!jvf.accept(ourselectedFile))
+ if (!jvf.accept(selectedFile))
{
String withExtension = getSelectedFile().getName() + "."
+ jvf.getAcceptableExtension();
- ourselectedFile = (new File(getCurrentDirectory(), withExtension));
- setSelectedFile(ourselectedFile);
+ selectedFile = (new File(getCurrentDirectory(), withExtension));
+ setSelectedFile(selectedFile);
}
}
- if (ourselectedFile.exists())
+ if (selectedFile.exists())
{
int confirm = JvOptionPane.showConfirmDialog(this,
MessageManager.getString("label.overwrite_existing_file"),
MessageManager.getString("label.file_already_exists"),
JvOptionPane.YES_NO_OPTION);
-
if (confirm != JvOptionPane.YES_OPTION)
{
return;
class RecentlyOpened extends JPanel
{
+ private static final long serialVersionUID = 1L;
JList<String> list;
- public RecentlyOpened()
+ RecentlyOpened()
{
-
setPreferredSize(new Dimension(300,100));
- String historyItems = jalview.bin.Cache.getProperty("RECENT_FILE");
+ String historyItems = Cache.getProperty("RECENT_FILE");
StringTokenizer st;
Vector<String> recent = new Vector<>();
}
@Override
- public JalviewFileChooser addResponse(RunResponse action)
+ public DialogRunnerI setResponseHandler(Object response, Runnable action)
{
- return runner.addResponse(action);
+ callbacks.put(response, action);
+ return this;
}
+ @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();
+ }
+ }
+
+ /**
+ * JalviewJS signals file selection by a property change event
+ * for property "SelectedFile". This methods responds to that by
+ * running the response action for 'OK' in the dialog.
+ *
+ * @param evt
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ // TODO other properties need runners...
+ switch (evt.getPropertyName())
+ {
+ /*
+ * property name here matches that used in JFileChooser.js
+ */
+ case "SelectedFile":
+ 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.List;
-import java.util.Map;
-
-/**
- * daft gymnastics to allow Dialogs to extend from a Swing class and use this
- * class to implement chained Response run() definition and execution.
- *
- * There is probably a better way of doing this.
- *
- * @author jprocter
- *
- * @param <T>
- * the actual dialog that will be shown - which will also initiate the
- * response chain.
- */
-public class DialogRunner<T extends DialogRunnerI> implements DialogRunnerI
-{
-
- private Map<Response, List<RunResponse>> callbacks = new java.util.HashMap<>();
-
- public T dialog;
-
- public DialogRunner(T ourDialog)
- {
- dialog = ourDialog;
- }
-
- /**
- * clear all 'was ran' flags so responses can be called again, and firstRun will
- * trigger response execution
- */
- public void resetResponses()
- {
- for (List<RunResponse> lr : callbacks.values())
- {
- for (RunResponse response : lr)
- {
- response.reset();
- }
- }
- responses.clear();
- if (defaultResponse != null)
- {
- defaultResponse.reset();
- }
- firstRunWasCalled = false;
- }
-
- @Override
- public T addResponse(RunResponse action)
- {
- return addResponse(false, action);
- }
-
- /**
- * insert a response at the beginning of the chain for the action. Useful to add
- * pre-action validations local to the Dialog class
- *
- * @param action
- * @return
- */
- public T firstResponse(RunResponse action)
- {
- return addResponse(true, action);
- }
-
- protected T addResponse(boolean prePend, RunResponse action)
- {
- List<RunResponse> laction = callbacks.get(action.ourTrigger);
- if (laction == null)
- {
- laction = new ArrayList<>();
- callbacks.put(action.ourTrigger, laction);
- }
- if (prePend)
- {
- laction.add(0,action);
- } else {
- laction.add(action);
- }
- return dialog;
- }
-
- /**
- *
- * @param action
- * @return true if action is a registered callback
- */
- public boolean isRegistered(RunResponse action)
- {
- List<RunResponse> resp = callbacks.get(action.ourTrigger);
- if (resp != null)
- {
- for (RunResponse r : resp)
- {
- if (r == action)
- {
- return true;
- }
- }
- }
- return false;
- }
- /**
- * handle a response
- *
- * @param responseCode
- */
- public void run(int responseCode)
- {
- run(new Response(responseCode));
- }
-
- public void run(String responseString)
- {
- run(new Response(responseString));
- }
-
- public void run(Object responseObj)
- {
- run(new Response(responseObj));
- }
-
- /**
- * start of response handling.
- *
- * @param responseCode
- */
- public void firstRun(int responseCode)
- {
- doFirstRun(new Response(responseCode));
- }
-
- public void firstRun(String responseString)
- {
- doFirstRun(new Response(responseString));
- }
-
- public void firstRun(Object responseObj)
- {
- if (responseObj != null && !responseObj.equals(responseObj))
- {
- // NaN is an object in Chrome - catch this weirdness
- // this so we don't cause issues later
- return;
- }
- doFirstRun(new Response(responseObj));
- }
-
-
- boolean firstRunWasCalled = false;
-
- private void doFirstRun(Response response)
- {
- if (firstRunWasCalled)
- {
- return;
- }
- firstRunWasCalled = true;
- run(response);
- }
-
- private void run(Response response)
- {
- if (response.objresp != null
- && !response.objresp.equals(response.objresp))
- {
- // NaN is an object in Chrome - catch this weirdness
- // this so we don't cause issues later
- return;
- }
- responses.add(response);
-
- List<RunResponse> laction = response.isNull() ? null : callbacks.get(response);
-
- if (laction == null)
- {
- if (defaultResponse != null)
- {
- defaultResponse.ourTrigger = response;
- defaultResponse.wasRun = true;
- defaultResponse.run();
- }
- else
- {
- System.err.println("Doing nothing for " + response);
- }
- return;
- }
- boolean wasRun = false;
- int num = 0;
- for (RunResponse action : laction)
- {
- num++;
- // find next action to execute
- if (!action.wasRun)
- {
- System.err
- .println("Executing action (" + num + ") for " + response);
- wasRun = true;
- action.wasRun = true;
- action.run();
- if (action.returned != null)
- {
- run(action.returned);
- }
- break;
- }
- }
- if (!wasRun)
- {
- System.err.println("Did nothing for " + response);
- }
- }
-
- List<Response> responses = new ArrayList<>();
-
- RunResponse defaultResponse = null;
-
- /**
- * Convenience wrapper for setting default response to a runnable
- *
- * @param runnable
- */
- public void setDefaultResponse(Runnable runnable)
- {
- defaultResponse = new RunResponse(runnable)
- {
- @Override
- public void run()
- {
- runnable.run();
- }
- };
- }
-
- /**
- * Default responses are called once, with ourTrigger set to the unHandled
- * response received
- *
- * @param runnable
- */
- public void setDefaultResponse(RunResponse runnable)
- {
- defaultResponse = runnable;
- }
-}
package jalview.util.dialogrunner;
/**
- * 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<T extends DialogRunnerI>
-{
+public interface DialogRunnerI {
- /**
- * Adds a new response for this dialog, and returns the dialog (this), to allow chaining, eg.
- * <pre>
- * dialog.addResponse(newRunResponse(OK_PRessed) { run()...})
- * .addResponse(new RunResponse(CANCEL_PRESSED);
- * </pre>
- *
- * @param action
- * @return the dialog
- */
- T addResponse(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 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;
-
-public class Response
-{
- int type = 0; // int = 0, String = 1, Object = 2;
-
- int intresp;
-
- String stringresp;
-
- Object objresp;
-
- public Response(int response)
- {
- type = 0;
- intresp = response;
- }
-
- public Response(String response)
- {
- type = 1;
- stringresp = response;
- }
-
- public Response(Object response)
- {
- if (response instanceof String)
- {
- type = 1;
- stringresp = (String) response;
- return;
- }
- if (response instanceof Integer)
- {
- type = 0;
- intresp = ((Integer) response).intValue();
- return;
- }
- objresp = response;
- type = 2;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == null || !(obj instanceof Response))
- {
- return false;
- }
- ;
- if (((Response) obj).type == type)
- {
- switch (type)
- {
- case 0:
- return ((((Response) obj).intresp) == intresp);
- case 1:
- return (((Response) obj).stringresp.equals(stringresp));
- case 2:
- return (((Response) obj).objresp).equals(objresp);
- }
- }
- return false;
- }
-
- @Override
- public int hashCode()
- {
- switch (type)
- {
- case 0:
- return Integer.valueOf(intresp).hashCode();
- case 1:
- return stringresp.hashCode();
- case 2:
- return objresp.hashCode();
- }
- return super.hashCode();
- }
-
- @Override
- public String toString()
- {
- switch (type)
- {
- case 0:
- return "DialogRunner int: " + intresp;
- case 1:
- return "DialogRunner str: '" + stringresp + "'";
- case 2:
- return "DialogRunner obj: " + String.valueOf(objresp);
- }
- return "Unconfigured response.";
- }
-
- /**
- * null response - triggers the default response
- * @return
- */
- public boolean isNull()
- {
- return (type==2 && objresp==null) || (type==1 && (stringresp==null || stringresp.equals("")));
- }
-}
\ No newline at end of file
+++ /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
- */
- public Response ourTrigger;
-
- /**
- * set by run() on exit
- */
- public Response returned = null;
-
- /**
- * set by dialog runner
- */
- public boolean wasRun = false;
-
- public RunResponse(int trigger)
- {
- ourTrigger = new Response(trigger);
- }
-
- public RunResponse(Object trigger)
- {
- ourTrigger = new Response(trigger);
- }
-
- public RunResponse(String trigger)
- {
- ourTrigger = new Response(trigger);
- }
-
- public void reset()
- {
- wasRun = false;
- returned = null;
-
- }
-
- @Override
- public String toString()
- {
- return "Runner for " + ourTrigger;
- }
-}
package jalview.util.dialogrunner;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
public class DialogRunnerTest
-{
- public class MockDialog implements DialogRunnerI<MockDialog>
- {
- DialogRunner<MockDialog> runner = new DialogRunner<>(this);
-
- @Override
- public MockDialog addResponse(RunResponse action)
- {
- return runner.addResponse(action);
- }
-
- public void doDialog(String resp)
- {
- runner.firstRun(resp);
- }
- }
-
- MockDialog dialog = new MockDialog();
-
- @Test
- public void testDialogRunner()
- {
- RunResponse ok, cancel, help, ineed;
- final Response ooh = new Response("OOOOoooOOOOH!"),
- r_ok = new Response("OK"), r_cancel = new Response("CANCEL"),
- r_done = new Response("DONE"), r_help = new Response("HELP"),
- r_ddoit = new Response("DIDNT DOIT"),
- r_needsb = new Response("I NEED SOMEBODY");
-
- ok = new RunResponse("OK")
- {
-
- @Override
- public void run()
- {
- returned = new Response("DONE");
- }
- };
- final RunResponse befok = new RunResponse("OK")
- {
-
- @Override
- public void run()
- {
- returned = new Response("OK");
- }
- };
-
- cancel = new RunResponse("CANCEL")
- {
- @Override
- public void run()
- {
- returned = r_ddoit;
- }
- };
- help = new RunResponse("HELP")
- {
- @Override
- public void run()
- {
- returned = r_needsb;
-
- }
- };
- ineed = new RunResponse(r_needsb)
- {
- @Override
- public void run()
- {
- returned = ooh;
- }
- };
-
- Assert.assertFalse(dialog.runner.isRegistered(ok));
-
- dialog.addResponse(ok).addResponse(cancel).addResponse(help).addResponse(ineed);
-
- Assert.assertTrue(dialog.runner.isRegistered(ok));
-
- Assert.assertFalse(dialog.runner.firstRunWasCalled);
- dialog.doDialog("OK");
- // OK called, nothing else.
- Assert.assertTrue(dialog.runner.firstRunWasCalled);
- Assert.assertTrue(ok.wasRun);
- Assert.assertEquals(ok.returned, r_done);
- Assert.assertFalse(cancel.wasRun);
- Assert.assertEquals(dialog.runner.responses.size(), 2);
-
- // do it again - check it doesn't trigger again
- ok.wasRun = false;
- dialog.doDialog("OK");
- Assert.assertFalse(ok.wasRun);
-
- // 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 ..
- dialog.doDialog("HELP");
- Assert.assertTrue(dialog.runner.firstRunWasCalled);
- Assert.assertFalse(ok.wasRun);
- Assert.assertEquals(ineed.returned, ooh);
- Assert.assertEquals(dialog.runner.responses.size(), 3);
-
- // TODO: test prepend and chained execution of tasks for a response.
- Assert.assertFalse(dialog.runner.isRegistered(befok));
- dialog.runner.firstResponse(befok);
-
- Assert.assertTrue(dialog.runner.isRegistered(befok));
- Assert.assertTrue(dialog.runner.isRegistered(ok));
-
- dialog.runner.resetResponses();
-
- dialog.doDialog("OK");
- Assert.assertTrue(befok.wasRun);
- Assert.assertTrue(ok.wasRun);
- Assert.assertEquals(dialog.runner.responses.size(), 3);
- }
-}
+{}
+++ /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 org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class ResponseTest
-{
- @Test
- public void testResonse() {
- Response intr=new Response(1),intrCopy=new Response(1);
- Response strr=new Response("1"),strrcopy=new Response("1");
- Response objr=new Response(Double.valueOf(1d));
- Assert.assertTrue(intr.equals(intrCopy));
- Assert.assertTrue(strr.equals(strrcopy));
- Assert.assertFalse(intr.equals(strr));
- Assert.assertFalse(intr.equals(objr));
- Assert.assertFalse(strr.equals(objr));
- Assert.assertEquals(intr.toString(), "DialogRunner int: 1");
- Assert.assertEquals(strr.toString(), "DialogRunner str: '1'");
- Assert.assertEquals(objr.toString(), "DialogRunner obj: 1.0");
- }
-}
+++ /dev/null
-package jalview.util.dialogrunner;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class RunResponseTest
-{
- @Test
- public void testRunResponse()
- {
-
- RunResponse rr = new RunResponse("OK")
- {
- @Override
- public void run()
- {
- returned = new Response("DONE");
- }
- };
- Assert.assertEquals(rr.ourTrigger, new Response("OK"));
- Assert.assertNotEquals(rr.ourTrigger, new Response("NOTOK"));
- Assert.assertNull(rr.returned);
- Assert.assertFalse(rr.wasRun);
- // trivial ..
- rr.wasRun = true;
- rr.run();
- Assert.assertTrue(rr.wasRun);
-
- Assert.assertEquals(rr.returned, new Response("DONE"));
- rr.reset();
- Assert.assertNull(rr.returned);
- Assert.assertFalse(rr.wasRun);
-
- Assert.assertEquals(rr.toString(), "Runner for " + new Response("OK"));
-
- // just test the other constructors
- RunResponse rr12 = new RunResponse(12)
- {
- @Override
- public void run()
- {
- returned = new Response("DONE");
- }
- };
- RunResponse rrpi = new RunResponse(new Double(3.142))
- {
- @Override
- public void run()
- {
- returned = new Response("DONE");
- }
- };
- Assert.assertEquals(rr12.ourTrigger, new Response(12));
- Assert.assertEquals(rrpi.ourTrigger,
- new Response(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");