List of usage examples for java.awt.event KeyEvent VK_LEFT
int VK_LEFT
To view the source code for java.awt.event KeyEvent VK_LEFT.
Click Source Link
From source file:ucar.unidata.idv.control.chart.PlotWrapper.java
/** * Handle event/*from ww w. j a v a2 s . c om*/ * * @param e The event */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_RIGHT) { panPlot(true); } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { panPlot(false); } else if (e.getKeyCode() == KeyEvent.VK_UP) { upDownPlot(true); } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { upDownPlot(false); } else if ((e.getKeyCode() == KeyEvent.VK_R) && e.isControlDown()) { resetPlot(); } else { super.keyPressed(e); } }
From source file:net.sf.jabref.groups.GroupSelector.java
/** * The first element for each group defines which field to use for the quicksearch. The next two define the name and * regexp for the group./*from ww w . ja va2 s. c o m*/ */ public GroupSelector(JabRefFrame frame, SidePaneManager manager) { super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); this.groupsRoot = new GroupTreeNode(new AllEntriesGroup()); this.frame = frame; hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"), !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"), Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); ButtonGroup nonHits = new ButtonGroup(); nonHits.add(hideNonHits); nonHits.add(grayOut); floatCb.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected()); } }); andCb.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected()); } }); invCb.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected()); } }); showOverlappingGroups.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING, showOverlappingGroups.isSelected()); if (!showOverlappingGroups.isSelected()) { groupsTree.setHighlight2Cells(null); } } }); select.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SELECT_MATCHES, select.isSelected()); } }); grayOut.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected())); JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) { floatCb.setSelected(true); highlCb.setSelected(false); } else { highlCb.setSelected(true); floatCb.setSelected(false); } JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) { andCb.setSelected(true); orCb.setSelected(false); } else { orCb.setSelected(true); andCb.setSelected(false); } showNumberOfElements.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS, showNumberOfElements.isSelected()); if (groupsTree != null) { groupsTree.invalidate(); groupsTree.validate(); groupsTree.repaint(); } } }); autoAssignGroup.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected()); } }); invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS)); showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING)); select.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SELECT_MATCHES)); editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE); editModeCb.setSelected(editModeIndicator); showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); openset.setMargin(new Insets(0, 0, 0, 0)); settings.add(andCb); settings.add(orCb); settings.addSeparator(); settings.add(invCb); settings.addSeparator(); settings.add(select); settings.addSeparator(); settings.add(editModeCb); settings.addSeparator(); settings.add(grayOut); settings.add(hideNonHits); settings.addSeparator(); settings.add(showOverlappingGroups); settings.addSeparator(); settings.add(showNumberOfElements); settings.add(autoAssignGroup); // settings.add(moreRow); // settings.add(lessRow); openset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!settings.isVisible()) { JButton src = (JButton) e.getSource(); showNumberOfElements .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); settings.show(src, 0, openset.getHeight()); } } }); JButton expand = new JButton(IconTheme.JabRefIcon.ADD_ROW.getSmallIcon()); expand.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) + 1; groupsTree.setVisibleRowCount(i); groupsTree.revalidate(); groupsTree.repaint(); GroupSelector.this.revalidate(); GroupSelector.this.repaint(); Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i); LOGGER.info("Height: " + GroupSelector.this.getHeight() + "; Preferred height: " + GroupSelector.this.getPreferredSize().getHeight()); } }); JButton reduce = new JButton(IconTheme.JabRefIcon.REMOVE_ROW.getSmallIcon()); reduce.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) - 1; if (i < 1) { i = 1; } groupsTree.setVisibleRowCount(i); groupsTree.revalidate(); groupsTree.repaint(); GroupSelector.this.revalidate(); // _panel.sidePaneManager.revalidate(); GroupSelector.this.repaint(); Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i); } }); editModeCb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editModeIndicator = editModeCb.getState(); updateBorder(editModeIndicator); Globals.prefs.putBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE, editModeIndicator); } }); int butSize = newButton.getIcon().getIconHeight() + 5; Dimension butDim = new Dimension(butSize, butSize); //Dimension butDimSmall = new Dimension(20, 20); newButton.setPreferredSize(butDim); newButton.setMinimumSize(butDim); refresh.setPreferredSize(butDim); refresh.setMinimumSize(butDim); JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFiles.groupsHelp) .getHelpButton(); helpButton.setPreferredSize(butDim); helpButton.setMinimumSize(butDim); autoGroup.setPreferredSize(butDim); autoGroup.setMinimumSize(butDim); openset.setPreferredSize(butDim); openset.setMinimumSize(butDim); expand.setPreferredSize(butDim); expand.setMinimumSize(butDim); reduce.setPreferredSize(butDim); reduce.setMinimumSize(butDim); Insets butIns = new Insets(0, 0, 0, 0); helpButton.setMargin(butIns); reduce.setMargin(butIns); expand.setMargin(butIns); openset.setMargin(butIns); newButton.addActionListener(this); refresh.addActionListener(this); andCb.addActionListener(this); orCb.addActionListener(this); invCb.addActionListener(this); showOverlappingGroups.addActionListener(this); autoGroup.addActionListener(this); floatCb.addActionListener(this); highlCb.addActionListener(this); select.addActionListener(this); hideNonHits.addActionListener(this); grayOut.addActionListener(this); newButton.setToolTipText(Localization.lang("New group")); refresh.setToolTipText(Localization.lang("Refresh view")); andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups.")); orCb.setToolTipText( Localization.lang("Display all entries belonging to one or more of the selected groups.")); autoGroup.setToolTipText(Localization.lang("Automatically create groups for database.")); invCb.setToolTipText(Localization.lang("Show entries *not* in group selection")); showOverlappingGroups.setToolTipText(Localization .lang("Highlight groups that contain entries contained in any currently selected group")); floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top")); highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection")); select.setToolTipText(Localization.lang("Select entries in group selection")); expand.setToolTipText(Localization.lang("Show one more row")); reduce.setToolTipText(Localization.lang("Show one less rows")); editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries")); ButtonGroup bgr = new ButtonGroup(); bgr.add(andCb); bgr.add(orCb); ButtonGroup visMode = new ButtonGroup(); visMode.add(floatCb); visMode.add(highlCb); JPanel main = new JPanel(); GridBagLayout gbl = new GridBagLayout(); main.setLayout(gbl); GridBagConstraints con = new GridBagConstraints(); con.fill = GridBagConstraints.BOTH; //con.insets = new Insets(0, 0, 2, 0); con.weightx = 1; con.gridwidth = 1; con.gridx = 0; con.gridy = 0; //con.insets = new Insets(1, 1, 1, 1); gbl.setConstraints(newButton, con); main.add(newButton); con.gridx = 1; gbl.setConstraints(refresh, con); main.add(refresh); con.gridx = 2; gbl.setConstraints(autoGroup, con); main.add(autoGroup); con.gridx = 3; con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(helpButton, con); main.add(helpButton); // header.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red)); // helpButton.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red)); groupsTree = new GroupsTree(this); groupsTree.addTreeSelectionListener(this); groupsTree.setModel(groupsTreeModel = new DefaultTreeModel(groupsRoot)); JScrollPane sp = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); revalidateGroups(); con.gridwidth = GridBagConstraints.REMAINDER; con.weighty = 1; con.gridx = 0; con.gridwidth = 4; con.gridy = 1; gbl.setConstraints(sp, con); main.add(sp); JPanel pan = new JPanel(); GridBagLayout gb = new GridBagLayout(); con.weighty = 0; gbl.setConstraints(pan, con); pan.setLayout(gb); con.insets = new Insets(0, 0, 0, 0); con.gridx = 0; con.gridy = 0; con.weightx = 1; con.gridwidth = 4; con.fill = GridBagConstraints.HORIZONTAL; gb.setConstraints(openset, con); pan.add(openset); con.gridwidth = 1; con.gridx = 4; con.gridy = 0; gb.setConstraints(expand, con); pan.add(expand); con.gridx = 5; gb.setConstraints(reduce, con); pan.add(reduce); con.gridwidth = 6; con.gridy = 1; con.gridx = 0; con.fill = GridBagConstraints.HORIZONTAL; con.gridy = 2; con.gridx = 0; con.gridwidth = 4; gbl.setConstraints(pan, con); main.add(pan); main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); add(main, BorderLayout.CENTER); updateBorder(editModeIndicator); definePopup(); NodeAction moveNodeUpAction = new MoveNodeUpAction(); moveNodeUpAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK)); NodeAction moveNodeDownAction = new MoveNodeDownAction(); moveNodeDownAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK)); NodeAction moveNodeLeftAction = new MoveNodeLeftAction(); moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK)); NodeAction moveNodeRightAction = new MoveNodeRightAction(); moveNodeRightAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK)); }
From source file:brainflow.app.toplevel.BrainFlow.java
private void initializeToolBar() { CommandGroup mainToolbarGroup = new CommandGroup("main-toolbar"); mainToolbarGroup.bind(getApplicationFrame()); ToggleGroup interpToggleGroup = new ToggleGroup("toggle-interp-group"); interpToggleGroup.bind(getApplicationFrame()); bindCommand(new OpenImageCommand(), true); bindCommand(new SnapshotCommand(), true); bindCommand(new NewCanvasCommand(), true); bindCommand(new CreateAxialViewCommand(), true); bindCommand(new CreateSagittalViewCommand(), true); bindCommand(new CreateCoronalViewCommand(), true); bindCommand(new CreateMontageViewCommand(), true); bindCommand(new CreateVerticalOrthogonalCommand(), true); bindCommand(new CreateHorizontalOrthogonalCommand(), true); bindCommand(new CreateTriangularOrthogonalCommand(), true); CommandGroup orthoGroup = new CommandGroup("ortho-view-group"); orthoGroup.bind(getApplicationFrame()); final NextSliceCommand nextSliceCommand = new NextSliceCommand(); bindCommand(nextSliceCommand, false); final PreviousSliceCommand previousSliceCommand = new PreviousSliceCommand(); bindCommand(previousSliceCommand, false); bindCommand(new PageBackSliceCommand(), true); bindCommand(new PageForwardSliceCommand(), true); bindCommand(new IncreaseContrastCommand(), true); bindCommand(new DecreaseContrastCommand(), true); bindCommand(new NearestInterpolationToggleCommand(), true); bindCommand(new LinearInterpolationToggleCommand(), true); bindCommand(new CubicInterpolationToggleCommand(), true); bindCommand(new ToggleAxisLabelCommand(), true); bindCommand(new ToggleCrossCommand(), true); //JToolBar mainToolbar = mainToolbarGroup.createToolBar(); final CommandBar mainToolbar = new CommandBar(); // for nimbus look and feel mainToolbar.setPaintBackground(false); // for nimbus look and feel mainToolbar.setBorder(new EmptyBorder(0, 0, 0, 0)); final ButtonFactory buttonFactory = createToolBarButtonFactory(); mainToolbarGroup.visitMembers(new GroupVisitor() { @Override/*from w w w . java 2 s . c o m*/ public void visit(ActionCommand actionCommand) { JideButton jb = new JideButton(actionCommand.getActionAdapter()); jb.setButtonStyle(JideButton.TOOLBAR_STYLE); jb.setText(""); mainToolbar.add(jb); } @Override public void visit(CommandGroup commandGroup) { JComponent jc = commandGroup.createButton(buttonFactory); mainToolbar.add(jc); } }); mainToolbar.setKey("toolbar"); brainFrame.getDockableBarManager().addDockableBar(mainToolbar); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event.getID() == KeyEvent.KEY_PRESSED) { KeyEvent ke = (KeyEvent) event; Component comp = ke.getComponent(); if (ke.getKeyCode() == KeyEvent.VK_LEFT) { ImageView view = BrainFlow.get().getSelectedView(); if (/*view.hasFocus() || */ parentIsImageView(comp)) { previousSliceCommand.execute(); } } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) { ImageView view = BrainFlow.get().getSelectedView(); if ( /*view.hasFocus() */ parentIsImageView(comp)) { nextSliceCommand.execute(); } else { System.out.println("no focus"); } } } } }, AWTEvent.KEY_EVENT_MASK); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event.getID() == MouseEvent.MOUSE_RELEASED) { MouseEvent me = (MouseEvent) event; if (me.isPopupTrigger()) { showActionMenu(me); } } } }, AWTEvent.MOUSE_EVENT_MASK); }
From source file:me.solhub.simple.engine.DebugLocationsStructure.java
/** * Switches the color of the agent from destination to group or vice versa * whenever the space bar is pressed/* w w w . j a va2 s.c o m*/ */ private void handleColorSwitchingInput() { if (_input.isKeyDown(KeyEvent.VK_SPACE) && inputDelayCount > inputDelay) { isDestinationColors = !isDestinationColors; inputDelayCount = 0; } if (_input.isKeyDown(KeyEvent.VK_PERIOD)) { LIVE_DELAY += 1; if (LIVE_DELAY < 0) { LIVE_DELAY = 0; } } if (_input.isKeyDown(KeyEvent.VK_COMMA)) { LIVE_DELAY -= 1; if (LIVE_DELAY < 0) { LIVE_DELAY = 0; } } if (_input.isKeyDown(KeyEvent.VK_UP)) { _yOffset += 1; } if (_input.isKeyDown(KeyEvent.VK_DOWN)) { _yOffset -= 1; } if (_input.isKeyDown(KeyEvent.VK_RIGHT)) { _xOffset -= 1; } if (_input.isKeyDown(KeyEvent.VK_LEFT)) { _xOffset += 1; } if (_input.isKeyDown(KeyEvent.VK_ENTER)) { while (!_input.isKeyDown(KeyEvent.VK_SHIFT)) { //this makes it work, without this line it will not work as desired // System.out.println(_input.isKeyDown( KeyEvent.VK_ENTER )); draw(); handleColorSwitchingInput(); } } inputDelayCount++; }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
@Override public void keyPressed(KeyEvent ke) { Logger.getLogger(getClass().getName()).log(Level.INFO, "Received key event: {0}", ke.toString()); if (ke.isControlDown()) { modeSpinner.setValue(InstanceContentSelectionHandler.Mode.ON_HOVER.toString()); }// www. ja v a 2 s. c o m if (getDataPoint() != null) { Logger.getLogger(getClass().getName()).info("Data point is not null!"); Point p = null; if (ke.getKeyCode() == KeyEvent.VK_RIGHT) { p = new Point(getDataPoint()); p.translate(1, 0); } else if (ke.getKeyCode() == KeyEvent.VK_LEFT) { p = new Point(getDataPoint()); p.translate(-1, 0); } else if (ke.getKeyCode() == KeyEvent.VK_UP) { p = new Point(getDataPoint()); p.translate(0, 1); } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) { p = new Point(getDataPoint()); p.translate(0, -1); } setDataPoint(p); if (!ke.isShiftDown()) { // triggerMSUpdate(); } } }
From source file:com.jvms.i18neditor.editor.Editor.java
private void setupGlobalKeyEventDispatcher() { KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(e -> { if (e.getID() != KeyEvent.KEY_PRESSED || !e.isAltDown() || (SystemUtils.IS_OS_MAC && !e.isMetaDown()) || (!SystemUtils.IS_OS_MAC && !e.isShiftDown())) { return false; }//from w ww. ja va 2 s .c om TreePath selected = translationTree.getSelectionPath(); if (selected == null) { return false; } boolean result = false; int row = translationTree.getRowForPath(selected); switch (e.getKeyCode()) { case KeyEvent.VK_RIGHT: if (!translationTree.isExpanded(row)) { translationTree.expandRow(row); } result = true; break; case KeyEvent.VK_LEFT: if (translationTree.isCollapsed(row)) { translationTree.setSelectionPath(selected.getParentPath()); } else { translationTree.collapseRow(row); } result = true; break; case KeyEvent.VK_UP: TreePath prev = translationTree.getPathForRow(Math.max(0, row - 1)); if (prev != null) { translationTree.setSelectionPath(prev); } result = true; break; case KeyEvent.VK_DOWN: TreePath next = translationTree.getPathForRow(row + 1); if (next != null) { translationTree.setSelectionPath(next); } result = true; break; } if (result && !resourceFields.isEmpty()) { Component comp = getFocusOwner(); if (comp != null && (comp instanceof ResourceField || comp.equals(this))) { TranslationTreeNode current = translationTree.getSelectionNode(); if (!current.isLeaf() || current.isRoot()) { requestFocusInWindow(); } else if (comp.equals(this)) { requestFocusInFirstResourceField(); } } } return result; }); }
From source file:io.heming.accountbook.ui.MainFrame.java
private void initMenuBar() { JMenuBar menuBar = new JMenuBar(); // File menu/*from w ww . j a v a 2 s .c o m*/ fileMenu = new JMenu("(F)"); fileMenu.setMnemonic('F'); exportMenuItem = new JMenuItem("(B)..."); exportMenuItem.setIcon(new ImageIcon(getClass().getResource("database-save.png"))); exportMenuItem.setMnemonic('B'); exportMenuItem.addActionListener(e -> exportRecords()); fileMenu.add(exportMenuItem); importMenuItem = new JMenuItem("??(R)..."); importMenuItem.setIcon(new ImageIcon(getClass().getResource("document-import-2.png"))); importMenuItem.setMnemonic('R'); importMenuItem.addActionListener(e -> importRecords()); fileMenu.add(importMenuItem); fileMenu.addSeparator(); quitMenuItem = new JMenuItem("(X)"); quitMenuItem.setIcon(new ImageIcon(getClass().getResource("application-exit-2.png"))); quitMenuItem.setMnemonic('X'); quitMenuItem.addActionListener(e -> quit()); fileMenu.add(quitMenuItem); // View menu viewMenu = new JMenu("(V)"); viewMenu.setMnemonic('V'); searchMenuItem = new JMenuItem("?(S)"); searchMenuItem.setIcon(new ImageIcon(getClass().getResource("edit-find-5.png"))); searchMenuItem.setMnemonic('S'); searchMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); searchMenuItem.addActionListener(e -> searchRecords()); viewMenu.add(searchMenuItem); keywordMenuItem = new JMenuItem("(K)"); keywordMenuItem.setIcon(new ImageIcon(getClass().getResource("text-field.png"))); keywordMenuItem.setMnemonic('K'); keywordMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK)); keywordMenuItem.addActionListener(e -> { keywordTextField.requestFocus(); keywordTextField.selectAll(); }); viewMenu.add(keywordMenuItem); viewMenu.addSeparator(); prevPageMenuItem = new JMenuItem("?(P)"); prevPageMenuItem.setIcon(new ImageIcon(getClass().getResource("go-previous-2.png"))); prevPageMenuItem.setMnemonic('P'); prevPageMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Event.CTRL_MASK)); prevPageMenuItem.addActionListener(e -> prevPage()); viewMenu.add(prevPageMenuItem); nextPageMenuItem = new JMenuItem("(N)"); nextPageMenuItem.setIcon(new ImageIcon(getClass().getResource("go-next-2.png"))); nextPageMenuItem.setMnemonic('N'); nextPageMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Event.CTRL_MASK)); nextPageMenuItem.addActionListener(e -> nextPage()); viewMenu.add(nextPageMenuItem); firstPageMenuItem = new JMenuItem("(F)"); firstPageMenuItem.setIcon(new ImageIcon(getClass().getResource("go-first.png"))); firstPageMenuItem.setMnemonic('F'); firstPageMenuItem .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Event.SHIFT_MASK + Event.CTRL_MASK)); firstPageMenuItem.addActionListener(e -> firstPage()); viewMenu.add(firstPageMenuItem); lastPageMenuItem = new JMenuItem("(L)"); lastPageMenuItem.setIcon(new ImageIcon(getClass().getResource("go-last.png"))); lastPageMenuItem.setMnemonic('L'); lastPageMenuItem .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Event.SHIFT_MASK + Event.CTRL_MASK)); lastPageMenuItem.addActionListener(e -> lastPage()); viewMenu.add(lastPageMenuItem); // Edit menu editMenu = new JMenu("(E)"); editMenu.setMnemonic('E'); addRecordMenuItem = new JMenuItem("(A)..."); addRecordMenuItem.setIcon(new ImageIcon(getClass().getResource("edit-add-3.png"))); addRecordMenuItem.setMnemonic('A'); addRecordMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK)); addRecordMenuItem.addActionListener(e -> showAddRecordDialog()); editMenu.add(addRecordMenuItem); // deleteRecordMenuItem = new JMenuItem("(D)"); // deleteRecordMenuItem.setIcon(new ImageIcon(getClass().getResource("edit-delete-6.png"))); // deleteRecordMenuItem.setMnemonic('D'); // deleteRecordMenuItem.addActionListener(e -> deleteRecord()); // editMenu.add(deleteRecordMenuItem); editMenu.addSeparator(); categoryMenuItem = new JMenuItem("???(T)..."); categoryMenuItem.setIcon(new ImageIcon(getClass().getResource("view-list-icons-2.png"))); categoryMenuItem.setMnemonic('T'); categoryMenuItem.addActionListener(e -> showCategoryDialog()); editMenu.add(categoryMenuItem); // Help menu helpMenu = new JMenu("(H)"); helpMenu.setMnemonic('H'); helpMenuItem = new JMenuItem("(I)"); helpMenuItem.setIcon(new ImageIcon(getClass().getResource("help-2.png"))); helpMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); helpMenuItem.setMnemonic('I'); helpMenuItem.addActionListener(e -> help()); helpMenu.add(helpMenuItem); aboutMenuItem = new JMenuItem("(A)"); aboutMenuItem.setIcon(new ImageIcon(getClass().getResource("help-about-2.png"))); aboutMenuItem.setMnemonic('A'); aboutMenuItem.addActionListener(e -> about()); helpMenu.add(aboutMenuItem); // Add menu to menu bar menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(viewMenu); menuBar.add(helpMenu); setJMenuBar(menuBar); }
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
@Override public void processKeyEvent(java.awt.event.KeyEvent e, JXLayer<? extends V> l) { if (e.getID() != KeyEvent.KEY_PRESSED) { // We are only interested in KEY_PRESSED event. return;/*ww w . java 2s.c o m*/ } final int code = e.getKeyCode(); switch (code) { case KeyEvent.VK_LEFT: this.updateTraceInfosIfPossible(-1); break; case KeyEvent.VK_RIGHT: this.updateTraceInfosIfPossible(+1); break; } }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
public void keyPressed(final KeyEvent event) { canvasLock.lock();//from www .ja va2 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:ch.zhaw.iamp.rct.ui.GrammarWindow.java
private boolean isArrowKeyCode(int keyCode) { return keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_DOWN; }