Example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

Introduction

In this page you can find the example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter.

Prototype

public FileNameExtensionFilter(String description, String... extensions) 

Source Link

Document

Creates a FileNameExtensionFilter with the specified description and file name extensions.

Usage

From source file:org.nekorp.workflow.desktop.view.ServicioView.java

private void ordenServicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ordenServicioActionPerformed
    try {//  w  w w.ja  v  a 2s. c  o m
        if (servicioMetaData.isEditado()) {
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
            this.aplication.guardaServicio();
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
        }
        ParametrosReporteOS param = new ParametrosReporteOS();
        Object[] options = { "Evaluacin", "Presupuesto" };
        int n = javax.swing.JOptionPane.showOptionDialog(mainFrame, "Qu tipo de reporte desea generar?",
                "Tipo de reporte", javax.swing.JOptionPane.YES_NO_OPTION,
                javax.swing.JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
        if (n == javax.swing.JOptionPane.CLOSED_OPTION) {
            return;
        }
        param.setConCosto(!(n == javax.swing.JOptionPane.YES_OPTION));
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf");
        chooser.setFileFilter(filter);
        String homePath = System.getProperty("user.home");
        String prefijo;
        if (param.isConCosto()) {
            prefijo = "/Orden-Servicio-presupuesto-";
        } else {
            prefijo = "/Orden-Servicio-evaluacion-";
        }
        File f = new File(
                new File(homePath + prefijo + this.viewServicioModel.getId() + ".pdf").getCanonicalPath());
        chooser.setSelectedFile(f);
        int returnVal = chooser.showSaveDialog(this.mainFrame);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
            param.setDestination(chooser.getSelectedFile());
            this.aplication.generaOrdenServicio(param);
        }
    } catch (IllegalArgumentException e) {
        //no lo guardo por que tenia horribles errores... tambien especializar la excepcion
    } catch (IOException ex) {
        ServicioView.LOGGER.error("error al exportar orden de servicio", ex);
    } finally {
        this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelTesting.java

/**
 * Initialises the interface of the results panel.
 *///from  w  w w  .  java 2s.  c  o  m
protected void initialize() {

    setLayout(null);
    isSimulated = false;

    lblExportChartTo = new JLabel("Export chart to ...");
    lblExportChartTo.setBounds(436, 479, 144, 14);
    lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblExportChartTo.setVisible(false);
    add(lblExportChartTo);

    btnCsv = new JButton("CSV");
    btnCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String csv;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("csv")) {
                    csv = "";
                } else {
                    csv = ".csv";
                }
                String csvPath = file.getAbsolutePath() + csv;
                double[] selectedValues;
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                final int day = 24;
                File csvFile = new File(csvPath);
                try {
                    OMCampaign campaign;
                    if (isResult) {
                        campaign = getResultCampaign();
                    } else {
                        campaign = new OMCampaign(start, rooms, 0);
                    }
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    csvOutput.write("\"ID\";\"Room\";\"Radon\"");
                    csvOutput.newLine();
                    selectedValues = campaign.getValueChain();
                    int x = 0;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[0].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[1].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[2].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[3].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[4].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[5].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[6].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                    csvOutput.close();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnCsv.setBounds(590, 475, 70, 23);
    btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnCsv.setVisible(false);
    add(btnCsv);

    btnPdf = new JButton("PDF");
    btnPdf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String pdf;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("pdf")) {
                    pdf = "";
                } else {
                    pdf = ".pdf";
                }
                String pdfPath = file.getAbsolutePath() + pdf;
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                OMCampaign campaign;
                try {
                    if (isResult) {
                        campaign = getResultCampaign();
                    } else {
                        campaign = new OMCampaign(start, rooms, 0);
                    }
                    JFreeChart chart = OMCharts.createCampaignChart(campaign, false);
                    String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId()
                            + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId()
                            + ", Start: " + start;
                    int height = (int) PageSize.A4.getWidth();
                    int width = (int) PageSize.A4.getHeight();
                    try {
                        OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title);
                        JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success",
                                JOptionPane.INFORMATION_MESSAGE);
                    } catch (IOException ioe) {
                        JOptionPane.showMessageDialog(null,
                                "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed",
                                JOptionPane.ERROR_MESSAGE);
                        ioe.printStackTrace();
                    }
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null, "Failed to create chart!\n" + ioe.getMessage(),
                            "Failed", JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnPdf.setBounds(670, 475, 70, 23);
    btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnPdf.setVisible(false);
    add(btnPdf);

    lblSelectProject = new JLabel("Select Project");
    lblSelectProject.setBounds(10, 65, 132, 14);
    lblSelectProject.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblSelectProject);

    lblSelectRooms = new JLabel("Select Rooms");
    lblSelectRooms.setBounds(10, 94, 132, 14);
    lblSelectRooms.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblSelectRooms);

    lblStartTime = new JLabel("Start Time");
    lblStartTime.setBounds(10, 123, 132, 14);
    lblStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblStartTime);

    lblWarning = new JLabel("Select 6 rooms and 1 cellar!");
    lblWarning.setForeground(Color.RED);
    lblWarning.setBounds(565, 123, 175, 14);
    lblWarning.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblWarning.setVisible(false);
    add(lblWarning);

    sliderStartTime = new JSlider();
    sliderStartTime.setMaximum(0);
    sliderStartTime.setBounds(152, 119, 285, 24);
    sliderStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(sliderStartTime);

    spnrStartTime = new JSpinner();
    spnrStartTime.setModel(new SpinnerNumberModel(0, 0, 0, 1));
    spnrStartTime.setBounds(447, 120, 108, 22);
    spnrStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(spnrStartTime);

    btnRefresh = new JButton("Load");
    btnRefresh.setBounds(616, 61, 124, 23);
    btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(btnRefresh);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(btnMaximize);

    panelCampaign = new JPanel();
    panelCampaign.setBounds(10, 150, 730, 315);
    panelCampaign.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(panelCampaign);

    progressBar = new JProgressBar();
    progressBar.setBounds(10, 475, 730, 23);
    progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11));
    progressBar.setVisible(false);
    add(progressBar);

    lblOpenOmbfile = new JLabel("Open OMB-File");
    lblOpenOmbfile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblOpenOmbfile.setBounds(10, 36, 132, 14);
    add(lblOpenOmbfile);

    lblHelp = new JLabel("Select an OMB-Object file to manually simulate virtual campaigns.");
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    txtOmbFile = new JTextField();
    txtOmbFile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    txtOmbFile.setColumns(10);
    txtOmbFile.setBounds(152, 33, 454, 20);
    add(txtOmbFile);

    btnBrowse = new JButton("Browse");
    btnBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnBrowse.setBounds(616, 32, 124, 23);
    add(btnBrowse);

    comboBoxRoom1 = new JComboBox<OMRoom>();
    comboBoxRoom1.setBounds(152, 90, 75, 22);
    comboBoxRoom1.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom1);

    comboBoxRoom2 = new JComboBox<OMRoom>();
    comboBoxRoom2.setBounds(237, 90, 75, 22);
    comboBoxRoom2.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom2);

    comboBoxRoom3 = new JComboBox<OMRoom>();
    comboBoxRoom3.setBounds(323, 90, 75, 22);
    comboBoxRoom3.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom3);

    comboBoxRoom4 = new JComboBox<OMRoom>();
    comboBoxRoom4.setBounds(408, 90, 75, 22);
    comboBoxRoom4.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom4);

    comboBoxRoom5 = new JComboBox<OMRoom>();
    comboBoxRoom5.setBounds(494, 90, 75, 22);
    comboBoxRoom5.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom5);

    comboBoxRoom6 = new JComboBox<OMRoom>();
    comboBoxRoom6.setBounds(579, 90, 75, 22);
    comboBoxRoom6.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom6);

    comboBoxRoom7 = new JComboBox<OMRoom>();
    comboBoxRoom7.setBounds(665, 90, 75, 22);
    comboBoxRoom7.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom7);

    comboBoxProjects = new JComboBox<OMBuilding>();
    comboBoxProjects.setBounds(152, 61, 454, 22);
    comboBoxProjects.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxProjects);

    comboBoxRoom1.addActionListener(this);
    comboBoxRoom1.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom2.addActionListener(this);
    comboBoxRoom2.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom3.addActionListener(this);
    comboBoxRoom3.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom4.addActionListener(this);
    comboBoxRoom4.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom5.addActionListener(this);
    comboBoxRoom5.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom6.addActionListener(this);
    comboBoxRoom6.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom7.addActionListener(this);
    comboBoxRoom7.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });

    sliderStartTime.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    spnrStartTime.setValue((int) sliderStartTime.getValue());
                    updateChart();
                }
            }
        }
    });
    spnrStartTime.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    sliderStartTime.setValue((Integer) spnrStartTime.getValue());
                    updateChart();
                }
            }
        }
    });
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("")
                    && !txtOmbFile.getText().equals(" ")) {
                txtOmbFile.setBackground(Color.WHITE);
                String ombPath = txtOmbFile.getText();
                String omb;
                String[] tmpFileName = ombPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(ombPath + omb);
                setOmbFile(ombPath + omb);
                File ombFile = new File(ombPath + omb);
                if (ombFile.exists()) {
                    txtOmbFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxProjects.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    progressBar.setVisible(true);
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    btnMaximize.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    progressBar.setIndeterminate(true);
                    progressBar.setStringPainted(true);
                    refreshTask = new Refresh();
                    refreshTask.execute();
                } else {
                    txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId()
                        + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId()
                        + ", Start: " + start;
                OMCampaign campaign;
                if (isResult) {
                    campaign = getResultCampaign();
                } else {
                    campaign = new OMCampaign(start, rooms, 0);
                }
                JPanel campaignChart = createCampaignPanel(campaign, false, true);
                JFrame chartFrame = new JFrame();
                chartFrame.getContentPane().add(campaignChart);
                chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                chartFrame.setTitle(title);
                chartFrame.setResizable(true);
                chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                chartFrame.setVisible(true);
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    });
    txtOmbFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            setOmbFile(txtOmbFile.getText());
        }
    });
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String omb;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(file.getAbsolutePath() + omb);
                setOmbFile(file.getAbsolutePath() + omb);
            }
        }
    });
}

