Search in sources :

Example 26 with FocusEvent

use of java.awt.event.FocusEvent in project jgnash by ccavanaugh.

the class SellSharePanel method registerListeners.

private void registerListeners() {
    FocusListener focusListener = new FocusAdapter() {

        @Override
        public void focusLost(final FocusEvent evt) {
            updateTotalField();
        }
    };
    feePanel.addFocusListener(focusListener);
    feePanel.addActionListener(this);
    gainsPanel.addActionListener(this);
    quantityField.addFocusListener(focusListener);
    priceField.addFocusListener(focusListener);
    datePanel.getDateField().addKeyListener(keyListener);
    feePanel.addKeyListener(keyListener);
    memoField.addKeyListener(keyListener);
    priceField.addKeyListener(keyListener);
    quantityField.addKeyListener(keyListener);
    securityCombo.addKeyListener(keyListener);
    getReconcileCheckBox().addKeyListener(keyListener);
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 27 with FocusEvent

use of java.awt.event.FocusEvent in project gephi by gephi.

the class DirectoryChooserUI method createBottomPanel.

private void createBottomPanel(JFileChooser fc) {
    bottomPanel = new JPanel();
    bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
    JPanel labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.PAGE_AXIS));
    labelPanel.add(Box.createRigidArea(verticalStrut1));
    JLabel fnl = new JLabel(fileNameLabelText);
    fnl.setDisplayedMnemonic(fileNameLabelMnemonic);
    fnl.setAlignmentY(0);
    labelPanel.add(fnl);
    labelPanel.add(Box.createRigidArea(new Dimension(1, 12)));
    JLabel ftl = new JLabel(filesOfTypeLabelText);
    ftl.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
    labelPanel.add(ftl);
    bottomPanel.add(labelPanel);
    bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
    JPanel fileAndFilterPanel = new JPanel();
    fileAndFilterPanel.add(Box.createRigidArea(verticalStrut3));
    fileAndFilterPanel.setLayout(new BoxLayout(fileAndFilterPanel, BoxLayout.Y_AXIS));
    filenameTextField = new JTextField(24) {

        @Override
        public Dimension getMaximumSize() {
            return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
        }
    };
    filenameTextField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateCompletions();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateCompletions();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    filenameTextField.addKeyListener(new TextFieldKeyListener());
    fnl.setLabelFor(filenameTextField);
    filenameTextField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            if (!getFileChooser().isMultiSelectionEnabled()) {
                tree.clearSelection();
            }
        }
    });
    // disable TAB focus transfer, we need it for completion
    Set<AWTKeyStroke> tKeys = filenameTextField.getFocusTraversalKeys(java.awt.KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    Set<AWTKeyStroke> newTKeys = new HashSet<AWTKeyStroke>(tKeys);
    newTKeys.remove(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
    // #107305: enable at least Ctrl+TAB if we have TAB for completion
    newTKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK));
    filenameTextField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newTKeys);
    fileAndFilterPanel.add(filenameTextField);
    fileAndFilterPanel.add(Box.createRigidArea(verticalStrut3));
    filterTypeComboBoxModel = createFilterComboBoxModel();
    fc.addPropertyChangeListener(filterTypeComboBoxModel);
    filterTypeComboBox = new JComboBox(filterTypeComboBoxModel);
    ftl.setLabelFor(filterTypeComboBox);
    filterTypeComboBox.setRenderer(createFilterComboBoxRenderer());
    fileAndFilterPanel.add(filterTypeComboBox);
    bottomPanel.add(fileAndFilterPanel);
    bottomPanel.add(Box.createRigidArea(horizontalStrut1));
    createButtonsPanel(fc);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) FocusAdapter(java.awt.event.FocusAdapter) DocumentEvent(javax.swing.event.DocumentEvent) FocusEvent(java.awt.event.FocusEvent)

Example 28 with FocusEvent

use of java.awt.event.FocusEvent in project OpenNotebook by jaltekruse.

the class StringAdjustmentPanel method addPanelContent.

