List of usage examples for java.awt.event KeyEvent getKeyChar
public char getKeyChar()
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
@Override public void keyPressed(KeyEvent e) { if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) { JTextComponent comp = (JTextComponent) e.getSource(); // replace typed characters by characters from completion lastBeginning = lastCompletions.get(lastShownCompletion); int end = comp.getSelectionEnd(); comp.select(end, end);/*ww w .j a va2s. com*/ toSetIn = null; if (consumeEnterKey) { e.consume(); } } // Cycle through alternative completions when user presses PGUP/PGDN: else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), 1); e.consume(); } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), -1); e.consume(); } // else if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) { // StringBuffer currentword = getCurrentWord((JTextComponent) e.getSource()); // // delete last char to obey semantics of back space // currentword.deleteCharAt(currentword.length()-1); // doCompletion(currentword, e); // } else if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { if (e.getKeyCode() == KeyEvent.VK_SHIFT) { // shift is OK, everything else leads to a reset LOGGER.debug("Special case: shift pressed. No action."); } else { resetAutoCompletion(); } } else { LOGGER.debug("Special case: defined character, but not caught above"); } }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
@Override public void keyPressed(KeyEvent e) { if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) { JTextComponent comp = (JTextComponent) e.getSource(); // replace typed characters by characters from completion lastBeginning = lastCompletions[lastShownCompletion]; int end = comp.getSelectionEnd(); comp.select(end, end);/* ww w. jav a 2 s.c o m*/ toSetIn = null; if (consumeEnterKey) { e.consume(); } } // Cycle through alternative completions when user presses PGUP/PGDN: else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), 1); e.consume(); } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), -1); e.consume(); } // else if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) { // StringBuffer currentword = getCurrentWord((JTextComponent) e.getSource()); // // delete last char to obey semantics of back space // currentword.deleteCharAt(currentword.length()-1); // doCompletion(currentword, e); // } else if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { if (e.getKeyCode() != KeyEvent.VK_SHIFT) { // shift is OK, everyhting else leads to a reset resetAutoCompletion(); } else { LOGGER.debug("Special case: shift pressed. No action."); } } else { LOGGER.debug("Special case: defined character, but not caught above"); } }
From source file:plugin.notes.gui.NotesView.java
private void editorKeyTyped(KeyEvent evt) { editor.getCaretPosition();// w ww . j a v a 2 s . c o m editor.getStyledDocument(); if (evt.getKeyChar() == KeyEvent.VK_BACK_SPACE) { handleBackspace(); } else if (evt.getKeyChar() == KeyEvent.VK_ENTER) { handleEnter(); } }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
/** * Start a new completion attempt (instead of treating a continuation of an existing word or an interrupt of the * current word)//from w w w . j a va 2s . co m */ private void startCompletion(StringBuffer currentword, KeyEvent e) { JTextComponent comp = (JTextComponent) e.getSource(); List<String> completed = findCompletions(currentword.toString()); String prefix = completer.getPrefix(); String cWord = (prefix != null) && (!prefix.isEmpty()) ? currentword.toString().substring(prefix.length()) : currentword.toString(); LOGGER.debug("StartCompletion currentword: >" + currentword + "'<' prefix: >" + prefix + "'<' cword: >" + cWord + '<'); int no = 0; // We use the first word in the array of completions. if ((completed != null) && (!completed.isEmpty())) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed.get(no); // these two lines obey the user's input //toSetIn = Character.toString(ch); //toSetIn = toSetIn.concat(sno.substring(cWord.length())); // BUT we obey the completion toSetIn = sno.substring(cWord.length() - 1); LOGGER.debug("toSetIn: >" + toSetIn + '<'); StringBuilder alltext = new StringBuilder(comp.getText()); int cp = comp.getCaretPosition(); alltext.insert(cp, toSetIn); comp.setText(alltext.toString()); comp.setCaretPosition(cp); comp.select(cp + 1, (cp + 1 + sno.length()) - cWord.length()); e.consume(); lastCaretPosition = comp.getCaretPosition(); char ch = e.getKeyChar(); LOGGER.debug("Appending >" + ch + '<'); if (cWord.length() <= 1) { lastBeginning = Character.toString(ch); } else { lastBeginning = cWord.substring(0, cWord.length() - 1).concat(Character.toString(ch)); } } }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
/** * Start a new completion attempt//from w w w . ja va 2s.c om * (instead of treating a continuation of an existing word or an interrupt of the current word) */ private void startCompletion(StringBuffer currentword, KeyEvent e) { JTextComponent comp = (JTextComponent) e.getSource(); String[] completed = findCompletions(currentword.toString(), comp); String prefix = completer.getPrefix(); String cWord = (prefix != null) && (!prefix.isEmpty()) ? currentword.toString().substring(prefix.length()) : currentword.toString(); LOGGER.debug("StartCompletion currentword: >" + currentword + "'<' prefix: >" + prefix + "'<' cword: >" + cWord + '<'); int no = 0; // We use the first word in the array of completions. if ((completed != null) && (completed.length > 0)) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed[no]; // these two lines obey the user's input //toSetIn = Character.toString(ch); //toSetIn = toSetIn.concat(sno.substring(cWord.length())); // BUT we obey the completion toSetIn = sno.substring(cWord.length() - 1); LOGGER.debug("toSetIn: >" + toSetIn + '<'); StringBuilder alltext = new StringBuilder(comp.getText()); int cp = comp.getCaretPosition(); alltext.insert(cp, toSetIn); comp.setText(alltext.toString()); comp.setCaretPosition(cp); comp.select(cp + 1, (cp + 1 + sno.length()) - cWord.length()); e.consume(); lastCaretPosition = comp.getCaretPosition(); char ch = e.getKeyChar(); LOGGER.debug("Appending >" + ch + '<'); if (cWord.length() <= 1) { lastBeginning = Character.toString(ch); } else { lastBeginning = cWord.substring(0, cWord.length() - 1).concat(Character.toString(ch)); } } }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
public void keyPressed(final KeyEvent event) { canvasLock.lock();/*from w w w .j a va 2 s . c om*/ char key = event.getKeyChar(); if (key == '+' || key == '=' || key == '-') { // Zoom float dS = 1.33f; float scale = 1.0f; float[] cp = { 0.0f, 0.0f }; float[] sc = { 0.0f, 0.0f }; Point mousePos = canvas.getMousePosition(); this.convertMousePointToSceneSpace(mousePos, cp); sc[0] = SceneGraph.getSceneCenterX(); sc[1] = SceneGraph.getSceneCenterY(); switch (key) { case '+': case '=': scale = 1 / dS; break; case '-': scale = dS; break; } SceneGraph.scaleScene(scale); float ncp[] = { 0.0f, 0.0f }; this.convertMousePointToSceneSpace(mousePos, ncp); ncp[0] = ncp[0] - cp[0]; ncp[1] = ncp[1] - cp[1]; SceneGraph.panScene(-ncp[0], -ncp[1]); } else if (key == 'j' || key == 'J') { CorelyzerApp app = CorelyzerApp.getApp(); app.getMainFrame().setAlwaysOnTop(false); String inputValue = JOptionPane.showInputDialog(getPopupParent(), "Please input the depth to jump to in meters: "); app.getMainFrame().setAlwaysOnTop(true); if (inputValue == null) { return; } try { float depthValue = Float.parseFloat(inputValue); float dpix = SceneGraph.getCanvasDPIX(this.canvasId); float dpiy = SceneGraph.getCanvasDPIY(this.canvasId); float px, py; if (SceneGraph.getDepthOrientation()) { px = depthValue * 100.0f / 2.54f * dpix; py = 0; } else { px = 0; py = depthValue * 100.0f / 2.54f * dpiy; } SceneGraph.lock(); { SceneGraph.positionScene(px, py); } SceneGraph.unlock(); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(getPopupParent(), "Please type in a number", "Alert", JOptionPane.ERROR_MESSAGE); } } else if (key == KeyEvent.VK_OPEN_BRACKET || key == KeyEvent.VK_CLOSE_BRACKET || key == '9' || key == '0') { // graph scaling float dS = 1.00f; if (key == KeyEvent.VK_OPEN_BRACKET || key == '9') { dS = 1.0f / 1.33f; } else if (key == KeyEvent.VK_CLOSE_BRACKET || key == '0') { dS = 1.33f; } SceneGraph.setGraphScale(dS); // SceneGraph.setMarkerScale(dS); } else if (key == 'D') { // Show onscreen debug information in // scenegraph boolean b = SceneGraph.getDebug(); SceneGraph.setDebug(!b); } else if (key == 'Q' || key == 'W' || key == 'E' || key == 'R') { int keyId = 0; if (key == 'Q') keyId = 1; // scaling if (key == 'W') keyId = 2; // labels if (key == 'E') keyId = 3; // border else if (key == 'R') keyId = 4; // scissoring SceneGraph.debugKey(keyId); } else { // pan float movX = 0.0f; float movY = 0.0f; int dX = 10; int dY = 10; float sx, sy; float w, h; w = SceneGraph.getCanvasWidth(canvasId); h = SceneGraph.getCanvasHeight(canvasId); sx = w / canvas.getWidth(); sy = h / canvas.getHeight(); switch (event.getKeyCode()) { case KeyEvent.VK_UP: movX = 0.0f; movY = -dY * sy; break; case KeyEvent.VK_DOWN: movX = 0.0f; movY = dY * sy; break; case KeyEvent.VK_LEFT: movX = -dX * sx; movY = 0.0f; break; case KeyEvent.VK_RIGHT: movX = dX * sx; movY = 0.0f; break; } SceneGraph.panScene(movX, movY); } canvasLock.unlock(); CorelyzerApp.getApp().updateGLWindows(); }
From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java
private void formKeyTyped(KeyEvent evt) { if (evt.getKeyChar() == ' ') { if (controlsFrame != null) { controlsFrame.setBounds(30, 30, 220, 500); controlsFrame.setVisible(true); } else if (transientControlsFrame != null) { transientControlsFrame.setBounds(30, 30, 240, 500); transientControlsFrame.setVisible(true); } else if (application != null) { application.getFrames().getGuiPanel().selectModule(name); }/*www . ja va2 s .c om*/ } else if (evt.getKeyChar() == 'c') { moveCamera(); } else if (evt.getKeyChar() == 'o') { moveScene(); } else if (evt.getKeyChar() == 'p') { boolean p = perspective; controlsPanel.togglePerspective(); setDisplayMode(!p); } else if (evt.getKeyChar() == 's') { boolean p = stereoActive; controlsPanel.toggleStereo(); setStereoEnable(!p); } else if (evt.getKeyChar() == '.') { controlsPanel.togglePick3D(); setPick3DActive(!pickObject.isActive()); } else if (evt.getKeyChar() == 'm') { moveCurrentObject(); } }
From source file:org.jcodec.player.app.PlayerMain.java
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { if (player.getStatus() == Player.Status.PAUSED) { if (stepper != null) { player.seek(stepper.getPos()); stepper = null;/* w w w . j a v a 2s .c om*/ } player.play(); } else player.pause(); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { RationalLarge pos = player.getPos(); player.seek(new RationalLarge(pos.getNum() - pos.getDen() * 15, pos.getDen())); } else if (e.getKeyCode() == KeyEvent.VK_UP) { RationalLarge pos = player.getPos(); player.seek(new RationalLarge(pos.getNum() + pos.getDen() * 15, pos.getDen())); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { // if (player.getStatus() != Player.Status.PAUSED) { // player.pause(); // return; // } // // try { // if (stepper == null) { // stepper = new Stepper(video, mixer, vo, new JSoundAudioOut()); // stepper.setListeners(player.getListeners()); // stepper.gotoFrame(player.getFrameNo()); // } // stepper.prev(); // } catch (IOException e1) { // System.out.println("Couldn't step " + e1.getMessage()); // } } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { if (player.getStatus() != Player.Status.PAUSED) { player.pause(); return; } try { if (stepper == null) { stepper = new Stepper(video, mixer, vo, new JSoundAudioOut()); stepper.setListeners(player.getListeners()); stepper.gotoFrame(player.getFrameNo()); } stepper.next(); } catch (IOException e1) { System.out.println("Couldn't step " + e1.getMessage()); } } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { player.destroy(); System.exit(-1); } else if (e.getKeyChar() >= '0' && e.getKeyChar() < '9') { int ch = e.getKeyChar() - '0'; for (Pin pin : mixer.getPins()) { if (ch < pin.getLabels().length) { pin.toggle(ch); break; } else ch -= pin.getLabels().length; } } }
From source file:neembuu.uploader.NeembuuUploader.java
private void neembuuUploaderTableKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_neembuuUploaderTableKeyTyped //If the delete key is pressed, then selected rows must be deleted. //Must be delete key and minimum of one row must be selected. if ((evt.getKeyChar() != KeyEvent.VK_DELETE) || (neembuuUploaderTable.getSelectedRowCount() < 0)) { return;// w w w .ja v a2s . co m } NULogger.getLogger().info("Delete Key event on Main window"); //Must lock queue QueueManager.getInstance().setQueueLock(true); int selectedrow; int[] selectedrows = neembuuUploaderTable.getSelectedRows(); //Remove from the end.. This is the correct way. //If you remove from top, then index will change everytime and it'll be stupid to try to do that way. for (int i = selectedrows.length - 1; i >= 0; i--) { selectedrow = selectedrows[i]; //Remove only if the selected upload is in one of these states. For others, there is stop method. if (UploadStatusUtils.isRowStatusOneOf(selectedrow, UploadStatus.QUEUED, UploadStatus.UPLOADFINISHED, UploadStatus.UPLOADFAILED, UploadStatus.UPLOADSTOPPED)) { NUTableModel.getInstance().removeUpload(selectedrow); NULogger.getLogger().log(Level.INFO, "{0}: Removed row no. {1}", new Object[] { getClass().getName(), selectedrow }); } } //Unlock Queue back QueueManager.getInstance().setQueueLock(false); }
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. ja v a 2s . co m } } 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(); } } } }