//////////////////////////////////////////////////////////////////
package jalview.io;
+import jalview.bin.Cache;
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
import jalview.util.Platform;
* @param selected
* @return
*/
- public static JalviewFileChooser forRead(String directory, String selected)
+ public static JalviewFileChooser forRead(String directory,
+ String selected)
{
List<String> extensions = new ArrayList<String>();
List<String> descs = new ArrayList<String>();
- for (FileFormatI format : FileFormat.values())
+ for (FileFormatI format : FileFormats.getInstance().getFormats())
{
if (format.isReadable())
{
extensions.add(format.getExtensions());
- descs.add(format.toString());
+ descs.add(format.getName());
}
}
return new JalviewFileChooser(directory,
// with a lambda expression parameter for isReadable/isWritable
List<String> extensions = new ArrayList<String>();
List<String> descs = new ArrayList<String>();
- for (FileFormatI format : FileFormat.values())
+ for (FileFormatI format : FileFormats.getInstance().getFormats())
{
if (format.isWritable())
{
extensions.add(format.getExtensions());
- descs.add(format.toString());
+ descs.add(format.getName());
}
}
return new JalviewFileChooser(directory,
/**
* Constructor for a single choice of file extension and description
*
- * @param dir
* @param extension
* @param desc
*/
- public JalviewFileChooser(String dir, String extension, String desc)
+ public JalviewFileChooser(String extension, String desc)
{
- // TODO inline dir as Cache.getProperty("LAST_DIRECTORY") ? if applet
- // builds ok
- this(dir, new String[] { extension }, new String[] { desc }, desc,
- true);
+ this(Cache.getProperty("LAST_DIRECTORY"), new String[] { extension },
+ new String[]
+ { desc }, desc, true);
}
JalviewFileChooser(String dir, String[] extensions, String[] descs,
format = format.substring(0, parenPos).trim();
try
{
- return FileFormat.valueOf(format);
+ return FileFormats.getInstance().forName(format);
} catch (IllegalArgumentException e)
{
System.err.println("Unexpected format: " + format);
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
{
setDialogType(SAVE_DIALOG);
+ this.setSelectedFile(null);
int ret = showDialog(parent, MessageManager.getString("action.save"));
+ ourselectedFile = getSelectedFile();
+ if (getSelectedFile() == null)
+ {
+ // Workaround for Java 9,10 on OSX - no selected file, but there is a
+ // filename typed in
+ try
+ {
+ String filename = ((BasicFileChooserUI) getUI()).getFileName();
+ if (filename != null && filename.length() > 0)
+ {
+ ourselectedFile = new File(getCurrentDirectory(), filename);
+ }
+ } catch (Throwable x)
+ {
+ System.err.println(
+ "Unexpected exception when trying to get filename.");
+ x.printStackTrace();
+ }
+ }
+ if (ourselectedFile == null)
+ {
+ return JalviewFileChooser.CANCEL_OPTION;
+ }
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"),
}
});
- this.setBorder(new javax.swing.border.TitledBorder(MessageManager
- .getString("label.recently_opened")));
+ this.setBorder(new javax.swing.border.TitledBorder(
+ MessageManager.getString("label.recently_opened")));
final JScrollPane scroller = new JScrollPane(list);
@Override
public void run()
{
- scroller.getHorizontalScrollBar().setValue(
- scroller.getHorizontalScrollBar().getMaximum());
+ scroller.getHorizontalScrollBar()
+ .setValue(scroller.getHorizontalScrollBar().getMaximum());
}
});