Search in sources :

Example 66 with KeyEvent

use of java.awt.event.KeyEvent in project jdk8u_jdk by JetBrains.

the class DefaultKeyboardFocusManager method repostIfFollowsKeyEvents.

/*
     * Checks if the focus window event follows key events waiting in the type-ahead
     * queue (if any). This may happen when a user types ahead in the window, the client
     * listeners hang EDT for a while, and the user switches b/w toplevels. In that
     * case the focus window events may be dispatched before the type-ahead events
     * get handled. This may lead to wrong focus behavior and in order to avoid it,
     * the focus window events are reposted to the end of the event queue. See 6981400.
     */
private boolean repostIfFollowsKeyEvents(WindowEvent e) {
    if (!(e instanceof TimedWindowEvent)) {
        return false;
    }
    TimedWindowEvent we = (TimedWindowEvent) e;
    long time = we.getWhen();
    synchronized (this) {
        KeyEvent ke = enqueuedKeyEvents.isEmpty() ? null : enqueuedKeyEvents.getFirst();
        if (ke != null && time >= ke.getWhen()) {
            TypeAheadMarker marker = typeAheadMarkers.isEmpty() ? null : typeAheadMarkers.getFirst();
            if (marker != null) {
                Window toplevel = marker.untilFocused.getContainingWindow();
                // the current focused window. See 8015454.
                if (toplevel != null && toplevel.isFocused()) {
                    SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e));
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : KeyEvent(java.awt.event.KeyEvent) TimedWindowEvent(sun.awt.TimedWindowEvent)

Example 67 with KeyEvent

use of java.awt.event.KeyEvent in project processdash by dtuma.

the class PreferencesTextField method addUpdateFromTextListeners.

@Override
protected void addUpdateFromTextListeners() {
    addActionListener((ActionListener) EventHandler.create(ActionListener.class, this, "updateFromText"));
    addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            updateFromText();
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter)

Example 68 with KeyEvent

use of java.awt.event.KeyEvent in project JMRI by JMRI.

the class BlockEditAction method physcialDetails.

BeanItemPanel physcialDetails() {
    defaultBlockSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + jmri.InstanceManager.getDefault(jmri.BlockManager.class).getDefaultSpeed());
    speedList.add(defaultBlockSpeedText);
    java.util.Vector<String> _speedMap = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames();
    for (int i = 0; i < _speedMap.size(); i++) {
        if (!speedList.contains(_speedMap.get(i))) {
            speedList.add(_speedMap.get(i));
        }
    }
    BeanItemPanel basic = new BeanItemPanel();
    basic.setName(Bundle.getMessage("BlockPhysicalProperties"));
    basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("BlockPropertiesText")));
    basic.addItem(new BeanEditItem(lengthField, Bundle.getMessage("BlockLengthColName"), Bundle.getMessage("BlockLengthText")));
    lengthField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent keyEvent) {
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            String text = lengthField.getText();
            // ensure data valid
            try {
                jmri.util.IntlUtilities.floatValue(text);
            } catch (java.text.ParseException e) {
                String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("BlockLengthColName") });
                jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "length", false, false);
            }
        }

        @Override
        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    ButtonGroup rg = new ButtonGroup();
    rg.add(inch);
    rg.add(cm);
    JPanel p = new JPanel();
    p.add(inch);
    p.add(cm);
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    inch.setSelected(true);
    inch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cm.setSelected(!inch.isSelected());
            updateLength();
        }
    });
    cm.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            inch.setSelected(!cm.isSelected());
            updateLength();
        }
    });
    basic.addItem(new BeanEditItem(p, Bundle.getMessage("BlockLengthUnits"), Bundle.getMessage("BlockLengthUnitsText")));
    basic.addItem(new BeanEditItem(curvatureField, Bundle.getMessage("BlockCurveColName"), ""));
    basic.addItem(new BeanEditItem(speedField = new JComboBox<String>(speedList), Bundle.getMessage("BlockSpeedColName"), Bundle.getMessage("BlockMaxSpeedText")));
    basic.addItem(new BeanEditItem(permissiveField, Bundle.getMessage("BlockPermColName"), Bundle.getMessage("BlockPermissiveText")));
    permissiveField.setSelected(((Block) bean).getPermissiveWorking());
    basic.setSaveItem(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Block blk = (Block) bean;
            String cName = (String) curvatureField.getSelectedItem();
            if (cName.equals(noneText)) {
                blk.setCurvature(Block.NONE);
            } else if (cName.equals(gradualText)) {
                blk.setCurvature(Block.GRADUAL);
            } else if (cName.equals(tightText)) {
                blk.setCurvature(Block.TIGHT);
            } else if (cName.equals(severeText)) {
                blk.setCurvature(Block.SEVERE);
            }
            String speed = (String) speedField.getSelectedItem();
            try {
                blk.setBlockSpeed(speed);
            } catch (jmri.JmriException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
                return;
            }
            if (!speedList.contains(speed) && !speed.contains("Global")) {
                speedList.add(speed);
            }
            float len = 0.0f;
            try {
                len = jmri.util.IntlUtilities.floatValue(lengthField.getText());
            } catch (java.text.ParseException ex2) {
                log.error("Error parsing length value of \"{}\"", lengthField.getText());
            }
            if (inch.isSelected()) {
                blk.setLength(len * 25.4f);
            } else {
                blk.setLength(len * 10.0f);
            }
            blk.setPermissiveWorking(permissiveField.isSelected());
        }
    });
    basic.setResetItem(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Block blk = (Block) bean;
            lengthField.setText(twoDigit.format(((Block) bean).getLengthMm()));
            if (blk.getCurvature() == Block.NONE) {
                curvatureField.setSelectedItem(0);
            } else if (blk.getCurvature() == Block.GRADUAL) {
                curvatureField.setSelectedItem(gradualText);
            } else if (blk.getCurvature() == Block.TIGHT) {
                curvatureField.setSelectedItem(tightText);
            } else if (blk.getCurvature() == Block.SEVERE) {
                curvatureField.setSelectedItem(severeText);
            }
            String speed = blk.getBlockSpeed();
            if (!speedList.contains(speed)) {
                speedList.add(speed);
            }
            speedField.setEditable(true);
            speedField.setSelectedItem(speed);
            double len = 0.0;
            if (inch.isSelected()) {
                len = blk.getLengthIn();
            } else {
                len = blk.getLengthCm();
            }
            lengthField.setText(twoDigit.format(len));
            permissiveField.setSelected(((Block) bean).getPermissiveWorking());
        }
    });
    bei.add(basic);
    return basic;
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyEvent(java.awt.event.KeyEvent) SignalSpeedMap(jmri.implementation.SignalSpeedMap) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) Block(jmri.Block) KeyListener(java.awt.event.KeyListener) AbstractAction(javax.swing.AbstractAction)

