Example usage for javax.swing JRadioButtonMenuItem setToolTipText

List of usage examples for javax.swing JRadioButtonMenuItem setToolTipText

Introduction

In this page you can find the example usage for javax.swing JRadioButtonMenuItem setToolTipText.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.")
public void setToolTipText(String text) 

Source Link

Document

Registers the text to display in a tool tip.

Usage

From source file:Main.java

public static JRadioButtonMenuItem createRadioButtonMenuItem(String text, Icon icon, String toolTip,
        ActionListener... listeners) {
    JRadioButtonMenuItem result = new JRadioButtonMenuItem(text, icon);

    if (toolTip != null) {
        result.setToolTipText(toolTip);
    }//from  w  w  w.j  av  a  2  s .  c o  m

    for (ActionListener listener : listeners) {
        result.addActionListener(listener);
    }

    return result;
}

From source file:net.sf.firemox.AbstractMainForm.java

/**
 * From the specified MDB file, and the specified radio button menu, we fill
 * this control with the information read from the MDB file.
 * /* www . j av a2s  . co m*/
 * @param mdbName
 *          the the MDB file containing the TBS rules
 * @param itemChck
 *          the radio button representing this TBS
 */
private void updateMdbMenu(String mdbName, JRadioButtonMenuItem itemChck) {
    String fullName = null;
    try {
        final FileInputStream in = MdbLoader.openMdb(IdConst.TBS_DIR + "/" + mdbName + "/" + mdbName + ".mdb",
                true);
        fullName = MToolKit.readString(in);
        itemChck.setToolTipText("<html><b>" + fullName + "</b> " + MToolKit.readString(in) + "</b> : "
                + MToolKit.readString(in) + "<br>" + MToolKit.readString(in));
        MdbLoader.closeMdb();
    } catch (IOException e) {
        Log.error("The mdb file associated to the TBS '" + mdbName
                + "' has not been found.\nYou must rebuild this TBS before playing with it");
        fullName = "*" + mdbName + " (rebuild it)";
    } catch (Throwable e) {
        Log.error("Exception during the TBS initalisation.\n\tInput file = " + IdConst.TBS_DIR + "/" + mdbName
                + "/" + mdbName + ".mdb", e);
        fullName = "*" + mdbName + " (rebuild it)";
    }
    itemChck.setText(fullName);
    itemChck.setSelected(mdbName.equalsIgnoreCase(MToolKit.tbsName));
}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

/**
 * The first element for each group defines which field to use for the quicksearch. The next two define the name and
 * regexp for the group./*w  w w .jav a2 s . com*/
 */
