Example usage for javax.swing JFileChooser APPROVE_OPTION

List of usage examples for javax.swing JFileChooser APPROVE_OPTION

Introduction

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

Prototype

int APPROVE_OPTION

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

Click Source Link

Document

Return value if approve (yes, ok) is chosen.

Usage

From source file:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java

protected JPanel buildFileSelectionSubPanel() {
    final JPanel panel = new JPanel();

    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(Box.createVerticalGlue());

    JButton openButton = new JButton(resourceBundle.getString("Select_file"));
    openButton.setMnemonic('O');
    openButton.setToolTipText(resourceBundle.getString("ToolTip.Select_file"));
    panel.add(openButton);/*from  w w  w  .  j a  v  a  2 s  .  c o m*/
    panel.add(Box.createRigidArea(new Dimension(10, 10)));

    JLabel fileLabel = new ABIFileLabel();
    panel.add(fileLabel);

    // Open button listener.
    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int returnVal = fileChooser.showOpenDialog(appWindow);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                abiFile = fileChooser.getSelectedFile();
                panel.repaint();
                saveButton.setEnabled(true);
            }
        }
    });

    panel.setAlignmentX(Component.LEFT_ALIGNMENT);

    return panel;
}

From source file:com.smart.aqimonitor.client.AqiSettingDialog.java

/**
 * Create the dialog.//from   w ww.j  a va  2 s.  c  o m
 */
