Ignore:
Timestamp:
2020-10-12T20:06:14+02:00 (4 years ago)
Author:
simon04
Message:

see #7548 - Re-organize the preference dialog (icons)

Location:
trunk/src/org/openstreetmap/josm/gui/preferences
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r17162 r17178  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.BorderLayout;
    67import java.awt.Component;
    78import java.awt.Container;
     
    218219        private void buildPanel() {
    219220            setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    220             add(buildHtmlPanel(preferenceSetting.getTitle(), Font.BOLD),
    221                     GBC.eol().insets(0, 5, 0, 10).anchor(GBC.NORTHWEST).fill(GBC.HORIZONTAL));
    222             add(buildHtmlPanel(preferenceSetting.getDescription(), Font.ITALIC),
    223                     GBC.eol().insets(5, 0, 5, 20).fill(GBC.HORIZONTAL));
    224         }
    225 
    226         private static JLabel buildHtmlPanel(String text, int fontStyle) {
    227             JLabel label = new JLabel("<html>" + text + "</html>");
    228             label.setFont(label.getFont().deriveFont(fontStyle));
    229             return label;
     221            JPanel headerPanel = new JPanel(new BorderLayout());
     222            add(headerPanel, GBC.eop().fill(GBC.HORIZONTAL));
     223
     224            JLabel label = new JLabel("<html>" +
     225                    "<b>" + preferenceSetting.getTitle() + "</b><br>" +
     226                    "<i>" + preferenceSetting.getDescription() + "</i></html>");
     227            label.setFont(label.getFont().deriveFont(Font.PLAIN));
     228            headerPanel.add(label, BorderLayout.CENTER);
     229
     230            ImageIcon icon = preferenceSetting.getIcon(ImageProvider.ImageSizes.SETTINGS_TAB);
     231            headerPanel.add(new JLabel(icon), BorderLayout.EAST);
    230232        }
    231233
     
    499501        int position = index;
    500502        for (PreferenceTab tab : tabs) {
    501             if (tab.getTabPreferenceSetting().equals(tps) && tps.getIconName() != null) {
    502                 insertTab(null, icon, tab.getComponent(), tps.getTooltip(), position++);
    503             } else if (tab.getTabPreferenceSetting().equals(tps)) {
    504                 insertTab(tps.getTitle(), null, tab.getComponent(), tps.getTooltip(), position++);
     503            if (tab.getTabPreferenceSetting().equals(tps)) {
     504                insertTab(tps.getTitle(), icon, tab.getComponent(), tps.getTooltip(), position++);
    505505            }
    506506        }
     
    519519                TabPreferenceSetting tps = (TabPreferenceSetting) setting;
    520520                if (expert || !tps.isExpert()) {
    521                     // Get icon
    522                     String iconName = tps.getIconName();
    523                     ImageIcon icon = null;
    524 
    525                     if (iconName != null && !iconName.isEmpty()) {
    526                         icon = ImageProvider.get("preferences", iconName, ImageProvider.ImageSizes.SETTINGS_TAB);
    527                     }
     521                    ImageIcon icon = tps.getIcon(ImageProvider.ImageSizes.LARGEICON);
    528522                    if (settingsInitialized.contains(tps)) {
    529523                        // If it has been initialized, add corresponding tab(s)
    530524                        addGUITabsForSetting(icon, tps);
    531                     } else if (tps.getIconName() != null) {
     525                    } else {
    532526                        // If it has not been initialized, create an empty tab with only icon and tooltip
    533                         addTab(null, icon, new PreferencePanel(tps), tps.getTooltip());
    534                     } else {
    535                         addTab(tps.getTitle(), null, new PreferencePanel(tps), tps.getTooltip());
     527                        addTab(tps.getTitle(), icon, new PreferencePanel(tps), tps.getTooltip());
    536528                    }
    537529                }
  • trunk/src/org/openstreetmap/josm/gui/preferences/TabPreferenceSetting.java

    r16966 r17178  
    33
    44import java.awt.Component;
     5
     6import javax.swing.ImageIcon;
     7
     8import org.openstreetmap.josm.tools.ImageProvider;
    59
    610/**
     
    1620     */
    1721    String getIconName();
     22
     23    /**
     24     * Returns the icon for this preference setting
     25     * @param size the icon size
     26     * @return the icon or {@code null}
     27     */
     28    default ImageIcon getIcon(ImageProvider.ImageSizes size) {
     29        String iconName = getIconName();
     30        return iconName == null || iconName.isEmpty() ? null : ImageProvider.get("preferences", iconName, size);
     31    }
    1832
    1933    /**
Note: See TracChangeset for help on using the changeset viewer.