1 | /* License: GPL. Copyright 2007 by Immanuel Scholz and others */
|
---|
2 | package org.openstreetmap.josm.data.osm.visitor.paint;
|
---|
3 |
|
---|
4 | /* To enable debugging or profiling remove the double / signs */
|
---|
5 |
|
---|
6 | import java.awt.BasicStroke;
|
---|
7 | import java.awt.Color;
|
---|
8 | import java.awt.Graphics2D;
|
---|
9 | import java.awt.Point;
|
---|
10 | import java.awt.Polygon;
|
---|
11 | import java.awt.Rectangle;
|
---|
12 | import java.awt.RenderingHints;
|
---|
13 | import java.awt.Stroke;
|
---|
14 | import java.awt.geom.GeneralPath;
|
---|
15 | import java.util.Collection;
|
---|
16 | import java.util.Iterator;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 | import org.openstreetmap.josm.data.Bounds;
|
---|
20 | import org.openstreetmap.josm.data.osm.BBox;
|
---|
21 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
22 | import org.openstreetmap.josm.data.osm.Node;
|
---|
23 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
24 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
25 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
26 | import org.openstreetmap.josm.data.osm.Way;
|
---|
27 | import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
|
---|
28 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
|
---|
29 | import org.openstreetmap.josm.gui.NavigatableComponent;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * A visitor that paints a simple scheme of every primitive it visits to a
|
---|
33 | * previous set graphic environment.
|
---|
34 | *
|
---|
35 | * @author imi
|
---|
36 | */
|
---|
37 | public class SimplePaintVisitor extends AbstractVisitor implements PaintVisitor {
|
---|
38 | /**
|
---|
39 | * The environment to paint to.
|
---|
40 | */
|
---|
41 | protected Graphics2D g;
|
---|
42 | /**
|
---|
43 | * MapView to get screen coordinates.
|
---|
44 | */
|
---|
45 | protected NavigatableComponent nc;
|
---|
46 |
|
---|
47 | public boolean inactive;
|
---|
48 |
|
---|
49 | protected static final double PHI = Math.toRadians(20);
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Preferences
|
---|
53 | */
|
---|
54 | protected Color inactiveColor;
|
---|
55 | protected Color selectedColor;
|
---|
56 | protected Color nodeColor;
|
---|
57 | protected Color dfltWayColor;
|
---|
58 | protected Color relationColor;
|
---|
59 | protected Color untaggedWayColor;
|
---|
60 | protected Color incompleteColor;
|
---|
61 | protected Color backgroundColor;
|
---|
62 | protected Color highlightColor;
|
---|
63 | protected Color taggedColor;
|
---|
64 | protected Color connectionColor;
|
---|
65 | protected Color taggedConnectionColor;
|
---|
66 | protected boolean showDirectionArrow;
|
---|
67 | protected boolean showRelevantDirectionsOnly;
|
---|
68 | protected boolean showHeadArrowOnly;
|
---|
69 | protected boolean showOrderNumber;
|
---|
70 | protected boolean fillSelectedNode;
|
---|
71 | protected boolean fillUnselectedNode;
|
---|
72 | protected boolean fillTaggedNode;
|
---|
73 | protected boolean fillConnectionNode;
|
---|
74 | protected int selectedNodeSize;
|
---|
75 | protected int unselectedNodeSize;
|
---|
76 | protected int connectionNodeSize;
|
---|
77 | protected int taggedNodeSize;
|
---|
78 | protected int defaultSegmentWidth;
|
---|
79 | protected int virtualNodeSize;
|
---|
80 | protected int virtualNodeSpace;
|
---|
81 | protected int segmentNumberSpace;
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Draw subsequent segments of same color as one Path
|
---|
85 | */
|
---|
86 | protected Color currentColor = null;
|
---|
87 | protected GeneralPath currentPath = new GeneralPath();
|
---|
88 |
|
---|
89 | public void getColors()
|
---|
90 | {
|
---|
91 | inactiveColor = PaintColors.INACTIVE.get();
|
---|
92 | selectedColor = PaintColors.SELECTED.get();
|
---|
93 | nodeColor = PaintColors.NODE.get();
|
---|
94 | dfltWayColor = PaintColors.DEFAULT_WAY.get();
|
---|
95 | relationColor = PaintColors.RELATION.get();
|
---|
96 | untaggedWayColor = PaintColors.UNTAGGED_WAY.get();
|
---|
97 | incompleteColor = PaintColors.INCOMPLETE_WAY.get();
|
---|
98 | backgroundColor = PaintColors.BACKGROUND.get();
|
---|
99 | highlightColor = PaintColors.HIGHLIGHT.get();
|
---|
100 | taggedColor = PaintColors.TAGGED.get();
|
---|
101 | connectionColor = PaintColors.CONNECTION.get();
|
---|
102 |
|
---|
103 | if (taggedColor != nodeColor) {
|
---|
104 | taggedConnectionColor = taggedColor;
|
---|
105 | } else {
|
---|
106 | taggedConnectionColor = connectionColor;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | protected void getSettings(boolean virtual) {
|
---|
111 | MapPaintSettings settings = MapPaintSettings.INSTANCE;
|
---|
112 | showDirectionArrow = settings.isShowDirectionArrow();
|
---|
113 | showRelevantDirectionsOnly = settings.isShowRelevantDirectionsOnly();
|
---|
114 | showHeadArrowOnly = settings.isShowHeadArrowOnly();
|
---|
115 | showOrderNumber = settings.isShowOrderNumber();
|
---|
116 | selectedNodeSize = settings.getSelectedNodeSize();
|
---|
117 | unselectedNodeSize = settings.getUnselectedNodeSize();
|
---|
118 | connectionNodeSize = settings.getConnectionNodeSize();
|
---|
119 | taggedNodeSize = settings.getTaggedNodeSize();
|
---|
120 | defaultSegmentWidth = settings.getDefaultSegmentWidth();
|
---|
121 | fillSelectedNode = settings.isFillSelectedNode();
|
---|
122 | fillUnselectedNode = settings.isFillUnselectedNode();
|
---|
123 | fillConnectionNode = settings.isFillConnectionNode();
|
---|
124 | fillTaggedNode = settings.isFillTaggedNode();
|
---|
125 | virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 8) / 2 : 0;
|
---|
126 | virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);
|
---|
127 | segmentNumberSpace = Main.pref.getInteger("mappaint.segmentnumber.space", 40);
|
---|
128 | getColors();
|
---|
129 |
|
---|
130 | g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
---|
131 | Main.pref.getBoolean("mappaint.use-antialiasing", false) ?
|
---|
132 | RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
|
---|
133 | }
|
---|
134 |
|
---|
135 | DataSet ds;
|
---|
136 | public void visitAll(DataSet data, boolean virtual, Bounds bounds) {
|
---|
137 | BBox bbox = new BBox(bounds);
|
---|
138 | this.ds = data;
|
---|
139 | //boolean profiler = Main.pref.getBoolean("simplepaint.profiler",false);
|
---|
140 | //long profilerStart = java.lang.System.currentTimeMillis();
|
---|
141 | //long profilerLast = profilerStart;
|
---|
142 | //int profilerN = 0;
|
---|
143 | //if(profiler)
|
---|
144 | // System.out.println("Simplepaint Profiler");
|
---|
145 |
|
---|
146 | getSettings(virtual);
|
---|
147 |
|
---|
148 | //if(profiler)
|
---|
149 | //{
|
---|
150 | // System.out.format("Prepare : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));
|
---|
151 | // profilerLast = java.lang.System.currentTimeMillis();
|
---|
152 | //}
|
---|
153 |
|
---|
154 | /* draw tagged ways first, then untagged ways. takes
|
---|
155 | time to iterate through list twice, OTOH does not
|
---|
156 | require changing the colour while painting... */
|
---|
157 | //profilerN = 0;
|
---|
158 | for (final OsmPrimitive osm: data.searchRelations(bbox)) {
|
---|
159 | if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isFiltered()) {
|
---|
160 | osm.visit(this);
|
---|
161 | // profilerN++;
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | //if(profiler)
|
---|
166 | //{
|
---|
167 | // System.out.format("Relations: %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
|
---|
168 | // profilerLast = java.lang.System.currentTimeMillis();
|
---|
169 | //}
|
---|
170 |
|
---|
171 | //profilerN = 0;
|
---|
172 | for (final OsmPrimitive osm:data.searchWays(bbox)){
|
---|
173 | if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isFiltered() && osm.isTagged()) {
|
---|
174 | osm.visit(this);
|
---|
175 | // profilerN++;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | displaySegments();
|
---|
179 |
|
---|
180 | for (final OsmPrimitive osm:data.searchWays(bbox)){
|
---|
181 | if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isFiltered() && !osm.isTagged()) {
|
---|
182 | osm.visit(this);
|
---|
183 | // profilerN++;
|
---|
184 | }
|
---|
185 | }
|
---|
186 | displaySegments();
|
---|
187 |
|
---|
188 | //if(profiler)
|
---|
189 | //{
|
---|
190 | // System.out.format("Ways : %4dms, n=%5d\n",
|
---|
191 | // (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
|
---|
192 | // profilerLast = java.lang.System.currentTimeMillis();
|
---|
193 | //}
|
---|
194 |
|
---|
195 | //profilerN = 0;
|
---|
196 | for (final OsmPrimitive osm : data.getSelected())
|
---|
197 | if (!osm.isDeleted()) {
|
---|
198 | osm.visit(this);
|
---|
199 | // profilerN++;
|
---|
200 | }
|
---|
201 | displaySegments();
|
---|
202 |
|
---|
203 | //if(profiler)
|
---|
204 | //{
|
---|
205 | // System.out.format("Selected : %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
|
---|
206 | // profilerLast = java.lang.System.currentTimeMillis();
|
---|
207 | //}
|
---|
208 |
|
---|
209 | //profilerN = 0;
|
---|
210 | for (final OsmPrimitive osm: data.searchNodes(bbox)) {
|
---|
211 | if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isFiltered())
|
---|
212 | {
|
---|
213 | osm.visit(this);
|
---|
214 | // profilerN++;
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 | //if(profiler)
|
---|
219 | //{
|
---|
220 | // System.out.format("Nodes : %4dms, n=%5d\n",
|
---|
221 | // (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
|
---|
222 | // profilerLast = java.lang.System.currentTimeMillis();
|
---|
223 | //}
|
---|
224 |
|
---|
225 | drawVirtualNodes(data.searchWays(bbox));
|
---|
226 |
|
---|
227 | //if(profiler)
|
---|
228 | //{
|
---|
229 | // System.out.format("All : %4dms\n", (profilerLast-profilerStart));
|
---|
230 | //}
|
---|
231 | }
|
---|
232 |
|
---|
233 | private static final int max(int a, int b, int c, int d) {
|
---|
234 | return Math.max(Math.max(a, b), Math.max(c, d));
|
---|
235 | }
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * Draw a small rectangle.
|
---|
239 | * White if selected (as always) or red otherwise.
|
---|
240 | *
|
---|
241 | * @param n The node to draw.
|
---|
242 | */
|
---|
243 | public void visit(Node n) {
|
---|
244 | if (n.isIncomplete()) return;
|
---|
245 |
|
---|
246 | if (n.isHighlighted()) {
|
---|
247 | drawNode(n, highlightColor, selectedNodeSize, fillSelectedNode);
|
---|
248 | } else {
|
---|
249 | Color color;
|
---|
250 |
|
---|
251 | if (inactive || n.isDisabled()) {
|
---|
252 | color = inactiveColor;
|
---|
253 | } else if (ds.isSelected(n)) {
|
---|
254 | color = selectedColor;
|
---|
255 | } else if (n.isConnectionNode()) {
|
---|
256 | if (n.isTagged()) {
|
---|
257 | color = taggedConnectionColor;
|
---|
258 | } else {
|
---|
259 | color = connectionColor;
|
---|
260 | }
|
---|
261 | } else {
|
---|
262 | if (n.isTagged()) {
|
---|
263 | color = taggedColor;
|
---|
264 | } else {
|
---|
265 | color = nodeColor;
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | final int size = max((ds.isSelected(n) ? selectedNodeSize : 0),
|
---|
270 | (n.isTagged() ? taggedNodeSize : 0),
|
---|
271 | (n.isConnectionNode() ? connectionNodeSize : 0),
|
---|
272 | unselectedNodeSize);
|
---|
273 |
|
---|
274 | final boolean fill = (ds.isSelected(n) && fillSelectedNode) ||
|
---|
275 | (n.isTagged() && fillTaggedNode) ||
|
---|
276 | (n.isConnectionNode() && fillConnectionNode) ||
|
---|
277 | fillUnselectedNode;
|
---|
278 |
|
---|
279 | drawNode(n, color, size, fill);
|
---|
280 | }
|
---|
281 | }
|
---|
282 |
|
---|
283 | public static boolean isLargeSegment(Point p1, Point p2, int space)
|
---|
284 | {
|
---|
285 | int xd = p1.x-p2.x; if(xd < 0) {
|
---|
286 | xd = -xd;
|
---|
287 | }
|
---|
288 | int yd = p1.y-p2.y; if(yd < 0) {
|
---|
289 | yd = -yd;
|
---|
290 | }
|
---|
291 | return (xd+yd > space);
|
---|
292 | }
|
---|
293 |
|
---|
294 | public void drawVirtualNodes(Collection<Way> ways) {
|
---|
295 |
|
---|
296 | if (virtualNodeSize != 0) {
|
---|
297 | GeneralPath path = new GeneralPath();
|
---|
298 | for (Way osm: ways){
|
---|
299 | if (osm.isUsable() && !osm.isFiltered()) {
|
---|
300 | visitVirtual(path, osm);
|
---|
301 | }
|
---|
302 | }
|
---|
303 | g.setColor(nodeColor);
|
---|
304 | g.draw(path);
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | public void visitVirtual(GeneralPath path, Way w) {
|
---|
309 | Iterator<Node> it = w.getNodes().iterator();
|
---|
310 | if (it.hasNext()) {
|
---|
311 | Point lastP = nc.getPoint(it.next());
|
---|
312 | while(it.hasNext())
|
---|
313 | {
|
---|
314 | Point p = nc.getPoint(it.next());
|
---|
315 | if(isSegmentVisible(lastP, p) && isLargeSegment(lastP, p, virtualNodeSpace))
|
---|
316 | {
|
---|
317 | int x = (p.x+lastP.x)/2;
|
---|
318 | int y = (p.y+lastP.y)/2;
|
---|
319 | path.moveTo(x-virtualNodeSize, y);
|
---|
320 | path.lineTo(x+virtualNodeSize, y);
|
---|
321 | path.moveTo(x, y-virtualNodeSize);
|
---|
322 | path.lineTo(x, y+virtualNodeSize);
|
---|
323 | }
|
---|
324 | lastP = p;
|
---|
325 | }
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * Draw a darkblue line for all segments.
|
---|
331 | * @param w The way to draw.
|
---|
332 | */
|
---|
333 | public void visit(Way w) {
|
---|
334 | if (w.isIncomplete() || w.getNodesCount() < 2)
|
---|
335 | return;
|
---|
336 |
|
---|
337 | /* show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key
|
---|
338 | (even if the tag is negated as in oneway=false) or the way is selected */
|
---|
339 |
|
---|
340 | boolean showThisDirectionArrow = ds.isSelected(w)
|
---|
341 | || (showDirectionArrow && (!showRelevantDirectionsOnly || w.hasDirectionKeys()));
|
---|
342 | /* head only takes over control if the option is true,
|
---|
343 | the direction should be shown at all and not only because it's selected */
|
---|
344 | boolean showOnlyHeadArrowOnly = showThisDirectionArrow && !ds.isSelected(w) && showHeadArrowOnly;
|
---|
345 | Color wayColor;
|
---|
346 |
|
---|
347 | if (inactive || w.isDisabled()) {
|
---|
348 | wayColor = inactiveColor;
|
---|
349 | } else if(w.isHighlighted()) {
|
---|
350 | wayColor = highlightColor;
|
---|
351 | } else if(ds.isSelected(w)) {
|
---|
352 | wayColor = selectedColor;
|
---|
353 | } else if (!w.isTagged()) {
|
---|
354 | wayColor = untaggedWayColor;
|
---|
355 | } else {
|
---|
356 | wayColor = dfltWayColor;
|
---|
357 | }
|
---|
358 |
|
---|
359 | Iterator<Node> it = w.getNodes().iterator();
|
---|
360 | if (it.hasNext()) {
|
---|
361 | Point lastP = nc.getPoint(it.next());
|
---|
362 | for (int orderNumber = 1; it.hasNext(); orderNumber++) {
|
---|
363 | Point p = nc.getPoint(it.next());
|
---|
364 | drawSegment(lastP, p, wayColor,
|
---|
365 | showOnlyHeadArrowOnly ? !it.hasNext() : showThisDirectionArrow);
|
---|
366 | if (showOrderNumber) {
|
---|
367 | drawOrderNumber(lastP, p, orderNumber);
|
---|
368 | }
|
---|
369 | lastP = p;
|
---|
370 | }
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | private Stroke relatedWayStroke = new BasicStroke(
|
---|
375 | 4, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
|
---|
376 | public void visit(Relation r) {
|
---|
377 | if (r.isIncomplete()) return;
|
---|
378 |
|
---|
379 | Color col;
|
---|
380 | if (inactive || r.isDisabled()) {
|
---|
381 | col = inactiveColor;
|
---|
382 | } else if (ds.isSelected(r)) {
|
---|
383 | col = selectedColor;
|
---|
384 | } else {
|
---|
385 | col = relationColor;
|
---|
386 | }
|
---|
387 | g.setColor(col);
|
---|
388 |
|
---|
389 | for (RelationMember m : r.getMembers()) {
|
---|
390 | if (m.getMember().isIncomplete() || m.getMember().isDeleted()) {
|
---|
391 | continue;
|
---|
392 | }
|
---|
393 |
|
---|
394 | if (m.isNode()) {
|
---|
395 | Point p = nc.getPoint(m.getNode());
|
---|
396 | if (p.x < 0 || p.y < 0
|
---|
397 | || p.x > nc.getWidth() || p.y > nc.getHeight()) {
|
---|
398 | continue;
|
---|
399 | }
|
---|
400 |
|
---|
401 | g.drawOval(p.x-3, p.y-3, 6, 6);
|
---|
402 | } else if (m.isWay()) {
|
---|
403 | GeneralPath path = new GeneralPath();
|
---|
404 |
|
---|
405 | boolean first = true;
|
---|
406 | for (Node n : m.getWay().getNodes()) {
|
---|
407 | if (n.isIncomplete() || n.isDeleted()) {
|
---|
408 | continue;
|
---|
409 | }
|
---|
410 | Point p = nc.getPoint(n);
|
---|
411 | if (first) {
|
---|
412 | path.moveTo(p.x, p.y);
|
---|
413 | first = false;
|
---|
414 | } else {
|
---|
415 | path.lineTo(p.x, p.y);
|
---|
416 | }
|
---|
417 | }
|
---|
418 |
|
---|
419 | g.draw(relatedWayStroke.createStrokedShape(path));
|
---|
420 | }
|
---|
421 | }
|
---|
422 | }
|
---|
423 |
|
---|
424 | /**
|
---|
425 | * Draw an number of the order of the two consecutive nodes within the
|
---|
426 | * parents way
|
---|
427 | */
|
---|
428 | protected void drawOrderNumber(Point p1, Point p2, int orderNumber) {
|
---|
429 | if (isSegmentVisible(p1, p2) && isLargeSegment(p1, p2, segmentNumberSpace)) {
|
---|
430 | String on = Integer.toString(orderNumber);
|
---|
431 | int strlen = on.length();
|
---|
432 | int x = (p1.x+p2.x)/2 - 4*strlen;
|
---|
433 | int y = (p1.y+p2.y)/2 + 4;
|
---|
434 |
|
---|
435 | if(virtualNodeSize != 0 && isLargeSegment(p1, p2, virtualNodeSpace))
|
---|
436 | {
|
---|
437 | y = (p1.y+p2.y)/2 - virtualNodeSize - 3;
|
---|
438 | }
|
---|
439 |
|
---|
440 | displaySegments(); /* draw nodes on top! */
|
---|
441 | Color c = g.getColor();
|
---|
442 | g.setColor(backgroundColor);
|
---|
443 | g.fillRect(x-1, y-12, 8*strlen+1, 14);
|
---|
444 | g.setColor(c);
|
---|
445 | g.drawString(on, x, y);
|
---|
446 | }
|
---|
447 | }
|
---|
448 |
|
---|
449 | /**
|
---|
450 | * Draw the node as small rectangle with the given color.
|
---|
451 | *
|
---|
452 | * @param n The node to draw.
|
---|
453 | * @param color The color of the node.
|
---|
454 | */
|
---|
455 | public void drawNode(Node n, Color color, int size, boolean fill) {
|
---|
456 | if (size > 1) {
|
---|
457 | int radius = size / 2;
|
---|
458 | Point p = nc.getPoint(n);
|
---|
459 | if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth())
|
---|
460 | || (p.y > nc.getHeight()))
|
---|
461 | return;
|
---|
462 | g.setColor(color);
|
---|
463 | if (fill) {
|
---|
464 | g.fillRect(p.x - radius, p.y - radius, size, size);
|
---|
465 | g.drawRect(p.x - radius, p.y - radius, size, size);
|
---|
466 | } else {
|
---|
467 | g.drawRect(p.x - radius, p.y - radius, size, size);
|
---|
468 | }
|
---|
469 | }
|
---|
470 | }
|
---|
471 |
|
---|
472 | protected void drawSegment(GeneralPath path, Point p1, Point p2, boolean showDirection) {
|
---|
473 | if (isSegmentVisible(p1, p2)) {
|
---|
474 | path.moveTo(p1.x, p1.y);
|
---|
475 | path.lineTo(p2.x, p2.y);
|
---|
476 |
|
---|
477 | if (showDirection) {
|
---|
478 | double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
|
---|
479 | path.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
|
---|
480 | path.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
|
---|
481 | path.lineTo(p2.x, p2.y);
|
---|
482 | }
|
---|
483 | }
|
---|
484 | }
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * Draw a line with the given color.
|
---|
488 | */
|
---|
489 | protected void drawSegment(Point p1, Point p2, Color col, boolean showDirection) {
|
---|
490 | if (col != currentColor) {
|
---|
491 | displaySegments(col);
|
---|
492 | }
|
---|
493 | drawSegment(currentPath, p1, p2, showDirection);
|
---|
494 | }
|
---|
495 |
|
---|
496 | protected boolean isSegmentVisible(Point p1, Point p2) {
|
---|
497 | if ((p1.x < 0) && (p2.x < 0)) return false;
|
---|
498 | if ((p1.y < 0) && (p2.y < 0)) return false;
|
---|
499 | if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
|
---|
500 | if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
|
---|
501 | return true;
|
---|
502 | }
|
---|
503 |
|
---|
504 | protected boolean isPolygonVisible(Polygon polygon) {
|
---|
505 | Rectangle bounds = polygon.getBounds();
|
---|
506 | if (bounds.width == 0 && bounds.height == 0) return false;
|
---|
507 | if (bounds.x > nc.getWidth()) return false;
|
---|
508 | if (bounds.y > nc.getHeight()) return false;
|
---|
509 | if (bounds.x + bounds.width < 0) return false;
|
---|
510 | if (bounds.y + bounds.height < 0) return false;
|
---|
511 | return true;
|
---|
512 | }
|
---|
513 |
|
---|
514 | public void setGraphics(Graphics2D g) {
|
---|
515 | this.g = g;
|
---|
516 | }
|
---|
517 |
|
---|
518 | public void setNavigatableComponent(NavigatableComponent nc) {
|
---|
519 | this.nc = nc;
|
---|
520 | }
|
---|
521 |
|
---|
522 | protected void displaySegments() {
|
---|
523 | displaySegments(null);
|
---|
524 | }
|
---|
525 | protected void displaySegments(Color newColor) {
|
---|
526 | if (currentPath != null) {
|
---|
527 | g.setColor(currentColor);
|
---|
528 | g.draw(currentPath);
|
---|
529 | currentPath = new GeneralPath();
|
---|
530 | currentColor = newColor;
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | public void setInactive(boolean inactive) {
|
---|
535 | this.inactive = inactive;
|
---|
536 | }
|
---|
537 | }
|
---|