Search in sources :

Example 6 with BasicComboBoxRenderer

use of javax.swing.plaf.basic.BasicComboBoxRenderer in project visualvm by oracle.

the class GenericToolbar method getPreferredSize.

public Dimension getPreferredSize() {
    Dimension dim = super.getPreferredSize();
    if (PREFERRED_HEIGHT == -1) {
        GenericToolbar tb = new GenericToolbar();
        tb.setBorder(getBorder());
        tb.setBorderPainted(isBorderPainted());
        tb.setRollover(isRollover());
        tb.setFloatable(isFloatable());
        Icon icon = Icons.getIcon(GeneralIcons.SAVE);
        // NOI18N
        tb.add(new JButton("Button", icon));
        // NOI18N
        tb.add(new JToggleButton("Button", icon));
        // NOI18N
        tb.add(new JTextField("Text"));
        JComboBox c = new JComboBox();
        c.setEditor(new BasicComboBoxEditor());
        c.setRenderer(new BasicComboBoxRenderer());
        tb.add(c);
        tb.addSeparator();
        PREFERRED_HEIGHT = tb.getSuperPreferredSize().height;
    }
    dim.height = getParent() instanceof JToolBar ? 1 : Math.max(dim.height, PREFERRED_HEIGHT);
    return dim;
}
Also used : BasicComboBoxEditor(javax.swing.plaf.basic.BasicComboBoxEditor) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) JToggleButton(javax.swing.JToggleButton) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) Icon(javax.swing.Icon) JToolBar(javax.swing.JToolBar) JTextField(javax.swing.JTextField)

Example 7 with BasicComboBoxRenderer

use of javax.swing.plaf.basic.BasicComboBoxRenderer in project droid by digital-preservation.

the class FilterDialog method getRowForTable.

/**
 * @return Object[] Object Array for the entire row in the filter table.
 */
public Object[] getRowForTable() {
    Component component = new TextBoxAndButton(this);
    component.hide();
    // get all the meta data and load the combo
    metaDataCombobox = new JComboBox(filterDomain.getMetaDataNames());
    metaDataCombobox.setRenderer(new BasicComboBoxRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            final String displayText = value == null ? "<Please select...>" : value.toString();
            return super.getListCellRendererComponent(list, displayText, index, isSelected, cellHasFocus);
        }
    });
    operationCombobox = new JComboBox();
    operationComboboxModel = new DefaultComboBoxModel();
    operationCombobox.setModel(operationComboboxModel);
    metaDataCombobox.addItemListener(new MetaDataComboItemListner());
    operationCombobox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED && !filterPredicatesLoading) {
                // set the corresponding value at filter context.
                FilterCriterionImpl filterCriterion = filterContext.getFilterCriterion(filterTable.getSelectedRow());
                JComboBox sourceCombo = (JComboBox) e.getSource();
                filterCriterion.setOperator((CriterionOperator) sourceCombo.getSelectedItem());
            }
        }
    });
    // Remove button and its listner.
    JButton jButton2 = new JButton(REMOVE);
    // CHECKSTYLE:OFF FIXME - inner class is too long
    jButton2.addActionListener(new ActionListener() {

        // CHECKSTYLE:ON
        @Override
        public void actionPerformed(ActionEvent e) {
            if (tableModel.getRowCount() > 1 && (filterTable.getSelectedRow() + 1) != tableModel.getRowCount()) {
                int size = filterContext.getNumberOfFilterCriterion();
                filterContext.removeFilterCriterion(filterTable.getSelectedRow());
                // fill the empty criteria which is been removed.
                for (int k = filterTable.getSelectedRow() + 1; k < size; k++) {
                    filterContext.getFilterCriteriaMap().put(k - 1, filterContext.getFilterCriteriaMap().get(k));
                }
                // remove the last one
                filterContext.removeFilterCriterion(size - 1);
                tableModel.removeRow(filterTable.getSelectedRow());
                tableModel.fireTableRowsDeleted(filterTable.getSelectedRow(), filterTable.getSelectedRow());
                filterTable.revalidate();
                initColumnSizes(filterTable);
            }
        }
    });
    Object[] data = { metaDataCombobox, operationCombobox, component, jButton2 };
    metaDataCombobox.setMaximumRowCount(filterDomain.getMetaDataNames().length);
    return data;
}
Also used : ItemEvent(java.awt.event.ItemEvent) CriterionOperator(uk.gov.nationalarchives.droid.core.interfaces.filter.CriterionOperator) JComboBox(javax.swing.JComboBox) FilterCriterionImpl(uk.gov.nationalarchives.droid.profile.FilterCriterionImpl) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) JComponent(javax.swing.JComponent) Component(java.awt.Component) JList(javax.swing.JList)

