use of java.awt.event.KeyAdapter in project buck by facebook.
the class ChooseTargetAction method gotoActionPerformed.
@Override
protected void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return;
}
final ChooseTargetModel model = new ChooseTargetModel(project);
GotoActionCallback<String> callback = new GotoActionCallback<String>() {
@Override
public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object element) {
if (element == null) {
return;
}
BuckSettingsProvider buckSettingsProvider = BuckSettingsProvider.getInstance();
if (buckSettingsProvider == null || buckSettingsProvider.getState() == null) {
return;
}
ChooseTargetItem item = (ChooseTargetItem) element;
// if the target selected isn't an alias, then it has to have :
if (item.getName().contains("//") && !item.getName().contains(":")) {
return;
}
if (buckSettingsProvider.getState().lastAlias != null) {
buckSettingsProvider.getState().lastAlias.put(project.getBasePath(), item.getBuildTarget());
}
BuckToolWindowFactory.updateBuckToolWindowTitle(project);
}
};
showNavigationPopup(e, model, callback, "Choose Build Target", true, false);
// Add navigation listener for auto complete
final ChooseByNamePopup chooseByNamePopup = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
chooseByNamePopup.getTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_RIGHT == e.getKeyCode()) {
ChooseTargetItem obj = (ChooseTargetItem) chooseByNamePopup.getChosenElement();
if (obj != null) {
chooseByNamePopup.getTextField().setText(obj.getName());
chooseByNamePopup.getTextField().repaint();
}
} else {
super.keyPressed(e);
}
String adText = chooseByNamePopup.getAdText();
if (adText != null) {
chooseByNamePopup.setAdText(adText + " and " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 2)) + " to use autocomplete");
}
}
});
}
use of java.awt.event.KeyAdapter in project jadx by skylot.
the class MainWindow method initUI.
private void initUI() {
mainPanel = new JPanel(new BorderLayout());
JSplitPane splitPane = new JSplitPane();
splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
mainPanel.add(splitPane);
DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
treeModel = new DefaultTreeModel(treeRoot);
tree = new JTree(treeModel);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
treeClickAction();
}
});
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
treeClickAction();
}
}
});
tree.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
if (value instanceof JNode) {
setIcon(((JNode) value).getIcon());
}
return c;
}
});
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
TreePath path = event.getPath();
Object node = path.getLastPathComponent();
if (node instanceof JClass) {
JClass cls = (JClass) node;
cls.getRootClass().load();
}
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
}
});
progressPane = new ProgressPanel(this, true);
JPanel leftPane = new JPanel(new BorderLayout());
leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
leftPane.add(progressPane, BorderLayout.PAGE_END);
splitPane.setLeftComponent(leftPane);
tabbedPane = new TabbedPane(this);
splitPane.setRightComponent(tabbedPane);
dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
setContentPane(mainPanel);
setTitle(DEFAULT_TITLE);
}
use of java.awt.event.KeyAdapter in project jadx by skylot.
the class SearchDialog method initUI.
private void initUI() {
JLabel findLabel = new JLabel(NLS.str("search_dialog.open_by_name"));
searchField = new JTextField();
searchField.setAlignmentX(LEFT_ALIGNMENT);
searchField.getDocument().addDocumentListener(new SearchFieldListener());
new TextStandardActions(searchField);
JCheckBox clsChBox = makeOptionsCheckBox(NLS.str("search_dialog.class"), SearchOptions.CLASS);
JCheckBox mthChBox = makeOptionsCheckBox(NLS.str("search_dialog.method"), SearchOptions.METHOD);
JCheckBox fldChBox = makeOptionsCheckBox(NLS.str("search_dialog.field"), SearchOptions.FIELD);
JCheckBox codeChBox = makeOptionsCheckBox(NLS.str("search_dialog.code"), SearchOptions.CODE);
JPanel searchOptions = new JPanel(new FlowLayout(FlowLayout.LEFT));
searchOptions.setBorder(BorderFactory.createTitledBorder(NLS.str("search_dialog.search_in")));
searchOptions.add(clsChBox);
searchOptions.add(mthChBox);
searchOptions.add(fldChBox);
searchOptions.add(codeChBox);
searchOptions.setAlignmentX(LEFT_ALIGNMENT);
JPanel searchPane = new JPanel();
searchPane.setLayout(new BoxLayout(searchPane, BoxLayout.PAGE_AXIS));
findLabel.setLabelFor(searchField);
searchPane.add(findLabel);
searchPane.add(Box.createRigidArea(new Dimension(0, 5)));
searchPane.add(searchField);
searchPane.add(Box.createRigidArea(new Dimension(0, 5)));
searchPane.add(searchOptions);
searchPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
initCommon();
JPanel resultsPanel = initResultsTable();
JPanel buttonPane = initButtonsPanel();
Container contentPane = getContentPane();
contentPane.add(searchPane, BorderLayout.PAGE_START);
contentPane.add(resultsPanel, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.PAGE_END);
searchField.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (resultsModel.getRowCount() != 0) {
resultsTable.setRowSelectionInterval(0, 0);
}
resultsTable.requestFocus();
}
}
});
setTitle(NLS.str("menu.text_search"));
pack();
setSize(800, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setModalityType(ModalityType.MODELESS);
}
use of java.awt.event.KeyAdapter 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();
}
});
}
use of java.awt.event.KeyAdapter 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;
}
Aggregations