use of java.awt.event.KeyAdapter in project gitblit by gitblit.
the class UsersPanel method initialize.
private void initialize() {
JButton refreshUsers = new JButton(Translation.get("gb.refresh"));
refreshUsers.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshUsers();
}
});
JButton createUser = new JButton(Translation.get("gb.create"));
createUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createUser();
}
});
final JButton editUser = new JButton(Translation.get("gb.edit"));
editUser.setEnabled(false);
editUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editUser(getSelectedUsers().get(0));
}
});
final JButton delUser = new JButton(Translation.get("gb.delete"));
delUser.setEnabled(false);
delUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteUsers(getSelectedUsers());
}
});
NameRenderer nameRenderer = new NameRenderer();
tableModel = new UsersTableModel();
defaultSorter = new TableRowSorter<UsersTableModel>(tableModel);
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
table.getColumn(name).setCellRenderer(nameRenderer);
int w = 130;
name = table.getColumnName(UsersTableModel.Columns.Type.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
name = table.getColumnName(UsersTableModel.Columns.Teams.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
name = table.getColumnName(UsersTableModel.Columns.Repositories.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
table.setRowSorter(defaultSorter);
table.getRowSorter().toggleSortOrder(UsersTableModel.Columns.Name.ordinal());
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean selected = table.getSelectedRow() > -1;
boolean singleSelection = table.getSelectedRows().length == 1;
editUser.setEnabled(singleSelection && selected);
delUser.setEnabled(selected);
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
editUser(getSelectedUsers().get(0));
}
}
});
filterTextfield = new JTextField();
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());
}
});
JPanel userFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
userFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
userFilterPanel.add(filterTextfield, BorderLayout.CENTER);
JPanel userTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
userTablePanel.add(userFilterPanel, BorderLayout.NORTH);
userTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
JPanel userControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
userControls.add(refreshUsers);
userControls.add(createUser);
userControls.add(editUser);
userControls.add(delUser);
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
header = new HeaderPanel(Translation.get("gb.users"), "user_16x16.png");
add(header, BorderLayout.NORTH);
add(userTablePanel, BorderLayout.CENTER);
add(userControls, BorderLayout.SOUTH);
}
use of java.awt.event.KeyAdapter in project gitblit by gitblit.
the class SettingsPanel method initialize.
private void initialize() {
JButton refreshSettings = new JButton(Translation.get("gb.refresh"));
refreshSettings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshSettings();
}
});
final JButton editSetting = new JButton(Translation.get("gb.edit"));
editSetting.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
String key = tableModel.keys.get(modelRow);
SettingModel setting = tableModel.settings.get(key);
editSetting(setting);
}
});
NameRenderer nameRenderer = new NameRenderer();
final SettingPanel settingPanel = new SettingPanel();
tableModel = new SettingsTableModel();
defaultSorter = new TableRowSorter<SettingsTableModel>(tableModel);
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
table.setDefaultRenderer(SettingModel.class, new SettingCellRenderer());
String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
table.getColumn(name).setCellRenderer(nameRenderer);
table.setRowSorter(defaultSorter);
table.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal());
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean singleSelection = table.getSelectedRows().length == 1;
editSetting.setEnabled(singleSelection);
if (singleSelection) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
SettingModel setting = tableModel.get(modelRow);
settingPanel.setSetting(setting);
} else {
settingPanel.clear();
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
SettingModel setting = tableModel.get(modelRow);
editSetting(setting);
}
}
});
filterTextfield = new JTextField();
filterTextfield.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterSettings(filterTextfield.getText());
}
});
filterTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
filterSettings(filterTextfield.getText());
}
});
JPanel settingFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
settingFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
settingFilterPanel.add(filterTextfield, BorderLayout.CENTER);
JPanel settingsTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
settingsTablePanel.add(settingFilterPanel, BorderLayout.NORTH);
settingsTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
settingsTablePanel.add(settingPanel, BorderLayout.SOUTH);
JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
settingsControls.add(refreshSettings);
settingsControls.add(editSetting);
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
header = new HeaderPanel(Translation.get("gb.settings"), "settings_16x16.png");
add(header, BorderLayout.NORTH);
add(settingsTablePanel, BorderLayout.CENTER);
add(settingsControls, BorderLayout.SOUTH);
}
use of java.awt.event.KeyAdapter in project binnavi by google.
the class AtomicTypePanel method createControls.
private void createControls() {
setLayout(new BorderLayout());
final JPanel contentPanel = new JPanel();
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
add(contentPanel, BorderLayout.CENTER);
final GridBagLayout gbl_m_contentPanel = new GridBagLayout();
gbl_m_contentPanel.columnWidths = new int[] { 0, 0, 0 };
gbl_m_contentPanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 };
gbl_m_contentPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
gbl_m_contentPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
contentPanel.setLayout(gbl_m_contentPanel);
final JLabel lblNewLabel = new JLabel("Name:");
final GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
gbc_lblNewLabel.gridx = 0;
gbc_lblNewLabel.gridy = 0;
contentPanel.add(lblNewLabel, gbc_lblNewLabel);
name = new JTextField();
name.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent e) {
updatePreview();
}
});
final GridBagConstraints gbc_m_name = new GridBagConstraints();
gbc_m_name.insets = new Insets(0, 0, 5, 0);
gbc_m_name.fill = GridBagConstraints.HORIZONTAL;
gbc_m_name.gridx = 1;
gbc_m_name.gridy = 0;
contentPanel.add(name, gbc_m_name);
name.setColumns(10);
final JLabel lblSize = new JLabel("Size (bits):");
final GridBagConstraints gbc_lblSize = new GridBagConstraints();
gbc_lblSize.anchor = GridBagConstraints.WEST;
gbc_lblSize.insets = new Insets(0, 0, 5, 5);
gbc_lblSize.gridx = 0;
gbc_lblSize.gridy = 1;
contentPanel.add(lblSize, gbc_lblSize);
size = new JTextField();
final GridBagConstraints gbc_m_size = new GridBagConstraints();
gbc_m_size.insets = new Insets(0, 0, 5, 0);
gbc_m_size.fill = GridBagConstraints.HORIZONTAL;
gbc_m_size.gridx = 1;
gbc_m_size.gridy = 1;
contentPanel.add(size, gbc_m_size);
size.setColumns(10);
signed = new JCheckBox("Signed");
final GridBagConstraints gbc_m_signed = new GridBagConstraints();
gbc_m_signed.anchor = GridBagConstraints.WEST;
gbc_m_signed.insets = new Insets(0, 0, 5, 5);
gbc_m_signed.gridx = 0;
gbc_m_signed.gridy = 2;
contentPanel.add(signed, gbc_m_signed);
lblPreview = new JLabel("Preview:");
final GridBagConstraints gbc_lblPreview = new GridBagConstraints();
gbc_lblPreview.insets = new Insets(0, 0, 5, 5);
gbc_lblPreview.gridx = 0;
gbc_lblPreview.gridy = 3;
contentPanel.add(lblPreview, gbc_lblPreview);
preview = new JTextArea();
preview.setEditable(false);
final GridBagConstraints gbc_preview = new GridBagConstraints();
gbc_preview.insets = new Insets(0, 0, 5, 0);
gbc_preview.fill = GridBagConstraints.BOTH;
gbc_preview.gridx = 1;
gbc_preview.gridy = 3;
contentPanel.add(preview, gbc_preview);
}
use of java.awt.event.KeyAdapter in project zaproxy by zaproxy.
the class AlertViewPanel method getAlertDisplay.
private JPanel getAlertDisplay() {
if (alertDisplay == null) {
alertDisplay = new JPanel();
alertDisplay.setLayout(new GridBagLayout());
alertDisplay.setName("alertDisplay");
// Create the labels
alertEditName = new JComboBox<>();
alertEditName.setEditable(true);
nameListModel = new DefaultComboBoxModel<>();
List<String> allVulns = getAllVulnerabilityNames();
// Default to blank
nameListModel.addElement("");
for (String vuln : allVulns) {
nameListModel.addElement(vuln);
}
alertEditName.setModel(nameListModel);
alertEditName.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ("comboBoxChanged".equals(e.getActionCommand())) {
Vulnerability v = getVulnerability((String) alertEditName.getSelectedItem());
if (v != null) {
if (v.getDescription() != null && v.getDescription().length() > 0) {
setAlertDescription(v.getDescription());
}
if (v.getSolution() != null && v.getSolution().length() > 0) {
setAlertSolution(v.getSolution());
}
if (v.getReferences() != null) {
StringBuilder sb = new StringBuilder();
for (String ref : v.getReferences()) {
sb.append(ref);
sb.append('\n');
}
setAlertReference(sb.toString());
}
alertEditWascId.setValue(v.getWascId());
}
}
}
});
alertEditRisk = new JComboBox<>(Alert.MSG_RISK);
alertEditConfidence = new JComboBox<>(Alert.MSG_CONFIDENCE);
alertEditConfidence.setSelectedItem(Alert.MSG_CONFIDENCE[Alert.CONFIDENCE_MEDIUM]);
alertEditAttack = new ZapTextField();
paramListModel = new DefaultComboBoxModel<>();
// Default is empty so user can type anything in
paramListModel.addElement("");
alertEditParam = new JComboBox<>();
alertEditParam.setModel(paramListModel);
alertEditParam.setEditable(true);
alertEditEvidence = new ZapTextField();
alertEditCweId = new ZapNumberSpinner();
if (alertEditCweId.getEditor() instanceof JSpinner.DefaultEditor) {
((JSpinner.DefaultEditor) alertEditCweId.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
}
alertEditWascId = new ZapNumberSpinner();
if (alertEditWascId.getEditor() instanceof JSpinner.DefaultEditor) {
((JSpinner.DefaultEditor) alertEditWascId.getEditor()).getTextField().setHorizontalAlignment(JTextField.LEFT);
}
// Read only ones
alertName = new ZapLabel();
alertName.setFont(FontUtils.getFont(Font.BOLD));
alertRisk = new JLabel();
alertConfidence = new JLabel();
alertParam = new ZapLabel();
alertAttack = new ZapLabel();
alertEvidence = new ZapLabel();
alertCweId = new JLabel();
alertWascId = new JLabel();
alertSource = new JLabel();
alertUrl = new ZapLabel();
alertDescription = createZapTextArea();
JScrollPane descSp = createJScrollPane(Constant.messages.getString("alert.label.desc"));
descSp.setViewportView(alertDescription);
alertDescription.addKeyListener(new KeyAdapter() {
// Change tab key to transfer focus to the next element
@Override
public void keyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode() == KeyEvent.VK_TAB) {
alertDescription.transferFocus();
}
}
});
alertOtherInfo = createZapTextArea();
JScrollPane otherSp = createJScrollPane(Constant.messages.getString("alert.label.other"));
otherSp.setViewportView(alertOtherInfo);
alertOtherInfo.addKeyListener(new KeyAdapter() {
// Change tab key to transfer focus to the next element
@Override
public void keyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode() == KeyEvent.VK_TAB) {
alertOtherInfo.transferFocus();
}
}
});
alertSolution = createZapTextArea();
JScrollPane solutionSp = createJScrollPane(Constant.messages.getString("alert.label.solution"));
solutionSp.setViewportView(alertSolution);
alertSolution.addKeyListener(new KeyAdapter() {
// Change tab key to transfer focus to the next element
@Override
public void keyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode() == KeyEvent.VK_TAB) {
alertSolution.transferFocus();
}
}
});
alertReference = createZapTextArea();
JScrollPane referenceSp = createJScrollPane(Constant.messages.getString("alert.label.ref"));
referenceSp.setViewportView(alertReference);
alertReference.addKeyListener(new KeyAdapter() {
// Change tab key to transfer focus to the next element
@Override
public void keyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode() == KeyEvent.VK_TAB) {
alertReference.transferFocus();
}
}
});
int gbcRow = 0;
alertDisplay.add(editable ? alertEditName : alertName, LayoutHelper.getGBC(0, gbcRow, 2, 0, DEFAULT_INSETS));
// Show a blank label instead of the edit button if already editing
gbcRow++;
alertDisplay.add(getUrlLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(alertUrl, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(getRiskLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(editable ? alertEditRisk : alertRisk, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(getConfidenceLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(editable ? alertEditConfidence : alertConfidence, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(getParameterLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(editable ? alertEditParam : alertParam, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(getAttackLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(editable ? alertEditAttack : alertAttack, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(getEvidenceLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(editable ? alertEditEvidence : alertEvidence, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(getCweidLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(editable ? alertEditCweId : alertCweId, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(getWascidLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(editable ? alertEditWascId : alertWascId, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
if (!editable) {
alertDisplay.add(getSourceLabel(), LayoutHelper.getGBC(0, gbcRow, 1, 0, DEFAULT_INSETS));
alertDisplay.add(alertSource, LayoutHelper.getGBC(1, gbcRow, 1, 1, DEFAULT_INSETS));
gbcRow++;
}
alertDisplay.add(descSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(otherSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(solutionSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
gbcRow++;
alertDisplay.add(referenceSp, LayoutHelper.getGBC(0, gbcRow, 2, 1.0D, 1.0D, GridBagConstraints.BOTH, DEFAULT_INSETS));
}
return alertDisplay;
}
use of java.awt.event.KeyAdapter in project jdk8u_jdk by JetBrains.
the class SpanishDiacriticsTest method init.
@Override
public void init() {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame();
JTextField textField = new JTextField(20);
textField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
LockSupport.parkNanos(1_000_000_000L);
}
});
frame.add(textField);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
});
}
Aggregations