Example usage for javax.swing JFileChooser setFileHidingEnabled

List of usage examples for javax.swing JFileChooser setFileHidingEnabled

Introduction

In this page you can find the example usage for javax.swing JFileChooser setFileHidingEnabled.

Prototype

@BeanProperty(preferred = true, description = "Sets file hiding on or off.")
public void setFileHidingEnabled(boolean b) 

Source Link

Document

Sets file hiding on or off.

Usage

From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java

private void importMarketLogs() {

    File inputDir = null;// ww  w  .  ja v  a  2 s .  c  o m
    if (appConfigProvider.getAppConfig().hasLastMarketLogImportDirectory()) {
        inputDir = appConfigProvider.getAppConfig().getLastMarketLogImportDirectory();

        if (!inputDir.exists() || !inputDir.isDirectory()) {
            inputDir = null;
        }
    }

    final JFileChooser chooser = inputDir != null ? new JFileChooser(inputDir) : new JFileChooser();

    chooser.setFileHidingEnabled(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(true);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File[] files = chooser.getSelectedFiles();
        if (!ArrayUtils.isEmpty(files)) {
            appConfigProvider.getAppConfig().setLastMarketLogImportDirectory(files[0].getParentFile());
            try {
                appConfigProvider.save();
            } catch (IOException e) {
                log.error("importMarketLogs(): Failed to save configuration", e);
            }
            importMarketLogs(files);
        }
    }

}

From source file:configuration.Util.java

public static String[] simpleSearchBox(String type, boolean multi, boolean hide) {
    JFrame f = createSearchFrame();
    JFileChooser jf;
    jf = new JFileChooser(config.getExplorerPath());
    if (type.contains("d") || type.contains("D"))
        jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    else if (type.contains("f") || type.contains("F"))
        jf.setFileSelectionMode(JFileChooser.FILES_ONLY);
    else//from ww w . j  ava 2  s .c o m
        jf.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    jf.setAcceptAllFileFilterUsed(false);
    jf.setMultiSelectionEnabled(multi);
    jf.setFileHidingEnabled(hide);
    int result = jf.showOpenDialog(f);
    f.dispose();

    if (result == JFileChooser.APPROVE_OPTION) {
        if (multi) {
            //--Save new filepath and files
            File[] files = jf.getSelectedFiles();
            String[] path = new String[files.length];
            for (int i = 0; i < files.length; i++) {
                path[i] = getCanonicalPath(files[i].getPath());
            }
            return path;
        } else {
            File file = jf.getSelectedFile();
            String[] path = new String[1];
            path[0] = getCanonicalPath(file.getPath());
            return path;
        }
    }
    String[] empty = new String[0];
    return empty;
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
    JFileChooser fc = new JFileChooser(new File(dirBox.getText()));

    fc.setFileHidingEnabled(false);
    fc.setDialogTitle("Select directory");
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        dirBox.setText(fc.getSelectedFile().toString());
    }/*from   www . j  a  va  2  s  .  c o m*/
}

From source file:com.pianobakery.complsa.MainGui.java

public File chooseAddCorpusFolder() {

    try {//from   w  w w  .ja v a  2 s.  c  o  m

        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
        chooser.setDialogTitle("Create Working Folder");
        chooser.setFileHidingEnabled(Boolean.TRUE);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        int whatChoose = chooser.showOpenDialog(null);
        File selected;
        if (whatChoose == JFileChooser.APPROVE_OPTION) {
            selected = chooser.getSelectedFile();
            logger.debug("AddCorpDir is: " + selected.toString());
            logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory());
            logger.debug("getSelectedFile() : " + chooser.getSelectedFile());
            enableUIElements(true);

            return selected;

        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Falsche Eingabe");
    }

    return null;
}

From source file:com.pianobakery.complsa.MainGui.java

