Example usage for java.awt.event FocusAdapter FocusAdapter

List of usage examples for java.awt.event FocusAdapter FocusAdapter

Introduction

In this page you can find the example usage for java.awt.event FocusAdapter FocusAdapter.

Prototype

FocusAdapter

Source Link

Usage

From source file:com.googlecode.vfsjfilechooser2.accessories.connection.ConnectionDialog.java

private void initListeners() {
    this.portTextField.addKeyListener(new KeyAdapter() {
        @Override//from   ww  w. j av  a 2 s  . c om
        public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();

            if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) {
                getToolkit().beep();
                e.consume();
            } else {
                setPortTextFieldDirty(true);
            }
        }
    });

    this.portTextField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            JFormattedTextField f = (JFormattedTextField) e.getSource();
            String text = f.getText();

            if (text.length() == 0) {
                f.setValue(null);
            }

            try {
                f.commitEdit();
            } catch (ParseException exc) {
            }
        }
    });

    this.cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (currentWorker != null) {
                if (currentWorker.isAlive()) {
                    currentWorker.interrupt();
                    setCursor(Cursor.getDefaultCursor());
                }
            }

            setVisible(false);
        }
    });

    this.connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            currentWorker = new Thread() {
                @Override
                public void run() {
                    StringBuilder error = new StringBuilder();
                    FileObject fo = null;

                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    try {
                        String m_username = usernameTextField.getText();
                        String m_defaultRemotePath = defaultRemotePathTextField.getText();
                        char[] m_password = passwordTextField.getPassword();
                        String m_hostname = hostnameTextField.getText();
                        String m_protocol = protocolList.getSelectedItem().toString();

                        int m_port = -1;

                        if (portTextField.isEditValid() && (portTextField.getValue() != null)) {
                            String s = portTextField.getValue().toString();
                            m_port = Integer.valueOf(s);
                        }

                        Builder credentialsBuilder = Credentials.newBuilder(m_hostname)
                                .defaultRemotePath(m_defaultRemotePath).username(m_username)
                                .password(m_password).protocol(m_protocol).port(m_port);

                        Credentials credentials = credentialsBuilder.build();

                        String uri = credentials.toFileObjectURL();

                        if (isInterrupted()) {
                            setPortTextFieldDirty(false);

                            return;
                        }

                        fo = VFSUtils.resolveFileObject(uri);

                        if ((fo != null) && !fo.exists()) {
                            fo = null;
                        }
                    } catch (Exception err) {
                        error.append(err.getMessage());
                        setCursor(Cursor.getDefaultCursor());
                    }

                    if ((error.length() > 0) || (fo == null)) {
                        error.delete(0, error.length());
                        error.append("Failed to connect!");
                        error.append("\n");
                        error.append("Please check parameters and try again.");

                        JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error",
                                JOptionPane.ERROR_MESSAGE);
                        setCursor(Cursor.getDefaultCursor());

                        return;
                    }

                    if (isInterrupted()) {
                        return;
                    }

                    fileChooser.setCurrentDirectoryObject(fo);

                    setCursor(Cursor.getDefaultCursor());

                    resetFields();

                    if (bookmarksDialog != null) {
                        String bTitle = fo.getName().getBaseName();

                        if (bTitle.trim().equals("")) {
                            bTitle = fo.getName().toString();
                        }

                        String bURL = fo.getName().getURI();
                        bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL));
                        bookmarksDialog.getBookmarks().save();
                    }

                    setVisible(false);
                }
            };

            currentWorker.setPriority(Thread.MIN_PRIORITY);
            currentWorker.start();
        }
    });

    // add the usual right click popup menu(copy, paste, etc.)
    PopupHandler.installDefaultMouseListener(hostnameTextField);
    PopupHandler.installDefaultMouseListener(portTextField);
    PopupHandler.installDefaultMouseListener(usernameTextField);
    PopupHandler.installDefaultMouseListener(passwordTextField);
    PopupHandler.installDefaultMouseListener(defaultRemotePathTextField);

    this.protocolList.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectPortNumber();
            }
        }
    });

    this.protocolList.setSelectedItem(Protocol.FTP);
}

