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