Example usage for javax.swing JFileChooser showOpenDialog

List of usage examples for javax.swing JFileChooser showOpenDialog

Introduction

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

Prototype

public int showOpenDialog(Component parent) throws HeadlessException 

Source Link

Document

Pops up an "Open File" file chooser dialog.

Usage

From source file:it.unibas.spicygui.controllo.spicy.ActionLoadComaCorrespondences.java

@Override
public void performAction() {
    executeInjection();//from   ww w  .j  a  v a2 s.  co m
    Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
    MappingTask mappingTask = scenario.getMappingTask();
    if (mappingTask.getCandidateCorrespondences().size() != 0 && mappingTask.isToBeSaved()) {
        NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Confirmation(
                NbBundle.getMessage(Costanti.class, Costanti.DISCARD_CANDIDATE_CORRESPONDENCES),
                DialogDescriptor.YES_NO_OPTION);
        DialogDisplayer.getDefault().notify(notifyDescriptor);
        if (notifyDescriptor.getValue().equals(NotifyDescriptor.NO_OPTION)
                || notifyDescriptor.getValue().equals(NotifyDescriptor.CLOSED_OPTION)) {
            return;
        }
    }
    mappingTask.clearCandidateCorrespondences();

    JFileChooser chooser = vista.getFileChooserApriTXT();
    File file;
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            String absoluteFile = file.getPath();
            List<ValueCorrespondence> valueCorrespondences = dAOComaCorrespondences.loadComaCorrespondences(
                    absoluteFile, mappingTask.getSourceProxy().getDataSource(),
                    mappingTask.getTargetProxy().getDataSource());

            mappingTask.setCandidateCorrespondences(valueCorrespondences);

            SpicyTopComponent spicyTopComponent = scenario
                    .getSpicyTopComponent();/*SpicyTopComponent.findInstance();*/
            if (spicyTopComponent.getJLayeredPane().isAnalizzato()) {
                spicyTopComponent.drawConnections();
            } else {
                spicyTopComponent.drawScene();
            }
            spicyTopComponent.resetSlider();
            actionViewSpicy.performAction();
            spicyTopComponent.creaSlider();
            enableActions();
            IOProvider.getDefault().getIO(Costanti.FLUSSO_SPICY, false).select();
            if (logger.isDebugEnabled())
                logger.debug("--------------Candidate correspondences---------------");
            for (ValueCorrespondence correspondence : mappingTask.getCandidateCorrespondences()) {
                logger.info(correspondence);
            }
            return;

        } catch (DAOException ex) {
            DialogDisplayer.getDefault()
                    .notify(new NotifyDescriptor.Message(
                            NbBundle.getMessage(Costanti.class, Costanti.OPEN_ERROR) + " : " + ex.getMessage(),
                            DialogDescriptor.ERROR_MESSAGE));
            logger.error(ex);
        }
    }
}

From source file:com.floreantpos.bo.actions.DataImportAction.java

@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser fileChooser = DataExportAction.getFileChooser();
    int option = fileChooser.showOpenDialog(com.floreantpos.util.POSUtil.getBackOfficeWindow());
    if (option != JFileChooser.APPROVE_OPTION) {
        return;/* w w w.ja v a  2s  .c om*/
    }

    File file = fileChooser.getSelectedFile();
    try {

        importMenuItemsFromFile(file);
        POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(),
                Messages.getString("DataImportAction.1")); //$NON-NLS-1$

    } catch (Exception e1) {
        PosLog.error(getClass(), e1);

        POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), e1.getMessage());
    }

}

From source file:de.hstsoft.sdeep.view.MainWindow.java

private void openFileChooser() {

    final JFileChooser fileChooser = new JFileChooser(new File("."));
    int retVal = fileChooser.showOpenDialog(this);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        openFile(selectedFile);//from  w  w  w.  jav a2 s. com
    }

}

From source file:com.jtk.medicalrecord.view.panel.InputMedrecPemeriksaanpendukung.java

