use of javax.swing.filechooser.FileNameExtensionFilter in project pcgen by PCGen.
the class DiceBagPluginController method fileOpen.
/**
* <p>
* Displays a file-open dialog box and processes the selected values.
* </p>
*
* @return {@code boolean} indicating success/failure of operation.
*/
public boolean fileOpen() {
boolean returnValue = false;
String sFile = SettingsHandler.getGMGenOption(DiceBagPlugin.LOG_NAME + ".LastFile", System.getProperty("user.dir"));
JFileChooser open = new JFileChooser();
if (sFile != null) {
File defaultFile = new File(sFile);
if (defaultFile.exists()) {
open.setCurrentDirectory(defaultFile);
}
}
String fileExt = "dbg";
FileFilter ff = new FileNameExtensionFilter("GMGen Dice Bag", fileExt);
open.addChoosableFileFilter(ff);
open.setFileFilter(ff);
if (open.showOpenDialog(GMGenSystem.inst) == JFileChooser.APPROVE_OPTION) {
openFile(open.getSelectedFile());
returnValue = true;
}
return returnValue;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project pcgen by PCGen.
the class NotesView method getImageFromChooser.
/**
* obtains an Image for input using a custom JFileChooser dialog
*
*@param startDir Directory to open JFielChooser to
*@param exts Extensions to search for
*@param desc Description for files
*@return File pointing to the selected image
*/
private File getImageFromChooser(String startDir, String[] exts, String desc) {
JFileChooser jImageDialog = new JFileChooser();
jImageDialog.setCurrentDirectory(new File(startDir));
jImageDialog.setAccessory(new ImageFileChooserPreview(jImageDialog));
jImageDialog.setDialogType(JFileChooser.CUSTOM_DIALOG);
jImageDialog.setFileFilter(new FileNameExtensionFilter(desc, exts));
jImageDialog.setDialogTitle("Select an Image to Insert");
int optionSelected = jImageDialog.showDialog(this, "Insert");
if (optionSelected == JFileChooser.APPROVE_OPTION) {
return jImageDialog.getSelectedFile();
}
return null;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project ACS by ACS-Community.
the class TablePopupMenu method saveSelectedLogs.
/**
* Save the selected logs into a file in the passed format.
*
* @param converter The converter to desired format
* @param fileIcon The icon of the file type
*/
private void saveSelectedLogs(LogConverter converter, ImageIcon fileIcon, String extension) {
if (converter == null) {
throw new IllegalArgumentException("The converter can't be null");
}
if (extension == null || extension.isEmpty()) {
throw new IllegalArgumentException("Invalid file extension");
}
converter.setCols(buildFields());
// Build the text to save in the file
StringBuilder strBuffer = new StringBuilder();
if (!selectionModel.isSelectionEmpty()) {
for (int i = selectionModel.getMinSelectionIndex(); i <= selectionModel.getMaxSelectionIndex(); i++) {
if (!selectionModel.isSelectedIndex(i)) {
continue;
} else {
ILogEntry log = model.getVisibleLogEntry(sorter.convertRowIndexToModel(i));
strBuffer.append(converter.convert(log));
}
}
if (strBuffer.length() == 0) {
// Nothing to save
return;
}
}
FileFilter fileFilter = new FileNameExtensionFilter("File " + extension, extension);
CustomFileChooser fc = new CustomFileChooser(fileIcon, fileFilter);
fc.addChoosableFileFilter(fileFilter);
if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// If not present, add the xml extension
if (!file.getAbsolutePath().toLowerCase().endsWith("." + extension)) {
file = new File(file.getAbsolutePath() + "." + extension);
}
FileOutputStream outFStream = null;
try {
outFStream = new FileOutputStream(file);
} catch (FileNotFoundException fnfe) {
JOptionPane.showMessageDialog(null, "Error creating " + file.getAbsolutePath() + ":\n" + fnfe.getMessage(), "Error saving logs", JOptionPane.ERROR_MESSAGE);
return;
}
try {
outFStream.write(strBuffer.toString().getBytes());
outFStream.flush();
outFStream.close();
} catch (IOException ioe) {
JOptionPane.showMessageDialog(null, "Error saving " + file.getAbsolutePath() + ":\n" + ioe.getMessage(), "Error saving logs", JOptionPane.ERROR_MESSAGE);
}
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project zaproxy by zaproxy.
the class PopupMenuExportURLs method getOutputFile.
protected File getOutputFile() {
WritableFileChooser chooser = new WritableFileChooser(extension.getModel().getOptionsParam().getUserDirectory());
FileNameExtensionFilter textFilesFilter = new FileNameExtensionFilter(Constant.messages.getString("file.format.ascii"), "txt");
FileNameExtensionFilter htmlFilesFilter = new FileNameExtensionFilter(Constant.messages.getString("file.format.html"), "html", "htm");
chooser.addChoosableFileFilter(textFilesFilter);
chooser.addChoosableFileFilter(htmlFilesFilter);
chooser.setFileFilter(textFilesFilter);
File file = null;
int rc = chooser.showSaveDialog(extension.getView().getMainFrame());
if (rc == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
if (file == null) {
return file;
}
extension.getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
String fileNameLc = file.getAbsolutePath().toLowerCase();
if (!fileNameLc.endsWith(".txt") && !fileNameLc.endsWith(".htm") && !fileNameLc.endsWith(".html")) {
String ext;
if (htmlFilesFilter.equals(chooser.getFileFilter())) {
ext = ".html";
} else {
ext = ".txt";
}
file = new File(file.getAbsolutePath() + ext);
}
return file;
}
return file;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project DistributedFractalNetwork by Budder21.
the class Display method menus.
private JMenuBar menus() {
ToolTipManager.sharedInstance().setInitialDelay(0);
JMenuBar bar = new JMenuBar();
JMenu view = new JMenu("View");
JMenuItem serverLog = new JMenuItem("Server Log");
serverLog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame f = new JFrame("Server Log");
JTextArea textArea = new JTextArea(35, 55);
JScrollPane scroll = new JScrollPane(textArea);
textArea.setText(log.getLog());
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
f.setLayout(new BorderLayout());
f.add(scroll, BorderLayout.CENTER);
JButton b = new JButton("Save");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
fileChooser.setFileFilter(filter);
fileChooser.setCurrentDirectory(new File("fractals/logs"));
fileChooser.showSaveDialog(null);
String dir = fileChooser.getSelectedFile().getPath();
if (!dir.substring(dir.lastIndexOf(".") + 1).equals("txt"))
dir = dir.substring(0, dir.lastIndexOf(".")) + ".txt";
System.out.println("\n\n" + dir + "\n\n");
try {
PrintWriter out = new PrintWriter(dir);
Scanner s = new Scanner(textArea.getText());
while (s.hasNextLine()) out.println(s.nextLine());
out.flush();
out.close();
} catch (FileNotFoundException e1) {
log.addError(e1);
}
}
});
JPanel tempPanel = new JPanel();
tempPanel.add(b);
f.add(tempPanel, BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setResizable(true);
f.setVisible(true);
}
});
serverLog.setToolTipText("Displays the log of the current server.");
view.add(serverLog);
bar.add(view);
return bar;
}
Aggregations