From source file:edu.ku.brc.specify.config.init.TaxonLoadSetupPanel.java

/**
 * Creates a dialog for entering database name and selecting the appropriate driver.
 *//*  w  w w.j a  v a2  s . c o  m*/
public TaxonLoadSetupPanel(final String helpContext, final JButton nextBtn, final JButton prevBtn) {
    super("PRELOADTXN", helpContext, nextBtn, prevBtn);

    String header = getResourceString("PRELOADTXN_INFO");

    CellConstraints cc = new CellConstraints();

    String rowDef = "p,10px," + createDuplicateJGoodiesDef("p", "2px", 8) + ",p:g";
    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p:g", rowDef), this);
    int row = 1;

    stdSep = builder.add(createLabel(header, SwingConstants.CENTER), cc.xywh(1, row, 3, 1));
    row += 2;

    fileCBX = createComboBox();
    srcTF = createTextField("");
    coverageTF = createTextField("");
    descTA = createTextArea();
    otherBrw = new ValBrowseBtnPanel(otherTF = new ValTextField(), false, true);
    otherBrw.setUseNativeFileDlg(true);

    descTA.setEditable(false);
    descTA.setColumns(30);
    descTA.setRows(5);
    descTA.setWrapStyleWord(true);
    descTA.setLineWrap(true);

    ViewFactory.changeTextFieldUIForDisplay(srcTF, false);
    ViewFactory.changeTextFieldUIForDisplay(coverageTF, false);

    builder.add(preloadChk = createI18NCheckBox("TFD_LOAD_TAXON"), cc.xy(1, row));
    row += 2;

    builder.addSeparator(UIRegistry.getResourceString("TFD_SEP_STD"), cc.xyw(1, row, 3));
    row += 2;

    builder.add(fileLbl = createI18NFormLabel("TFD_FILE_LBL"), cc.xy(1, row));
    builder.add(fileCBX, cc.xy(3, row));
    row += 2;

    builder.add(srcLbl = createI18NFormLabel("TFD_SRC_LBL"), cc.xy(1, row));
    builder.add(srcTF, cc.xy(3, row));
    row += 2;

    builder.add(coverageLbl = createI18NFormLabel("TFD_CVRG_LBL"), cc.xy(1, row));
    builder.add(coverageTF, cc.xy(3, row));
    row += 2;

    builder.add(descLbl = createI18NFormLabel("TFD_DESC_LBL"), cc.xy(1, row));
    builder.add(createScrollPane(descTA), cc.xy(3, row));
    row += 2;

    //othSep = builder.addSeparator(UIRegistry.getResourceString("TFD_SEP_OTH"), cc.xyw(1, row, 3));
    row += 2;

    //builder.add(otherLbl = createI18NFormLabel("TFD_OTHER_LBL"), cc.xy(1, row));
    //builder.add(otherBrw,        cc.xy(3, row));
    row += 2;

    updateBtnUI();

    otherTF.getDocument().addDocumentListener(new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent e) {
            updateBtnUI();
        }
    });

    preloadChk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean checked = preloadChk.isSelected();
            if (checked) {
                if (fileCBX.getModel().getSize() > 0 && fileCBX.getSelectedIndex() == -1) {
                    fileCBX.setSelectedIndex(0);
                }
                enableUI(otherTF.getText().isEmpty(), true, true);

            } else {
                enableUI(false, true, false);
            }
        }
    });

    otherTF.addFocusListener(new FocusAdapter() {

        /* (non-Javadoc)
         * @see java.awt.event.FocusAdapter#focusLost(java.awt.event.FocusEvent)
         */
        @Override
        public void focusLost(FocusEvent e) {
            updateBtnUI();
        }

    });

    otherBrw.setNativeDlgFilter(new FilenameFilter() {

        /* (non-Javadoc)
         * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
         */
        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(XLS);
        }
    });
}

