Example usage for java.awt.event KeyEvent VK_ENTER

List of usage examples for java.awt.event KeyEvent VK_ENTER

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_ENTER.

Prototype

int VK_ENTER

To view the source code for java.awt.event KeyEvent VK_ENTER.

Click Source Link

Document

Constant for the ENTER virtual key.

Usage

From source file:org.piraso.ui.base.ContextMonitorTopComponent.java

private void initKeyboardActions() {
    Action findAction = new AbstractAction() {
        @Override/*from   www .j  a v  a  2s .  com*/
        public void actionPerformed(ActionEvent e) {
            searcher.reset();
            btnSearch.setSelected(!btnSearch.isSelected());
            btnSearchActionPerformed(e);
        }
    };

    Action nextAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnNextActionPerformed(e);
        }
    };

    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.META_MASK);
    registerKeyboardAction(findAction, stroke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    txtSearch.registerKeyboardAction(findAction, stroke, JComponent.WHEN_FOCUSED);

    stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    txtSearch.registerKeyboardAction(nextAction, stroke, JComponent.WHEN_FOCUSED);
}

From source file:ocropusgtedit.mainFrame.java

private void GTTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_GTTextFieldKeyPressed
    // TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        try {/*www  . j av a2s.  com*/
            // TODO: save
            BufferedWriter out = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(txtFilesArray[globalCounter]), "UTF8"));
            out.write(GTTextField.getText());
            out.close();

            // load new img+txt
            globalCounter++;
            img = ImageIO.read(imgFilesArray[globalCounter]);
            Icon ico = new ImageIcon(
                    Scalr.resize(img, Scalr.Method.SPEED, Scalr.Mode.FIT_TO_HEIGHT, 50, Scalr.OP_ANTIALIAS));
            GTLabel.setIcon(ico);

            GTTextField.setText("");
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(new FileInputStream(txtFilesArray[globalCounter]), "UTF8"));
            String str;
            while ((str = in.readLine()) != null) {
                GTTextField.setText(GTTextField.getText() + str);
            }
            in.close();

        } catch (IOException ex) {
            Logger.getLogger(mainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.pegadi.client.LoginDialog.java

void userNameField_keyReleased(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        passwordField.requestFocus();
    }
}

From source file:com.mirth.connect.client.ui.components.rsta.FindReplaceDialog.java

private void initComponents() {
    setLayout(new MigLayout("insets 11, novisualpadding, hidemode 3, fill, gap 6"));
    setBackground(UIConstants.COMBO_BOX_BACKGROUND);
    getContentPane().setBackground(getBackground());

    findPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill, gap 6"));
    findPanel.setBackground(getBackground());

    ActionListener findActionListener = new ActionListener() {
        @Override//from   www  .j  a  v a  2 s.  c  om
        public void actionPerformed(ActionEvent evt) {
            find();
        }
    };

    findLabel = new JLabel("Find text:");
    findComboBox = new JComboBox<String>();
    findComboBox.setEditable(true);
    findComboBox.setBackground(UIConstants.BACKGROUND_COLOR);

    findComboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent evt) {
            if (evt.getKeyCode() == KeyEvent.VK_ENTER && evt.getModifiers() == 0) {
                find();
            }
        }
    });

    ActionListener replaceActionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            replace();
        }
    };

    replaceLabel = new JLabel("Replace with:");
    replaceComboBox = new JComboBox<String>();
    replaceComboBox.setEditable(true);
    replaceComboBox.setBackground(UIConstants.BACKGROUND_COLOR);

    directionPanel = new JPanel(new MigLayout("insets 8, novisualpadding, hidemode 3, fill, gap 6"));
    directionPanel.setBackground(getBackground());
    directionPanel.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(new Color(150, 150, 150)), "Direction",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11)));

    ButtonGroup directionButtonGroup = new ButtonGroup();

    directionForwardRadio = new JRadioButton("Forward");
    directionForwardRadio.setBackground(directionPanel.getBackground());
    directionButtonGroup.add(directionForwardRadio);

    directionBackwardRadio = new JRadioButton("Backward");
    directionBackwardRadio.setBackground(directionPanel.getBackground());
    directionButtonGroup.add(directionBackwardRadio);

    optionsPanel = new JPanel(new MigLayout("insets 8, novisualpadding, hidemode 3, fill, gap 6"));
    optionsPanel.setBackground(getBackground());
    optionsPanel.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(new Color(150, 150, 150)), "Options",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11)));

    wrapSearchCheckBox = new JCheckBox("Wrap Search");
    matchCaseCheckBox = new JCheckBox("Match Case");
    regularExpressionCheckBox = new JCheckBox("Regular Expression");
    wholeWordCheckBox = new JCheckBox("Whole Word");

    findButton = new JButton("Find");
    findButton.addActionListener(findActionListener);

    replaceButton = new JButton("Replace");
    replaceButton.addActionListener(replaceActionListener);

    replaceAllButton = new JButton("Replace All");
    replaceAllButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            replaceAll();
        }
    });

    warningLabel = new JLabel();

    closeButton = new JButton("Close");
    closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            dispose();
        }
    });
}

