1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.history;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Component;
|
---|
6 | import java.util.logging.Logger;
|
---|
7 |
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.JTable;
|
---|
10 | import javax.swing.table.TableCellRenderer;
|
---|
11 |
|
---|
12 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * The {@see TableCellRenderer} for a list of tagsin {@see HistoryBrower}
|
---|
16 | *
|
---|
17 | */
|
---|
18 | public class TagTableCellRenderer extends JLabel implements TableCellRenderer {
|
---|
19 |
|
---|
20 | static private Logger logger = Logger.getLogger(TagTableCellRenderer.class.getName());
|
---|
21 |
|
---|
22 | public final static Color BGCOLOR_SELECTED = new Color(143,170,255);
|
---|
23 | public final static Color BGCOLOR_DIFFERENCE = new Color(255,197,197);
|
---|
24 |
|
---|
25 | public TagTableCellRenderer() {
|
---|
26 | setOpaque(true);
|
---|
27 | setForeground(Color.BLACK);
|
---|
28 | }
|
---|
29 |
|
---|
30 | protected void renderName(String key, HistoryBrowserModel.TagTableModel model, boolean isSelected) {
|
---|
31 | String text = key;
|
---|
32 | Color bgColor = Color.WHITE;
|
---|
33 | if (! model.hasTag(key)) {
|
---|
34 | text = tr("<undefined>");
|
---|
35 | bgColor = BGCOLOR_DIFFERENCE;
|
---|
36 | } else if (!model.oppositeHasTag(key)) {
|
---|
37 | bgColor = BGCOLOR_DIFFERENCE;
|
---|
38 | }
|
---|
39 | if (isSelected) {
|
---|
40 | bgColor = BGCOLOR_SELECTED;
|
---|
41 | }
|
---|
42 | setText(text);
|
---|
43 | setToolTipText(text);
|
---|
44 | setBackground(bgColor);
|
---|
45 | }
|
---|
46 |
|
---|
47 | protected void renderValue(String key, HistoryBrowserModel.TagTableModel model, boolean isSelected) {
|
---|
48 | String text = "";
|
---|
49 | Color bgColor = Color.WHITE;
|
---|
50 | if (! model.hasTag(key)) {
|
---|
51 | text = tr("<undefined>");
|
---|
52 | bgColor = BGCOLOR_DIFFERENCE;
|
---|
53 | } else {
|
---|
54 | text = model.getValue(key);
|
---|
55 | if (!model.hasSameValueAsOpposite(key)) {
|
---|
56 | bgColor = BGCOLOR_DIFFERENCE;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | if (isSelected) {
|
---|
60 | bgColor = BGCOLOR_SELECTED;
|
---|
61 | }
|
---|
62 |
|
---|
63 | setText(text);
|
---|
64 | setToolTipText(text);
|
---|
65 | setBackground(bgColor);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
69 | int row, int column) {
|
---|
70 |
|
---|
71 | String key = (String)value;
|
---|
72 | HistoryBrowserModel.TagTableModel model = getTagTableModel(table);
|
---|
73 |
|
---|
74 | switch(column) {
|
---|
75 | case 0:
|
---|
76 | // the name column
|
---|
77 | renderName(key, model, isSelected);
|
---|
78 | break;
|
---|
79 | case 1:
|
---|
80 | // the value column
|
---|
81 | renderValue(key, model, isSelected);
|
---|
82 | break;
|
---|
83 | }
|
---|
84 |
|
---|
85 | return this;
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected HistoryBrowserModel.TagTableModel getTagTableModel(JTable table) {
|
---|
89 | return (HistoryBrowserModel.TagTableModel) table.getModel();
|
---|
90 | }
|
---|
91 | }
|
---|