From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java

private JTextField createSetsTextField() {
    final JTextField textField = new JTextField(30);

    textField.addFocusListener(new FocusAdapter() {
        @Override/*w  w  w  .  j a v  a2s.c  om*/
        public void focusGained(FocusEvent e) {
            e.getOppositeComponent().requestFocus();

            // get the frame the panel is embedded in
            Component currentComponent = HarvesterPanel.this;
            while (currentComponent.getParent() != null && !(currentComponent instanceof JFrame)) {
                currentComponent = currentComponent.getParent();
            }
            final JFrame parentFrame = currentComponent instanceof JFrame ? (JFrame) currentComponent : null;

            if (HarvesterPanel.this.availableSets == null) {
                LocalizedOptionPane.showMessageDialog(parentFrame, "No_setnames_retrieved",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            String[] selectedSets = textField.getText().split(","); //$NON-NLS-1$

            for (int i = 0; i < selectedSets.length; i++) {
                selectedSets[i] = selectedSets[i].trim();
            }

            SetSelectionWindow ssw = new SetSelectionWindow(parentFrame, HarvesterPanel.this.availableSets,
                    selectedSets);
            ssw.setVisible(true);

            textField.setText(StringUtils.join(ssw.getSelectedSets(), ", "));
        }
    });

    return textField;
}

From source file:tvbrowser.extras.favoritesplugin.wizards.TypeWizardStep.java

public JPanel createContent(final WizardHandler handler) {

    LinkButton expertBtn = new LinkButton(mLocalizer.msg("advancedView", "Switch to expert view"), null);

    CellConstraints cc = new CellConstraints();
    PanelBuilder panelBuilder = new PanelBuilder(
            new FormLayout("5dlu, pref, default:grow", "pref, 5dlu, pref, 5dlu, pref, 5dlu, pref, 5dlu, pref"));

    panelBuilder.add(new JLabel(mMainQuestion), cc.xyw(1, 1, 3));
    panelBuilder.add(mTitleRb = new JRadioButton(mLocalizer.msg("option.title", "I like this program:")),
            cc.xy(2, 3));//from   w  w w  .  j  ava  2s. co m
    panelBuilder.add(mProgramNameTf = new JTextField(), cc.xy(3, 3));
    panelBuilder.add(mTopicRb = new JRadioButton(mLocalizer.msg("option.topic", "I like this subject:")),
            cc.xy(2, 5));
    panelBuilder.add(mTopicTf = new JTextField(), cc.xy(3, 5));

    panelBuilder.add(mActorsRb = new JRadioButton(mLocalizer.msg("option.actors", "I like these actors:")),
            cc.xy(2, 7));
    mActorsCb = new JComboBox();
    mActorsCb.setEditable(true);
    panelBuilder.add(mActorsCb, cc.xy(3, 7));
    panelBuilder.setBorder(Borders.DLU4_BORDER);
    panelBuilder.add(expertBtn, cc.xyw(1, 9, 3));
    ButtonGroup group = new ButtonGroup();
    group.add(mTitleRb);
    group.add(mTopicRb);
    group.add(mActorsRb);

    mTitleRb.setSelected(true);

    updateTextfields();

    mTitleRb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateTextfields();
        }
    });

    mTopicRb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateTextfields();
        }
    });

    mActorsRb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateTextfields();
        }
    });

    expertBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handler.closeCurrentStep();
            String title;
            if (mProgram != null) {
                title = mProgram.getTitle();
            } else {
                title = "";
            }
            AdvancedFavorite favorite = new AdvancedFavorite(title);
            Window parent = UiUtilities.getLastModalChildOf(MainFrame.getInstance());
            EditFavoriteDialog dlg = new EditFavoriteDialog(parent, favorite);
            UiUtilities.centerAndShow(dlg);
            if (dlg.getOkWasPressed()) {
                FavoriteTreeModel.getInstance().addFavorite(favorite, mParentNode);
                FavoritesPlugin.getInstance().updateRootNode(true);

                if (ManageFavoritesDialog.getInstance() != null) {
                    ManageFavoritesDialog.getInstance().addFavorite(favorite, false);
                }
            }
        }
    });

    if (mProgram != null) {
        mProgramNameTf.setText(mProgram.getTitle());
        String[] actors = ProgramUtilities.getActorNames(mProgram);
        if (actors != null) {
            for (String actor : actors) {
                mActorsCb.addItem(actor);
            }
        }
    }

    mContent = panelBuilder.getPanel();

    mContent.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            handleFocusEvent();
        }
    });

    mContent.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            handleFocusEvent();
        }
    });

    if (mTopic != null) {
        mTopicRb.setSelected(true);
        updateTextfields();
        mTopicTf.setText(mTopic);
        // the topic might also be an actor name
        if (mActor == null && ProgramUtilities.getActorNames(mProgram) == null) {
            mActorsCb.setSelectedItem(mTopic);
        }
    } else if (mActor != null) {
        mActorsRb.setSelected(true);
        updateTextfields();
        mActorsCb.setSelectedItem(mActor);
    }

    return mContent;
}