public void importSearchFile() {
    searchDocValue.setText("loading...");

    try {//from ww  w . j  a v a  2s.c o  m
        File selected;
        searchFileString = "";
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
        chooser.setDialogTitle("Choose Search File");
        chooser.setFileHidingEnabled(Boolean.TRUE);
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        int whatChoose = chooser.showOpenDialog(null);
        if (whatChoose == JFileChooser.APPROVE_OPTION) {
            selected = chooser.getSelectedFile();
            logger.debug("AddCorpDir is: " + selected.toString());
            logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory());
            logger.debug("getSelectedFile() : " + chooser.getSelectedFile());
            enableUIElements(true);
            if (selected.exists()) {

                Parser parser = new Parser(selected);
                try {
                    parser.parseDocToPlainText();

                    searchFileString = Utilities.removeQuoteFromString(parser.getPlainText());
                    logger.debug("The Search File: " + searchFileString);
                    searchDocValue
                            .setText(selected.getParentFile().getName() + File.separator + selected.getName());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (SAXException e) {
                    e.printStackTrace();
                } catch (TikaException e) {
                    e.printStackTrace();
                }
            }

        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Falsche Eingabe");
    }

}

From source file:com.pianobakery.complsa.MainGui.java

public void chooseNewProjectFolder() {

    try {/*from   w  ww.  j a  v  a 2  s .c o m*/

        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(openFolder);
        //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home")));
        chooser.setDialogTitle("Choose Folder");
        chooser.setFileHidingEnabled(Boolean.TRUE);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setApproveButtonText("Choose");
        int whatChoose = chooser.showOpenDialog(null);

        if (whatChoose == JFileChooser.APPROVE_OPTION) {
            String text = chooser.getSelectedFile().toString();
            wDirText.setText(text);
            wDir = chooser.getSelectedFile();
            logger.debug("WDir is: " + wDir.toString());
            logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory());
            logger.debug("getSelectedFile() : " + chooser.getSelectedFile());
            enableUIElements(true);
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Falsche Eingabe");
    }

}

From source file:com.pianobakery.complsa.MainGui.java

public void createNewProjectFolder() {

    try {//from  ww  w .  j ava2  s.  com
        JFrame frame = new JFrame();
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(openFolder);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home")));
        chooser.setDialogTitle("Create Folder");
        chooser.setFileHidingEnabled(Boolean.TRUE);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        chooser.setSelectedFile(new File("Workingfile"));
        frame.getContentPane().add(chooser);
        chooser.setApproveButtonText("Choose");

        //Disable Save as
        ArrayList<JPanel> jpanels = new ArrayList<JPanel>();
        for (Component c : chooser.getComponents()) {
            if (c instanceof JPanel) {
                jpanels.add((JPanel) c);
            }

        }
        jpanels.get(0).getComponent(0).setVisible(false);
        frame.pack();
        frame.setLocationRelativeTo(null);

        int whatChoose = chooser.showSaveDialog(null);
        if (whatChoose == JFileChooser.APPROVE_OPTION) {
            File selFile = chooser.getSelectedFile();
            File currDir = chooser.getCurrentDirectory();
            Path parentDir = Paths.get(chooser.getCurrentDirectory().getParent());
            String parentDirName = parentDir.getFileName().toString();

            logger.debug("Chooser SelectedFile: " + selFile.toString());
            logger.debug("getCurrentDirectory(): " + currDir.toString());
            logger.debug("Chooser parentdir: " + parentDir);
            logger.debug("Parentdirname: " + parentDirName);

            if (selFile.getName().equals(parentDirName)) {
                wDir = currDir;
            } else {
                wDir = chooser.getSelectedFile();
            }

            logger.debug("WDIR is: " + wDir.toString());
            wDirText.setText(wDir.toString());
            enableUIElements(true);
        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Falsche Eingabe");
        logger.debug("Exeption: " + ex.toString());
    }
}

From source file:org.parosproxy.paros.control.MenuFileControl.java

private void openFileBasedSession() {
    JFileChooser chooser = new JFileChooser(model.getOptionsParam().getUserDirectory());
    chooser.setFileHidingEnabled(false); // By default ZAP on linux puts timestamped sessions under a 'dot' directory 
    File file = null;/*ww w  . j  a  v  a2s .  c o m*/
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".session")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            // ZAP: Rebrand
            return Constant.messages.getString("file.format.zap.session");
        }
    });
    int rc = chooser.showOpenDialog(view.getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            if (file == null) {
                return;
            }
            model.getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
            log.info("opening session file " + file.getAbsolutePath());
            waitMessageDialog = view.getWaitMessageDialog(Constant.messages.getString("menu.file.loadSession"));
            control.openSession(file, this);
            waitMessageDialog.setVisible(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.sonar.scanner.protocol.viewer.ScannerReportViewerApp.java

private void loadReport() {
    final JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Choose scanner report directory");
    File lastReport = getLastUsedReport();
    if (lastReport != null) {
        fc.setCurrentDirectory(lastReport);
    }//from   ww w  .  j  a  v  a2s. co  m
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setFileHidingEnabled(false);
    fc.setApproveButtonText("Open scanner report");
    int returnVal = fc.showOpenDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {
            setLastUsedReport(file);
            loadReport(file);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(frame, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            exit();
        }
    } else {
        exit();
    }

}

From source file:org.squidy.designer.Designer.java

/**
 * Initializes menu bar.//from   ww  w  .j  a va 2  s. co  m
 */
private void initMenuBar() {

    JMenuBar menuBar = new JMenuBar();

    JMenu workspace = new JMenu("Workspace");
    workspace.add(new AbstractAction("Open from...") {

        /*
         * (non-Javadoc)
         * 
         * @see
         * java.awt.event.ActionListener#actionPerformed(java.awt.event.
         * ActionEvent)
         */
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileHidingEnabled(true);
            fileChooser.setFileFilter(new FileFilter() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see
                 * javax.swing.filechooser.FileFilter#accept(java.io.File)
                 */
                @Override
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().endsWith(".sdy");
                }

                /*
                 * (non-Javadoc)
                 * 
                 * @see javax.swing.filechooser.FileFilter#getDescription()
                 */
                @Override
                public String getDescription() {
                    return "Squidy Workspace";
                }
            });
            int option = fileChooser.showOpenDialog(Designer.this);

            if (option == JFileChooser.APPROVE_OPTION) {

                // Stop replacing workspace if currently running.
                if (data != null) {
                    data.getWorkspace().stop();
                }

                File workspaceFile = fileChooser.getSelectedFile();

                if (storage instanceof LocalJAXBStorage) {
                    ((LocalJAXBStorage) storage).setWorkspaceFile(workspaceFile);
                    load();
                } else {
                    try {
                        data = ModelViewHandler.getModelViewHandler().load(new FileInputStream(workspaceFile));

                        WorkspaceShape workspace = data.getWorkspaceShape();
                        workspace.setModel(data);
                        workspace.setStorageHandler(Designer.this);
                        workspace.initialize();
                        LayoutConstraint lc = workspace.getLayoutConstraint();
                        workspace.setScale(lc.getScale());
                        workspace.setOffset(lc.getX(), lc.getY());

                        getCanvas().getLayer().addChild(workspace);

                        zoomToZoomedShape(data);
                    } catch (SquidyException e1) {
                        e1.printStackTrace();
                    } catch (FileNotFoundException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    });

    workspace.add(new AbstractAction("Export as...") {

        /*
         * (non-Javadoc)
         * 
         * @see
         * java.awt.event.ActionListener#actionPerformed(java.awt.event.
         * ActionEvent)
         */
        public void actionPerformed(ActionEvent e) {

            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileHidingEnabled(true);
            fileChooser.setFileFilter(new FileFilter() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see
                 * javax.swing.filechooser.FileFilter#accept(java.io.File)
                 */
                @Override
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().endsWith(".sdy");
                }

                /*
                 * (non-Javadoc)
                 * 
                 * @see javax.swing.filechooser.FileFilter#getDescription()
                 */
                @Override
                public String getDescription() {
                    return "Squidy Workspace";
                }
            });

            if (storage instanceof LocalJAXBStorage) {
                fileChooser.setSelectedFile(((LocalJAXBStorage) storage).getWorkspaceFile());
            }

            int option = fileChooser.showSaveDialog(Designer.this);

            if (option == JFileChooser.APPROVE_OPTION) {

                File workspaceFile = fileChooser.getSelectedFile();

                try {
                    ModelViewHandler.getModelViewHandler().save(new FileOutputStream(workspaceFile), data);
                } catch (FileNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }
    });

    JMenu options = new JMenu("Options");
    rendering.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            VisualShape.setRenderPrimitiveRect(rendering.isSelected());
            data.setRenderPrimitiveRect(rendering.isSelected());
            storage.store(data);
            repaint();
        }
    });
    options.add(rendering);

    JMenu storage = new JMenu("Storage");

    ButtonGroup group = new ButtonGroup();

    final JRadioButtonMenuItem storageLocalJAXB = new JRadioButtonMenuItem("Local JAXB");
    storageLocalJAXB.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (storageLocalJAXB.isSelected()) {
                setStorageMode(StorageMode.FILE);
            }
        }
    });
    storage.add(storageLocalJAXB);
    group.add(storageLocalJAXB);

    final JRadioButtonMenuItem storageBaseX = new JRadioButtonMenuItem("BaseX");
    storageBaseX.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (storageBaseX.isSelected()) {
                setStorageMode(StorageMode.BASEX);
            }
        }
    });
    storageBaseX.setSelected(storageType.equals(BaseXStorage.class));

    storage.add(storageBaseX);
    group.add(storageBaseX);
    options.add(storage);

    menuBar.add(workspace);
    menuBar.add(options);

    setJMenuBar(menuBar);
}