Example usage for javax.swing JFileChooser FILES_ONLY

List of usage examples for javax.swing JFileChooser FILES_ONLY

Introduction

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

Prototype

int FILES_ONLY

To view the source code for javax.swing JFileChooser FILES_ONLY.

Click Source Link

Document

Instruction to display only files.

Usage

From source file:org.apache.uima.tools.docanalyzer.DBAnnotationViewerDialog.java

/**
 * If the current AE filename is not know ask for it. Then parse the selected file and return the
 * AnalysisEngineDescription object.//from  ww w  .ja va 2  s  .  co  m
 * 
 * @return the selected AnalysisEngineDescription, null if the user cancelled
 */
protected AnalysisEngineDescription promptForAE()
        throws IOException, InvalidXMLException, ResourceInitializationException {
    if (med1.getTAEfile() != null) {
        File taeFile = new File(med1.getTAEfile());
        XMLInputSource in = new XMLInputSource(taeFile);
        AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
        return aed;
    } else {
        String taeDir = med1.getTAEfile();
        JFileChooser chooser = new JFileChooser(taeDir);
        chooser.setDialogTitle("Select the Analysis Engine that Generated this Output");
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int returnVal = chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            XMLInputSource in = new XMLInputSource(chooser.getSelectedFile());
            return UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
        } else {
            return null;
        }
    }
}

From source file:org.domainmath.gui.MainFrame.java

public void saveplot() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works"));
    fc.setFileFilter(DomainMathFileFilter.SAVE_PLOT_FILE_FILTER);
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);//from w ww . j  a  v  a  2s.  c o  m

    File file_plot;
    String name;
    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        System.err.println(fc.getFileFilter().getDescription());
        file_plot = fc.getSelectedFile();
        name = file_plot.getName();
        evaluateWithOutput("saveas(1," + "'" + file_plot.getAbsolutePath() + "');");

    }
}

From source file:org.executequery.gui.drivers.AbstractDriverPanel.java

public void browseDrivers(ActionEvent e) {

    if (databaseDriver.isDefaultSunOdbc()) {

        return;//  ww w  .  j av  a  2s .  c om
    }

    FileSelector jarFiles = new FileSelector(new String[] { "jar" },
            getString("AbstractDriverPanel.javaArchiveFiles"));

    FileSelector zipFiles = new FileSelector(new String[] { "zip" },
            getString("AbstractDriverPanel.zipArchiveFiles"));

    final FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.addChoosableFileFilter(zipFiles);
    fileChooser.addChoosableFileFilter(jarFiles);

    fileChooser.setDialogTitle(getString("AbstractDriverPanel.selectJdbcDrivers"));
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(true);

    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(),
            getString("AbstractDriverPanel.select"));

    if (result == JFileChooser.CANCEL_OPTION) {

        return;
    }

    ThreadUtils.startWorker(new Runnable() {

        public void run() {

            try {
                GUIUtilities.showWaitCursor();

                File[] files = fileChooser.getSelectedFiles();
                for (int i = 0; i < files.length; i++) {

                    String path = files[i].getAbsolutePath();
                    if (!jarPathListModel.contains(path)) {

                        jarPathListModel.addElement(path);
                    }

                }

                databaseDriver.setPath(jarPathsFormatted());
                populateDriverClassCombo();

            } finally {

                GUIUtilities.showNormalCursor();
            }

        }

    });

}

From source file:org.executequery.gui.editor.LobDataItemViewerPanel.java

public void save() {

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int result = fileChooser.showSaveDialog((JDialog) parent);
    if (result == JFileChooser.CANCEL_OPTION) {

        return;/*from   w  w w .ja va  2  s  . com*/
    }

    if (fileChooser.getSelectedFile() != null) {

        try {

            GUIUtilities.showWaitCursor();

            new ByteArrayFileWriter().write(fileChooser.getSelectedFile(), recordDataItemByteArray());

        } catch (IOException e) {

            if (Log.isDebugEnabled()) {

                Log.debug("Error writing LOB to file", e);
            }

            GUIUtilities.displayErrorMessage("Error writing LOB data to file:\n" + e.getMessage());
            return;

        } finally {

            GUIUtilities.showNormalCursor();
        }

    }

    close();
}

From source file:org.executequery.gui.ExecuteSqlScriptPanel.java

public void browse() {

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);

    fileChooser.setDialogTitle("Select Export File Path");
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select");
    if (result == JFileChooser.CANCEL_OPTION) {

        return;/*from  w  ww  .  j ava 2s  .  c om*/
    }

    File file = fileChooser.getSelectedFile();
    fileNameField.setText(file.getAbsolutePath());
}

From source file:org.executequery.gui.ExportResultSetPanel.java

