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:id.co.nlp.MachineTranslationAPP.FormTraining.java

private void englishCorpusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_englishCorpusButtonActionPerformed
    this.fileChooser.setFileFilter(new FileOpenFilter("txt", "Data Latih BP"));
    if (this.fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {/* w w w  .  j a  v a2  s. c om*/
            this.sourceFile = this.fileChooser.getSelectedFile().getCanonicalPath();
            this.englishCorpusTextField.setText(this.sourceFile);
        } catch (IOException ex) {
            Logger.getLogger(FormTraining.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:net.sf.profiler4j.console.Console.java

/**
 * Saves the current project.//from   w w w  .  j  a v a  2 s .c o m
 * 
 * @param saveAs force the user to select a file name even
 * @return <code>true</code> if the user has cancelled (only in the case of save as)
 */
public boolean saveProject(boolean saveAs) {
    if (project.getFile() == null || saveAs) {
        JFileChooser fc = new JFileChooser(lastDir);

        fc.setDialogTitle("Save Project As");

        fc.addChoosableFileFilter(projectFilter);
        if (fc.showSaveDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
            File f = fc.getSelectedFile();
            if (!f.getName().endsWith(".p4j")) {
                f = new File(f.getAbsolutePath() + ".p4j");
            }
            project.setFile(f);
        } else {
            return true;
        }
    }

    Element rootEl = new Element("Profiler4jProject");
    Document doc = new Document(rootEl);

    rootEl.addContent(new Element("Host").setText(project.getHostname()));
    rootEl.addContent(new Element("Port").setText(String.valueOf(project.getPort())));

    Element rulesEl = new Element("Rules");
    rootEl.addContent(rulesEl);

    rulesEl.setAttribute("access", project.getAccess().name());
    rulesEl.setAttribute("beanProps", String.valueOf(project.isBeanprops()));

    for (Rule rule : project.getRules()) {
        rulesEl.addContent(
                new Element("Rule").setText(rule.getPattern()).setAttribute("action", rule.getAction().name()));
    }

    Element exportPatternEl = new Element(PROJECT_XML_ELEMENT__EXPORT_PATTERN);
    String enabled = String.valueOf(project.isExportAutomaticallyEnabled());
    exportPatternEl.setAttribute(PROJECT_XML_ATTRIBUTE__ENABLED, enabled);
    exportPatternEl.setAttribute(PROJECT_XML_ATTRIBUTE__PATTERN, project.getExportPattern());
    rootEl.addContent(exportPatternEl);

    try {
        FileWriter fw = new FileWriter(project.getFile());
        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        outputter.output(doc, fw);
        fw.close();
        project.clearChanged();
    } catch (IOException e) {
        error("I/O Error", e);
    }
    return false;
}

From source file:ca.uhn.hl7v2.testpanel.controller.Controller.java

public void chooseAndLoadConformanceProfileForMessage(Hl7V2MessageCollection theMessage,
        IOkCancelCallback<Void> theCallback) {
    if (myConformanceProfileFileChooser == null) {
        myConformanceProfileFileChooser = new JFileChooser(Prefs.getInstance().getOpenPathConformanceProfile());
        myConformanceProfileFileChooser.setDialogTitle("Choose an HL7 Conformance Profile");

        ExtensionFilter type = new ExtensionFilter("XML Files", new String[] { ".xml" });
        myConformanceProfileFileChooser.addChoosableFileFilter(type);
    }/*from  www.j a va  2 s.c o m*/

    int value = myConformanceProfileFileChooser.showOpenDialog(myView.getFrame());
    if (value == JFileChooser.APPROVE_OPTION) {

        File file = myConformanceProfileFileChooser.getSelectedFile();
        Prefs.getInstance().setOpenPathConformanceProfile(file.getPath());

        try {
            String profileString = FileUtils.readFile(file);
            theMessage.setRuntimeProfile(ProfileGroup.createFromRuntimeProfile(profileString));

            theCallback.ok(null);

        } catch (IOException e) {
            ourLog.error("Failed to load profile", e);
            theCallback.cancel(null);
        } catch (ProfileException e) {
            ourLog.error("Failed to load profile", e);
            theCallback.cancel(null);
        }
    } else {
        theCallback.cancel(null);
    }

}

From source file:com.civprod.writerstoolbox.OpenNLP.training.WordSplitingTokenizerTrainer.java

private void cmdLoadAbbreviationDictionaryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdLoadAbbreviationDictionaryActionPerformed
    final WordSplitingTokenizerTrainer tempThis = this;
    new Thread(() -> {
        tempThis.setVisible(false);/*www . ja  v  a2 s. co  m*/
        int returnval = myFileChooser.showOpenDialog(tempThis);
        if (returnval == JFileChooser.APPROVE_OPTION) {
            final File selectedFile = myFileChooser.getSelectedFile();
            InputStream DictionaryInputStream = null;
            try {
                DictionaryInputStream = new java.io.BufferedInputStream(new FileInputStream(selectedFile));
                mAbbreviationDictionary = new Dictionary(DictionaryInputStream);
            } catch (IOException ex) {
                Logger.getLogger(DictionaryEditor.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if (DictionaryInputStream != null) {
                    try {
                        DictionaryInputStream.close();
                    } catch (IOException ex) {
                        Logger.getLogger(DictionaryEditor.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
        tempThis.setVisible(true);
    }).start();
}

From source file:networkanalyzer.NetworkAnalyzer.java

private void browseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browseMouseClicked
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle("Browse the folder to process");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setAcceptAllFileFilterUsed(true);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        String fileName = chooser.getSelectedFile().toString();
        saveLoc.setText(fileName);/*from w  w  w .  j a  v  a2s . c om*/
    }

}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public SpinCADBank fileOpenBank() {
    loadRecentBankFileList();/* w ww  . j  a  v  a 2  s.c  om*/
    SpinCADBank b = null;
    File file = null;

    final String newline = "\n";
    // In response to a button click:
    FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Bank Files", "spbk");
    fc.setFileFilter(filter);
    fc.setAccessory(recentBankFileList);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int returnVal = fc.showOpenDialog(new JFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = fc.getSelectedFile();
        // This is where a real application would open the file.
        System.out.println("Opening: " + file.getName() + "." + newline);
        try {
            // first, open bank, then open patch 0
            b = fileReadBank(file);
        } catch (Exception e) { // thrown over in SpinCADFile.java
            e.printStackTrace();
            //            MessageBox("File open failed!", "This spbk file may be from\nan incompatible version of \nSpinCAD Designer.");
        }
    } else {
        System.out.println("Open command cancelled by user." + newline);
    }
    String filePath = file.getPath();
    String fileName = file.getName();
    saveMRUBankFolder(filePath);
    recentBankFileList.add(file);
    // XXX debug looks like we kinda have the same info in 2 places
    b.bankFileName = fileName;
    b.cb.setFileName(fileName);
    b.changed = false;
    saveRecentBankFileList();
    return b;
}

From source file:com.jvms.i18neditor.editor.Editor.java

public void showCreateProjectDialog(ResourceType type) {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(MessageBundle.get("dialogs.project.new.title"));
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int result = fc.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        createProject(Paths.get(fc.getSelectedFile().getPath()), type);
    } else {/* w w  w .  j  a  va  2  s. co m*/
        updateHistory();
        updateUI();
    }
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showImportDialog() {
    String path = null;//w  w  w  . j a  v  a  2  s .c o  m
    if (resourcesDir != null) {
        path = resourcesDir.toString();
    }
    JFileChooser fc = new JFileChooser(path);
    fc.setDialogTitle(MessageBundle.get("dialogs.import.title"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(new FileNameExtensionFilter("json i18n file", "json"));
    int result = fc.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        importResources(Paths.get(fc.getSelectedFile().getPath()));
    }
}

From source file:com.dieterholvoet.scoutsapp.util.CSVParser.java

public void chooseFile() {
    int returnVal = chooser.showOpenDialog(this.parent);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selectedFile = chooser.getSelectedFile().getPath();

    } else if (returnVal != JFileChooser.CANCEL_OPTION) {
        JOptionPane.showMessageDialog(this.parent, "Invalid file!");
    }//  ww  w .  j a va  2  s . c o  m
}

From source file:com.socrata.datasync.ui.MetadataJobTab.java

public void saveJob() {
    populateJobFromFields();//  ww w.j  a  v a 2s .  c  o  m

    // TODO If an existing file was selected WARN user of overwriting

    // if first time saving this job: Open dialog box to select "Save as..." location
    // otherwise save to existing file
    boolean updateJobCommandTextField = false;
    String selectedJobFileLocation = jobFileLocation;
    if (selectedJobFileLocation.equals("")) {
        JFileChooser savedJobFileChooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter(
                JOB_FILE_NAME + " (*." + JOB_FILE_EXTENSION + ")", JOB_FILE_EXTENSION);
        savedJobFileChooser.setFileFilter(filter);
        int returnVal = savedJobFileChooser.showSaveDialog(mainFrame);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = savedJobFileChooser.getSelectedFile();
            selectedJobFileLocation = file.getAbsolutePath();
            if (!selectedJobFileLocation.endsWith("." + JOB_FILE_EXTENSION)) {
                selectedJobFileLocation += "." + JOB_FILE_EXTENSION;
            }
            jobFileLocation = selectedJobFileLocation;
            metadataJob.setPathToSavedFile(selectedJobFileLocation);
            jobTabTitleLabel.setText(metadataJob.getJobFilename());
            updateJobCommandTextField = true;
        }
    }
    // actually save the job file (may overwrite)
    try {
        metadataJob.writeToFile(selectedJobFileLocation);

        // Update job tab title label
        jobTabTitleLabel.setText(metadataJob.getJobFilename());

        // Update the textfield with new command
        if (updateJobCommandTextField) {
            String runJobCommand = Utils.getRunJobCommand(metadataJob.getPathToSavedFile());
            runCommandTextField.setText(runJobCommand);
        }
    } catch (IOException e) {
        JOptionPane.showMessageDialog(mainFrame,
                "Error saving " + selectedJobFileLocation + ": " + e.getMessage());
    }
}