use of java.awt.event.KeyAdapter in project jdk8u_jdk by JetBrains.
the class ExtendedKeyCodeTest method main.
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
Robot robot = new Robot();
robot.setAutoDelay(50);
Frame frame = new Frame();
frame.setSize(300, 300);
frame.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
eventsCount++;
setExtendedKeyCode = setExtendedKeyCode && (e.getExtendedKeyCode() == ExtendedKeyCodes.getExtendedKeyCodeForChar(e.getKeyChar()));
}
@Override
public void keyReleased(KeyEvent e) {
eventsCount++;
setExtendedKeyCode = setExtendedKeyCode && (e.getExtendedKeyCode() == ExtendedKeyCodes.getExtendedKeyCodeForChar(e.getKeyChar()));
}
});
frame.setVisible(true);
toolkit.realSync();
robot.keyPress(KeyEvent.VK_D);
robot.keyRelease(KeyEvent.VK_D);
toolkit.realSync();
frame.dispose();
if (eventsCount != 2 || !setExtendedKeyCode) {
throw new RuntimeException("Wrong extended key code");
}
frame = new Frame();
frame.setSize(300, 300);
setExtendedKeyCode = false;
frame.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
setExtendedKeyCode = e.getExtendedKeyCode() == KeyEvent.VK_LEFT;
}
});
frame.setVisible(true);
toolkit.realSync();
robot.keyPress(KeyEvent.VK_LEFT);
robot.keyRelease(KeyEvent.VK_LEFT);
toolkit.realSync();
frame.dispose();
if (!setExtendedKeyCode) {
throw new RuntimeException("Wrong extended key code!");
}
}
use of java.awt.event.KeyAdapter in project jdk8u_jdk by JetBrains.
the class TestApplet method init.
public void init() {
final TextArea log = new TextArea("Events:\n");
log.setEditable(false);
log.setSize(400, 200);
this.add(log);
log.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
log.append("Key typed: char = " + e.getKeyChar() + "\n");
}
@Override
public void keyPressed(KeyEvent e) {
log.append("Key pressed: char = " + e.getKeyChar() + " code = " + e.getKeyCode() + "\n");
}
@Override
public void keyReleased(KeyEvent e) {
log.append("Key released: char = " + e.getKeyChar() + " code = " + e.getKeyCode() + "\n");
}
});
}
use of java.awt.event.KeyAdapter in project jabref by JabRef.
the class BasePanel method createMainTable.
private void createMainTable() {
bibDatabaseContext.getDatabase().registerListener(tableModel.getListSynchronizer());
bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance());
tableFormat = new MainTableFormat(bibDatabaseContext.getDatabase());
tableFormat.updateTableFormat();
mainTable = new MainTable(tableFormat, tableModel, frame, this);
selectionListener = new MainTableSelectionListener(this, mainTable);
mainTable.updateFont();
mainTable.addSelectionListener(selectionListener);
mainTable.addMouseListener(selectionListener);
mainTable.addKeyListener(selectionListener);
mainTable.addFocusListener(selectionListener);
// Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX)
mainTable.addSelectionListener(listEvent -> Platform.runLater(() -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries())));
String clearSearch = "clearSearch";
mainTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), clearSearch);
mainTable.getActionMap().put(clearSearch, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// need to close these here, b/c this action overshadows the responsible actions when the main table is selected
switch(mode) {
case SHOWING_NOTHING:
frame.getGlobalSearchBar().endSearch();
break;
case SHOWING_PREVIEW:
getPreviewPanel().close();
break;
case SHOWING_EDITOR:
case WILL_SHOW_EDITOR:
getCurrentEditor().close();
break;
default:
LOGGER.warn("unknown BasePanelMode: '" + mode + "', doing nothing");
break;
}
}
});
mainTable.getActionMap().put(Actions.CUT, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
runCommand(Actions.CUT);
} catch (Throwable ex) {
LOGGER.warn("Could not cut", ex);
}
}
});
mainTable.getActionMap().put(Actions.COPY, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
runCommand(Actions.COPY);
} catch (Throwable ex) {
LOGGER.warn("Could not copy", ex);
}
}
});
mainTable.getActionMap().put(Actions.PASTE, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
runCommand(Actions.PASTE);
} catch (Throwable ex) {
LOGGER.warn("Could not paste", ex);
}
}
});
mainTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
final int keyCode = e.getKeyCode();
if (e.isControlDown()) {
switch(keyCode) {
case KeyEvent.VK_PAGE_DOWN:
frame.nextTab.actionPerformed(null);
e.consume();
break;
case KeyEvent.VK_PAGE_UP:
frame.prevTab.actionPerformed(null);
e.consume();
break;
default:
break;
}
} else if (keyCode == KeyEvent.VK_ENTER) {
e.consume();
try {
runCommand(Actions.EDIT);
} catch (Throwable ex) {
LOGGER.warn("Could not run action based on key press", ex);
}
}
}
});
}
use of java.awt.event.KeyAdapter in project JMRI by JMRI.
the class IconAdder method complete.
/*
* Supports selection of NamedBean from a pick list table
* @param addIconAction - ActionListener that adds an icon to the panel -
* representing either an entity a pick list selection, an
* arbitrary inmage, or a value, such a
* memory value.
* @param changeIconAction - ActionListener that displays sources from
* which to select an image file.
*/
public void complete(ActionListener addIconAction, boolean changeIcon, boolean addToTable, boolean update) {
_update = update;
if (_buttonPanel != null) {
this.remove(_buttonPanel);
}
_buttonPanel = new JPanel();
_buttonPanel.setLayout(new BoxLayout(_buttonPanel, BoxLayout.Y_AXIS));
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
if (addToTable) {
_sysNametext = new JTextField();
_sysNametext.setPreferredSize(new Dimension(150, _sysNametext.getPreferredSize().height + 2));
_addTableButton = new JButton(Bundle.getMessage("addToTable"));
_addTableButton.addActionListener((ActionEvent a) -> {
addToTable();
});
_addTableButton.setEnabled(false);
_addTableButton.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
p.add(_sysNametext);
_sysNametext.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent a) {
if (_sysNametext.getText().length() > 0) {
_addTableButton.setEnabled(true);
_addTableButton.setToolTipText(null);
_table.clearSelection();
}
}
});
p.add(_addTableButton);
_buttonPanel.add(p);
p = new JPanel();
//new BoxLayout(p, BoxLayout.Y_AXIS)
p.setLayout(new FlowLayout());
}
if (update) {
_addButton = new JButton(Bundle.getMessage("ButtonUpdateIcon"));
} else {
_addButton = new JButton(Bundle.getMessage("ButtonAddIcon"));
}
_addButton.addActionListener(addIconAction);
_addButton.setEnabled(true);
if (changeIcon) {
_changeButton = new JButton(Bundle.getMessage("ButtonChangeIcon"));
_changeButton.addActionListener((ActionEvent a) -> {
addCatalog();
});
p.add(_changeButton);
_closeButton = new JButton(Bundle.getMessage("ButtonCloseCatalog"));
_closeButton.addActionListener((ActionEvent a) -> {
closeCatalog();
});
_closeButton.setVisible(false);
p.add(_closeButton);
}
_buttonPanel.add(p);
if (_table != null) {
_addButton.setEnabled(false);
_addButton.setToolTipText(Bundle.getMessage("ToolTipPickFromTable"));
}
addAdditionalButtons(_buttonPanel);
p = new JPanel();
p.add(_addButton);
_buttonPanel.add(p);
_buttonPanel.add(Box.createVerticalStrut(STRUT_SIZE));
_buttonPanel.add(new JSeparator());
this.add(_buttonPanel);
if (changeIcon) {
_catalog = CatalogPanel.makeDefaultCatalog();
_catalog.setVisible(false);
_catalog.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
this.add(_catalog);
}
if (_type != null) /*&& _defaultIcons == null*/
{
getDefaultIconNodeFromMap();
}
// Allow initial row to be set without getting callback to valueChanged
if (_table != null) {
_table.getSelectionModel().addListSelectionListener(this);
}
pack();
}
use of java.awt.event.KeyAdapter in project JMRI by JMRI.
the class AddProfileDialog method initComponents.
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
void initComponents() {
lblProfileNameAndLocation = new JLabel();
jSeparator2 = new JSeparator();
profileName = new JTextField();
lblProfileName = new JLabel();
lblProfileLocation = new JLabel();
profileLocation = new JTextField();
profileFolder = new JTextField();
btnBrowse = new JButton();
lblProfileFolder = new JLabel();
jSeparator1 = new JSeparator();
btnCancel = new JButton();
btnOk = new JButton();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
// NOI18N
ResourceBundle bundle = ResourceBundle.getBundle("jmri/profile/Bundle");
// NOI18N
setTitle(bundle.getString("AddProfileDialog.title"));
setMinimumSize(new Dimension(413, 239));
lblProfileNameAndLocation.setFont(lblProfileNameAndLocation.getFont().deriveFont(lblProfileNameAndLocation.getFont().getStyle() | Font.BOLD));
// NOI18N
lblProfileNameAndLocation.setText(bundle.getString("AddProfileDialog.lblProfileNameAndLocation.text"));
profileName.setText("");
profileName.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
profileNameActionPerformed(null);
}
public void insertUpdate(DocumentEvent e) {
profileNameActionPerformed(null);
}
public void removeUpdate(DocumentEvent e) {
profileNameActionPerformed(null);
}
});
profileName.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent evt) {
profileNameFocusLost(evt);
}
});
profileName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
profileNameActionPerformed(evt);
}
});
profileName.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent evt) {
profileNameKeyTyped(evt);
}
});
// NOI18N
lblProfileName.setText(bundle.getString("AddProfileDialog.lblProfileName.text"));
// NOI18N
lblProfileLocation.setText(bundle.getString("AddProfileDialog.lblProfileLocation.text"));
profileLocation.setText(ProfileManager.getDefault().getDefaultSearchPath().getPath());
profileLocation.setMinimumSize(new Dimension(14, 128));
profileLocation.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent evt) {
profileLocationFocusLost(evt);
}
});
profileLocation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
profileLocationActionPerformed(evt);
}
});
profileLocation.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent evt) {
profileLocationKeyTyped(evt);
}
});
profileFolder.setEditable(false);
profileFolder.setText(ProfileManager.getDefault().getDefaultSearchPath().getPath());
profileFolder.setEnabled(false);
profileFolder.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
profileFolderActionPerformed(evt);
}
});
// NOI18N
btnBrowse.setText(bundle.getString("AddProfileDialog.btnBrowse.text"));
btnBrowse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnBrowseActionPerformed(evt);
}
});
// NOI18N
lblProfileFolder.setText(bundle.getString("AddProfileDialog.lblProfileFolder.text"));
// NOI18N
btnCancel.setText(bundle.getString("AddProfileDialog.btnCancel.text"));
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
// NOI18N
btnOk.setText(bundle.getString("AddProfileDialog.btnOk.text"));
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btnOkActionPerformed(evt);
}
});
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jSeparator2).addGroup(layout.createSequentialGroup().addGap(6, 6, 6).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(lblProfileName).addGap(24, 24, 24).addComponent(profileName, GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(lblProfileLocation).addComponent(lblProfileFolder)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(profileFolder).addComponent(profileLocation, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(btnBrowse)).addGroup(layout.createSequentialGroup().addComponent(lblProfileNameAndLocation).addGap(0, 0, Short.MAX_VALUE)).addComponent(jSeparator1).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(btnOk).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(btnCancel))).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(lblProfileNameAndLocation).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jSeparator2, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(profileName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblProfileName)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(profileLocation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(btnBrowse).addComponent(lblProfileLocation)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(profileFolder, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(lblProfileFolder)).addGap(18, 18, 18).addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(btnCancel).addComponent(btnOk)).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
pack();
}
Aggregations