Search in sources :

Example 41 with JFileChooser

use of javax.swing.JFileChooser in project zxing by zxing.

the class GUIRunner method chooseImage.

private void chooseImage() throws MalformedURLException {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.showOpenDialog(this);
    Path file = fileChooser.getSelectedFile().toPath();
    Icon imageIcon = new ImageIcon(file.toUri().toURL());
    setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight() + 100);
    imageLabel.setIcon(imageIcon);
    String decodeText = getDecodeText(file);
    textArea.setText(decodeText);
}
Also used : Path(java.nio.file.Path) ImageIcon(javax.swing.ImageIcon) JFileChooser(javax.swing.JFileChooser) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon)

Example 42 with JFileChooser

use of javax.swing.JFileChooser in project ACS by ACS-Community.

the class ScriptFilter method getFileMenuSaveStatusButton.

/**
	 * This method initializes FileMenuSaveStatusButton
	 * @return javax.swing.JMenuItem
	 */
private JMenuItem getFileMenuSaveStatusButton() {
    if (FileMenuSaveStatusButton == null) {
        FileMenuSaveStatusButton = new JMenuItem();
        FileMenuSaveStatusButton.setText("Save GUI status");
        FileMenuSaveStatusButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {
                JFileChooser chooser = new JFileChooser();
                int returnVal = chooser.showSaveDialog(cl.utfsm.samplingSystemUI.SamplingSystemGUI.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    try {
                        String file = chooser.getSelectedFile().getAbsolutePath();
                        if (file.endsWith(".ssgst")) {
                            writeStatusFile(file);
                        } else {
                            writeStatusFile(file + ".ssgst");
                        }
                    } catch (ParserConfigurationException e1) {
                        e1.printStackTrace();
                    } catch (TransformerException e1) {
                        e1.printStackTrace();
                    } catch (FileNotFoundException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
    }
    return FileMenuSaveStatusButton;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) JMenuItem(javax.swing.JMenuItem) ActionEvent(java.awt.event.ActionEvent) TransformerException(javax.xml.transform.TransformerException)

Example 43 with JFileChooser

use of javax.swing.JFileChooser in project ACS by ACS-Community.

the class ZoomPrefsDlg method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == okBtn) {
        if (okPressed()) {
            setVisible(false);
            dispose();
        }
    } else if (e.getSource() == cancelBtn) {
        setVisible(false);
        dispose();
    } else if (e.getSource() == folderBtn) {
        JFileChooser fileChooser = new JFileChooser(folder);
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = fileChooser.getSelectedFile();
            folder = f.getAbsolutePath();
            setupFolderLbl();
        }
        okBtn.setEnabled(folder != null);
    } else {
        System.out.println("Unknown event: " + e.getSource());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File) Point(java.awt.Point)

Example 44 with JFileChooser

use of javax.swing.JFileChooser in project ACS by ACS-Community.

the class ErrorLogDialog method saveAllLog.

/**
	 * Save the content of the temporary file and the content of the text area 
	 * into a file
	 *
	 */
private void saveAllLog() {
    File f = null;
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    chooser.setDialogTitle("Save error log");
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        f = chooser.getSelectedFile();
    } else {
        return;
    }
    FileOutputStream fStream = null;
    try {
        fStream = new FileOutputStream(f);
    } catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(this, "Error opening the file", "Error saving the log", JOptionPane.ERROR_MESSAGE);
        System.out.println(fnfe.getMessage());
        fnfe.printStackTrace();
        return;
    }
    BufferedOutputStream bufOutStream = new BufferedOutputStream(fStream);
    // Save the log from the temporary file
    try {
        outFile.copy(bufOutStream);
    } catch (Exception e) {
        System.err.println("Error saving the logs on disk: " + e.getMessage());
        JOptionPane.showMessageDialog(this, "Error saving logs from temp file", "Error saving error log", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }
    // Save the content of the window
    synchronized (logTA) {
        try {
            bufOutStream.write(logTA.getText().getBytes());
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(this, "Error writing on file", "Error saving the log", JOptionPane.ERROR_MESSAGE);
            System.out.println(ioe.getMessage());
            ioe.printStackTrace();
            return;
        }
    }
    try {
        bufOutStream.flush();
        bufOutStream.close();
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(this, "Error closing the file", "Error saving the log", JOptionPane.ERROR_MESSAGE);
        System.out.println(ioe.getMessage());
        ioe.printStackTrace();
        return;
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException) FileNotFoundException(java.io.FileNotFoundException)

Example 45 with JFileChooser

use of javax.swing.JFileChooser in project ACS by ACS-Community.

the class FilterChooserDialog method loadFilters.

/**
	 * Load filters from a XML file The user chooses if the loaded filters
	 * substitutes the existing ones or merges with them
	 */
private void loadFilters() {
    boolean eraseOldFilters;
    // Check if already exists filters
    if (filterList.getItemsSize() > 0) {
        int ret = JOptionPane.showConfirmDialog(this, "Do you want do discard existing filters?", "Merge filters?", JOptionPane.YES_NO_CANCEL_OPTION);
        if (ret == JOptionPane.CANCEL_OPTION) {
            return;
        }
        eraseOldFilters = (ret == JOptionPane.YES_OPTION);
    } else {
        // We have no filters so.. nothing to
        eraseOldFilters = false;
    // delete ;-)
    }
    // Show the dialog to choose the file to load
    JFileChooser fileChooserDlg = new JFileChooser();
    fileChooserDlg.setMultiSelectionEnabled(false);
    fileChooserDlg.setDialogTitle("Load filters");
    XmlFileFilter fileFilter = new XmlFileFilter();
    fileChooserDlg.setFileFilter(fileFilter);
    if (fileChooserDlg.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        // Load filters from file
        File fileToLoad = fileChooserDlg.getSelectedFile();
        if (fileToLoad != null) {
            FiltersVector filters = new FiltersVector();
            try {
                filters.loadFilters(fileToLoad, eraseOldFilters, null);
            } catch (Throwable t) {
                JOptionPane.showMessageDialog(this, "Error: " + t.getMessage(), "Error loading filters", JOptionPane.ERROR_MESSAGE);
            }
            setupFields(filters, !eraseOldFilters);
            modified = true;
            filterFileName = fileToLoad.getAbsolutePath();
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FiltersVector(com.cosylab.logging.engine.FiltersVector) File(java.io.File)

Aggregations

JFileChooser (javax.swing.JFileChooser)297 File (java.io.File)178 IOException (java.io.IOException)63 FileFilter (javax.swing.filechooser.FileFilter)40 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)30 ActionEvent (java.awt.event.ActionEvent)27 ActionListener (java.awt.event.ActionListener)22 FileOutputStream (java.io.FileOutputStream)19 JButton (javax.swing.JButton)19 JPanel (javax.swing.JPanel)16 Point (java.awt.Point)14 Preferences (java.util.prefs.Preferences)12 JMenuItem (javax.swing.JMenuItem)12 Component (java.awt.Component)11 FileNotFoundException (java.io.FileNotFoundException)11 JFrame (javax.swing.JFrame)10 JLabel (javax.swing.JLabel)10 ResourceBundle (java.util.ResourceBundle)8 BorderLayout (java.awt.BorderLayout)7 FileDialog (java.awt.FileDialog)7