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:com.stanley.captioner.MainFrame.java

private void addButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed
{//GEN-HEADEREND:event_addButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(true);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("MP4 VIDEOS", "mp4", "mpeg");
    fileChooser.setFileFilter(filter);/*from www .  j  a  v a  2s.c  o m*/
    if (lastAddDirectory != null) {
        fileChooser.setCurrentDirectory(lastAddDirectory);
    }
    int returnValue = fileChooser.showOpenDialog(this);

    if (returnValue == JFileChooser.APPROVE_OPTION) {
        lastAddDirectory = fileChooser.getCurrentDirectory();

        DefaultTableModel model = (DefaultTableModel) videoTable.getModel();
        File files[] = fileChooser.getSelectedFiles();
        for (File file : files) {
            boolean alreadyExists = false;
            for (int i = model.getRowCount() - 1; i >= 0; i--) {
                String path = (String) model.getValueAt(i, 0);
                if (file.getAbsolutePath().equals(path)) {
                    alreadyExists = true;
                }
            }

            if (!alreadyExists) {
                model.addRow(getVideoInfo(file));
            }
        }
    }
}

From source file:de.stefanwndelmann.zy1270logger.ZY1270LoggerMain.java

private void saveCSVButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCSVButtonActionPerformed
    // TODO add your handling code here:
    String data = getCSVData();// w ww  . j  a  va2  s  .  c  o  m
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv"));
    int retrival = chooser.showSaveDialog(null);
    if (retrival == JFileChooser.APPROVE_OPTION) {
        try (FileWriter fw = new FileWriter(chooser.getSelectedFile() + ".csv")) {
            fw.write(data);
        } catch (IOException ex) {
            Logger.getLogger(ZY1270LoggerMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:com.stacksync.desktop.util.FileUtil.java

private static File showBrowseDialogDefault(int jFileChooserFileSelectionMode) {
    JFileChooser fc = new JFileChooser();

    fc.setFileSelectionMode(jFileChooserFileSelectionMode);

    if (fc.showDialog(null, "Select") != JFileChooser.APPROVE_OPTION) {
        return null;
    }//from w  ww.ja  v a 2  s  .  c  o  m

    return fc.getSelectedFile();
}

From source file:id.co.nlp.MachineTranslationAPP.FormTraining.java

private void IndButtonCorpusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IndButtonCorpusActionPerformed
    if (this.fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {//from   ww  w  .j  a va2  s. c  o m
            this.targetFile = this.fileChooser.getSelectedFile().getCanonicalPath();
            this.indCorpusTextField.setText(this.targetFile);
        } catch (IOException ex) {
            Logger.getLogger(FormTraining.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.webcrawler.WebCrawlerMain.java

private void btnBrowseDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseDirActionPerformed

    fileChooser.setVisible(true);/*from  w w w .  j a v a  2 s. c om*/
    int returnVal = fileChooser.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        txtFldChooseDir.setText(fileChooser.getSelectedFile().getAbsolutePath());
    }

}

From source file:IHM.FenetreAjoutPhoto.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    JFileChooser chooser = new JFileChooser(new File("."));

    chooser.setDialogTitle("ouvrir une image");

    int reponse = chooser.showOpenDialog(this);

    if (reponse == JFileChooser.APPROVE_OPTION) {

        InputStream input = null;

        f = chooser.getSelectedFile();/*  w ww. j a v  a  2s .  c  o m*/

        nomPhoto = f.getName();
        nomF = f.getAbsolutePath();

        txtNomPhoto.setText(nomPhoto);

    }

}

From source file:net.sf.mzmine.chartbasics.graphicsexport.GraphicsExportDialog.java

/**
 * choose a path by file chooser/*ww  w.  j a  v  a 2s.c o m*/
 */
protected void choosePath() {
    // open filechooser
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        //
        StringComponent txtPath = (StringComponent) parametersAndComponents
                .get(GraphicsExportParameters.path.getName());
        StringComponent txtName = (StringComponent) parametersAndComponents
                .get(GraphicsExportParameters.filename.getName());
        ComboComponent<String> format = (ComboComponent<String>) parametersAndComponents
                .get(GraphicsExportParameters.exportFormat.getName());
        // only a folder? or also a file name > then split
        if (file.isDirectory()) {
            // only a folder
            txtPath.setText(file.getAbsolutePath());
        } else {
            // data file selected
            // get folder
            txtPath.setText(FileAndPathUtil.getFolderOfFile(file).getAbsolutePath());
            // get filename
            txtName.setText(FileAndPathUtil.getFileNameFromPath(file));
            // get format without .
            String f = FileAndPathUtil.getFormat(file).toUpperCase();
            format.setSelectedItem(f);
        }
    }
}

From source file:archive_v1.Archive_Form.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    CreateConnection();/*from w w w  .  j a va 2  s.c  o  m*/
    JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int a = jfc.showOpenDialog(this);
    if (a == JFileChooser.APPROVE_OPTION) {
        File file = jfc.getSelectedFile();
        try {
            // What to do with the file, e.g. display it in a TextArea
            System.out.println(file.getAbsolutePath());
        } catch (Exception ex) {
            System.out.println("problem accessing file" + file.getAbsolutePath());
        }
        File[] folder = new File(file.getAbsolutePath()).listFiles();
        for (File vid : folder) {
            filename = vid.getName();
            size = getFileSize(file.getAbsolutePath() + "\\" + filename);
            tape_id = generateTapeId();
            insertArchive(filename, size, tape_id, username);

        }
    } else {
        System.out.println("File access cancelled by user.");
    }
}

From source file:com.qawaa.gui.EventWebScanGUI.java

/**
 * ??/*from   w w  w. ja v  a 2s. co  m*/
 */
private static void setConsoleRight() {
    consoleRight = new JPopupMenu();
    consoleRight.setBorderPainted(true);
    consoleRight.setPopupSize(new Dimension(105, 135));
    JMenuItem clear = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.clear", null, Locale.CHINA),
            KeyEvent.VK_L);
    JMenuItem copy = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.copy", null, Locale.CHINA),
            KeyEvent.VK_C);
    JMenuItem cut = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.cut", null, Locale.CHINA),
            KeyEvent.VK_X);
    JMenuItem font = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.font", null, Locale.CHINA),
            KeyEvent.VK_F);
    JMenuItem choose = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.choose", null, Locale.CHINA),
            KeyEvent.VK_O);
    JMenuItem saveas = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.saveas", null, Locale.CHINA),
            KeyEvent.VK_S);
    consoleRight.add(clear);
    consoleRight.add(copy);
    consoleRight.add(cut);
    consoleRight.add(font);
    consoleRight.add(choose);
    consoleRight.add(saveas);
    clear.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            consolePane.setText("");
            jConsole.clear();
        }
    });
    copy.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) {
                Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                Transferable tText = new StringSelection(consolePane.getText());
                clip.setContents(tText, null);
            }

        }
    });
    cut.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) {
                Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                Transferable tText = new StringSelection(consolePane.getText());
                clip.setContents(tText, null);
            }
            consolePane.setText("");
            jConsole.clear();
        }
    });
    saveas.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            int option = fileChooser.showSaveDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                try {
                    if (file.exists() == false) {
                        file.createNewFile();
                    }
                    FileWriter writer = new FileWriter(file);
                    char[] arry = consolePane.getText().toCharArray();
                    writer.write(arry);
                    writer.flush();
                    writer.close();
                    LOG.info(CONTEXT.getMessage("gobal.right.menu.saveas.success", null, Locale.CHINA));
                } catch (IOException ioe) {
                }
            }
        }
    });
}

