Search in sources :

Example 21 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 22 with FocusAdapter

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

the class ExtractMethodDialog method createParametersPanel.

protected void createParametersPanel() {
    if (myParamTable != null) {
        myCenterPanel.remove(myParamTable);
    }
    myParamTable = createParameterTableComponent();
    myParamTable.setMinimumSize(JBUI.size(500, 100));
    myCenterPanel.add(myParamTable, BorderLayout.CENTER);
    final JTable table = UIUtil.findComponentOfType(myParamTable, JTable.class);
    myCenterPanel.add(SeparatorFactory.createSeparator("&Parameters", table), BorderLayout.NORTH);
    if (table != null) {
        table.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(FocusEvent e) {
                if (table.getRowCount() > 0) {
                    final int col = table.getSelectedColumn();
                    final int row = table.getSelectedRow();
                    if (col == -1 || row == -1) {
                        table.getSelectionModel().setSelectionInterval(0, 0);
                        table.getColumnModel().getSelectionModel().setSelectionInterval(0, 0);
                    }
                }
            }
        });
    }
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusEvent(java.awt.event.FocusEvent)

Example 23 with FocusAdapter

use of java.awt.event.FocusAdapter in project antlrworks by antlr.

the class DialogTestTemplate method initComponents.

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - RP Talusan
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    textTestRadio = new JRadioButton();
    scrollPane1 = new JScrollPane();
    testTextArea = new JTextPane();
    classTestRadio = new JRadioButton();
    testClassField = new JTextField();
    buttonBar = new JPanel();
    okButton = new JButton();
    cancelButton = new JButton();
    testClassHiddenField = new JTextField();
    CellConstraints cc = new CellConstraints();
    //======== this ========
    String title = "Edit Test Rig";
    if (qualifiedFileName != null && !"".equals(qualifiedFileName))
        title = "Edit " + XJUtils.getLastPathComponent(qualifiedFileName) + " Test Rig";
    if (grammarLanguage != null && !"".equals(grammarLanguage))
        title += " for " + grammarLanguage;
    setTitle(title);
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    //======== dialogPane ========
    {
        dialogPane.setBorder(Borders.DIALOG_BORDER);
        dialogPane.setMinimumSize(new Dimension(340, 250));
        dialogPane.setLayout(new BorderLayout());
        //======== contentPanel ========
        {
            contentPanel.setLayout(new FormLayout(new ColumnSpec[] { new ColumnSpec(ColumnSpec.RIGHT, Sizes.DEFAULT, FormSpec.NO_GROW), FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC, new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW) }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC, new RowSpec(RowSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW), FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC }));
            //---- textTestRadio ----
            textTestRadio.setText("Text:");
            contentPanel.add(textTestRadio, cc.xy(1, 1));
            //======== scrollPane1 ========
            {
                scrollPane1.setPreferredSize(new Dimension(300, 200));
                scrollPane1.setViewportView(testTextArea);
            }
            contentPanel.add(scrollPane1, cc.xywh(3, 1, 3, 5));
            //---- classTestRadio ----
            classTestRadio.setText("Class:");
            contentPanel.add(classTestRadio, cc.xy(1, 7));
            //---- testClassField ----
            testClassField.addFocusListener(new FocusAdapter() {

                @Override
                public void focusGained(FocusEvent e) {
                    if (TEXT_FULLY_QUALIFIED_CLASS_NAME.equals(testClassField.getText())) {
                        testClassField.setForeground(Color.BLACK);
                        testClassField.setText("");
                    }
                }

                @Override
                public void focusLost(FocusEvent e) {
                    testClassHiddenField.setText(testClassField.getText());
                    if ("".equals(testClassField.getText())) {
                        testClassField.setForeground(Color.LIGHT_GRAY);
                        testClassField.setText(TEXT_FULLY_QUALIFIED_CLASS_NAME);
                    }
                }
            });
            contentPanel.add(testClassField, cc.xywh(3, 7, 3, 1));
        }
        dialogPane.add(contentPanel, BorderLayout.CENTER);
        //======== buttonBar ========
        {
            buttonBar.setBorder(Borders.BUTTON_BAR_GAP_BORDER);
            buttonBar.setLayout(new FormLayout(new ColumnSpec[] { FormFactory.GLUE_COLSPEC, FormFactory.BUTTON_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.BUTTON_COLSPEC }, RowSpec.decodeSpecs("pref")));
            //---- okButton ----
            okButton.setText("OK");
            buttonBar.add(okButton, cc.xy(2, 1));
            //---- cancelButton ----
            cancelButton.setText("Cancel");
            buttonBar.add(cancelButton, cc.xy(4, 1));
        }
        dialogPane.add(buttonBar, BorderLayout.SOUTH);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    setSize(625, 395);
    //---- buttonGroup1 ----
    ButtonGroup buttonGroup1 = new ButtonGroup();
    buttonGroup1.add(textTestRadio);
    buttonGroup1.add(classTestRadio);
