Changeset 5438 in josm
- Timestamp:
- 2012-08-13T00:12:48+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java
r4608 r5438 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.io.File; 4 import java.util.Collection; 7 5 8 6 import javax.swing.JFileChooser; 7 import javax.swing.filechooser.FileFilter; 9 8 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.gui.ExtendedDialog; 9 import org.openstreetmap.josm.gui.widgets.JFileChooserManager; 12 10 import org.openstreetmap.josm.tools.Shortcut; 13 11 14 12 /** 15 * Helper class for all actions that access the disk 13 * Helper class for all actions that access the disk. 14 * @since 78 16 15 */ 17 16 abstract public class DiskAccessAction extends JosmAction { 18 17 18 /** 19 * Constructs a new {@code DiskAccessAction}. 20 * 21 * @param name The action's text as displayed on the menu (if it is added to a menu) 22 * @param iconName The filename of the icon to use 23 * @param tooltip A longer description of the action that will be displayed in the tooltip 24 * @param shortcut A ready-created shortcut object or {@code null} if you don't want a shortcut 25 * @since 1084 26 */ 19 27 public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut) { 20 28 super(name, iconName, tooltip, shortcut, true); 21 29 } 22 30 31 /** 32 * Constructs a new {@code DiskAccessAction}. 33 * 34 * @param name The action's text as displayed on the menu (if it is added to a menu) 35 * @param iconName The filename of the icon to use 36 * @param tooltip A longer description of the action that will be displayed in the tooltip 37 * @param shortcut A ready-created shortcut object or null if you don't want a shortcut 38 * @param register Register this action for the toolbar preferences? 39 * @param toolbarId Identifier for the toolbar preferences. The iconName is used, if this parameter is null 40 * @param installAdapters False, if you don't want to install layer changed and selection changed adapters 41 * @since 5438 42 */ 43 public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register, String toolbarId, boolean installAdapters) { 44 super(name, iconName, tooltip, shortcut, register, toolbarId, installAdapters); 45 } 46 47 /** 48 * Creates a new {@link JFileChooser} and makes it visible. 49 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog 50 * @param multiple If true, makes the dialog allow multiple file selections 51 * @param title The string that goes in the dialog window's title bar 52 * @return The {@code JFileChooser}. 53 * @since 1646 54 */ 23 55 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) { 24 56 return createAndOpenFileChooser(open, multiple, title, null); 25 57 } 26 58 59 /** 60 * Creates a new {@link JFileChooser} and makes it visible. 61 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog 62 * @param multiple If true, makes the dialog allow multiple file selections 63 * @param title The string that goes in the dialog window's title bar 64 * @param extension The file extension that will be selected as the default file filter 65 * @return The {@code JFileChooser}. 66 * @since 2020 67 */ 27 68 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) { 28 String curDir = Main.pref.get("lastDirectory"); 29 if (curDir.equals("")) { 30 curDir = "."; 31 } 32 JFileChooser fc = new JFileChooser(new File(curDir)); 33 if (title != null) { 34 fc.setDialogTitle(title); 35 } 69 return createAndOpenFileChooser(open, multiple, title, extension, JFileChooser.FILES_ONLY, true, null); 70 } 36 71 37 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 38 fc.setMultiSelectionEnabled(multiple); 39 fc.setAcceptAllFileFilterUsed(false); 40 ExtensionFileFilter.applyChoosableImportFileFilters(fc, extension); 72 /** 73 * Creates a new {@link JFileChooser} and makes it visible. 74 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog 75 * @param multiple If true, makes the dialog allow multiple file selections 76 * @param title The string that goes in the dialog window's title bar 77 * @param extension The file extension that will be selected as the default file filter 78 * @param selectionMode The selection mode that allows the user to:<br/> 79 * <li>just select files ({@code JFileChooser.FILES_ONLY})</li> 80 * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li> 81 * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li> 82 * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox. 83 * If false, only the file filters that include {@code extension} will be proposed 84 * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory. 85 * This property will then be updated to the new "last directory" chosen by the user. If null, the default property "lastDirectory" will be used. 86 * @return The {@code JFileChooser}. 87 * @since 5438 88 */ 89 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension, int selectionMode, boolean allTypes, String lastDirProperty) { 90 return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, extension, allTypes, selectionMode).openFileChooser(); 91 } 41 92 42 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent); 43 if (answer != JFileChooser.APPROVE_OPTION) 44 return null; 93 /** 94 * Creates a new {@link JFileChooser} for a single {@link FileFilter} and makes it visible. 95 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog 96 * @param multiple If true, makes the dialog allow multiple file selections 97 * @param title The string that goes in the dialog window's title bar 98 * @param filter The only file filter that will be proposed by the dialog 99 * @param selectionMode The selection mode that allows the user to:<br/> 100 * <li>just select files ({@code JFileChooser.FILES_ONLY})</li> 101 * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li> 102 * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li> 103 * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user 104 * @return The {@code JFileChooser}. 105 * @since 5438 106 */ 107 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, FileFilter filter, int selectionMode, String lastDirProperty) { 108 return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filter, selectionMode).openFileChooser(); 109 } 45 110 46 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 47 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 48 } 49 50 if (!open) { 51 File file = fc.getSelectedFile(); 52 if (file != null && file.exists()) { 53 ExtendedDialog dialog = new ExtendedDialog( 54 Main.parent, 55 tr("Overwrite"), 56 new String[] {tr("Overwrite"), tr("Cancel")} 57 ); 58 dialog.setContent(tr("File exists. Overwrite?")); 59 dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"}); 60 dialog.showDialog(); 61 if (dialog.getValue() != 1) 62 return null; 63 } 64 } 65 66 return fc; 111 /** 112 * Creates a new {@link JFileChooser} for several {@link FileFilter}s and makes it visible. 113 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog 114 * @param multiple If true, makes the dialog allow multiple file selections 115 * @param title The string that goes in the dialog window's title bar 116 * @param filters The file filters that will be proposed by the dialog 117 * @param defaultFilter The file filter that will be selected by default 118 * @param selectionMode The selection mode that allows the user to:<br/> 119 * <li>just select files ({@code JFileChooser.FILES_ONLY})</li> 120 * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li> 121 * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li> 122 * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user 123 * @return The {@code JFileChooser}. 124 * @since 5438 125 */ 126 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, 127 Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode, String lastDirProperty) { 128 return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode).openFileChooser(); 67 129 } 68 130 } -
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r5266 r5438 19 19 * A file filter that filters after the extension. Also includes a list of file 20 20 * filters used in JOSM. 21 * 21 * @since 32 22 22 */ 23 23 public class ExtensionFileFilter extends FileFilter { 24 24 25 25 /** 26 * list of supported formats 26 * List of supported formats for import. 27 * @since 4869 27 28 */ 28 29 public static final ArrayList<FileImporter> importers; 29 30 31 /** 32 * List of supported formats for export. 33 * @since 4869 34 */ 30 35 public static final ArrayList<FileExporter> exporters; 31 36 … … 95 100 * Updates the {@link AllFormatsImporter} that is contained in the importers list. If 96 101 * you do not use the importers variable directly, you don’t need to call this. 102 * <p> 103 * Updating the AllFormatsImporter is required when plugins add new importers that 104 * support new file extensions. The old AllFormatsImporter doesn’t include the new 105 * extensions and thus will not display these files. 97 106 * 98 * Updating the AllFormatsImporter is required when plugins add new importers that 99 * support new file extensions. The old AllFormatsImporter doesn’t include the new 100 * extensions and thus will not display these files. 107 * @since 5131 101 108 */ 102 109 public static void updateAllFormatsImporter() { … … 114 121 * 115 122 * @return an ordered list of {@link ExtensionFileFilter}s for importing. 123 * @since 2029 116 124 */ 117 125 public static List<ExtensionFileFilter> getImportExtensionFileFilters() { … … 131 139 * 132 140 * @return an ordered list of {@link ExtensionFileFilter}s for exporting. 141 * @since 2029 133 142 */ 134 143 public static List<ExtensionFileFilter> getExportExtensionFileFilters() { … … 149 158 * @param extension the extension 150 159 * @return the default {@link ExtensionFileFilter} for a given extension 160 * @since 2029 151 161 */ 152 162 public static ExtensionFileFilter getDefaultImportExtensionFileFilter(String extension) { … … 164 174 * @param extension the extension 165 175 * @return the default {@link ExtensionFileFilter} for a given extension 176 * @since 2029 166 177 */ 167 178 public static ExtensionFileFilter getDefaultExportExtensionFileFilter(String extension) { … … 180 191 * @param fileChooser the file chooser 181 192 * @param extension the default extension 182 */ 183 public static void applyChoosableImportFileFilters(JFileChooser fileChooser, String extension) { 193 * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox. 194 * If false, only the file filters that include {@code extension} will be proposed 195 * @since 5438 196 */ 197 public static void applyChoosableImportFileFilters(JFileChooser fileChooser, String extension, boolean allTypes) { 184 198 for (ExtensionFileFilter filter: getImportExtensionFileFilters()) { 185 fileChooser.addChoosableFileFilter(filter); 199 if (allTypes || filter.acceptName("file."+extension)) { 200 fileChooser.addChoosableFileFilter(filter); 201 } 186 202 } 187 203 fileChooser.setFileFilter(getDefaultImportExtensionFileFilter(extension)); … … 194 210 * @param fileChooser the file chooser 195 211 * @param extension the default extension 196 */ 197 public static void applyChoosableExportFileFilters(JFileChooser fileChooser, String extension) { 212 * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox. 213 * If false, only the file filters that include {@code extension} will be proposed 214 * @since 5438 215 */ 216 public static void applyChoosableExportFileFilters(JFileChooser fileChooser, String extension, boolean allTypes) { 198 217 for (ExtensionFileFilter filter: getExportExtensionFileFilters()) { 199 fileChooser.addChoosableFileFilter(filter); 218 if (allTypes || filter.acceptName("file."+extension)) { 219 fileChooser.addChoosableFileFilter(filter); 220 } 200 221 } 201 222 fileChooser.setFileFilter(getDefaultExportExtensionFileFilter(extension)); … … 204 225 /** 205 226 * Construct an extension file filter by giving the extension to check after. 227 * @param extension The comma-separated list of file extensions 228 * @param defaultExtension The default extension 229 * @param description A short textual description of the file type 230 * @since 1169 206 231 */ 207 232 public ExtensionFileFilter(String extension, String defaultExtension, String description) { … … 211 236 } 212 237 238 /** 239 * Returns true if this file filter accepts the given filename. 240 * @param filename The filename to check after 241 * @return true if this file filter accepts the given filename (i.e if this filename ends with one of the extensions) 242 * @since 1169 243 */ 213 244 public boolean acceptName(String filename) { 214 245 String name = filename.toLowerCase(); … … 219 250 } 220 251 221 @Override public boolean accept(File pathname) { 252 @Override 253 public boolean accept(File pathname) { 222 254 if (pathname.isDirectory()) 223 255 return true; … … 225 257 } 226 258 227 @Override public String getDescription() { 259 @Override 260 public String getDescription() { 228 261 return description; 229 262 } 230 263 264 /** 265 * Replies the comma-separated list of file extensions of this file filter. 266 * @return the comma-separated list of file extensions of this file filter, as a String 267 * @since 5131 268 */ 231 269 public String getExtensions() { 232 270 return extensions; 233 271 } 234 272 273 /** 274 * Replies the default file extension of this file filter. 275 * @return the default file extension of this file filter 276 * @since 2029 277 */ 235 278 public String getDefaultExtension() { 236 279 return defaultExtension; -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r5014 r5438 182 182 183 183 public static File createAndOpenSaveFileChooser(String title, String extension) { 184 String curDir = Main.pref.get("lastDirectory"); 185 if (curDir.equals("")) { 186 curDir = "."; 187 } 188 JFileChooser fc = new JFileChooser(new File(curDir)); 189 if (title != null) { 190 fc.setDialogTitle(title); 191 } 192 193 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 194 fc.setMultiSelectionEnabled(false); 195 fc.setAcceptAllFileFilterUsed(false); 196 ExtensionFileFilter.applyChoosableExportFileFilters(fc, extension); 197 int answer = fc.showSaveDialog(Main.parent); 198 if (answer != JFileChooser.APPROVE_OPTION) 199 return null; 200 201 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 202 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 203 } 184 185 JFileChooser fc = createAndOpenFileChooser(false, false, title, extension); 186 if (fc == null) return null; 204 187 205 188 File file = fc.getSelectedFile(); 206 189 String fn = file.getPath(); 207 if (fn.indexOf('.') == -1)190 if (fn.indexOf('.') == -1) 208 191 { 209 192 FileFilter ff = fc.getFileFilter(); -
trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java
r4874 r5438 13 13 import javax.swing.JOptionPane; 14 14 import javax.swing.SwingUtilities; 15 import javax.swing.filechooser.FileFilter;16 15 17 16 import org.openstreetmap.josm.Main; … … 23 22 import org.openstreetmap.josm.io.session.SessionReader; 24 23 25 public class SessionLoadAction extends JosmAction { 24 public class SessionLoadAction extends DiskAccessAction { 25 26 26 public SessionLoadAction() { 27 27 super(tr("Load Session"), "open", tr("Load a session from file."), null, true, "load-session", true); … … 30 30 31 31 public void actionPerformed(ActionEvent e) { 32 String curDir = Main.pref.get("lastDirectory"); 33 if (curDir.equals("")) { 34 curDir = "."; 35 } 36 JFileChooser fc = new JFileChooser(new File(curDir)); 37 fc.setDialogTitle(tr("Open session")); 38 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 39 fc.setMultiSelectionEnabled(false); 40 fc.setAcceptAllFileFilterUsed(true); 41 FileFilter ff = new ExtensionFileFilter("jos,joz", "jos", tr("Session file (*.jos, *.joz)")); 42 fc.addChoosableFileFilter(ff); 43 int answer = fc.showOpenDialog(Main.parent); 44 if (answer != JFileChooser.APPROVE_OPTION) 45 return; 46 47 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 48 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 49 } 32 ExtensionFileFilter ff = new ExtensionFileFilter("jos,joz", "jos", tr("Session file (*.jos, *.joz)")); 33 JFileChooser fc = createAndOpenFileChooser(true, false, tr("Open session"), ff, JFileChooser.FILES_ONLY, "lastDirectory"); 34 if (fc == null) return; 50 35 File file = fc.getSelectedFile(); 51 boolean zip = true; 52 if (file.getName().toLowerCase().endsWith(".jos")) { 53 zip = false; 54 } 36 boolean zip = file.getName().toLowerCase().endsWith(".joz"); 55 37 Main.worker.submit(new Loader(file, zip)); 56 38 } … … 72 54 @Override 73 55 protected void cancel() { 74 Thread. currentThread().dumpStack();56 Thread.dumpStack(); 75 57 canceled = true; 76 58 } -
trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java
r4910 r5438 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 6 7 7 import java.awt.Component; … … 12 12 import java.io.IOException; 13 13 import java.util.ArrayList; 14 import java.util.Arrays; 14 15 import java.util.Collection; 16 import java.util.Collections; 15 17 import java.util.HashMap; 16 18 import java.util.HashSet; … … 32 34 33 35 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.actions.ExtensionFileFilter;35 36 import org.openstreetmap.josm.gui.ExtendedDialog; 36 37 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 42 43 import org.openstreetmap.josm.tools.WindowGeometry; 43 44 44 public class SessionSaveAsAction extends JosmAction {45 public class SessionSaveAsAction extends DiskAccessAction { 45 46 46 47 private List<Layer> layers; … … 52 53 /** 53 54 * Construct the action with "Save" as label. 54 * @param layer Save this layer.55 55 */ 56 56 public SessionSaveAsAction() { … … 77 77 } 78 78 } 79 80 String curDir = Main.pref.get("lastDirectory"); 81 if (curDir.equals("")) { 82 curDir = "."; 83 } 84 JFileChooser fc = new JFileChooser(new File(curDir)); 85 fc.setDialogTitle(tr("Save session")); 86 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 79 87 80 FileFilter joz = new ExtensionFileFilter("joz", "joz", tr("Session file (archive) (*.joz)")); 88 81 FileFilter jos = new ExtensionFileFilter("jos", "jos", tr("Session file (*.jos)")); 82 83 JFileChooser fc; 84 89 85 if (zipRequired) { 90 fc .addChoosableFileFilter(joz);86 fc = createAndOpenFileChooser(false, false, tr("Save session"), joz, JFileChooser.FILES_ONLY, "lastDirectory"); 91 87 } else { 92 fc.addChoosableFileFilter(jos); 93 fc.addChoosableFileFilter(joz); 94 fc.setFileFilter(jos); 95 } 96 int answer = fc.showSaveDialog(Main.parent); 97 if (answer != JFileChooser.APPROVE_OPTION) 88 fc = createAndOpenFileChooser(false, false, tr("Save session"), Arrays.asList(new FileFilter[]{jos, joz}), jos, JFileChooser.FILES_ONLY, "lastDirectory"); 89 } 90 91 if (fc == null) 98 92 return; 99 100 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {101 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());102 }103 93 104 94 File file = fc.getSelectedFile(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r5219 r5438 71 71 import org.openstreetmap.josm.gui.preferences.SourceEntry; 72 72 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 73 import org.openstreetmap.josm.gui.widgets.JFileChooserManager; 73 74 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 74 75 import org.openstreetmap.josm.tools.GBC; … … 522 523 final StyleSource s = model.getRow(sel); 523 524 524 String curDir = Main.pref.get("mappaint.clone-style.lastDirectory", System.getProperty("user.home")); 525 526 String suggestion = curDir + File.separator + s.getFileNamePart(); 527 JFileChooser fc = new JFileChooser(); 528 fc.setSelectedFile(new File(suggestion)); 529 530 int answer = fc.showSaveDialog(Main.parent); 531 if (answer != JFileChooser.APPROVE_OPTION) 525 JFileChooserManager fcm = new JFileChooserManager(false, "mappaint.clone-style.lastDirectory", System.getProperty("user.home")); 526 String suggestion = fcm.getInitialDirectory() + File.separator + s.getFileNamePart(); 527 fcm.createFileChooser().getFileChooser().setSelectedFile(new File(suggestion)); 528 JFileChooser fc = fcm.openFileChooser(); 529 if (fc == null) 532 530 return; 533 531 534 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {535 Main.pref.put("mappaint.clone-style.lastDirectory", fc.getCurrentDirectory().getAbsolutePath());536 }537 532 File file = fc.getSelectedFile(); 538 533 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r5429 r5438 62 62 import org.openstreetmap.josm.Main; 63 63 import org.openstreetmap.josm.actions.AbstractMergeAction.LayerListCellRenderer; 64 import org.openstreetmap.josm.actions.DiskAccessAction; 64 65 import org.openstreetmap.josm.actions.RenameLayerAction; 65 66 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList; … … 95 96 import org.openstreetmap.josm.gui.progress.ProgressTaskIds; 96 97 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 98 import org.openstreetmap.josm.gui.widgets.JFileChooserManager; 97 99 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 98 100 import org.openstreetmap.josm.io.JpgImporter; … … 1909 1911 return; 1910 1912 } 1911 String dir = Main.pref.get("markers.lastaudiodirectory"); 1912 JFileChooser fc = new JFileChooser(dir); 1913 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 1914 fc.setAcceptAllFileFilterUsed(false); 1915 fc.setFileFilter(new FileFilter() { 1913 FileFilter filter = new FileFilter() { 1916 1914 @Override 1917 1915 public boolean accept(File f) { … … 1923 1921 return tr("Wave Audio files (*.wav)"); 1924 1922 } 1925 }); 1926 fc.setMultiSelectionEnabled(true); 1927 if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 1928 if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) { 1929 Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath()); 1930 } 1931 1923 }; 1924 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, true, null, filter, JFileChooser.FILES_ONLY, "markers.lastaudiodirectory"); 1925 if (fc != null) { 1932 1926 File sel[] = fc.getSelectedFiles(); 1933 1927 // sort files in increasing order of timestamp (this is the end time, but so … … 1968 1962 Main.map.repaint(); 1969 1963 } 1970 1971 1964 } 1972 1965 } … … 2010 2003 return; 2011 2004 } 2012 String curDir = Main.pref.get("geoimage.lastdirectory", Main.pref.get("lastDirectory")); 2013 if (curDir.equals("")) { 2014 curDir = "."; 2015 } 2016 JFileChooser fc = new JFileChooser(new File(curDir)); 2017 2018 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 2019 fc.setMultiSelectionEnabled(true); 2020 fc.setAcceptAllFileFilterUsed(false); 2005 2021 2006 JpgImporter importer = new JpgImporter(GpxLayer.this); 2022 fc.setFileFilter(importer.filter); 2023 fc.showOpenDialog(Main.parent); 2024 LinkedList<File> files = new LinkedList<File>(); 2025 File[] sel = fc.getSelectedFiles(); 2026 if (sel == null || sel.length == 0) 2027 return; 2028 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 2029 Main.pref.put("geoimage.lastdirectory", fc.getCurrentDirectory().getAbsolutePath()); 2030 } 2031 addRecursiveFiles(files, sel); 2032 importer.importDataHandleExceptions(files, NullProgressMonitor.INSTANCE); 2007 JFileChooser fc = new JFileChooserManager(true, "geoimage.lastdirectory", Main.pref.get("lastDirectory")). 2008 createFileChooser(true, null, importer.filter, JFileChooser.FILES_AND_DIRECTORIES).openFileChooser(); 2009 if (fc != null) { 2010 File[] sel = fc.getSelectedFiles(); 2011 if (sel != null && sel.length > 0) { 2012 LinkedList<File> files = new LinkedList<File>(); 2013 addRecursiveFiles(files, sel); 2014 importer.importDataHandleExceptions(files, NullProgressMonitor.INSTANCE); 2015 } 2016 } 2033 2017 } 2034 2018 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r5429 r5438 65 65 66 66 import org.openstreetmap.josm.Main; 67 import org.openstreetmap.josm.actions.DiskAccessAction; 67 68 import org.openstreetmap.josm.data.gpx.GpxData; 68 69 import org.openstreetmap.josm.data.gpx.GpxTrack; … … 134 135 135 136 public void actionPerformed(ActionEvent arg0) { 136 JFileChooser fc = new JFileChooser(Main.pref.get("lastDirectory")); 137 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 138 fc.setAcceptAllFileFilterUsed(false); 139 fc.setMultiSelectionEnabled(false); 140 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 141 fc.setFileFilter(new FileFilter(){ 137 FileFilter filter = new FileFilter(){ 142 138 @Override public boolean accept(File f) { 143 139 return (f.isDirectory() … … 148 144 return tr("GPX Files (*.gpx *.gpx.gz)"); 149 145 } 150 }); 151 fc.showOpenDialog(Main.parent); 146 }; 147 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, filter, JFileChooser.FILES_ONLY, null); 148 if (fc == null) 149 return; 152 150 File sel = fc.getSelectedFile(); 153 if (sel == null)154 return;155 151 156 152 try { 157 153 outerPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 158 159 Main.pref.put("lastDirectory", sel.getPath());160 154 161 155 for (int i = gpxLst.size() - 1 ; i >= 0 ; i--) { … … 375 369 376 370 public void actionPerformed(ActionEvent arg0) { 377 JFileChooser fc = new JFileChooser(Main.pref.get("geoimage.lastdirectory")); 378 fc.setAcceptAllFileFilterUsed(false); 379 fc.setMultiSelectionEnabled(false); 380 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 381 fc.setFileFilter(JpegFileFilter.getInstance()); 382 fc.showOpenDialog(Main.parent); 371 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, JpegFileFilter.getInstance(), JFileChooser.FILES_ONLY, "geoimage.lastdirectory"); 372 if (fc == null) 373 return; 383 374 File sel = fc.getSelectedFile(); 384 if (sel == null)385 return;386 375 387 376 Integer orientation = null; -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r5220 r5438 75 75 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 76 76 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 77 import org.openstreetmap.josm.gui.widgets.JFileChooserManager; 77 78 import org.openstreetmap.josm.io.MirroredInputStream; 78 79 import org.openstreetmap.josm.io.OsmTransferException; … … 751 752 752 753 public void actionPerformed(ActionEvent e) { 753 JFileChooser fc= new JFileChooser();754 prepareFileChooser(tfURL.getText(), fc );755 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(SourceEditor.this));756 if ( ret != JFileChooser.APPROVE_OPTION)757 return;758 tfURL.setText(fc.getSelectedFile().toString());754 JFileChooserManager fcm = new JFileChooserManager(true); 755 prepareFileChooser(tfURL.getText(), fcm.getFileChooser()); 756 JFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this)); 757 if (fc != null) { 758 tfURL.setText(fc.getSelectedFile().toString()); 759 } 759 760 } 760 761 } … … 1285 1286 private CopyOnWriteArrayList<CellEditorListener> listeners; 1286 1287 private String value; 1287 private JFileChooser fileChooser;1288 1288 private boolean isFile; 1289 1290 protected JFileChooser getFileChooser() {1291 if (fileChooser == null) {1292 this.fileChooser = new JFileChooser();1293 if(!isFile) {1294 fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);1295 }1296 }1297 return fileChooser;1298 }1299 1289 1300 1290 /** … … 1428 1418 1429 1419 public void actionPerformed(ActionEvent e) { 1430 JFileChooser fc = getFileChooser(); 1431 prepareFileChooser(tfFileName.getText(), fc); 1432 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(SourceEditor.this)); 1433 if (ret != JFileChooser.APPROVE_OPTION) 1434 return; 1435 tfFileName.setText(fc.getSelectedFile().toString()); 1420 JFileChooserManager fcm = new JFileChooserManager(true).createFileChooser(); 1421 if (!isFile) { 1422 fcm.getFileChooser().setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 1423 } 1424 prepareFileChooser(tfFileName.getText(), fcm.getFileChooser()); 1425 JFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this)); 1426 if (fc != null) { 1427 tfFileName.setText(fc.getSelectedFile().toString()); 1428 } 1436 1429 } 1437 1430 } -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r5203 r5438 2 2 package org.openstreetmap.josm.gui.preferences.advanced; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.marktr;6 6 7 7 import java.awt.Color; … … 14 14 import java.awt.event.MouseAdapter; 15 15 import java.awt.event.MouseEvent; 16 17 16 import java.io.File; 18 17 import java.util.ArrayList; … … 43 42 44 43 import org.openstreetmap.josm.Main; 44 import org.openstreetmap.josm.actions.DiskAccessAction; 45 45 import org.openstreetmap.josm.data.CustomConfigurator; 46 46 import org.openstreetmap.josm.data.Preferences; … … 316 316 317 317 private File[] askUserForCustomSettingsFiles(boolean saveFileFlag, String title) { 318 String dir = Main.pref.get("customsettings.lastDirectory"); 319 if (dir.length()==0) dir ="."; 320 321 JFileChooser fc = new JFileChooser(dir); 322 fc.setDialogTitle(title); 323 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 324 fc.setAcceptAllFileFilterUsed(false); 325 fc.setFileFilter(new FileFilter() { 318 FileFilter filter = new FileFilter() { 326 319 @Override 327 320 public boolean accept(File f) { … … 332 325 return tr("JOSM custom settings files (*.xml)"); 333 326 } 334 }); 335 336 fc.setMultiSelectionEnabled(!saveFileFlag); 337 int result = saveFileFlag? fc.showSaveDialog(Main.parent) : fc.showOpenDialog(Main.parent); 338 if (result == JFileChooser.APPROVE_OPTION) { 339 if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) { 340 Main.pref.put("customsettings.lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 341 } 342 File sel[] = fc.isMultiSelectionEnabled() ? fc.getSelectedFiles() : (new File[]{fc.getSelectedFile()}); 343 if (sel.length==1 && !sel[0].getName().contains(".")) sel[0]=new File(sel[0].getAbsolutePath()+".xml"); 344 return sel; 345 } 346 return new File[0]; 327 }; 328 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(!saveFileFlag, !saveFileFlag, title, filter, JFileChooser.FILES_ONLY, "customsettings.lastDirectory"); 329 if (fc != null) { 330 File sel[] = fc.isMultiSelectionEnabled() ? fc.getSelectedFiles() : (new File[]{fc.getSelectedFile()}); 331 if (sel.length==1 && !sel[0].getName().contains(".")) sel[0]=new File(sel[0].getAbsolutePath()+".xml"); 332 return sel; 333 } 334 return new File[0]; 347 335 } 348 336 -
trunk/src/org/openstreetmap/josm/io/JpgImporter.java
r5361 r5438 17 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 18 18 19 /** 20 * File importer allowing to import geottaged images (*.jpg files). 21 * 22 */ 19 23 public class JpgImporter extends FileImporter { 20 24 private GpxLayer gpx; 21 25 26 /** 27 * The default file filter (only *.jpg files). 28 */ 22 29 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 30 "jpg", "jpg", tr("Image Files") + " (*.jpg)"); 31 32 /** 33 * An alternate file filter that also includes folders. 34 * @since 5438 35 */ 36 public static final ExtensionFileFilter FILE_FILTER_WITH_FOLDERS = new ExtensionFileFilter( 23 37 "jpg", "jpg", tr("Image Files") + " (*.jpg, "+ tr("folder")+")"); 24 38 39 /** 40 * Constructs a new {@code JpgImporter}. 41 */ 25 42 public JpgImporter() { 26 super(FILE_FILTER);43 this(false); 27 44 } 28 45 46 /** 47 * Constructs a new {@code JpgImporter} with folders selection, if wanted. 48 * @param includeFolders If true, includes folders in the file filter 49 * @since 5438 50 */ 51 public JpgImporter(boolean includeFolders) { 52 super(includeFolders ? FILE_FILTER_WITH_FOLDERS : FILE_FILTER); 53 } 54 55 /** 56 * Constructs a new {@code JpgImporter} for the given GPX layer. Folders selection is allowed. 57 * @param gpx The GPX layer 58 */ 29 59 public JpgImporter(GpxLayer gpx) { 30 this( );60 this(true); 31 61 this.gpx = gpx; 32 62 }
Note:
See TracChangeset
for help on using the changeset viewer.