Example 8 with BasicComboBoxRenderer

use of javax.swing.plaf.basic.BasicComboBoxRenderer in project mucommander by mucommander.

the class AppearancePanel method createLookAndFeelPanel.

/**
 * Creates the look and feel panel.
 *
 * @return the look and feel panel.
 */
private JPanel createLookAndFeelPanel() {
    JPanel lnfPanel;
    // Creates the panel.
    lnfPanel = new YBoxPanel();
    lnfPanel.setAlignmentX(LEFT_ALIGNMENT);
    lnfPanel.setBorder(BorderFactory.createTitledBorder(Translator.get("prefs_dialog.look_and_feel")));
    // Creates the look and feel combo box.
    lookAndFeelComboBox = new PrefComboBox() {

        public boolean hasChanged() {
            int selectedIndex = getSelectedIndex();
            if (selectedIndex < 0)
                return false;
            return !lookAndFeels[selectedIndex].getClassName().equals(MuConfigurations.getPreferences().getVariable(MuPreference.LOOK_AND_FEEL));
        }
    };
    lookAndFeelComboBox.setRenderer(new BasicComboBoxRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel label;
            label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (index < 0)
                return label;
            // All look and feels that are not modifiable must be flagged with a lock icon.
            if (isLookAndFeelModifiable(lookAndFeels[index]))
                label.setIcon(transparentIcon);
            else
                label.setIcon(lockIcon);
            return label;
        }
    });
    // Populates the look and feel combo box.
    populateLookAndFeels();
    // Initialises buttons and event listening.
    importLookAndFeelButton = new JButton(Translator.get("prefs_dialog.import") + "...");
    deleteLookAndFeelButton = new JButton(Translator.get("delete"));
    importLookAndFeelButton.addActionListener(this);
    deleteLookAndFeelButton.addActionListener(this);
    resetLookAndFeelButtons();
    lookAndFeelComboBox.addActionListener(this);
    // Adds the look and feel list and the action buttons to the panel.
    JPanel flowPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    flowPanel.add(lookAndFeelComboBox);
    flowPanel.add(importLookAndFeelButton);
    flowPanel.add(deleteLookAndFeelButton);
    flowPanel.add(new JLabel(dial = new SpinningDial()));
    lnfPanel.add(flowPanel);
    return lnfPanel;
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) YBoxPanel(com.mucommander.commons.util.ui.layout.YBoxPanel) PrefComboBox(com.mucommander.ui.dialog.pref.component.PrefComboBox) SpinningDial(com.mucommander.ui.icon.SpinningDial) Component(java.awt.Component) JList(javax.swing.JList)

Example 9 with BasicComboBoxRenderer

use of javax.swing.plaf.basic.BasicComboBoxRenderer in project jtharness by openjdk.

the class MessageStrip method createRightPanel.

