Search in sources :

Example 26 with JLabel

use of javax.swing.JLabel in project lombok by rzwitserloot.

the class InstallerGUI method buildSuccessArea.

private Component buildSuccessArea() {
    JPanel container = new JPanel();
    container.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    JLabel title;
    container.add(title = new JLabel(SUCCESS_TITLE), constraints);
    title.setPreferredSize(new Dimension(INSTALLER_WINDOW_WIDTH - 82, 20));
    constraints.gridy = 1;
    constraints.insets = new Insets(8, 0, 0, 16);
    container.add(successExplanation = new JLabel(SUCCESS_EXPLANATION), constraints);
    successExplanation.setPreferredSize(new Dimension(INSTALLER_WINDOW_WIDTH - 82, 175));
    successExplanation.setMinimumSize(new Dimension(INSTALLER_WINDOW_WIDTH - 82, 175));
    constraints.gridy++;
    constraints.fill = GridBagConstraints.BOTH;
    JTextPane notes = new JTextPane();
    notes.setContentType("text/html");
    notes.setText(readChangeLog());
    notes.setEditable(false);
    notes.setOpaque(false);
    notes.setBorder(null);
    notes.setSelectionStart(0);
    notes.setSelectionEnd(0);
    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument) notes.getDocument()).getStyleSheet().addRule(bodyRule);
    JScrollPane scroller = new JScrollPane(notes);
    container.add(scroller, constraints);
    scroller.setPreferredSize(new Dimension(INSTALLER_WINDOW_WIDTH - 82, 200));
    scroller.setMinimumSize(new Dimension(INSTALLER_WINDOW_WIDTH - 82, 200));
    container.setPreferredSize(new Dimension(INSTALLER_WINDOW_WIDTH, 415));
    container.setMinimumSize(new Dimension(INSTALLER_WINDOW_WIDTH, 415));
    return container;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextPane(javax.swing.JTextPane) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Font(java.awt.Font)

Example 27 with JLabel

use of javax.swing.JLabel 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)

Example 28 with JLabel

use of javax.swing.JLabel in project lombok by rzwitserloot.

the class InstallerGUI method buildUninstallArea.

private Component buildUninstallArea() {
    JPanel container = new JPanel();
    container.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    container.add(new JLabel(UNINSTALL_TITLE), constraints);
    constraints.gridy = 1;
    constraints.insets = new Insets(8, 0, 0, 16);
    container.add(new JLabel(UNINSTALL_EXPLANATION), constraints);
    uninstallBox = Box.createVerticalBox();
    constraints.gridy = 2;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    container.add(uninstallBox, constraints);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridy = 3;
    container.add(new JLabel("Are you sure?"), constraints);
    Box buttonBar = Box.createHorizontalBox();
    JButton noButton = new JButton("No - Don't uninstall");
    buttonBar.add(noButton);
    buttonBar.add(Box.createHorizontalGlue());
    JButton yesButton = new JButton("Yes - uninstall Lombok");
    buttonBar.add(yesButton);
    noButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            uninstallArea.setVisible(false);
            javacArea.setVisible(true);
            ideArea.setVisible(true);
            appWindow.pack();
        }
    });
    yesButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            doUninstall();
        }
    });
    constraints.gridy = 4;
    container.add(buttonBar, constraints);
    container.setPreferredSize(new Dimension(INSTALLER_WINDOW_WIDTH, 415));
    return container;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension)

Example 29 with JLabel

use of javax.swing.JLabel in project lombok by rzwitserloot.

the class InstallerGUI method doUninstall.

