Example usage for javax.swing JButton setMinimumSize

List of usage examples for javax.swing JButton setMinimumSize

Introduction

In this page you can find the example usage for javax.swing JButton setMinimumSize.

Prototype

@BeanProperty(description = "The minimum size of the component.")
public void setMinimumSize(Dimension minimumSize) 

Source Link

Document

Sets the minimum size of this component to a constant value.

Usage

From source file:Main.java

/**
 * Sets the JButtons inside a JPanelto be the same size.
 * This is done dynamically by setting each button's preferred and maximum
 * sizes after the buttons are created. This way, the layout automatically
 * adjusts to the locale-specific strings.
 *
 * @param jPanelButtons JPanel containing buttons
 *//*from   w w w  .  j  av  a  2s  .  c  o m*/
public static void equalizeButtonSizes(JPanel jPanelButtons) {
    ArrayList<JButton> lbuttons = new ArrayList<JButton>();
    for (int i = 0; i < jPanelButtons.getComponentCount(); i++) {
        Component c = jPanelButtons.getComponent(i);
        if (c instanceof JButton) {
            lbuttons.add((JButton) c);
        }
    }

    // Get the largest width and height
    Dimension maxSize = new Dimension(0, 0);
    for (JButton lbutton : lbuttons) {
        Dimension d = lbutton.getPreferredSize();
        maxSize.width = Math.max(maxSize.width, d.width);
        maxSize.height = Math.max(maxSize.height, d.height);
    }

    for (JButton btn : lbuttons) {
        btn.setPreferredSize(maxSize);
        btn.setMinimumSize(maxSize);
        btn.setMaximumSize(maxSize);
    }
}

From source file:Main.java

/**
 * Ensures that all buttons are the same size, and that the chosen size is sufficient to contain the content of any.
 *///from   ww  w  .j a  v a 2s. c  om
public static void tieButtonSizes(List<JButton> buttons) {
    int maxWidth = 0;
    int maxHeight = 0;
    for (JButton button : buttons) {
        Dimension buttonSize = button.getPreferredSize();
        maxWidth = (int) Math.max(buttonSize.getWidth(), maxWidth);
        maxHeight = (int) Math.max(buttonSize.getHeight(), maxHeight);
    }
    Dimension maxButtonSize = new Dimension(maxWidth, maxHeight);
    for (JButton button : buttons) {
        // Seemingly, to get the GTK+ LAF to behave when there are buttons with and without icons, we need to set every size.
        button.setPreferredSize(maxButtonSize);
        button.setMinimumSize(maxButtonSize);
        button.setMaximumSize(maxButtonSize);
        button.setSize(maxButtonSize);
    }
}

From source file:Main.java

private JButton createButton(String text, Dimension size) {
    JButton button = new JButton(text);
    button.setPreferredSize(size);/*from w w  w . ja v  a2 s  . c om*/
    button.setMinimumSize(size);
    button.setMaximumSize(size);
    return button;
}

From source file:com.willwinder.ugs.nbp.setupwizard.panels.WizardPanelStepCalibration.java

private void addSubHeaderRow(JPanel panel) {
    JButton resetButton = new JButton(Localization.getString("platform.plugin.setupwizard.reset-to-zero"));
    resetButton.setMinimumSize(new Dimension(36, 36));
    resetButton.addActionListener(event -> {
        try {/*from   www .  j  ava  2  s . com*/
            getBackend().resetCoordinatesToZero();
        } catch (Exception ignored) {
            // Never mind
        }
    });
    panel.add(resetButton, "grow, spanx 3, gapbottom 0, gaptop 0");
    panel.add(new JLabel(Localization.getString("platform.plugin.setupwizard.calibration.actual-movement")),
            "span 2, grow");
    panel.add(new JLabel(Localization.getString("platform.plugin.setupwizard.calibration.adjust")),
            "spanx 5, grow, wrap");
}

From source file:org.jdal.swing.Selector.java

/**
 * Initialize component after construction.
 *///w w w  .  j  av a2  s.c  o  m
