Search in sources :

Example 16 with FocusEvent

use of java.awt.event.FocusEvent in project intellij-community by JetBrains.

the class XWatchesViewImpl method installEditListeners.

private void installEditListeners() {
    final XDebuggerTree watchTree = getTree();
    final Alarm quitePeriod = new Alarm();
    final Alarm editAlarm = new Alarm();
    final ClickListener mouseListener = new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            if (!SwingUtilities.isLeftMouseButton(event) || ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) != 0)) {
                return false;
            }
            boolean sameRow = isAboveSelectedItem(event, watchTree, false);
            if (!sameRow || clickCount > 1) {
                editAlarm.cancelAllRequests();
                return false;
            }
            final AnAction editWatchAction = ActionManager.getInstance().getAction(XDebuggerActions.XEDIT_WATCH);
            Presentation presentation = editWatchAction.getTemplatePresentation().clone();
            DataContext context = DataManager.getInstance().getDataContext(watchTree);
            final AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
            Runnable runnable = () -> editWatchAction.actionPerformed(actionEvent);
            if (editAlarm.isEmpty() && quitePeriod.isEmpty()) {
                editAlarm.addRequest(runnable, UIUtil.getMultiClickInterval());
            } else {
                editAlarm.cancelAllRequests();
            }
            return false;
        }
    };
    final ClickListener mouseEmptySpaceListener = new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            if (!isAboveSelectedItem(event, watchTree, true)) {
                myRootNode.addNewWatch();
                return true;
            }
            return false;
        }
    };
    ListenerUtil.addClickListener(watchTree, mouseListener);
    ListenerUtil.addClickListener(watchTree, mouseEmptySpaceListener);
    final FocusListener focusListener = new FocusListener() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            editAlarm.cancelAllRequests();
        }
    };
    ListenerUtil.addFocusListener(watchTree, focusListener);
    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(@NotNull TreeSelectionEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }
    };
    watchTree.addTreeSelectionListener(selectionListener);
    myDisposables.add(new Disposable() {

        @Override
        public void dispose() {
            ListenerUtil.removeClickListener(watchTree, mouseListener);
            ListenerUtil.removeClickListener(watchTree, mouseEmptySpaceListener);
            ListenerUtil.removeFocusListener(watchTree, focusListener);
            watchTree.removeTreeSelectionListener(selectionListener);
        }
    });
}
Also used : CompositeDisposable(com.intellij.openapi.CompositeDisposable) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) NotNull(org.jetbrains.annotations.NotNull) FocusEvent(java.awt.event.FocusEvent) Alarm(com.intellij.util.Alarm) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) FocusListener(java.awt.event.FocusListener) DoubleClickListener(com.intellij.ui.DoubleClickListener) ClickListener(com.intellij.ui.ClickListener)

Example 17 with FocusEvent

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

the class AddSignalMastPanel method dccUnLitPanel.

