001package jmri.util.swing;
002
003import java.io.File;
004
005import javax.swing.JFileChooser;
006import javax.swing.filechooser.FileSystemView;
007
008import jmri.InstanceManager;
009
010public class JmriJFileChooser extends JFileChooser {
011
012
013    public JmriJFileChooser() {
014        super();
015        setJFileChooserFormat();
016    }
017
018    public JmriJFileChooser(String path) {
019        super(path);
020        setJFileChooserFormat();
021    }
022
023    public JmriJFileChooser(FileSystemView fsv) {
024        super(fsv);
025        setJFileChooserFormat();
026    }
027
028
029    public JmriJFileChooser(File f) {
030        super(f);
031        setJFileChooserFormat();
032    }
033
034    private void setJFileChooserFormat() {
035        javax.swing.Action details;
036        switch (InstanceManager.getDefault(jmri.util.gui.GuiLafPreferencesManager.class).getJFileChooserFormat()) {
037            case 1:
038                details = this.getActionMap().get("viewTypeList");
039                break;
040            case 2:
041                details = this.getActionMap().get("viewTypeDetails");
042                break;
043            default:
044                return;
045        }
046        if (details!=null) {
047            details.actionPerformed(null);
048        }
049    }
050
051    // set ModalityType.DOCUMENT_MODAL so does not clash with Always On Top windows.
052    @Override
053    protected javax.swing.JDialog createDialog(java.awt.Component parent) throws java.awt.HeadlessException {
054        javax.swing.JDialog dialog = super.createDialog(parent);
055        if ( parent != null ) {
056            dialog.setModalityType(java.awt.Dialog.ModalityType.DOCUMENT_MODAL);
057        }
058        return dialog;
059    }
060
061}