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:eu.apenet.dpt.standalone.gui.XsdAdderActionListener.java

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

    if (xsdChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        File file = xsdChooser.getSelectedFile();
        if (isXSD(file)) {
            XsdInfoQueryComponent xsdInfoQueryComponent = new XsdInfoQueryComponent(labels, file.getName());

            int result = JOptionPane.showConfirmDialog(parent, xsdInfoQueryComponent, "title",
                    JOptionPane.OK_CANCEL_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                if (StringUtils.isEmpty(xsdInfoQueryComponent.getName())) {
                    errorMessage();/*  w w w  . j  a v  a 2s.  c  om*/
                } else {
                    if (saveXsd(file, xsdInfoQueryComponent.getName(), false,
                            xsdInfoQueryComponent.getXsdVersion(), xsdInfoQueryComponent.getFileType())) {
                        JRadioButton newButton = new JRadioButton(xsdInfoQueryComponent.getName());
                        newButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI));
                        dataPreparationToolGUI.getGroupXsd().add(newButton);
                        dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsdPanel(newButton);
                        dataPreparationToolGUI.getAPEPanel().getApeTabbedPane()
                                .addToXsdPanel(Box.createRigidArea(new Dimension(0, 10)));
                        JOptionPane.showMessageDialog(parent, labels.getString("xsdSaved") + ".",
                                labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon);
                    } else {
                        errorMessage();
                    }
                }
            }
        } else {
            errorMessage();
        }
    }
}

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

@Override
public void performAction() {
    this.executeInjection();
    JFileChooser chooser = vista.getFileChooserApriTGD();
    File file;// w  ww  .j a v a2s .  co  m
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            String fileAbsoluteFile = file.getPath();
            ParseMappingTask generator = new ParseMappingTask();
            //giannisk
            Scenarios.getNextFreeNumber();
            MappingTask mappingTask = generator.generateMappingTask(fileAbsoluteFile);
            gestioneScenario(mappingTask);
            this.actionViewSchema.performAction();
            enableActions();
        } catch (Exception 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.jtk.pengelolaanujian.view.dosenpengampu.UploadNilai.java

private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    int result = fileChooser.showOpenDialog(null);
    if (result == JFileChooser.APPROVE_OPTION) {
        url = fileChooser.getSelectedFile().getAbsolutePath();
        textUrl.setText(url);/*w w  w .j ava  2s.co m*/
    }
}

From source file:be.fedict.eid.tsl.tool.SignSelectPkcs11FinishablePanel.java

@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Select PKCS#11 library");
    int returnValue = fileChooser.showOpenDialog(null);
    if (JFileChooser.APPROVE_OPTION == returnValue) {
        String pkcs11Library = fileChooser.getSelectedFile().getAbsolutePath();
        this.pkcs11TextField.setText(pkcs11Library);
    }/*from ww w .  ja v  a 2s.co  m*/
}

From source file:com.johnson3yo.dubem.plugin.ArtifactWizardMojo.java

private void updateAppServletXml_JFileChooser(String functionName) throws IOException, JDOMException {

    getLog().info("please select app-servlet.xml from foundation-guiwar  ");

    JFileChooser fc = new JFileChooser();

    int retValue = fc.showOpenDialog(new JPanel());

    if (retValue == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();

        SAXBuilder builder = new SAXBuilder();

        Document document = (Document) builder.build(f);
        Element rootNode = document.getRootElement();

        List<Element> list = rootNode.getChildren("component-scan",
                Namespace.getNamespace("http://www.springframework.org/schema/context"));

        Element e = list.get(0);//from w w w .java2  s .c  o m

        String cnt = "<context:exclude-filter type=\"regex\" expression=\"pegasus\\.module\\."
                + functionName.toLowerCase() + "\\..*\" />";

        e.addContent(cnt);

        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()) {
            @Override
            public String escapeElementEntities(String str) {
                return str;
            }
        };

        Writer writer = new OutputStreamWriter(new FileOutputStream(f), "utf-8");
        outputter.output(document, writer);
        writer.close();
    } else {
        getLog().info("Next time select a file.");
        System.exit(1);
    }

}

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

