1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation;
|
---|
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.Graphics;
|
---|
9 | import java.awt.Image;
|
---|
10 |
|
---|
11 | import javax.swing.JTable;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
14 |
|
---|
15 | public class MemberTableLinkedCellRenderer extends MemberTableCellRenderer {
|
---|
16 |
|
---|
17 | final static Image arrowUp = ImageProvider.get("dialogs", "arrowup").getImage();
|
---|
18 | final static Image arrowDown = ImageProvider.get("dialogs", "arrowdown").getImage();
|
---|
19 | private WayConnectionType value = new WayConnectionType();
|
---|
20 |
|
---|
21 | @Override
|
---|
22 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
23 | int row, int column) {
|
---|
24 | reset();
|
---|
25 | this.value = (WayConnectionType) value;
|
---|
26 | renderForeground(isSelected);
|
---|
27 | //setText(value.toString());
|
---|
28 | setToolTipText(((WayConnectionType)value).getToolTip());
|
---|
29 | renderBackground(getModel(table), null, isSelected);
|
---|
30 | return this;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void paintComponent(Graphics g) {
|
---|
35 | super.paintComponent(g);
|
---|
36 | if (value == null || value.invalid) {
|
---|
37 | return;
|
---|
38 | }
|
---|
39 |
|
---|
40 | Image image = null;
|
---|
41 | switch (value.direction) {
|
---|
42 | case 1:
|
---|
43 | image = arrowDown;
|
---|
44 | break;
|
---|
45 | case -1:
|
---|
46 | image = arrowUp;
|
---|
47 | break;
|
---|
48 | }
|
---|
49 |
|
---|
50 | int ymax=this.getSize().height - 1;
|
---|
51 | int xoff = this.getSize().width / 2;
|
---|
52 | int w = 2;
|
---|
53 | int p = 2 + w + 1;
|
---|
54 | int y1 = 0;
|
---|
55 | int y2 = 0;
|
---|
56 |
|
---|
57 | if (image != null && (value.connectedToPrevious || value.connectedToNext)) {
|
---|
58 | g.drawImage(image, xoff-3, ymax / 2 - 2, null);
|
---|
59 | }
|
---|
60 |
|
---|
61 | if (value.connectedToPrevious) {
|
---|
62 | g.setColor(Color.black);
|
---|
63 | g.fillRect(xoff - 2, 0, 5, 2);
|
---|
64 | y1 = 0;
|
---|
65 | } else {
|
---|
66 | g.setColor(Color.red);
|
---|
67 | g.drawRect(xoff-1, p - 1 - w, w, w);
|
---|
68 | y1 = p;
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (value.connectedToNext) {
|
---|
72 | g.setColor(Color.black);
|
---|
73 | g.fillRect(xoff - 2, ymax - 1, 5, 2);
|
---|
74 | y2 = ymax;
|
---|
75 | } else {
|
---|
76 | g.setColor(Color.red);
|
---|
77 | g.drawRect(xoff-1, ymax - p + 1, w, w);
|
---|
78 | y2 = ymax - p;
|
---|
79 | }
|
---|
80 | g.setColor(Color.black);
|
---|
81 | g.drawLine(xoff, y1, xoff, y2);
|
---|
82 | }
|
---|
83 | }
|
---|