private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTambahActionPerformed
    if (view) {// ww  w  .ja  v a 2  s.c  om
        download();
    } else {
        JFileChooser fileChooser = new JFileChooser();
        int result = fileChooser.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION) {
            String url = fileChooser.getSelectedFile().getAbsolutePath();
            try {
                InputStream is = new FileInputStream(new File(url));
                String tipeFile = FilenameUtils.getExtension(url);
                String namaFile = FilenameUtils.getBaseName(url);

                PemeriksaanPendukung pp = new PemeriksaanPendukung();
                pp.setPemId(UUID.randomUUID().toString().replace("-", ""));
                pp.setPemNmFile(namaFile);
                pp.setPemTipeFile(tipeFile);
                pp.setPemFile(IOUtils.toByteArray(is));

                pemeriksaanPendukungs.add(pp);

                createTableValue();
            } catch (FileNotFoundException ex) {
                MessageHelper.addErrorMessage("Error add file", ex.getMessage());
                Logger.getLogger(InputMedrecPemeriksaanpendukung.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                MessageHelper.addErrorMessage("Error add file", ex.getMessage());
                Logger.getLogger(InputMedrecPemeriksaanpendukung.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

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

public void execute(MacroContext context, String macro, MapToolMacroContext executionContext) {
    File aliasFile = null;/*from   w ww  .  ja v a  2  s  .c om*/
    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:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java

protected void browseFile(JTextField dirField) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_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  . jav  a2s . c  o  m
}

From source file:org.pmedv.jake.commands.OpenPlayerViewCommand.java

@Override
public void execute() {

    final ApplicationContext ctx = AppContext.getApplicationContext();
    final ApplicationWindow win = (ApplicationWindow) ctx.getBean(BeanDirectory.WINDOW_APPLICATION);

    /**//from   w  w w  . j  a  v  a2  s.c o  m
     * Get last selected folder to simplify file browsing
     */

    if (AppContext.getLastSelectedFolder() == null)
        AppContext.setLastSelectedFolder(System.getProperty("user.home"));

    JFileChooser fc = new JFileChooser(AppContext.getLastSelectedFolder());
    fc.setDialogTitle("Open directory");
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    int result = fc.showOpenDialog(win);

    if (result == JFileChooser.CANCEL_OPTION)
        return;

    AppContext.setLastSelectedFolder(fc.getSelectedFile().getAbsolutePath());

    List<File> files = new ArrayList<File>();
    FileUtils.findFile(files, fc.getSelectedFile(), ".mp3", true, true);

    final PlayerController controller = new PlayerController(files);
    JakeUtil.updateRecentFiles(fc.getSelectedFile().getAbsolutePath());

    View view = new View(fc.getSelectedFile().getAbsolutePath(), null, controller.getPlayerView());

    view.addListener(new DockingWindowAdapter() {

        @Override
        public void windowClosing(DockingWindow arg0) throws OperationAbortedException {
            if (controller.getPlayer() != null)
                controller.getPlayer().close();
            controller.getPlayFileCommand().setPlaying(false);
        }

    });

    openEditor(view);
}

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);
    }// w  w w. j a v  a 2s  . co  m
}

From source file:com.decypher.threadsclient.JPanelChart.java

private String getFolder() {
    JFileChooser folderPick = new JFileChooser();
    folderPick.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folderPick.setDialogType(JFileChooser.SAVE_DIALOG);
    folderPick.setMultiSelectionEnabled(false);
    String selected;/*from   www. ja va 2 s . co m*/
    int returnVal = folderPick.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selected = folderPick.getSelectedFile().getPath();
    } else {
        selected = "";
    }
    return selected;
}

From source file:de.atomfrede.tools.evalutation.tools.plot.ui.wizard.time.pages.TimeFileSelectionPage.java

@Override
public JButton getSelectInputFileButton() {
    if (selectInputFileButton == null) {
        selectInputFileButton = new JButton(Icons.IC_MIME_CSV_SMALL);
        selectInputFileButton.setText("Select Data File");

        selectInputFileButton.addActionListener(new ActionListener() {

            @Override/*from  w  ww.  ja  v a 2  s.  c om*/
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                JFileChooser fc = getFileChooser();
                if (dataFile != null)
                    fc.setCurrentDirectory(dataFile.getParentFile());
                int returnValue = fc.showOpenDialog(parent);

                if (returnValue == JFileChooser.APPROVE_OPTION) {
                    dataFile = fc.getSelectedFile();
                    getInputFileTextField().setText(dataFile.getName());
                    // TODO check if that file contains a time column
                    if (checkFile()) {
                        plotWizard.setDataFile(dataFile);
                    } else {
                        plotWizard.setDataFile(null);
                    }
                }
            }
        });
    }
    return selectInputFileButton;
}