public GroupSelector(JabRefFrame frame, SidePaneManager manager) {
    super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups"));

    this.frame = frame;
    hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"),
            !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"),
            Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    ButtonGroup nonHits = new ButtonGroup();
    nonHits.add(hideNonHits);
    nonHits.add(grayOut);
    floatCb.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected()));
    andCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS,
            andCb.isSelected()));
    invCb.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected()));
    showOverlappingGroups.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING,
                    showOverlappingGroups.isSelected());
            if (!showOverlappingGroups.isSelected()) {
                groupsTree.setOverlappingGroups(Collections.emptyList());
            }
        }
    });

    grayOut.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected()));

    JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) {

        floatCb.setSelected(true);
        highlCb.setSelected(false);
    } else {
        highlCb.setSelected(true);
        floatCb.setSelected(false);
    }
    JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) {
        andCb.setSelected(true);
        orCb.setSelected(false);
    } else {
        orCb.setSelected(true);
        andCb.setSelected(false);
    }

    showNumberOfElements.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS,
                    showNumberOfElements.isSelected());
            if (groupsTree != null) {
                groupsTree.invalidate();
                groupsTree.repaint();
            }
        }
    });

    autoAssignGroup.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP,
            autoAssignGroup.isSelected()));

    invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS));
    showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING));
    editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE);
    editModeCb.setSelected(editModeIndicator);
    showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
    autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));

    JButton openSettings = new JButton(IconTheme.JabRefIcon.PREFERENCES.getSmallIcon());
    settings.add(andCb);
    settings.add(orCb);
    settings.addSeparator();
    settings.add(invCb);
    settings.addSeparator();
    settings.add(editModeCb);
    settings.addSeparator();
    settings.add(grayOut);
    settings.add(hideNonHits);
    settings.addSeparator();
    settings.add(showOverlappingGroups);
    settings.addSeparator();
    settings.add(showNumberOfElements);
    settings.add(autoAssignGroup);
    openSettings.addActionListener(e -> {
        if (!settings.isVisible()) {
            JButton src = (JButton) e.getSource();
            showNumberOfElements
                    .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
            autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));
            settings.show(src, 0, openSettings.getHeight());
        }
    });

    editModeCb.addActionListener(e -> setEditMode(editModeCb.getState()));

    JButton newButton = new JButton(IconTheme.JabRefIcon.ADD_NOBOX.getSmallIcon());
    int butSize = newButton.getIcon().getIconHeight() + 5;
    Dimension butDim = new Dimension(butSize, butSize);

    newButton.setPreferredSize(butDim);
    newButton.setMinimumSize(butDim);
    JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFile.GROUP).getHelpButton();
    helpButton.setPreferredSize(butDim);
    helpButton.setMinimumSize(butDim);
    JButton autoGroup = new JButton(IconTheme.JabRefIcon.AUTO_GROUP.getSmallIcon());
    autoGroup.setPreferredSize(butDim);
    autoGroup.setMinimumSize(butDim);
    openSettings.setPreferredSize(butDim);
    openSettings.setMinimumSize(butDim);
    Insets butIns = new Insets(0, 0, 0, 0);
    helpButton.setMargin(butIns);
    openSettings.setMargin(butIns);
    newButton.addActionListener(e -> {
        GroupDialog gd = new GroupDialog(frame, panel, null);
        gd.setVisible(true);
        if (gd.okPressed()) {
            AbstractGroup newGroup = gd.getResultingGroup();
            groupsRoot.addNewGroup(newGroup, panel.getUndoManager());
            panel.markBaseChanged();
            frame.output(Localization.lang("Created group \"%0\".", newGroup.getName()));
        }
    });
    andCb.addActionListener(e -> valueChanged(null));
    orCb.addActionListener(e -> valueChanged(null));
    invCb.addActionListener(e -> valueChanged(null));
    showOverlappingGroups.addActionListener(e -> valueChanged(null));
    autoGroup.addActionListener(e -> {
        AutoGroupDialog gd = new AutoGroupDialog(frame, panel, groupsRoot,
                Globals.prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD), " .,",
                Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR));
        gd.setVisible(true);
        // gd does the operation itself
    });
    floatCb.addActionListener(e -> valueChanged(null));
    highlCb.addActionListener(e -> valueChanged(null));
    hideNonHits.addActionListener(e -> valueChanged(null));
    grayOut.addActionListener(e -> valueChanged(null));
    newButton.setToolTipText(Localization.lang("New group"));
    andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups."));
    orCb.setToolTipText(
            Localization.lang("Display all entries belonging to one or more of the selected groups."));
    autoGroup.setToolTipText(Localization.lang("Automatically create groups for database."));
    openSettings.setToolTipText(Localization.lang("Settings"));
    invCb.setToolTipText(
            "<html>" + Localization.lang("Show entries <b>not</b> in group selection") + "</html>");
    showOverlappingGroups.setToolTipText(Localization
            .lang("Highlight groups that contain entries contained in any currently selected group"));
    floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top"));
    highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection"));
    editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries"));
    ButtonGroup bgr = new ButtonGroup();
    bgr.add(andCb);
    bgr.add(orCb);
    ButtonGroup visMode = new ButtonGroup();
    visMode.add(floatCb);
    visMode.add(highlCb);

    JPanel rootPanel = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    rootPanel.setLayout(gbl);

    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;
    con.gridwidth = 1;
    con.gridy = 0;

    con.gridx = 0;
    gbl.setConstraints(newButton, con);
    rootPanel.add(newButton);

    con.gridx = 1;
    gbl.setConstraints(autoGroup, con);
    rootPanel.add(autoGroup);

    con.gridx = 2;
    gbl.setConstraints(openSettings, con);
    rootPanel.add(openSettings);

    con.gridx = 3;
    con.gridwidth = GridBagConstraints.REMAINDER;
    gbl.setConstraints(helpButton, con);
    rootPanel.add(helpButton);

    groupsTree = new GroupsTree(this);
    groupsTree.addTreeSelectionListener(this);

    JScrollPane groupsTreePane = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    con.gridwidth = GridBagConstraints.REMAINDER;
    con.weighty = 1;
    con.gridx = 0;
    con.gridwidth = 4;
    con.gridy = 1;
    gbl.setConstraints(groupsTreePane, con);
    rootPanel.add(groupsTreePane);

    add(rootPanel, BorderLayout.CENTER);
    setEditMode(editModeIndicator);
    definePopup();
    NodeAction moveNodeUpAction = new MoveNodeUpAction();
    moveNodeUpAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK));
    NodeAction moveNodeDownAction = new MoveNodeDownAction();
    moveNodeDownAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK));
    NodeAction moveNodeLeftAction = new MoveNodeLeftAction();
    moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK));
    NodeAction moveNodeRightAction = new MoveNodeRightAction();
    moveNodeRightAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK));

    setGroups(GroupTreeNode.fromGroup(new AllEntriesGroup()));
}

