Example usage for com.jgoodies.looks Options COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY

List of usage examples for com.jgoodies.looks Options COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY

Introduction

In this page you can find the example usage for com.jgoodies.looks Options COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY.

Prototype

String COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY

To view the source code for com.jgoodies.looks Options COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY.

Click Source Link

Document

A JComboBox client property key for the combo's popup menu prototype display value.

Usage

From source file:etomica.virial.cluster2.mvc.view.ClusterWizardPageTemplate.java

License:Mozilla Public License

protected JComboBox createComboBox(String[] values, boolean enabled) {

    JComboBox box = new JComboBox(values);
    box.setEnabled(enabled);//w w  w.j a  v  a2  s  .c om
    box.setEditable(false);
    box.putClientProperty(Options.COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY, "A Quite Long Label");
    return box;
}

From source file:net.sf.jabref.FieldContentSelector.java

License:Open Source License

/**
 * /*  w w  w  . j  a  v  a2 s  .co m*/
 * Create a new FieldContentSelector.
 * 
 * @param frame
 *            The one JabRef-Frame.
 * @param panel
 *            The basepanel the entry-editor is on.
 * @param owner
 *            The window/frame/dialog which should be the owner of the
 *            content selector dialog.
 * @param editor
 *            The entry editor which will be appended by the text selected
 *            by the user from the combobox.
 * @param metaData
 *            The metadata that contains the list of items to display in the
 *            combobox under the key Globals.SELECTOR_META_PREFIX +
 *            editor.getFieldName().
 * @param action
 *            The action that will be performed to after an item from the
 *            combobox has been appended to the text in the entryeditor.
 * @param horizontalLayout
 *            Whether to put a 2 pixel horizontal strut between combobox and
 *            button.
 */
public FieldContentSelector(JabRefFrame frame, final BasePanel panel, Window owner, final FieldEditor editor,
        final MetaData metaData, final AbstractAction action, boolean horizontalLayout, String delimiter) {

    this.frame = frame;
    this.editor = editor;
    this.metaData = metaData;
    this.owner = owner;
    this.action = action;
    this.delimiter = delimiter;

    comboBox = new JComboBox() {

        @Override
        public Dimension getPreferredSize() {
            Dimension parents = super.getPreferredSize();
            if (parents.width > GUIGlobals.MAX_CONTENT_SELECTOR_WIDTH) {
                parents.width = GUIGlobals.MAX_CONTENT_SELECTOR_WIDTH;
            }
            return parents;
        }
    };

    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints con = new GridBagConstraints();

    setLayout(gbl);

    // comboBox.setEditable(true);

    comboBox.setMaximumRowCount(35);

    // Set the width of the popup independent of the size of th box itself:
    comboBox.putClientProperty(Options.COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY,
            "The longest text in the combo popup menu. And even longer.");

    rebuildComboBox();

    con.gridwidth = horizontalLayout ? 3 : GridBagConstraints.REMAINDER;
    con.fill = GridBagConstraints.HORIZONTAL;
    con.weightx = 1;
    gbl.setConstraints(comboBox, con);

    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            /*
             * These conditions signify arrow key navigation in the dropdown
             * list, so we should not react to it. I'm not sure if this is
             * well defined enough to be guaranteed to work everywhere.
             */
            if (e.getActionCommand().equals("comboBoxChanged") && (e.getModifiers() == 0)) {
                return;
            }

            selectionMade();
        }
    });
    // Add an action for the Enter key that signals a selection:
    comboBox.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter");
    comboBox.getActionMap().put("enter", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            selectionMade();
            comboBox.setPopupVisible(false);
        }
    });

    add(comboBox);

    if (horizontalLayout) {
        add(Box.createHorizontalStrut(Sizes.dialogUnitXAsPixel(2, this)));
    }

    JButton manage = new JButton(Globals.lang("Manage"));
    gbl.setConstraints(manage, con);
    add(manage);

    manage.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ContentSelectorDialog2 csd = new ContentSelectorDialog2(FieldContentSelector.this.owner,
                    FieldContentSelector.this.frame, panel, true, metaData, editor.getFieldName());
            Util.placeDialog(csd, FieldContentSelector.this.frame);

            // Calling setVisible(true) will open the modal dialog and block
            // for the dialog to close.
            csd.setVisible(true);

            // So we need to rebuild the ComboBox afterwards
            rebuildComboBox();
        }
    });
}

