Search in sources :

Example 41 with FocusListener

use of java.awt.event.FocusListener in project vcell by virtualcell.

the class DisabledTreeCellEditor method getTreeCellEditorComponent.

@Override
public Component getTreeCellEditorComponent(final JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
    Component container = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
    // Note: System.out.println("Components Type: "+containeractually.getClass().getName());
    // was used to show it was container, javax.swing.tree.DefaultTreeCellEditor$EditorContainer
    // getTreeCellEditorComponent(parameters) is called as soon as editing begins
    // also at this time editingComponent != null (aka initialized)
    // so it's a good place to add in a Focus Listener
    editingComponent.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
        }

        @Override
        public void focusLost(FocusEvent e) {
            tree.stopEditing();
        }
    });
    // (I think the return statement means it's about to be used)
    return container;
}
Also used : Component(java.awt.Component) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 42 with FocusListener

use of java.awt.event.FocusListener in project omegat by omegat-org.

the class StaticUIUtils method makeCaretAlwaysVisible.

/**
 * Make caret visible even when the {@link JTextComponent} is not editable.
 */
public static FocusListener makeCaretAlwaysVisible(final JTextComponent comp) {
    FocusListener listener = new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            Caret caret = comp.getCaret();
            caret.setVisible(true);
            caret.setSelectionVisible(true);
        }
    };
    comp.addFocusListener(listener);
    return listener;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Caret(javax.swing.text.Caret) DefaultCaret(javax.swing.text.DefaultCaret)

Example 43 with FocusListener

use of java.awt.event.FocusListener in project sldeditor by robward-scisys.

the class FieldConfigGeometry method createUI.

/**
 * Creates the ui.
 */
/*
     * (non-Javadoc)
     *
     * @see com.sldeditor.ui.detail.config.FieldConfigBase#createUI()
     */
@Override
public void createUI() {
    if (textField == null) {
        int xPos = getXPos();
        FieldPanel fieldPanel = createFieldPanel(xPos, getLabel());
        textField = new JTextField();
        textField.setBounds(xPos + BasePanel.WIDGET_X_START, 0, this.isValueOnly() ? BasePanel.WIDGET_EXTENDED_WIDTH : BasePanel.WIDGET_STANDARD_WIDTH, BasePanel.WIDGET_HEIGHT);
        fieldPanel.add(textField);
        textField.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                originalValue = textField.getText();
            }

            @Override
            public void focusLost(FocusEvent e) {
                valueStored(textField.getText());
            }
        });
        if (buttonText != null) {
            final JButton buttonExternal = new JButton(buttonText);
            buttonExternal.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    externalButtonPressed(buttonExternal);
                }
            });
            int buttonWidth = 26;
            int padding = 3;
            buttonExternal.setBounds(xPos + textField.getX() - buttonWidth - padding, 0, buttonWidth, BasePanel.WIDGET_HEIGHT);
            fieldPanel.add(buttonExternal);
        }
        if (!isValueOnly()) {
            setAttributeSelectionPanel(fieldPanel.internalCreateAttrButton(Geometry.class, this, isRasterSymbol()));
        }
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) FieldPanel(com.sldeditor.ui.widgets.FieldPanel) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 44 with FocusListener

use of java.awt.event.FocusListener in project OsmAnd-tools by osmandapp.

the class OsmExtractionUI method updateStatusField.

