1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation;
|
---|
3 |
|
---|
4 | import java.awt.BasicStroke;
|
---|
5 | import java.awt.Color;
|
---|
6 | import java.awt.Component;
|
---|
7 | import java.awt.Graphics;
|
---|
8 | import java.awt.Graphics2D;
|
---|
9 | import java.awt.Image;
|
---|
10 |
|
---|
11 | import javax.swing.JTable;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;
|
---|
14 | import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | public class MemberTableLinkedCellRenderer extends MemberTableCellRenderer {
|
---|
18 |
|
---|
19 | final static Image arrowUp = ImageProvider.get("dialogs/relation", "arrowup").getImage();
|
---|
20 | final static Image arrowDown = ImageProvider.get("dialogs/relation", "arrowdown").getImage();
|
---|
21 | final static Image corners = ImageProvider.get("dialogs/relation", "roundedcorners").getImage();
|
---|
22 | final static Image roundabout_right = ImageProvider.get("dialogs/relation", "roundabout_right_tiny").getImage();
|
---|
23 | final static Image roundabout_left = ImageProvider.get("dialogs/relation", "roundabout_left_tiny").getImage();
|
---|
24 | private WayConnectionType value = new WayConnectionType();
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
28 | int row, int column) {
|
---|
29 |
|
---|
30 | reset();
|
---|
31 | if (value == null)
|
---|
32 | return this;
|
---|
33 |
|
---|
34 | this.value = (WayConnectionType) value;
|
---|
35 | renderForeground(isSelected);
|
---|
36 | //setText(value.toString());
|
---|
37 | setToolTipText(((WayConnectionType)value).getToolTip());
|
---|
38 | renderBackground(getModel(table), null, isSelected);
|
---|
39 | return this;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void paintComponent(Graphics g) {
|
---|
44 | super.paintComponent(g);
|
---|
45 | if (value == null || !value.isValid())
|
---|
46 | return;
|
---|
47 |
|
---|
48 | int ymax=this.getSize().height - 1;
|
---|
49 | int xloop = 10;
|
---|
50 | int xowloop = 0;
|
---|
51 | if(value.isOnewayLoopForwardPart) {
|
---|
52 | xowloop = -3;
|
---|
53 | }
|
---|
54 | if(value.isOnewayLoopBackwardPart) {
|
---|
55 | xowloop = 3;
|
---|
56 | }
|
---|
57 |
|
---|
58 | int xoff = this.getSize().width / 2;
|
---|
59 | if (value.isLoop) {
|
---|
60 | xoff -= xloop / 2 - 1;
|
---|
61 | }
|
---|
62 | int w = 2;
|
---|
63 | int p = 2 + w + 1;
|
---|
64 | int y1 = 0;
|
---|
65 | int y2 = 0;
|
---|
66 |
|
---|
67 | if (value.linkPrev) {
|
---|
68 | g.setColor(Color.black);
|
---|
69 | if(value.isOnewayHead) {
|
---|
70 | g.fillRect(xoff - 1, 0, 3, 1);
|
---|
71 | } else {
|
---|
72 | g.fillRect(xoff - 1 + xowloop, 0, 3, 1);
|
---|
73 | }
|
---|
74 | y1 = 0;
|
---|
75 | } else {
|
---|
76 | if (value.isLoop) {
|
---|
77 | g.setColor(Color.black);
|
---|
78 | y1 = 5;
|
---|
79 | g.drawImage(corners,xoff,y1-3,xoff+3,y1, 0,0,3,3, new Color(0,0,0,0), null);
|
---|
80 | g.drawImage(corners,xoff+xloop-2,y1-3,xoff+xloop+1,y1, 2,0,5,3, new Color(0,0,0,0), null);
|
---|
81 | g.drawLine(xoff+3,y1-3,xoff+xloop-3,y1-3);
|
---|
82 | }
|
---|
83 | else {
|
---|
84 | g.setColor(Color.red);
|
---|
85 | if(value.isOnewayHead) {
|
---|
86 | g.drawRect(xoff-1, p - 3 - w, w, w);
|
---|
87 | } else {
|
---|
88 | g.drawRect(xoff-1 + xowloop, p - 1 - w, w, w);
|
---|
89 | }
|
---|
90 | y1 = p;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | if (value.linkNext) {
|
---|
95 | g.setColor(Color.black);
|
---|
96 | if(value.isOnewayTail) {
|
---|
97 | g.fillRect(xoff - 1, ymax, 3, 1);
|
---|
98 | } else {
|
---|
99 | g.fillRect(xoff - 1 + xowloop, ymax, 3, 1);
|
---|
100 | }
|
---|
101 | y2 = ymax;
|
---|
102 | } else {
|
---|
103 | if (value.isLoop) {
|
---|
104 | g.setColor(Color.black);
|
---|
105 | y2 = ymax - 5;
|
---|
106 | g.fillRect(xoff-1, y2+2, 3, 3);
|
---|
107 | g.drawLine(xoff, y2, xoff, y2+2);
|
---|
108 | g.drawImage(corners,xoff+xloop-2,y2+1,xoff+xloop+1,y2+4, 2,2,5,5, new Color(0,0,0,0), null);
|
---|
109 | g.drawLine(xoff+3-1,y2+3,xoff+xloop-3,y2+3);
|
---|
110 | }
|
---|
111 | else {
|
---|
112 | g.setColor(Color.red);
|
---|
113 | if(value.isOnewayTail) {
|
---|
114 | g.drawRect(xoff-1, ymax - p + 3, w, w);
|
---|
115 | } else {
|
---|
116 | g.drawRect(xoff-1 + xowloop, ymax - p + 1, w, w);
|
---|
117 | }
|
---|
118 | y2 = ymax - p;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* vertical lines */
|
---|
123 | g.setColor(Color.black);
|
---|
124 | if (value.isLoop) {
|
---|
125 | g.drawLine(xoff+xloop, y1, xoff+xloop, y2);
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (value.isOnewayHead) {
|
---|
129 | setDotted(g);
|
---|
130 | y1 = 7;
|
---|
131 |
|
---|
132 | int[] xValues = {xoff - xowloop + 1, xoff - xowloop + 1, xoff};
|
---|
133 | int[] yValues = {ymax, y1+1, 1};
|
---|
134 | g.drawPolyline(xValues, yValues, 3);
|
---|
135 | unsetDotted(g);
|
---|
136 | g.drawLine(xoff + xowloop, y1+1, xoff, 1);
|
---|
137 | }
|
---|
138 |
|
---|
139 | if(value.isOnewayTail){
|
---|
140 | setDotted(g);
|
---|
141 | y2 = ymax - 7;
|
---|
142 |
|
---|
143 | int[] xValues = {xoff+1, xoff - xowloop + 1, xoff - xowloop + 1};
|
---|
144 | int[] yValues = {ymax-1, y2, y1};
|
---|
145 | g.drawPolyline(xValues, yValues, 3);
|
---|
146 | unsetDotted(g);
|
---|
147 | g.drawLine(xoff + xowloop, y2, xoff, ymax-1);
|
---|
148 | }
|
---|
149 |
|
---|
150 | if ((value.isOnewayLoopForwardPart || value.isOnewayLoopBackwardPart) && !value.isOnewayTail && !value.isOnewayHead) {
|
---|
151 | setDotted(g);
|
---|
152 | g.drawLine(xoff - xowloop+1, y1, xoff - xowloop+1, y2 + 1);
|
---|
153 | unsetDotted(g);
|
---|
154 | }
|
---|
155 |
|
---|
156 | if (!value.isOnewayLoopForwardPart && !value.isOnewayLoopBackwardPart){
|
---|
157 | g.drawLine(xoff, y1, xoff, y2);
|
---|
158 | }
|
---|
159 |
|
---|
160 | g.drawLine(xoff+xowloop, y1, xoff+xowloop, y2);
|
---|
161 |
|
---|
162 | /* special icons */
|
---|
163 | Image arrow = null;
|
---|
164 | switch (value.direction) {
|
---|
165 | case FORWARD:
|
---|
166 | arrow = arrowDown;
|
---|
167 | break;
|
---|
168 | case BACKWARD:
|
---|
169 | arrow = arrowUp;
|
---|
170 | break;
|
---|
171 | }
|
---|
172 | if (value.direction == Direction.ROUNDABOUT_LEFT) {
|
---|
173 | g.drawImage(roundabout_left, xoff-6, 1, null);
|
---|
174 | } else if (value.direction == Direction.ROUNDABOUT_RIGHT) {
|
---|
175 | g.drawImage(roundabout_right, xoff-6, 1, null);
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (!value.isOnewayLoopForwardPart && !value.isOnewayLoopBackwardPart &&
|
---|
179 | (arrow != null)) {
|
---|
180 | g.drawImage(arrow, xoff-3, (y1 + y2) / 2 - 2, null);
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (value.isOnewayLoopBackwardPart && value.isOnewayLoopForwardPart) {
|
---|
184 | if(arrow == arrowDown) {
|
---|
185 | arrow = arrowUp;
|
---|
186 | } else if (arrow == arrowUp) {
|
---|
187 | arrow = arrowDown;
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | if ((arrow != null)) {
|
---|
192 | g.drawImage(arrow, xoff+xowloop-3, (y1 + y2) / 2 - 2, null);
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | private void setDotted(Graphics g) {
|
---|
197 | ((Graphics2D)g).setStroke(new BasicStroke(
|
---|
198 | 1f,
|
---|
199 | BasicStroke.CAP_BUTT,
|
---|
200 | BasicStroke.CAP_BUTT,
|
---|
201 | 5f,
|
---|
202 | new float[] {1f, 2f},
|
---|
203 | 0f));
|
---|
204 | }
|
---|
205 |
|
---|
206 | private void unsetDotted(Graphics g) {
|
---|
207 | ((Graphics2D)g).setStroke(new BasicStroke());
|
---|
208 | }
|
---|
209 | }
|
---|