From source file:org.kalypso.ui.editor.mapeditor.AbstractMapPart.java

@Override
public synchronized void createPartControl(final Composite parent) {
    final IWorkbenchPartSite site = getSite();

    m_control = MapForm.createMapForm(parent);
    m_mapPanel = m_control.createMapPanel(this, m_selectionManager);

    updatePanel(m_mapModell, m_initialEnv);
    m_mapPanel.addMapPanelListener(m_mapPanelListener);

    final MapPanelSourceProvider sourceProvider = new MapPanelSourceProvider(site, m_mapPanel);
    setSourceProvider(sourceProvider);//from ww  w  .  j ava  2  s .co m

    // REMARK: important: the map panel (awt) never gets the focus now. This fixes the following strange behavior,
    // - click into map
    // - click into other view -> view gets activated
    // - again click into map and than into other view -> view does not get activated, only the clicked control gets the focus.

    // Actually playing with focus and view activation did not solve this problem.

    // SOLUTION: is now: we keep the focus in our swt control and translate all swt key/mousewheel event manually to awt events
    // This will lead probably to some effects with the key events (so far testing did not show any strange behavior).
    // so TODO: the map-widgets should directly work with swt events instead; next step would be to incorporate the translation code
    // into the widget manager itself for backwards compatibility (i.e. introduce a new widget interface and make the old one deprecated).
    if (m_mapPanel instanceof MapPanel) {
        final MapPanel mapPanelComponent = (MapPanel) m_mapPanel;
        mapPanelComponent.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(final java.awt.event.FocusEvent e) {
                handleFocuesGained();
            }
        });

        m_control.addMouseWheelListener(new MapSwtWheelAdapter(mapPanelComponent));
        m_control.addKeyListener(new MapSwtKeyAdapter(mapPanelComponent));
    }

    // HACK: at the moment views never have a menu... maybe we could get the information,
    // if a context menu is desired from the defining extension
    if (this instanceof IEditorPart) {
        final MenuManager contextMenu = MapPartHelper.createMapContextMenu(m_control.getBody(), m_mapPanel,
                site);
        ((IEditorSite) site).registerContextMenu(contextMenu, m_mapPanel, false);
    }

    site.setSelectionProvider(m_mapPanel);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopSearchField.java