// JFormDesigner - End of component initialization  //GEN-END:initComponents
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusEvent(java.awt.event.FocusEvent)

Example 24 with FocusAdapter

use of java.awt.event.FocusAdapter in project adempiere by adempiere.

the class WindowMenu method createImageBox.

private JXTitledPanel createImageBox(JPanel p, JDialog dialog, int width, int height, CFrame window) {
    BufferedImage bi = new BufferedImage(window.getWidth(), window.getHeight(), //	TYPE_INT_ARGB is tinted red
    BufferedImage.TYPE_INT_RGB);
    window.paintAll(bi.createGraphics());
    Image image = bi.getScaledInstance(width, height, Image.SCALE_SMOOTH);
    final JXTitledPanel box = new JXTitledPanel();
    final Painter painter = box.getTitlePainter();
    box.setTitlePainter(null);
    box.setFocusable(true);
    box.setTitle(window.getTitle());
    final JXImageView imageView = new JXImageView();
    imageView.setImage(image);
    imageView.setEditable(false);
    box.setContentContainer(imageView);
    box.setPreferredSize(new Dimension(width, height));
    box.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    box.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            box.requestFocus();
        }
    });
    imageView.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            box.requestFocus();
        }
    });
    PreviewMouseAdapter adapter = new PreviewMouseAdapter(dialog, window);
    box.addMouseListener(adapter);
    imageView.addMouseListener(adapter);
    imageView.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    box.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            box.setTitlePainter(painter);
        }

        @Override
        public void focusLost(FocusEvent e) {
            box.setTitlePainter(null);
        }
    });
    return box;
}
Also used : JXTitledPanel(org.jdesktop.swingx.JXTitledPanel) FocusAdapter(java.awt.event.FocusAdapter) MouseEvent(java.awt.event.MouseEvent) JXImageView(org.jdesktop.swingx.JXImageView) Painter(org.jdesktop.swingx.painter.Painter) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) FocusEvent(java.awt.event.FocusEvent) BufferedImage(java.awt.image.BufferedImage)

Example 25 with FocusAdapter

use of java.awt.event.FocusAdapter in project adempiere by adempiere.

the class ADempiereAutoCompleteDecorator method decorate.

/**
     * Decorates a given text component for automatic completion using the
     * given AutoCompleteDocument and AbstractAutoCompleteAdaptor.
     * 
     * 
     * @param textComponent a text component that should be decorated
     * @param document the AutoCompleteDocument to be installed on the text component
     * @param adaptor the AbstractAutoCompleteAdaptor to be used
     */
public static void decorate(JTextComponent textComponent, AutoCompleteDocument document, final AbstractAutoCompleteAdaptor adaptor) {
    // install the document on the text component
    textComponent.setDocument(document);
    // mark entire text when the text component gains focus
    // otherwise the last mark would have been retained which is quiet confusing
    textComponent.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            JTextComponent textComponent = (JTextComponent) e.getSource();
            adaptor.markEntireText();
        }
    });
    // Tweak some key bindings
    InputMap editorInputMap = textComponent.getInputMap();
    if (document.isStrictMatching()) {
        // move the selection to the left on VK_BACK_SPACE
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), DefaultEditorKit.selectionBackwardAction);
        // ignore VK_DELETE and CTRL+VK_X and beep instead when strict matching
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0), errorFeedbackAction);
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_DOWN_MASK), errorFeedbackAction);
    } else {
        ActionMap editorActionMap = textComponent.getActionMap();
        // leave VK_DELETE and CTRL+VK_X as is
        // VK_BACKSPACE will move the selection to the left if the selected item is in the list
        // it will delete the previous character otherwise
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), "nonstrict-backspace");
        editorActionMap.put("nonstrict-backspace", new NonStrictBackspaceAction(editorActionMap.get(DefaultEditorKit.deletePrevCharAction), editorActionMap.get(DefaultEditorKit.selectionBackwardAction), adaptor));
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_TAB, java.awt.event.KeyEvent.CTRL_DOWN_MASK), "NextMatchAction");
        editorActionMap.put("NextMatchAction", new NextMatchAction(textComponent, document, adaptor));
    }
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) ActionMap(javax.swing.ActionMap) JTextComponent(javax.swing.text.JTextComponent) InputMap(javax.swing.InputMap) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusAdapter (java.awt.event.FocusAdapter)33 FocusEvent (java.awt.event.FocusEvent)33 JLabel (javax.swing.JLabel)11 JTextField (javax.swing.JTextField)10 Dimension (java.awt.Dimension)8 JPanel (javax.swing.JPanel)7 KeyAdapter (java.awt.event.KeyAdapter)5 KeyEvent (java.awt.event.KeyEvent)5 BoxLayout (javax.swing.BoxLayout)4 JButton (javax.swing.JButton)4 JCheckBox (javax.swing.JCheckBox)4 FlowLayout (java.awt.FlowLayout)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 FocusListener (java.awt.event.FocusListener)3 Box (javax.swing.Box)3 BorderLayout (java.awt.BorderLayout)2 Container (java.awt.Container)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2