Search in sources :

Example 61 with FocusListener

use of java.awt.event.FocusListener in project Spark by igniterealtime.

the class SearchService method setActiveSearchService.

public void setActiveSearchService(final Searchable searchable) {
    this.activeSearchable = searchable;
    newSearch = true;
    findField.requestFocus();
    findField.getTextComponent().setForeground((Color) UIManager.get("TextField.lightforeground"));
    findField.setIcon(searchable.getIcon());
    findField.setText(searchable.getDefaultText());
    findField.setToolTipText(searchable.getToolTip());
    findField.getTextComponent().addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            findField.setText("");
        }

        public void focusLost(FocusEvent e) {
            findField.getTextComponent().setForeground((Color) UIManager.get("TextField.lightforeground"));
            findField.setText(searchable.getDefaultText());
        }
    });
}
Also used : Color(java.awt.Color) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 62 with FocusListener

use of java.awt.event.FocusListener in project freeplane by freeplane.

the class MMapController method startEditingAfterSelect.

private void startEditingAfterSelect(final NodeModel newNode) {
    final Component component = Controller.getCurrentController().getMapViewManager().getComponent(newNode);
    if (component == null)
        return;
    component.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
        }

        public void focusGained(FocusEvent e) {
            e.getComponent().removeFocusListener(this);
            final TextController textController = TextController.getController();
            ((MTextController) textController).edit(newNode, newNode.getParentNode(), true, false, false);
        }
    });
}
Also used : MTextController(org.freeplane.features.text.mindmapmode.MTextController) TextController(org.freeplane.features.text.TextController) Component(java.awt.Component) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 63 with FocusListener

use of java.awt.event.FocusListener in project sirix by sirixdb.

the class TreeView method dispose.

@Override
public void dispose() {
    mTree.clearSelection();
    mTree.setModel(null);
    mTree.setCellRenderer(null);
    for (final FocusListener listener : mTree.getFocusListeners()) {
        mTree.removeFocusListener(listener);
    }
    for (final ComponentListener listener : mTree.getComponentListeners()) {
        mTree.removeComponentListener(listener);
    }
    for (final TreeSelectionListener listener : mTree.getTreeSelectionListeners()) {
        mTree.removeTreeSelectionListener(listener);
    }
    for (final ContainerListener listener : mTree.getContainerListeners()) {
        mTree.removeContainerListener(listener);
    }
}
Also used : ComponentListener(java.awt.event.ComponentListener) ContainerListener(java.awt.event.ContainerListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) FocusListener(java.awt.event.FocusListener)

Example 64 with FocusListener

use of java.awt.event.FocusListener in project blue by kunstmusik.

the class Knob method createKnob.

private void createKnob(int preferredWidth) {
    DRAG_SPEED = 0.01F;
    CLICK_SPEED = 0.01F;
    SHADOWX = 1;
    SHADOWY = 1;
    focusColor = DEFAULT_FOCUS_COLOR;
    Dimension prefSize = new Dimension(preferredWidth, preferredWidth);
    setPreferredSize(prefSize);
    // Degrees ??? Radians???
    hitArc.setAngleStart(235);
    addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent me) {
            dragpos = me.getX() + me.getY();
            startVal = val;
            // Fix last angle
            int xpos = middle - me.getX();
            int ypos = middle - me.getY();
            lastAng = Math.atan2(xpos, ypos);
            requestFocus();
        }

        @Override
        public void mouseClicked(MouseEvent me) {
            hitArc.setAngleExtent(-(LENGTH + 20));
            if (hitArc.contains(me.getX(), me.getY())) {
                hitArc.setAngleExtent(MULTIP * (ang - START_ANG) - 10);
                if (hitArc.contains(me.getX(), me.getY())) {
                    decValue();
                } else {
                    incValue();
                }
            }
        }
    });
    // Let the user control the knob with the mouse
    addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseDragged(MouseEvent me) {
            if (dragType == SIMPLE) {
                float f = DRAG_SPEED * ((me.getX() + me.getY()) - dragpos);
                setValue(startVal + f);
            } else if (dragType == ROUND) {
                // Measure relative the middle of the button!
                int xpos = middle - me.getX();
                int ypos = middle - me.getY();
                double ang = Math.atan2(xpos, ypos);
                double diff = lastAng - ang;
                setValue((float) (getValue() + (diff / LENGTH_ANG)));
                lastAng = ang;
            }
        }

        @Override
        public void mouseMoved(MouseEvent me) {
        }
    });
    // Let the user control the knob with the keyboard
    addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            int k = e.getKeyCode();
            if (k == KeyEvent.VK_RIGHT) {
                incValue();
            } else if (k == KeyEvent.VK_LEFT) {
                decValue();
            }
        }
    });
    // Handle focus so that the knob gets the correct focus highlighting.
    addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            repaint();
        }

        @Override
        public void focusLost(FocusEvent e) {
            repaint();
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) KeyListener(java.awt.event.KeyListener) Dimension(java.awt.Dimension) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 65 with FocusListener

use of java.awt.event.FocusListener in project cytoscape-impl by cytoscape.

the class EnhancedSearchPanel method initComponents.

private void initComponents() {
    final String defText = "Enter search term...";
    final Font defFont = UIManager.getFont("TextField.font") != null ? UIManager.getFont("TextField.font").deriveFont(LookAndFeelUtil.getSmallFontSize()) : null;
    tfSearchText = new JTextField();
    tfSearchText.putClientProperty("JTextField.variant", "search");
    tfSearchText.setToolTipText("<html>Example Search Queries:<br><br>YL* -- Search all columns<br>name:YL* -- Search 'name' column<br>GO\\:1232 -- Escape special characters with backslash</html>");
    tfSearchText.setName("tfSearchText");
    if (!isAquaLAF()) {
        tfSearchText.setText(defText);
        if (defFont != null)
            tfSearchText.setFont(defFont);
    }
    tfSearchText.addActionListener(evt -> tfSearchTextActionPerformed(evt));
    tfSearchText.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            if (tfSearchText.getText().equals(defText)) {
                tfSearchText.setText("");
                tfSearchText.setFont(UIManager.getFont("TextField.font"));
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            if (!isAquaLAF() && tfSearchText.getText().trim().isEmpty()) {
                tfSearchText.setText(defText);
                if (defFont != null)
                    tfSearchText.setFont(defFont);
            }
        }
    });
    setKeyBindings(tfSearchText);
    final GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(true);
    layout.setHorizontalGroup(layout.createSequentialGroup().addGap(10, 20, Short.MAX_VALUE).addComponent(tfSearchText, 120, 240, 300));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(tfSearchText, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
}
Also used : GroupLayout(javax.swing.GroupLayout) JTextField(javax.swing.JTextField) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Font(java.awt.Font)

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