List of usage examples for java.awt.event KeyEvent VK_TAB
int VK_TAB
To view the source code for java.awt.event KeyEvent VK_TAB.
Click Source Link
From source file:com.fanniemae.ezpie.actions.HighlightScan.java
private void changeOracleExtractExtension(File castExtractionFile) { ProcessBuilder pb = new ProcessBuilder("java", "-jar", _dbDeliveryToolPath); Process process = null;//from www . j av a 2 s . c om Robot robot = null; try { process = pb.start(); robot = new Robot(); } catch (IOException | AWTException e) { throw new PieException("Could not start Oracle extract.", e); } sleep(15000); // navigating to input text for (int i = 0; i < 3; i++) { keyPressRelease(KeyEvent.VK_TAB, 200); sleep(200); } // select populated target folder path keyPressReleaseControlA(500); // entering target folder path Keyboard keyboard = new Keyboard(robot); keyboard.type(castExtractionFile.getParent() + "\\deliveryResults"); // navigate to options keyPressReleaseShiftTab(200); keyPressRelease(KeyEvent.VK_RIGHT, 500); for (int i = 0; i < 2; i++) { keyPressRelease(KeyEvent.VK_TAB, 200); sleep(200); } // select populated extraction file path keyPressReleaseControlA(500); // entering target folder path that contains .castextraction file keyboard.type(castExtractionFile.getPath()); sleep(500); keyPressRelease(KeyEvent.VK_TAB, 200); sleep(500); // navigate to menu bar to select Application/Run Application since tabbing to 'Run Application' button // and pressing enter does not execute run keyPressRelease(KeyEvent.VK_ALT, 500); sleep(500); for (int i = 0; i < 2; i++) { keyPressRelease(KeyEvent.VK_RIGHT, 200); } keyPressRelease(KeyEvent.VK_ENTER, 200); keyPressRelease(KeyEvent.VK_DOWN, 500); keyPressRelease(KeyEvent.VK_ENTER, 200); sleep(5000); process.destroy(); }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
public AsciidocBrowserApplication(final String[] args) { super("Asciidoc Browser"); setIconImage(Icons.APPLICATION.image()); setSize(1200, 1024);/*from w ww.j ava 2 s . c o m*/ addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { actionExit(); } }); JPanel buttonPanel = new JPanel(); backButton = new JButton(""); backButton.setIcon(Icons.BACK.icon()); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionBack(); } }); buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]")); JButton btnOptionsbutton = new JButton(""); btnOptionsbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { settingsDialog.setVisible(true); } }); btnOptionsbutton.setIcon(Icons.OPTIONS.icon()); buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0"); backButton.setEnabled(false); buttonPanel.add(backButton, "cell 0 0,grow"); forwardButton = new JButton(""); forwardButton.setIcon(Icons.FORWARD.icon()); forwardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionForward(); } }); forwardButton.setEnabled(false); buttonPanel.add(forwardButton, "cell 0 0,grow"); getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]")); getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top"); locationTextField = new JTextField(65); locationTextField.setText(""); locationTextField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) { actionGo(); refreshDocumentTree(); } } }); locationTextField.setTransferHandler( new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() { @Override public void run() { locationTextField.setText(""); } }, new Runnable() { @Override public void run() { actionGo(); refreshDocumentTree(); } })); homebutton = new JButton(""); homebutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { locationTextField.setText(Settings.getHome()); actionGo(); refreshDocumentTree(); } }); refreshButton = new JButton(""); refreshButton.setToolTipText("Refresh"); refreshButton.setEnabled(false); refreshButton.setIcon(Icons.REFRESH.icon()); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionGo(); refreshPreview(); } }); buttonPanel.add(refreshButton, "cell 1 0"); homebutton.setIcon(Icons.HOME.icon()); buttonPanel.add(homebutton, "cell 2 0"); buttonPanel.add(locationTextField, "cell 3 0,grow"); treeSourceSplitPane = new JSplitPane(); treeSourceSplitPane.setResizeWeight(0.3); getContentPane().add(treeSourceSplitPane, "cell 0 1,grow"); treeScrollPane = new JScrollPane(); treeScrollPane.setMinimumSize(new Dimension(200, 200)); treeSourceSplitPane.setLeftComponent(treeScrollPane); documentTree = new DocumentTree(documentModel); documentTree.setCellRenderer(new TooltipsTreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(documentTree); ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY); ToolTipManager.sharedInstance().setReshowDelay(0); documentTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent tse) { TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath(); if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath .getLastPathComponent(); FileWrapper file = (FileWrapper) node.getUserObject(); showFile(file, true); refreshPreview(); } } }); treeScrollPane.setViewportView(documentTree); sourceEditorPane = new JEditorPane(); sourceEditorPane.setContentType("text/html"); sourceEditorPane.setEditable(false); sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate()); JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane); fileScrollPane.setMinimumSize(new Dimension(600, 600)); documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM); documentTabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent ce) { refreshPreview(); } }); sourceLogSplitPane = new JSplitPane(); sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); treeSourceSplitPane.setRightComponent(sourceLogSplitPane); sourceLogSplitPane.setTopComponent(documentTabbedPane); documentTabbedPane.add(fileScrollPane); documentTabbedPane.setTitleAt(0, "Source"); browserPane = new BrowserPane(); previewScrollPane = new JScrollPane(browserPane); documentTabbedPane.addTab("Preview", null, previewScrollPane, null); console = new JConsole(); System.setErr(console.getErr()); System.setOut(console.getOut()); sourceLogSplitPane.setBottomComponent(console); executor = new AsciidocExecutor(); }
From source file:org.dishevelled.brainstorm.BrainStorm.java
/** * Initialize components.// ww w . jav a 2 s.c o m */ private void initComponents() { Font font = new Font(chooseFontName(), Font.PLAIN, fontSize); hiddenCursor = createHiddenCursor(); textArea = new JTextArea() { /** {@inheritDoc} */ protected void paintComponent(final Graphics graphics) { Graphics2D g2 = (Graphics2D) graphics; g2.setRenderingHint(KEY_FRACTIONALMETRICS, VALUE_FRACTIONALMETRICS_ON); g2.setRenderingHint(KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_LCD_HRGB); super.paintComponent(g2); } }; textArea.setFont(font); textArea.setOpaque(true); textArea.setCursor(hiddenCursor); textArea.setBackground(backgroundColor); textArea.setForeground(textColor); textArea.setRows(rows); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); // clear all input mappings InputMap inputMap = textArea.getInputMap(); while (inputMap != null) { inputMap.clear(); inputMap = inputMap.getParent(); } // re-add select default input mappings textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "insert-break"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "insert-tab"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete-previous"); int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, keyMask), "delete-previous-word"); // add new input mappings textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, keyMask), "increase-font-size"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, keyMask), "decrease-font-size"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask), "save"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "quit"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, keyMask), "quit"); Action increaseFontSizeAction = new IncreaseFontSizeAction(); Action decreaseFontSizeAction = new DecreaseFontSizeAction(); Action saveAction = new SaveAction(); Action quitAction = new QuitAction(); textArea.getActionMap().put("increase-font-size", increaseFontSizeAction); textArea.getActionMap().put("decrease-font-size", decreaseFontSizeAction); textArea.getActionMap().put("save", saveAction); textArea.getActionMap().put("quit", quitAction); placeholder = Box.createGlue(); }
From source file:com.grillecube.editor.ModelEditor.java
@Override public void invokeMouseEnter(GLFWWindow window, boolean cursor, double posx, double posy) { if (this._robot == null || !cursor) { return;//from w w w.j ava2 s. c o m } this._robot.keyPress(KeyEvent.VK_ALT); this._robot.keyPress(KeyEvent.VK_TAB); this._robot.delay(10); this._robot.keyRelease(KeyEvent.VK_ALT); this._robot.keyRelease(KeyEvent.VK_TAB); }
From source file:com.fanniemae.ezpie.actions.HighlightScan.java
private void discoverFiles() { // wait until 'Discover Files' is viewable int xx = (int) Math.round(Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2); int yy = 0;//from ww w . ja va2s. c om boolean atButtonLocation = false; while (!atButtonLocation) { yy += 5; Color color = this._robot.getPixelColor(xx, yy); if (checkIfColorInRange(color, buttonColorOnDiscoverPage, 10)) atButtonLocation = true; if (yy > 1000) yy = 0; } // navigating to input text for (int i = 0; i < 3; i++) { keyPressRelease(KeyEvent.VK_TAB, 200); sleep(200); } // entering path to analyzed folder keyPressReleaseControlA(500); Keyboard keyboard = new Keyboard(this._robot); keyboard.type(_destination + "\\Analyzed"); sleep(200); // add folder path keyPressRelease(KeyEvent.VK_ENTER, 500); sleep(500); // click on 'Discover Files' atButtonLocation = false; while (!atButtonLocation) { yy += 5; Color color = this._robot.getPixelColor(xx, yy); if (checkIfColorInRange(color, buttonColorOnDiscoverPage, 10)) { atButtonLocation = true; } } moveMouseAndClick(xx, yy); }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
public MindMapPanel(final MindMapPanelController controller) { super(null);/*from w w w. j a v a 2 s .c o m*/ this.textEditorPanel.setLayout(new BorderLayout(0, 0)); this.controller = controller; this.config = new MindMapPanelConfig(controller.provideConfigForMindMapPanel(this), false); this.textEditor.setMargin(new Insets(5, 5, 5, 5)); this.textEditor.setBorder(BorderFactory.createEtchedBorder()); this.textEditor.setTabSize(4); this.textEditor.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_ENTER: { e.consume(); } break; case KeyEvent.VK_TAB: { if ((e.getModifiers() & ALL_SUPPORTED_MODIFIERS) == 0) { e.consume(); final Topic edited = elementUnderEdit.getModel(); final int[] topicPosition = edited.getPositionPath(); endEdit(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final Topic theTopic = model.findForPositionPath(topicPosition); if (theTopic != null) { makeNewChildAndStartEdit(theTopic, null); } } }); } } break; default: break; } } @Override public void keyTyped(final KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ENTER) { if ((e.getModifiers() & ALL_SUPPORTED_MODIFIERS) == 0) { e.consume(); endEdit(true); } else { e.consume(); textEditor.insert("\n", textEditor.getCaretPosition()); //NOI18N } } } @Override public void keyReleased(final KeyEvent e) { if (config.isKeyEvent(MindMapPanelConfig.KEY_CANCEL_EDIT, e)) { e.consume(); final Topic edited = elementUnderEdit == null ? null : elementUnderEdit.getModel(); endEdit(false); if (edited != null && edited.canBeLost()) { deleteTopics(edited); if (pathToPrevTopicBeforeEdit != null) { final int[] path = pathToPrevTopicBeforeEdit; pathToPrevTopicBeforeEdit = null; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final Topic topic = model.findForPositionPath(path); if (topic != null) { select(topic, false); } } }); } } } } }); this.textEditor.getDocument().addDocumentListener(new DocumentListener() { private void updateEditorPanelSize(final Dimension newSize) { final Dimension editorPanelMinSize = textEditorPanel.getMinimumSize(); final Dimension newDimension = new Dimension(Math.max(editorPanelMinSize.width, newSize.width), Math.max(editorPanelMinSize.height, newSize.height)); textEditorPanel.setSize(newDimension); textEditorPanel.repaint(); } @Override public void insertUpdate(DocumentEvent e) { updateEditorPanelSize(textEditor.getPreferredSize()); } @Override public void removeUpdate(DocumentEvent e) { updateEditorPanelSize(textEditor.getPreferredSize()); } @Override public void changedUpdate(DocumentEvent e) { updateEditorPanelSize(textEditor.getPreferredSize()); } }); this.textEditorPanel.add(this.textEditor, BorderLayout.CENTER); super.setOpaque(true); final KeyAdapter keyAdapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (config.isKeyEvent(MindMapPanelConfig.KEY_ADD_CHILD_AND_START_EDIT, e)) { if (!selectedTopics.isEmpty()) { makeNewChildAndStartEdit(selectedTopics.get(0), null); } } else if (config.isKeyEvent(MindMapPanelConfig.KEY_ADD_SIBLING_AND_START_EDIT, e)) { if (!hasActiveEditor() && hasOnlyTopicSelected()) { final Topic baseTopic = selectedTopics.get(0); makeNewChildAndStartEdit(baseTopic.getParent() == null ? baseTopic : baseTopic.getParent(), baseTopic); } } else if (config.isKeyEvent(MindMapPanelConfig.KEY_FOCUS_ROOT_OR_START_EDIT, e)) { if (!hasSelectedTopics()) { select(getModel().getRoot(), false); } else if (hasOnlyTopicSelected()) { startEdit((AbstractElement) selectedTopics.get(0).getPayload()); } } } @Override public void keyReleased(final KeyEvent e) { if (config.isKeyEvent(MindMapPanelConfig.KEY_DELETE_TOPIC, e)) { e.consume(); deleteSelectedTopics(); } else if (config.isKeyEventDetected(e, MindMapPanelConfig.KEY_FOCUS_MOVE_LEFT, MindMapPanelConfig.KEY_FOCUS_MOVE_RIGHT, MindMapPanelConfig.KEY_FOCUS_MOVE_UP, MindMapPanelConfig.KEY_FOCUS_MOVE_DOWN)) { e.consume(); processMoveFocusByKey(e); } } }; this.setFocusTraversalKeysEnabled(false); final MindMapPanel theInstance = this; final MouseAdapter adapter = new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { setCursor(Cursor.getDefaultCursor()); } @Override public void mouseMoved(final MouseEvent e) { if (!controller.isMouseMoveProcessingAllowed(theInstance)) { return; } final AbstractElement element = findTopicUnderPoint(e.getPoint()); if (element == null) { setCursor(Cursor.getDefaultCursor()); setToolTipText(null); } else { final ElementPart part = element.findPartForPoint(e.getPoint()); setCursor(part == ElementPart.ICONS || part == ElementPart.COLLAPSATOR ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : Cursor.getDefaultCursor()); if (part == ElementPart.ICONS) { final Extra<?> extra = element.getIconBlock().findExtraForPoint( e.getPoint().getX() - element.getBounds().getX(), e.getPoint().getY() - element.getBounds().getY()); if (extra != null) { setToolTipText(makeHtmlTooltipForExtra(extra)); } else { setToolTipText(null); } } else { setToolTipText(null); } } } @Override public void mousePressed(final MouseEvent e) { if (!controller.isMouseClickProcessingAllowed(theInstance)) { return; } try { if (e.isPopupTrigger()) { mouseDragSelection = null; MindMap theMap = model; AbstractElement element = null; if (theMap != null) { element = findTopicUnderPoint(e.getPoint()); } processPopUp(e.getPoint(), element); e.consume(); } else { endEdit(elementUnderEdit != null); mouseDragSelection = null; } } catch (Exception ex) { LOGGER.error("Error during mousePressed()", ex); } } @Override public void mouseReleased(final MouseEvent e) { if (!controller.isMouseClickProcessingAllowed(theInstance)) { return; } try { if (draggedElement != null) { draggedElement.updatePosition(e.getPoint()); if (endDragOfElement(draggedElement, destinationElement)) { updateView(true); } } else if (mouseDragSelection != null) { final List<Topic> covered = mouseDragSelection.getAllSelectedElements(model); if (e.isShiftDown()) { for (final Topic m : covered) { select(m, false); } } else if (e.isControlDown()) { for (final Topic m : covered) { select(m, true); } } else { removeAllSelection(); for (final Topic m : covered) { select(m, false); } } } else if (e.isPopupTrigger()) { mouseDragSelection = null; MindMap theMap = model; AbstractElement element = null; if (theMap != null) { element = findTopicUnderPoint(e.getPoint()); } processPopUp(e.getPoint(), element); e.consume(); } } catch (Exception ex) { LOGGER.error("Error during mouseReleased()", ex); } finally { mouseDragSelection = null; draggedElement = null; destinationElement = null; repaint(); } } @Override public void mouseDragged(final MouseEvent e) { if (!controller.isMouseMoveProcessingAllowed(theInstance)) { return; } scrollRectToVisible(new Rectangle(e.getX(), e.getY(), 1, 1)); if (!popupMenuActive) { if (draggedElement == null && mouseDragSelection == null) { final AbstractElement elementUnderMouse = findTopicUnderPoint(e.getPoint()); if (elementUnderMouse == null) { MindMap theMap = model; if (theMap != null) { final AbstractElement element = findTopicUnderPoint(e.getPoint()); if (controller.isSelectionAllowed(theInstance) && element == null) { mouseDragSelection = new MouseSelectedArea(e.getPoint()); } } } else if (controller.isElementDragAllowed(theInstance)) { if (elementUnderMouse.isMoveable()) { selectedTopics.clear(); final Point mouseOffset = new Point( (int) Math .round(e.getPoint().getX() - elementUnderMouse.getBounds().getX()), (int) Math .round(e.getPoint().getY() - elementUnderMouse.getBounds().getY())); draggedElement = new DraggedElement(elementUnderMouse, config, mouseOffset, e.isControlDown() || e.isMetaDown() ? DraggedElement.Modifier.MAKE_JUMP : DraggedElement.Modifier.NONE); draggedElement.updatePosition(e.getPoint()); findDestinationElementForDragged(); } else { draggedElement = null; } repaint(); } } else if (mouseDragSelection != null) { if (controller.isSelectionAllowed(theInstance)) { mouseDragSelection.update(e); } else { mouseDragSelection = null; } repaint(); } else if (draggedElement != null) { if (controller.isElementDragAllowed(theInstance)) { draggedElement.updatePosition(e.getPoint()); findDestinationElementForDragged(); } else { draggedElement = null; } repaint(); } } else { mouseDragSelection = null; } } @Override public void mouseWheelMoved(final MouseWheelEvent e) { if (controller.isMouseWheelProcessingAllowed(theInstance)) { mouseDragSelection = null; draggedElement = null; final MindMapPanelConfig theConfig = config; if (!e.isConsumed() && (theConfig != null && ((e.getModifiers() & theConfig.getScaleModifiers()) == theConfig .getScaleModifiers()))) { endEdit(elementUnderEdit != null); setScale( Math.max(0.3d, Math.min(getScale() + (SCALE_STEP * -e.getWheelRotation()), 10.0d))); updateView(false); e.consume(); } else { sendToParent(e); } } } @Override public void mouseClicked(final MouseEvent e) { if (!controller.isMouseClickProcessingAllowed(theInstance)) { return; } mouseDragSelection = null; draggedElement = null; MindMap theMap = model; AbstractElement element = null; if (theMap != null) { element = findTopicUnderPoint(e.getPoint()); } if (element != null) { final ElementPart part = element.findPartForPoint(e.getPoint()); if (part == ElementPart.COLLAPSATOR) { removeAllSelection(); if (element.isCollapsed()) { ((AbstractCollapsableElement) element).setCollapse(false); if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) { ((AbstractCollapsableElement) element).collapseAllFirstLevelChildren(); } } else { ((AbstractCollapsableElement) element).setCollapse(true); } invalidate(); fireNotificationMindMapChanged(); repaint(); } else if (part != ElementPart.ICONS && e.getClickCount() > 1) { startEdit(element); } else if (part == ElementPart.ICONS) { final Extra<?> extra = element.getIconBlock().findExtraForPoint( e.getPoint().getX() - element.getBounds().getX(), e.getPoint().getY() - element.getBounds().getY()); if (extra != null) { fireNotificationClickOnExtra(element.getModel(), e.getClickCount(), extra); } } else { if (!e.isControlDown()) { // only removeAllSelection(); select(element.getModel(), false); } else // group if (selectedTopics.isEmpty()) { select(element.getModel(), false); } else { select(element.getModel(), true); } } } } }; addMouseWheelListener(adapter); addMouseListener(adapter); addMouseMotionListener(adapter); addKeyListener(keyAdapter); this.textEditorPanel.setVisible(false); this.add(this.textEditorPanel); }
From source file:savant.view.swing.NavigationBar.java
NavigationBar() { this.setOpaque(false); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); String buttonStyle = "segmentedCapsule"; String shortcutMod = MiscUtils.MAC ? "Cmd" : "Ctrl"; add(getRigidPadding());//from w w w . ja v a 2 s. com JButton loadGenomeButton = (JButton) add(new JButton("")); loadGenomeButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.GENOME)); loadGenomeButton.setToolTipText("Load or change genome"); loadGenomeButton.setFocusable(false); loadGenomeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Savant.getInstance().showOpenGenomeDialog(); } }); loadGenomeButton.putClientProperty("JButton.buttonType", buttonStyle); loadGenomeButton.putClientProperty("JButton.segmentPosition", "first"); loadGenomeButton.setPreferredSize(ICON_SIZE); loadGenomeButton.setMinimumSize(ICON_SIZE); loadGenomeButton.setMaximumSize(ICON_SIZE); JButton loadTrackButton = (JButton) add(new JButton("")); loadTrackButton.setFocusable(false); loadTrackButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.TRACK)); loadTrackButton.setToolTipText("Load a track"); loadTrackButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Savant.getInstance().openTrack(); } }); loadTrackButton.putClientProperty("JButton.buttonType", buttonStyle); loadTrackButton.putClientProperty("JButton.segmentPosition", "last"); loadTrackButton.setPreferredSize(ICON_SIZE); loadTrackButton.setMinimumSize(ICON_SIZE); loadTrackButton.setMaximumSize(ICON_SIZE); if (!Savant.getInstance().isStandalone()) { add(loadGenomeButton); add(loadTrackButton); add(getRigidPadding()); add(getRigidPadding()); } else { loadGenomeButton.setVisible(false); loadTrackButton.setVisible(false); } JLabel rangeText = new JLabel("Location "); add(rangeText); String[] a = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }; locationField = new JComboBox(a); locationField.setEditable(true); locationField.setRenderer(new ReferenceListRenderer()); // When the item is chosen from the menu, navigate to the given feature/reference. locationField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (!currentlyPopulating) { if (ae.getActionCommand().equals("comboBoxChanged")) { // Assumes that combo-box items created by populateCombo() are of the form "GENE (chrX:1-1000)". String itemText = locationField.getSelectedItem().toString(); int lastBracketPos = itemText.lastIndexOf('('); if (lastBracketPos > 0) { itemText = itemText.substring(lastBracketPos + 1, itemText.length() - 1); } setRangeFromText(itemText); } } } }); // When the combo-box is popped open, we may want to repopulate the menu. locationField.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent pme) { String text = (String) locationField.getEditor().getItem(); if (!text.equals(lastPoppedUp)) { try { // Building the menu could take a while. setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); populateCombo(); } finally { setCursor(Cursor.getDefaultCursor()); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) { } @Override public void popupMenuCanceled(PopupMenuEvent pme) { } }); // Add our special keystroke-handling to the JComboBox' text-field. // We have to turn off default tab-handling so that tab can pop up our list. Component textField = locationField.getEditor().getEditorComponent(); textField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_TAB) { locationField.showPopup(); } else if (evt.getModifiers() == KeyEvent.SHIFT_MASK) { switch (evt.getKeyCode()) { case KeyEvent.VK_LEFT: locationController.shiftRangeLeft(); evt.consume(); break; case KeyEvent.VK_RIGHT: locationController.shiftRangeRight(); evt.consume(); break; case KeyEvent.VK_UP: locationController.zoomIn(); evt.consume(); break; case KeyEvent.VK_DOWN: locationController.zoomOut(); evt.consume(); break; case KeyEvent.VK_HOME: locationController.shiftRangeFarLeft(); evt.consume(); break; case KeyEvent.VK_END: locationController.shiftRangeFarRight(); evt.consume(); break; } } } }); add(locationField); locationField.setToolTipText("Current display range"); locationField.setPreferredSize(LOCATION_SIZE); locationField.setMaximumSize(LOCATION_SIZE); locationField.setMinimumSize(LOCATION_SIZE); add(getRigidPadding()); JButton goButton = (JButton) add(new JButton(" Go ")); goButton.putClientProperty("JButton.buttonType", buttonStyle); goButton.putClientProperty("JButton.segmentPosition", "only"); goButton.setToolTipText("Go to specified range (Enter)"); goButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setRangeFromText(locationField.getEditor().getItem().toString()); } }); add(getRigidPadding()); JLabel l = new JLabel("Length: "); add(l); lengthLabel = (JLabel) add(new JLabel()); lengthLabel.setToolTipText("Length of the current range"); lengthLabel.setPreferredSize(LENGTH_SIZE); lengthLabel.setMaximumSize(LENGTH_SIZE); lengthLabel.setMinimumSize(LENGTH_SIZE); add(Box.createGlue()); double screenwidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); JButton afterGo = null; //if (screenwidth > 800) { final JButton undoButton = (JButton) add(new JButton("")); afterGo = undoButton; undoButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UNDO)); undoButton.setToolTipText("Undo range change (" + shortcutMod + "+Z)"); undoButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.undoLocationChange(); } }); undoButton.putClientProperty("JButton.buttonType", buttonStyle); undoButton.putClientProperty("JButton.segmentPosition", "first"); undoButton.setPreferredSize(ICON_SIZE); undoButton.setMinimumSize(ICON_SIZE); undoButton.setMaximumSize(ICON_SIZE); final JButton redo = (JButton) add(new JButton("")); redo.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.REDO)); redo.setToolTipText("Redo range change (" + shortcutMod + "+Y)"); redo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.redoLocationChange(); } }); redo.putClientProperty("JButton.buttonType", buttonStyle); redo.putClientProperty("JButton.segmentPosition", "last"); redo.setPreferredSize(ICON_SIZE); redo.setMinimumSize(ICON_SIZE); redo.setMaximumSize(ICON_SIZE); //} add(getRigidPadding()); add(getRigidPadding()); final JButton zoomInButton = (JButton) add(new JButton()); if (afterGo == null) { afterGo = zoomInButton; } zoomInButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMIN)); zoomInButton.putClientProperty("JButton.buttonType", buttonStyle); zoomInButton.putClientProperty("JButton.segmentPosition", "first"); zoomInButton.setPreferredSize(ICON_SIZE); zoomInButton.setMinimumSize(ICON_SIZE); zoomInButton.setMaximumSize(ICON_SIZE); zoomInButton.setToolTipText("Zoom in (Shift+Up)"); zoomInButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.zoomIn(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"), new NameValuePair("navigation-direction", "in"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton zoomOut = (JButton) add(new JButton("")); zoomOut.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMOUT)); zoomOut.setToolTipText("Zoom out (Shift+Down)"); zoomOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.zoomOut(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"), new NameValuePair("navigation-direction", "out"), new NameValuePair("navigation-modality", "navbar") }); } }); zoomOut.putClientProperty("JButton.buttonType", buttonStyle); zoomOut.putClientProperty("JButton.segmentPosition", "last"); zoomOut.setPreferredSize(ICON_SIZE); zoomOut.setMinimumSize(ICON_SIZE); zoomOut.setMaximumSize(ICON_SIZE); add(getRigidPadding()); add(getRigidPadding()); final JButton shiftFarLeft = (JButton) add(new JButton()); shiftFarLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARLEFT)); shiftFarLeft.putClientProperty("JButton.buttonType", buttonStyle); shiftFarLeft.putClientProperty("JButton.segmentPosition", "first"); shiftFarLeft.setToolTipText("Move to the beginning of the genome (Shift+Home)"); shiftFarLeft.setPreferredSize(ICON_SIZE); shiftFarLeft.setMinimumSize(ICON_SIZE); shiftFarLeft.setMaximumSize(ICON_SIZE); shiftFarLeft.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeFarLeft(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "left"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftLeft = (JButton) add(new JButton()); shiftLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_LEFT)); shiftLeft.putClientProperty("JButton.buttonType", buttonStyle); shiftLeft.putClientProperty("JButton.segmentPosition", "middle"); shiftLeft.setToolTipText("Move left (Shift+Left)"); shiftLeft.setPreferredSize(ICON_SIZE); shiftLeft.setMinimumSize(ICON_SIZE); shiftLeft.setMaximumSize(ICON_SIZE); shiftLeft.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeLeft(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "left"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftRight = (JButton) add(new JButton()); shiftRight.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_RIGHT)); shiftRight.putClientProperty("JButton.buttonType", buttonStyle); shiftRight.putClientProperty("JButton.segmentPosition", "middle"); shiftRight.setToolTipText("Move right (Shift+Right)"); shiftRight.setPreferredSize(ICON_SIZE); shiftRight.setMinimumSize(ICON_SIZE); shiftRight.setMaximumSize(ICON_SIZE); shiftRight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeRight(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "right"), new NameValuePair("navigation-modality", "navbar") }); } }); final JButton shiftFarRight = (JButton) add(new JButton()); shiftFarRight .setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARRIGHT)); shiftFarRight.putClientProperty("JButton.buttonType", buttonStyle); shiftFarRight.putClientProperty("JButton.segmentPosition", "last"); shiftFarRight.setToolTipText("Move to the end of the genome (Shift+End)"); shiftFarRight.setPreferredSize(ICON_SIZE); shiftFarRight.setMinimumSize(ICON_SIZE); shiftFarRight.setMaximumSize(ICON_SIZE); shiftFarRight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { locationController.shiftRangeFarRight(); AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"), new NameValuePair("navigation-direction", "right"), new NameValuePair("navigation-modality", "navbar") }); } }); add(getRigidPadding()); locationController.addListener(new Listener<LocationChangedEvent>() { @Override public void handleEvent(LocationChangedEvent event) { updateLocation(event.getReference(), (Range) event.getRange()); } }); // When the genome changes, we may need to invalidate our menu. GenomeController.getInstance().addListener(new Listener<GenomeChangedEvent>() { @Override public void handleEvent(GenomeChangedEvent event) { lastPoppedUp = "INVALID"; } }); this.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { int width = ce.getComponent().getWidth(); undoButton.setVisible(true); redo.setVisible(true); zoomInButton.setVisible(true); zoomOut.setVisible(true); shiftFarLeft.setVisible(true); shiftLeft.setVisible(true); shiftRight.setVisible(true); shiftFarRight.setVisible(true); // hide some components if the window isn't wide enough if (width < 1200) { undoButton.setVisible(false); redo.setVisible(false); } if (width < 1000) { shiftFarLeft.setVisible(false); shiftFarRight.setVisible(false); shiftRight.putClientProperty("JButton.segmentPosition", "last"); shiftLeft.putClientProperty("JButton.segmentPosition", "first"); } else { shiftRight.putClientProperty("JButton.segmentPosition", "middle"); shiftLeft.putClientProperty("JButton.segmentPosition", "middle"); } } public void componentMoved(ComponentEvent ce) { } @Override public void componentShown(ComponentEvent ce) { } @Override public void componentHidden(ComponentEvent ce) { } }); }
From source file:org.omegat.gui.issues.IssuesPanelController.java
@SuppressWarnings("serial") synchronized void init() { if (frame != null) { // Regenerate menu bar to reflect current prefs frame.setJMenuBar(generateMenuBar()); return;/*from ww w .j a va 2 s .c om*/ } frame = new JFrame(OStrings.getString("ISSUES_WINDOW_TITLE")); StaticUIUtils.setEscapeClosable(frame); StaticUIUtils.setWindowIcon(frame); if (Platform.isMacOSX()) { OSXIntegration.enableFullScreen(frame); } panel = new IssuesPanel(); frame.add(panel); frame.setJMenuBar(generateMenuBar()); frame.setPreferredSize(new Dimension(600, 400)); frame.pack(); frame.setLocationRelativeTo(parent); panel.innerSplitPane.setDividerLocation(INNER_SPLIT_INITIAL_RATIO); panel.outerSplitPane.setDividerLocation(OUTER_SPLIT_INITIAL_RATIO); StaticUIUtils.persistGeometry(frame, Preferences.ISSUES_WINDOW_GEOMETRY_PREFIX, () -> { Preferences.setPreference(Preferences.ISSUES_WINDOW_DIVIDER_LOCATION_BOTTOM, panel.outerSplitPane.getDividerLocation()); }); try { int bottomDL = Integer .parseInt(Preferences.getPreference(Preferences.ISSUES_WINDOW_DIVIDER_LOCATION_BOTTOM)); panel.outerSplitPane.setDividerLocation(bottomDL); } catch (NumberFormatException e) { // Ignore } frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { reset(); } }); if (Preferences.isPreference(Preferences.PROJECT_FILES_USE_FONT)) { String fontName = Preferences.getPreference(Preferences.TF_SRC_FONT_NAME); int fontSize = Integer.parseInt(Preferences.getPreference(Preferences.TF_SRC_FONT_SIZE)); setFont(new Font(fontName, Font.PLAIN, fontSize)); } panel.table.getSelectionModel().addListSelectionListener(e -> { if (!e.getValueIsAdjusting()) { viewSelectedIssueDetail(); selectedEntry = getSelectedIssue().map(IIssue::getSegmentNumber).orElse(-1); } }); panel.table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ACTION_KEY_JUMP_TO_SELECTED_ISSUE); panel.table.getActionMap().put(ACTION_KEY_JUMP_TO_SELECTED_ISSUE, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { jumpToSelectedIssue(); } }); // Swap focus between the Types list and Issues table; don't allow // tabbing within the table because it's pointless. Maybe this would be // better accomplished by adjusting the focus traversal policy? panel.table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK), ACTION_KEY_FOCUS_ON_TYPES_LIST); panel.table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), ACTION_KEY_FOCUS_ON_TYPES_LIST); panel.table.getActionMap().put(ACTION_KEY_FOCUS_ON_TYPES_LIST, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (panel.typeList.isVisible()) { panel.typeList.requestFocusInWindow(); } } }); panel.closeButton.addActionListener(e -> StaticUIUtils.closeWindowByEvent(frame)); MouseAdapter adapter = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { jumpToSelectedIssue(); } else if (e.getButton() == MouseEvent.BUTTON1 && mouseoverCol == IssueColumn.ACTION_BUTTON.index) { doPopup(e); } } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { doPopup(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { doPopup(e); } } @Override public void mouseExited(MouseEvent e) { updateRollover(); } @Override public void mouseMoved(MouseEvent e) { updateRollover(); } private void doPopup(MouseEvent e) { getIssueAt(e.getPoint()).ifPresent(issue -> showPopupMenu(e.getComponent(), e.getPoint(), issue)); } }; panel.table.addMouseListener(adapter); panel.table.addMouseMotionListener(adapter); panel.typeList.addListSelectionListener(e -> { if (!e.getValueIsAdjusting()) { updateFilter(); selectedType = getSelectedType().orElse(null); } }); panel.jumpButton.addActionListener(e -> jumpToSelectedIssue()); panel.reloadButton.addActionListener(e -> refreshData(selectedEntry, selectedType)); panel.showAllButton.addActionListener(e -> showAll()); colSizer = TableColumnSizer.autoSize(panel.table, IssueColumn.DESCRIPTION.index, true); CoreEvents.registerProjectChangeListener(e -> { switch (e) { case CLOSE: SwingUtilities.invokeLater(() -> { filePattern = ALL_FILES_PATTERN; instructions = NO_INSTRUCTIONS; reset(); frame.setVisible(false); }); break; case MODIFIED: if (frame.isVisible()) { SwingUtilities.invokeLater(() -> refreshData(selectedEntry, selectedType)); } break; default: } }); CoreEvents.registerFontChangedEventListener(f -> { if (!Preferences.isPreference(Preferences.PROJECT_FILES_USE_FONT)) { f = new JTable().getFont(); } setFont(f); viewSelectedIssueDetail(); }); }
From source file:org.executequery.gui.browser.FindAction.java
public void keyPressed(KeyEvent keyEvent) { int keyCode = keyEvent.getKeyCode(); if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_TAB) { setFirstListItemSelectedAndFocus(); }/* w w w .ja va2 s.co m*/ }
From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java
/** * //from ww w. j a v a 2 s . c om */ public void createUI() { //setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setLayout(new BorderLayout()); setOpaque(false); textField = new JTextField(10); // we are going to handle focus traversal manually // so that we can do searches when 'tab' is pressed textField.setFocusTraversalKeysEnabled(false); setControlSize(textField); ImageIcon img = IconManager.getIcon("DropDownArrow", IconManager.IconSize.NonStd); //$NON-NLS-1$ dbBtn = UIHelper.isMacOS() ? new MacGradiantBtn(img) : new JButton(img); dbBtn.setFocusable(false); PanelBuilder pb = new PanelBuilder(new FormLayout("f:d:g,p", "f:p:g"), this); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); pb.add(textField, cc.xy(1, 1)); pb.add(dbBtn, cc.xy(2, 1)); textField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (ignoreTab && e.getKeyCode() == KeyEvent.VK_TAB) { ignoreTab = false; } else { cbxKeyReleased(e); } super.keyReleased(e); } @Override public void keyPressed(KeyEvent e) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } super.keyReleased(e); } }); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { prevEnteredText = textField.getText(); boolean oldWasCleared = wasCleared; if (!ignoreDocChange) { wasCleared = wasCleared || selectedId != null; idList.clear(); list.clear(); selectedId = null; if (oldWasCleared != wasCleared && wasCleared) { notifyListenersOfChange( StringUtils.isEmpty(prevEnteredText) ? null : TextFieldWithQuery.this); } } } }); StringBuilder sb = new StringBuilder(); for (String k : keyColumns) { String title = k; DBFieldInfo fi = tableInfo.getFieldByName(k); if (fi != null) { title = fi.getTitle(); } if (sb.length() > 0) sb.append(", "); sb.append(title); } textField.setToolTipText(UIRegistry.getFormattedResStr("TFWQ_SEARCHES_FLDS", sb.toString())); textField.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { if (e instanceof CausedFocusEvent) { switch (((CausedFocusEvent) e).getCause()) { case TRAVERSAL: case TRAVERSAL_BACKWARD: case TRAVERSAL_FORWARD: case TRAVERSAL_UP: case TRAVERSAL_DOWN: ignoreTab = true; } } } @Override public void focusLost(FocusEvent e) { int len = textField.getText().length(); if (len < 1) { setText(""); //$NON-NLS-1$ /////////////////////////////////////////////////////////////////////////////////// // We only want to generate a change event if it once had a value and then it is // cleared and the user tabs to a new control. - rods 02/28/08 /////////////////////////////////////////////////////////////////////////////////// if (wasCleared || selectedId != null) { notifyListenersOfChange(TextFieldWithQuery.this); } } textField.setCaretPosition(0); } }); dbBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } log.debug("currentText: " + currentText); doQuery(currentText, currentText, 0); } }); }