Search in sources :

Example 16 with FocusAdapter

use of java.awt.event.FocusAdapter 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 17 with FocusAdapter

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

the class ShareDialog method createFolderPanel.

private JComponent createFolderPanel() {
    final Project project = myVCS.getProject();
    myCommitMessage = new CommitMessage(project) {

        @Override
        public Dimension getPreferredSize() {
            final Dimension superValue = super.getPreferredSize();
            return new Dimension(superValue.width, superValue.height > 90 ? superValue.height : 90);
        }

        @Override
        public void addNotify() {
            super.addNotify();
            myCommitMessage.getEditorField().getFocusTarget().addFocusListener(new FocusAdapter() {

                @Override
                public void focusGained(FocusEvent e) {
                    myPrefferedFocused = myCommitMessage.getEditorField();
                }
            });
        }
    };
    final JPanel panel = new JPanel(new GridBagLayout());
    final GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(1), 0, 0);
    gb.insets.top = 5;
    final JLabel label = new JLabel("Define share target");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    panel.add(label, gb);
    gb.insets.top = 1;
    final ButtonGroup bg = new ButtonGroup();
    myExisting = new JRadioButton();
    mySameNameAsLocal = new JRadioButton();
    myTrunk = new JRadioButton();
    bg.add(myExisting);
    bg.add(mySameNameAsLocal);
    bg.add(myTrunk);
    gb.insets.top = 1;
    ++gb.gridy;
    panel.add(myExisting, gb);
    ++gb.gridy;
    panel.add(mySameNameAsLocal, gb);
    ++gb.gridy;
    gb.insets.top = 5;
    panel.add(myTrunk, gb);
    myCreateStandard = new JCheckBox("Create /tags and /branches");
    myTrunk.addChangeListener(e -> myCreateStandard.setEnabled(myTrunk.isSelected()));
    myCreateStandard.setSelected(true);
    ++gb.gridy;
    gb.insets.top = 0;
    gb.insets.left = 10;
    panel.add(myCreateStandard, gb);
    ++gb.gridy;
    gb.gridx = 0;
    gb.insets.top = 1;
    gb.insets.left = 1;
    gb.weightx = 1;
    gb.fill = GridBagConstraints.HORIZONTAL;
    final LocalChangeList list = ChangeListManager.getInstance(project).getDefaultChangeList();
    String text = list.getComment();
    text = StringUtil.isEmptyOrSpaces(text) ? (list.hasDefaultName() ? "" : list.getName()) : text;
    myCommitMessage.setText(text);
    panel.add(myCommitMessage, gb);
    myCommitMessage.setSeparatorText("Commit Comment Prefix");
    for (EditChangelistSupport support : Extensions.getExtensions(EditChangelistSupport.EP_NAME, project)) {
        support.installSearch(myCommitMessage.getEditorField(), myCommitMessage.getEditorField());
    }
    myTrunk.setSelected(true);
    return panel;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) CommitMessage(com.intellij.openapi.vcs.ui.CommitMessage) FocusEvent(java.awt.event.FocusEvent) Project(com.intellij.openapi.project.Project) EditChangelistSupport(com.intellij.openapi.vcs.changes.ui.EditChangelistSupport) LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList)

Example 18 with FocusAdapter

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

the class ShareDialog method init.

public void init() {
    super.init();
    setTitle("Select Share Target");
    setOKButtonText("Share");
    getRepositoryBrowser().addChangeListener(e -> {
        if (getOKAction() != null) {
            final String selectedURL = getRepositoryBrowser().getSelectedURL();
            updateOptionsTexts(selectedURL);
            getOKAction().setEnabled(selectedURL != null);
        }
    });
    getOKAction().setEnabled(getRepositoryBrowser().getSelectedURL() != null);
    ((RepositoryTreeModel) getRepositoryBrowser().getRepositoryTree().getModel()).setShowFiles(false);
    getRepositoryBrowser().getPreferredFocusedComponent().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            myPrefferedFocused = (JComponent) getRepositoryBrowser().getPreferredFocusedComponent();
        }
    });
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusEvent(java.awt.event.FocusEvent)

Example 19 with FocusAdapter

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

the class CopiesPanel method setFocusableForLinks.

@SuppressWarnings("MethodMayBeStatic")
private void setFocusableForLinks(final LinkLabel label) {
    final Border border = new DottedBorder(new Insets(1, 2, 1, 1), JBColor.BLACK);
    label.setFocusable(true);
    label.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            super.focusGained(e);
            label.setBorder(border);
        }

        @Override
        public void focusLost(FocusEvent e) {
            super.focusLost(e);
            label.setBorder(null);
        }
    });
    label.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                label.doClick();
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) FocusAdapter(java.awt.event.FocusAdapter) KeyAdapter(java.awt.event.KeyAdapter) DottedBorder(com.intellij.ui.DottedBorder) Border(javax.swing.border.Border) DottedBorder(com.intellij.ui.DottedBorder) FocusEvent(java.awt.event.FocusEvent)

Example 20 with FocusAdapter

use of java.awt.event.FocusAdapter in project intellij-plugins by JetBrains.

the class JSpinnerCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    mySpinner.setValue(value);
    mySpinner.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent e) {
            fireEditingStopped();
        }
    });
    mySpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            fireEditingStopped();
        }
    });
    adjust(table, column);
    return mySpinner;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusAdapter (java.awt.event.FocusAdapter)26 FocusEvent (java.awt.event.FocusEvent)26 Dimension (java.awt.Dimension)6 KeyAdapter (java.awt.event.KeyAdapter)5 KeyEvent (java.awt.event.KeyEvent)5 JLabel (javax.swing.JLabel)5 JTextField (javax.swing.JTextField)5 FocusListener (java.awt.event.FocusListener)3 JButton (javax.swing.JButton)3 Container (java.awt.Container)2 FlowLayout (java.awt.FlowLayout)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 JComponent (javax.swing.JComponent)2 JPanel (javax.swing.JPanel)2 JPasswordField (javax.swing.JPasswordField)2 JScrollPane (javax.swing.JScrollPane)2 Border (javax.swing.border.Border)2 DocumentEvent (javax.swing.event.DocumentEvent)2 DocumentListener (javax.swing.event.DocumentListener)2