Ticket #13423: patch-clean-properties-cell-renderer.patch

File patch-clean-properties-cell-renderer.patch, 5.5 KB (added by michael2402, 8 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java
    index 7eb11e4..3965738 100644
    a b import javax.swing.UIDefaults;  
    1919import javax.swing.table.DefaultTableCellRenderer;
    2020import javax.swing.table.TableCellRenderer;
    2121
    22 import org.openstreetmap.josm.Main;
    2322import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.data.preferences.BooleanProperty;
     24import org.openstreetmap.josm.data.preferences.CachingProperty;
     25import org.openstreetmap.josm.data.preferences.ColorProperty;
    2426
    2527/**
    2628 * Cell renderer of tags table.
    import org.openstreetmap.josm.data.osm.OsmPrimitive;  
    2830 */
    2931public class PropertiesCellRenderer extends DefaultTableCellRenderer {
    3032
     33    private static final CachingProperty<Color> SELECTED_FG
     34            = new ColorProperty(marktr("Discardable key: selection Foreground"), Color.GRAY).cached();
     35    private static final CachingProperty<Color> SELECTED_BG;
     36    private static final CachingProperty<Color> NORMAL_FG
     37            = new ColorProperty(marktr("Discardable key: foreground"), Color.GRAY).cached();
     38    private static final CachingProperty<Color> NORMAL_BG;
     39    private static final CachingProperty<Boolean> DISCARDABLE
     40            = new BooleanProperty("display.discardable-keys", false).cached();
     41
     42    static {
     43        UIDefaults defaults = javax.swing.UIManager.getDefaults();
     44        SELECTED_BG = new ColorProperty(marktr("Discardable key: selection Background"),
     45                defaults.getColor("Table.selectionBackground")).cached();
     46        NORMAL_BG = new ColorProperty(marktr("Discardable key: background"),
     47                defaults.getColor("Table.background")).cached();
     48    }
     49
    3150    private final Collection<TableCellRenderer> customRenderer = new CopyOnWriteArrayList<>();
    3251
    3352    private static void setColors(Component c, String key, boolean isSelected) {
    34         UIDefaults defaults = javax.swing.UIManager.getDefaults();
     53
    3554        if (OsmPrimitive.getDiscardableKeys().contains(key)) {
    36             if (isSelected) {
    37                 c.setForeground(Main.pref.getColor(marktr("Discardable key: selection Foreground"), Color.GRAY));
    38                 c.setBackground(Main.pref.getColor(marktr("Discardable key: selection Background"),
    39                         defaults.getColor("Table.selectionBackground")));
    40             } else {
    41                 c.setForeground(Main.pref.getColor(marktr("Discardable key: foreground"), Color.GRAY));
    42                 c.setBackground(Main.pref.getColor(marktr("Discardable key: background"), defaults.getColor("Table.background")));
    43             }
     55            CachingProperty<Color> fg = isSelected ? SELECTED_FG : NORMAL_FG;
     56            CachingProperty<Color> bg = isSelected ? SELECTED_BG : NORMAL_BG;
     57            c.setForeground(fg.get());
     58            c.setBackground(bg.get());
    4459        } else {
     60            UIDefaults defaults = javax.swing.UIManager.getDefaults();
    4561            c.setForeground(defaults.getColor("Table."+(isSelected ? "selectionF" : "f")+"oreground"));
    4662            c.setBackground(defaults.getColor("Table."+(isSelected ? "selectionB" : "b")+"ackground"));
    4763        }
    public class PropertiesCellRenderer extends DefaultTableCellRenderer {  
    5571                return component;
    5672            }
    5773        }
    58         Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    5974        if (value == null)
    6075            return this;
     76
     77        Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    6178        if (c instanceof JLabel) {
    6279            String str = null;
    6380            if (value instanceof String) {
    public class PropertiesCellRenderer extends DefaultTableCellRenderer {  
    7693                    }
    7794                    StringBuilder sb = new StringBuilder("<");
    7895                    if (otherCount == 1) {
    79                         for (Map.Entry<?, ?> entry : v.entrySet()) { // Find the non-blank value in the map
    80                             if (!Objects.equals(entry.getKey(), "")) {
     96                        // Find the non-blank value in the map
     97                        v.entrySet().stream().filter(entry -> !Objects.equals(entry.getKey(), ""))
    8198                                /* I18n: properties display partial string joined with comma, frst is count, second is value */
    82                                 sb.append(tr("{0} ''{1}''", entry.getValue().toString(), entry.getKey()));
    83                             }
    84                         }
     99                            .findAny().ifPresent(entry -> sb.append(tr("{0} ''{1}''", entry.getValue().toString(), entry.getKey())));
    85100                    } else {
    86101                        /* I18n: properties display partial string joined with comma */
    87102                        sb.append(trn("{0} different", "{0} different", otherCount, otherCount));
    public class PropertiesCellRenderer extends DefaultTableCellRenderer {  
    101116            }
    102117            ((JLabel) c).putClientProperty("html.disable", Boolean.TRUE); // Fix #8730
    103118            ((JLabel) c).setText(str);
    104             if (Main.pref.getBoolean("display.discardable-keys", false)) {
     119            if (DISCARDABLE.get()) {
    105120                String key = null;
    106121                if (column == 0) {
    107122                    key = str;