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 |
|
---|
9 | import javax.swing.ImageIcon;
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JTable;
|
---|
12 | import javax.swing.table.TableCellRenderer;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * The {@see TableCellRenderer} for a list of nodes in [@see HistoryBrower}
|
---|
18 | *
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer {
|
---|
22 |
|
---|
23 | public final static Color BGCOLOR_EMPTY_ROW = new Color(234,234,234);
|
---|
24 | public final static Color BGCOLOR_NOT_IN_OPPOSITE = new Color(255,197,197);
|
---|
25 | public final static Color BGCOLOR_IN_OPPOSITE = new Color(255,234,213);
|
---|
26 | public final static Color BGCOLOR_SELECTED = new Color(143,170,255);
|
---|
27 |
|
---|
28 | private ImageIcon nodeIcon;
|
---|
29 |
|
---|
30 | public NodeListTableCellRenderer(){
|
---|
31 | setOpaque(true);
|
---|
32 | nodeIcon = ImageProvider.get("data", "node");
|
---|
33 | setIcon(nodeIcon);
|
---|
34 | }
|
---|
35 |
|
---|
36 | protected void renderNode(HistoryBrowserModel.NodeListTableModel model, Long nodeId, int row, boolean isSelected) {
|
---|
37 | String text = "";
|
---|
38 | Color bgColor = Color.WHITE;
|
---|
39 | if (nodeId == null) {
|
---|
40 | text = "";
|
---|
41 | bgColor = BGCOLOR_EMPTY_ROW;
|
---|
42 | setIcon(null);
|
---|
43 | } else {
|
---|
44 | text = tr("Node {0}", nodeId.toString());
|
---|
45 | setIcon(nodeIcon);
|
---|
46 | if (model.isSameInOppositeWay(row)) {
|
---|
47 | bgColor = Color.WHITE;
|
---|
48 | } else if (model.isInOppositeWay(row)) {
|
---|
49 | bgColor = BGCOLOR_IN_OPPOSITE;
|
---|
50 | } else {
|
---|
51 | bgColor = BGCOLOR_NOT_IN_OPPOSITE;
|
---|
52 | }
|
---|
53 | }
|
---|
54 | if (isSelected) {
|
---|
55 | bgColor = BGCOLOR_SELECTED;
|
---|
56 | }
|
---|
57 | setText(text);
|
---|
58 | setBackground(bgColor);
|
---|
59 | }
|
---|
60 |
|
---|
61 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
62 | int row, int column) {
|
---|
63 | HistoryBrowserModel.NodeListTableModel model = getNodeListTableModel(table);
|
---|
64 | Long nodeId = (Long)value;
|
---|
65 | renderNode(model, nodeId, row, isSelected);
|
---|
66 | return this;
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected HistoryBrowserModel.NodeListTableModel getNodeListTableModel(JTable table) {
|
---|
70 | return (HistoryBrowserModel.NodeListTableModel) table.getModel();
|
---|
71 | }
|
---|
72 | }
|
---|