Example usage for javax.swing JFileChooser CANCEL_OPTION

List of usage examples for javax.swing JFileChooser CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

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

Click Source Link

Document

Return value if cancel is chosen.

Usage

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 www  .  jav a2  s  .com
    }

    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;/*from   w ww. j a  v  a2s .c  o  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) {

            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 va2 s . 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;/*w  ww. jav  a  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;
    }/*from  w w w. j ava  2s  .c o 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  w  w w .  j ava 2  s.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);
    }

}

From source file:org.openmicroscopy.shoola.util.ui.filechooser.FileChooser.java

/** Closes the window and disposes. */
void cancelSelection() {
    firePropertyChange(CANCEL_SELECTION_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true));
    option = JFileChooser.CANCEL_OPTION;
    setVisible(false);/*from   www.ja va2  s  .  co  m*/
    dispose();
}

From source file:org.richie.codeGen.ui.configui.ConstantConfigWin.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == addLineBtn) {
        ConstantConfigVo vo = new ConstantConfigVo();
        constantConfigModel.addRow(vo);/* w ww  .  ja va  2 s .c  o  m*/
        table.updateUI();
    } else if (e.getSource() == saveBtn) {
        onSave();
    } else if (e.getSource() == chooseBtn1 || e.getSource() == chooseBtn2 || e.getSource() == chooseBtn3
            || e.getSource() == chooseBtn4) {
        JFileChooser jfc = new JFileChooser();// 
        if (e.getSource() == chooseBtn1) {
            jfc.setCurrentDirectory(new File(rootPathValue1.getText()));
        } else if (e.getSource() == chooseBtn2) {
            jfc.setCurrentDirectory(new File(rootPathValue2.getText()));
        } else if (e.getSource() == chooseBtn3) {
            jfc.setCurrentDirectory(new File(rootPathValue3.getText()));
        } else if (e.getSource() == chooseBtn4) {
            jfc.setCurrentDirectory(new File(rootPathValue4.getText()));
        }
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);// ?
        int status = jfc.showOpenDialog(this);
        if (status == JFileChooser.CANCEL_OPTION) {
            return;
        } else {
            File file = jfc.getSelectedFile();
            if (e.getSource() == chooseBtn1) {
                rootPathValue1.setText(file.getAbsolutePath());
            } else if (e.getSource() == chooseBtn2) {
                rootPathValue2.setText(file.getAbsolutePath());
            } else if (e.getSource() == chooseBtn3) {
                rootPathValue3.setText(file.getAbsolutePath());
            } else if (e.getSource() == chooseBtn4) {
                rootPathValue4.setText(file.getAbsolutePath());
            }
        }
    }

}

From source file:org.ut.biolab.medsavant.client.view.dialog.SavantExportForm.java

private void chooseFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseFileButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Save Savant Project");
    fc.setDialogType(JFileChooser.SAVE_DIALOG);
    fc.addChoosableFileFilter(new ExtensionsFileFilter(new String[] { "svp" }));
    fc.setMultiSelectionEnabled(false);//from ww w  .j av a2s .  c o  m

    int result = fc.showDialog(null, null);
    if (result == JFileChooser.CANCEL_OPTION || result == JFileChooser.ERROR_OPTION) {
        return;
    }

    outputFile = fc.getSelectedFile();
    String path = outputFile.getAbsolutePath();
    outputFileField.setText(path);
    exportButton.setEnabled(true);
}

From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java

/**
 * Saves input vectors tab//w  w w.  j  ava2 s.c  om
 * @param scannerParam void `
 */
protected void saveScannerParam(ScannerParam scannerParam) {

    JFileChooser chooser = new JFileChooser(Constant.getPoliciesDir());
    File file = new File(Constant.getZapHome(), "Input Vectors.ser");
    chooser.setSelectedFile(file);

    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".ser")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            return Constant.messages.getString("customFire.custom.file.format.csp.ser");
        }
    });
    int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return;
        }
        try {

            FileOutputStream fos = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(scannerParam);
            oos.close();
            fos.close();
            View.getSingleton()
                    .showMessageDialog(Constant.messages.getString("customFire.custom.ser.saveIV.success"));

        } catch (IOException e1) {
            View.getSingleton()
                    .showWarningDialog(Constant.messages.getString("customFire.custom.ser.saveIV.error"));
            return;
        }
    }
    if (rc == JFileChooser.CANCEL_OPTION) {
        chooser.setVisible(false);
        return;
    }
}