Search in sources :

Example 16 with JComponent

use of javax.swing.JComponent in project gephi by gephi.

the class GraphFileExporterUI method action.

@Override
public void action() {
    final String LAST_PATH = "GraphFileExporterUI_Last_Path";
    final String LAST_PATH_DEFAULT = "GraphFileExporterUI_Last_Path_Default";
    final ExportControllerUI exportController = Lookup.getDefault().lookup(ExportControllerUI.class);
    if (exportController == null) {
        return;
    }
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH, lastPathDefault);
    //Options panel
    FlowLayout layout = new FlowLayout(FlowLayout.RIGHT);
    JPanel optionsPanel = new JPanel(layout);
    final JButton optionsButton = new JButton(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsButton_name"));
    optionsPanel.add(optionsButton);
    optionsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ExporterUI exporterUI = exportController.getExportController().getUI(selectedExporter);
            if (exporterUI != null) {
                JPanel panel = exporterUI.getPanel();
                exporterUI.setup(selectedExporter);
                DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsDialog_title", selectedBuilder.getName()));
                TopDialog topDialog = new TopDialog(dialog, dd.getTitle(), dd.isModal(), dd, dd.getClosingOptions(), dd.getButtonListener());
                topDialog.setVisible(true);
                Object result = (dd.getValue() != null) ? dd.getValue() : NotifyDescriptor.CLOSED_OPTION;
                //                    Object result = DialogDisplayer.getDefault().notify(dd);
                exporterUI.unsetup(result == NotifyDescriptor.OK_OPTION);
            }
        }
    });
    //Graph Settings Panel
    final JPanel southPanel = new JPanel(new BorderLayout());
    southPanel.add(optionsPanel, BorderLayout.NORTH);
    GraphFileExporterUIPanel graphSettings = new GraphFileExporterUIPanel();
    graphSettings.setVisibleOnlyGraph(visibleOnlyGraph);
    southPanel.add(graphSettings, BorderLayout.CENTER);
    //Optionable file chooser
    final JFileChooser chooser = new JFileChooser(lastPath) {

        @Override
        protected JDialog createDialog(Component parent) throws HeadlessException {
            dialog = super.createDialog(parent);
            dialog.setSize(640, 480);
            dialog.setResizable(true);
            Component c = dialog.getContentPane().getComponent(0);
            if (c != null && c instanceof JComponent) {
                Insets insets = ((JComponent) c).getInsets();
                southPanel.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
            }
            dialog.getContentPane().add(southPanel, BorderLayout.SOUTH);
            return dialog;
        }

        @Override
        public void approveSelection() {
            if (canExport(this)) {
                super.approveSelection();
            }
        }
    };
    chooser.setDialogTitle(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_filechooser_title"));
    chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            DialogFileFilter fileFilter = (DialogFileFilter) evt.getNewValue();
            //Options panel enabling
            selectedBuilder = getExporter(fileFilter);
            if (selectedBuilder != null) {
                selectedExporter = selectedBuilder.buildExporter();
            }
            if (selectedBuilder != null && exportController.getExportController().getUI(selectedExporter) != null) {
                optionsButton.setEnabled(true);
            } else {
                optionsButton.setEnabled(false);
            }
            //Selected file extension change
            if (selectedFile != null && fileFilter != null) {
                String fileName = selectedFile.getName();
                String directoryPath = chooser.getCurrentDirectory().getAbsolutePath();
                if (fileName.lastIndexOf(".") != -1) {
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                    fileName = fileName.concat(fileFilter.getExtensions().get(0));
                    selectedFile = new File(directoryPath, fileName);
                    chooser.setSelectedFile(selectedFile);
                }
            }
        }
    });
    chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue() != null) {
                selectedFile = (File) evt.getNewValue();
            }
        }
    });
    //File filters
    DialogFileFilter defaultFilter = null;
    for (GraphFileExporterBuilder graphFileExporter : Lookup.getDefault().lookupAll(GraphFileExporterBuilder.class)) {
        for (FileType fileType : graphFileExporter.getFileTypes()) {
            DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
            dialogFileFilter.addExtensions(fileType.getExtensions());
            if (defaultFilter == null) {
                defaultFilter = dialogFileFilter;
            }
            chooser.addChoosableFileFilter(dialogFileFilter);
        }
    }
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(defaultFilter);
    selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFilter.getExtensions().get(0));
    chooser.setSelectedFile(selectedFile);
    //Show
    int returnFile = chooser.showSaveDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        file = FileUtil.normalizeFile(file);
        FileObject fileObject = FileUtil.toFileObject(file);
        //Save last path
        NbPreferences.forModule(GraphFileExporterUI.class).put(LAST_PATH, file.getAbsolutePath());
        //Save variable
        visibleOnlyGraph = graphSettings.isVisibleOnlyGraph();
        //Do
        selectedExporter.setExportVisible(visibleOnlyGraph);
        exportController.exportFile(fileObject, selectedExporter);
    }
    dialog = null;
}
Also used : JPanel(javax.swing.JPanel) GraphFileExporterBuilder(org.gephi.io.exporter.spi.GraphFileExporterBuilder) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) ExporterUI(org.gephi.io.exporter.spi.ExporterUI) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GraphFileExporterUIPanel(org.gephi.desktop.io.export.GraphFileExporterUIPanel) BorderLayout(java.awt.BorderLayout) FileObject(org.openide.filesystems.FileObject) JComponent(javax.swing.JComponent) Component(java.awt.Component) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) ExportControllerUI(org.gephi.desktop.io.export.ExportControllerUI) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) FileType(org.gephi.io.exporter.api.FileType) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 17 with JComponent

