Search in sources :

Example 66 with FocusListener

use of java.awt.event.FocusListener in project com.revolsys.open by revolsys.

the class MouseOverlay method focusLost.

@Override
public void focusLost(final FocusEvent e) {
    if (!e.isTemporary()) {
        final Component component = e.getComponent();
        if (component != this) {
            final Component oppositeComponent = e.getOppositeComponent();
            if (oppositeComponent != SwingUtilities.getWindowAncestor(this)) {
                for (final Component overlay : getOverlays()) {
                    if (overlay instanceof FocusListener) {
                        final FocusListener listener = (FocusListener) overlay;
                        listener.focusLost(e);
                    }
                }
            }
        }
    }
}
Also used : JComponent(javax.swing.JComponent) Component(java.awt.Component) FocusListener(java.awt.event.FocusListener)

Example 67 with FocusListener

use of java.awt.event.FocusListener in project deltahex-java by exbin.

the class CodeArea method registerControlListeners.

private void registerControlListeners() {
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(@Nonnull ComponentEvent event) {
            resetPainter();
        }
    });
    addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(@Nonnull KeyEvent keyEvent) {
            commandHandler.keyTyped(keyEvent);
        }

        @Override
        public void keyPressed(@Nonnull KeyEvent keyEvent) {
            commandHandler.keyPressed(keyEvent);
        }
    });
    addFocusListener(new FocusListener() {

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

        @Override
        public void focusLost(@Nonnull FocusEvent e) {
            repaint();
        }
    });
    UIManager.addPropertyChangeListener((@Nonnull PropertyChangeEvent evt) -> {
        worker.rebuildColors();
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) Nonnull(javax.annotation.Nonnull) KeyAdapter(java.awt.event.KeyAdapter) ComponentEvent(java.awt.event.ComponentEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 68 with FocusListener

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

the class ResourceListPane method attachQuickSearchListeners.

public void attachQuickSearchListeners() {
    quickSearch.addKeyListener(search);
    quickSearch.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(final FocusEvent arg0) {
            if (quickSearch.getText().equals(TranslatedStrings.QUICK_FILE_SEARCH_NO_FILE_EXTENSION.toString())) {
                quickSearch.setText("");
                quickSearch.setForeground(Color.black);
            }
        }

        @Override
        public void focusLost(final FocusEvent arg0) {
            if (quickSearch.getText().isEmpty()) {
                quickSearch.setText(TranslatedStrings.QUICK_FILE_SEARCH_NO_FILE_EXTENSION.toString());
                quickSearch.setForeground(Color.gray);
            }
        }
    });
}
Also used : FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 69 with FocusListener

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

the class ScrollTable method initialize.

private void initialize() {
    autoResizeMode = AUTO_RESIZE_OFF;
    // make it bigger on Mac
    setRowHeight(getRowHeight() + 4);
    putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
    scrollTableActionManager = new DefaultScrollTableActionManager(this);
    enclosingScrollPane = new JScrollPane(this);
    enclosingScrollPane.getViewport().setBackground(Color.WHITE);
    contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(enclosingScrollPane, BorderLayout.CENTER);
    setPreferredScrollableViewportSize(new Dimension(200, 100));
    setIntercellSpacing(new Dimension(2, 2));
    defaultTableCellRenderer = new DefaultScrollTableCellRenderer();
    setDefaultRenderer(Object.class, defaultTableCellRenderer);
    setDefaultRenderer(Number.class, defaultTableCellRenderer);
    setDefaultRenderer(Double.class, defaultTableCellRenderer);
    setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
    setDefaultEditor(Boolean.class, new ScrollTableBooleanEditor());
    final TableCellRenderer defaultTableCellHeaderRenderer = getTableHeader().getDefaultRenderer();
    TableCellRenderer defaultTableHeaderRenderer = new TableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component component = defaultTableCellHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (component instanceof JLabel) {
                JLabel label = (JLabel) component;
                label.setHorizontalAlignment(SwingConstants.CENTER);
                label.setBackground(tableHeaderColor);
                label.setBorder(BorderFactory.createCompoundBorder(tableCellHeaderBorder, new EmptyBorder(1, 0, 1, 0)));
            }
            return component;
        }
    };
    getTableHeader().setDefaultRenderer(defaultTableHeaderRenderer);
    MouseAdapter mouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (!javaVersion.startsWith("1.5")) {
                if (!hasFocus()) {
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        addFocusListener(new FocusListener() {

                            public void focusLost(FocusEvent e) {
                            }

                            public void focusGained(FocusEvent e) {
                                removeFocusListener(this);
                                Robot robot;
                                try {
                                    robot = new Robot();
                                    robot.mousePress(InputEvent.BUTTON1_MASK);
                                    robot.mouseRelease(InputEvent.BUTTON1_MASK);
                                } catch (AWTException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        });
                    }
                    requestFocusInWindow();
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            scrollTableActionManager.triggerPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            scrollTableActionManager.triggerPopup(e);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            hoverRow = rowAtPoint(e.getPoint());
            hoverColumn = columnAtPoint(e.getPoint());
            repaint();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            hoverRow = -1;
            hoverColumn = -1;
            repaint();
        }
    };
    MouseMotionAdapter mouseMotionListener = new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            hoverRow = rowAtPoint(e.getPoint());
            hoverColumn = columnAtPoint(e.getPoint());
            repaint();
        }
    };
    addMouseListener(mouseListener);
    addMouseMotionListener(mouseMotionListener);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TableCellRenderer(javax.swing.table.TableCellRenderer) ScopedExpressionTableCellRenderer(cbit.vcell.model.gui.ScopedExpressionTableCellRenderer) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) EventObject(java.util.EventObject) Component(java.awt.Component) JComponent(javax.swing.JComponent) EmptyBorder(javax.swing.border.EmptyBorder) FocusListener(java.awt.event.FocusListener) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Example 70 with FocusListener

use of java.awt.event.FocusListener in project triplea by triplea-game.

the class CollectionProperty method getEditorComponent.

@Override
public JComponent getEditorComponent() {
    if (m_values == null) {
        return new JTable();
    }
    final Object[][] tableD = new Object[m_values.size()][1];
    for (int i = 0; i < m_values.size(); i++) {
        tableD[i][0] = m_values.get(i);
    }
    final JTable table = new JTable(tableD, new Object[] { "Values: " });
    table.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(final FocusEvent e) {
        }

        @Override
        public void focusLost(final FocusEvent e) {
        // TODO: change m_values
        }
    });
    return table;
}
Also used : JTable(javax.swing.JTable) 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