public DesktopSearchField() {
    composition = new JPanel();
    composition.setLayout(new BorderLayout());
    composition.setFocusable(false);/*from   ww  w.  ja v  a2  s .co  m*/

    comboBox = new SearchComboBox() {
        @Override
        public void setPopupVisible(boolean v) {
            if (!items.isEmpty()) {
                super.setPopupVisible(v);
            } else if (!v) {
                super.setPopupVisible(false);
            }
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (SearchAutoCompleteSupport.SEARCH_ENTER_COMMAND.equals(e.getActionCommand())) {
                enterHandling = true;
            }

            super.actionPerformed(e);
        }
    };
    comboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (settingValue || disableActionListener)
                return;

            if ("comboBoxEdited".equals(e.getActionCommand())) {
                Object selectedItem = comboBox.getSelectedItem();

                if (popupItemSelectionHandling) {
                    if (selectedItem instanceof ValueWrapper) {
                        Object selectedValue = ((ValueWrapper) selectedItem).getValue();
                        setValue(selectedValue);
                        updateOptionsDsItem();
                    } else if (selectedItem instanceof String) {
                        handleSearch((String) selectedItem);
                    }
                    popupItemSelectionHandling = false;
                } else if (enterHandling) {
                    if (selectedItem instanceof String) {
                        boolean found = false;
                        String newFilter = (String) selectedItem;
                        if (prevValue != null) {
                            if (Objects.equals(getDisplayString((Entity) prevValue), newFilter)) {
                                found = true;
                            }
                        }
                        if (!found) {
                            handleSearch(newFilter);
                        } else {
                            updateComponent(prevValue);
                            clearSearchVariants();
                        }
                    } else {
                        // Disable variants after select
                        clearSearchVariants();
                    }
                    enterHandling = false;
                }
            }

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    updateEditState();
                }
            });
        }
    });

    Component editorComponent = comboBox.getEditor().getEditorComponent();
    editorComponent.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    updateEditState();
                }
            });
        }
    });

    comboBox.setEditable(true);
    comboBox.setPrototypeDisplayValue("AAAAAAAAAAAA");
    autoComplete = SearchAutoCompleteSupport.install(comboBox, items);
    autoComplete.setFilterEnabled(false);

    for (int i = 0; i < comboBox.getComponentCount(); i++) {
        java.awt.Component component = comboBox.getComponent(i);
        component.addFocusListener(new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
                clearSearchVariants();
                // Reset invalid value

                checkSelectedValue();
            }
        });
    }
    // set value only on PopupMenu closing to avoid firing listeners on keyboard navigation
    comboBox.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            comboBox.updatePopupWidth();
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            if (!autoComplete.isEditableState()) {
                // Only if realy item changed
                if (!enterHandling) {
                    Object selectedItem = comboBox.getSelectedItem();
                    if (selectedItem instanceof ValueWrapper) {
                        Object selectedValue = ((ValueWrapper) selectedItem).getValue();
                        setValue(selectedValue);
                        updateOptionsDsItem();
                    } else if (selectedItem instanceof String) {
                        handleSearch((String) selectedItem);
                    }
                } else {
                    popupItemSelectionHandling = true;
                }

                updateMissingValueState();
            }
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            clearSearchVariants();
        }
    });

    setFilterMode(DEFAULT_FILTER_MODE);

    textField = new JTextField();
    textField.setEditable(false);
    UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
    valueFormatter = new DefaultValueFormatter(sessionSource.getLocale());

    composition.add(comboBox, BorderLayout.CENTER);
    impl = comboBox;

    DesktopComponentsHelper.adjustSize(comboBox);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopSuggestionField.java

