1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 |
|
---|
6 | import javax.swing.JLabel;
|
---|
7 | import javax.swing.JTable;
|
---|
8 | import javax.swing.UIManager;
|
---|
9 | import javax.swing.table.TableCellRenderer;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
12 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * This is the {@link TableCellRenderer} used in the tables of
|
---|
16 | * {@link org.openstreetmap.josm.gui.conflict.pair.relation.RelationMemberMerger}.
|
---|
17 | *
|
---|
18 | */
|
---|
19 | public abstract class MemberTableCellRenderer extends JLabel implements TableCellRenderer {
|
---|
20 | public static final Color BGCOLOR_IN_JOSM_SELECTION = new Color(235, 255, 177);
|
---|
21 |
|
---|
22 | public static final Color BGCOLOR_DOUBLE_ENTRY = new Color(254, 226, 214);
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * constructor
|
---|
26 | */
|
---|
27 | public MemberTableCellRenderer() {
|
---|
28 | setIcon(null);
|
---|
29 | setOpaque(true);
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * reset the renderer
|
---|
34 | */
|
---|
35 | protected void reset() {
|
---|
36 | setBackground(UIManager.getColor("Table.background"));
|
---|
37 | setForeground(UIManager.getColor("Table.foreground"));
|
---|
38 | setBorder(null);
|
---|
39 | setIcon(null);
|
---|
40 | setToolTipText(null);
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected void renderBackgroundForeground(MemberTableModel model, OsmPrimitive primitive, boolean isSelected) {
|
---|
44 | Color bgc = UIManager.getColor("Table.background");
|
---|
45 | if (isSelected) {
|
---|
46 | bgc = UIManager.getColor("Table.selectionBackground");
|
---|
47 | } else if (primitive != null && model.isInJosmSelection(primitive)) {
|
---|
48 | bgc = BGCOLOR_IN_JOSM_SELECTION;
|
---|
49 | } else if (primitive != null && model.getNumMembersWithPrimitive(primitive) > 1) {
|
---|
50 | bgc = BGCOLOR_DOUBLE_ENTRY;
|
---|
51 | }
|
---|
52 | GuiHelper.setBackgroundReadable(this, bgc);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * replies the model
|
---|
57 | * @param table the table
|
---|
58 | * @return the table model
|
---|
59 | */
|
---|
60 | protected MemberTableModel getModel(JTable table) {
|
---|
61 | return (MemberTableModel) table.getModel();
|
---|
62 | }
|
---|
63 | }
|
---|