public AqiSettingDialog(Frame owner, final AbstractAqiParser aqiParser) {
    super(owner);
    this.aqiParser = aqiParser;
    setTitle("\u8BBE\u7F6E");
    setResizable(false);
    setBounds(100, 100, 450, 135);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    GridBagLayout gbl_contentPanel = new GridBagLayout();
    gbl_contentPanel.columnWidths = new int[] { 33, 48, 66, 41, 48, 66, 0, 0 };
    gbl_contentPanel.rowHeights = new int[] { 21, 0, 0 };
    gbl_contentPanel.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_contentPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    contentPanel.setLayout(gbl_contentPanel);
    {
        JLabel lblRetryTimes = new JLabel("\u91CD\u8BD5\u6B21\u6570\uFF1A");
        GridBagConstraints gbc_lblRetryTimes = new GridBagConstraints();
        gbc_lblRetryTimes.anchor = GridBagConstraints.WEST;
        gbc_lblRetryTimes.insets = new Insets(0, 0, 5, 5);
        gbc_lblRetryTimes.gridx = 1;
        gbc_lblRetryTimes.gridy = 0;
        contentPanel.add(lblRetryTimes, gbc_lblRetryTimes);
    }
    {
        tfRetryTimes = new JTextField();
        tfRetryTimes.setPreferredSize(new Dimension(6, 29));
        tfRetryTimes.setMinimumSize(new Dimension(60, 29));
        GridBagConstraints gbc_tfRetryTimes = new GridBagConstraints();
        gbc_tfRetryTimes.anchor = GridBagConstraints.NORTHWEST;
        gbc_tfRetryTimes.insets = new Insets(0, 0, 5, 5);
        gbc_tfRetryTimes.gridx = 2;
        gbc_tfRetryTimes.gridy = 0;
        contentPanel.add(tfRetryTimes, gbc_tfRetryTimes);
        tfRetryTimes.setColumns(10);
    }
    {
        JLabel lblRetryGap = new JLabel("\u91CD\u8BD5\u95F4\u9694\uFF1A");
        GridBagConstraints gbc_lblRetryGap = new GridBagConstraints();
        gbc_lblRetryGap.anchor = GridBagConstraints.WEST;
        gbc_lblRetryGap.insets = new Insets(0, 0, 5, 5);
        gbc_lblRetryGap.gridx = 4;
        gbc_lblRetryGap.gridy = 0;
        contentPanel.add(lblRetryGap, gbc_lblRetryGap);
    }
    {
        tfRetryGap = new JTextField();
        tfRetryGap.setMinimumSize(new Dimension(60, 29));
        tfRetryGap.setPreferredSize(new Dimension(60, 29));
        GridBagConstraints gbc_tfRetryGap = new GridBagConstraints();
        gbc_tfRetryGap.insets = new Insets(0, 0, 5, 5);
        gbc_tfRetryGap.anchor = GridBagConstraints.NORTHWEST;
        gbc_tfRetryGap.gridx = 5;
        gbc_tfRetryGap.gridy = 0;
        contentPanel.add(tfRetryGap, gbc_tfRetryGap);
        tfRetryGap.setColumns(10);
    }
    {
        JLabel label = new JLabel("\u5206\u949F");
        GridBagConstraints gbc_label = new GridBagConstraints();
        gbc_label.insets = new Insets(0, 0, 5, 0);
        gbc_label.gridx = 6;
        gbc_label.gridy = 0;
        contentPanel.add(label, gbc_label);
    }
    {
        JLabel lblExportPath = new JLabel("\u8F93\u51FA\u8DEF\u5F84\uFF1A");
        GridBagConstraints gbc_lblExportPath = new GridBagConstraints();
        gbc_lblExportPath.anchor = GridBagConstraints.EAST;
        gbc_lblExportPath.insets = new Insets(0, 0, 0, 5);
        gbc_lblExportPath.gridx = 1;
        gbc_lblExportPath.gridy = 1;
        contentPanel.add(lblExportPath, gbc_lblExportPath);
    }
    {
        tfExportPath = new JTextField();
        tfExportPath.setEditable(false);
        tfExportPath.setPreferredSize(new Dimension(180, 29));
        tfExportPath.setMinimumSize(new Dimension(180, 29));
        GridBagConstraints gbc_tfExportPath = new GridBagConstraints();
        gbc_tfExportPath.gridwidth = 4;
        gbc_tfExportPath.insets = new Insets(0, 0, 0, 5);
        gbc_tfExportPath.fill = GridBagConstraints.HORIZONTAL;
        gbc_tfExportPath.gridx = 2;
        gbc_tfExportPath.gridy = 1;
        contentPanel.add(tfExportPath, gbc_tfExportPath);
        tfExportPath.setColumns(10);
    }
    {
        JButton button = new JButton("...");
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                fDialog = new JFileChooser(); // 
                fDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                int result = fDialog.showOpenDialog(contentPanel);
                if (result == JFileChooser.APPROVE_OPTION) {
                    tfExportPath.setText(fDialog.getSelectedFile().getAbsolutePath());
                }
            }
        });
        GridBagConstraints gbc_button = new GridBagConstraints();
        gbc_button.gridx = 6;
        gbc_button.gridy = 1;
        contentPanel.add(button, gbc_button);
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("\u786E\u5B9A");
            okButton.setName("settingOk");
            okButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {

                    String retryTimes = tfRetryTimes.getText();
                    if (StringUtils.isEmpty(retryTimes) || !isNumeric(retryTimes)) {
                        JOptionPane.showMessageDialog(contentPanel, "", "",
                                JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                    String retryGap = tfRetryGap.getText();
                    if (StringUtils.isEmpty(retryGap) || !isNumeric(retryGap)) {
                        JOptionPane.showMessageDialog(contentPanel, "", "",
                                JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                    String exportPath = tfExportPath.getText();
                    if (StringUtils.isEmpty(exportPath)) {
                        JOptionPane.showMessageDialog(contentPanel, "", "",
                                JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    File testFile = new File(exportPath);
                    if (!testFile.exists()) {
                        JOptionPane.showMessageDialog(contentPanel, "", "",
                                JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                    props.put("query.retryTimes", retryTimes);
                    props.put("query.retryGap", retryGap);
                    props.put("result.path", exportPath);

                    try {
                        props.store(new FileOutputStream(propertiesResource.getFile()), "");
                        aqiParser.setRetryTimes(Integer.parseInt(retryTimes));
                        aqiParser.setRetryGap(Integer.parseInt(retryGap));
                        aqiParser.setFilePath(exportPath);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    } finally {
                        dispose();
                    }
                }
            });
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("\u53D6\u6D88");
            cancelButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    dispose();
                }
            });
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }
}

From source file:com.strath.view.MainGUI.java

private void projectSelectMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_projectSelectMouseReleased
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    int returnValue = chooser.showOpenDialog(null);
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        File directory = chooser.getSelectedFile();
        String[] extensions = new String[1];
        extensions[0] = "java";
        selectedProject = listFiles(directory, extensions, true);
        isProjectSet = true;/*from   ww w  . ja va 2s.c o m*/
    }
}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createDataConversionRulesList() {
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(labels.getString("dateConversion.valueRead"));
    columnNames.add(labels.getString("dateConversion.valueConverted"));
    dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);
    dm.addRow(new Vector<String>());
    dm.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1
                    && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                            && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) {
                dm.removeRow(ruleTable.getEditingRow());
            }//  w  w w.  jav a  2 s.  c  o  m
            if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                        && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    dm.addRow(new Vector<String>());
                }
            }
            if (ruleTable.getEditingColumn() == 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))
                        && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1);
                }
            }
        }
    });

    ruleTable = new JTable(dm);
    oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);

    JButton saveButton = new JButton(labels.getString("saveBtn"));
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            for (int i = 0; i < data.size() - 1; i++) {
                Vector<String> vector = data.elementAt(i);
                if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) {
                    createOptionPaneForIsoDate(i, 1);
                }
            }
            xmlFilehandler.saveDataToFile(data, FILENAME);
            saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                    new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
        }
    });

    JButton closeButton = new JButton(labels.getString("quit"));
    closeButton.addActionListener(new ActionListener() {
        // boolean cancel = true;

        public void actionPerformed(ActionEvent e) {
            /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1));
            if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) {
            cancel = showUnsavedChangesDialog();
            } else {
            for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) {
                for (int j = 0; j <= 1; j++) {
                    System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j));
                    if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) {
                        cancel = showUnsavedChangesDialog();
                    }
                }
            }
            }
            if (cancel) {*/
            dispose();
            //  }
        }
    });

    JButton downloadButton = new JButton(labels.getString("downloadBtn"));
    downloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            File currentLocation = new File(retrieveFromDb.retrieveOpenLocation());
            JFileChooser fileChooser = new JFileChooser(currentLocation);
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
            fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml"));
            int returnedVal = fileChooser.showSaveDialog(getParent());

            if (returnedVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fileChooser.getSelectedFile().toString();
                if (!fileName.endsWith(".xml")) {
                    fileName = fileName + ".xml";
                }
                xmlFilehandler.saveDataToFile(data, fileName);
                //additionally save data to standard file
                xmlFilehandler.saveDataToFile(data, FILENAME);
                saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                        new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
            }
        }
    });

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(new JScrollPane(ruleTable));
    saveMessage = new JLabel();
    contentPanel.add(saveMessage, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(saveButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(downloadButton);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(contentPanel, BorderLayout.PAGE_START);
    pane.add(buttonPanel, BorderLayout.PAGE_END);
    add(pane);
}

From source file:com.akman.excel.view.frmSelectImage.java

private void btnSelectImageActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSelectImageActionPerformed
{//GEN-HEADEREND:event_btnSelectImageActionPerformed
    JFileChooser chooser = new JFileChooser();

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "png", "gif", "bmp");
    chooser.setFileFilter(filter);/*from  ww w  .  j  a  va2s  .  com*/

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogTitle("Select The Image");
    chooser.setMultiSelectionEnabled(false);
    int res = chooser.showOpenDialog(null);
    if (res == JFileChooser.APPROVE_OPTION) {

        //Saving file inside the file
        File file = chooser.getSelectedFile();

        //        if(!file.equals(filter))
        //        {
        //        JOptionPane.showMessageDialog(null, "Wrong File Selected","ERROR",JOptionPane.ERROR_MESSAGE);
        //        return;
        //        }

        //System.out.println(file.getAbsolutePath());
        ImageIcon image = new ImageIcon(file.getAbsolutePath());

        fileName = file.getAbsolutePath();

        // Get Width And Height of PicLabel
        Rectangle rect = lblImage.getBounds();

        //System.out.println(lblImage.getBounds());
        //Scaling the image to fit in the picLabel
        Image scaledimage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT);
        //converting the image back to image icon to make an acceptable picLabel
        image = new ImageIcon(scaledimage);

        lblImage.setIcon(image);

        txtPath.setText(fileName);

        try {

            File images = new File(fileName);

            FileInputStream fis = new FileInputStream(images);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();

            byte[] buf = new byte[1024];

            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);
            }

            person_image = bos.toByteArray();

        } catch (Exception e) {

            JOptionPane.showMessageDialog(null, e);
        }

    }
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveTSV() {
    JFileChooser chooser = new JFileChooser("Save evaluation result as TSV");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame,
                "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) {
            return;
        }/*from ww w  .j ava  2 s  .co  m*/
        frame.saveTSV(chooser.getSelectedFile());
    }
}

