Search in sources :

Example 41 with FocusEvent

use of java.awt.event.FocusEvent in project Botnak by Gocnak.

the class BaseEditorPaneUI method installListeners.

protected void installListeners() {
    super.installListeners();
    if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
        focusListener = new FocusListener() {

            public void focusGained(FocusEvent e) {
                if (getComponent() != null) {
                    orgBorder = getComponent().getBorder();
                    LookAndFeel laf = UIManager.getLookAndFeel();
                    if (laf instanceof AbstractLookAndFeel && orgBorder instanceof UIResource) {
                        Border focusBorder = ((AbstractLookAndFeel) laf).getBorderFactory().getFocusFrameBorder();
                        getComponent().setBorder(focusBorder);
                    }
                    getComponent().invalidate();
                    getComponent().repaint();
                }
            }

            public void focusLost(FocusEvent e) {
                if (getComponent() != null) {
                    if (orgBorder instanceof UIResource) {
                        getComponent().setBorder(orgBorder);
                    }
                    getComponent().invalidate();
                    getComponent().repaint();
                }
            }
        };
        getComponent().addFocusListener(focusListener);
    }
}
Also used : FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Border(javax.swing.border.Border) UIResource(javax.swing.plaf.UIResource)

Example 42 with FocusEvent

use of java.awt.event.FocusEvent in project Botnak by Gocnak.

the class BasePasswordFieldUI method installListeners.

protected void installListeners() {
    super.installListeners();
    if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
        focusListener = new FocusListener() {

            public void focusGained(FocusEvent e) {
                if (getComponent() != null) {
                    orgBorder = getComponent().getBorder();
                    LookAndFeel laf = UIManager.getLookAndFeel();
                    if (laf instanceof AbstractLookAndFeel && orgBorder instanceof UIResource) {
                        Border focusBorder = ((AbstractLookAndFeel) laf).getBorderFactory().getFocusFrameBorder();
                        getComponent().setBorder(focusBorder);
                    }
                    getComponent().invalidate();
                    getComponent().repaint();
                }
            }

            public void focusLost(FocusEvent e) {
                if (getComponent() != null) {
                    if (orgBorder instanceof UIResource) {
                        getComponent().setBorder(orgBorder);
                    }
                    getComponent().invalidate();
                    getComponent().repaint();
                }
            }
        };
        getComponent().addFocusListener(focusListener);
    }
}
Also used : FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Border(javax.swing.border.Border) UIResource(javax.swing.plaf.UIResource)

Example 43 with FocusEvent

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

the class ChangeSignatureDialogBase method createSignaturePanel.

private JComponent createSignaturePanel() {
    mySignatureArea = createSignaturePreviewComponent();
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(SeparatorFactory.createSeparator(RefactoringBundle.message("signature.preview.border.title"), null), BorderLayout.NORTH);
    panel.add(mySignatureArea, BorderLayout.CENTER);
    mySignatureArea.setPreferredSize(new Dimension(-1, 130));
    mySignatureArea.setMinimumSize(new Dimension(-1, 130));
    mySignatureArea.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            Container root = findTraversalRoot(getContentPane());
            if (root != null) {
                Component c = root.getFocusTraversalPolicy().getComponentAfter(root, mySignatureArea);
                if (c != null) {
                    IdeFocusManager.findInstance().requestFocus(c, true);
                }
            }
        }
    });
    updateSignature();
    return panel;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusEvent(java.awt.event.FocusEvent)

Example 44 with FocusEvent

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

the class JBLabel method setCopyable.

/**
   * In 'copyable' mode JBLabel has the same appearance but user can select text with mouse and copy it to clipboard with standard shortcut.
   * By default JBLabel is NOT copyable
   * @return 'this' (the same instance)
   */
