From 7b733539862769ff2438a3149d120aedd044b1be Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 29 Jun 2018 16:21:35 +0100 Subject: [PATCH] JAL-3048 refactored Desktop->File->Open to use jalview.utils.dialogrunner.DialogRunner --- src/jalview/gui/Desktop.java | 13 +++---------- src/jalview/io/JalviewFileChooser.java | 33 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 06c3b36..65e936c 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -44,6 +44,7 @@ import jalview.util.ImageMaker; 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; @@ -105,7 +106,6 @@ import javax.swing.JCheckBox; 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; @@ -1129,7 +1129,7 @@ public class Desktop extends jalview.jbgui.GDesktop MessageManager.getString("label.open_local_file")); chooser.setToolTipText(MessageManager.getString("action.open")); - chooser.setCallback(new Runnable() + chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION) { @Override @@ -1160,14 +1160,7 @@ public class Desktop extends jalview.jbgui.GDesktop new FileLoader().LoadFile(viewport, selectedFile, DataSourceType.FILE, format); } - }); - - int value = chooser.showOpenDialog(this); - if (value == JFileChooser.APPROVE_OPTION) - { - chooser.getCallback().run(); - } - + }).openDialog(this); } /** diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index ae6c9eb..65cb603 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -25,6 +25,8 @@ import jalview.bin.Cache; 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; @@ -58,8 +60,10 @@ import javax.swing.plaf.basic.BasicFileChooserUI; * */ public class JalviewFileChooser extends JFileChooser - implements PropertyChangeListener + implements PropertyChangeListener, DialogRunnerI { + jalview.util.dialogrunner.DialogRunner runner = new jalview.util.dialogrunner.DialogRunner<>( + this); /** * Factory method to return a file chooser that offers readable alignment file * formats @@ -159,25 +163,14 @@ public class JalviewFileChooser extends JFileChooser } } - 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; } } @@ -197,6 +190,12 @@ public class JalviewFileChooser extends JFileChooser return f; } + public void openDialog(Component parent) + { + int value = showOpenDialog(this); + runner.run(value); + } + /** * * @param formats @@ -436,4 +435,10 @@ public class JalviewFileChooser extends JFileChooser } + @Override + public JalviewFileChooser response(RunResponse action) + { + return runner.response(action); + } + } -- 1.7.10.2