Search in sources :

Example 6 with KeyListener

use of java.awt.event.KeyListener in project jabref by JabRef.

the class ManageKeywordsAction method createDialog.

private void createDialog() {
    if (diag != null) {
        return;
    }
    // keyword to add
    JTextField keyword = new JTextField();
    keywordListModel = new DefaultListModel<>();
    JList<Keyword> keywordList = new JList<>(keywordListModel);
    keywordList.setVisibleRowCount(8);
    JScrollPane kPane = new JScrollPane(keywordList);
    diag = new JDialog(frame, Localization.lang("Manage keywords"), true);
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    JButton add = new JButton(Localization.lang("Add"));
    JButton remove = new JButton(Localization.lang("Remove"));
    keywordList.setVisibleRowCount(10);
    intersectKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ALL entries"));
    mergeKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ANY entry"));
    ButtonGroup group = new ButtonGroup();
    group.add(intersectKeywords);
    group.add(mergeKeywords);
    ActionListener stateChanged = e -> fillKeyWordList();
    intersectKeywords.addActionListener(stateChanged);
    mergeKeywords.addActionListener(stateChanged);
    intersectKeywords.setSelected(true);
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:200dlu:grow, 4dlu, fill:pref", "pref, 2dlu, pref, 1dlu, pref, 2dlu, fill:100dlu:grow, 4dlu, pref, 4dlu, pref, "));
    builder.addSeparator(Localization.lang("Keywords of selected entries")).xyw(1, 1, 3);
    builder.add(intersectKeywords).xyw(1, 3, 3);
    builder.add(mergeKeywords).xyw(1, 5, 3);
    builder.add(kPane).xywh(1, 7, 1, 3);
    builder.add(remove).xy(3, 9);
    builder.add(keyword).xy(1, 11);
    builder.add(add).xy(3, 11);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    ok.addActionListener(e -> {
        canceled = false;
        diag.dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            canceled = true;
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    final ActionListener addActionListener = arg0 -> addButtonActionListener(keyword);
    add.addActionListener(addActionListener);
    final ActionListener removeActionListenter = arg0 -> {
        List<Keyword> values = keywordList.getSelectedValuesList();
        for (Keyword val : values) {
            keywordListModel.removeElement(val);
        }
    };
    remove.addActionListener(removeActionListenter);
    keywordList.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_DELETE) {
                removeActionListenter.actionPerformed(null);
            }
        }
    });
    AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters().get(FieldName.KEYWORDS);
    AutoCompleteListener acl = new AutoCompleteListener(autoComp);
    keyword.addKeyListener(acl);
    keyword.addFocusListener(acl);
    keyword.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                addActionListener.actionPerformed(null);
            }
        }
    });
    // Key bindings:
    ActionMap am = builder.getPanel().getActionMap();
    InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
}
Also used : KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) NamedCompound(org.jabref.gui.undo.NamedCompound) AutoCompleter(org.jabref.logic.autocompleter.AutoCompleter) Enumeration(java.util.Enumeration) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) StringUtil(org.jabref.model.strings.StringUtil) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) Action(javax.swing.Action) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) Keyword(org.jabref.model.entry.Keyword) BorderLayout(java.awt.BorderLayout) SpecialFieldsUtils(org.jabref.logic.specialfields.SpecialFieldsUtils) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) JabRefGUI(org.jabref.JabRefGUI) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) JScrollPane(javax.swing.JScrollPane) FieldChange(org.jabref.model.FieldChange) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) FormLayout(com.jgoodies.forms.layout.FormLayout) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) Optional(java.util.Optional) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) InputMap(javax.swing.InputMap) KeyBinding(org.jabref.gui.keyboard.KeyBinding) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) KeyEvent(java.awt.event.KeyEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) JList(javax.swing.JList) List(java.util.List) AbstractAction(javax.swing.AbstractAction) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) Keyword(org.jabref.model.entry.Keyword) ActionMap(javax.swing.ActionMap) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) KeyListener(java.awt.event.KeyListener) InputMap(javax.swing.InputMap) JList(javax.swing.JList) JDialog(javax.swing.JDialog)

Example 7 with KeyListener

use of java.awt.event.KeyListener 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 8 with KeyListener

use of java.awt.event.KeyListener 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 9 with KeyListener

use of java.awt.event.KeyListener in project bytecode-viewer by Konloch.

