Search in sources :

Example 16 with FileDialog

use of java.awt.FileDialog 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));
    container.setMinimumSize(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)

Example 17 with FileDialog

use of java.awt.FileDialog in project pdfbox by apache.

the class PDFDebugger method openMenuItemActionPerformed.

private void openMenuItemActionPerformed(ActionEvent evt) {
    try {
        if (IS_MAC_OS) {
            FileDialog openDialog = new FileDialog(this, "Open");
            openDialog.setFilenameFilter(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".pdf");
                }
            });
            openDialog.setVisible(true);
            if (openDialog.getFile() != null) {
                readPDFFile(openDialog.getFile(), "");
            }
        } else {
            String[] extensions = new String[] { "pdf", "PDF" };
            FileFilter pdfFilter = new ExtensionFileFilter(extensions, "PDF Files (*.pdf)");
            FileOpenSaveDialog openDialog = new FileOpenSaveDialog(this, pdfFilter);
            File file = openDialog.openFile();
            if (file != null) {
                readPDFFile(file, "");
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) COSString(org.apache.pdfbox.cos.COSString) IOException(java.io.IOException) ExtensionFileFilter(org.apache.pdfbox.debugger.ui.ExtensionFileFilter) FileFilter(javax.swing.filechooser.FileFilter) FileDialog(java.awt.FileDialog) File(java.io.File) ExtensionFileFilter(org.apache.pdfbox.debugger.ui.ExtensionFileFilter) FileOpenSaveDialog(org.apache.pdfbox.debugger.ui.FileOpenSaveDialog)

Example 18 with FileDialog

use of java.awt.FileDialog in project algs4 by kevin-wayne.

the class Picture method actionPerformed.

/**
 * Opens a save dialog box when the user selects "Save As" from the menu.
 */
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog chooser = new FileDialog(frame, "Use a .png or .jpg extension", FileDialog.SAVE);
    chooser.setVisible(true);
    if (chooser.getFile() != null) {
        save(chooser.getDirectory() + File.separator + chooser.getFile());
    }
}
Also used : FileDialog(java.awt.FileDialog)

Example 19 with FileDialog

use of java.awt.FileDialog in project algs4 by kevin-wayne.

the class Draw method actionPerformed.

/**
 * This method cannot be called directly.
 */
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog chooser = new FileDialog(frame, "Use a .png or .jpg extension", FileDialog.SAVE);
    chooser.setVisible(true);
    String filename = chooser.getFile();
    if (filename != null) {
        save(chooser.getDirectory() + File.separator + chooser.getFile());
    }
}
Also used : FileDialog(java.awt.FileDialog)

Example 20 with FileDialog

use of java.awt.FileDialog in project AlgorithmsSolutions by Allenskoo856.

the class StdDraw method actionPerformed.

/**
 * This method cannot be called directly.
 */
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog chooser = new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
    chooser.setVisible(true);
    String filename = chooser.getFile();
    if (filename != null) {
        StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
    }
}
Also used : FileDialog(java.awt.FileDialog)

Aggregations

FileDialog (java.awt.FileDialog)78 File (java.io.File)43 JFileChooser (javax.swing.JFileChooser)18 Frame (java.awt.Frame)16 IOException (java.io.IOException)16 FilenameFilter (java.io.FilenameFilter)10 Dialog (java.awt.Dialog)8 FileFilter (javax.swing.filechooser.FileFilter)7 FileOutputStream (java.io.FileOutputStream)5 PrintStream (java.io.PrintStream)4 Button (java.awt.Button)3 Dimension (java.awt.Dimension)3 MenuItem (java.awt.MenuItem)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 MalformedURLException (java.net.MalformedURLException)3 SQLException (java.sql.SQLException)3 JLabel (javax.swing.JLabel)3 Component (java.awt.Component)2 GridLayout (java.awt.GridLayout)2