Changeset 15211 in josm


Ignore:
Timestamp:
2019-07-06T22:15:55+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #13458 - display external resources icons in the preferences

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/sources/ExtendedSourceEntry.java

    r12825 r15211  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import org.openstreetmap.josm.tools.ImageResource;
    67import org.openstreetmap.josm.tools.Utils;
    78
     
    1718    /** author name used for display */
    1819    public String author;
     20    /** icon used for display */
     21    public ImageResource icon;
    1922    /** webpage link used for display */
    2023    public String link;
  • trunk/src/org/openstreetmap/josm/data/preferences/sources/MapPaintPrefHelper.java

    r12846 r15211  
    77import java.util.Arrays;
    88import java.util.Collection;
    9 import java.util.HashMap;
    109import java.util.List;
    1110import java.util.Map;
     
    1413
    1514import org.openstreetmap.josm.spi.preferences.Config;
     15import org.openstreetmap.josm.tools.ImageProvider;
    1616import org.openstreetmap.josm.tools.Utils;
    1717
     
    8484        defJosmMapcss.active = true;
    8585        defJosmMapcss.name = "standard";
     86        defJosmMapcss.icon = new ImageProvider("logo").getResource();
    8687        defJosmMapcss.title = tr("JOSM default (MapCSS)");
    8788        defJosmMapcss.description = tr("Internal style to be used as base for runtime switchable overlay styles");
     
    8990        defPL2.active = false;
    9091        defPL2.name = "standard";
     92        defPL2.icon = new ImageProvider("dialogs/mappaint", "pl2_small").getResource();
    9193        defPL2.title = tr("Potlatch 2");
    9294        defPL2.description = tr("the main Potlatch 2 style");
     
    9799    @Override
    98100    public Map<String, String> serialize(SourceEntry entry) {
    99         Map<String, String> res = new HashMap<>();
    100         res.put("url", entry.url == null ? "" : entry.url);
    101         res.put("title", entry.title == null ? "" : entry.title);
     101        Map<String, String> res = super.serialize(entry);
    102102        res.put("active", Boolean.toString(entry.active));
    103103        if (entry.name != null) {
  • trunk/src/org/openstreetmap/josm/data/preferences/sources/PresetPrefHelper.java

    r12825 r15211  
    66import java.util.Collection;
    77import java.util.Collections;
    8 import java.util.HashMap;
    9 import java.util.Map;
     8
     9import org.openstreetmap.josm.tools.ImageProvider;
    1010
    1111/**
     
    3131        ExtendedSourceEntry i = new ExtendedSourceEntry(type, "defaultpresets.xml", "resource://data/defaultpresets.xml");
    3232        i.title = tr("Internal Preset");
     33        i.icon = new ImageProvider("logo").getResource();
    3334        i.description = tr("The default preset for JOSM");
    3435        return Collections.singletonList(i);
    3536    }
    36 
    37     @Override
    38     public Map<String, String> serialize(SourceEntry entry) {
    39         Map<String, String> res = new HashMap<>();
    40         res.put("url", entry.url);
    41         res.put("title", entry.title == null ? "" : entry.title);
    42         return res;
    43     }
    44 
    45     @Override
    46     public SourceEntry deserialize(Map<String, String> s) {
    47         return new SourceEntry(type, s.get("url"), null, s.get("title"), true);
    48     }
    4937}
  • trunk/src/org/openstreetmap/josm/data/preferences/sources/SourcePrefHelper.java

    r15099 r15211  
    88import java.util.List;
    99import java.util.Map;
     10import java.util.Optional;
    1011import java.util.Set;
    1112import java.util.stream.Collectors;
     
    4445     * @return map (key=value)
    4546     */
    46     public abstract Map<String, String> serialize(SourceEntry entry);
     47    public Map<String, String> serialize(SourceEntry entry) {
     48        Map<String, String> res = new HashMap<>();
     49        res.put("url", entry.url);
     50        res.put("title", entry.title == null ? "" : entry.title);
     51        return res;
     52    }
    4753
    4854    /**
     
    5157     * @return source entry
    5258     */
    53     public abstract SourceEntry deserialize(Map<String, String> entryStr);
     59    public SourceEntry deserialize(Map<String, String> entryStr) {
     60        return new SourceEntry(type,
     61                entryStr.get("url"),
     62                entryStr.get("name"),
     63                entryStr.get("title"),
     64                Optional.ofNullable(entryStr.get("active")).map(Boolean::parseBoolean).orElse(true));
     65    }
    5466
    5567    /**
  • trunk/src/org/openstreetmap/josm/data/preferences/sources/ValidatorPrefHelper.java

    r14828 r15211  
    66import java.util.ArrayList;
    77import java.util.Collection;
    8 import java.util.HashMap;
    98import java.util.List;
    109import java.util.Map;
     
    1211import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1312import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
     13import org.openstreetmap.josm.tools.ImageProvider;
    1414
    1515/**
     
    8686        ExtendedSourceEntry i = new ExtendedSourceEntry(type, filename+".mapcss", "resource://data/validator/"+filename+".mapcss");
    8787        i.title = title;
     88        i.icon = new ImageProvider("logo").getResource();
    8889        i.description = description;
    8990        defaults.add(i);
     
    9293    @Override
    9394    public Map<String, String> serialize(SourceEntry entry) {
    94         Map<String, String> res = new HashMap<>();
    95         res.put("url", entry.url);
    96         res.put("title", entry.title == null ? "" : entry.title);
     95        Map<String, String> res = super.serialize(entry);
    9796        res.put("active", Boolean.toString(entry.active));
    9897        return res;
    9998    }
    100 
    101     @Override
    102     public SourceEntry deserialize(Map<String, String> s) {
    103         return new SourceEntry(type, s.get("url"), null, s.get("title"), Boolean.parseBoolean(s.get("active")));
    104     }
    10599}
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r14214 r15211  
    33
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.marktr;
    56import static org.openstreetmap.josm.tools.I18n.tr;
    67
     8import java.awt.Color;
    79import java.awt.Component;
    810import java.awt.Dimension;
     
    4244import javax.swing.DefaultListModel;
    4345import javax.swing.DefaultListSelectionModel;
    44 import javax.swing.ImageIcon;
    4546import javax.swing.JButton;
    4647import javax.swing.JCheckBox;
     
    5859import javax.swing.ListCellRenderer;
    5960import javax.swing.ListSelectionModel;
     61import javax.swing.UIManager;
    6062import javax.swing.event.CellEditorListener;
    6163import javax.swing.event.ChangeEvent;
     
    7476import org.openstreetmap.josm.actions.ExtensionFileFilter;
    7577import org.openstreetmap.josm.data.Version;
     78import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    7679import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
    7780import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
     
    13531356    static class SourceEntryListCellRenderer extends JLabel implements ListCellRenderer<ExtendedSourceEntry> {
    13541357
    1355         private final ImageIcon GREEN_CHECK = ImageProvider.getIfAvailable("misc", "green_check");
    1356         private final ImageIcon GRAY_CHECK = ImageProvider.getIfAvailable("misc", "gray_check");
     1358        private static final NamedColorProperty SOURCE_ENTRY_ACTIVE_BACKGROUND_COLOR = new NamedColorProperty(
     1359                marktr("External resource entry: Active"),
     1360                new Color(200, 255, 200));
     1361        private static final NamedColorProperty SOURCE_ENTRY_INACTIVE_BACKGROUND_COLOR = new NamedColorProperty(
     1362                marktr("External resource entry: Inactive"),
     1363                new Color(200, 200, 200));
     1364
    13571365        private final Map<String, SourceEntry> entryByUrl = new HashMap<>();
    13581366
     
    13741382            setOpaque(true);
    13751383            setToolTipText(value.getTooltip());
    1376             final SourceEntry sourceEntry = entryByUrl.get(value.url);
    1377             setIcon(sourceEntry == null ? null : sourceEntry.active ? GREEN_CHECK : GRAY_CHECK);
     1384            if (!isSelected) {
     1385                final SourceEntry sourceEntry = entryByUrl.get(value.url);
     1386                GuiHelper.setBackgroundReadable(this, sourceEntry == null ? UIManager.getColor("Table.background") :
     1387                    sourceEntry.active ? SOURCE_ENTRY_ACTIVE_BACKGROUND_COLOR.get() : SOURCE_ENTRY_INACTIVE_BACKGROUND_COLOR.get());
     1388            }
     1389            final ImageSizes size = ImageSizes.TABLE;
     1390            setIcon(value.icon == null ? ImageProvider.getEmpty(size) : value.icon.getImageIcon(size.getImageDimension()));
    13781391            return this;
    13791392        }
     
    14751488                            } else if ("version".equals(key)) {
    14761489                                last.version = value;
     1490                            } else if ("icon".equals(key) && last.icon == null) {
     1491                                last.icon = new ImageProvider(value).setOptional(true).getResource();
    14771492                            } else if ("link".equals(key) && last.link == null) {
    14781493                                last.link = value;
Note: See TracChangeset for help on using the changeset viewer.