private void doUninstall() {
    JPanel spinner = new JPanel();
    spinner.setOpaque(true);
    spinner.setLayout(new FlowLayout());
    spinner.add(new JLabel(new ImageIcon(Installer.class.getResource("/lombok/installer/loading.gif"))));
    final Container originalContentPane = appWindow.getContentPane();
    appWindow.setContentPane(spinner);
    final AtomicInteger successes = new AtomicInteger();
    new Thread(new Runnable() {

        @Override
        public void run() {
            for (IdeLocation loc : toUninstall) {
                try {
                    loc.uninstall();
                    successes.incrementAndGet();
                } catch (final UninstallException e) {
                    if (e.isWarning()) {
                        try {
                            SwingUtilities.invokeAndWait(new Runnable() {

                                @Override
                                public void run() {
                                    JOptionPane.showMessageDialog(appWindow, e.getMessage(), "Uninstall Problem", JOptionPane.WARNING_MESSAGE);
                                }
                            });
                        } catch (Exception e2) {
                            e2.printStackTrace();
                            //Shouldn't happen.
                            throw new RuntimeException(e2);
                        }
                    } else {
                        try {
                            SwingUtilities.invokeAndWait(new Runnable() {

                                @Override
                                public void run() {
                                    JOptionPane.showMessageDialog(appWindow, e.getMessage(), "Uninstall Problem", JOptionPane.ERROR_MESSAGE);
                                }
                            });
                        } catch (Exception e2) {
                            e2.printStackTrace();
                            //Shouldn't happen.
                            throw new RuntimeException(e2);
                        }
                    }
                }
            }
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (successes.get() > 0) {
                        JOptionPane.showMessageDialog(appWindow, "Lombok has been removed from the selected IDE installations.", "Uninstall successful", JOptionPane.INFORMATION_MESSAGE);
                        appWindow.setVisible(false);
                        System.exit(0);
                        return;
                    }
                    appWindow.setContentPane(originalContentPane);
                }
            });
        }
    }).start();
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) FlowLayout(java.awt.FlowLayout) JLabel(javax.swing.JLabel) Container(java.awt.Container) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 30 with JLabel

use of javax.swing.JLabel in project lombok by rzwitserloot.

the class InstallerGUI method buildChrome.

private void buildChrome(Container appWindowContainer) {
    JLabel leftGraphic = new JLabel(new ImageIcon(Installer.class.getResource("lombok.png")));
    GridBagConstraints constraints = new GridBagConstraints();
    appWindowContainer.setLayout(new GridBagLayout());
    constraints.gridheight = 3;
    constraints.gridwidth = 1;
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.insets = new Insets(8, 8, 8, 8);
    appWindowContainer.add(leftGraphic, constraints);
    constraints.insets = new Insets(0, 0, 0, 0);
    constraints.gridx++;
    constraints.gridy++;
    constraints.gridheight = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.ipadx = 16;
    constraints.ipady = 14;
    appWindowContainer.add(javacArea, constraints);
    constraints.gridy++;
    appWindowContainer.add(ideArea, constraints);
    appWindowContainer.add(uninstallArea, constraints);
    appWindowContainer.add(howIWorkArea, constraints);
    appWindowContainer.add(successArea, constraints);
    constraints.gridy++;
    constraints.gridwidth = 2;
    constraints.gridx = 0;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.ipadx = 0;
    constraints.ipady = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.SOUTHWEST;
    constraints.insets = new Insets(0, 16, 8, 8);
    appWindow.add(buildButtonBar(), constraints);
}
Also used : ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel)

Aggregations

JLabel (javax.swing.JLabel)1208 JPanel (javax.swing.JPanel)737 JButton (javax.swing.JButton)280 BoxLayout (javax.swing.BoxLayout)251 GridBagLayout (java.awt.GridBagLayout)243 BorderLayout (java.awt.BorderLayout)239 Dimension (java.awt.Dimension)221 JScrollPane (javax.swing.JScrollPane)210 GridBagConstraints (java.awt.GridBagConstraints)205 ActionEvent (java.awt.event.ActionEvent)203 JTextField (javax.swing.JTextField)193 ActionListener (java.awt.event.ActionListener)183 Insets (java.awt.Insets)166 FlowLayout (java.awt.FlowLayout)156 JCheckBox (javax.swing.JCheckBox)125 JComboBox (javax.swing.JComboBox)77 JTable (javax.swing.JTable)69 ImageIcon (javax.swing.ImageIcon)63 Container (java.awt.Container)61 Font (java.awt.Font)60