public DesktopSuggestionField() {
    composition = new JPanel();
    composition.setLayout(new BorderLayout());
    composition.setFocusable(false);//from w w  w .j av  a2 s  . c  o  m

    comboBox = new SearchComboBox() {
        @Override
        public void setPopupVisible(boolean v) {
            if (!items.isEmpty()) {
                super.setPopupVisible(v);
            } else if (!v) {
                super.setPopupVisible(false);
            }
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (SearchAutoCompleteSupport.SEARCH_ENTER_COMMAND.equals(e.getActionCommand())) {
                enterHandling = true;
            }

            super.actionPerformed(e);
        }
    };

    comboBox.addActionListener(e -> {
        if (settingValue || disableActionListener) {
            return;
        }

        if ("comboBoxEdited".equals(e.getActionCommand())) {
            Object selectedItem = comboBox.getSelectedItem();

            if (popupItemSelectionHandling) {
                if (selectedItem instanceof ValueWrapper) {
                    Object selectedValue = ((ValueWrapper) selectedItem).getValue();
                    setValue(selectedValue);
                }
            } else if (enterHandling) {
                if (selectedItem instanceof String) {
                    boolean found = false;
                    String newFilter = (String) selectedItem;
                    if (prevValue != null) {
                        if (Objects.equals(getDisplayString(prevValue), newFilter)) {
                            found = true;
                        }
                    }

                    final boolean searchStringEqualsToCurrentValue = found;
                    // we need to do it later
                    // unable to change current text from ActionListener
                    SwingUtilities.invokeLater(() -> {
                        updateComponent(prevValue);

                        if (!searchStringEqualsToCurrentValue) {
                            handleOnEnterAction(((String) selectedItem));
                        }
                    });
                } else if (currentSearchComponentText != null) {
                    // Disable variants after select
                    final String enterActionString = currentSearchComponentText;
                    SwingUtilities.invokeLater(() -> {
                        updateComponent(prevValue);

                        handleOnEnterAction(enterActionString);
                    });

                    currentSearchComponentText = null;
                }
            }

            clearSearchVariants();

            popupItemSelectionHandling = false;
            enterHandling = false;
        }

        SwingUtilities.invokeLater(this::updateEditState);
    });

    Component editorComponent = comboBox.getEditor().getEditorComponent();
    editorComponent.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            SwingUtilities.invokeLater(() -> {
                updateEditState();

                if (e.getKeyChar() != '\n') {
                    handleSearchInput();
                }
            });
        }

        @Override
        public void keyPressed(KeyEvent e) {
            SwingUtilities.invokeLater(() -> {
                if (e.getKeyCode() == KeyEvent.VK_DOWN && arrowDownActionHandler != null
                        && !comboBox.isPopupVisible()) {
                    arrowDownActionHandler.onArrowDownKeyPressed(getComboBoxEditorField().getText());
                }
            });
        }
    });

    comboBox.setEditable(true);
    comboBox.setPrototypeDisplayValue("AAAAAAAAAAAA");

    autoComplete = SearchAutoCompleteSupport.install(comboBox, items);
    autoComplete.setFilterEnabled(false);

    for (int i = 0; i < comboBox.getComponentCount(); i++) {
        Component component = comboBox.getComponent(i);
        component.addFocusListener(new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
                clearSearchVariants();
                // Reset invalid value

                checkSelectedValue();
            }
        });
    }

    final JTextField searchEditorComponent = getComboBoxEditorField();
    searchEditorComponent.addActionListener(e -> currentSearchComponentText = searchEditorComponent.getText());

    // set value only on PopupMenu closing to avoid firing listeners on keyboard navigation
    comboBox.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            comboBox.updatePopupWidth();
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            if (!autoComplete.isEditableState()) {
                popupItemSelectionHandling = comboBox.getSelectedIndex() >= 0;

                // Only if really item changed
                if (!enterHandling) {
                    Object selectedItem = comboBox.getSelectedItem();
                    if (selectedItem instanceof ValueWrapper) {
                        Object selectedValue = ((ValueWrapper) selectedItem).getValue();
                        setValue(selectedValue);

                        clearSearchVariants();
                    }
                }

                updateMissingValueState();
            }
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            clearSearchVariants();
        }
    });

    textField = new JTextField();
    textField.setEditable(false);
    UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
    valueFormatter = new DefaultValueFormatter(sessionSource.getLocale());

    composition.add(comboBox, BorderLayout.CENTER);
    impl = comboBox;

    DesktopComponentsHelper.adjustSize(comboBox);

    Configuration configuration = AppBeans.get(Configuration.NAME);
    asyncSearchDelayMs = configuration.getConfig(ClientConfig.class).getSuggestionFieldAsyncSearchDelayMs();
}

From source file:plugin.notes.gui.JIcon.java

/**
 *  This method is called from within the constructor to initialize the form.
 *  WARNING: Do NOT modify this code. The content of this method is always
 *  regenerated by the Form Editor./*from w ww . j a  v a 2  s.  c o  m*/
 */