private JComponent createRightPanel() {
    JPanel right = uif.createPanel("strip.right", new GridBagLayout(), false);
    selector = uif.createLiteralChoice("strip.sel", monitors);
    uif.setAccessibleName(selector, "strip.sel");
    selector.addActionListener(actionListener);
    selector.setRenderer(new BasicComboBoxRenderer() {

        @Override
        @SuppressWarnings("rawtypes")
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            try {
                JLabel lab = (JLabel) c;
                if (value instanceof Monitor) {
                    lab.setText(((Monitor) value).getSmallMonitorName());
                }
            } catch (ClassCastException e) {
            }
            return c;
        }
    });
    ContextHelpManager.setHelpIDString(selector, "run.testProgress");
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 2.0d;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    monitorCards = new CardLayout();
    rightPanel = uif.createPanel("strip.", monitorCards, false);
    for (Monitor monitor : monitors) {
        rightPanel.add(monitor.getSmallMonitorName(), monitor.getSmallMonitor());
    }
    currMonitor = getDefaultSmallMonitor();
    monitorCards.show(rightPanel, monitors[currMonitor].getSmallMonitorName());
    JPanel tmpPanel = uif.createPanel("monitor container", new BorderLayout(), false);
    tmpPanel.add(selector, BorderLayout.WEST);
    tmpPanel.add(rightPanel, BorderLayout.CENTER);
    right.add(tmpPanel, gbc);
    gbc.gridx = 1;
    gbc.weightx = 0.0d;
    /*
        gbc.anchor = GridBagConstraints.EAST;
        selectButt = uif.createIconButton("strip.drop");
        selectButt.addMouseListener(popupListener);
        selectButt.addActionListener(popupListener);
        uif.setAccessibleName(selectButt, "strip.drop");

        gbc.gridx = 2;
        */
    magButt = uif.createIconButton("strip.magnify");
    magButt.addActionListener(actionListener);
    uif.setAccessibleName(magButt, "strip.magnify");
    JToolBar tb = uif.createToolBar("strip.tb", magButt);
    tb.setFloatable(false);
    tb.setBorderPainted(true);
    right.add(tb, gbc);
    right.setEnabled(true);
    right.setVisible(true);
    rightPanel.setEnabled(true);
    rightPanel.setVisible(true);
    return right;
}
Also used : JPanel(javax.swing.JPanel) CardLayout(java.awt.CardLayout) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) BorderLayout(java.awt.BorderLayout) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) Component(java.awt.Component) JList(javax.swing.JList)

Example 10 with BasicComboBoxRenderer

use of javax.swing.plaf.basic.BasicComboBoxRenderer in project visualvm by oracle.

the class TransparentToolBar method getPreferredSize.

public Dimension getPreferredSize() {
    Dimension dim = getPreferredSizeSuper();
    if (horizontal) {
        if (PREFERRED_HEIGHT == -1) {
            TransparentToolBar tb = new TransparentToolBar();
            Icon icon = new Icon() {

                public int getIconWidth() {
                    return 16;
                }

                public int getIconHeight() {
                    return 16;
                }

                public void paintIcon(Component c, Graphics g, int x, int y) {
                }
            };
            // NOI18N
            JButton b = new JButton("Button", icon);
            tb.addItem(b);
            // NOI18N
            JToggleButton t = new JToggleButton("Button", icon);
            tb.addItem(t);
            JComboBox c = new JComboBox();
            c.setEditor(new BasicComboBoxEditor());
            c.setRenderer(new BasicComboBoxRenderer());
            tb.addItem(c);
            tb.addSeparator();
            PREFERRED_HEIGHT = tb.getPreferredSizeSuper().height;
        }
        dim.height = Math.max(dim.height, PREFERRED_HEIGHT);
    }
    return dim;
}
Also used : Graphics(java.awt.Graphics) BasicComboBoxEditor(javax.swing.plaf.basic.BasicComboBoxEditor) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) JToggleButton(javax.swing.JToggleButton) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) Icon(javax.swing.Icon) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

BasicComboBoxRenderer (javax.swing.plaf.basic.BasicComboBoxRenderer)11 JList (javax.swing.JList)6 Component (java.awt.Component)5 JButton (javax.swing.JButton)5 JComboBox (javax.swing.JComboBox)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 FlowLayout (java.awt.FlowLayout)3 JComponent (javax.swing.JComponent)3 PrefComboBox (com.mucommander.ui.dialog.pref.component.PrefComboBox)2 Dimension (java.awt.Dimension)2 Icon (javax.swing.Icon)2 JToggleButton (javax.swing.JToggleButton)2 JToolBar (javax.swing.JToolBar)2 BasicComboBoxEditor (javax.swing.plaf.basic.BasicComboBoxEditor)2 ComboBox (com.intellij.openapi.ui.ComboBox)1 Pair (com.intellij.openapi.util.Pair)1 ProportionalGridPanel (com.mucommander.commons.util.ui.layout.ProportionalGridPanel)1 YBoxPanel (com.mucommander.commons.util.ui.layout.YBoxPanel)1 SpinningDial (com.mucommander.ui.icon.SpinningDial)1