use of javax.swing.JComponent in project gephi by gephi.

the class VectorialFileExporterUI method action.

@Override
public void action() {
    final String LAST_PATH = "VectorialFileExporterUI_Last_Path";
    final String LAST_PATH_DEFAULT = "VectorialFileExporterUI_Last_Path_Default";
    final ExportControllerUI exportController = Lookup.getDefault().lookup(ExportControllerUI.class);
    if (exportController == null) {
        return;
    }
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(VectorialFileExporterUI.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(VectorialFileExporterUI.class).get(LAST_PATH, lastPathDefault);
    //Options panel
    FlowLayout layout = new FlowLayout(FlowLayout.RIGHT);
    JPanel optionsPanel = new JPanel(layout);
    final JButton optionsButton = new JButton(NbBundle.getMessage(VectorialFileExporterUI.class, "VectorialFileExporterUI_optionsButton_name"));
    optionsPanel.add(optionsButton);
    optionsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ExporterUI exporterUI = exportController.getExportController().getUI(selectedExporter);
            if (exporterUI != null) {
                JPanel panel = exporterUI.getPanel();
                exporterUI.setup(selectedExporter);
                DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(VectorialFileExporterUI.class, "VectorialFileExporterUI_optionsDialog_title", selectedBuilder.getName()));
                TopDialog topDialog = new TopDialog(dialog, dd.getTitle(), dd.isModal(), dd, dd.getClosingOptions(), dd.getButtonListener());
                topDialog.setVisible(true);
                Object result = (dd.getValue() != null) ? dd.getValue() : NotifyDescriptor.CLOSED_OPTION;
                //                    Object result = DialogDisplayer.getDefault().notify(dd);
                exporterUI.unsetup(result == NotifyDescriptor.OK_OPTION);
            }
        }
    });
    //Graph Settings Panel
    final JPanel southPanel = new JPanel(new BorderLayout());
    southPanel.add(optionsPanel, BorderLayout.NORTH);
    //Optionable file chooser
    final JFileChooser chooser = new JFileChooser(lastPath) {

        @Override
        protected JDialog createDialog(Component parent) throws HeadlessException {
            dialog = super.createDialog(parent);
            Component c = dialog.getContentPane().getComponent(0);
            if (c != null && c instanceof JComponent) {
                Insets insets = ((JComponent) c).getInsets();
                southPanel.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
            }
            dialog.getContentPane().add(southPanel, BorderLayout.SOUTH);
            return dialog;
        }

        @Override
        public void approveSelection() {
            if (canExport(this)) {
                super.approveSelection();
            }
        }
    };
    chooser.setDialogTitle(NbBundle.getMessage(VectorialFileExporterUI.class, "VectorialFileExporterUI_filechooser_title"));
    chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            DialogFileFilter fileFilter = (DialogFileFilter) evt.getNewValue();
            //Options panel enabling
            selectedBuilder = getExporter(fileFilter);
            if (selectedBuilder != null) {
                selectedExporter = selectedBuilder.buildExporter();
            }
            if (selectedExporter != null && exportController.getExportController().getUI(selectedExporter) != null) {
                optionsButton.setEnabled(true);
            } else {
                optionsButton.setEnabled(false);
            }
            //Selected file extension change
            if (selectedFile != null && fileFilter != null) {
                String fileName = selectedFile.getName();
                String directoryPath = chooser.getCurrentDirectory().getAbsolutePath();
                if (fileName.lastIndexOf(".") != -1) {
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                    fileName = fileName.concat(fileFilter.getExtensions().get(0));
                    selectedFile = new File(directoryPath, fileName);
                    chooser.setSelectedFile(selectedFile);
                }
            }
        }
    });
    chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue() != null) {
                selectedFile = (File) evt.getNewValue();
            }
        }
    });
    //File filters
    DialogFileFilter defaultFilter = null;
    for (VectorFileExporterBuilder vectorFileExporter : Lookup.getDefault().lookupAll(VectorFileExporterBuilder.class)) {
        for (FileType fileType : vectorFileExporter.getFileTypes()) {
            DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
            dialogFileFilter.addExtensions(fileType.getExtensions());
            if (defaultFilter == null) {
                defaultFilter = dialogFileFilter;
            }
            chooser.addChoosableFileFilter(dialogFileFilter);
        }
    }
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(defaultFilter);
    selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFilter.getExtensions().get(0));
    chooser.setSelectedFile(selectedFile);
    //Show
    int returnFile = chooser.showSaveDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        file = FileUtil.normalizeFile(file);
        FileObject fileObject = FileUtil.toFileObject(file);
        //Save last path
        NbPreferences.forModule(VectorialFileExporterUI.class).put(LAST_PATH, file.getAbsolutePath());
        //Do
        exportController.exportFile(fileObject, selectedExporter);
    }
    dialog = null;
}
Also used : JPanel(javax.swing.JPanel) VectorFileExporterBuilder(org.gephi.io.exporter.spi.VectorFileExporterBuilder) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) ExporterUI(org.gephi.io.exporter.spi.ExporterUI) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) BorderLayout(java.awt.BorderLayout) FileObject(org.openide.filesystems.FileObject) JComponent(javax.swing.JComponent) Component(java.awt.Component) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) ExportControllerUI(org.gephi.desktop.io.export.ExportControllerUI) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) FileType(org.gephi.io.exporter.api.FileType) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 18 with JComponent