Example 69 with KeyEvent

use of java.awt.event.KeyEvent in project JMRI by JMRI.

the class SensorDebounceEditAction method sensorDebounce.

public BeanItemPanel sensorDebounce(BeanItemPanel basic) {
    if (basic == null) {
        basic = new BeanItemPanel();
        basic.setName(Bundle.getMessage("SensorDebounce"));
    }
    sensorDebounceGlobalCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (sensorDebounceGlobalCheck.isSelected()) {
                sensorDebounceInactiveField.setEnabled(false);
                sensorDebounceActiveField.setEnabled(false);
            } else {
                sensorDebounceInactiveField.setEnabled(true);
                sensorDebounceActiveField.setEnabled(true);
            }
        }
    });
    sensorDebounceInactiveField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent keyEvent) {
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            String text = sensorDebounceInactiveField.getText();
            if (!validateNumericalInput(text)) {
                String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("SensorInActiveDebounce") });
                jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "Inactive", false, false);
            }
        }

        @Override
        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    sensorDebounceActiveField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent keyEvent) {
        }

        @Override
        public void keyReleased(KeyEvent keyEvent) {
            String text = sensorDebounceActiveField.getText();
            if (!validateNumericalInput(text)) {
                String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("SensorActiveDebounce") });
                jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "Active", false, false);
            }
        }

        @Override
        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("SensorDebounceText")));
    basic.addItem(new BeanEditItem(sensorDebounceGlobalCheck, Bundle.getMessage("SensorDebounceUseGlobalText"), null));
    basic.addItem(new BeanEditItem(sensorDebounceInactiveField, Bundle.getMessage("SensorInActiveDebounce"), Bundle.getMessage("SensorInActiveDebounceText")));
    basic.addItem(new BeanEditItem(sensorDebounceActiveField, Bundle.getMessage("SensorActiveDebounce"), Bundle.getMessage("SensorActiveDebounceText")));
    basic.setSaveItem(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveDebounceItems(e);
        }
    });
    basic.setResetItem(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            resetDebounceItems(e);
        }
    });
    return basic;
}
Also used : KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) KeyListener(java.awt.event.KeyListener) AbstractAction(javax.swing.AbstractAction)

Example 70 with KeyEvent

use of java.awt.event.KeyEvent in project android by JetBrains.

the class KeyEventBuilder method build.

public KeyEvent build() {
    KeyEvent event = mock(KeyEvent.class);
    when(event.getSource()).thenReturn(mySource);
    when(event.getKeyCode()).thenReturn(myKeyCode);
    when(event.getKeyChar()).thenReturn(myKeyChar);
    when(event.getModifiers()).thenReturn(myMask);
    when(event.getModifiersEx()).thenReturn(myMask);
    when(event.getKeyLocation()).thenReturn(KeyEvent.KEY_LOCATION_UNKNOWN);
    when(event.getWhen()).thenReturn(System.currentTimeMillis());
    return event;
}
Also used : KeyEvent(java.awt.event.KeyEvent)

Aggregations

KeyEvent (java.awt.event.KeyEvent)301 KeyAdapter (java.awt.event.KeyAdapter)159 MouseEvent (java.awt.event.MouseEvent)79 ActionEvent (java.awt.event.ActionEvent)74 JPanel (javax.swing.JPanel)69 ActionListener (java.awt.event.ActionListener)61 MouseAdapter (java.awt.event.MouseAdapter)59 KeyListener (java.awt.event.KeyListener)54 Dimension (java.awt.Dimension)50 JLabel (javax.swing.JLabel)48 JTextField (javax.swing.JTextField)44 BorderLayout (java.awt.BorderLayout)40 JButton (javax.swing.JButton)40 JScrollPane (javax.swing.JScrollPane)35 Insets (java.awt.Insets)33 Point (java.awt.Point)33 FocusEvent (java.awt.event.FocusEvent)31 GridBagConstraints (java.awt.GridBagConstraints)23 BoxLayout (javax.swing.BoxLayout)22 GridBagLayout (java.awt.GridBagLayout)20