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:MyViewChooser.java

public MyViewChooser() {
    super("File View Test Frame");
    setSize(350, 200);/*from ww w  .j a  v  a  2s .  c  o m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    parent = this;

    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();

            // Ok, set up our own file view for the chooser
            chooser.setFileView(new ThumbNailFileView(MyViewChooser.this));

            int option = chooser.showOpenDialog(parent);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You chose " + chooser.getSelectedFile().getName());
            } else {
                statusbar.setText("You cancelled.");
            }
        }
    });

    c.add(openButton);
    c.add(statusbar);
}

From source file:net.rptools.maptool.client.macro.impl.SaveAliasesMacro.java

public void execute(MacroContext context, String macro, MapToolMacroContext executionContext) {
    File aliasFile = null;/*from www . ja v a2 s. c o  m*/
    if (macro.length() > 0) {
        aliasFile = new File(macro);
    } else {
        JFileChooser chooser = MapTool.getFrame().getSaveFileChooser();
        chooser.setDialogTitle("savealiases.dialogTitle");
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        if (chooser.showOpenDialog(MapTool.getFrame()) != JFileChooser.APPROVE_OPTION) {
            return;
        }
        aliasFile = chooser.getSelectedFile();
    }
    if (aliasFile.getName().indexOf(".") < 0) {
        aliasFile = new File(aliasFile.getAbsolutePath() + ".alias");
    }
    if (aliasFile.exists() && !MapTool.confirm(I18N.getText("msg.confirm.fileExists"))) {
        return;
    }

    try {
        StringBuilder builder = new StringBuilder();
        builder.append("# ").append(I18N.getText("savealiases.created")).append(" ")
                .append(new SimpleDateFormat().format(new Date())).append("\n\n");

        Map<String, String> aliasMap = MacroManager.getAliasMap();
        List<String> aliasList = new ArrayList<String>();
        aliasList.addAll(aliasMap.keySet());
        Collections.sort(aliasList);
        for (String key : aliasList) {
            String value = aliasMap.get(key);
            builder.append(key).append(":").append(value).append("\n"); // LATER: this character should be externalized and shared with the load alias macro
        }
        FileUtils.writeByteArrayToFile(aliasFile, builder.toString().getBytes("UTF-8"));

        MapTool.addLocalMessage(I18N.getText("aliases.saved"));
    } catch (FileNotFoundException fnfe) {
        MapTool.addLocalMessage(
                I18N.getText("savealiases.couldNotSave", I18N.getText("msg.error.fileNotFound")));
    } catch (IOException ioe) {
        MapTool.addLocalMessage(I18N.getText("savealiases.couldNotSave", ioe));
    }
}

From source file:task5.Histogram.java

