Changeset 10878 in josm


Ignore:
Timestamp:
2016-08-23T20:31:46+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13423 - Convert properties cell renderer to new color preferences (patch by michael2402, modified) - gsoc-core

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java

    r10043 r10878  
    1717import javax.swing.JTable;
    1818import javax.swing.UIDefaults;
     19import javax.swing.UIManager;
    1920import javax.swing.table.DefaultTableCellRenderer;
    2021import javax.swing.table.TableCellRenderer;
    2122
    22 import org.openstreetmap.josm.Main;
    2323import org.openstreetmap.josm.data.osm.OsmPrimitive;
     24import org.openstreetmap.josm.data.preferences.BooleanProperty;
     25import org.openstreetmap.josm.data.preferences.CachingProperty;
     26import org.openstreetmap.josm.data.preferences.ColorProperty;
    2427
    2528/**
     
    2932public class PropertiesCellRenderer extends DefaultTableCellRenderer {
    3033
     34    private static final CachingProperty<Color> SELECTED_FG
     35            = new ColorProperty(marktr("Discardable key: selection Foreground"), Color.GRAY).cached();
     36    private static final CachingProperty<Color> SELECTED_BG;
     37    private static final CachingProperty<Color> NORMAL_FG
     38            = new ColorProperty(marktr("Discardable key: foreground"), Color.GRAY).cached();
     39    private static final CachingProperty<Color> NORMAL_BG;
     40    private static final CachingProperty<Boolean> DISCARDABLE
     41            = new BooleanProperty("display.discardable-keys", false).cached();
     42
     43    static {
     44        UIDefaults defaults = UIManager.getDefaults();
     45        SELECTED_BG = new ColorProperty(marktr("Discardable key: selection Background"),
     46                defaults.getColor("Table.selectionBackground")).cached();
     47        NORMAL_BG = new ColorProperty(marktr("Discardable key: background"),
     48                defaults.getColor("Table.background")).cached();
     49    }
     50
    3151    private final Collection<TableCellRenderer> customRenderer = new CopyOnWriteArrayList<>();
    3252
    3353    private static void setColors(Component c, String key, boolean isSelected) {
    34         UIDefaults defaults = javax.swing.UIManager.getDefaults();
     54
    3555        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             }
     56            c.setForeground((isSelected ? SELECTED_FG : NORMAL_FG).get());
     57            c.setBackground((isSelected ? SELECTED_BG : NORMAL_BG).get());
    4458        } else {
     59            UIDefaults defaults = UIManager.getDefaults();
    4560            c.setForeground(defaults.getColor("Table."+(isSelected ? "selectionF" : "f")+"oreground"));
    4661            c.setBackground(defaults.getColor("Table."+(isSelected ? "selectionB" : "b")+"ackground"));
     
    5671            }
    5772        }
    58         Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    5973        if (value == null)
    6074            return this;
     75        Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    6176        if (c instanceof JLabel) {
    6277            String str = null;
     
    7792                    StringBuilder sb = new StringBuilder("<");
    7893                    if (otherCount == 1) {
    79                         for (Map.Entry<?, ?> entry : v.entrySet()) { // Find the non-blank value in the map
    80                             if (!Objects.equals(entry.getKey(), "")) {
    81                                 /* 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                         }
     94                        // Find the non-blank value in the map
     95                        v.entrySet().stream().filter(entry -> !Objects.equals(entry.getKey(), ""))
     96                                /* I18n: properties display partial string joined with comma, first is count, second is value */
     97                            .findAny().ifPresent(entry -> sb.append(tr("{0} ''{1}''", entry.getValue().toString(), entry.getKey())));
    8598                    } else {
    8699                        /* I18n: properties display partial string joined with comma */
     
    102115            ((JLabel) c).putClientProperty("html.disable", Boolean.TRUE); // Fix #8730
    103116            ((JLabel) c).setText(str);
    104             if (Main.pref.getBoolean("display.discardable-keys", false)) {
     117            if (DISCARDABLE.get()) {
    105118                String key = null;
    106119                if (column == 0) {
Note: See TracChangeset for help on using the changeset viewer.