use of javax.swing.filechooser.FileFilter in project aima-java by aimacode.
the class MapViewFrame method actionPerformed.
/**
* Defines what happens when a button is pressed.
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loadButton) {
String title = "Load OSM Data";
if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)
title += " (Bounding Box Mode)";
if ((e.getModifiers() & KeyEvent.SHIFT_MASK) != 0)
title += " (Overview Mode)";
fileChooser.setDialogTitle(title);
int returnVal = fileChooser.showDialog(this, "Load");
if (returnVal == JFileChooser.APPROVE_OPTION) {
if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
// ctrl+load -> ask the user for a bounding box.
BoundingBox bb = askForBoundingBox();
if (bb != null)
mapReader.setFilter(bb);
else
return;
}
if ((e.getModifiers() & KeyEvent.SHIFT_MASK) != 0) {
EntityClassifier<Boolean> filter = createOverviewFilter();
mapReader.setFilter(filter);
}
readMap(fileChooser.getSelectedFile());
}
} else if (e.getSource() == saveButton) {
JFileChooser fc = new JFileChooser();
String[] exts = mapWriter.fileFormatDescriptions();
for (int i = 0; i < exts.length; i++) {
FileFilter filter = new FileNameExtensionFilter(exts[i], mapWriter.fileFormatExtensions()[i]);
fc.addChoosableFileFilter(filter);
}
fc.setFileFilter(fc.getChoosableFileFilters()[0]);
fc.setCurrentDirectory(fileChooser.getCurrentDirectory());
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION && (!fc.getSelectedFile().exists() || JOptionPane.showConfirmDialog(this, "File exists, overwrite?", "Confirm", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) {
mapWriter.writeMap(fc.getSelectedFile(), getMap(), view.getBoundingBox());
}
} else if (e.getSource() == statisticsButton) {
Object[][] data = getMap().getStatistics();
JTable table = new JTable(data, new String[] { "Attribute", "Value" });
JScrollPane scroller = new JScrollPane(table);
scroller.setPreferredSize(new Dimension(250, 300));
JOptionPane.showConfirmDialog(this, scroller, "Map Statistics", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == sidebarCheckBox) {
showSidebar(sidebarCheckBox.isSelected());
}
}
use of javax.swing.filechooser.FileFilter in project aima-java by aimacode.
the class MapViewFrame method setMapReader.
public void setMapReader(MapReader mapReader) {
this.mapReader = mapReader;
for (int i = fileChooser.getChoosableFileFilters().length - 1; i > 0; i--) fileChooser.removeChoosableFileFilter(fileChooser.getChoosableFileFilters()[i]);
String[] exts = mapReader.fileFormatDescriptions();
for (int i = 0; i < exts.length; i++) {
FileFilter filter = new FileNameExtensionFilter(exts[i], mapReader.fileFormatExtensions()[i]);
fileChooser.addChoosableFileFilter(filter);
}
fileChooser.setFileFilter(fileChooser.getChoosableFileFilters()[0]);
fileChooser.setSelectedFile(new File(""));
}
use of javax.swing.filechooser.FileFilter in project aima-java by aimacode.
the class MapViewPopup method getFileChooser.
private JFileChooser getFileChooser() {
if (fileChooser == null) {
fileChooser = new JFileChooser();
FileFilter filter = new javax.swing.filechooser.FileNameExtensionFilter("Marker Data (xml)", "xml");
fileChooser.setFileFilter(filter);
}
return fileChooser;
}
use of javax.swing.filechooser.FileFilter in project adempiere by adempiere.
the class PDFViewerBean method save.
public void save() {
final JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
public String getDescription() {
return "PDF File";
}
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".pdf");
}
});
if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
return;
}
File targetFile = fc.getSelectedFile();
if (!targetFile.getName().toLowerCase().endsWith(".pdf")) {
targetFile = new File(targetFile.getParentFile(), targetFile.getName() + ".pdf");
}
if (targetFile.exists()) {
if (JOptionPane.showConfirmDialog(this, "Do you want to overwrite the file?") != JOptionPane.YES_OPTION) {
return;
}
}
try {
final InputStream is = new FileInputStream(filename);
try {
final OutputStream os = new FileOutputStream(targetFile);
try {
final byte[] buffer = new byte[32768];
for (int read; (read = is.read(buffer)) != -1; ) {
os.write(buffer, 0, read);
}
} finally {
os.close();
}
} finally {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of javax.swing.filechooser.FileFilter in project lombok by rzwitserloot.
the class InstallerGUI method buildIdeArea.
private Component buildIdeArea() {
JPanel container = new JPanel();
container.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(8, 0, 0, 16);
container.add(new JLabel(IDE_TITLE), constraints);
constraints.gridy = 1;
container.add(new JLabel(IDE_EXPLANATION), constraints);
constraints.gridy = 2;
loadingExpl = Box.createHorizontalBox();
loadingExpl.add(new JLabel(new ImageIcon(Installer.class.getResource("loading.gif"))));
loadingExpl.add(new JLabel(IDE_LOADING_EXPLANATION));
container.add(loadingExpl, constraints);
constraints.weightx = 1.0;
constraints.gridy = 3;
constraints.fill = GridBagConstraints.HORIZONTAL;
idesList = new IdesList();
JScrollPane idesListScroll = new JScrollPane(idesList);
idesListScroll.setBackground(Color.WHITE);
idesListScroll.getViewport().setBackground(Color.WHITE);
container.add(idesListScroll, constraints);
Thread findIdesThread = new Thread() {
@Override
public void run() {
try {
final List<IdeLocation> locations = new ArrayList<IdeLocation>();
final List<CorruptedIdeLocationException> problems = new ArrayList<CorruptedIdeLocationException>();
Installer.autoDiscover(locations, problems);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (IdeLocation location : locations) {
try {
idesList.addLocation(location);
} catch (Throwable t) {
handleException(t);
}
}
for (CorruptedIdeLocationException problem : problems) {
problem.showDialog(appWindow);
}
loadingExpl.setVisible(false);
if (locations.size() + problems.size() == 0) {
JOptionPane.showMessageDialog(appWindow, "I can't find any IDEs on your computer.\n" + "If you have IDEs installed on this computer, please use the " + "'Specify Location...' button to manually point out the \n" + "location of your IDE installation to me. Thanks!", "Can't find IDE", JOptionPane.INFORMATION_MESSAGE);
}
}
});
} catch (Throwable t) {
handleException(t);
}
}
};
findIdesThread.start();
Box buttonBar = Box.createHorizontalBox();
JButton specifyIdeLocationButton = new JButton("Specify location...");
buttonBar.add(specifyIdeLocationButton);
specifyIdeLocationButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
final List<Pattern> exeNames = Installer.getIdeExecutableNames();
String file = null;
if (OsUtils.getOS() == OS.MAC_OS_X) {
FileDialog chooser = new FileDialog(appWindow);
chooser.setMode(FileDialog.LOAD);
chooser.setFilenameFilter(new FilenameFilter() {
@Override
public boolean accept(File dir, String fileName) {
for (Pattern exeName : exeNames) if (exeName.matcher(fileName).matches())
return true;
return false;
}
});
chooser.setVisible(true);
if (chooser.getDirectory() != null && chooser.getFile() != null) {
file = new File(chooser.getDirectory(), chooser.getFile()).getAbsolutePath();
}
} else {
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory())
return true;
for (Pattern exeName : exeNames) if (exeName.matcher(f.getName()).matches())
return true;
return false;
}
@Override
public String getDescription() {
return "IDE Installation";
}
});
switch(chooser.showDialog(appWindow, "Select")) {
case JFileChooser.APPROVE_OPTION:
file = chooser.getSelectedFile().getAbsolutePath();
}
}
if (file != null) {
try {
IdeLocation loc = Installer.tryAllProviders(file);
if (loc != null)
idesList.addLocation(loc);
else
JOptionPane.showMessageDialog(appWindow, "I can't find any IDE that lombok supports at location: " + file, "No IDE found", JOptionPane.WARNING_MESSAGE);
} catch (CorruptedIdeLocationException e) {
e.showDialog(appWindow);
} catch (Throwable t) {
handleException(t);
}
}
}
});
buttonBar.add(Box.createHorizontalGlue());
installButton = new JButton("Install / Update");
buttonBar.add(installButton);
installButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<IdeLocation> locationsToInstall = new ArrayList<IdeLocation>(idesList.getSelectedIdes());
if (locationsToInstall.isEmpty()) {
JOptionPane.showMessageDialog(appWindow, "You haven't selected any IDE installations!.", "No Selection", JOptionPane.WARNING_MESSAGE);
return;
}
install(locationsToInstall);
}
});
constraints.gridy = 4;
constraints.weightx = 0;
container.add(buttonBar, constraints);
constraints.gridy = 5;
constraints.fill = GridBagConstraints.NONE;
JHyperLink showMe = new JHyperLink("Show me what this installer will do to my IDE installation.");
container.add(showMe, constraints);
showMe.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showWhatIDo();
}
});
constraints.gridy = 6;
uninstallButton = new JHyperLink("Uninstall lombok from selected IDE installations.");
uninstallPlaceholder = new JLabel("<html> </html>");
uninstallButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<IdeLocation> locationsToUninstall = new ArrayList<IdeLocation>();
for (IdeLocation location : idesList.getSelectedIdes()) {
if (location.hasLombok())
locationsToUninstall.add(location);
}
if (locationsToUninstall.isEmpty()) {
JOptionPane.showMessageDialog(appWindow, "You haven't selected any IDE installations that have been lombok-enabled.", "No Selection", JOptionPane.WARNING_MESSAGE);
return;
}
uninstall(locationsToUninstall);
}
});
container.add(uninstallButton, constraints);
uninstallPlaceholder.setVisible(false);
container.add(uninstallPlaceholder, constraints);
container.setPreferredSize(new Dimension(INSTALLER_WINDOW_WIDTH, 296));
return container;
}
Aggregations