source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesCellRenderer.java@ 8189

Last change on this file since 8189 was 8189, checked in by stoecker, 9 years ago

see #11275 - i18n fixes

  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.properties;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6import static org.openstreetmap.josm.tools.I18n.trn;
7
8import java.awt.Color;
9import java.awt.Component;
10import java.awt.Font;
11import java.util.Map;
12
13import javax.swing.JLabel;
14import javax.swing.JTable;
15import javax.swing.UIDefaults;
16import javax.swing.table.DefaultTableCellRenderer;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.data.osm.OsmPrimitive;
20
21/**
22 * Cell renderer of tags table.
23 * @since 6314
24 */
25public class PropertiesCellRenderer extends DefaultTableCellRenderer {
26
27 private void setColors(Component c, String key, boolean isSelected) {
28 UIDefaults defaults = javax.swing.UIManager.getDefaults();
29 if (OsmPrimitive.getDiscardableKeys().contains(key)) {
30 if (isSelected) {
31 c.setForeground(Main.pref.getColor(marktr("Discardable key: selection Foreground"), Color.GRAY));
32 c.setBackground(Main.pref.getColor(marktr("Discardable key: selection Background"), defaults.getColor("Table.selectionBackground")));
33 } else {
34 c.setForeground(Main.pref.getColor(marktr("Discardable key: foreground"), Color.GRAY));
35 c.setBackground(Main.pref.getColor(marktr("Discardable key: background"), defaults.getColor("Table.background")));
36 }
37 } else {
38 c.setForeground(defaults.getColor("Table."+(isSelected ? "selectionF" : "f")+"oreground"));
39 c.setBackground(defaults.getColor("Table."+(isSelected ? "selectionB" : "b")+"ackground"));
40 }
41 }
42
43 @Override
44 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
45 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
46 if (value == null)
47 return this;
48 if (c instanceof JLabel) {
49 String str = null;
50 if (value instanceof String) {
51 str = (String) value;
52 } else if (value instanceof Map<?, ?>) {
53 Map<?, ?> v = (Map<?, ?>) value;
54 if (v.size() != 1) { // Multiple values: give user a short summary of the values
55 Integer blank_count;
56 Integer other_count;
57 if (v.get("") == null) {
58 blank_count = 0;
59 other_count = v.size();
60 } else {
61 blank_count = (Integer)v.get("");
62 other_count = v.size()-1;
63 }
64 str = "<";
65 if (other_count == 1) {
66 for (Map.Entry<?, ?> entry : v.entrySet()) { // Find the non-blank value in the map
67 if ( entry.getKey() != "") {
68 /* I18n: properties display partial string joined with comma, frst is count, second is value */
69 str += tr("{0} ''{1}''", entry.getValue().toString(), entry.getKey());
70 }
71 }
72 } else {
73 /* I18n: properties display partial string joined with comma */
74 str += trn("{0} different", "{0} different", other_count, other_count);
75 }
76 if(blank_count > 0) {
77 /* I18n: properties display partial string joined with comma */
78 str += trn(", {0} unset", ", {0} unset", blank_count, blank_count);
79 }
80 str += ">";
81 c.setFont(c.getFont().deriveFont(Font.ITALIC));
82
83 } else { // One value: display the value
84 final Map.Entry<?, ?> entry = v.entrySet().iterator().next();
85 str = (String) entry.getKey();
86 }
87 }
88 ((JLabel)c).putClientProperty("html.disable", Boolean.TRUE); // Fix #8730
89 ((JLabel)c).setText(str);
90 if (Main.pref.getBoolean("display.discardable-keys", false)) {
91 String key = null;
92 if (column == 0) {
93 key = str;
94 } else if (column == 1) {
95 Object value0 = table.getModel().getValueAt(row, 0);
96 if (value0 instanceof String) {
97 key = (String) value0;
98 }
99 }
100 setColors(c, key, isSelected);
101 }
102 }
103 return c;
104 }
105}
Note: See TracBrowser for help on using the repository browser.