use of java.awt.event.KeyEvent 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.KeyEvent 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.KeyEvent in project binnavi by google.
the class ConsoleCodeDocument method insertString.
/**
* Insert a String of source code to be highlighted to the document. The string is then inserted
* character by character if longer than 1 char.
*
* @param offs the position in the document
* @param str the String containig source code
* @param attr the attributes to set
*/
@Override
public void insertString(final int offs, final String str, final AttributeSet attr) {
if (offs < 0) {
return;
}
if (str.length() > 1) {
int i;
for (i = 0; i < str.length(); i++) {
if (str.charAt(i) == '\n') {
remainingTextString = str.substring(i + 1);
remainingTextAttr = attr;
inputKeyListener.keyPressed(new KeyEvent(new Container(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_ENTER, '\n'));
break;
} else {
insertChar(offs + i, "" + str.charAt(i));
}
}
} else if (str.length() == 1) {
insertChar(offs, str);
}
}
use of java.awt.event.KeyEvent 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.KeyEvent 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