Search in sources :

Example 6 with KeyEvent

use of java.awt.event.KeyEvent in project limelight by slagyr.

the class StageKeyListenerTest method focuedPanelReceivesTypedKeyEvents.

@Test
public void focuedPanelReceivesTypedKeyEvents() throws Exception {
    panel.getEventHandler().add(CharTypedEvent.class, action);
    listener.focusOn(panel);
    final KeyEvent typedEvent = new KeyEvent(component, 1, 2, 3, 4, 'a');
    listener.keyTyped(typedEvent);
    assertEquals(panel, action.recipient);
    assertEquals('a', ((CharTypedEvent) action.event).getChar());
}
Also used : KeyEvent(java.awt.event.KeyEvent) Test(org.junit.Test)

Example 7 with KeyEvent

use of java.awt.event.KeyEvent in project limelight by slagyr.

the class StageKeyListenerTest method focuedPanelReceivesPressKeyEvents.

@Test
public void focuedPanelReceivesPressKeyEvents() throws Exception {
    panel.getEventHandler().add(KeyPressedEvent.class, action);
    listener.focusOn(panel);
    final KeyEvent pressedEvent = new KeyEvent(component, 1, 2, 3, KeyEvent.VK_A, 'b');
    listener.keyPressed(pressedEvent);
    KeyPressedEvent keyEvent = (KeyPressedEvent) action.event;
    assertSame(panel, keyEvent.getSource());
    assertEquals(limelight.ui.events.panel.KeyEvent.KEY_A, keyEvent.getKeyCode());
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyPressedEvent(limelight.ui.events.panel.KeyPressedEvent) Test(org.junit.Test)

Example 8 with KeyEvent

use of java.awt.event.KeyEvent in project limelight by slagyr.

the class StageKeyListenerTest method focuedPanelReceivesReleaseKeyEvents.

@Test
public void focuedPanelReceivesReleaseKeyEvents() throws Exception {
    panel.getEventHandler().add(KeyReleasedEvent.class, action);
    listener.focusOn(panel);
    final KeyEvent releasedEvent = new KeyEvent(component, 1, 2, 3, KeyEvent.VK_B, 'c');
    listener.keyReleased(releasedEvent);
    KeyReleasedEvent keyEvent1 = (KeyReleasedEvent) action.event;
    assertSame(panel, keyEvent1.getSource());
    assertEquals(limelight.ui.events.panel.KeyEvent.KEY_B, keyEvent1.getKeyCode());
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyReleasedEvent(limelight.ui.events.panel.KeyReleasedEvent) Test(org.junit.Test)

Example 9 with KeyEvent

use of java.awt.event.KeyEvent in project libgdx by libgdx.

the class Hiero method initializeEvents.

private void initializeEvents() {
    fontList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            prefs.put("system.font", (String) fontList.getSelectedValue());
            updateFont();
        }
    });
    class FontUpdateListener implements ChangeListener, ActionListener {

        public void stateChanged(ChangeEvent evt) {
            updateFont();
        }

        public void actionPerformed(ActionEvent evt) {
            updateFont();
        }

        public void addSpinners(JSpinner[] spinners) {
            for (int i = 0; i < spinners.length; i++) {
                final JSpinner spinner = spinners[i];
                spinner.addChangeListener(this);
                ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().addKeyListener(new KeyAdapter() {

                    String lastText;

                    public void keyReleased(KeyEvent evt) {
                        JFormattedTextField textField = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
                        String text = textField.getText();
                        if (text.length() == 0)
                            return;
                        if (text.equals(lastText))
                            return;
                        lastText = text;
                        int caretPosition = textField.getCaretPosition();
                        try {
                            spinner.setValue(Integer.valueOf(text));
                        } catch (NumberFormatException ex) {
                        }
                        textField.setCaretPosition(caretPosition);
                    }
                });
            }
        }
    }
    FontUpdateListener listener = new FontUpdateListener();
    listener.addSpinners(new JSpinner[] { padTopSpinner, padRightSpinner, padBottomSpinner, padLeftSpinner, padAdvanceXSpinner, padAdvanceYSpinner });
    fontSizeSpinner.addChangeListener(listener);
    gammaSpinner.addChangeListener(listener);
    glyphPageWidthCombo.addActionListener(listener);
    glyphPageHeightCombo.addActionListener(listener);
    boldCheckBox.addActionListener(listener);
    italicCheckBox.addActionListener(listener);
    monoCheckBox.addActionListener(listener);
    resetCacheButton.addActionListener(listener);
    javaRadio.addActionListener(listener);
    nativeRadio.addActionListener(listener);
    freeTypeRadio.addActionListener(listener);
    sampleTextRadio.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            glyphCachePanel.setVisible(false);
        }
    });
    glyphCacheRadio.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            glyphCachePanel.setVisible(true);
        }
    });
    fontFileText.getDocument().addDocumentListener(new DocumentListener() {

        public void removeUpdate(DocumentEvent evt) {
            changed();
        }

        public void insertUpdate(DocumentEvent evt) {
            changed();
        }

        public void changedUpdate(DocumentEvent evt) {
            changed();
        }

        private void changed() {
            File file = new File(fontFileText.getText());
            if (fontList.isEnabled() && (!file.exists() || !file.isFile()))
                return;
            prefs.put("font.file", fontFileText.getText());
            updateFont();
        }
    });
    final ActionListener al = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            updateFontSelector();
            updateFont();
        }
    };
    systemFontRadio.addActionListener(al);
    fontFileRadio.addActionListener(al);
    browseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.ttf");
            dialog.setDirectory(prefs.get("dir.font", ""));
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.font", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
        }
    });
    backgroundColorLabel.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent evt) {
            java.awt.Color color = JColorChooser.showDialog(null, "Choose a background color", EffectUtil.fromString(prefs.get("background", "000000")));
            if (color == null)
                return;
            renderingBackgroundColor = new Color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1);
            backgroundColorLabel.setIcon(getColorIcon(color));
            prefs.put("background", EffectUtil.toString(color));
        }
    });
    effectsList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            ConfigurableEffect selectedEffect = (ConfigurableEffect) effectsList.getSelectedValue();
            boolean enabled = selectedEffect != null;
            for (Iterator iter = effectPanels.iterator(); iter.hasNext(); ) {
                ConfigurableEffect effect = ((EffectPanel) iter.next()).getEffect();
                if (effect == selectedEffect) {
                    enabled = false;
                    break;
                }
            }
            addEffectButton.setEnabled(enabled);
        }
    });
    effectsList.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2 && addEffectButton.isEnabled())
                addEffectButton.doClick();
        }
    });
    addEffectButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            new EffectPanel((ConfigurableEffect) effectsList.getSelectedValue());
        }
    });
    openMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.hiero");
            dialog.setDirectory(prefs.get("dir.open", ""));
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.open", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            lastOpenFilename = fileName;
            open(new File(dialog.getDirectory(), fileName));
        }
    });
    saveMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.hiero");
            dialog.setDirectory(prefs.get("dir.save", ""));
            if (lastSaveFilename.length() > 0) {
                dialog.setFile(lastSaveFilename);
            } else if (lastOpenFilename.length() > 0) {
                dialog.setFile(lastOpenFilename);
            }
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.save", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            if (!fileName.endsWith(".hiero"))
                fileName += ".hiero";
            lastSaveFilename = fileName;
            File file = new File(dialog.getDirectory(), fileName);
            try {
                save(file);
            } catch (IOException ex) {
                throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
            }
        }
    });
    saveBMFontMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
            dialog.setLocationRelativeTo(null);
            dialog.setFile("*.fnt");
            dialog.setDirectory(prefs.get("dir.savebm", ""));
            if (lastSaveBMFilename.length() > 0) {
                dialog.setFile(lastSaveBMFilename);
            } else if (lastOpenFilename.length() > 0) {
                dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
            }
            dialog.setVisible(true);
            if (dialog.getDirectory() != null) {
                prefs.put("dir.savebm", dialog.getDirectory());
            }
            String fileName = dialog.getFile();
            if (fileName == null)
                return;
            lastSaveBMFilename = fileName;
            saveBm(new File(dialog.getDirectory(), fileName));
        }
    });
    exitMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            dispose();
        }
    });
    sampleNeheButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sampleTextPane.setText(NEHE_CHARS);
            resetCacheButton.doClick();
        }
    });
    sampleAsciiButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            StringBuilder buffer = new StringBuilder();
            buffer.append(NEHE_CHARS);
            buffer.append('\n');
            int count = 0;
            for (int i = 33; i <= 255; i++) {
                if (buffer.indexOf(Character.toString((char) i)) != -1)
                    continue;
                buffer.append((char) i);
                if (++count % 30 == 0)
                    buffer.append('\n');
            }
            sampleTextPane.setText(buffer.toString());
            resetCacheButton.doClick();
        }
    });
    sampleExtendedButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sampleTextPane.setText(EXTENDED_CHARS);
            resetCacheButton.doClick();
        }
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) StringBuilder(com.badlogic.gdx.utils.StringBuilder) ActionEvent(java.awt.event.ActionEvent) ConfigurableEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect) KeyAdapter(java.awt.event.KeyAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) KeyEvent(java.awt.event.KeyEvent) Iterator(java.util.Iterator) ChangeListener(javax.swing.event.ChangeListener) MouseEvent(java.awt.event.MouseEvent) Color(com.badlogic.gdx.graphics.Color) JFormattedTextField(javax.swing.JFormattedTextField) MouseAdapter(java.awt.event.MouseAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) JSpinner(javax.swing.JSpinner) File(java.io.File) FileDialog(java.awt.FileDialog)

Example 10 with KeyEvent

use of java.awt.event.KeyEvent 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)

Aggregations

KeyEvent (java.awt.event.KeyEvent)135 KeyAdapter (java.awt.event.KeyAdapter)69 MouseEvent (java.awt.event.MouseEvent)31 ActionEvent (java.awt.event.ActionEvent)23 ActionListener (java.awt.event.ActionListener)19 KeyListener (java.awt.event.KeyListener)19 JPanel (javax.swing.JPanel)18 MouseAdapter (java.awt.event.MouseAdapter)17 JLabel (javax.swing.JLabel)17 JButton (javax.swing.JButton)14 JTextField (javax.swing.JTextField)14 JScrollPane (javax.swing.JScrollPane)13 BorderLayout (java.awt.BorderLayout)12 NotNull (org.jetbrains.annotations.NotNull)12 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)11 FlowLayout (java.awt.FlowLayout)10 Tree (com.intellij.ui.treeStructure.Tree)9 Project (com.intellij.openapi.project.Project)8 Dimension (java.awt.Dimension)8