From source file:net.sf.jabref.gui.FieldContentSelector.java

License:Open Source License

/**
 *
 * Create a new FieldContentSelector./*w w  w  .ja  v a  2s .co m*/
 *
 * @param frame
 *            The one JabRef-Frame.
 * @param panel
 *            The basepanel the entry-editor is on.
 * @param owner
 *            The window/frame/dialog which should be the owner of the
 *            content selector dialog.
 * @param editor
 *            The entry editor which will be appended by the text selected
 *            by the user from the combobox.
 * @param metaData
 *            The metadata that contains the list of items to display in the
 *            combobox under the key Globals.SELECTOR_META_PREFIX +
 *            editor.getFieldName().
 * @param action
 *            The action that will be performed to after an item from the
 *            combobox has been appended to the text in the entryeditor.
 * @param horizontalLayout
 *            Whether to put a 2 pixel horizontal strut between combobox and
 *            button.
 */
public FieldContentSelector(JabRefFrame frame, final BasePanel panel, Window owner, final FieldEditor editor,
        final MetaData metaData, final AbstractAction action, boolean horizontalLayout, String delimiter) {

    this.editor = editor;
    this.metaData = metaData;
    this.action = action;
    this.delimiter = delimiter;

    comboBox = new JComboBox<String>() {

        @Override
        public Dimension getPreferredSize() {
            Dimension parents = super.getPreferredSize();
            if (parents.width > GUIGlobals.MAX_CONTENT_SELECTOR_WIDTH) {
                parents.width = GUIGlobals.MAX_CONTENT_SELECTOR_WIDTH;
            }
            return parents;
        }
    };

    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints con = new GridBagConstraints();

    setLayout(gbl);

    // comboBox.setEditable(true);

    comboBox.setMaximumRowCount(35);

    // Set the width of the popup independent of the size of th box itself:
    comboBox.putClientProperty(Options.COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY,
            "The longest text in the combo popup menu. And even longer.");

    rebuildComboBox();

    con.gridwidth = horizontalLayout ? 3 : GridBagConstraints.REMAINDER;
    con.fill = GridBagConstraints.HORIZONTAL;
    con.weightx = 1;
    gbl.setConstraints(comboBox, con);

    comboBox.addActionListener(e -> {
        /*
         * These conditions signify arrow key navigation in the dropdown
         * list, so we should not react to it. I'm not sure if this is
         * well defined enough to be guaranteed to work everywhere.
         */
        if ("comboBoxChanged".equals(e.getActionCommand()) && (e.getModifiers() == 0)) {
            return;
        }

        selectionMade();
    });
    // Add an action for the Enter key that signals a selection:
    comboBox.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter");
    comboBox.getActionMap().put("enter", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            selectionMade();
            comboBox.setPopupVisible(false);
        }
    });

    add(comboBox);

    if (horizontalLayout) {
        add(Box.createHorizontalStrut(Sizes.dialogUnitXAsPixel(2, this)));
    }

    JButton manage = new JButton(Localization.lang("Manage"));
    gbl.setConstraints(manage, con);
    add(manage);

    manage.addActionListener(e -> {
        ContentSelectorDialog2 csd = new ContentSelectorDialog2(owner, frame, panel, true, metaData,
                editor.getFieldName());
        PositionWindow.placeDialog(csd, frame);

        // Calling setVisible(true) will open the modal dialog and block
        // for the dialog to close.
        csd.setVisible(true);

        // So we need to rebuild the ComboBox afterwards
        rebuildComboBox();
    });
}