Search in sources :

Example 21 with FileFilter

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());
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JFileChooser(javax.swing.JFileChooser) BoundingBox(aimax.osm.data.BoundingBox) JTable(javax.swing.JTable) Dimension(java.awt.Dimension) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) FileFilter(javax.swing.filechooser.FileFilter)

Example 22 with FileFilter

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(""));
}
Also used : FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 23 with FileFilter

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;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter)

Example 24 with FileFilter

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();
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 25 with FileFilter

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>&nbsp;</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;
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) FilenameFilter(java.io.FilenameFilter) List(java.util.List) ArrayList(java.util.ArrayList) FileFilter(javax.swing.filechooser.FileFilter) JScrollPane(javax.swing.JScrollPane) Pattern(java.util.regex.Pattern) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) FileDialog(java.awt.FileDialog) File(java.io.File)

Aggregations

FileFilter (javax.swing.filechooser.FileFilter)59 File (java.io.File)48 JFileChooser (javax.swing.JFileChooser)39 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)15 IOException (java.io.IOException)10 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)5 DatabaseException (org.parosproxy.paros.db.DatabaseException)5 PCGFile (pcgen.io.PCGFile)5 IllegalContextNameException (org.zaproxy.zap.model.IllegalContextNameException)4 TopLevelWindowManager (cbit.vcell.client.TopLevelWindowManager)3 UserPreferences (cbit.vcell.client.server.UserPreferences)3 ArrayList (java.util.ArrayList)3 Preferences (java.util.prefs.Preferences)3 JButton (javax.swing.JButton)3 Session (org.parosproxy.paros.model.Session)3 Component (java.awt.Component)2 Cursor (java.awt.Cursor)2 Dimension (java.awt.Dimension)2 FileDialog (java.awt.FileDialog)2