* make sure to apply dialog titles for all providers

This commit is contained in:
Reinhard Pointner 2014-08-08 16:44:35 +00:00
parent a616577ab9
commit a35aa77bb8
1 changed files with 14 additions and 1 deletions

View File

@ -72,9 +72,11 @@ public class UserFiles {
public enum FileChooser { public enum FileChooser {
Swing { Swing {
@Override @Override
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) { public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
JFileChooser chooser = new JFileChooser(); JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(title);
chooser.setMultiSelectionEnabled(multiSelection); chooser.setMultiSelectionEnabled(multiSelection);
chooser.setFileSelectionMode(folderMode && filter == null ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileSelectionMode(folderMode && filter == null ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
chooser.setSelectedFile(defaultFile); chooser.setSelectedFile(defaultFile);
@ -94,6 +96,7 @@ public class UserFiles {
@Override @Override
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) { public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
JFileChooser chooser = new JFileChooser(); JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(title);
chooser.setMultiSelectionEnabled(false); chooser.setMultiSelectionEnabled(false);
chooser.setFileSelectionMode(folderMode ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileSelectionMode(folderMode ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
chooser.setSelectedFile(defaultFile); chooser.setSelectedFile(defaultFile);
@ -106,15 +109,24 @@ public class UserFiles {
}, },
AWT { AWT {
@Override @Override
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) { public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
FileDialog fileDialog = createFileDialog(parent, title, FileDialog.LOAD, folderMode); FileDialog fileDialog = createFileDialog(parent, title, FileDialog.LOAD, folderMode);
fileDialog.setTitle(title);
fileDialog.setMultipleMode(multiSelection); fileDialog.setMultipleMode(multiSelection);
if (filter != null) { if (filter != null) {
fileDialog.setFilenameFilter(filter); fileDialog.setFilenameFilter(filter);
} }
if (defaultFile != null) { if (defaultFile != null) {
fileDialog.setFile(defaultFile.getPath()); if (folderMode && defaultFile.isDirectory()) {
fileDialog.setDirectory(defaultFile.getPath());
} else {
if (defaultFile.getParentFile() != null) {
fileDialog.setDirectory(defaultFile.getParentFile().getPath());
}
fileDialog.setFile(defaultFile.getName());
}
} }
fileDialog.setVisible(true); fileDialog.setVisible(true);
@ -124,6 +136,7 @@ public class UserFiles {
@Override @Override
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) { public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
FileDialog fileDialog = createFileDialog(getWindow(parent), title, FileDialog.SAVE, folderMode); FileDialog fileDialog = createFileDialog(getWindow(parent), title, FileDialog.SAVE, folderMode);
fileDialog.setTitle(title);
fileDialog.setMultipleMode(false); fileDialog.setMultipleMode(false);
if (defaultFile != null) { if (defaultFile != null) {
if (defaultFile.getParentFile() != null) { if (defaultFile.getParentFile() != null) {