1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.tags;
|
---|
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 |
|
---|
10 | import javax.swing.DefaultComboBoxModel;
|
---|
11 | import javax.swing.ImageIcon;
|
---|
12 | import javax.swing.JComboBox;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JTable;
|
---|
15 | import javax.swing.UIManager;
|
---|
16 | import javax.swing.table.TableCellRenderer;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * This is a {@see TableCellRenderer} for {@see MultiValueResolutionDecision}s.
|
---|
22 | *
|
---|
23 | */
|
---|
24 | public class MultiValueCellRenderer extends JLabel implements TableCellRenderer {
|
---|
25 |
|
---|
26 | public final static Color BGCOLOR_UNDECIDED = new Color(255,197,197);
|
---|
27 |
|
---|
28 | private ImageIcon iconDecided;
|
---|
29 | private ImageIcon iconUndecided;
|
---|
30 | private DefaultComboBoxModel model;
|
---|
31 | private JComboBox cbDecisionRenderer;
|
---|
32 |
|
---|
33 | public MultiValueCellRenderer() {
|
---|
34 | setOpaque(true);
|
---|
35 | iconDecided = ImageProvider.get("dialogs/conflict", "tagconflictresolved");
|
---|
36 | iconUndecided = ImageProvider.get("dialogs/conflict", "tagconflictunresolved");
|
---|
37 | cbDecisionRenderer = new JComboBox(model = new DefaultComboBoxModel());
|
---|
38 | }
|
---|
39 |
|
---|
40 | protected void renderColors(MultiValueResolutionDecision decision, boolean selected) {
|
---|
41 | if (selected) {
|
---|
42 | setForeground(UIManager.getColor("Table.selectionForeground"));
|
---|
43 | setBackground(UIManager.getColor("Table.selectionBackground"));
|
---|
44 | } else{
|
---|
45 | switch(decision.getDecisionType()) {
|
---|
46 | case UNDECIDED:
|
---|
47 | setForeground(UIManager.getColor("Table.foreground"));
|
---|
48 | setBackground(BGCOLOR_UNDECIDED);
|
---|
49 | break;
|
---|
50 | case KEEP_NONE:
|
---|
51 | setForeground(UIManager.getColor("Panel.foreground"));
|
---|
52 | setBackground(UIManager.getColor("Panel.background"));
|
---|
53 | break;
|
---|
54 | default:
|
---|
55 | setForeground(UIManager.getColor("Table.foreground"));
|
---|
56 | setBackground(UIManager.getColor("Table.background"));
|
---|
57 | break;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected void renderValue(MultiValueResolutionDecision decision) {
|
---|
63 | model.removeAllElements();
|
---|
64 | switch(decision.getDecisionType()) {
|
---|
65 | case UNDECIDED:
|
---|
66 | model.addElement(tr("Choose a value"));
|
---|
67 | setFont(getFont().deriveFont(Font.ITALIC));
|
---|
68 | setToolTipText(tr("Please decide which values to keep"));
|
---|
69 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
70 | break;
|
---|
71 | case KEEP_ONE:
|
---|
72 | model.addElement(decision.getChosenValue());
|
---|
73 | setToolTipText(tr("Value ''{0}'' is going to be applied for key ''{1}''", decision.getChosenValue(), decision.getKey()));
|
---|
74 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
75 | break;
|
---|
76 | case KEEP_NONE:
|
---|
77 | model.addElement(tr("deleted"));
|
---|
78 | setFont(getFont().deriveFont(Font.ITALIC));
|
---|
79 | setToolTipText(tr("The key ''{0}'' and all its values are going to be removed", decision.getKey()));
|
---|
80 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
81 | break;
|
---|
82 | case KEEP_ALL:
|
---|
83 | model.addElement(decision.getChosenValue());
|
---|
84 | setToolTipText(tr("All values joined as ''{0}'' are going to be applied for key ''{1}''", decision.getChosenValue(), decision.getKey()));
|
---|
85 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
86 | break;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | protected void reset() {
|
---|
91 | setFont(UIManager.getFont("Table.font"));
|
---|
92 | setIcon(null);
|
---|
93 | setText("");
|
---|
94 | }
|
---|
95 |
|
---|
96 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
97 | int row, int column) {
|
---|
98 |
|
---|
99 | reset();
|
---|
100 | MultiValueResolutionDecision decision = (MultiValueResolutionDecision)value;
|
---|
101 | renderColors(decision,isSelected);
|
---|
102 | switch(column) {
|
---|
103 | case 0:
|
---|
104 | if (decision.isDecided()) {
|
---|
105 | setIcon(iconDecided);
|
---|
106 | } else {
|
---|
107 | setIcon(iconUndecided);
|
---|
108 | }
|
---|
109 | return this;
|
---|
110 |
|
---|
111 | case 1:
|
---|
112 | setText(decision.getKey());
|
---|
113 | return this;
|
---|
114 |
|
---|
115 | case 2:
|
---|
116 | renderValue(decision);
|
---|
117 | return cbDecisionRenderer;
|
---|
118 | }
|
---|
119 | return this;
|
---|
120 | }
|
---|
121 | }
|
---|