From source file:rework.MainFrame.java

private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jMenuItem1MousePressed
{//GEN-HEADEREND:event_jMenuItem1MousePressed
 // TODO add your handling code here:
    int open = fileChooser.showOpenDialog(this);
    if (open == JFileChooser.APPROVE_OPTION) {
        System.out.print(fileChooser.getSelectedFile().getAbsolutePath());
        try {//from   ww w .j av  a2 s .c om
            csv = new CSVtoObject(fileChooser.getSelectedFile().getAbsolutePath(), datalist);
        } catch (IOException | ParseException ex) {
            Logger.getLogger(mainActivity.class.getName()).log(Level.SEVERE, null, ex);
        }
        //System.out.print(dataList);
    } else {
        System.out.print("FAILURE");
    }
}

From source file:com.neurotec.samples.panels.EnrollFromScanner.java

private void saveImage() throws IOException {
    if (subject != null) {
        if (oldImageFile != null) {
            fcImage.setSelectedFile(oldImageFile);
        }/*from  ww  w . j a  v a 2 s  .  c  o  m*/
        if (fcImage.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            oldImageFile = fcImage.getSelectedFile();
            if (cbShowProcessed.isSelected()) {
                subject.getFingers().get(0).getProcessedImage()
                        .save(fcImage.getSelectedFile().getAbsolutePath());
            } else {
                subject.getFingers().get(0).getImage().save(fcImage.getSelectedFile().getAbsolutePath());
            }
        }
    }
}