@Override
public void addPanelContent() {
    // to prevent the panel from looking too small, estimate the amount of lines needed to
    // show all of the text
    int numLines = 0;
    if (getGraphics() != null) {
        // one of these panels is constructed in the background to initialize some resources
        // at that time there is no graphics object to reference to measure text 
        numLines = getGraphics().getFontMetrics().stringWidth(mAtt.getValue()) / 120;
    } else {
        numLines = mAtt.getValue().length() / 20;
    }
    if (numLines < 2) {
        numLines = 2;
    }
    textArea = new JTextArea(numLines, 12);
    textArea.setEditable(true);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setText(mAtt.getValue());
    textArea.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent arg0) {
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            applyPanelValueToObject();
        }
    });
    // need to decide if having this panel set with the enter key is worth
    // not being able to include line breaks
    textArea.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent ev) {
            if (ev.getKeyCode() == KeyEvent.VK_ENTER) {
                applyPanelValueToObject();
                enterJustPressed = true;
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_ENTER && enterJustPressed) {
                // had issue with hitting enter to confirm dialog, dialog disappeared but enter key release event
                // was still received here if an object was selected, hence the boolean set in the keypressed
                // method and checked here
                String s = textArea.getText();
                int caretPos = textArea.getCaretPosition() - 1;
                s = s.substring(0, textArea.getCaretPosition() - 1) + s.substring(textArea.getCaretPosition());
                textArea.setText(s);
                textArea.setCaretPosition(caretPos);
                enterJustPressed = false;
            }
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
        }
    });
    setLayout(new GridBagLayout());
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.HORIZONTAL;
    con.weightx = .5;
    con.gridx = 0;
    con.gridwidth = 1;
    con.gridy = 0;
    con.insets = new Insets(2, 5, 0, 5);
    add(new JLabel(mAtt.getName()), con);
    JButton keyboard = new JButton(ObjectPropertiesFrame.SMALL_KEYBOARD_IMAGE);
    keyboard.setToolTipText("Show On-Screen Keyboard");
    keyboard.setMargin(new Insets(3, 3, 3, 3));
    keyboard.setFocusable(false);
    con.insets = new Insets(2, 2, 2, 2);
    con.gridx = 1;
    con.weightx = .1;
    con.weighty = .1;
    con.gridheight = 1;
    add(keyboard, con);
    keyboard.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            notebookPanel.getCurrentDocViewer().setOnScreenKeyBoardVisible(true);
        }
    });
    JButton applyChanges = new JButton("Apply");
    applyChanges.setToolTipText("Value can also be applied by hitting Enter");
    applyChanges.setMargin(new Insets(5, 3, 5, 3));
    applyChanges.setFocusable(false);
    con.gridx = 2;
    con.weightx = .1;
    con.weighty = .1;
    con.gridheight = 1;
    add(applyChanges, con);
    applyChanges.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            applyPanelValueToObject();
        }
    });
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;
    con.weighty = 1;
    con.gridwidth = 3;
    con.gridy = 1;
    con.gridx = 0;
    con.gridheight = 3;
    scrollPane = new JScrollPane(textArea);
    scrollPane.setWheelScrollingEnabled(false);
    con.insets = new Insets(0, 5, 2, 0);
    add(scrollPane, con);
    scrollPane.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            Point componentPoint = SwingUtilities.convertPoint(scrollPane, e.getPoint(), parentPanel);
            parentPanel.dispatchEvent(new MouseWheelEvent(parentPanel, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation()));
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) MouseWheelListener(java.awt.event.MouseWheelListener) Point(java.awt.Point) FocusEvent(java.awt.event.FocusEvent) Point(java.awt.Point) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) MouseWheelEvent(java.awt.event.MouseWheelEvent) KeyListener(java.awt.event.KeyListener) FocusListener(java.awt.event.FocusListener)

Example 29 with FocusEvent

use of java.awt.event.FocusEvent in project jna by java-native-access.

the class BalloonTipManager method getBalloonTip.

/**
   * Returns the popup window of the balloon tip.
   * @param owner the owner component for the balloon tip
   * @param content the text string to display in the balloon tip
   * @param x the x coordinate for the origin for the balloon tip in relation
   * to the owner component
   * @param y the y coordinate for the origin for the balloon tip in relation
   * to the owner component
   * @param position the position for the balloon; either above or below the
     * owner component
   * @param duration the duration in milliseconds to display balloon tip
   * @param bordercolor the background color for the balloon tip
   * @param backgroundcolor the border color for the balloon tip
   * @param textcolor the text color for the balloon tip
   * @return the popup window of the balloon tip
   */