use of javax.swing.JComponent in project gephi by gephi.

the class PropertiesBar method select.

public void select(JPanel propertiesBar) {
    this.propertiesBar = propertiesBar;
    propertiesBar.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
    add(propertiesBar, BorderLayout.CENTER);
    propertiesBar.setOpaque(false);
    for (Component c : propertiesBar.getComponents()) {
        if (c instanceof JPanel || c instanceof JToolBar) {
            ((JComponent) c).setOpaque(false);
        }
    }
    revalidate();
}
Also used : JPanel(javax.swing.JPanel) JComponent(javax.swing.JComponent) JToolBar(javax.swing.JToolBar) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 19 with JComponent

use of javax.swing.JComponent in project gitblit by gitblit.

the class GitblitAuthority method getUI.

private Container getUI() {
    userCertificatePanel = new UserCertificatePanel(this) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }

        @Override
        public boolean isAllowEmail() {
            return mail.isReady();
        }

        @Override
        public Date getDefaultExpiration() {
            Calendar c = Calendar.getInstance();
            c.add(Calendar.DATE, defaultDuration);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);
            return c.getTime();
        }

        @Override
        public boolean saveUser(String username, UserCertificateModel ucm) {
            return userService.updateUserModel(username, ucm.user);
        }

        @Override
        public boolean newCertificate(UserCertificateModel ucm, X509Metadata metadata, boolean sendEmail) {
            if (!prepareX509Infrastructure()) {
                return false;
            }
            Date notAfter = metadata.notAfter;
            setMetadataDefaults(metadata);
            metadata.notAfter = notAfter;
            // set user's specified OID values
            UserModel user = ucm.user;
            if (!StringUtils.isEmpty(user.organizationalUnit)) {
                metadata.oids.put("OU", user.organizationalUnit);
            }
            if (!StringUtils.isEmpty(user.organization)) {
                metadata.oids.put("O", user.organization);
            }
            if (!StringUtils.isEmpty(user.locality)) {
                metadata.oids.put("L", user.locality);
            }
            if (!StringUtils.isEmpty(user.stateProvince)) {
                metadata.oids.put("ST", user.stateProvince);
            }
            if (!StringUtils.isEmpty(user.countryCode)) {
                metadata.oids.put("C", user.countryCode);
            }
            File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
            File zip = X509Utils.newClientBundle(user, metadata, caKeystoreFile, caKeystorePassword, GitblitAuthority.this);
            // save latest expiration date
            if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {
                ucm.expires = metadata.notAfter;
            }
            updateAuthorityConfig(ucm);
            // refresh user
            ucm.certs = null;
            int selectedIndex = table.getSelectedRow();
            tableModel.fireTableDataChanged();
            table.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
            if (sendEmail) {
                sendEmail(user, metadata, zip);
            }
            return true;
        }

        @Override
        public boolean revoke(UserCertificateModel ucm, X509Certificate cert, RevocationReason reason) {
            if (!prepareX509Infrastructure()) {
                return false;
            }
            File caRevocationList = new File(folder, X509Utils.CA_REVOCATION_LIST);
            File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
            if (X509Utils.revoke(cert, reason, caRevocationList, caKeystoreFile, caKeystorePassword, GitblitAuthority.this)) {
                File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
                FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
                if (certificatesConfigFile.exists()) {
                    try {
                        config.load();
                    } catch (Exception e) {
                        Utils.showException(GitblitAuthority.this, e);
                    }
                }
                // add serial to revoked list
                ucm.revoke(cert.getSerialNumber(), reason);
                ucm.update(config);
                try {
                    config.save();
                } catch (Exception e) {
                    Utils.showException(GitblitAuthority.this, e);
                }
                // refresh user
                ucm.certs = null;
                int modelIndex = table.convertRowIndexToModel(table.getSelectedRow());
                tableModel.fireTableDataChanged();
                table.getSelectionModel().setSelectionInterval(modelIndex, modelIndex);
                return true;
            }
            return false;
        }
    };
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    table.setRowSorter(defaultSorter);
    table.setDefaultRenderer(CertificateStatus.class, new CertificateStatusRenderer());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            int row = table.getSelectedRow();
            if (row < 0) {
                return;
            }
            int modelIndex = table.convertRowIndexToModel(row);
            UserCertificateModel ucm = tableModel.get(modelIndex);
            if (ucm.certs == null) {
                ucm.certs = findCerts(folder, ucm.user.username);
            }
            userCertificatePanel.setUserCertificateModel(ucm);
        }
    });
    JPanel usersPanel = new JPanel(new BorderLayout()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }
    };
    usersPanel.add(new HeaderPanel(Translation.get("gb.users"), "users_16x16.png"), BorderLayout.NORTH);
    usersPanel.add(new JScrollPane(table), BorderLayout.CENTER);
    usersPanel.setMinimumSize(new Dimension(400, 10));
    certificateDefaultsButton = new JButton(new ImageIcon(getClass().getResource("/settings_16x16.png")));
    certificateDefaultsButton.setFocusable(false);
    certificateDefaultsButton.setToolTipText(Translation.get("gb.newCertificateDefaults"));
    certificateDefaultsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            X509Metadata metadata = new X509Metadata("whocares", "whocares");
            File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
            FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
            NewCertificateConfig certificateConfig = null;
            if (certificatesConfigFile.exists()) {
                try {
                    config.load();
                } catch (Exception x) {
                    Utils.showException(GitblitAuthority.this, x);
                }
                certificateConfig = NewCertificateConfig.KEY.parse(config);
                certificateConfig.update(metadata);
            }
            InputVerifier verifier = new InputVerifier() {

                @Override
                public boolean verify(JComponent comp) {
                    boolean returnValue;
                    JTextField textField = (JTextField) comp;
                    try {
                        Integer.parseInt(textField.getText());
                        returnValue = true;
                    } catch (NumberFormatException e) {
                        returnValue = false;
                    }
                    return returnValue;
                }
            };
            JTextField siteNameTF = new JTextField(20);
            siteNameTF.setText(gitblitSettings.getString(Keys.web.siteName, "Gitblit"));
            JPanel siteNamePanel = Utils.newFieldPanel(Translation.get("gb.siteName"), siteNameTF, Translation.get("gb.siteNameDescription"));
            JTextField validityTF = new JTextField(4);
            validityTF.setInputVerifier(verifier);
            validityTF.setVerifyInputWhenFocusTarget(true);
            validityTF.setText("" + certificateConfig.duration);
            JPanel validityPanel = Utils.newFieldPanel(Translation.get("gb.validity"), validityTF, Translation.get("gb.duration.days").replace("{0}", "").trim());
            JPanel p1 = new JPanel(new GridLayout(0, 1, 5, 2));
            p1.add(siteNamePanel);
            p1.add(validityPanel);
            DefaultOidsPanel oids = new DefaultOidsPanel(metadata);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(p1, BorderLayout.NORTH);
            panel.add(oids, BorderLayout.CENTER);
            int result = JOptionPane.showConfirmDialog(GitblitAuthority.this, panel, Translation.get("gb.newCertificateDefaults"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(getClass().getResource("/settings_32x32.png")));
            if (result == JOptionPane.OK_OPTION) {
                try {
                    oids.update(metadata);
                    certificateConfig.duration = Integer.parseInt(validityTF.getText());
                    certificateConfig.store(config, metadata);
                    config.save();
                    Map<String, String> updates = new HashMap<String, String>();
                    updates.put(Keys.web.siteName, siteNameTF.getText());
                    gitblitSettings.saveSettings(updates);
                } catch (Exception e1) {
                    Utils.showException(GitblitAuthority.this, e1);
                }
            }
        }
    });
    newSSLCertificate = new JButton(new ImageIcon(getClass().getResource("/rosette_16x16.png")));
    newSSLCertificate.setFocusable(false);
    newSSLCertificate.setToolTipText(Translation.get("gb.newSSLCertificate"));
    newSSLCertificate.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Date defaultExpiration = new Date(System.currentTimeMillis() + 10 * TimeUtils.ONEYEAR);
            NewSSLCertificateDialog dialog = new NewSSLCertificateDialog(GitblitAuthority.this, defaultExpiration);
            dialog.setModal(true);
            dialog.setVisible(true);
            if (dialog.isCanceled()) {
                return;
            }
            final Date expires = dialog.getExpiration();
            final String hostname = dialog.getHostname();
            final boolean serveCertificate = dialog.isServeCertificate();
            AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {

                @Override
                protected Boolean doRequest() throws IOException {
                    if (!prepareX509Infrastructure()) {
                        return false;
                    }
                    // read CA private key and certificate
                    File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
                    PrivateKey caPrivateKey = X509Utils.getPrivateKey(X509Utils.CA_ALIAS, caKeystoreFile, caKeystorePassword);
                    X509Certificate caCert = X509Utils.getCertificate(X509Utils.CA_ALIAS, caKeystoreFile, caKeystorePassword);
                    // generate new SSL certificate
                    X509Metadata metadata = new X509Metadata(hostname, caKeystorePassword);
                    setMetadataDefaults(metadata);
                    metadata.notAfter = expires;
                    File serverKeystoreFile = new File(folder, X509Utils.SERVER_KEY_STORE);
                    X509Certificate cert = X509Utils.newSSLCertificate(metadata, caPrivateKey, caCert, serverKeystoreFile, GitblitAuthority.this);
                    boolean hasCert = cert != null;
                    if (hasCert && serveCertificate) {
                        // update Gitblit https connector alias
                        Map<String, String> updates = new HashMap<String, String>();
                        updates.put(Keys.server.certificateAlias, metadata.commonName);
                        gitblitSettings.saveSettings(updates);
                    }
                    return hasCert;
                }

                @Override
                protected void onSuccess() {
                    if (serveCertificate) {
                        JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.sslCertificateGeneratedRestart"), hostname), Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.sslCertificateGenerated"), hostname), Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            };
            worker.execute();
        }
    });
    JButton emailBundle = new JButton(new ImageIcon(getClass().getResource("/mail_16x16.png")));
    emailBundle.setFocusable(false);
    emailBundle.setToolTipText(Translation.get("gb.emailCertificateBundle"));
    emailBundle.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int row = table.getSelectedRow();
            if (row < 0) {
                return;
            }
            int modelIndex = table.convertRowIndexToModel(row);
            final UserCertificateModel ucm = tableModel.get(modelIndex);
            if (ArrayUtils.isEmpty(ucm.certs)) {
                JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.pleaseGenerateClientCertificate"), ucm.user.getDisplayName()));
            }
            final File zip = new File(folder, X509Utils.CERTS + File.separator + ucm.user.username + File.separator + ucm.user.username + ".zip");
            if (!zip.exists()) {
                return;
            }
            AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {

                @Override
                protected Boolean doRequest() throws IOException {
                    X509Metadata metadata = new X509Metadata(ucm.user.username, "whocares");
                    metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);
                    if (StringUtils.isEmpty(metadata.serverHostname)) {
                        metadata.serverHostname = Constants.NAME;
                    }
                    metadata.userDisplayname = ucm.user.getDisplayName();
                    return sendEmail(ucm.user, metadata, zip);
                }

                @Override
                protected void onSuccess() {
                    JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.clientCertificateBundleSent"), ucm.user.getDisplayName()));
                }
            };
            worker.execute();
        }
    });
    JButton logButton = new JButton(new ImageIcon(getClass().getResource("/script_16x16.png")));
    logButton.setFocusable(false);
    logButton.setToolTipText(Translation.get("gb.log"));
    logButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            File log = new File(folder, X509Utils.CERTS + File.separator + "log.txt");
            if (log.exists()) {
                String content = FileUtils.readContent(log, "\n");
                JTextArea textarea = new JTextArea(content);
                JScrollPane scrollPane = new JScrollPane(textarea);
                scrollPane.setPreferredSize(new Dimension(700, 400));
                JOptionPane.showMessageDialog(GitblitAuthority.this, scrollPane, log.getAbsolutePath(), JOptionPane.INFORMATION_MESSAGE);
            }
        }
    });
    final JTextField filterTextfield = new JTextField(15);
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    JToolBar buttonControls = new JToolBar(JToolBar.HORIZONTAL);
    buttonControls.setFloatable(false);
    buttonControls.add(certificateDefaultsButton);
    buttonControls.add(newSSLCertificate);
    buttonControls.add(emailBundle);
    buttonControls.add(logButton);
    JPanel userControls = new JPanel(new FlowLayout(FlowLayout.RIGHT, Utils.MARGIN, Utils.MARGIN));
    userControls.add(new JLabel(Translation.get("gb.filter")));
    userControls.add(filterTextfield);
    JPanel topPanel = new JPanel(new BorderLayout(0, 0));
    topPanel.add(buttonControls, BorderLayout.WEST);
    topPanel.add(userControls, BorderLayout.EAST);
    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(topPanel, BorderLayout.NORTH);
    leftPanel.add(usersPanel, BorderLayout.CENTER);
    userCertificatePanel.setMinimumSize(new Dimension(375, 10));
    JLabel statusLabel = new JLabel();
    statusLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    if (X509Utils.unlimitedStrength) {
        statusLabel.setText("JCE Unlimited Strength Jurisdiction Policy");
    } else {
        statusLabel.setText("JCE Standard Encryption Policy");
    }
    JPanel root = new JPanel(new BorderLayout()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }
    };
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, userCertificatePanel);
    splitPane.setDividerLocation(1d);
    root.add(splitPane, BorderLayout.CENTER);
    root.add(statusLabel, BorderLayout.SOUTH);
    return root;
}
Also used : JPanel(javax.swing.JPanel) PrivateKey(java.security.PrivateKey) JTextArea(javax.swing.JTextArea) X509Metadata(com.gitblit.utils.X509Utils.X509Metadata) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) BorderLayout(java.awt.BorderLayout) X509Certificate(java.security.cert.X509Certificate) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) ImageIcon(javax.swing.ImageIcon) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) UserModel(com.gitblit.models.UserModel) KeyEvent(java.awt.event.KeyEvent) GridLayout(java.awt.GridLayout) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) RevocationReason(com.gitblit.utils.X509Utils.RevocationReason) JScrollPane(javax.swing.JScrollPane) Calendar(java.util.Calendar) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) IOException(java.io.IOException) JToolBar(javax.swing.JToolBar) InputVerifier(javax.swing.InputVerifier) Date(java.util.Date) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) HeaderPanel(com.gitblit.client.HeaderPanel)

Example 20 with JComponent

use of javax.swing.JComponent in project gitblit by gitblit.

the class RequestFocusListener method ancestorAdded.

@Override
public void ancestorAdded(AncestorEvent e) {
    JComponent component = e.getComponent();
    component.requestFocusInWindow();
    if (removeListener)
        component.removeAncestorListener(this);
}
Also used : JComponent(javax.swing.JComponent)

Aggregations

JComponent (javax.swing.JComponent)159 Component (java.awt.Component)30 JButton (javax.swing.JButton)22 JPanel (javax.swing.JPanel)22 BorderLayout (java.awt.BorderLayout)18 Dimension (java.awt.Dimension)17 Insets (java.awt.Insets)15 JLabel (javax.swing.JLabel)15 ActionEvent (java.awt.event.ActionEvent)11 JFrame (javax.swing.JFrame)11 Color (java.awt.Color)10 ActionListener (java.awt.event.ActionListener)10 ArrayList (java.util.ArrayList)10 Point (java.awt.Point)9 Container (java.awt.Container)8 GridBagConstraints (java.awt.GridBagConstraints)8 JTextField (javax.swing.JTextField)8 Graphics (java.awt.Graphics)7 GridBagLayout (java.awt.GridBagLayout)7 File (java.io.File)7