use of java.awt.event.KeyListener in project intellij-community by JetBrains.
the class CheckboxTreeHelper method setupKeyListener.
private KeyListener setupKeyListener(final Tree tree, final JComponent mainComponent) {
KeyListener listener = new KeyAdapter() {
public void keyPressed(@NotNull KeyEvent e) {
if (isToggleEvent(e, mainComponent)) {
TreePath treePath = tree.getLeadSelectionPath();
if (treePath == null)
return;
final Object o = treePath.getLastPathComponent();
if (!(o instanceof CheckedTreeNode))
return;
CheckedTreeNode firstNode = (CheckedTreeNode) o;
if (!firstNode.isEnabled())
return;
toggleNode(tree, firstNode);
boolean checked = firstNode.isChecked();
TreePath[] selectionPaths = tree.getSelectionPaths();
for (int i = 0; selectionPaths != null && i < selectionPaths.length; i++) {
final TreePath selectionPath = selectionPaths[i];
final Object o1 = selectionPath.getLastPathComponent();
if (!(o1 instanceof CheckedTreeNode))
continue;
CheckedTreeNode node = (CheckedTreeNode) o1;
setNodeState(tree, node, checked);
}
e.consume();
}
}
};
mainComponent.addKeyListener(listener);
return listener;
}
use of java.awt.event.KeyListener in project jdk8u_jdk by JetBrains.
the class bug6980209 method setup.
private static void setup(final JFrame frame) {
JButton jButton = new JButton("Button");
frame.getContentPane().add(jButton);
jButton.addActionListener(new bug6980209());
frame.pack();
frame.setVisible(true);
jButton.setFocusable(true);
jButton.requestFocus();
jButton.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == '1')
dispatchedEvents++;
}
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyChar() == '1')
dispatchedEvents++;
}
});
}
use of java.awt.event.KeyListener in project JMRI by JMRI.
the class PositionablePropertiesUtil method editText.
/**
* Create and fill in the Contents tab of the UI (Text Label objects).
*/
void editText() {
JPanel editText = new JPanel();
editText.setLayout(new BoxLayout(editText, BoxLayout.Y_AXIS));
for (int i = 0; i < txtList.size(); i++) {
final int x = i;
JPanel p = new JPanel();
String _borderTitle = txtList.get(i).getDescription();
if (_borderTitle.equals(Bundle.getMessage("TextExampleLabel"))) {
// replace label provided by Ctor by an appropriate one for text string box on Contents tab
_borderTitle = Bundle.getMessage("TextBorderLabel");
}
p.setBorder(BorderFactory.createTitledBorder(_borderTitle));
JLabel txt = new JLabel(Bundle.getMessage("TextValueLabel") + ": ");
JTextField textField = new JTextField(txtList.get(i).getText(), 20);
textField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent E) {
}
@Override
public void keyPressed(KeyEvent E) {
}
@Override
public void keyReleased(KeyEvent E) {
JTextField tmp = (JTextField) E.getSource();
txtList.get(x).setText(tmp.getText());
preview();
}
});
p.add(txt);
p.add(textField);
editText.add(p);
}
propertiesPanel.addTab(Bundle.getMessage("EditTextLabel"), null, editText, Bundle.getMessage("EditTabTooltip"));
}
use of java.awt.event.KeyListener in project JMRI by JMRI.
the class AbstractNetworkConnectionConfig method checkInitDone.
@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
if (log.isDebugEnabled()) {
log.debug("init called for " + name());
}
if (init) {
return;
}
hostNameField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setHostName(hostNameField.getText());
p.addComboBoxLastSelection(adapter.getClass().getName() + ".hostname", hostNameField.getText());
}
});
hostNameField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
adapter.setHostName(hostNameField.getText());
p.addComboBoxLastSelection(adapter.getClass().getName() + ".hostname", hostNameField.getText());
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
portField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
adapter.setPort(Integer.parseInt(portField.getText()));
} catch (java.lang.NumberFormatException ex) {
log.warn("Could not parse port attribute");
}
}
});
portField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
try {
adapter.setPort(Integer.parseInt(portField.getText()));
} catch (java.lang.NumberFormatException ex) {
log.warn("Could not parse port attribute");
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
adNameField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setAdvertisementName(adNameField.getText());
}
});
adNameField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
adapter.setAdvertisementName(adNameField.getText());
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
serviceTypeField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setServiceType(serviceTypeField.getText());
}
});
serviceTypeField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
adapter.setServiceType(serviceTypeField.getText());
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
for (String i : options.keySet()) {
final String item = i;
if (options.get(i).getComponent() instanceof JComboBox) {
((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setOptionState(item, options.get(item).getItem());
}
});
}
}
if (adapter.getSystemConnectionMemo() != null) {
systemPrefixField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
}
}
});
systemPrefixField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
connectionNameField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
}
}
});
connectionNameField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
}
init = true;
}
use of java.awt.event.KeyListener in project JMRI by JMRI.
the class DecoratorPanel method makeTextPanel.
private JPanel makeTextPanel(String caption, JLabel sample, int state, boolean addTextField) {
JPanel panel = new JPanel();
// use NamedBeanBundle property for basic beans like "Turnout" I18N
if ("Active".equals(caption)) {
BundleCaption = "SensorStateActive";
} else if ("InActive".equals(caption)) {
BundleCaption = "SensorStateInactive";
} else if ("Unknown".equals(caption)) {
BundleCaption = "BeanStateUnknown";
} else if ("Inconsistent".equals(caption)) {
BundleCaption = "BeanStateInconsistent";
} else {
BundleCaption = caption;
}
panel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage(BundleCaption)));
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JPanel p = new JPanel();
if (addTextField) {
JTextField textField = new JTextField(sample.getText(), 25);
textField.addKeyListener(new KeyListener() {
JLabel sample;
KeyListener init(JLabel s) {
sample = s;
return this;
}
@Override
public void keyTyped(KeyEvent E) {
}
@Override
public void keyPressed(KeyEvent E) {
}
@Override
public void keyReleased(KeyEvent E) {
JTextField tmp = (JTextField) E.getSource();
sample.setText(tmp.getText());
}
}.init(sample));
p.add(textField);
}
panel.add(p);
p = new JPanel();
p.add(makeButton(new AJRadioButton(Bundle.getMessage("FontColor"), state)));
p.add(makeButton(new AJRadioButton(Bundle.getMessage("FontBackgroundColor"), state + 10)));
AJRadioButton button = new AJRadioButton(Bundle.getMessage("transparentBack"), state + 20);
_buttonGroup.add(button);
p.add(button);
button.addActionListener(new ActionListener() {
AJRadioButton button;
@Override
public void actionPerformed(ActionEvent a) {
if (button.isSelected()) {
switch(button.which) {
case TRANSPARENT_COLOR:
_sample.get("Text").setOpaque(false);
break;
case ACTIVE_TRANSPARENT_COLOR:
_sample.get("Active").setOpaque(false);
break;
case INACTIVE_TRANSPARENT_COLOR:
_sample.get("InActive").setOpaque(false);
break;
case UNKNOWN_TRANSPARENT_COLOR:
_sample.get("Unknown").setOpaque(false);
break;
case INCONSISTENT_TRANSPARENT_COLOR:
_sample.get("Inconsistent").setOpaque(false);
break;
default:
log.warn("Unexpected button.which {} in actionPerformed", button.which);
break;
}
updateSamples();
}
}
ActionListener init(AJRadioButton b) {
button = b;
return this;
}
}.init(button));
panel.add(p);
return panel;
}
Aggregations