From source file:ch.bfh.lca._15h.server.gui.MainWindowServer.java

private String getPath() {
    String text = "";
    FileNameExtensionFilter filter = null;
    String path = "";

    if (this.activeModule.equals("table")) {
        filter = new FileNameExtensionFilter("EXCEL File", "xlsx");
        text = "Wo mchten Sie das Excel ersellen?";
    } else {/* ww  w . j av a2s  . c o m*/
        filter = new FileNameExtensionFilter("JPEG File", "jpg");
        text = "Wo mchten Sie das Bild ersellen?";
    }

    // JFileChooser-Objekt erstellen
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(filter);
    // Dialog zum Speichern von Dateien anzeigen
    int resultValue = chooser.showDialog(null, text);

    if (resultValue != JFileChooser.ABORT) {
        path = chooser.getSelectedFile().getAbsolutePath();
    }

    return path;

}

From source file:gui.InboxPanel.java

private void openVerifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openVerifyButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    int retrieval = chooser.showOpenDialog(null);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Public file", "pub");
    chooser.setFileFilter(filter);//from  w ww . ja v a  2s. c o  m
    if (retrieval == JFileChooser.APPROVE_OPTION) {
        FileInputStream fis = null;
        try {
            File file = chooser.getSelectedFile();
            Path path = Paths.get(file.getAbsolutePath());
            fis = new FileInputStream(file);
            //Construct BufferedReader from InputStreamReader
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            try {
                String x = br.readLine();
                String y = br.readLine();
                publickey = new BigPoint(new BigInteger(x), new BigInteger(y));
                System.out.println("Public key : " + publickey.getX() + publickey.getY());
                br.close();
            } catch (IOException ex) {
                Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                fis.close();
            } catch (IOException ex) {
                Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:org.samjoey.gui.GraphicalViewer.java

private void jButton_Parser_OpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_Parser_OpenActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    String[] exts = new String[2];
    exts[0] = "pgn";
    exts[1] = "jsca";
    FileNameExtensionFilter filter = new FileNameExtensionFilter(".pgn or .jsca files ONLY!", exts);
    fc.setFileFilter(filter);/*  w w  w . j a  v a2 s  . c o m*/
    int returnVal = fc.showDialog(this, "Parse");

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final java.io.File file = fc.getSelectedFile();
        //This is where a real application would open the file.
        this.jTextField_Parser.setText(file.getName());
        (new Thread() {
            @Override
            public void run() {
                selectedPGN(file);
            }
        }).start();
    } else {
    }
}

From source file:com.unsa.view.MainView.java

private void btnSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSeleccionarActionPerformed
    // TODO add your handling code here:

    //JFileChooser file=new JFileChooser();
    file = new JFileChooser();
    //FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF & DOC & DOCX Files", "pdf", "docx","doc");
    FileNameExtensionFilter filter1 = new FileNameExtensionFilter("PDF", "pdf");
    FileNameExtensionFilter filter2 = new FileNameExtensionFilter("DOCX, DOC", "docx", "doc");
    //FileNameExtensionFilter filter3 = new FileNameExtensionFilter("DOC","doc");

    file.setFileFilter(filter1);/*from w  ww. j a v a 2 s.c  o  m*/
    file.setFileFilter(filter2);

    file.setMultiSelectionEnabled(true);
    file.showOpenDialog(null);

    File[] abrir = file.getSelectedFiles();
    if (abrir.length == 0) {
        JOptionPane.showMessageDialog(null, "No seleccion ningun archivo");
        return;
    }

    txtArchivos.setText(abrir[0].getParent());
    String[] lnames = { "Nombre Archivo", "Obs. Dudosa", "Obs. Critica", "Abrir Archivo" };

    DefaultTableModel model = new DefaultTableModel(lnames, 0);
    tableSalida.setModel(model);
    for (File file2 : abrir) {
        Object[] data = new Object[4];
        data[0] = file2.getName();
        data[1] = "";

        model.addRow(data);
    }

    if (lblInstitucion.getText().equals("") || lblSiglas.getText().equals("")
            || lblIdioma.getText().equals("")) {
        btnProcesar.setEnabled(false);
    } else {
        btnProcesar.setEnabled(true);
    }

}