public static Popup getBalloonTip(final Component owner, final String content, int x, int y, final Integer duration, final Color bordercolor, final Color backgroundcolor, final Color textcolor) {
    final Point origin = owner == null ? new Point(0, 0) : owner.getLocationOnScreen();
    final Window parent = owner != null ? SwingUtilities.getWindowAncestor(owner) : null;
    final String text = content != null ? content : "";
    final Integer timerDuration = duration != null ? duration : 10000;
    origin.translate(x, y);
    vpos = VPOS_BELOW;
    hpos = HPOS_LEFT;
    return new Popup() {

        private BalloonTip bt = null;

        final ComponentEar componentEar = new ComponentEar();

        final MouseEar mouseEar = new MouseEar();

        final FocusEar focusEar = new FocusEar();

        /*
       * (non-Javadoc)
       * @see javax.swing.Popup#show()
       */
        public void show() {
            hidePopupTimer = new Timer(timerDuration, new TimerAction());
            bt = new BalloonTip(parent, text, origin, bordercolor, backgroundcolor, textcolor);
            bt.pack();
            Point pt = new Point(origin);
            pt.translate(10, owner.getHeight());
            bt.setLocation(getAdjustedOrigin(pt));
            bt.setWindowMask();
            bt.setVisible(true);
            owner.addFocusListener(focusEar);
            owner.addMouseListener(mouseEar);
            parent.addMouseListener(mouseEar);
            parent.addComponentListener(componentEar);
            hidePopupTimer.start();
            isShowing = true;
        }

        /*
       * (non-Javadoc)
       * @see javax.swing.Popup#hide()
       */
        public void hide() {
            if (bt != null) {
                isShowing = false;
                hidePopupTimer.stop();
                parent.removeComponentListener(componentEar);
                parent.removeMouseListener(mouseEar);
                owner.removeMouseListener(mouseEar);
                owner.removeFocusListener(focusEar);
                bt.setVisible(false);
                bt.dispose();
            }
        }

        /*
       * Adjust the location of the balloon popup so that is drawn completely
       * on the screen and specify the orientation.
       */
        private Point getAdjustedOrigin(Point pt) {
            Point ret = new Point(pt.x, pt.y);
            GraphicsConfiguration gc = owner.getGraphicsConfiguration();
            Rectangle sBounds = gc.getBounds();
            Insets sInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
            sBounds.x += sInsets.left;
            sBounds.y += sInsets.top;
            sBounds.width -= (sInsets.left + sInsets.right);
            sBounds.height -= (sInsets.top + sInsets.bottom);
            if (ret.x < sBounds.x) {
                ret.x = sBounds.x;
            } else if (ret.x - sBounds.x + bt.getWidth() > sBounds.width) {
                ret.x = owner.getLocationOnScreen().x - bt.getWidth() + 43;
            }
            if (ret.x >= pt.x) {
                hpos = HPOS_LEFT;
            } else {
                hpos = HPOS_RIGHT;
            }
            if (ret.y < sBounds.y) {
                ret.y = sBounds.y;
            } else if (ret.y - sBounds.y + bt.getHeight() > sBounds.height) {
                ret.y = owner.getLocationOnScreen().y - bt.getHeight();
            }
            if (ret.y >= pt.y) {
                vpos = VPOS_BELOW;
            } else {
                vpos = VPOS_ABOVE;
            }
            return ret;
        }

        /*
       * This class handles actions from the balloon tip timer.
       */
        @SuppressWarnings("serial")
        final class TimerAction extends AbstractAction {

            /*
         * (non-Javadoc)
         * @see java.awt.event.ActionListener#actionPerformed(
         * java.awt.event.ActionEvent)
         */
            public void actionPerformed(ActionEvent e) {
                hide();
            }
        }

        /*
       * This class handles events spawned from moving the component.
       */
        final class ComponentEar extends ComponentAdapter {

            /*
         * (non-Javadoc)
         * @see java.awt.event.ComponentAdapter#componentMoved(
         * java.awt.event.ComponentEvent)
         */
            public void componentMoved(ComponentEvent e) {
                hide();
            }
        }

        /*
       * This class handles events spawned when a mouse button is pressed.
       */
        final class MouseEar extends MouseAdapter {

            /*
         * (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(
         * java.awt.event.MouseEvent)
         */
            public void mousePressed(MouseEvent e) {
                hide();
            }
        }

        /*
       * This class handles events spawned when the component loses focus.
       */
        final class FocusEar extends FocusAdapter {

            /*
         * (non-Javadoc)
         * @see java.awt.event.FocusAdapter#focusLost(
         * java.awt.event.FocusEvent)
         */
            public void focusLost(FocusEvent e) {
                hide();
            }
        }
    };
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) Rectangle(java.awt.Rectangle) Point(java.awt.Point) FocusEvent(java.awt.event.FocusEvent) GraphicsConfiguration(java.awt.GraphicsConfiguration) Timer(javax.swing.Timer) Popup(javax.swing.Popup) ComponentEvent(java.awt.event.ComponentEvent)

Example 30 with FocusEvent

use of java.awt.event.FocusEvent 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)

Aggregations

FocusEvent (java.awt.event.FocusEvent)68 FocusListener (java.awt.event.FocusListener)32 FocusAdapter (java.awt.event.FocusAdapter)26 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)14 JLabel (javax.swing.JLabel)12 Dimension (java.awt.Dimension)8 KeyEvent (java.awt.event.KeyEvent)8 JButton (javax.swing.JButton)8 JPanel (javax.swing.JPanel)8 JTextField (javax.swing.JTextField)8 Border (javax.swing.border.Border)8 UIResource (javax.swing.plaf.UIResource)6 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 Insets (java.awt.Insets)5 KeyAdapter (java.awt.event.KeyAdapter)5 MouseEvent (java.awt.event.MouseEvent)5 JComboBox (javax.swing.JComboBox)5 Component (java.awt.Component)4