Search in sources :

Example 11 with BasicComboBoxRenderer

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

the class AppearancePanel method createThemesPanel.

/**
 * Creates the themes panel.
 *
 * @return the themes panel.
 */
private JPanel createThemesPanel() {
    JPanel gridPanel = new ProportionalGridPanel(4);
    // Creates the various panel's buttons.
    editThemeButton = new JButton(Translator.get("edit") + "...");
    importThemeButton = new JButton(Translator.get("prefs_dialog.import") + "...");
    exportThemeButton = new JButton(Translator.get("prefs_dialog.export") + "...");
    renameThemeButton = new JButton(Translator.get("rename"));
    deleteThemeButton = new JButton(Translator.get("delete"));
    duplicateThemeButton = new JButton(Translator.get("duplicate"));
    editThemeButton.addActionListener(this);
    importThemeButton.addActionListener(this);
    exportThemeButton.addActionListener(this);
    renameThemeButton.addActionListener(this);
    deleteThemeButton.addActionListener(this);
    duplicateThemeButton.addActionListener(this);
    // Creates the panel's 'type label'.
    typeLabel = new JLabel("");
    // Creates the theme combo box.
    themeComboBox = new PrefComboBox() {

        public boolean hasChanged() {
            return !ThemeManager.isCurrentTheme((Theme) getSelectedItem());
        }
    };
    themeComboBox.addActionListener(this);
    // Sets the combobox's renderer.
    lockIcon = IconManager.getIcon(IconManager.PREFERENCES_ICON_SET, "lock.png");
    transparentIcon = new ImageIcon(new BufferedImage(lockIcon.getIconWidth(), lockIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB));
    themeComboBox.setRenderer(new BasicComboBoxRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel label;
            Theme theme;
            label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            theme = (Theme) value;
            if (ThemeManager.isCurrentTheme(theme))
                label.setText(theme.getName() + " (" + Translator.get("theme.current") + ")");
            else
                label.setText(theme.getName());
            if (theme.getType() != Theme.CUSTOM_THEME)
                label.setIcon(lockIcon);
            else
                label.setIcon(transparentIcon);
            return label;
        }
    });
    // Initialises the content of the combo box.
    populateThemes(ThemeManager.getCurrentTheme());
    gridPanel.add(themeComboBox);
    gridPanel.add(editThemeButton);
    gridPanel.add(importThemeButton);
    gridPanel.add(exportThemeButton);
    gridPanel.add(typeLabel);
    gridPanel.add(renameThemeButton);
    gridPanel.add(deleteThemeButton);
    gridPanel.add(duplicateThemeButton);
    JPanel flowPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
    flowPanel.setBorder(BorderFactory.createTitledBorder(Translator.get("prefs_dialog.themes")));
    flowPanel.add(gridPanel);
    return flowPanel;
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) FlowLayout(java.awt.FlowLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) BufferedImage(java.awt.image.BufferedImage) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) PrefComboBox(com.mucommander.ui.dialog.pref.component.PrefComboBox) Theme(com.mucommander.ui.theme.Theme) ProportionalGridPanel(com.mucommander.commons.util.ui.layout.ProportionalGridPanel) Component(java.awt.Component) JList(javax.swing.JList)

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