private void updateStatusField(final JTextField statusField) {
    popup = new JScrollPopupMenu();
    popup.setMaximumVisibleRows(25);
    popup.setFocusable(false);
    searchUICore.setOnResultsComplete(new Runnable() {

        @Override
        public void run() {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    updateSearchResult(statusField, searchUICore.getCurrentSearchResult(), true);
                }
            });
        }
    });
    statusField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
        // if(e.getOppositeComponent() != popup) {
        // popup.setVisible(false);
        // }
        }

        @Override
        public void focusGained(FocusEvent e) {
            popup.setFocusable(false);
            SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation(new LatLon(mapPanel.getLatitude(), mapPanel.getLongitude()));
            settings = settings.setLang(DataExtractionSettings.getSettings().getSearchLocale(), false);
            searchUICore.updateSettings(settings);
        }
    });
    statusField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            super.keyPressed(e);
            mapPanel.setStatusField(null);
            if (e.getKeyCode() == KeyEvent.VK_DOWN && popup.getComponentCount() > 0) {
                popup.setVisible(false);
                popup.setFocusable(true);
                Point p = statusField.getLocation();
                popup.show(e.getComponent(), p.x, p.y - 4);
                // popup.show();
                popup.requestFocus();
                return;
            }
        }

        @Override
        public void keyTyped(KeyEvent e) {
            mapPanel.setStatusField(null);
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                return;
            }
            String text = statusField.getText();
            int ps = statusField.getCaretPosition();
            if (e.getKeyChar() == '\b') {
            // nothing
            } else if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
                if (ps >= text.length()) {
                    text += e.getKeyChar();
                } else {
                    text = text.substring(0, ps) + e.getKeyChar() + text.substring(ps);
                }
            }
            SearchSettings settings = searchUICore.getPhrase().getSettings();
            if (settings.getRadiusLevel() != 1) {
                searchUICore.updateSettings(settings.setRadiusLevel(1));
            }
            SearchResultCollection c = null;
            if (!text.contains("#map")) {
                searchUICore.search(text, true, null);
            }
        // if(c != null) {
        // updateSearchResult(statusField, c, false);
        // }
        }
    });
    statusField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            mapPanel.setStatusField(statusField);
            String txt = statusField.getText();
            int i = txt.indexOf("#map=");
            if (i != -1) {
                String[] vs = txt.substring(i + "#map=".length()).split("/");
                mapPanel.setLatLon(Float.parseFloat(vs[1]), Float.parseFloat(vs[2]));
                mapPanel.setZoom(Integer.parseInt(vs[0]));
            }
            mapPanel.refresh();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) Point(java.awt.Point) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) LatLon(net.osmand.data.LatLon) ActionListener(java.awt.event.ActionListener) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) FocusListener(java.awt.event.FocusListener)

Example 45 with FocusListener

use of java.awt.event.FocusListener in project ACS by ACS-Community.

the class ScriptFilter method getGroupTextField.

/**
	 * This method initializes groupTextField
	 * @return javax.swing.JTextField
	 */
private JTextField getGroupTextField() {
    if (groupTextField == null) {
        Dimension d = new Dimension(150, 19);
        groupTextField = new JTextField();
        groupTextField.setPreferredSize(d);
        //groupTextField.setSize(d);
        groupTextField.setMinimumSize(d);
        groupTextField.setToolTipText("Sampling Group where to add the new Sample. Only alphanumeric and underscore characters.");
        groupTextField.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        groupTextField.setHorizontalAlignment(JTextField.LEFT);
        groupTextField.setText("SampGroup");
        groupTextField.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {
            // Do nothing special :)
            }

            public void focusLost(FocusEvent e) {
                if (!groupTextField.getText().matches("^([a-z]|[A-Z]|[0-9]|_)+$")) {
                    JOptionPane.showConfirmDialog(SamplingSystemGUI.this, "Group name '" + groupTextField.getText() + "' is invalid.\nPlease use only alphanumeric characters and/or underscores.", "Invalid group name", JOptionPane.PLAIN_MESSAGE, JOptionPane.WARNING_MESSAGE);
                    groupTextField.setText("");
                    groupTextField.grabFocus();
                }
            }
        });
    }
    return groupTextField;
}
Also used : Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusListener (java.awt.event.FocusListener)87 FocusEvent (java.awt.event.FocusEvent)80 ActionEvent (java.awt.event.ActionEvent)24 ActionListener (java.awt.event.ActionListener)23 JLabel (javax.swing.JLabel)20 JTextField (javax.swing.JTextField)17 Dimension (java.awt.Dimension)16 JPanel (javax.swing.JPanel)16 JButton (javax.swing.JButton)15 KeyEvent (java.awt.event.KeyEvent)12 JComboBox (javax.swing.JComboBox)11 BorderLayout (java.awt.BorderLayout)9 Component (java.awt.Component)9 MouseEvent (java.awt.event.MouseEvent)9 KeyListener (java.awt.event.KeyListener)8 JCheckBox (javax.swing.JCheckBox)8 ChangeListener (javax.swing.event.ChangeListener)8 Color (java.awt.Color)7 GridBagConstraints (java.awt.GridBagConstraints)7 MouseAdapter (java.awt.event.MouseAdapter)7