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.gui.conflict.ConflictColors;
|
---|
19 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * This is a {@link TableCellRenderer} for {@link MultiValueResolutionDecision}s.
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public class MultiValueCellRenderer extends JLabel implements TableCellRenderer {
|
---|
26 |
|
---|
27 | private ImageIcon iconDecided;
|
---|
28 | private ImageIcon iconUndecided;
|
---|
29 | private DefaultComboBoxModel model;
|
---|
30 | private JComboBox cbDecisionRenderer;
|
---|
31 |
|
---|
32 | public MultiValueCellRenderer() {
|
---|
33 | setOpaque(true);
|
---|
34 | iconDecided = ImageProvider.get("dialogs/conflict", "tagconflictresolved");
|
---|
35 | iconUndecided = ImageProvider.get("dialogs/conflict", "tagconflictunresolved");
|
---|
36 | cbDecisionRenderer = new JComboBox(model = new DefaultComboBoxModel());
|
---|
37 | }
|
---|
38 |
|
---|
39 | protected void renderColors(MultiValueResolutionDecision decision, boolean selected) {
|
---|
40 | if (selected) {
|
---|
41 | setForeground(UIManager.getColor("Table.selectionForeground"));
|
---|
42 | setBackground(UIManager.getColor("Table.selectionBackground"));
|
---|
43 | } else{
|
---|
44 | switch(decision.getDecisionType()) {
|
---|
45 | case UNDECIDED:
|
---|
46 | setForeground(UIManager.getColor("Table.foreground"));
|
---|
47 | setBackground(ConflictColors.BGCOLOR_UNDECIDED.get());
|
---|
48 | break;
|
---|
49 | case KEEP_NONE:
|
---|
50 | setForeground(UIManager.getColor("Panel.foreground"));
|
---|
51 | setBackground(UIManager.getColor("Panel.background"));
|
---|
52 | break;
|
---|
53 | default:
|
---|
54 | setForeground(UIManager.getColor("Table.foreground"));
|
---|
55 | setBackground(UIManager.getColor("Table.background"));
|
---|
56 | break;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected void renderValue(MultiValueResolutionDecision decision) {
|
---|
62 | model.removeAllElements();
|
---|
63 | switch(decision.getDecisionType()) {
|
---|
64 | case UNDECIDED:
|
---|
65 | model.addElement(tr("Choose a value"));
|
---|
66 | cbDecisionRenderer.setFont(getFont().deriveFont(Font.ITALIC));
|
---|
67 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
68 | break;
|
---|
69 | case KEEP_ONE:
|
---|
70 | model.addElement(decision.getChosenValue());
|
---|
71 | cbDecisionRenderer.setFont(getFont());
|
---|
72 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
73 | break;
|
---|
74 | case KEEP_NONE:
|
---|
75 | model.addElement(tr("deleted"));
|
---|
76 | cbDecisionRenderer.setFont(getFont().deriveFont(Font.ITALIC));
|
---|
77 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
78 | break;
|
---|
79 | case KEEP_ALL:
|
---|
80 | model.addElement(decision.getChosenValue());
|
---|
81 | cbDecisionRenderer.setFont(getFont());
|
---|
82 | cbDecisionRenderer.setSelectedIndex(0);
|
---|
83 | break;
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Sets the text of the tooltip for both renderers, this (the JLabel) and the combobox renderer.
|
---|
89 | */
|
---|
90 | protected void renderToolTipText(MultiValueResolutionDecision decision) {
|
---|
91 | switch(decision.getDecisionType()) {
|
---|
92 | case UNDECIDED:
|
---|
93 | {
|
---|
94 | String toolTipText = tr("Please decide which values to keep");
|
---|
95 | setToolTipText(toolTipText);
|
---|
96 | cbDecisionRenderer.setToolTipText(toolTipText);
|
---|
97 | break;
|
---|
98 | }
|
---|
99 | case KEEP_ONE:
|
---|
100 | {
|
---|
101 | String toolTipText = tr("Value ''{0}'' is going to be applied for key ''{1}''", decision.getChosenValue(), decision.getKey());
|
---|
102 | setToolTipText(toolTipText);
|
---|
103 | cbDecisionRenderer.setToolTipText(toolTipText);
|
---|
104 | break;
|
---|
105 | }
|
---|
106 | case KEEP_NONE:
|
---|
107 | {
|
---|
108 | String toolTipText = tr("The key ''{0}'' and all its values are going to be removed", decision.getKey());
|
---|
109 | setToolTipText(toolTipText);
|
---|
110 | cbDecisionRenderer.setToolTipText(toolTipText);
|
---|
111 | break;
|
---|
112 | }
|
---|
113 | case KEEP_ALL:
|
---|
114 | String toolTipText = tr("All values joined as ''{0}'' are going to be applied for key ''{1}''", decision.getChosenValue(), decision.getKey());
|
---|
115 | setToolTipText(toolTipText);
|
---|
116 | cbDecisionRenderer.setToolTipText(toolTipText);
|
---|
117 | break;
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | protected void reset() {
|
---|
122 | setFont(UIManager.getFont("Table.font"));
|
---|
123 | setIcon(null);
|
---|
124 | setText("");
|
---|
125 | }
|
---|
126 |
|
---|
127 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
128 | int row, int column) {
|
---|
129 |
|
---|
130 | reset();
|
---|
131 | if (value == null)
|
---|
132 | return this;
|
---|
133 |
|
---|
134 | MultiValueResolutionDecision decision = (MultiValueResolutionDecision)value;
|
---|
135 | renderColors(decision,isSelected);
|
---|
136 | renderToolTipText(decision);
|
---|
137 | switch(column) {
|
---|
138 | case 0:
|
---|
139 | if (decision.isDecided()) {
|
---|
140 | setIcon(iconDecided);
|
---|
141 | } else {
|
---|
142 | setIcon(iconUndecided);
|
---|
143 | }
|
---|
144 | return this;
|
---|
145 |
|
---|
146 | case 1:
|
---|
147 | setText(decision.getKey());
|
---|
148 | return this;
|
---|
149 |
|
---|
150 | case 2:
|
---|
151 | renderValue(decision);
|
---|
152 | return cbDecisionRenderer;
|
---|
153 | }
|
---|
154 | return this;
|
---|
155 | }
|
---|
156 | }
|
---|