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 javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
-import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
MessageManager.getString("label.open_local_file"));
chooser.setToolTipText(MessageManager.getString("action.open"));
- chooser.setCallback(new Runnable()
+ chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
{
@Override
new FileLoader().LoadFile(viewport, selectedFile,
DataSourceType.FILE, format);
}
- });
-
- int value = chooser.showOpenDialog(this);
- if (value == JFileChooser.APPROVE_OPTION)
- {
- chooser.getCallback().run();
- }
-
+ }).openDialog(this);
}
/**
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.dialogrunner.DialogRunnerI;
+import jalview.util.dialogrunner.RunResponse;
import java.awt.Component;
import java.awt.Dimension;
*
*/
public class JalviewFileChooser extends JFileChooser
- implements PropertyChangeListener
+ implements PropertyChangeListener, DialogRunnerI
{
+ jalview.util.dialogrunner.DialogRunner<JalviewFileChooser> runner = new jalview.util.dialogrunner.DialogRunner<>(
+ this);
/**
* Factory method to return a file chooser that offers readable alignment file
* formats
}
}
- private Runnable theCallback;
-
- public void setCallback(Runnable callback)
- {
- this.theCallback = callback;
- }
-
- public Runnable getCallback()
- {
- return theCallback;
- }
-
@Override
public void propertyChange(PropertyChangeEvent evt)
{
+ // TODO other properties need runners...
switch (evt.getPropertyName())
{
case "SelectedFile":
- theCallback.run();
+ runner.run(APPROVE_OPTION);
break;
}
}
return f;
}
+ public void openDialog(Component parent)
+ {
+ int value = showOpenDialog(this);
+ runner.run(value);
+ }
+
/**
*
* @param formats
}
+ @Override
+ public JalviewFileChooser response(RunResponse action)
+ {
+ return runner.response(action);
+ }
+
}