From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java

public void actionPerformed(ActionEvent e) {

    String cmd = e.getActionCommand();
    if (cmd.equals("Get")) {

        if (lstHybris.getSelectedIndex() >= 0) {
            try {
                System.out.println("Retrieving " + lstHybris.getSelectedValue() + "...");
                byte[] retrieved = cm.hybris.get(lstHybris.getSelectedValue());
                if (retrieved != null) {
                    JFileChooser fc = new JFileChooser(
                            System.getProperty("user.home") + File.separator + "Desktop");
                    fc.setSelectedFile(new File("RETRIEVED_" + lstHybris.getSelectedValue()));
                    int returnVal = fc.showSaveDialog(frame);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        FileUtils.writeByteArrayToFile(file, retrieved);
                        System.out.println("Saved: " + file.getName() + ".");
                    }//from   ww  w .  j ava2s .  c  o  m
                } else
                    JOptionPane.showMessageDialog(frame, "Hybris could not download the file.", "Error",
                            JOptionPane.ERROR_MESSAGE);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

    }
    if (cmd.equals("Put")) {

        JFileChooser fc = new JFileChooser(System.getProperty("user.home") + File.separator + "Desktop");
        int returnVal = fc.showOpenDialog(frame);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            System.out.println("Putting: " + file.getName() + ".");
            byte[] array;
            try {
                array = FileUtils.readFileToByteArray(file);
                new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.HYBRIS, file.getName(), array))
                        .start();
            } catch (Exception e1) {
                e1.printStackTrace();
            }

        }

    }
    if (cmd.equals("Delete")) {

        if (lstHybris.getSelectedIndex() >= 0) {
            new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS,
                    lstHybris.getSelectedValue(), null)).start();
            System.out.println("Removed " + lstHybris.getSelectedValue() + " from Hybris.");
        }
    }
}