* improvements for GTK laf

This commit is contained in:
Reinhard Pointner 2009-06-02 17:03:52 +00:00
parent c49b68c836
commit 1640041266
2 changed files with 27 additions and 14 deletions

View File

@ -5,8 +5,9 @@ package net.sourceforge.filebot.ui.panel.subtitle;
import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
@ -14,37 +15,48 @@ import javax.swing.border.EmptyBorder;
import net.sourceforge.filebot.ResourceManager;
class LanguageComboBoxCellRenderer extends DefaultListCellRenderer {
class LanguageComboBoxCellRenderer implements ListCellRenderer {
private final Border padding = new EmptyBorder(2, 2, 2, 2);
private final Border padding = new EmptyBorder(2, 4, 2, 4);
private final Border favoritePadding = new EmptyBorder(0, 6, 0, 6);
private final ListCellRenderer base;
public LanguageComboBoxCellRenderer(final ListCellRenderer base) {
this.base = base;
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
JLabel c = (JLabel)base.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
Language language = (Language) value;
setText(language.getName());
setIcon(ResourceManager.getFlagIcon(language.getCode()));
c.setText(language.getName());
c.setIcon(ResourceManager.getFlagIcon(language.getCode()));
// default padding
setBorder(padding);
c.setBorder(padding);
LanguageComboBoxModel model = (LanguageComboBoxModel) list.getModel();
if ((index > 0 && index <= model.favorites().size())) {
// add favorite padding
setBorder(new CompoundBorder(favoritePadding, getBorder()));
c.setBorder(new CompoundBorder(favoritePadding, c.getBorder()));
}
if (index == 0 || index == model.favorites().size()) {
// add separator border
setBorder(new CompoundBorder(new DashedSeparator(10, 4, Color.lightGray, list.getBackground()), getBorder()));
c.setBorder(new CompoundBorder(new DashedSeparator(10, 4, Color.lightGray, list.getBackground()), c.getBorder()));
}
return this;
return c;
}
}

View File

@ -2,8 +2,9 @@
package net.sourceforge.filebot.ui.panel.subtitle;
import static net.sourceforge.filebot.Settings.*;
import static net.sourceforge.filebot.ui.panel.subtitle.LanguageComboBoxModel.*;
import static net.sourceforge.filebot.Settings.getApplicationName;
import static net.sourceforge.filebot.Settings.getApplicationVersion;
import static net.sourceforge.filebot.ui.panel.subtitle.LanguageComboBoxModel.ALL_LANGUAGES;
import java.awt.event.ItemEvent;
import java.net.URI;
@ -43,8 +44,8 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
JComboBox languageComboBox = new JComboBox(languageModel);
languageComboBox.setRenderer(new LanguageComboBoxCellRenderer());
languageComboBox.setRenderer(new LanguageComboBoxCellRenderer(languageComboBox.getRenderer()));
// restore state
languageModel.setSelectedItem(persistentSelectedLanguage.getValue());
languageModel.favorites().addAll(0, persistentFavorites.getValue());