the class PaneUpdaterThread method run.

public void run() {
    try {
        final byte[] b = BytecodeViewer.getClassBytes(viewer.container, viewer.cn.name + ".class");
        if (decompiler != Decompiler.HEXCODE) {
            RSyntaxTextArea panelArea = new RSyntaxTextArea();
            panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
            panelArea.setCodeFoldingEnabled(true);
            panelArea.setAntiAliasingEnabled(true);
            final RTextScrollPane scrollPane = new RTextScrollPane(panelArea);
            panelArea.setText(decompiler.decompileClassNode(viewer.cn, b));
            panelArea.setCaretPosition(0);
            panelArea.setEditable(viewer.isPaneEditable(paneId));
            panelArea.addKeyListener(new KeyListener() {

                @Override
                public void keyPressed(KeyEvent e) {
                    if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
                        viewer.requestFocus(paneId);
                    }
                    BytecodeViewer.checkHotKey(e);
                }

                @Override
                public void keyReleased(KeyEvent arg0) {
                }

                @Override
                public void keyTyped(KeyEvent arg0) {
                }
            });
            scrollPane.setColumnHeaderView(new JLabel(decompiler.getName() + " Decompiler - Editable: " + panelArea.isEditable()));
            panelArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    target.add(scrollPane);
                }
            });
            viewer.updatePane(paneId, panelArea, decompiler);
        } else {
            final JHexEditor hex = new JHexEditor(b);
            hex.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    target.add(hex);
                }
            });
        }
    } catch (Exception e) {
        new ExceptionUI(e);
    } finally {
        viewer.resetDivider();
        BytecodeViewer.viewer.setIcon(false);
        if (button != null)
            button.setEnabled(true);
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) JHexEditor(com.jhe.hexed.JHexEditor) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) ExceptionUI(the.bytecode.club.bytecodeviewer.api.ExceptionUI) KeyListener(java.awt.event.KeyListener) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Example 10 with KeyListener

use of java.awt.event.KeyListener in project dogecade by ebanisadr.

the class MainMenu method createUIComponents.

private void createUIComponents() {
    myAccountButton = new JButton("My MyProfileScreen");
    myAccountButton.addActionListener(e -> MyAccountScreen.showMyAccountWindow());
    chatTextArea = new JChatBox();
    sendButton = new JButton("send");
    sendButton.addActionListener(e -> ((JChatBox) chatTextArea).getMessageFromEnterBox());
    enterTextField = new JTextField();
    enterTextField.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                ((JChatBox) chatTextArea).getMessageFromEnterBox();
            }
        }
    });
    roomsPanel = new JPanel();
    JButton startRPSButton = new JButton("play rps against the computer");
    startRPSButton.addActionListener(e -> {
        List<Player> p = new ArrayList<>();
        p.add(new Player(Dogecade.server.getUsername(), BigDecimal.valueOf(100)));
        p.add(new Player("name2", BigDecimal.valueOf(33)));
        new RockPaperScissors(p, Dogecade.rpsServer, 3).startGame();
    });
    roomsPanel.add(startRPSButton);
}
Also used : KeyEvent(java.awt.event.KeyEvent) Player(dogecade.games.Player) RockPaperScissors(dogecade.games.rps.RockPaperScissors) ArrayList(java.util.ArrayList) KeyListener(java.awt.event.KeyListener)

Aggregations

KeyListener (java.awt.event.KeyListener)64 KeyEvent (java.awt.event.KeyEvent)53 JPanel (javax.swing.JPanel)20 ActionEvent (java.awt.event.ActionEvent)18 ActionListener (java.awt.event.ActionListener)17 GridBagConstraints (java.awt.GridBagConstraints)15 JLabel (javax.swing.JLabel)14 JTextField (javax.swing.JTextField)13 GridBagLayout (java.awt.GridBagLayout)12 Insets (java.awt.Insets)11 BorderLayout (java.awt.BorderLayout)8 Dimension (java.awt.Dimension)8 FocusEvent (java.awt.event.FocusEvent)8 FocusListener (java.awt.event.FocusListener)8 JButton (javax.swing.JButton)8 Point (java.awt.Point)7 MouseAdapter (java.awt.event.MouseAdapter)6 MouseEvent (java.awt.event.MouseEvent)6 JComponent (javax.swing.JComponent)5 Color (java.awt.Color)4