List of usage examples for java.awt.event KeyEvent getKeyCode
public int getKeyCode()
From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidIconsImporter.java
public AndroidIconsImporter(@Nullable final Project project, Module module) { super(project, true); this.project = project; setTitle("Android Icons Importer"); setResizable(false);// w ww. ja va2 s . c o m AndroidResourcesHelper.initResourceBrowser(project, module, "Select res root", this.resRoot); assetRoot = SettingsHelper.getAssetPath(IconPack.ANDROID_ICONS); colorSpinner.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { assetColor = (String) colorSpinner.getSelectedItem(); updateImage(); } }); AssetSpinnerRenderer renderer = new AssetSpinnerRenderer(); //noinspection GtkPreferredJComboBoxRenderer assetSpinner.setRenderer(renderer); assetSpinner.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { assetName = (String) assetSpinner.getSelectedItem(); updateImage(); } }); fillComboBoxes(); resExportName.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent keyEvent) { super.keyTyped(keyEvent); if (!exportNameChanged && keyEvent != null && keyEvent.getKeyCode() > -1) { exportNameChanged = true; } } @Override public void keyPressed(KeyEvent keyEvent) { super.keyPressed(keyEvent); } @Override public void keyReleased(KeyEvent keyEvent) { super.keyReleased(keyEvent); } }); imageContainer.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { super.componentResized(e); updateImage(); } }); init(); }
From source file:net.rptools.tokentool.ui.TokenCompositionPanel.java
public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { case java.awt.event.KeyEvent.VK_UP: tokenOffsetY += -1;//from w w w. j a v a 2 s .com repaint(); fireCompositionChanged(); break; case java.awt.event.KeyEvent.VK_DOWN: tokenOffsetY += 1; repaint(); fireCompositionChanged(); break; case java.awt.event.KeyEvent.VK_LEFT: tokenOffsetX += -1; repaint(); fireCompositionChanged(); break; case java.awt.event.KeyEvent.VK_RIGHT: tokenOffsetX += 1; repaint(); fireCompositionChanged(); } }
From source file:org.kalypso.ogc.gml.map.widgets.GetFeatureInfoWidget.java
/** * @see org.kalypso.ogc.gml.widgets.AbstractWidget#keyPressed(java.awt.event.KeyEvent) *//*from www . j a va 2s . com*/ @Override public void keyPressed(final KeyEvent event) { /* Get the key code. */ final int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.VK_SPACE: { openDialog(); break; } } }
From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java
public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { JList<String> jlist = (JList<String>) e.getComponent(); if (jlist.getSelectedIndex() >= 0) { if (jlist.equals(lstAmazon)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.AWS, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Amazon S3."); corruptedItems.remove("amazon" + jlist.getSelectedValue()); } else if (jlist.equals(lstAzure)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.AZURE, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Azure."); corruptedItems.remove("azure" + jlist.getSelectedValue()); } else if (jlist.equals(lstGoogle)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.GOOGLE, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Google."); corruptedItems.remove("google" + jlist.getSelectedValue()); } else if (jlist.equals(lstRackspace)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.RACKSPACE, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Rackspace."); corruptedItems.remove("rackspace" + jlist.getSelectedValue()); } else if (jlist.equals(lstHybris)) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS, jlist.getSelectedValue(), null)).start(); System.out.println("Removed " + jlist.getSelectedValue() + " from Hybris."); }/* w w w.jav a 2 s.c om*/ } } else if (e.getKeyChar() == 'c') { JList<String> jlist = (JList<String>) e.getComponent(); if (jlist.getSelectedIndex() >= 0) { byte[] corruptedPayload = "I_AM_THE_BOGUS_PAYLOAD".getBytes(); if (jlist.equals(lstAmazon)) { JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Amazon S3.", "Corruption", JOptionPane.WARNING_MESSAGE); System.out.println("Corrupted " + jlist.getSelectedValue() + " on Amazon S3."); corruptedItems.add("amazon" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.AWS, jlist.getSelectedValue(), corruptedPayload)).start(); } else if (jlist.equals(lstAzure)) { System.out.println("Corrupted " + jlist.getSelectedValue() + " on Azure."); JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Azure.", "Corruption", JOptionPane.WARNING_MESSAGE); corruptedItems.add("azure" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.AZURE, jlist.getSelectedValue(), corruptedPayload)).start(); } else if (jlist.equals(lstGoogle)) { JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Google.", "Corruption", JOptionPane.WARNING_MESSAGE); System.out.println("Corrupted " + jlist.getSelectedValue() + " on Google."); corruptedItems.add("google" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.GOOGLE, jlist.getSelectedValue(), corruptedPayload)).start(); } else if (jlist.equals(lstRackspace)) { JOptionPane.showMessageDialog(frame, "Corrupted " + jlist.getSelectedValue() + " on Rackspace.", "Corruption", JOptionPane.WARNING_MESSAGE); System.out.println("Corrupted " + jlist.getSelectedValue() + " on Rackspace."); corruptedItems.add("rackspace" + jlist.getSelectedValue()); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.RACKSPACE, jlist.getSelectedValue(), corruptedPayload)).start(); } } } }
From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java
@Override public JComponent createComponent() { // create the component, that is shown in the sidebar final HelloWorldList list = new HelloWorldList(); list.setModel(ObjectUtils.defaultIfNull(createListModel(), new DefaultListModel<>())); list.setCellRenderer(new HelloWorldListRenderer()); // register keyboard events list.addKeyListener(new KeyAdapter() { @Override// w w w. ja va 2 s . co m public void keyPressed(KeyEvent e) { if (!list.isEnabled()) return; // ENTER was pressed if (e.getKeyCode() == KeyEvent.VK_ENTER) { DbHelloWorldObject object = list.getSelectedValue(); if (object != null) new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null); } } }); // register mouse events list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (!list.isEnabled()) return; // single click with the right mouse button if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) { // fetch the clicked element int index = list.locationToIndex(e.getPoint()); if (index >= 0) list.setSelectedIndex(index); // show popup menu with further actions DbHelloWorldObject object = list.getSelectedValue(); JPopupMenu popup = createActionMenu(object); if (popup != null) popup.show(list, e.getPoint().x, e.getPoint().y); } // double click with the left mouse button else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { DbHelloWorldObject object = list.getSelectedValue(); if (object != null) new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null); } } }); return list; }
From source file:org.squidy.designer.zoom.NavigationShape.java
/** * Default constructor required for JAXB. *///from w w w . ja va 2 s .c o m public NavigationShape() { super(); addInputEventListener(new PBasicInputEventHandler() { private JTextField titleInput = new JTextField(getTitle()); { titleInputWrapper = new JComponentWrapper(titleInput); titleInput.setFont(fontBreadcrumb); addChild(titleInputWrapper); // titleInputWrapper.setScale(2); ShapeUtils.setApparent(titleInputWrapper, false); titleInput.addKeyListener(new KeyAdapter() { /** * @param e */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (ShapeUtils.isApparent(titleInputWrapper)) { prepareTitleIfNecessary(); } } } }); } /** * Prepare title if user did new input and title is different than * current title. */ void prepareTitleIfNecessary() { String oldTitle = getTitle(); String newTitle = titleInput.getText(); if (!oldTitle.equals(newTitle)) { if (changeTitle(oldTitle, newTitle)) { setTitle(titleInput.getText()); ShapeUtils.setApparent(titleInputWrapper, false); invalidateTitle(); invalidateBreadcrumb(); invalidatePaint(); } } else { ShapeUtils.setApparent(titleInputWrapper, false); } } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseClicked * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseClicked(PInputEvent event) { if (!event.isHandled()) { switch (event.getClickCount()) { case 1: if (!event.getPickedNode().equals(titleInputWrapper) && ShapeUtils.isApparent(titleInputWrapper)) { prepareTitleIfNecessary(); event.setHandled(true); } break; case 2: Point2D p = event.getPositionRelativeTo(NavigationShape.this); if (titleBounds != null && titleBounds.contains(p)) { if (!ShapeUtils.isApparent(titleInputWrapper)) { titleInputWrapper.setOffset(titleBounds.getX(), titleBounds.getY()); titleInput.setText(getTitle()); // titleInput.requestFocus(); ShapeUtils.setApparent(titleInputWrapper, true); } event.setHandled(true); } break; } } } }); }
From source file:de.codesourcery.jasm16.ide.ui.viewcontainers.EditorContainer.java
private JPanel createPanel() { final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH); setColors(result);/* ww w . j a v a2 s . c o m*/ tabbedPane.setBackground(Color.WHITE); tabbedPane.setForeground(Color.black); result.add(tabbedPane, cnstrs); if (getViewContainer().getMenuManager() != null) { getViewContainer().getMenuManager().addEntry(saveCurrent); } tabbedPane.addChangeListener(changeListener); tabbedPane.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_W && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) { int idx = tabbedPane.getSelectedIndex(); if (idx != -1) { disposeView(getViewForTabIndex(idx)); } } } }); return result; }
From source file:edu.ku.brc.af.ui.db.JEditComboBox.java
protected KeyAdapter createKeyAdapter() { return new KeyAdapter() { @Override// w w w. j ava 2 s . c o m public void keyReleased(KeyEvent ev) { char key = ev.getKeyChar(); if (ev.getKeyCode() == clearKeyStroke.getKeyCode()) { int selectedIndex = getSelectedIndex(); if (selectedIndex > -1 && dbAdapter != null && textField != null && textField.getText().length() == 0 && !dbAdapter.isReadOnly()) { // delete item PickListItem item = (PickListItem) getSelectedItem(); dbAdapter.getList().remove(item); } } else if (!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) { if (ev.getKeyCode() == KeyEvent.VK_ENTER) { addNewItemFromTextField(); } } else { if (textField != null) { if (getSelectedIndex() > -1) { int pos = textField.getCaretPosition(); String currentText = textField.getText(); setSelectedIndex(-1); textField.setText(currentText); textField.moveCaretPosition(pos); textField.setSelectionStart(pos); textField.setSelectionEnd(pos); } } else { setSelectedIndex(-1); } } } }; }
From source file:com.tradedesksoftware.ets.client.charting.ChartShiftController.java
/** * Pan/Shifts a plot if the arrow keys are pressed. * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) *//* w ww .j a va 2s . c o m*/ public void keyPressed(KeyEvent e) { if (!plotSupported) return; int keyCode = e.getKeyCode(); // we're only interested in arrows (code 37,38,39,40) if ((keyCode < 37) || (keyCode > 40)) return; // The axis we're gonna shift ValueAxis axis = null; // Delta is the amount we'll shift in axis units. double delta; boolean domainShift = false; // used for PAN_FIXED // Calculations for the domain axis if ((keyCode == KeyEvent.VK_LEFT) || (keyCode == KeyEvent.VK_RIGHT)) { axis = getPlotAxis(chartPanel.getChart(), !axesSwaped); domainShift = true; } // Calculations for the range axis else { axis = getPlotAxis(chartPanel.getChart(), axesSwaped); } // Let's calculate 'delta', the amount by which we'll shift the plot switch (shiftType) { case SHIFT_PERCENTUAL: delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0; break; case SHIFT_FIXED: delta = (domainShift ? fixedDomainShiftUnits : fixedRangeShiftUnits); break; case SHIFT_PIXEL: // also the default default: // Let's find out what's the range for 1 pixel. final Rectangle scaledDataArea = chartPanel.getScreenDataArea(); delta = axis.getRange().getLength() / (scaledDataArea.width); break; } // Shift modifier multiplies delta by 10 if (e.isShiftDown()) { delta *= 10; } switch (keyCode) { case KeyEvent.VK_LEFT: case KeyEvent.VK_DOWN: axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta); break; case KeyEvent.VK_UP: case KeyEvent.VK_RIGHT: axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta); break; } }
From source file:org.lisapark.octopus.swing.BaseFormattedTextField.java
/** * Invoked to process the key bindings for <code>ks</code> as the result * of the <code>KeyEvent</code> <code>e</code>. We override this method to make * sure that the text field has the proper action for when the user presses * the enter key// ww w . j av a2s. c o m * * @param ks the <code>KeyStroke</code> queried * @param e the <code>KeyEvent</code> * @param condition one of the following values: * <ul> * <li>JComponent.WHEN_FOCUSED * <li>JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT * <li>JComponent.WHEN_IN_FOCUSED_WINDOW * </ul> * @param pressed true if the key is pressed * @return true if there was a binding to an action, and the action * was enabled */ protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { // we need to override this method to allow for handling of the delete key properly if (e.getKeyCode() == KeyEvent.VK_ENTER) { InputMap map = getInputMap(condition); ActionMap am = getActionMap(); if (map != null && am != null && isEnabled()) { Object binding = map.get(ks); Action action; // replace the nofify action if necessary if (binding != null && binding.equals(JTextField.notifyAction)) { action = am.get(binding); if (action != commitOnEnterAction) { am.put(JTextField.notifyAction, commitOnEnterAction); } } } } return super.processKeyBinding(ks, e, condition, pressed); }