From source file:net.sf.jabref.groups.GroupSelector.java

/**
 * The first element for each group defines which field to use for the quicksearch. The next two define the name and
 * regexp for the group.//from   w  w  w.  ja v  a  2  s .c o m
 */
public GroupSelector(JabRefFrame frame, SidePaneManager manager) {
    super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups"));
    this.groupsRoot = new GroupTreeNode(new AllEntriesGroup());

    this.frame = frame;
    hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"),
            !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"),
            Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS));
    ButtonGroup nonHits = new ButtonGroup();
    nonHits.add(hideNonHits);
    nonHits.add(grayOut);
    floatCb.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected());
        }
    });
    andCb.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected());
        }
    });
    invCb.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected());
        }
    });
    showOverlappingGroups.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING,
                    showOverlappingGroups.isSelected());
            if (!showOverlappingGroups.isSelected()) {
                groupsTree.setHighlight2Cells(null);
            }
        }
    });

    select.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SELECT_MATCHES, select.isSelected());
        }
    });
    grayOut.addChangeListener(
            event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected()));

    JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) {

        floatCb.setSelected(true);
        highlCb.setSelected(false);
    } else {
        highlCb.setSelected(true);
        floatCb.setSelected(false);
    }
    JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false);
    if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) {
        andCb.setSelected(true);
        orCb.setSelected(false);
    } else {
        orCb.setSelected(true);
        andCb.setSelected(false);
    }

    showNumberOfElements.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS,
                    showNumberOfElements.isSelected());
            if (groupsTree != null) {
                groupsTree.invalidate();
                groupsTree.validate();
                groupsTree.repaint();
            }
        }
    });

    autoAssignGroup.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected());
        }
    });

    invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS));
    showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING));
    select.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SELECT_MATCHES));
    editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE);
    editModeCb.setSelected(editModeIndicator);
    showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
    autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));

    openset.setMargin(new Insets(0, 0, 0, 0));
    settings.add(andCb);
    settings.add(orCb);
    settings.addSeparator();
    settings.add(invCb);
    settings.addSeparator();
    settings.add(select);
    settings.addSeparator();
    settings.add(editModeCb);
    settings.addSeparator();
    settings.add(grayOut);
    settings.add(hideNonHits);
    settings.addSeparator();
    settings.add(showOverlappingGroups);
    settings.addSeparator();
    settings.add(showNumberOfElements);
    settings.add(autoAssignGroup);
    // settings.add(moreRow);
    // settings.add(lessRow);
    openset.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!settings.isVisible()) {
                JButton src = (JButton) e.getSource();
                showNumberOfElements
                        .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS));
                autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));
                settings.show(src, 0, openset.getHeight());
            }
        }
    });
    JButton expand = new JButton(IconTheme.JabRefIcon.ADD_ROW.getSmallIcon());
    expand.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) + 1;
            groupsTree.setVisibleRowCount(i);
            groupsTree.revalidate();
            groupsTree.repaint();
            GroupSelector.this.revalidate();
            GroupSelector.this.repaint();
            Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i);
            LOGGER.info("Height: " + GroupSelector.this.getHeight() + "; Preferred height: "
                    + GroupSelector.this.getPreferredSize().getHeight());
        }
    });
    JButton reduce = new JButton(IconTheme.JabRefIcon.REMOVE_ROW.getSmallIcon());
    reduce.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) - 1;
            if (i < 1) {
                i = 1;
            }
            groupsTree.setVisibleRowCount(i);
            groupsTree.revalidate();
            groupsTree.repaint();
            GroupSelector.this.revalidate();
            // _panel.sidePaneManager.revalidate();
            GroupSelector.this.repaint();
            Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i);
        }
    });

    editModeCb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editModeIndicator = editModeCb.getState();
            updateBorder(editModeIndicator);
            Globals.prefs.putBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE, editModeIndicator);
        }
    });

    int butSize = newButton.getIcon().getIconHeight() + 5;
    Dimension butDim = new Dimension(butSize, butSize);
    //Dimension butDimSmall = new Dimension(20, 20);

    newButton.setPreferredSize(butDim);
    newButton.setMinimumSize(butDim);
    refresh.setPreferredSize(butDim);
    refresh.setMinimumSize(butDim);
    JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFiles.groupsHelp)
            .getHelpButton();
    helpButton.setPreferredSize(butDim);
    helpButton.setMinimumSize(butDim);
    autoGroup.setPreferredSize(butDim);
    autoGroup.setMinimumSize(butDim);
    openset.setPreferredSize(butDim);
    openset.setMinimumSize(butDim);
    expand.setPreferredSize(butDim);
    expand.setMinimumSize(butDim);
    reduce.setPreferredSize(butDim);
    reduce.setMinimumSize(butDim);
    Insets butIns = new Insets(0, 0, 0, 0);
    helpButton.setMargin(butIns);
    reduce.setMargin(butIns);
    expand.setMargin(butIns);
    openset.setMargin(butIns);
    newButton.addActionListener(this);
    refresh.addActionListener(this);
    andCb.addActionListener(this);
    orCb.addActionListener(this);
    invCb.addActionListener(this);
    showOverlappingGroups.addActionListener(this);
    autoGroup.addActionListener(this);
    floatCb.addActionListener(this);
    highlCb.addActionListener(this);
    select.addActionListener(this);
    hideNonHits.addActionListener(this);
    grayOut.addActionListener(this);
    newButton.setToolTipText(Localization.lang("New group"));
    refresh.setToolTipText(Localization.lang("Refresh view"));
    andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups."));
    orCb.setToolTipText(
            Localization.lang("Display all entries belonging to one or more of the selected groups."));
    autoGroup.setToolTipText(Localization.lang("Automatically create groups for database."));
    invCb.setToolTipText(Localization.lang("Show entries *not* in group selection"));
    showOverlappingGroups.setToolTipText(Localization
            .lang("Highlight groups that contain entries contained in any currently selected group"));
    floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top"));
    highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection"));
    select.setToolTipText(Localization.lang("Select entries in group selection"));
    expand.setToolTipText(Localization.lang("Show one more row"));
    reduce.setToolTipText(Localization.lang("Show one less rows"));
    editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries"));
    ButtonGroup bgr = new ButtonGroup();
    bgr.add(andCb);
    bgr.add(orCb);
    ButtonGroup visMode = new ButtonGroup();
    visMode.add(floatCb);
    visMode.add(highlCb);

    JPanel main = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    main.setLayout(gbl);

    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.BOTH;
    //con.insets = new Insets(0, 0, 2, 0);
    con.weightx = 1;
    con.gridwidth = 1;
    con.gridx = 0;
    con.gridy = 0;
    //con.insets = new Insets(1, 1, 1, 1);
    gbl.setConstraints(newButton, con);
    main.add(newButton);
    con.gridx = 1;
    gbl.setConstraints(refresh, con);
    main.add(refresh);
    con.gridx = 2;
    gbl.setConstraints(autoGroup, con);
    main.add(autoGroup);
    con.gridx = 3;
    con.gridwidth = GridBagConstraints.REMAINDER;

    gbl.setConstraints(helpButton, con);
    main.add(helpButton);

    // header.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
    // helpButton.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
    groupsTree = new GroupsTree(this);
    groupsTree.addTreeSelectionListener(this);
    groupsTree.setModel(groupsTreeModel = new DefaultTreeModel(groupsRoot));
    JScrollPane sp = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    revalidateGroups();
    con.gridwidth = GridBagConstraints.REMAINDER;
    con.weighty = 1;
    con.gridx = 0;
    con.gridwidth = 4;
    con.gridy = 1;
    gbl.setConstraints(sp, con);
    main.add(sp);

    JPanel pan = new JPanel();
    GridBagLayout gb = new GridBagLayout();
    con.weighty = 0;
    gbl.setConstraints(pan, con);
    pan.setLayout(gb);
    con.insets = new Insets(0, 0, 0, 0);
    con.gridx = 0;
    con.gridy = 0;
    con.weightx = 1;
    con.gridwidth = 4;
    con.fill = GridBagConstraints.HORIZONTAL;
    gb.setConstraints(openset, con);
    pan.add(openset);

    con.gridwidth = 1;
    con.gridx = 4;
    con.gridy = 0;
    gb.setConstraints(expand, con);
    pan.add(expand);

    con.gridx = 5;
    gb.setConstraints(reduce, con);
    pan.add(reduce);

    con.gridwidth = 6;
    con.gridy = 1;
    con.gridx = 0;
    con.fill = GridBagConstraints.HORIZONTAL;

    con.gridy = 2;
    con.gridx = 0;
    con.gridwidth = 4;
    gbl.setConstraints(pan, con);
    main.add(pan);
    main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    add(main, BorderLayout.CENTER);
    updateBorder(editModeIndicator);
    definePopup();
    NodeAction moveNodeUpAction = new MoveNodeUpAction();
    moveNodeUpAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK));
    NodeAction moveNodeDownAction = new MoveNodeDownAction();
    moveNodeDownAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK));
    NodeAction moveNodeLeftAction = new MoveNodeLeftAction();
    moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK));
    NodeAction moveNodeRightAction = new MoveNodeRightAction();
    moveNodeRightAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK));
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * @param result//from   ww w . j  a va 2s.c o m
 * @param clctcomp
 */
