use of java.awt.event.KeyAdapter in project intellij-plugins by JetBrains.
the class ChooseBuildConfigurationDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
List<Module> modules = new ArrayList<>(myTreeItems.keySet());
Collections.sort(modules, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
for (Module module : modules) {
DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module, true);
root.add(moduleNode);
List<FlexBCConfigurable> bcs = myTreeItems.get(module);
Collections.sort(bcs, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
for (FlexBCConfigurable bc : bcs) {
DefaultMutableTreeNode bcNode = new DefaultMutableTreeNode(bc, false);
moduleNode.add(bcNode);
}
}
myTree.setModel(new DefaultTreeModel(root));
myTree.setRootVisible(false);
new TreeSpeedSearch(myTree, o -> {
Object lastPathComponent = o.getLastPathComponent();
return getText((DefaultMutableTreeNode) lastPathComponent);
}, true).setComparator(new SpeedSearchComparator(false));
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
updateOnSelectionChange();
}
});
myTree.setCellRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
Object object = treeNode.getUserObject();
if (object instanceof Module) {
Module module = (Module) object;
setIcon(ModuleType.get(module).getIcon());
append(module.getName());
} else if (object instanceof FlexBCConfigurable) {
FlexBCConfigurable configurable = (FlexBCConfigurable) object;
setIcon(configurable.getIcon());
BCUtils.renderBuildConfiguration(configurable.getEditableObject(), null).appendToComponent(this);
}
}
});
TreeUtil.expandAll(myTree);
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
if (mySelection != null) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
doOKAction();
}
}
});
updateOnSelectionChange();
return myContentPane;
}
use of java.awt.event.KeyAdapter in project processdash by dtuma.
the class PreferencesTextField method addUpdateFromTextListeners.
@Override
protected void addUpdateFromTextListeners() {
addActionListener((ActionListener) EventHandler.create(ActionListener.class, this, "updateFromText"));
addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
updateFromText();
}
});
}
use of java.awt.event.KeyAdapter in project aerospike-client-java by aerospike.
the class GuiDisplay method initialize.
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmAerospikeExamples = new JFrame();
frmAerospikeExamples.setTitle("Aerospike Java Client Examples");
frmAerospikeExamples.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmAerospikeExamples.pack();
frmAerospikeExamples.getContentPane().setLayout(new BorderLayout(0, 0));
splitPane = new JSplitPane();
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
frmAerospikeExamples.getContentPane().add(splitPane, BorderLayout.CENTER);
mainPanel = new JPanel();
splitPane.setLeftComponent(mainPanel);
mainPanel.setLayout(new BorderLayout(0, 0));
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
runButton = new JButton("Run");
runButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
consoleTextArea.setText("");
run_selected_examples();
}
});
buttonPanel.add(runButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
exitButton = new JButton("Quit");
exitButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
Container Frame = exitButton.getParent();
do {
Frame = Frame.getParent();
} while (!(Frame instanceof JFrame));
((JFrame) Frame).dispose();
}
});
buttonPanel.add(exitButton);
sourceTextPane = new JTextArea();
sourceTextPane.setTabSize(2);
sourceTextPane.setEditable(false);
scrollPane = new JScrollPane(sourceTextPane);
scrollPane.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
scrollPane.setPreferredSize(new Dimension(600, 100));
mainPanel.add(scrollPane, BorderLayout.CENTER);
connectionPanel = new JPanel();
connectionPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
lblServerHost = new JLabel("Server Host");
connectionPanel.add(lblServerHost);
seedHostTextField = new JTextField();
seedHostTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
params.host = seedHostTextField.getText();
}
});
connectionPanel.add(seedHostTextField);
seedHostTextField.setColumns(10);
lblPort = new JLabel("Port");
connectionPanel.add(lblPort);
portTextField = new JTextField();
portTextField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent arg0) {
String newValue = namespaceTextField.getText();
if (newValue != null && newValue != "") {
try {
params.port = Integer.parseInt(newValue);
} catch (NumberFormatException ne) {
// ne.printStackTrace();
}
}
}
});
connectionPanel.add(portTextField);
portTextField.setColumns(4);
lblusername = new JLabel("User");
connectionPanel.add(lblusername);
usernameTextField = new JTextField();
usernameTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
params.user = usernameTextField.getText();
}
});
connectionPanel.add(usernameTextField);
usernameTextField.setColumns(8);
lblpassword = new JLabel("Password");
connectionPanel.add(lblpassword);
passwordTextField = new JPasswordField();
passwordTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
params.user = new String(passwordTextField.getPassword());
}
});
connectionPanel.add(passwordTextField);
passwordTextField.setColumns(8);
lblnameSpace = new JLabel("Namespace");
connectionPanel.add(lblnameSpace);
namespaceTextField = new JTextField();
namespaceTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
params.namespace = namespaceTextField.getText();
}
});
connectionPanel.add(namespaceTextField);
namespaceTextField.setColumns(8);
lblSet = new JLabel("Set");
connectionPanel.add(lblSet);
txtSetTextfield = new JTextField();
txtSetTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
params.set = txtSetTextfield.getText();
}
});
connectionPanel.add(txtSetTextfield);
txtSetTextfield.setColumns(8);
mainPanel.add(connectionPanel, BorderLayout.NORTH);
examplePanel = new JPanel();
examplePanel.setLayout(new BoxLayout(examplePanel, BoxLayout.Y_AXIS));
exampleScrollPane = new JScrollPane(examplePanel);
mainPanel.add(exampleScrollPane, BorderLayout.WEST);
// init values
seedHostTextField.setText(params.host);
portTextField.setText(Integer.toString(params.port));
namespaceTextField.setText(params.namespace);
txtSetTextfield.setText(params.set);
// int width = 785;
int width = 1000;
int height = 180;
consoleTextArea = new JTextArea();
consoleTextArea.setSize(new Dimension(width, height));
consoleTextArea.setEditable(false);
consoleScrollPane = new JScrollPane(consoleTextArea);
consoleScrollPane.setPreferredSize(new Dimension(width, height));
consoleScrollPane.setSize(new Dimension(width, height));
splitPane.setRightComponent(consoleScrollPane);
buttonGroup = new ButtonGroup();
JRadioButton jrb;
for (String example : Main.getAllExampleNames()) {
jrb = new JRadioButton(example);
jrb.setActionCommand(example);
jrb.addActionListener(this);
buttonGroup.add(jrb);
examplePanel.add(jrb);
}
frmAerospikeExamples.pack();
}
use of java.awt.event.KeyAdapter in project knime-core by knime.
the class JSnippetPanel method initComponents.
private void initComponents() {
m_colList = new JList(new DefaultListModel());
m_colList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_colList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_colList.getSelectedValue();
if (selected != null) {
onSelectionInColumnList(selected);
}
}
}
});
m_colList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_colList.getSelectedValue();
if (selected != null) {
onSelectionInColumnList(selected);
}
}
}
});
m_colList.setCellRenderer(new ListRenderer());
m_flowVarsList = new JList(new DefaultListModel());
m_flowVarsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// enable tooltip
m_flowVarsList.setToolTipText("");
m_flowVarsList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_flowVarsList.getSelectedValue();
if (selected != null) {
onSelectionInVariableList(selected);
}
}
}
});
m_flowVarsList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_flowVarsList.getSelectedValue();
if (selected != null) {
onSelectionInVariableList(selected);
}
}
}
});
m_flowVarsList.setCellRenderer(new FlowVariableListCellRenderer());
m_categories = new JComboBox(m_manipProvider.getCategories().toArray());
m_categories.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
String category = (String) cb.getSelectedItem();
updateManipulatorList(category);
}
});
m_manipulators = new JList(new DefaultListModel());
m_manipulators.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_manipulators.setCellRenderer(new ManipulatorListCellRenderer());
m_manipulators.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
onSelectionInManipulatorList(selected);
}
}
}
});
m_manipulators.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
onSelectionInManipulatorList(selected);
}
}
}
});
m_manipulators.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
Manipulator manipulator = (Manipulator) selected;
m_description.setText(manipulator.getDescription());
m_description.setCaretPosition(0);
} else {
m_description.setText("");
}
}
});
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet css = new StyleSheet();
css.addRule("* { font-family: sans-serif; }");
kit.setStyleSheet(css);
m_description = new JTextPane();
m_description.setEditorKit(kit);
m_description.setEditable(false);
m_description.setBackground(getBackground());
updateManipulatorList(ManipulatorProvider.ALL_CATEGORY);
initSubComponents();
}
use of java.awt.event.KeyAdapter in project knime-core by knime.
the class WrappedMultipleNodeDialog method createButtonsForButtonBar.
/**
* {@inheritDoc}
*/
@Override
protected void createButtonsForButtonBar(final Composite parent) {
// WORKAROUND: can't use IDialogConstants.OK_ID here, as this always
// closes the dialog, regardless if the settings couldn't be applied.
final Button btnOK = createButton(parent, IDialogConstants.NEXT_ID, IDialogConstants.OK_LABEL, false);
final Button btnCancel = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
((GridLayout) parent.getLayout()).numColumns++;
this.swtKeyListener = new KeyListener() {
/**
* {@inheritDoc}
*/
@Override
public void keyReleased(final KeyEvent ke) {
// TODO there's no point to this presently since we don't ever change the text
if (ke.keyCode == SWT.MOD1) {
btnOK.setText("OK");
}
}
/**
* {@inheritDoc}
*/
@Override
public void keyPressed(final KeyEvent ke) {
if (ke.keyCode == SWT.ESC) {
// close dialog on ESC
doCancel();
}
// TODO this does not mimic the same behavior as found in WrappedNodeDialog to change the OK button text
if ((ke.keyCode == SWT.CR) && ((ke.stateMask == SWT.MOD1) || (ke.stateMask == SWT.SHIFT + SWT.MOD1))) {
// force OK - Execute when CTRL/Command and ENTER is pressed
// open first out-port view if SHIFT is pressed
doOK(ke);
}
}
};
this.awtKeyListener = new KeyAdapter() {
@Override
public void keyReleased(final java.awt.event.KeyEvent ke) {
// TODO there's no point to this presently since we don't ever change the text
int menuAccelerator = (Platform.OS_MACOSX.equals(Platform.getOS())) ? java.awt.event.KeyEvent.VK_META : java.awt.event.KeyEvent.VK_CONTROL;
if (ke.getKeyCode() == menuAccelerator) {
getShell().getDisplay().asyncExec(() -> {
btnOK.setText("OK");
});
}
}
@Override
public void keyPressed(final java.awt.event.KeyEvent ke) {
if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
// close dialog on ESC
getShell().getDisplay().asyncExec(() -> {
doCancel();
});
}
// TODO this does not mimic the same behavior as found in WrappedNodeDialog to change the OK button text
int modifierKey = (Platform.OS_MACOSX.equals(Platform.getOS())) ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK;
if ((ke.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) && ((ke.getModifiersEx() & modifierKey) != 0)) {
getShell().getDisplay().asyncExec(() -> {
// force OK - Execute when CTRL/Command and ENTER is pressed
if (doApply()) {
runOK();
}
});
}
}
};
if (!Platform.OS_MACOSX.equals(Platform.getOS())) {
btnOK.addKeyListener(this.swtKeyListener);
btnCancel.addKeyListener(this.swtKeyListener);
m_wrapper.addKeyListener(this.swtKeyListener);
}
// Register listeners that notify the content object, which
// in turn notify the dialog about the particular event.
btnOK.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent se) {
// OK only
doOK(se);
}
});
btnCancel.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent se) {
doCancel();
}
});
}
Aggregations