@PostConstruct
public void init() {
    if (availableList == null) {
        availableList = new JList<T>(available);
    } else {
        availableList.setModel(available);
    }
    if (selectedList == null) {
        selectedList = new JList<T>(selected);
    } else {
        selectedList.setModel(selected);
    }

    availableSearch.setVisible(showSearchFields);
    selectedSearch.setVisible(showSearchFields);

    JButton addButton = new JButton(new AddSelectedAction());
    JButton removeButton = new JButton(new RemoveSelectedAction());
    addButton.setMinimumSize(new Dimension(buttonWidth, buttonHeight));
    removeButton.setMinimumSize(new Dimension(buttonWidth, buttonHeight));

    JScrollPane availableScroll = new JScrollPane(availableList);
    JScrollPane selectedScroll = new JScrollPane(selectedList);
    availableScroll.setPreferredSize(new Dimension(listWidth, listheight));
    selectedScroll.setPreferredSize(new Dimension(listWidth, listheight));
    availableScroll.setMinimumSize(new Dimension(listWidth, listheight));
    selectedScroll.setMinimumSize(new Dimension(listWidth, listheight));

    // test message source
    if (messageSource == null) {
        messageSource = new ResourceBundleMessageSource();
        ((ResourceBundleMessageSource) messageSource).setBasename("i18n.jdal");
    }

    MessageSourceAccessor msa = new MessageSourceAccessor(messageSource);

    BoxFormBuilder fb = new BoxFormBuilder();

    fb.row(Short.MAX_VALUE);
    fb.startBox();
    fb.row();
    fb.add(availableSearch);
    fb.row();
    fb.add(FormUtils.newLabelForBox(msa.getMessage("Selector.available")));
    fb.row(Short.MAX_VALUE);
    fb.add(availableScroll);
    fb.endBox();
    fb.startBox();
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.row(buttonHeight);
    fb.add(removeButton);
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.endBox();
    fb.setMaxWidth(buttonWidth);
    fb.startBox();
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.row(buttonHeight);
    fb.add(addButton);
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.endBox();
    fb.setMaxWidth(buttonWidth);
    fb.startBox();
    fb.row();
    fb.add(selectedSearch);
    fb.row();
    fb.add(FormUtils.newLabelForBox(msa.getMessage("Selector.selected")));
    fb.row(Short.MAX_VALUE);
    fb.add(selectedScroll);
    fb.endBox();

    setLayout(new BorderLayout());
    add(fb.getForm(), BorderLayout.CENTER);
}

From source file:SuitaDetails.java