From source file:nosqltools.MainForm.java

/**
 * This event handler is used to save the JSON objects to the file chosen
 * @param evt /*  ww w. j av a2  s.  c  o  m*/
 */
private void Save_FileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Save_FileActionPerformed
    try {
        file = null;
        sb.setLength(0);

        //choosable file extensions 
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files (" + ext + ")", ext_array);
        fc.setFileFilter(filter);

        //save is OK
        int returnVal = fc.showSaveDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            Save_File.setEnabled(true);
            file = fc.getSelectedFile();

            parser.parse(textArea.getText());
            //parse data
            if (json_util.isDataParsed(textArea.getText())) {
                try {
                    BufferedWriter writer = new BufferedWriter(new FileWriter(fc.getSelectedFile()));
                    writer.write(textArea.getText());
                    writer.close();
                    Text_MessageBar.setText(Initializations.JSONSAVESUCCESS);
                    Text_MessageBar.setForeground(Color.GREEN);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else //case for saving error
            {
                Text_MessageBar.setForeground(Color.RED);
                Text_MessageBar.setText(Initializations.VALIDATIONERROR);
                JOptionPane.showMessageDialog(null,
                        Initializations.JSONSAVEERROR + Initializations.VALIDATIONERROR, "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } catch (org.json.simple.parser.ParseException pe) //case for incorrect JSON object
    {
        Text_MessageBar.setForeground(Color.RED);
        Text_MessageBar.setText(Initializations.JSONSAVEERROR + Initializations.ERRORLINE
                + json_util.getLineNumber(pe.getPosition(), textArea.getText()) + " - " + pe);
    }
}

From source file:com.ga.forms.DailyLogUI.java

private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
    System.out.print(//from ww w.  j a  v  a 2 s  . c o  m
            "REGEX: " + monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString());
    JFrame fileChooserFrame = new JFrame();
    JFileChooser saveFileDialog = new JFileChooser();
    FileNameExtensionFilter fileExtentionFilter = new FileNameExtensionFilter("Comma Seperated Values (*.csv)",
            "csv");
    saveFileDialog.setFileFilter(fileExtentionFilter);
    int saveFileDialogStatus = saveFileDialog.showSaveDialog(fileChooserFrame);
    if (saveFileDialogStatus == JFileChooser.APPROVE_OPTION) {
        String fileSaveDetails = saveFileDialog.getSelectedFile().toString();
        args = new HashMap();
        HashMap regex = new HashMap();
        regex.put("$regex",
                monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString());
        args.put("date", regex);
        DailyLogRecord record = new DailyLogRecord();
        ArrayList logs = record.retrieveRecord(args);
        String[] columnNames = new String[] { "Date", "Day", "In", "Out", "Break", "Duration", "Under-Time",
                "Over-Time" };
        ArrayList data = null;
        if (!logs.isEmpty()) {
            data = new ArrayList();
            data.add(String.join(",", columnNames));
            for (int logIndex = 0; logIndex < logs.size(); logIndex++) {
                JSONObject logJSONOBject = new JSONObject((Map) logs.get(logIndex));
                String csvRecord = logJSONOBject.get("date").toString() + ","
                        + logJSONOBject.get("day").toString() + "," + logJSONOBject.get("check-in").toString()
                        + "," + logJSONOBject.get("check-out").toString() + ","
                        + logJSONOBject.get("break").toString() + "," + logJSONOBject.get("duration").toString()
                        + "," + logJSONOBject.get("under-time").toString() + ","
                        + logJSONOBject.get("over-time").toString();
                data.add(csvRecord);
            }

        }
        DailyLogCSVExport csvExporter = new DailyLogCSVExport();
        csvExporter.save(data, fileSaveDetails);
    }
}

From source file:com.signalcollect.sna.visualization.SignalCollectSNATopComponent.java

/**
 * Displays a file chooser when clicking on the "Choose File" button The
 * chosen file is then used for a new gephi project
 *
 * @param evt// w w  w  .  j a  v  a  2 s . c  om
 */
private void fileChooserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileChooserButtonActionPerformed

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Graph Files", "gml");
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(filter);
    int result = chooser.showOpenDialog(this);
    if (chooser.getSelectedFile() != null && result == JFileChooser.APPROVE_OPTION) {
        fileName = chooser.getSelectedFile().getAbsolutePath();
        jTextArea1.setText(fileName);
        distributionFrame = new JFrame();

        try {
            ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
            pc.newProject();
            ImportController ic = Lookup.getDefault().lookup(ImportController.class);
            File file = new File(fileName);
            Container c = ic.importFile(file);
            ic.process(c, new DefaultProcessor(), pc.newWorkspace(pc.getCurrentProject()));
            propertyContentDisplay.setText("");

        } catch (Exception exception) {
            messageFrame = new JFrame();
            exception.printStackTrace();
            JOptionPane.showMessageDialog(messageFrame,
                    "Error while creating graph (" + exception.getCause()
                            + "), please choose a valid .gml-File",
                    "Signal/Collect Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:AltiConsole.AltiConsoleMainScreen.java

/**
 * Handles all the actions.//from w  w  w.ja v a2  s .  com
 * 
 * @param e
 *            the action event.
 */
public void actionPerformed(final ActionEvent e) {
    final Translator trans = Application.getTranslator();

    if (e.getActionCommand().equals("EXIT")) {
        System.out.println("exit and disconnecting\n");
        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.ClosingWindow"),
                trans.get("AltiConsoleMainScreen.ReallyClosing"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            DisconnectFromAlti();
            System.exit(0);
        }
    } else if (e.getActionCommand().equals("ABOUT")) {
        AboutDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // ERASE_FLIGHT
    else if (e.getActionCommand().equals("ERASE_FLIGHT")) {

        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.eraseAllflightData"),
                trans.get("AltiConsoleMainScreen.eraseAllflightDataTitle"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            System.out.println("erasing flight\n");
            ErasingFlight();
        }

    } else if (e.getActionCommand().equals("RETRIEVE_FLIGHT")) {

        System.out.println("retrieving flight\n");
        RetrievingFlight();

    } else
    // SAVE_FLIGHT
    if (e.getActionCommand().equals("SAVE_FLIGHT")) {
        System.out.println("Saving current flight\n");
        SavingFlight();
    } else
    // RETRIEVE_ALTI_CFG
    if (e.getActionCommand().equals("RETRIEVE_ALTI_CFG")) {
        System.out.println("retrieving alti config\n");
        AltiConfigData pAlticonfig = retrieveAltiConfig();
        if (pAlticonfig != null)
            AltiConfigDlg.showPreferences(AltiConsoleMainScreen.this, pAlticonfig, Serial);

    }
    // LICENSE
    else if (e.getActionCommand().equals("LICENSE")) {

        LicenseDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // comPorts
    else if (e.getActionCommand().equals("comPorts")) {
        DisconnectFromAlti();
        String currentPort;
        //e.
        currentPort = (String) comPorts.getSelectedItem();
        if (Serial != null)
            Serial.searchForPorts();

        System.out.println("We have a new selected value for comport\n");
        comPorts.setSelectedItem(currentPort);
    }
    // UPLOAD_FIRMWARE
    else if (e.getActionCommand().equals("UPLOAD_FIRMWARE")) {
        System.out.println("upload firmware\n");
        //make sure to disconnect first
        DisconnectFromAlti();
        JFileChooser fc = new JFileChooser();
        String hexfile = null;
        File startFile = new File(System.getProperty("user.dir"));
        //FileNameExtensionFilter filter;

        fc.setDialogTitle("Select firmware");
        //fc.set
        fc.setCurrentDirectory(startFile);
        //fc.addChoosableFileFilter(new FileNameExtensionFilter("*.HEX", "hex"));
        fc.setFileFilter(new FileNameExtensionFilter("*.hex", "hex"));
        //fc.fil
        int action = fc.showOpenDialog(SwingUtilities.windowForComponent(this));
        if (action == JFileChooser.APPROVE_OPTION) {
            hexfile = fc.getSelectedFile().getAbsolutePath();
        }
        if (hexfile != null) {

            String exefile = UserPref.getAvrdudePath();

            String conffile = UserPref.getAvrdudeConfigPath();

            String opts = " -v -v -v -v -patmega328p -carduino -P\\\\.\\"
                    + (String) this.comPorts.getSelectedItem() + " -b115200 -D -V ";

            String cmd = exefile + " -C" + conffile + opts + " -Uflash:w:" + hexfile + ":i";
            System.out.println(cmd);

            try {
                Process p = Runtime.getRuntime().exec(cmd);
                AfficheurFlux fluxSortie = new AfficheurFlux(p.getInputStream(), this);
                AfficheurFlux fluxErreur = new AfficheurFlux(p.getErrorStream(), this);

                new Thread(fluxSortie).start();
                new Thread(fluxErreur).start();

                p.waitFor();
            } catch (IOException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e2) {
                e2.printStackTrace();
            }
        }
    }
    // ON_LINE_HELP
    else if (e.getActionCommand().equals("ON_LINE_HELP")) {
        Desktop d = Desktop.getDesktop();
        System.out.println("Online help \n");
        try {
            d.browse(new URI(trans.get("help.url")));
        } catch (URISyntaxException e1) {

            System.out.println("Illegal URL:  " + trans.get("help.url") + " " + e1.getMessage());
        } catch (IOException e1) {
            System.out.println("Unable to launch browser: " + e1.getMessage());
        }

    }
}