use of java.awt.event.KeyListener in project jabref by JabRef.
the class ManageKeywordsAction method createDialog.
private void createDialog() {
if (diag != null) {
return;
}
// keyword to add
JTextField keyword = new JTextField();
keywordListModel = new DefaultListModel<>();
JList<Keyword> keywordList = new JList<>(keywordListModel);
keywordList.setVisibleRowCount(8);
JScrollPane kPane = new JScrollPane(keywordList);
diag = new JDialog(frame, Localization.lang("Manage keywords"), true);
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));
JButton add = new JButton(Localization.lang("Add"));
JButton remove = new JButton(Localization.lang("Remove"));
keywordList.setVisibleRowCount(10);
intersectKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ALL entries"));
mergeKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ANY entry"));
ButtonGroup group = new ButtonGroup();
group.add(intersectKeywords);
group.add(mergeKeywords);
ActionListener stateChanged = e -> fillKeyWordList();
intersectKeywords.addActionListener(stateChanged);
mergeKeywords.addActionListener(stateChanged);
intersectKeywords.setSelected(true);
FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:200dlu:grow, 4dlu, fill:pref", "pref, 2dlu, pref, 1dlu, pref, 2dlu, fill:100dlu:grow, 4dlu, pref, 4dlu, pref, "));
builder.addSeparator(Localization.lang("Keywords of selected entries")).xyw(1, 1, 3);
builder.add(intersectKeywords).xyw(1, 3, 3);
builder.add(mergeKeywords).xyw(1, 5, 3);
builder.add(kPane).xywh(1, 7, 1, 3);
builder.add(remove).xy(3, 9);
builder.add(keyword).xy(1, 11);
builder.add(add).xy(3, 11);
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
ok.addActionListener(e -> {
canceled = false;
diag.dispose();
});
Action cancelAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
canceled = true;
diag.dispose();
}
};
cancel.addActionListener(cancelAction);
final ActionListener addActionListener = arg0 -> addButtonActionListener(keyword);
add.addActionListener(addActionListener);
final ActionListener removeActionListenter = arg0 -> {
List<Keyword> values = keywordList.getSelectedValuesList();
for (Keyword val : values) {
keywordListModel.removeElement(val);
}
};
remove.addActionListener(removeActionListenter);
keywordList.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent arg0) {
// Do nothing
}
@Override
public void keyReleased(KeyEvent arg0) {
// Do nothing
}
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getKeyCode() == KeyEvent.VK_DELETE) {
removeActionListenter.actionPerformed(null);
}
}
});
AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters().get(FieldName.KEYWORDS);
AutoCompleteListener acl = new AutoCompleteListener(autoComp);
keyword.addKeyListener(acl);
keyword.addFocusListener(acl);
keyword.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
// Do nothing
}
@Override
public void keyReleased(KeyEvent e) {
// Do nothing
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
addActionListener.actionPerformed(null);
}
}
});
// Key bindings:
ActionMap am = builder.getPanel().getActionMap();
InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
am.put("close", cancelAction);
diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
}
use of java.awt.event.KeyListener in project JMRI by JMRI.
the class BlockEditAction method physcialDetails.
BeanItemPanel physcialDetails() {
defaultBlockSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + jmri.InstanceManager.getDefault(jmri.BlockManager.class).getDefaultSpeed());
speedList.add(defaultBlockSpeedText);
java.util.Vector<String> _speedMap = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames();
for (int i = 0; i < _speedMap.size(); i++) {
if (!speedList.contains(_speedMap.get(i))) {
speedList.add(_speedMap.get(i));
}
}
BeanItemPanel basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("BlockPhysicalProperties"));
basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("BlockPropertiesText")));
basic.addItem(new BeanEditItem(lengthField, Bundle.getMessage("BlockLengthColName"), Bundle.getMessage("BlockLengthText")));
lengthField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
String text = lengthField.getText();
// ensure data valid
try {
jmri.util.IntlUtilities.floatValue(text);
} catch (java.text.ParseException e) {
String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("BlockLengthColName") });
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "length", false, false);
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
ButtonGroup rg = new ButtonGroup();
rg.add(inch);
rg.add(cm);
JPanel p = new JPanel();
p.add(inch);
p.add(cm);
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
inch.setSelected(true);
inch.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cm.setSelected(!inch.isSelected());
updateLength();
}
});
cm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
inch.setSelected(!cm.isSelected());
updateLength();
}
});
basic.addItem(new BeanEditItem(p, Bundle.getMessage("BlockLengthUnits"), Bundle.getMessage("BlockLengthUnitsText")));
basic.addItem(new BeanEditItem(curvatureField, Bundle.getMessage("BlockCurveColName"), ""));
basic.addItem(new BeanEditItem(speedField = new JComboBox<String>(speedList), Bundle.getMessage("BlockSpeedColName"), Bundle.getMessage("BlockMaxSpeedText")));
basic.addItem(new BeanEditItem(permissiveField, Bundle.getMessage("BlockPermColName"), Bundle.getMessage("BlockPermissiveText")));
permissiveField.setSelected(((Block) bean).getPermissiveWorking());
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
String cName = (String) curvatureField.getSelectedItem();
if (cName.equals(noneText)) {
blk.setCurvature(Block.NONE);
} else if (cName.equals(gradualText)) {
blk.setCurvature(Block.GRADUAL);
} else if (cName.equals(tightText)) {
blk.setCurvature(Block.TIGHT);
} else if (cName.equals(severeText)) {
blk.setCurvature(Block.SEVERE);
}
String speed = (String) speedField.getSelectedItem();
try {
blk.setBlockSpeed(speed);
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
return;
}
if (!speedList.contains(speed) && !speed.contains("Global")) {
speedList.add(speed);
}
float len = 0.0f;
try {
len = jmri.util.IntlUtilities.floatValue(lengthField.getText());
} catch (java.text.ParseException ex2) {
log.error("Error parsing length value of \"{}\"", lengthField.getText());
}
if (inch.isSelected()) {
blk.setLength(len * 25.4f);
} else {
blk.setLength(len * 10.0f);
}
blk.setPermissiveWorking(permissiveField.isSelected());
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
lengthField.setText(twoDigit.format(((Block) bean).getLengthMm()));
if (blk.getCurvature() == Block.NONE) {
curvatureField.setSelectedItem(0);
} else if (blk.getCurvature() == Block.GRADUAL) {
curvatureField.setSelectedItem(gradualText);
} else if (blk.getCurvature() == Block.TIGHT) {
curvatureField.setSelectedItem(tightText);
} else if (blk.getCurvature() == Block.SEVERE) {
curvatureField.setSelectedItem(severeText);
}
String speed = blk.getBlockSpeed();
if (!speedList.contains(speed)) {
speedList.add(speed);
}
speedField.setEditable(true);
speedField.setSelectedItem(speed);
double len = 0.0;
if (inch.isSelected()) {
len = blk.getLengthIn();
} else {
len = blk.getLengthCm();
}
lengthField.setText(twoDigit.format(len));
permissiveField.setSelected(((Block) bean).getPermissiveWorking());
}
});
bei.add(basic);
return basic;
}
use of java.awt.event.KeyListener in project JMRI by JMRI.
the class SensorDebounceEditAction method sensorDebounce.
public BeanItemPanel sensorDebounce(BeanItemPanel basic) {
if (basic == null) {
basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("SensorDebounce"));
}
sensorDebounceGlobalCheck.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (sensorDebounceGlobalCheck.isSelected()) {
sensorDebounceInactiveField.setEnabled(false);
sensorDebounceActiveField.setEnabled(false);
} else {
sensorDebounceInactiveField.setEnabled(true);
sensorDebounceActiveField.setEnabled(true);
}
}
});
sensorDebounceInactiveField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
String text = sensorDebounceInactiveField.getText();
if (!validateNumericalInput(text)) {
String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("SensorInActiveDebounce") });
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "Inactive", false, false);
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
sensorDebounceActiveField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
String text = sensorDebounceActiveField.getText();
if (!validateNumericalInput(text)) {
String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("SensorActiveDebounce") });
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "Active", false, false);
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("SensorDebounceText")));
basic.addItem(new BeanEditItem(sensorDebounceGlobalCheck, Bundle.getMessage("SensorDebounceUseGlobalText"), null));
basic.addItem(new BeanEditItem(sensorDebounceInactiveField, Bundle.getMessage("SensorInActiveDebounce"), Bundle.getMessage("SensorInActiveDebounceText")));
basic.addItem(new BeanEditItem(sensorDebounceActiveField, Bundle.getMessage("SensorActiveDebounce"), Bundle.getMessage("SensorActiveDebounceText")));
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
saveDebounceItems(e);
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
resetDebounceItems(e);
}
});
return basic;
}
use of java.awt.event.KeyListener in project bytecode-viewer by Konloch.
the class PaneUpdaterThread method run.
public void run() {
try {
final byte[] b = BytecodeViewer.getClassBytes(viewer.container, viewer.cn.name + ".class");
if (decompiler != Decompiler.HEXCODE) {
RSyntaxTextArea panelArea = new RSyntaxTextArea();
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
panelArea.setCodeFoldingEnabled(true);
panelArea.setAntiAliasingEnabled(true);
final RTextScrollPane scrollPane = new RTextScrollPane(panelArea);
panelArea.setText(decompiler.decompileClassNode(viewer.cn, b));
panelArea.setCaretPosition(0);
panelArea.setEditable(viewer.isPaneEditable(paneId));
panelArea.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
viewer.requestFocus(paneId);
}
BytecodeViewer.checkHotKey(e);
}
@Override
public void keyReleased(KeyEvent arg0) {
}
@Override
public void keyTyped(KeyEvent arg0) {
}
});
scrollPane.setColumnHeaderView(new JLabel(decompiler.getName() + " Decompiler - Editable: " + panelArea.isEditable()));
panelArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
target.add(scrollPane);
}
});
viewer.updatePane(paneId, panelArea, decompiler);
} else {
final JHexEditor hex = new JHexEditor(b);
hex.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
target.add(hex);
}
});
}
} catch (Exception e) {
new ExceptionUI(e);
} finally {
viewer.resetDivider();
BytecodeViewer.viewer.setIcon(false);
if (button != null)
button.setEnabled(true);
}
}
use of java.awt.event.KeyListener in project dogecade by ebanisadr.
the class MainMenu method createUIComponents.
private void createUIComponents() {
myAccountButton = new JButton("My MyProfileScreen");
myAccountButton.addActionListener(e -> MyAccountScreen.showMyAccountWindow());
chatTextArea = new JChatBox();
sendButton = new JButton("send");
sendButton.addActionListener(e -> ((JChatBox) chatTextArea).getMessageFromEnterBox());
enterTextField = new JTextField();
enterTextField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
((JChatBox) chatTextArea).getMessageFromEnterBox();
}
}
});
roomsPanel = new JPanel();
JButton startRPSButton = new JButton("play rps against the computer");
startRPSButton.addActionListener(e -> {
List<Player> p = new ArrayList<>();
p.add(new Player(Dogecade.server.getUsername(), BigDecimal.valueOf(100)));
p.add(new Player("name2", BigDecimal.valueOf(33)));
new RockPaperScissors(p, Dogecade.rpsServer, 3).startGame();
});
roomsPanel.add(startRPSButton);
}
Aggregations