public DefPanel(String descriptions, String button, String id, int width, final int index,
        SuitaDetails container) {//from  ww w. ja  v a2 s  .  co m
    this.descriptions = descriptions;
    this.id = id;
    reference = this;
    this.container = container;
    this.index = index;
    setBackground(new Color(255, 255, 255));
    setBorder(BorderFactory.createEmptyBorder(2, 20, 2, 20));
    setMaximumSize(new Dimension(32767, 30));
    setMinimumSize(new Dimension(100, 30));
    setPreferredSize(new Dimension(300, 30));
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    description = new JLabel(descriptions);
    description.setPreferredSize(new Dimension(width, 20));
    description.setMinimumSize(new Dimension(width, 20));
    description.setMaximumSize(new Dimension(width, 20));
    add(description);
    filedsGap = new JPanel();
    filedsGap.setBackground(new Color(255, 255, 255));
    filedsGap.setMaximumSize(new Dimension(20, 20));
    filedsGap.setMinimumSize(new Dimension(20, 20));
    filedsGap.setPreferredSize(new Dimension(20, 20));
    GroupLayout filedsGapLayout = new GroupLayout(filedsGap);
    filedsGap.setLayout(filedsGapLayout);
    filedsGapLayout.setHorizontalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    filedsGapLayout.setVerticalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    add(filedsGap);
    userDefinition = new JTextField();
    doclistener = new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            setParentField(userDefinition.getText(), false);
        }

        public void removeUpdate(DocumentEvent e) {
            setParentField(userDefinition.getText(), false);
        }

        public void insertUpdate(DocumentEvent e) {
            setParentField(userDefinition.getText(), false);
        }
    };
    userDefinition.getDocument().addDocumentListener(doclistener);
    userDefinition.setText("");
    userDefinition.setMaximumSize(new Dimension(300, 100));
    userDefinition.setMinimumSize(new Dimension(50, 20));
    userDefinition.setPreferredSize(new Dimension(100, 20));
    add(userDefinition);
    filedsGap = new JPanel();
    filedsGap.setBackground(new Color(255, 255, 255));
    filedsGap.setMaximumSize(new Dimension(20, 20));
    filedsGap.setMinimumSize(new Dimension(20, 20));
    filedsGap.setPreferredSize(new Dimension(20, 20));
    filedsGapLayout = new GroupLayout(filedsGap);
    filedsGap.setLayout(filedsGapLayout);
    filedsGapLayout.setHorizontalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    filedsGapLayout.setVerticalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    add(filedsGap);
    if (button.equals("UserSelect")) {
        final JButton database = new JButton("Database");
        database.setMaximumSize(new Dimension(100, 20));
        database.setMinimumSize(new Dimension(50, 20));
        database.setPreferredSize(new Dimension(80, 20));
        add(database);
        database.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
                DatabaseFrame frame = new DatabaseFrame(reference);
                frame.executeQuery();
                frame.setLocation((int) database.getLocationOnScreen().getX() - 100,
                        (int) database.getLocationOnScreen().getY());
                frame.setVisible(true);
            }
        });
    } else if (button.equals("UserScript")) {
        JButton script = new JButton("Script");
        script.setMaximumSize(new Dimension(100, 20));
        script.setMinimumSize(new Dimension(50, 20));
        script.setPreferredSize(new Dimension(80, 20));
        add(script);
        script.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
                Container c;
                if (RunnerRepository.container != null)
                    c = RunnerRepository.container.getParent();
                else
                    c = RunnerRepository.window;
                try {
                    //                         String passwd = RunnerRepository.getRPCClient().execute("sendFile", new Object[]{"/etc/passwd"}).toString();
                    //                         new MySftpBrowser(RunnerRepository.host,RunnerRepository.user,RunnerRepository.password,userDefinition,c,passwd);
                    new MySftpBrowser(RunnerRepository.host, RunnerRepository.user, RunnerRepository.password,
                            userDefinition, c, false);
                } catch (Exception e) {
                    System.out.println("There was a problem in opening sftp browser!");
                    e.printStackTrace();
                }
            }
        });
        filedsGap = new JPanel();
        filedsGap.setBackground(new Color(255, 255, 255));
        filedsGap.setMaximumSize(new Dimension(10, 10));
        filedsGap.setMinimumSize(new Dimension(10, 10));
        filedsGap.setPreferredSize(new Dimension(10, 10));
        filedsGapLayout = new GroupLayout(filedsGap);
        filedsGap.setLayout(filedsGapLayout);
        filedsGapLayout.setHorizontalGroup(filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGap(0, 20, Short.MAX_VALUE));
        filedsGapLayout.setVerticalGroup(filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGap(0, 20, Short.MAX_VALUE));
        filedsGap.setLayout(filedsGapLayout);
        add(filedsGap);
        final JButton value = new JButton("Value");
        value.setMaximumSize(new Dimension(100, 20));
        value.setMinimumSize(new Dimension(50, 20));
        value.setPreferredSize(new Dimension(80, 20));
        add(value);
        value.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
                String script = userDefinition.getText();
                if (script != null && !script.equals("")) {
                    try {
                        String result = RunnerRepository.getRPCClient().execute("runUserScript",
                                new Object[] { script }) + "";
                        JFrame f = new JFrame();
                        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                        f.setLocation(value.getLocationOnScreen());
                        JLabel l = new JLabel("Script result: " + result);
                        f.getContentPane().add(l, BorderLayout.CENTER);
                        f.pack();
                        f.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    } else if (button.equals("UserText")) {
        JPanel database = new JPanel();
        database.setBackground(Color.WHITE);
        database.setMaximumSize(new Dimension(100, 20));
        database.setMinimumSize(new Dimension(50, 20));
        database.setPreferredSize(new Dimension(80, 20));
        add(database);
    }
}

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 .j  a  v a  2s. c om*/
 */
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./*  w w  w .  ja  v a  2  s. c om*/
 */
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:ffx.ui.ModelingPanel.java

