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);
}
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;
}
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());
}
}
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;
}
}
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();
}
}
}
Aggregations