From 109e015cd41fbdffb065131acd0d767dfefb2ef6 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 7 Sep 2018 14:23:16 +0100 Subject: [PATCH] JAL-2988 workaround: overload getSelectedFile() because calling setSelectedFile(..) results in getSelectedFile()==null on OSX/Java 10/VAqua4/5. --- src/jalview/io/JalviewFileChooser.java | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index cb42662..2ba7bbf 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -278,6 +278,19 @@ public class JalviewFileChooser extends JFileChooser return null; } + File ourselectedFile = null; + + @Override + public File getSelectedFile() + { + File selfile = super.getSelectedFile(); + if (selfile == null && ourselectedFile != null) + { + return ourselectedFile; + } + return selfile; + } + @Override public int showSaveDialog(Component parent) throws HeadlessException { @@ -287,22 +300,24 @@ public class JalviewFileChooser extends JFileChooser this.setSelectedFile(null); int ret = showDialog(parent, MessageManager.getString("action.save")); + ourselectedFile = getSelectedFile(); if (getFileFilter() instanceof JalviewFileFilter) { JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter(); - if (!jvf.accept(getSelectedFile())) + if (!jvf.accept(ourselectedFile)) { - String withExtension = getSelectedFile() + "." + String withExtension = getSelectedFile().getName() + "." + jvf.getAcceptableExtension(); - setSelectedFile(new File(withExtension)); + ourselectedFile = (new File(getCurrentDirectory(), withExtension)); + setSelectedFile(ourselectedFile); } } // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE // USER PROMPTED FOR A NEW FILENAME if ((ret == JalviewFileChooser.APPROVE_OPTION) - && getSelectedFile().exists()) + && ourselectedFile.exists()) { int confirm = JvOptionPane.showConfirmDialog(parent, MessageManager.getString("label.overwrite_existing_file"), -- 1.7.10.2