private void loadCommand() {
    synchronized (this) {
        // Force Field X Command
        Element command;//from  w w  w  .j a  v  a2 s .c o  m
        // Command Options
        NodeList options;
        Element option;
        // Option Values
        NodeList values;
        Element value;
        // Options may be Conditional based on previous Option values (not
        // always supplied)
        NodeList conditionalList;
        Element conditional;
        // JobPanel GUI Components that change based on command
        JPanel optionPanel;
        // Clear the previous components
        commandPanel.removeAll();
        optionsTabbedPane.removeAll();
        conditionals.clear();
        String currentCommand = (String) currentCommandBox.getSelectedItem();
        if (currentCommand == null) {
            commandPanel.validate();
            commandPanel.repaint();
            return;
        }
        command = null;
        for (int i = 0; i < commandList.getLength(); i++) {
            command = (Element) commandList.item(i);
            String name = command.getAttribute("name");
            if (name.equalsIgnoreCase(currentCommand)) {
                break;
            }
        }
        int div = splitPane.getDividerLocation();
        descriptTextArea.setText(currentCommand.toUpperCase() + ": " + command.getAttribute("description"));
        splitPane.setBottomComponent(descriptScrollPane);
        splitPane.setDividerLocation(div);
        // The "action" tells Force Field X what to do when the
        // command finishes
        commandActions = command.getAttribute("action").trim();
        // The "fileType" specifies what file types this command can execute
        // on
        String string = command.getAttribute("fileType").trim();
        String[] types = string.split(" +");
        commandFileTypes.clear();
        for (String type : types) {
            if (type.contains("XYZ")) {
                commandFileTypes.add(FileType.XYZ);
            }
            if (type.contains("INT")) {
                commandFileTypes.add(FileType.INT);
            }
            if (type.contains("ARC")) {
                commandFileTypes.add(FileType.ARC);
            }
            if (type.contains("PDB")) {
                commandFileTypes.add(FileType.PDB);
            }
            if (type.contains("ANY")) {
                commandFileTypes.add(FileType.ANY);
            }
        }
        // Determine what options are available for this command
        options = command.getElementsByTagName("Option");
        int length = options.getLength();
        for (int i = 0; i < length; i++) {
            // This Option will be enabled (isEnabled = true) unless a
            // Conditional disables it
            boolean isEnabled = true;
            option = (Element) options.item(i);
            conditionalList = option.getElementsByTagName("Conditional");
            /*
             * Currently, there can only be 0 or 1 Conditionals per Option
             * There are three types of Conditionals implemented. 1.)
             * Conditional on a previous Option, this option may be
             * available 2.) Conditional on input for this option, a
             * sub-option may be available 3.) Conditional on the presence
             * of keywords, this option may be available
             */
            if (conditionalList != null) {
                conditional = (Element) conditionalList.item(0);
            } else {
                conditional = null;
            }
            // Get the command line flag
            String flag = option.getAttribute("flag").trim();
            // Get the description
            String optionDescript = option.getAttribute("description");
            JTextArea optionTextArea = new JTextArea("  " + optionDescript.trim());
            optionTextArea.setEditable(false);
            optionTextArea.setLineWrap(true);
            optionTextArea.setWrapStyleWord(true);
            optionTextArea.setBorder(etchedBorder);
            // Get the default for this Option (if one exists)
            String defaultOption = option.getAttribute("default");
            // Option Panel
            optionPanel = new JPanel(new BorderLayout());
            optionPanel.add(optionTextArea, BorderLayout.NORTH);
            String swing = option.getAttribute("gui");
            JPanel optionValuesPanel = new JPanel(new FlowLayout());
            optionValuesPanel.setBorder(etchedBorder);
            ButtonGroup bg = null;
            if (swing.equalsIgnoreCase("CHECKBOXES")) {
                // CHECKBOXES allows selection of 1 or more values from a
                // predefined set (Analyze, for example)
                values = option.getElementsByTagName("Value");
                for (int j = 0; j < values.getLength(); j++) {
                    value = (Element) values.item(j);
                    JCheckBox jcb = new JCheckBox(value.getAttribute("name"));
                    jcb.addMouseListener(this);
                    jcb.setName(flag);
                    if (defaultOption != null && jcb.getActionCommand().equalsIgnoreCase(defaultOption)) {
                        jcb.setSelected(true);
                    }
                    optionValuesPanel.add(jcb);
                }
            } else if (swing.equalsIgnoreCase("TEXTFIELD")) {
                // TEXTFIELD takes an arbitrary String as input
                JTextField jtf = new JTextField(20);
                jtf.addMouseListener(this);
                jtf.setName(flag);
                if (defaultOption != null && defaultOption.equals("ATOMS")) {
                    FFXSystem sys = mainPanel.getHierarchy().getActive();
                    if (sys != null) {
                        jtf.setText("" + sys.getAtomList().size());
                    }
                } else if (defaultOption != null) {
                    jtf.setText(defaultOption);
                }
                optionValuesPanel.add(jtf);
            } else if (swing.equalsIgnoreCase("RADIOBUTTONS")) {
                // RADIOBUTTONS allows one choice from a set of predifined
                // values
                bg = new ButtonGroup();
                values = option.getElementsByTagName("Value");
                for (int j = 0; j < values.getLength(); j++) {
                    value = (Element) values.item(j);
                    JRadioButton jrb = new JRadioButton(value.getAttribute("name"));
                    jrb.addMouseListener(this);
                    jrb.setName(flag);
                    bg.add(jrb);
                    if (defaultOption != null && jrb.getActionCommand().equalsIgnoreCase(defaultOption)) {
                        jrb.setSelected(true);
                    }
                    optionValuesPanel.add(jrb);
                }
            } else if (swing.equalsIgnoreCase("PROTEIN")) {
                // Protein allows selection of amino acids for the protein
                // builder
                optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(getAminoAcidPanel());
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidComboBox.removeAllItems();
                JButton add = new JButton("Edit");
                add.setActionCommand("PROTEIN");
                add.addActionListener(this);
                add.setAlignmentX(Button.CENTER_ALIGNMENT);
                JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidTextField);
                comboPanel.add(add);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton remove = new JButton("Remove");
                add.setMinimumSize(remove.getPreferredSize());
                add.setPreferredSize(remove.getPreferredSize());
                remove.setActionCommand("PROTEIN");
                remove.addActionListener(this);
                remove.setAlignmentX(Button.CENTER_ALIGNMENT);
                comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidComboBox);
                comboPanel.add(remove);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(acidScrollPane);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton reset = new JButton("Reset");
                reset.setActionCommand("PROTEIN");
                reset.addActionListener(this);
                reset.setAlignmentX(Button.CENTER_ALIGNMENT);
                optionValuesPanel.add(reset);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidTextArea.setText("");
                acidTextField.setText("");
            } else if (swing.equalsIgnoreCase("NUCLEIC")) {
                // Nucleic allows selection of nucleic acids for the nucleic
                // acid builder
                optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(getNucleicAcidPanel());
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidComboBox.removeAllItems();
                JButton add = new JButton("Edit");
                add.setActionCommand("NUCLEIC");
                add.addActionListener(this);
                add.setAlignmentX(Button.CENTER_ALIGNMENT);
                JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidTextField);
                comboPanel.add(add);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton remove = new JButton("Remove");
                add.setMinimumSize(remove.getPreferredSize());
                add.setPreferredSize(remove.getPreferredSize());
                remove.setActionCommand("NUCLEIC");
                remove.addActionListener(this);
                remove.setAlignmentX(Button.CENTER_ALIGNMENT);
                comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidComboBox);
                comboPanel.add(remove);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(acidScrollPane);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton button = new JButton("Reset");
                button.setActionCommand("NUCLEIC");
                button.addActionListener(this);
                button.setAlignmentX(Button.CENTER_ALIGNMENT);
                optionValuesPanel.add(button);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidTextArea.setText("");
                acidTextField.setText("");
            } else if (swing.equalsIgnoreCase("SYSTEMS")) {
                // SYSTEMS allows selection of an open system
                JComboBox<FFXSystem> jcb = new JComboBox<>(mainPanel.getHierarchy().getNonActiveSystems());
                jcb.setSize(jcb.getMaximumSize());
                jcb.addActionListener(this);
                optionValuesPanel.add(jcb);
            }
            // Set up a Conditional for this Option
            if (conditional != null) {
                isEnabled = false;
                String conditionalName = conditional.getAttribute("name");
                String conditionalValues = conditional.getAttribute("value");
                String cDescription = conditional.getAttribute("description");
                String cpostProcess = conditional.getAttribute("postProcess");
                if (conditionalName.toUpperCase().startsWith("KEYWORD")) {
                    optionPanel.setName(conditionalName);
                    String keywords[] = conditionalValues.split(" +");
                    if (activeSystem != null) {
                        Hashtable<String, Keyword> systemKeywords = activeSystem.getKeywords();
                        for (String key : keywords) {
                            if (systemKeywords.containsKey(key.toUpperCase())) {
                                isEnabled = true;
                            }
                        }
                    }
                } else if (conditionalName.toUpperCase().startsWith("VALUE")) {
                    isEnabled = true;
                    // Add listeners to the values of this option so
                    // the conditional options can be disabled/enabled.
                    for (int j = 0; j < optionValuesPanel.getComponentCount(); j++) {
                        JToggleButton jtb = (JToggleButton) optionValuesPanel.getComponent(j);
                        jtb.addActionListener(this);
                        jtb.setActionCommand("Conditional");
                    }
                    JPanel condpanel = new JPanel();
                    condpanel.setBorder(etchedBorder);
                    JLabel condlabel = new JLabel(cDescription);
                    condlabel.setEnabled(false);
                    condlabel.setName(conditionalValues);
                    JTextField condtext = new JTextField(10);
                    condlabel.setLabelFor(condtext);
                    if (cpostProcess != null) {
                        condtext.setName(cpostProcess);
                    }
                    condtext.setEnabled(false);
                    condpanel.add(condlabel);
                    condpanel.add(condtext);
                    conditionals.add(condlabel);
                    optionPanel.add(condpanel, BorderLayout.SOUTH);
                } else if (conditionalName.toUpperCase().startsWith("REFLECTION")) {
                    String[] condModifiers;
                    if (conditionalValues.equalsIgnoreCase("AltLoc")) {
                        condModifiers = activeSystem.getAltLocations();
                        if (condModifiers != null && condModifiers.length > 1) {
                            isEnabled = true;
                            bg = new ButtonGroup();
                            for (int j = 0; j < condModifiers.length; j++) {
                                JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
                                jrbmi.addMouseListener(this);
                                bg.add(jrbmi);
                                optionValuesPanel.add(jrbmi);
                                if (j == 0) {
                                    jrbmi.setSelected(true);
                                }
                            }
                        }
                    } else if (conditionalValues.equalsIgnoreCase("Chains")) {
                        condModifiers = activeSystem.getChainNames();
                        if (condModifiers != null && condModifiers.length > 0) {
                            isEnabled = true;
                            for (int j = 0; j < condModifiers.length; j++) {
                                JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
                                jrbmi.addMouseListener(this);
                                bg.add(jrbmi);
                                optionValuesPanel.add(jrbmi, j);
                            }
                        }
                    }
                }
            }
            optionPanel.add(optionValuesPanel, BorderLayout.CENTER);
            optionPanel.setPreferredSize(optionPanel.getPreferredSize());
            optionsTabbedPane.addTab(option.getAttribute("name"), optionPanel);
            optionsTabbedPane.setEnabledAt(optionsTabbedPane.getTabCount() - 1, isEnabled);
        }
    }
    optionsTabbedPane.setPreferredSize(optionsTabbedPane.getPreferredSize());
    commandPanel.setLayout(borderLayout);
    commandPanel.add(optionsTabbedPane, BorderLayout.CENTER);
    commandPanel.validate();
    commandPanel.repaint();
    loadLogSettings();
    statusLabel.setText("  " + createCommandInput());
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a button with an icon in it/*from w  ww  .  j  av  a2 s . co m*/
 * 
 * @param container - parent container
 * @param label - button label
 * @param image - button image
 * @param width - button width
 * @param height - button height
 * @param mnemonic - button mnemonic
 * @param tooltip - tool tip for button
 * @param placement - TableLayout placement in parent container
 * @param debug - turn on/off red debug borders
 * @return JButton with image
 */
