List of usage examples for java.awt.event KeyEvent getKeyChar
public char getKeyChar()
From source file:EventTestPane.java
/** * Display keyboard events./* w ww . ja v a 2 s . co m*/ * * Note that there are three distinct types of key events, and that key * events are reported by key code and/or Unicode character. KEY_PRESSED and * KEY_RELEASED events are generated for all key strokes. KEY_TYPED events * are only generated when a key stroke produces a Unicode character; these * events do not report a key code. If isActionKey() returns true, then the * key event reports only a key code, because the key that was pressed or * released (such as a function key) has no corresponding Unicode character. * Key codes can be interpreted by using the many VK_ constants defined by * the KeyEvent class, or they can be converted to strings using the static * getKeyText() method as we do here. */ public void processKeyEvent(KeyEvent e) { String eventtype, modifiers, code, character; switch (e.getID()) { case KeyEvent.KEY_PRESSED: eventtype = "KEY_PRESSED"; break; case KeyEvent.KEY_RELEASED: eventtype = "KEY_RELEASED"; break; case KeyEvent.KEY_TYPED: eventtype = "KEY_TYPED"; break; default: eventtype = "UNKNOWN"; } // Convert the list of modifier keys to a string modifiers = KeyEvent.getKeyModifiersText(e.getModifiers()); // Get string and numeric versions of the key code, if any. if (e.getID() == KeyEvent.KEY_TYPED) code = ""; else code = "Code=" + KeyEvent.getKeyText(e.getKeyCode()) + " (" + e.getKeyCode() + ")"; // Get string and numeric versions of the Unicode character, if any. if (e.isActionKey()) character = ""; else character = "Character=" + e.getKeyChar() + " (Unicode=" + ((int) e.getKeyChar()) + ")"; // Display it all. showLine(eventtype + ": " + modifiers + " " + code + " " + character); }
From source file:org.scify.talkandplay.gui.users.UserFormPanel.java
/** * The action listeners for the text fields and radio buttons *//*from w ww . j a va 2s .com*/ private void setActionListeners() { selectionSensorTextField1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (selectionSensorTextField1.isEnabled()) { selectionSensor = new MouseSensor(me.getButton(), me.getClickCount(), "mouse"); navigationSensor = null; selectionSensorTextField1.setText(setSensorText(selectionSensor)); } } }); selectionSensorTextField1.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent ke) { if (selectionSensorTextField1.isEnabled()) { selectionSensor = new KeyboardSensor(ke.getKeyCode(), String.valueOf(ke.getKeyChar()), "keyboard"); navigationSensor = null; selectionSensorTextField1.setText(setSensorText(selectionSensor)); } } }); navigationSensorTextField.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (navigationSensorTextField.isEnabled()) { navigationSensor = new MouseSensor(me.getButton(), me.getClickCount(), "mouse"); navigationSensorTextField.setText(setSensorText(navigationSensor)); } } }); navigationSensorTextField.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent ke) { if (navigationSensorTextField.isEnabled()) { navigationSensor = new KeyboardSensor(ke.getKeyCode(), String.valueOf(ke.getKeyChar()), "keyboard"); navigationSensorTextField.setText(setSensorText(navigationSensor)); } } }); selectionSensorTextField2.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (selectionSensorTextField2.isEnabled()) { selectionSensor = new MouseSensor(me.getButton(), me.getClickCount(), "mouse"); selectionSensorTextField2.setText(setSensorText(selectionSensor)); } } }); selectionSensorTextField2.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent ke) { if (selectionSensorTextField2.isEnabled()) { selectionSensor = new KeyboardSensor(ke.getKeyCode(), String.valueOf(ke.getKeyChar()), "keyboard"); selectionSensorTextField2.setText(setSensorText(selectionSensor)); } } }); backButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { parent.changePanel(new MainPanel(parent)); } }); autoScanRadioButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (autoScanRadioButton.isSelected()) { disableTextField(selectionSensorTextField2); disableTextField(navigationSensorTextField); enableTextField(selectionSensorTextField1); } } }); manualScanRadioButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (manualScanRadioButton.isSelected()) { disableTextField(selectionSensorTextField1); enableTextField(selectionSensorTextField2); enableTextField(navigationSensorTextField); } } }); }
From source file:com.github.fritaly.dualcommander.TabbedPane.java
@Override public void keyPressed(KeyEvent e) { if (e.getSource() == getSelectedComponent()) { final boolean metaDown = (e.getModifiersEx() | KeyEvent.META_DOWN_MASK) == KeyEvent.META_DOWN_MASK; if ((e.getKeyCode() == KeyEvent.VK_T) && metaDown) { // Create a new tab and set to focus on it setSelectedComponent(addBrowserTab(getActiveBrowser().getDirectory())); } else if ((e.getKeyCode() == KeyEvent.VK_W) && metaDown) { if (getTabCount() > 1) { // Close the current tab (only if not the last one) closeActiveBrowserTab(); }//from www.ja v a 2s . c om } else if ((e.getKeyCode() >= KeyEvent.VK_1) && (e.getKeyCode() <= KeyEvent.VK_9) && metaDown) { final int index = e.getKeyCode() - KeyEvent.VK_1; if (index <= getTabCount() - 1) { setSelectedIndex(index); } } else { // Propagate event to our listeners processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); } } }
From source file:gdsc.smlm.ij.plugins.SpotAnalysis.java
public void keyTyped(KeyEvent e) { System.out.println("keyTyped"); switch (e.getKeyChar()) { case 'a': addFrame();//from w w w . j a va 2 s . com break; case ',': rawImp.setSlice(rawImp.getSlice() + 1); break; case '.': rawImp.setSlice(rawImp.getSlice() - 1); break; } }
From source file:uk.chromis.pos.forms.JRootApp.java
private void m_txtKeysKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_m_txtKeysKeyTyped if (evt.getModifiers() != 0) { String keys = evt.getKeyModifiersText(evt.getModifiers()) + "+" + evt.getKeyChar(); if ((keys.equals("Alt+Shift+P")) || (keys.equals("Alt+Shift+p"))) { superUserLogin();//from w w w . j a va2 s .c o m } } m_txtKeys.setText("0"); processKey(evt.getKeyChar()); }
From source file:EnvironmentExplorer.java
public void processStimulus(Enumeration criteria) { while (criteria.hasMoreElements()) { wakeup = (WakeupCriterion) criteria.nextElement(); if (wakeup instanceof WakeupOnAWTEvent) { AWTEvent[] evt = ((WakeupOnAWTEvent) wakeup).getAWTEvent(); for (int i = 0; i < evt.length; i++) { if (evt[i] instanceof KeyEvent) { KeyEvent keyEvt = (KeyEvent) evt[i]; System.out.println("Key pressed: '" + keyEvt.getKeyChar() + "'"); }//from w w w . jav a2s. c o m } } } // set the wakeup so we'll get the next event wakeupOn(wakeup); }
From source file:com.eviware.soapui.SoapUI.java
private JComponent buildToolbar() { mainToolbar = new JXToolBar(); mainToolbar.setFloatable(false);/* w ww. j a va 2 s .com*/ mainToolbar.setRollover(true); mainToolbar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); mainToolbar.add(new NewWsdlProjectActionDelegate()); mainToolbar.add(new ImportWsdlProjectActionDelegate()); mainToolbar.add(new SaveAllActionDelegate()); mainToolbar.addSpace(2); mainToolbar.add(new ShowOnlineHelpAction("User Guide", HelpUrls.USERGUIDE_HELP_URL, "Opens the soapUI User-Guide in a browser")); mainToolbar.add(new ShowOnlineHelpAction("Forum", HelpUrls.FORUMS_HELP_URL, "Opens the soapUI Forum in a browser", "/group_go.png")); mainToolbar.addSpace(2); mainToolbar.add(new ShowOnlineHelpAction("Trial", HelpUrls.TRIAL_URL, "Apply for soapUI Pro Trial License", "/favicon.png")); mainToolbar.addSpace(2); mainToolbar.add(new PreferencesActionDelegate()); applyProxyButton = (JToggleButton) mainToolbar.add(new JToggleButton(new ApplyProxyButtonAction())); ProxyUtils.setProxyEnabled(getSettings().getBoolean(ProxySettings.ENABLE_PROXY)); if (ProxyUtils.isProxyEnabled()) { applyProxyButton.setIcon(UISupport.createImageIcon(PROXY_ENABLED_ICON)); applyProxyButton.setSelected(true); ProxyUtils.setProxyEnabled(true); } else { applyProxyButton.setIcon(UISupport.createImageIcon(PROXY_DISABLED_ICON)); ProxyUtils.setProxyEnabled(false); } launchLoadUIButton = mainToolbar.add(new LaunchLoadUIButtonAction()); // mainToolbar.add( new ExitButtonAction() ); mainToolbar.addGlue(); searchField = new JTextField(20); searchField.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == '\n') { doForumSearch(searchField.getText()); } } }); mainToolbar.addLabeledFixed("Search Forum", searchField); mainToolbar.add(new ToolbarForumSearchAction()); mainToolbar.add(new ShowOnlineHelpAction(HelpUrls.USERGUIDE_HELP_URL)); for (int i = 0; i < mainToolbar.getComponentCount(); i++) { if (mainToolbar.getComponent(i) instanceof JComponent) { ((JComponent) mainToolbar.getComponent(i)).setBorder(BorderFactory.createEmptyBorder(4, 2, 4, 2)); } } mainToolbar.setBorder(BorderFactory.createEmptyBorder(3, 1, 3, 1)); return mainToolbar; }
From source file:PVGraph.java
public PVGraph(Calendar date, int initialViewIndex) { super(WINDOW_TITLE_PREFIX); this.date = date; synchronized (graphs) { graphs.add(this); }//ww w . j a v a 2 s .co m views = new PVGraphView[4]; views[DAY_VIEW_INDEX] = new DayView(); views[MONTH_VIEW_INDEX] = new MonthView(); views[YEAR_VIEW_INDEX] = new YearView(); views[YEARS_VIEW_INDEX] = new YearsView(); tabPane = new JTabbedPane(); for (PVGraphView v : views) tabPane.addTab(v.getTabLabel(), v.makePanel()); tabPane.setSelectedIndex(initialViewIndex); setContentPane(tabPane); pack(); try { java.net.URL url = getClass().getResource("sun.png"); if (url != null) setIconImage(ImageIO.read(url)); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } ; setVisible(true); KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent ke) { Object src = ke.getSource(); if (src instanceof JComponent && ((JComponent) src).getRootPane().getContentPane() == tabPane) { if (ke.getID() == KeyEvent.KEY_TYPED) { switch (ke.getKeyChar()) { case 'd': tabPane.setSelectedIndex(DAY_VIEW_INDEX); return true; case 'm': tabPane.setSelectedIndex(MONTH_VIEW_INDEX); return true; case 'N' - 0x40: new PVGraph((Calendar) PVGraph.this.date.clone(), tabPane.getSelectedIndex()); return true; case 'Q' - 0x40: dispatchEvent(new WindowEvent(PVGraph.this, WindowEvent.WINDOW_CLOSING)); return true; case 'R' - 0x40: loadProperties(); updateView(); return true; case 'S': try { runSmatool(); updateView(); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } return true; case 'y': tabPane.setSelectedIndex(YEAR_VIEW_INDEX); return true; case 'Y': tabPane.setSelectedIndex(YEARS_VIEW_INDEX); return true; default: return views[tabPane.getSelectedIndex()].handleKey(ke.getKeyChar()); } } } return false; } }); }
From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java
@Override public void keyPressed(KeyEvent e) { if (e.getSource() != table) { return;/*from w w w.jav a 2s. c om*/ } if (e.getKeyCode() == KeyEvent.VK_ENTER) { // What's the current selection ? final List<File> selection = getSelection(); if (selection.size() == 1) { final File selectedFile = selection.iterator().next(); if (selectedFile.isDirectory()) { // Change to the selected directory setDirectory(selectedFile); } } } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { // Return to the parent directory (if any) final File parentDir = getParentDirectory(); if ((parentDir != null) && parentDir.exists()) { setDirectory(parentDir); } } else { // Propagate event to our listeners processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); } }
From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java
protected void init() { final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate(); mainPanel = new JPanel(); double sizeHeader[][] = { { TableLayout.PREFERRED, 5, TableLayout.PREFERRED, 10 }, { 10, 25, 10 } }; panelHeader = new JPanel(); panelHeader.setLayout(new TableLayout(sizeHeader)); clcttfName.setLabelText(localeDelegate.getMessage("nuclos.entityfield.entityrelation.name.label", "Name")); clcttfName.setToolTipText(/* ww w . j a v a 2 s.c om*/ localeDelegate.getMessage("nuclos.entityfield.entityrelation.name.description", "Name")); clcttfName.setColumns(20); panelHeader.add(this.clcttfName.getJComponent(), "0,1"); clcttfDescription.setLabelText( localeDelegate.getMessage("nuclos.entityfield.entityrelation.description.label", "Beschreibung")); clcttfDescription.setToolTipText(localeDelegate .getMessage("nuclos.entityfield.entityrelation.description.description", "Beschreibung")); clcttfDescription.setColumns(20); panelHeader.add(this.clcttfDescription.getJComponent(), "2,1"); double size[][] = { { 5, TableLayout.FILL, 5 }, { 35, 5, TableLayout.FILL, 5 } }; TableLayout layout = new TableLayout(size); layout.setVGap(3); layout.setHGap(5); mainPanel.setLayout(layout); mainPanel.add(panelHeader, "1,0"); MyGraphModel model = new MyGraphModel(graphComponent, this, mf); mxGraph myGraph = new MyGraph(model); mxCodecRegistry.register(new mxModelCodec(model)); mxCodecRegistry.register(new mxModelCodec(new java.sql.Date(System.currentTimeMillis()))); mxCodecRegistry.register(new mxModelCodec(new Integer(0))); addEventListener(myGraph); graphComponent = new mxGraphComponent(myGraph); graphComponent.setGridVisible(true); graphComponent.getViewport().setOpaque(false); graphComponent.setBackground(Color.WHITE); graphComponent.setToolTips(true); graphComponent.setCellEditor(new MyCellEditor(graphComponent)); model.setGraphComponent(graphComponent); graphComponent.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_DELETE) { mxCell cell = (mxCell) graphComponent.getGraph().getSelectionModel().getCell(); if (cell.getValue() instanceof EntityMetaDataVO) { int iEdge = cell.getEdgeCount(); for (int i = 0; i < iEdge; i++) { mxCell cellRelation = (mxCell) cell.getEdgeAt(i); getGraphModel().remove(cellRelation); } getGraphModel().remove(cell); fireChangeListenEvent(); } else if (cell.getValue() instanceof EntityFieldMetaDataVO) { int opt = JOptionPane.showConfirmDialog(mainPanel, localeDelegate.getMessage("nuclos.entityrelation.editor.7", "M\u00f6chten Sie die Verbindung wirklich l\u00f6sen?")); if (opt != 0) { return; } mxCell cellSource = (mxCell) cell.getSource(); if (cellSource != null && cellSource.getValue() instanceof EntityMetaDataVO) { EntityMetaDataVO metaSource = (EntityMetaDataVO) cellSource.getValue(); if (cell.getValue() instanceof EntityFieldMetaDataVO) { EntityFieldMetaDataVO voField = (EntityFieldMetaDataVO) cell.getValue(); voField.flagRemove(); List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>(); EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO(); toField.setEntityFieldMeta(voField); toList.add(toField); MetaDataDelegate.getInstance().modifyEntityMetaData(metaSource, toList); if (mpRemoveRelation.containsKey(metaSource)) { mpRemoveRelation.get(metaSource).add(voField); } else { Set<EntityFieldMetaDataVO> s = new HashSet<EntityFieldMetaDataVO>(); s.add(voField); mpRemoveRelation.put(metaSource, s); } } } mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); model.remove(cell); EntityRelationshipModelEditPanel.this.fireChangeListenEvent(); } else if (cell.getValue() != null && cell.getValue() instanceof String) { String sValue = (String) cell.getValue(); if (sValue.length() == 0) { getGraphModel().remove(cell); EntityRelationshipModelEditPanel.this.fireChangeListenEvent(); } } } } }); createMouseWheelListener(); createMouseListener(); //mainPanel.add(graphComponent, "1,2, 4,4"); mainPanel.add(graphComponent, "1,2"); this.add(mainPanel); }