1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.properties;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.Color;
|
---|
8 | import java.awt.Component;
|
---|
9 | import java.awt.Font;
|
---|
10 | import java.util.Map;
|
---|
11 |
|
---|
12 | import javax.swing.JLabel;
|
---|
13 | import javax.swing.JTable;
|
---|
14 | import javax.swing.UIDefaults;
|
---|
15 | import javax.swing.table.DefaultTableCellRenderer;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.Main;
|
---|
18 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Cell renderer of tags table.
|
---|
22 | * @since 6314
|
---|
23 | */
|
---|
24 | public class PropertiesCellRenderer extends DefaultTableCellRenderer {
|
---|
25 |
|
---|
26 | private void setColors(Component c, String key, boolean isSelected) {
|
---|
27 | UIDefaults defaults = javax.swing.UIManager.getDefaults();
|
---|
28 | if (OsmPrimitive.getDiscardableKeys().contains(key)) {
|
---|
29 | if (isSelected) {
|
---|
30 | c.setForeground(Main.pref.getColor(marktr("Discardable key: selection Foreground"), Color.GRAY));
|
---|
31 | c.setBackground(Main.pref.getColor(marktr("Discardable key: selection Background"), defaults.getColor("Table.selectionBackground")));
|
---|
32 | } else {
|
---|
33 | c.setForeground(Main.pref.getColor(marktr("Discardable key: foreground"), Color.GRAY));
|
---|
34 | c.setBackground(Main.pref.getColor(marktr("Discardable key: background"), defaults.getColor("Table.background")));
|
---|
35 | }
|
---|
36 | } else {
|
---|
37 | c.setForeground(defaults.getColor("Table."+(isSelected ? "selectionF" : "f")+"oreground"));
|
---|
38 | c.setBackground(defaults.getColor("Table."+(isSelected ? "selectionB" : "b")+"ackground"));
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
44 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
45 | if (value == null)
|
---|
46 | return this;
|
---|
47 | if (c instanceof JLabel) {
|
---|
48 | String str = null;
|
---|
49 | if (value instanceof String) {
|
---|
50 | str = (String) value;
|
---|
51 | } else if (value instanceof Map<?, ?>) {
|
---|
52 | Map<?, ?> v = (Map<?, ?>) value;
|
---|
53 | if (v.size() != 1) {
|
---|
54 | str=tr("<different>");
|
---|
55 | c.setFont(c.getFont().deriveFont(Font.ITALIC));
|
---|
56 | } else {
|
---|
57 | final Map.Entry<?, ?> entry = v.entrySet().iterator().next();
|
---|
58 | str = (String) entry.getKey();
|
---|
59 | }
|
---|
60 | }
|
---|
61 | ((JLabel)c).putClientProperty("html.disable", Boolean.TRUE); // Fix #8730
|
---|
62 | ((JLabel)c).setText(str);
|
---|
63 | if (Main.pref.getBoolean("display.discardable-keys", false)) {
|
---|
64 | String key = null;
|
---|
65 | if (column == 0) {
|
---|
66 | key = str;
|
---|
67 | } else if (column == 1) {
|
---|
68 | Object value0 = table.getModel().getValueAt(row, 0);
|
---|
69 | if (value0 instanceof String) {
|
---|
70 | key = (String) value0;
|
---|
71 | }
|
---|
72 | }
|
---|
73 | setColors(c, key, isSelected);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | return c;
|
---|
77 | }
|
---|
78 | }
|
---|