Ignore:
Timestamp:
2012-08-13T00:12:48+02:00 (14 years ago)
Author:
Don-vip
Message:

fix #6733 - File Open dialog incorrectly accepts folder selection

Major rework of how the JFileChooser are created in JOSM

  • Simple need: use DiskAccessAction.createAndOpenFileChooser methods
  • Complex need: use directly the new class JFileChooserManager

Concerning the directory selection for geottaged images, this is still possible via:

  • right-click on GPX layer -> Import Photos
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r5220 r5438  
    7575import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    7676import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     77import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
    7778import org.openstreetmap.josm.io.MirroredInputStream;
    7879import org.openstreetmap.josm.io.OsmTransferException;
     
    751752
    752753            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                }
    759760            }
    760761        }
     
    12851286        private CopyOnWriteArrayList<CellEditorListener> listeners;
    12861287        private String value;
    1287         private JFileChooser fileChooser;
    12881288        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         }
    12991289
    13001290        /**
     
    14281418
    14291419            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                }
    14361429            }
    14371430        }
Note: See TracChangeset for help on using the changeset viewer.