From 23a413a98ae476ff445ebde22c74aa66e57a9378 Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 1 Dec 2015 13:58:57 -0500 Subject: [PATCH] use AWT's FileDialog so we get real native OS file dialogs i need to test this more on Windows/Linux to ensure it works fine there too, but i think it should be fine. getting native OS file dialogs is _probably_ most important on OS X as the Swing JFileChooser version lacks the favourites column which a lot of users will end up feeling somewhat lost without. --- src/main/java/org/fenix/llanfair/Actions.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/fenix/llanfair/Actions.java b/src/main/java/org/fenix/llanfair/Actions.java index a0ec05e..58e3733 100644 --- a/src/main/java/org/fenix/llanfair/Actions.java +++ b/src/main/java/org/fenix/llanfair/Actions.java @@ -39,7 +39,7 @@ final class Actions { private Llanfair master; private File file; - private JFileChooser fileChooser; + private FileDialog fileChooser; private volatile long lastUnsplit; private volatile long lastSkip; @@ -55,7 +55,8 @@ final class Actions { master = owner; file = null; - fileChooser = new JFileChooser( UserSettings.getSplitsPath() ); + fileChooser = new FileDialog(master); + fileChooser.setDirectory(UserSettings.getSplitsPath()); lastUnsplit = 0L; lastSkip = 0L; @@ -227,17 +228,17 @@ final class Actions { * @return a file selected by the user or {@code null} if he canceled */ private File selectFile(FILE_CHOOSER_TYPE dialogType) { - int option = -1; if (dialogType == FILE_CHOOSER_TYPE.OPEN) - option = fileChooser.showOpenDialog(master); + fileChooser.setMode(FileDialog.LOAD); else if (dialogType == FILE_CHOOSER_TYPE.SAVE) - option = fileChooser.showSaveDialog(master); + fileChooser.setMode(FileDialog.SAVE); - if ( option == JFileChooser.APPROVE_OPTION ) { - return fileChooser.getSelectedFile(); - } else { + fileChooser.setVisible(true); + String selectedFile = fileChooser.getFile(); + if (selectedFile != null) + return new File(fileChooser.getDirectory() + File.separator + selectedFile); + else return null; - } } /**