From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

public MindMapPanel(final MindMapPanelController controller) {
    super(null);//  www  . j  a  v  a 2 s .com
    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:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java

@Override
public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException {

    double[] selectedValues;
    if (encoding == null) {
        selectedValues = null;//from w  ww .  j a  va2 s  .c o  m
    } else {
        selectedValues = NumericConditionEncoder.unencodeConditions(encoding);
    }

    final double[] extremeValues = generator.getExtremeNumericValues();
    this.removeAll();

    if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(Box.createHorizontalGlue());
        p.add(new JLabel("<html>All values are blank for this condition.</html>"));
        p.add(Box.createHorizontalGlue());
        this.add(p);
        return;
    }

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel p = ViewUtil.getClearPanel();
    ViewUtil.applyVerticalBoxLayout(p);

    JPanel labelPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(labelPanel);
    labelPanel.add(Box.createHorizontalGlue());
    labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": "));
    labelPanel.add(Box.createHorizontalGlue());
    ButtonGroup group = new ButtonGroup();
    //JRadioButton isButton = new JRadioButton("is within the following range:");
    //JRadioButton nullButton = new JRadioButton("is missing");
    //group.add(isButton);
    //group.add(nullButton);

    final JCheckBox nullButton = new JCheckBox("include missing values");

    JPanel bp = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(bp);
    p.add(labelPanel);
    p.add(bp);
    add(p);
    final DecimalRangeSlider slider = new DecimalRangeSlider();

    slider.setMajorTickSpacing(5);
    slider.setMinorTickSpacing(1);

    final JTextField fromBox = new JTextField();
    final JTextField toBox = new JTextField();

    nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding));

    nullButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                    ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                    extremeValues[1], nullButton.isSelected());
        }
    });

    fromBox.setMaximumSize(new Dimension(10000, 24));
    toBox.setMaximumSize(new Dimension(10000, 24));
    fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setHorizontalAlignment(JTextField.RIGHT);
    toBox.setHorizontalAlignment(JTextField.RIGHT);

    final JLabel fromLabel = new JLabel();
    final JLabel toLabel = new JLabel();

    ViewUtil.makeMini(fromLabel);
    ViewUtil.makeMini(toLabel);

    JPanel fromToContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(fromToContainer);
    fromToContainer.add(Box.createHorizontalGlue());
    fromToContainer.add(fromBox);
    fromToContainer.add(new JLabel(" - "));
    fromToContainer.add(toBox);
    fromToContainer.add(Box.createHorizontalGlue());

    JPanel minMaxContainer = ViewUtil.getClearPanel();
    minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS));

    JPanel sliderContainer = ViewUtil.getClearPanel();
    sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS));
    sliderContainer.add(slider);

    JPanel nullValueContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(nullValueContainer);
    nullValueContainer.add(Box.createHorizontalGlue());
    nullValueContainer.add(nullButton);
    nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue.
    nullValueContainer.add(Box.createHorizontalGlue());

    JPanel labelContainer = ViewUtil.getClearPanel();
    labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS));
    labelContainer.add(fromLabel);
    labelContainer.add(Box.createHorizontalGlue());
    labelContainer.add(toLabel);
    sliderContainer.add(labelContainer);
    minMaxContainer.add(Box.createHorizontalGlue());
    minMaxContainer.add(sliderContainer);
    minMaxContainer.add(Box.createHorizontalGlue());

    add(fromToContainer);
    add(minMaxContainer);
    add(nullValueContainer);
    add(Box.createVerticalBox());

    slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (slider.isEnabled()) {
                fromBox.setText(ViewUtil.numToString(slider.getLow()));
                toBox.setText(ViewUtil.numToString(slider.getHigh()));
                encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                        ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                        extremeValues[1], nullButton.isSelected());
            }
        }
    });

    final KeyListener keyListener = new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText()));
                setSelectedValues(slider, fromBox, toBox, selectedRage);
            }
        }

        private double getNumber(String s) {
            try {
                return Double.parseDouble(s.replaceAll(",", ""));
            } catch (NumberFormatException ignored) {
                return 0;
            }
        }
    };

    CaretListener caretListener = new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent ce) {
            if (!isAdjustingSlider) {
                try {
                    encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                            ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                            extremeValues[1], nullButton.isSelected());
                } catch (Exception e) {
                }
            }
        }
    };

    fromBox.addKeyListener(keyListener);

    toBox.addKeyListener(keyListener);

    fromBox.addCaretListener(caretListener);

    toBox.addCaretListener(caretListener);

    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            isAdjustingSlider = true;
            fromBox.setText(ViewUtil.numToString(slider.getLow()));
            toBox.setText(ViewUtil.numToString(slider.getHigh()));
            isAdjustingSlider = false;
        }
    });

    JPanel bottomContainer = new JPanel();

    bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS));

    bottomContainer.add(Box.createHorizontalGlue());

    add(bottomContainer);

    setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0,
            new Range(extremeValues[0], extremeValues[1]));

    if (encoding != null) {
        double[] d = NumericConditionEncoder.unencodeConditions(encoding);
        setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1]));
    }
}

