Search in sources :

Example 1 with FileFilter

use of javax.swing.filechooser.FileFilter in project SKMCLauncher by SKCraft.

the class FileField method getFileChooser.

@Override
protected JFileChooser getFileChooser() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(title);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return true;
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return chooser;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 2 with FileFilter

use of javax.swing.filechooser.FileFilter in project jphp by jphp-compiler.

the class UIFileChooser method addChoosableExtensions.

@Signature({ @Arg(value = "extensions", type = HintType.ARRAY), @Arg(value = "description"), @Arg(value = "showDirectories", optional = @Optional(value = "1", type = HintType.BOOLEAN)) })
public Memory addChoosableExtensions(final Environment env, final Memory... args) {
    final Set<String> extensions = new HashSet<String>();
    ForeachIterator iterator = args[0].getNewIterator(env, false, false);
    while (iterator.next()) {
        extensions.add(iterator.getValue().toString());
    }
    final String description = args[1].toString();
    component.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return args[2].toBoolean();
            }
            String path = f.getPath();
            for (String ext : extensions) {
                if (Constants.PATH_NAME_CASE_INSENSITIVE) {
                    if (path.endsWith("." + ext))
                        return true;
                } else {
                    if (path.toLowerCase().endsWith("." + ext.toLowerCase()))
                        return true;
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with FileFilter

use of javax.swing.filechooser.FileFilter in project jphp by jphp-compiler.

the class UIFileChooser method addChoosableFilter.

@Signature({ @Arg(value = "filter", type = HintType.CALLABLE), @Arg(value = "description") })
public Memory addChoosableFilter(final Environment env, Memory... args) {
    final Invoker invoker = Invoker.valueOf(env, null, args[0]);
    final String description = args[1].toString();
    component.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return invoker.callNoThrow(new ObjectMemory(new FileObject(env, f))).toBoolean();
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return Memory.NULL;
}
Also used : Invoker(php.runtime.invoke.Invoker) FileObject(php.runtime.ext.core.classes.stream.FileObject) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 4 with FileFilter

use of javax.swing.filechooser.FileFilter in project hid-serial by rayshobby.

the class G4P method selectImpl.

/**
	 * The implementation of the select input and output methods.
	 * @param prompt
	 * @param mode
	 * @param types
	 * @param typeDesc
	 * @return the absolute path name for the selected folder, or null if action 
	 * cancelled.
	 */
private static String selectImpl(String prompt, int mode, String types, String typeDesc) {
    // If no initial selection made then use last selection	
    // Assume that a file will not be selected
    String selectedFile = null;
    // Get the owner
    Frame owner = (sketchApplet == null) ? null : sketchApplet.frame;
    // Create a file filter
    if (PApplet.useNativeSelect) {
        FileDialog dialog = new FileDialog(owner, prompt, mode);
        FilenameFilter filter = null;
        if (types != null && types.length() > 0) {
            filter = new FilenameChooserFilter(types);
            dialog.setFilenameFilter(filter);
        }
        dialog.setVisible(true);
        String directory = dialog.getDirectory();
        if (directory != null) {
            selectedFile = dialog.getFile();
            if (selectedFile != null) {
                try {
                    selectedFile = (new File(directory, selectedFile)).getCanonicalPath();
                } catch (IOException e) {
                    selectedFile = null;
                }
            }
        }
    } else {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle(prompt);
        FileFilter filter = null;
        if (types != null && types.length() > 0) {
            filter = new FileChooserFilter(types, typeDesc);
            chooser.setFileFilter(filter);
        }
        int result = JFileChooser.ERROR_OPTION;
        if (mode == FileDialog.SAVE) {
            result = chooser.showSaveDialog(owner);
        } else if (mode == FileDialog.LOAD) {
            result = chooser.showOpenDialog(owner);
        }
        if (result == JFileChooser.APPROVE_OPTION) {
            try {
                selectedFile = chooser.getSelectedFile().getCanonicalPath();
            } catch (IOException e) {
                selectedFile = null;
            }
        }
    }
    return selectedFile;
}
Also used : FilenameFilter(java.io.FilenameFilter) Frame(java.awt.Frame) JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) FileDialog(java.awt.FileDialog) File(java.io.File)

Example 5 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)55 File (java.io.File)44 JFileChooser (javax.swing.JFileChooser)39 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)15 IOException (java.io.IOException)10 ActionEvent (java.awt.event.ActionEvent)6 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 Preferences (java.util.prefs.Preferences)3 JButton (javax.swing.JButton)3 Session (org.parosproxy.paros.model.Session)3 Cursor (java.awt.Cursor)2 Dimension (java.awt.Dimension)2 FileDialog (java.awt.FileDialog)2 BufferedImage (java.awt.image.BufferedImage)2 FileOutputStream (java.io.FileOutputStream)2 FilenameFilter (java.io.FilenameFilter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2