public static JButton addIconButton(Container container, String label, String image, Integer width,
        Integer height, Integer mnemonic, String tooltip, String placement, boolean debug) {
    JButton button = null;

    if (image == null) {
        button = new JButton(label);
    } else {
        java.net.URL imgURL = GuiImporter.class.getResource(image);
        if (imgURL != null && label.length() > 0) {
            button = new JButton(label, new ImageIcon(imgURL));
        } else if (imgURL != null) {
            button = new JButton(null, new ImageIcon(imgURL));
        } else {
            button = new JButton(label);
            log.error("Couldn't find icon: " + image);
        }
    }

    if (width != null && height != null && width > 0 && height > 0) {
        button.setMaximumSize(new Dimension(width, height));
        button.setPreferredSize(new Dimension(width, height));
        button.setMinimumSize(new Dimension(width, height));
        button.setSize(new Dimension(width, height));
    }

    if (mnemonic != null)
        button.setMnemonic(mnemonic);
    button.setOpaque(!getIsMac());
    button.setToolTipText(tooltip);
    container.add(button, placement);
    if (isMotif() == true) {
        Border b = BorderFactory.createLineBorder(Color.gray);
        button.setMargin(new Insets(0, 0, 0, 0));
        button.setBorder(b);
    }

    if (debug == true)
        button.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                button.getBorder()));

    return button;
}