public JBLabel setCopyable(boolean copyable) {
    if (copyable ^ myEditorPane != null) {
        if (myEditorPane == null) {
            final JLabel ellipsisLabel = new JBLabel("...");
            myIconLabel = new JLabel(getIcon());
            myEditorPane = new JEditorPane() {

                @Override
                public void paint(Graphics g) {
                    Dimension size = getSize();
                    boolean paintEllipsis = getPreferredSize().width > size.width && !myMultiline;
                    if (!paintEllipsis) {
                        super.paint(g);
                    } else {
                        Dimension ellipsisSize = ellipsisLabel.getPreferredSize();
                        int endOffset = size.width - ellipsisSize.width;
                        try {
                            // do not paint half of the letter
                            endOffset = modelToView(viewToModel(new Point(endOffset, 0)) - 1).x;
                        } catch (BadLocationException ignore) {
                        }
                        Shape oldClip = g.getClip();
                        g.clipRect(0, 0, endOffset, size.height);
                        super.paint(g);
                        g.setClip(oldClip);
                        g.translate(endOffset, 0);
                        ellipsisLabel.setSize(ellipsisSize);
                        ellipsisLabel.paint(g);
                        g.translate(-endOffset, 0);
                    }
                }
            };
            myEditorPane.addFocusListener(new FocusAdapter() {

                @Override
                public void focusLost(FocusEvent e) {
                    if (myEditorPane == null)
                        return;
                    int caretPosition = myEditorPane.getCaretPosition();
                    myEditorPane.setSelectionStart(caretPosition);
                    myEditorPane.setSelectionEnd(caretPosition);
                }
            });
            myEditorPane.setContentType("text/html");
            myEditorPane.setEditable(false);
            myEditorPane.setBackground(UIUtil.TRANSPARENT_COLOR);
            myEditorPane.setOpaque(false);
            myEditorPane.setBorder(null);
            UIUtil.putClientProperty(myEditorPane, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Collections.singleton(ellipsisLabel));
            myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
            updateStyle(myEditorPane);
            myEditorPane.setText(getText());
            checkMultiline();
            myEditorPane.setCaretPosition(0);
            updateLayout();
        } else {
            removeAll();
            myEditorPane = null;
            myIconLabel = null;
        }
    }
    return this;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusEvent(java.awt.event.FocusEvent) BadLocationException(javax.swing.text.BadLocationException)

Example 45 with FocusEvent

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

the class FocusTracesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
    if (!(manager instanceof FocusManagerImpl))
        return;
    final FocusManagerImpl focusManager = (FocusManagerImpl) manager;
    myActive = !myActive;
    if (myActive) {
        myFocusTracker = new AWTEventListener() {

            @Override
            public void eventDispatched(AWTEvent event) {
                if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
                    focusManager.recordFocusRequest(((FocusEvent) event).getComponent(), false);
                }
            }
        };
        Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
    }
    if (!myActive) {
        final List<FocusRequestInfo> requests = focusManager.getRequests();
        new FocusTracesDialog(project, new ArrayList<>(requests)).show();
        Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
        myFocusTracker = null;
        requests.clear();
    }
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) Project(com.intellij.openapi.project.Project) AWTEventListener(java.awt.event.AWTEventListener) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) ArrayList(java.util.ArrayList) FocusEvent(java.awt.event.FocusEvent) FocusRequestInfo(com.intellij.openapi.wm.impl.FocusRequestInfo)

Aggregations

FocusEvent (java.awt.event.FocusEvent)81 FocusListener (java.awt.event.FocusListener)38 FocusAdapter (java.awt.event.FocusAdapter)33 JLabel (javax.swing.JLabel)21 ActionEvent (java.awt.event.ActionEvent)18 ActionListener (java.awt.event.ActionListener)17 JPanel (javax.swing.JPanel)15 JTextField (javax.swing.JTextField)15 Dimension (java.awt.Dimension)14 JButton (javax.swing.JButton)10 KeyEvent (java.awt.event.KeyEvent)9 JCheckBox (javax.swing.JCheckBox)9 BoxLayout (javax.swing.BoxLayout)8 JComboBox (javax.swing.JComboBox)8 Border (javax.swing.border.Border)8 Component (java.awt.Component)7 GridBagConstraints (java.awt.GridBagConstraints)6 GridBagLayout (java.awt.GridBagLayout)6 Insets (java.awt.Insets)6 MouseEvent (java.awt.event.MouseEvent)6