From source file:org.pegadi.client.LoginDialog.java

void passwordField_keyReleased(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        okButton.doClick();
    }
}

From source file:ja.lingo.application.gui.main.settings.dictionaries.add.AddPanel.java

public void onReaderListKeyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER && !fileChooser.hasSelectedFile()) {
        fileChooser.askForFile();//from   w ww  .  j  a  v  a 2 s  .c  o  m
        e.consume();
    }
}

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  w w  w.  j  a  v a2 s.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:au.org.ala.delta.editor.ui.CharacterTree.java

public CharacterTree() {

    setToggleClickCount(0);/*from  w w  w.  j a v  a2  s  .c  om*/
    _characterListBehaviour = new CharacterListBehaviour();
    _stateListBehaviour = new StateListBehaviour();

    ToolTipManager.sharedInstance().registerComponent(this);

    addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            if (_doubleProcessingMouseEvent) {
                return;
            }
            if (!isEditing()) {
                int selectedRow = getClosestRowForLocation(e.getX(), e.getY());

                if ((selectedRow >= 0) && (e.getClickCount() == 2) && SwingUtilities.isLeftMouseButton(e)) {
                    Action action = getActionMap().get(SELECTION_ACTION_KEY);
                    if (action != null) {
                        action.actionPerformed(new ActionEvent(this, -1, ""));
                    }
                }
            }
        }
    });

    addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {

            TreePath selection = e.getNewLeadSelectionPath();
            if (selection != null) {
                Object lastComponent = selection.getLastPathComponent();
                if (lastComponent instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;

                    if (node.isLeaf()) {
                        CharacterTree.super.setTransferHandler(_stateTransferHandler);
                    } else {
                        CharacterTree.super.setTransferHandler(_characterTransferHandler);
                    }
                }
            }
        }
    });

    ActionMap actionMap = Application.getInstance().getContext().getActionMap(this);

    javax.swing.Action find = actionMap.get("find");
    if (find != null) {
        getActionMap().put("find", find);
    }

    javax.swing.Action findNext = actionMap.get("findNext");
    if (findNext != null) {
        getActionMap().put("findNext", findNext);
    }

    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), SELECTION_ACTION_KEY);

}