@Override
public void performAction() {
    this.executeInjection();
    JFileChooser chooser = vista.getFileChooserApriCSV();
    File file;/*from   w w  w. ja va  2s .  c o  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")) {
            UnpivotCSVDAO daoUnpivot = new UnpivotCSVDAO();
            try {
                //                    avenet 20170410 
                //                    String[] columnNames = daoUnpivot.getCsvTableColumns(file);
                String[] columnNames = daoUnpivot.getCsvTableColumnsWithoutSpecialCharacters(file);
                UnpivotCsvMainFrame unpivotMain = new UnpivotCsvMainFrame(columnNames);
                List<String> colNames = unpivotMain.getColNames();
                List<String> keepColNames = unpivotMain.getKeepColNames();
                String newColName = unpivotMain.getNewColName();
                if (!colNames.isEmpty() && newColName != null && !newColName.equals("")) {
                    try {
                        daoUnpivot.unpivotTable(keepColNames, colNames, newColName, file);
                        DialogDisplayer.getDefault()
                                .notify(new NotifyDescriptor.Message(
                                        NbBundle.getMessage(Costanti.class, Costanti.EXPORT_UNPIVOTED_OK)
                                                + file.getParent()));
                    } catch (DAOException ex) {
                        DialogDisplayer.getDefault().notify(
                                new NotifyDescriptor.Message(ex.getMessage(), DialogDescriptor.ERROR_MESSAGE));
                        logger.error(ex);
                    } catch (SQLException ex) {
                        DialogDisplayer.getDefault().notify(
                                new NotifyDescriptor.Message(ex.getMessage(), DialogDescriptor.ERROR_MESSAGE));
                        logger.error(ex);
                    }
                }
            } 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:ZipTest.java

public ZipTestFrame() {
    setTitle("ZipTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add the menu and the Open and Exit menu items
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");

    JMenuItem openItem = new JMenuItem("Open");
    menu.add(openItem);//www . j av  a  2s. c o  m
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new File("."));
            int r = chooser.showOpenDialog(ZipTestFrame.this);
            if (r == JFileChooser.APPROVE_OPTION) {
                zipname = chooser.getSelectedFile().getPath();
                fileCombo.removeAllItems();
                scanZipFile();
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    menuBar.add(menu);
    setJMenuBar(menuBar);

    // add the text area and combo box
    fileText = new JTextArea();
    fileCombo = new JComboBox();
    fileCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadZipFile((String) fileCombo.getSelectedItem());
        }
    });

    add(fileCombo, BorderLayout.SOUTH);
    add(new JScrollPane(fileText), BorderLayout.CENTER);
}

From source file:org.vimarsha.ui.DataLoaderForm.java

public DataLoaderForm() {

    for (String str : UIHandler.getInstance().getArchitectureList()) {
        architectureComboBox.addItem(str);
        architectureComboBox.setSelectedItem(null);
    }//w  w  w . java  2  s  .  c o m

    architectureComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            UIHandler.getInstance().setArchitecture((String) architectureComboBox.getSelectedItem());
            trainingModelTextBox.setText(UIHandler.getInstance().getTrainingModel());
        }
    });
    openRAWFileButton.addActionListener(new ActionListener() {
        File file = null;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showOpenDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
            }
            if ((UIHandler.getInstance().setRawFile(file) == 100)
                    && (UIHandler.getInstance().convertRawToArff() == 100)) {
                saveToARFFFileButton.setEnabled(true);
                attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray());
                testDataTextField.setText(UIHandler.getInstance().getTestDataName());
            }

        }
    });
    openARFFFileButton.addActionListener(new ActionListener() {
        File file = null;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showOpenDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                UIHandler.getInstance().setArffFile(file);
                attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray());
                saveToARFFFileButton.setEnabled(true);
                testDataTextField.setText(UIHandler.getInstance().getTestDataName());
            }

        }
    });
    saveToARFFFileButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            File file = null;
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showSaveDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                System.out.println(fc.getSelectedFile());
                UIHandler.getInstance().saveAsArff(fc.getSelectedFile());
            }

        }
    });

    attributeList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            int selectedEvent = attributeList.getSelectedIndex();
            attributesSummaryTable
                    .setModel(UIHandler.getInstance().getArffAttributeInfo(attributeList.getSelectedIndex()));
            DefaultCategoryDataset data = UIHandler.getInstance().getBarChartDataSet(selectedEvent);
            drawBarChart(data);
        }
    });
}

From source file:firmadigital.Parametros.java

private void cmdExaminarAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarAlmacenActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        String selectedFile = fileChooser.getSelectedFile().getAbsolutePath();
        txtUbicacionAlmacenCertificado.setText(selectedFile);
    }//from  ww  w.j a va2  s  .c o m
}

From source file:firmadigital.Parametros.java

private void cmdExaminarCertificadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarCertificadoActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        String selectedFile = fileChooser.getSelectedFile().getAbsolutePath();
        txtCertificado.setText(selectedFile);
    }//  www . j a  va2  s .  c om
}