public void browse() {

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);

    fileChooser.setDialogTitle("Select Export File Path");
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select");
    if (result == JFileChooser.CANCEL_OPTION) {

        return;// ww  w  . j ava 2s . c  om
    }

    File file = fileChooser.getSelectedFile();
    if (file.exists()) {

        result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?");

        if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) {

            browse();
            return;
        }

    }

    fileNameField.setText(file.getAbsolutePath());
}

From source file:org.executequery.gui.ReadOnlyTextPanePopUpMenu.java

public void saveToFile(ActionEvent e) {

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);

    fileChooser.setDialogTitle("Select Output File Path");
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select");
    if (result == JFileChooser.CANCEL_OPTION) {

        return;//  w w w.  j a v  a  2s  . co m
    }

    File file = fileChooser.getSelectedFile();
    if (file.exists()) {

        result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?");

        if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) {

            saveToFile(e);
            return;
        }

    }

    try {

        FileUtils.writeFile(file.getAbsolutePath(), readOnlyTextArea.getText());

    } catch (IOException e1) {

        GUIUtilities.displayErrorMessage("Error writing output pane contents to file.\n" + e1.getMessage());
    }
}

From source file:org.executequery.gui.scriptgenerators.GenerateScriptsPanelThree.java

public void actionPerformed(ActionEvent e) {
    FileSelector textFiles = new FileSelector(new String[] { "txt" }, "Text files");
    FileSelector sqlFiles = new FileSelector(new String[] { "sql" }, "SQL files");

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.addChoosableFileFilter(textFiles);
    fileChooser.addChoosableFileFilter(sqlFiles);

    fileChooser.setDialogTitle("Select File...");
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select");
    if (result == JFileChooser.CANCEL_OPTION) {
        return;/*from ww w  . ja  va  2 s  .c o  m*/
    }

    String path = fileChooser.getSelectedFile().getAbsolutePath();
    if (!path.toUpperCase().endsWith(".SQL")) {
        path += ".sql";
    }
    pathField.setText(path);
}

From source file:org.executequery.gui.text.TextFileWriter.java

private boolean showSaveDialog() {

    if (!showDialog && !MiscUtils.isNull(path)) { // already have path

        return true;
    }/* w  w w .  ja  v  a  2s. co m*/

    FileSelector textFiles = new FileSelector(new String[] { "txt" }, "Text files");
    FileSelector sqlFiles = new FileSelector(new String[] { "sql" }, "SQL files");

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.addChoosableFileFilter(textFiles);
    fileChooser.addChoosableFileFilter(sqlFiles);

    if (selectedFile != null) {

        fileChooser.setSelectedFile(selectedFile);
    }

    int result = fileChooser.showSaveDialog(GUIUtilities.getInFocusDialogOrWindow());
    if (result == JFileChooser.CANCEL_OPTION) {

        return false;
    }

    if (fileChooser.getSelectedFile() != null) {

        path = fileChooser.getSelectedFile().getAbsolutePath();
    }

    String extension = null;
    FileFilter filter = fileChooser.getFileFilter();
    if (filter == textFiles) {

        extension = ".txt";

    } else if (filter == sqlFiles) {

        extension = ".sql";
    }

    if (StringUtils.isNotBlank(extension) && !path.endsWith(extension)) {

        path += extension;
    }

    return true;
}

From source file:org.executequery.gui.text.TextUtilities.java

public static void insertFromFile(JTextComponent textComponent) {
    StringBuffer buf = null;//from   www .ja  va 2s.  c o  m
    String text = null;

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setDialogTitle("Insert from file");
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Insert");

    if (result == JFileChooser.CANCEL_OPTION)
        return;

    File file = fileChooser.getSelectedFile();

    try {
        FileInputStream input = new FileInputStream(file);
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        buf = new StringBuffer(10000);

        char newLine = '\n';

        while ((text = reader.readLine()) != null)
            buf.append(text).append(newLine);

        reader.close();
        reader = null;
        input.close();
        input = null;

        int index = textComponent.getCaretPosition();
        StringBuffer sb = new StringBuffer(textComponent.getText());
        sb.insert(index, buf.toString());
        textComponent.setText(sb.toString());
        textComponent.setCaretPosition(index + buf.length());

    } catch (OutOfMemoryError e) {
        buf = null;
        text = null;
        System.gc();
        GUIUtilities.displayErrorMessage("Out of Memory.\nThe file is " + "too large to\nopen for viewing.");
    } catch (IOException e) {
        e.printStackTrace();
        StringBuffer sb = new StringBuffer();
        sb.append("An error occurred opening the selected file.").append("\n\nThe system returned:\n")
                .append(e.getMessage());
        GUIUtilities.displayExceptionErrorDialog(sb.toString(), e);
    }

}