void dccUnLitPanel() {
    dccUnLitPanel.setLayout(new BoxLayout(dccUnLitPanel, BoxLayout.Y_AXIS));
    JPanel dccDetails = new JPanel();
    dccDetails.add(new JLabel(Bundle.getMessage("DCCMastSetAspectId") + ":"));
    dccDetails.add(unLitAspectField);
    unLitAspectField.setText("31");
    dccUnLitPanel.add(dccDetails);
    TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
    border.setTitle(Bundle.getMessage("DCCUnlitAspectNumber"));
    dccUnLitPanel.setBorder(border);
    unLitAspectField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (unLitAspectField.getText().equals("")) {
                return;
            }
            if (!validateAspectId(unLitAspectField.getText())) {
                unLitAspectField.requestFocusInWindow();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) TitledBorder(javax.swing.border.TitledBorder) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 18 with FocusEvent

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

the class AbstractStreamConnectionConfig method checkInitDone.

@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
    if (log.isDebugEnabled()) {
        log.debug("init called for " + name());
    }
    if (init) {
        return;
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
                    JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
                    systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
                }
            }
        });
        systemPrefixField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
                    JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
                    systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
                }
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        });
        connectionNameField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
                    JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
                    connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
                }
            }
        });
        connectionNameField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
                    JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
                    connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
                }
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        });
        for (String i : options.keySet()) {
            final String item = i;
            if (options.get(i).getComponent() instanceof JComboBox) {
                ((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        adapter.setOptionState(item, options.get(item).getItem());
                    }
                });
            }
        }
    }
    init = true;
}
Also used : ActionListener(java.awt.event.ActionListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 19 with FocusEvent

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

the class AddSignalMastPanel method updateDCCMastPanel.

void updateDCCMastPanel() {
    if ((!Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) && (!Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
        return;
    }
    dccAspect = new HashMap<String, DCCAspectPanel>(10);
    java.util.List<jmri.CommandStation> connList = jmri.InstanceManager.getList(jmri.CommandStation.class);
    systemPrefixBox.removeAllItems();
    if (!connList.isEmpty()) {
        for (int x = 0; x < connList.size(); x++) {
            jmri.CommandStation station = connList.get(x);
            if (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem())) {
                if (station instanceof jmri.jmrix.loconet.SlotManager) {
                    systemPrefixBox.addItem(station.getUserName());
                }
            } else {
                systemPrefixBox.addItem(station.getUserName());
            }
        }
    } else {
        systemPrefixBox.addItem("None");
    }
    String mastType = mastNames.get(mastBox.getSelectedIndex()).getName();
    mastType = mastType.substring(11, mastType.indexOf(".xml"));
    jmri.implementation.DefaultSignalAppearanceMap sigMap = jmri.implementation.DefaultSignalAppearanceMap.getMap(sigsysname, mastType);
    java.util.Enumeration<String> aspects = sigMap.getAspects();
    SignalSystem sigsys = InstanceManager.getDefault(jmri.SignalSystemManager.class).getSystem(sigsysname);
    while (aspects.hasMoreElements()) {
        String aspect = aspects.nextElement();
        DCCAspectPanel aPanel = new DCCAspectPanel(aspect);
        dccAspect.put(aspect, aPanel);
        aPanel.setAspectId((String) sigsys.getProperty(aspect, "dccAspect"));
    }
    dccMastPanel.removeAll();
    dccMastPanel.setLayout(new jmri.util.javaworld.GridLayout2(dccAspect.size() + 3, 2));
    dccMastPanel.add(systemPrefixBoxLabel);
    dccMastPanel.add(systemPrefixBox);
    dccMastPanel.add(dccAspectAddressLabel);
    dccMastPanel.add(dccAspectAddressField);
    if (dccAddressListener == null) {
        dccAddressListener = new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                if (dccAspectAddressField.getText().equals("")) {
                    return;
                }
                validateDCCAddress();
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        };
        dccAspectAddressField.addFocusListener(dccAddressListener);
    }
    if (mast == null) {
        systemPrefixBoxLabel.setEnabled(true);
        systemPrefixBox.setEnabled(true);
        dccAspectAddressLabel.setEnabled(true);
        dccAspectAddressField.setEnabled(true);
    }
    for (String aspect : dccAspect.keySet()) {
        // load aspect panels from hashmap
        dccMastPanel.add(dccAspect.get(aspect).getPanel());
    }
    if ((dccAspect.size() & 1) == 1) {
        // spacer
        dccMastPanel.add(new JLabel());
    }
    dccMastPanel.add(new JLabel(Bundle.getMessage("DCCMastCopyAspectId") + ":"));
    dccMastPanel.add(copyFromMastSelection());
}
Also used : JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) SignalSystemManager(jmri.SignalSystemManager) SignalSystem(jmri.SignalSystem) FocusListener(java.awt.event.FocusListener)

Example 20 with FocusEvent

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

the class JsonNetworkConnectionConfig method checkInitDone.

@Override
protected void checkInitDone() {
    super.checkInitDone();
    //options.put(Bundle.getMessage("DiscoveredServices"), new Option(Bundle.getMessage("DiscoveredServices"), services, false));
    if (this.adapter.getSystemConnectionMemo() != null) {
        final JsonClientSystemConnectionMemo memo = (JsonClientSystemConnectionMemo) this.adapter.getSystemConnectionMemo();
        this.transmitPrefixField.setText(memo.getTransmitPrefix());
        this.transmitPrefixField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                memo.setTransmitPrefix(transmitPrefixField.getText());
                transmitPrefixField.setText(memo.getTransmitPrefix());
            }
        });
        this.transmitPrefixField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                memo.setTransmitPrefix(transmitPrefixField.getText());
                transmitPrefixField.setText(memo.getTransmitPrefix());
            }

            @Override
            public void focusGained(FocusEvent e) {
            // nothing to do
            }
        });
        this.nodeIdentityField.setText(memo.getNodeIdentity());
        this.nodeIdentityField.setToolTipText(Bundle.getMessage("NodeIdentityToolTip"));
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusEvent (java.awt.event.FocusEvent)68 FocusListener (java.awt.event.FocusListener)32 FocusAdapter (java.awt.event.FocusAdapter)26 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)14 JLabel (javax.swing.JLabel)12 Dimension (java.awt.Dimension)8 KeyEvent (java.awt.event.KeyEvent)8 JButton (javax.swing.JButton)8 JPanel (javax.swing.JPanel)8 JTextField (javax.swing.JTextField)8 Border (javax.swing.border.Border)8 UIResource (javax.swing.plaf.UIResource)6 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 Insets (java.awt.Insets)5 KeyAdapter (java.awt.event.KeyAdapter)5 MouseEvent (java.awt.event.MouseEvent)5 JComboBox (javax.swing.JComboBox)5 Component (java.awt.Component)4