From source file:com.view.Main.java

private void filePathBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filePathBrowseButtonActionPerformed
    final JFileChooser fileChooser = new JFileChooser(".");
    final FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel files", "xlsx", "xls");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);/*from   www .j a v  a 2s.c om*/
    int result = fileChooser.showDialog(this, "choose a file");
    if (result == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        filePathTextField.setText(selectedFile.getAbsolutePath());
    }

}

From source file:com.sf.energy.transfer.form.DataConfiguration.java

/**
 * ??//from  www .  j av  a  2  s.co m
 * @param evt ?
 */
private void scanActionPerformed(java.awt.event.ActionEvent evt) {
    JFileChooser fc = new JFileChooser();
    File directory = new File(dir);
    // ??
    fc.setCurrentDirectory(directory);
    fc.setDialogTitle("");
    // 
    FileNameExtensionFilter filter1 = new FileNameExtensionFilter(".xls", "xls");
    fc.addChoosableFileFilter(filter1);
    FileNameExtensionFilter filter2 = new FileNameExtensionFilter(".dmp", "dmp");
    fc.addChoosableFileFilter(filter1);
    // 
    fc.setFileFilter(fc.getAcceptAllFileFilter());
    int intRetVal = fc.showOpenDialog(new JFrame());
    // ?
    if (intRetVal == JFileChooser.APPROVE_OPTION) {
        // ?
        dir = fc.getSelectedFile().getPath();
        // 
        filePath.setText(dir);
    }

}