private void initComponents() {

    contextMenu = new JPopupMenu();
    JMenuItem launchMI = new JMenuItem();
    JMenuItem deleteMI = new JMenuItem();
    button = new JButton();
    label = new JLabel();

    launchMI.setText("Launch File (enter)");
    launchMI.addActionListener(this::launchMIActionPerformed);

    contextMenu.add(launchMI);
    deleteMI.setText("Delete File (del)");
    deleteMI.addActionListener(this::deleteMIActionPerformed);

    contextMenu.add(deleteMI);

    setLayout(new BorderLayout());

    setBackground((Color) UIManager.getDefaults().get("Panel.background"));
    setBorder(new LineBorder(new Color(0, 0, 0)));
    button.setBackground((Color) UIManager.getDefaults().get("Button.background"));
    button.setBorder(null);
    button.addActionListener(this::buttonActionPerformed);

    button.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent evt) {
            buttonFocusGained(evt);
        }

        @Override
        public void focusLost(FocusEvent evt) {
            buttonFocusLost(evt);
        }
    });

    button.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent evt) {
            buttonKeyReleased(evt);
        }
    });

    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            buttonMouseClicked(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            buttonMouseReleased(evt);
        }
    });

    add(button, BorderLayout.NORTH);

    label.setBackground(new Color(204, 204, 204));
    add(label, BorderLayout.CENTER);
}

From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextFieldSingle.java

/**
 * @param formatterArg the formatter (can't be null)
 * @param isViewOnlyArg is it for view mode
 * @param isPartialOK can only a part of the format be typed in (used for search forms)
 * @param suggestedNumCols suggested number of columns that can be bigger than the format
 *//*from  w w  w .  j a  v a2s.  c o m*/
protected void init(final UIFieldFormatterIFace formatterArg, final boolean isViewOnlyArg,
        final boolean isPartialOKArg, final Integer suggNumCols, final boolean addFocusListeners) {
    setControlSize(this);

    isPartialOK = isPartialOKArg;

    this.isViewOnly = isViewOnlyArg;
    this.suggestedNumCols = suggNumCols;

    initColors();

    inner = getInsets();

    setFormatterInternal(formatterArg);

    //log.debug(formatter.getName());
    int numCols;
    if (suggestedNumCols != null) {
        numCols = Math.max(suggestedNumCols, formatter.getUILength());
    } else {
        numCols = formatter.getUILength();
    }

    setColumns(numCols);

    addMouseListener(new MouseAdapter() {

        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @Override
        public void mousePressed(MouseEvent e) {
            //System.err.println(e);
            super.mousePressed(e);
        }

    });

    if (addFocusListeners) {
        addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                log.debug("[" + getText() + "]");
                ((JTextField) e.getSource()).selectAll();
                //System.err.println(e);
                repaint();
            }

            @Override
            public void focusLost(FocusEvent e) {
                isNew = false;
                validateState();
                repaint();

            }
        });
    }

    setBackground(isRequired ? requiredFieldColor.getColor() : viewBGColor.getColor());

    if (!isViewOnlyArg) {
        if (!formatterArg.isUserInputNeeded() && !isPartialOK && isAutoFmtOn) {
            ViewFactory.changeTextFieldUIForDisplay(this, false);

        } else {
            super.setEnabled(true);
        }
    }
}

From source file:edu.pdi2.visual.PDI.java