private static void addRightOperandToPopupMenu(JPopupMenu result, final AbstractCollectableComponent clctcomp) {
    result.addSeparator();
    final ButtonGroup btngrpCompareWith = new ButtonGroup();
    final SpringLocaleDelegate localeDelegate = SpringLocaleDelegate.getInstance();

    final JRadioButtonMenuItem miValue = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.17", "Wertvergleich"));
    miValue.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.10",
            "Dieses Feld mit einem festen Wert vergleichen"));
    result.add(miValue);
    btngrpCompareWith.add(miValue);
    miValue.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            clctcomp.resetWithComparison();
            clctcomp.runLocked(new Runnable() {
                @Override
                public void run() {
                    clctcomp.updateSearchConditionInModel();
                }
            });
        }
    });

    final JRadioButtonMenuItem miOtherField = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.12", "Feldvergleich..."));
    miOtherField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.9",
            "Dieses Feld mit dem Inhalt eines anderen Felds vergleichen"));
    result.add(miOtherField);
    btngrpCompareWith.add(miOtherField);
    miOtherField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            assert clctcomp.clcte != null;

            // select entity field with the same data type:
            final List<CollectableEntityField> lstclctefFiltered = CollectionUtils.select(
                    CollectableUtils.getCollectableEntityFields(clctcomp.clcte),
                    new Predicate<CollectableEntityField>() {
                        @Override
                        public boolean evaluate(CollectableEntityField clctef) {
                            return clctef.getJavaClass() == clctcomp.clctef.getJavaClass();
                        }
                    });
            // and sort by label:
            final List<CollectableEntityField> lstclctefSorted = CollectionUtils.sorted(lstclctefFiltered,
                    new CollectableEntityField.LabelComparator());

            final JComboBox cmbbx = new JComboBox(lstclctefSorted.toArray());
            cmbbx.setSelectedItem(clctcomp.getComparisonOtherField());

            final int iBtn = JOptionPane
                    .showConfirmDialog(clctcomp.getJComponent(),
                            new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.6",
                                    "Anderes Feld: "), cmbbx },
                            localeDelegate.getMessage("AbstractCollectableComponent.15",
                                    "Vergleich mit anderem Feld"),
                            JOptionPane.OK_CANCEL_OPTION);

            if (iBtn == JOptionPane.OK_OPTION) {
                clctcomp.setWithComparison((CollectableEntityField) cmbbx.getSelectedItem());
                if (clctcomp.getComparisonOtherField() != null) {
                    // clear the view:
                    clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField()));

                    if (clctcomp.compop.getOperandCount() < 2) {
                        // If the user selects "other field" and forgot to set the operator, we assume "EQUAL":
                        clctcomp.compop = ComparisonOperator.EQUAL;
                    }
                }
                clctcomp.runLocked(new Runnable() {
                    @Override
                    public void run() {
                        clctcomp.updateSearchConditionInModel();
                    }
                });
            }
        }
    });

    final List<ComparisonParameter> compatibleParameters = ComparisonParameter
            .getCompatibleParameters(clctcomp.getEntityField());
    final JRadioButtonMenuItem miParameterField = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.18", null));
    miParameterField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.19", null));
    btngrpCompareWith.add(miParameterField);
    if (compatibleParameters.size() > 0) {
        result.add(miParameterField);
        miParameterField.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ev) {
                ResourceIdMapper<ComparisonParameter> mapper = new ResourceIdMapper<ComparisonParameter>(
                        compatibleParameters);
                JComboBox cmbbx = new JComboBox(CollectionUtils.sorted(compatibleParameters, mapper).toArray());
                cmbbx.setRenderer(new DefaultListRenderer(mapper));
                cmbbx.setSelectedItem(clctcomp.getComparisonParameter());

                final int opt = JOptionPane.showConfirmDialog(clctcomp.getJComponent(),
                        new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.20", null),
                                cmbbx },
                        localeDelegate.getMessage("AbstractCollectableComponent.19", null),
                        JOptionPane.OK_CANCEL_OPTION);

                if (opt == JOptionPane.OK_OPTION) {
                    clctcomp.setWithComparison((ComparisonParameter) cmbbx.getSelectedItem());
                    if (clctcomp.getComparisonParameter() != null) {
                        clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField()));
                        if (clctcomp.compop.getOperandCount() < 2) {
                            clctcomp.compop = ComparisonOperator.EQUAL;
                        }
                    }
                    clctcomp.runLocked(new Runnable() {
                        @Override
                        public void run() {
                            clctcomp.updateSearchConditionInModel();
                        }
                    });
                }
            }
        });
    }

    result.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            if (clctcomp.getComparisonParameter() != null) {
                miParameterField.setSelected(true);
            } else if (clctcomp.getComparisonOtherField() == null
                    || clctcomp.getComparisonOperator().getOperandCount() < 2) {
                miValue.setSelected(true);
            } else {
                miOtherField.setSelected(true);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent ev) {
        }
    });
}