private void getImage() {
    String userDir = System.getProperty("user.home");
    JFileChooser fileChooser = new JFileChooser(userDir + "/Desktop");
    int result = fileChooser.showOpenDialog(null);
    if (result == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        try {//from   w w  w  .  j av a 2  s  . com
            img = ImageIO.read(selectedFile);
            myframe = get_MYIMAGE();
        } catch (IOException ex) {
            Logger.getLogger(MyImage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:it.unibas.spicygui.controllo.file.ActionCsvFileChooserSchema.java

public void actionPerformed(ActionEvent e) {
    executeInjection();//from  w  w w .j a v a2s.  com
    JFileChooser chooser = vista.getFileChooserApriCSV();
    File file;
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        //giannisk Add schema file path to previous ones
        csvConfigurationPM.addToSchemaPathList(file.getAbsolutePath());
    }
}

From source file:it.unibas.spicygui.controllo.preprocessing.ActionChangeDelimiter.java

@Override
public void performAction() {
    JFileChooser chooser = vista.getFileChooserApriCSV();
    File file;//from w w  w .j  a va 2  s  .  co m
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        //file extension
        String ext = file.getPath().substring(file.getPath().lastIndexOf(".") + 1);
        if (ext.equalsIgnoreCase("csv")) {
            ChangeDelimiterFrame frame = new ChangeDelimiterFrame();
            String sourceDelimiter = frame.getSourceDelimiter();
            String sourceQuotes = frame.getSourceQuotes();
            boolean useTargetQuotes = frame.getTargetQuotes();
            //                System.out.println(sourceDelimiter);
            //                System.out.println(sourceQuotes);
            //                System.out.println(useTargetQuotes);
            if (sourceDelimiter != null && sourceQuotes != null)
                try {
                    ChangeDelimiterCSV changer = new ChangeDelimiterCSV();
                    changer.changeDelimiter(file, sourceDelimiter, sourceQuotes, useTargetQuotes);
                    DialogDisplayer.getDefault()
                            .notify(new NotifyDescriptor.Message(
                                    NbBundle.getMessage(Costanti.class, Costanti.EXPORT_CHANGED_DELIMITER)
                                            + file.getParent()));
                } catch (IOException ex) {
                    DialogDisplayer.getDefault().notify(
                            new NotifyDescriptor.Message(ex.getMessage(), DialogDescriptor.ERROR_MESSAGE));
                }
        } else {
            DialogDisplayer.getDefault()
                    .notify(new NotifyDescriptor.Message(
                            NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_WRONG_FILE_INPUT) + ": \""
                                    + ext + "\"",
                            DialogDescriptor.ERROR_MESSAGE));
        }
    }
}

From source file:AccessoryFileChooser.java

public AccessoryFileChooser() {
    super("Accessory Test Frame");
    setSize(350, 200);/*from  w  ww .  jav a  2  s. co  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton accButton = new JButton("Accessory");
    statusbar = new JLabel("Output of your selection will go here");
    chooser = new JFileChooser();
    AudioAccessory aa = new AudioAccessory();
    chooser.setAccessory(aa);
    chooser.addPropertyChangeListener(aa); // to receive selection changes
    chooser.addActionListener(aa); // to receive approve/cancel button
    // events

    accButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int option = chooser.showOpenDialog(AccessoryFileChooser.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You chose "
                        + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName()
                                : "nothing"));
            } else {
                statusbar.setText("You canceled.");
            }
        }
    });
    c.add(accButton);
    c.add(statusbar);
}

From source file:eu.apenet.dpt.standalone.gui.XsltAdderActionListener.java

public void actionPerformed(ActionEvent e) {
    JFileChooser xsltChooser = new JFileChooser();
    xsltChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (xsltChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        File file = xsltChooser.getSelectedFile();
        if (isXSLT(file)) {
            if (saveXslt(file)) {
                JRadioButton newButton = new JRadioButton(file.getName());
                newButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI));
                dataPreparationToolGUI.getGroupXslt().add(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsltPanel(newButton);
                dataPreparationToolGUI.getAPEPanel().getApeTabbedPane()
                        .addToXsltPanel(Box.createRigidArea(new Dimension(0, 10)));
                JOptionPane.showMessageDialog(parent, labels.getString("xsltSaved") + ".",
                        labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon);
            } else {
                JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                        labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
            }/*from w  ww. j a v  a  2s  .  c  o  m*/
        } else {
            JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".",
                    labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon);
        }
    }
}

From source file:org.pgptool.gui.ui.tools.browsefs.ExistingFileChooserDialog.java

public String askUserForFile() {
    JFileChooser ofd = buildFileChooserDialog();

    int result = ofd.showOpenDialog(optionalParent);
    if (result != JFileChooser.APPROVE_OPTION) {
        return handleFileWasChosen(null);
    }// w w w .j av a 2  s  .  co m
    File retFile = ofd.getSelectedFile();
    if (retFile == null) {
        return handleFileWasChosen(null);
    }

    String ret = retFile.getAbsolutePath();
    ret = handleFileWasChosen(ret);
    configPairs.put(configPairNameToRemember, FilenameUtils.getFullPathNoEndSeparator(ret));
    return ret;
}

From source file:it.unibas.spicygui.controllo.file.ActionFileChooserSchema.java

public void actionPerformed(ActionEvent e) {
    executeInjection();//from   ww  w  . j  a  v  a2 s . c  o m

    JFileChooser chooser = vista.getFileChooserApriXSD();

    File file;
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        xmlConfigurationPM.setSchemaPath(file.getAbsolutePath());
    }
}

From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java

protected void browseDir(JTextField dirField) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = fileChooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        String selectedFilePath = selectedFile.getAbsolutePath();
        dirField.setText(selectedFilePath);
    }/*from w  ww .ja  v  a 2 s. c  om*/
}