private void initGUI() {
    try {/*  ww w  . j  a  v  a2  s  .c  o  m*/
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        this.setTitle("Procesamiento Digital de Imagenes"); //$NON-NLS-1$
        getContentPane().setBackground(new java.awt.Color(212, 208, 200));
        this.setResizable(false);
        this.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent evt) {
                thisFocusGained(evt);
            }
        });
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu1 = new JMenu();
                jMenuBar1.add(jMenu1);
                jMenu1.setText("File"); //$NON-NLS-1$
                {
                    jMenuItem1 = new JMenuItem();
                    // jMenu1.add(jMenuItem1);
                    jMenu1.add(getJMenuOpenImage());
                    jMenu1.add(getJSeparator1());
                    jMenu1.add(getJMenuItemExit());

                    jMenuItem1.setText("Open Image"); //$NON-NLS-1$
                    jMenuItem1.addMouseListener(new MouseAdapter() {
                        public void mouseReleased(MouseEvent evt) {
                            jMenuItem1MouseReleased(evt);
                        }

                    });
                }
            }
            {
                jMenu3 = new JMenu();
                jMenuBar1.add(jMenu3);
                jMenuBar1.add(getJMenuView());
                jMenu3.setText("Options"); //$NON-NLS-1$
                jMenu3.setEnabled(false);
                {
                    jMenuItem3 = new JMenuItem();
                    jMenu3.add(getJMenuItem2());
                    jMenu3.add(jMenuItem3);
                    jMenuItem3.setText("False Color Image"); //$NON-NLS-1$
                    jMenuItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            menuFalseColorActionPerformed(evt);
                        }
                    });
                }
                {
                    jMenuItem4 = new JMenuItem();
                    jMenu3.add(jMenuItem4);
                    jMenuItem4.setText("Mesh"); //$NON-NLS-1$
                    jMenuItem4.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jMenuItem4ActionPerformed(evt);
                        }
                    });
                }
                {
                    jMenu4 = new JMenu();
                    jMenu3.add(jMenu4);
                    jMenu3.add(getJMenuItem5());
                    jMenu3.add(getJGenerarSignature());
                    jMenu4.setText("Image"); //$NON-NLS-1$
                    {
                        jmiCorrectedReflectance = new JMenuItem();
                        jMenu4.add(jmiCorrectedReflectance);
                        jmiCorrectedReflectance.setText("Corrected Reflectance"); //$NON-NLS-1$
                        jmiCorrectedReflectance.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed 1")); //$NON-NLS-1$
                        jmiCorrectedReflectance.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jmiCorrectedRadianceActionPerformed(evt);
                            }
                        });
                    }
                    {
                        jmiCorrectedRadiance = new JMenuItem();
                        jMenu4.add(jmiCorrectedRadiance);
                        jmiCorrectedRadiance.setText("Corrected Radiance"); //$NON-NLS-1$
                        jmiCorrectedRadiance.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed 2"));
                        jmiCorrectedRadiance.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jmiCorrectedReflectanceActionPerformed(evt);
                            }
                        });
                    }
                }
            }
        }
        // First we create the instance of DisplayThumbnail with a 0.1
        // scale.
        // dt.setBorder(BorderFactory.createTitledBorder(""));
        // We must register mouse motion listeners to it !

        // Now we create the instance of DisplayJAI to show the region
        // corresponding to the viewport.

        // Set it size.
        {
            image = new JPanel();

            getContentPane().add(image);
            image.setBounds(1, 10, 590, dHeight + 10);
            {
                dj = new DisplayJAIWithAnnotations();
                image.add(dj);
                dj.setBounds(0, 0, dWidth, dHeight);
                dj.setPreferredSize(new Dimension(dWidth, dHeight));
                dj.setMinimumSize(new Dimension(dWidth, dHeight));
                dj.setMaximumSize(new Dimension(dWidth, dHeight));
                dj.setBorder(BorderFactory.createTitledBorder(""));
                dj.addMouseListener(new MouseAdapter() {
                    public void mousePressed(MouseEvent evt) {
                        djMousePressed(evt);
                    }
                });
                dj.addMouseMotionListener(new MouseMotionAdapter() {
                    public void mouseMoved(MouseEvent evt) {
                        djMouseMoved(evt);
                    }

                    public void mouseDragged(MouseEvent evt) {
                        djMouseDragged(evt);
                    }
                });
            }
            getContentPane().add(getLatLon());
        }

        pack();
        this.setSize(604, 579);
    } catch (Exception e) {
        e.printStackTrace();
    }
}