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