|
1 | | -/** |
| 1 | +/* |
2 | 2 | * Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
17 | 17 |
|
18 | 18 | import java.io.File; |
19 | 19 | import java.util.logging.Logger; |
| 20 | + |
20 | 21 | import javax.swing.JFileChooser; |
21 | 22 | import javax.swing.JFrame; |
22 | 23 | import javax.swing.JTextField; |
23 | | -import org.eclipse.xtend2.lib.StringConcatenation; |
24 | 24 |
|
25 | | -@SuppressWarnings("all") |
26 | 25 | public class DirectoryChooser { |
27 | | - private static final Logger logger = Logger.getLogger(DirectoryChooser.class.getName()); |
28 | | - |
29 | | - public static String choose(final JFrame parentFrame, final String title, final String initialDirectory) { |
30 | | - StringConcatenation _builder = new StringConcatenation(); |
31 | | - _builder.append("parantFrame: "); |
32 | | - _builder.append(parentFrame); |
33 | | - DirectoryChooser.logger.finest(_builder.toString()); |
34 | | - String ret = null; |
35 | | - final JFileChooser chooser = new JFileChooser(); |
36 | | - File _file = new File(initialDirectory); |
37 | | - chooser.setCurrentDirectory(_file); |
38 | | - chooser.setDialogTitle(title); |
39 | | - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
40 | | - chooser.setAcceptAllFileFilterUsed(false); |
41 | | - int _showOpenDialog = chooser.showOpenDialog(parentFrame); |
42 | | - boolean _equals = (_showOpenDialog == JFileChooser.APPROVE_OPTION); |
43 | | - if (_equals) { |
44 | | - ret = chooser.getSelectedFile().getAbsolutePath(); |
| 26 | + private static final Logger logger = Logger.getLogger(DirectoryChooser.class.getName()); |
| 27 | + |
| 28 | + // do not instantiate this class |
| 29 | + private DirectoryChooser() { |
| 30 | + super(); |
45 | 31 | } |
46 | | - return ret; |
47 | | - } |
48 | | - |
49 | | - public static void choose(final JFrame parentFrame, final String title, final JTextField textField) { |
50 | | - final String dir = DirectoryChooser.choose(parentFrame, title, textField.getText()); |
51 | | - if ((dir != null)) { |
52 | | - textField.setText(dir); |
| 32 | + |
| 33 | + public static String choose(final JFrame parentFrame, final String title, final String initialDirectory) { |
| 34 | + logger.finest(() -> "parantFrame: " + parentFrame); |
| 35 | + String ret = null; |
| 36 | + final JFileChooser chooser = new JFileChooser(); |
| 37 | + chooser.setCurrentDirectory(new File(initialDirectory)); |
| 38 | + chooser.setDialogTitle(title); |
| 39 | + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
| 40 | + chooser.setAcceptAllFileFilterUsed(false); |
| 41 | + if (chooser.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION) { |
| 42 | + ret = chooser.getSelectedFile().getAbsolutePath(); |
| 43 | + } |
| 44 | + return ret; |
| 45 | + } |
| 46 | + |
| 47 | + public static void choose(final JFrame parentFrame, final String title, final JTextField textField) { |
| 48 | + final String dir = choose(parentFrame, title, textField.getText()); |
| 49 | + if (dir != null) { |
| 50 | + textField.setText(dir); |
| 51 | + } |
53 | 52 | } |
54 | | - } |
55 | 53 | } |
0 commit comments