1 | package org.openstreetmap.josm.gui.mappaint;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.util.Collection;
|
---|
5 |
|
---|
6 | public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle>
|
---|
7 | {
|
---|
8 | public int width;
|
---|
9 | public int realWidth; //the real width of this line in meter
|
---|
10 | public Color color;
|
---|
11 | public boolean dashed;
|
---|
12 |
|
---|
13 | public boolean over;
|
---|
14 | public enum WidthMode { ABSOLUTE, PERCENT, OFFSET };
|
---|
15 | public WidthMode widthMode;
|
---|
16 |
|
---|
17 | public Collection<LineElemStyle> overlays;
|
---|
18 |
|
---|
19 | public LineElemStyle(LineElemStyle s, long maxScale, long minScale) {
|
---|
20 | this.width = s.width;
|
---|
21 | this.realWidth = s.realWidth;
|
---|
22 | this.color = s.color;
|
---|
23 | this.dashed = s.dashed;
|
---|
24 | this.over = s.over;
|
---|
25 | this.widthMode = s.widthMode;
|
---|
26 |
|
---|
27 | this.priority = s.priority;
|
---|
28 | this.maxScale = maxScale;
|
---|
29 | this.minScale = minScale;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public LineElemStyle(LineElemStyle s, Collection<LineElemStyle> overlays) {
|
---|
33 | this.width = s.width;
|
---|
34 | this.realWidth = s.realWidth;
|
---|
35 | this.color = s.color;
|
---|
36 | this.dashed = s.dashed;
|
---|
37 | this.over = s.over;
|
---|
38 | this.widthMode = s.widthMode;
|
---|
39 |
|
---|
40 | this.priority = s.priority;
|
---|
41 | this.maxScale = s.maxScale;
|
---|
42 | this.minScale = s.minScale;
|
---|
43 |
|
---|
44 | this.overlays = overlays;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public LineElemStyle() { init(); }
|
---|
48 |
|
---|
49 | public void init()
|
---|
50 | {
|
---|
51 | width = 1;
|
---|
52 | realWidth = 0;
|
---|
53 | dashed = false;
|
---|
54 | priority = 0;
|
---|
55 | color = null;
|
---|
56 | over = true; // only used for line modifications
|
---|
57 | widthMode = WidthMode.ABSOLUTE;
|
---|
58 | overlays = null;
|
---|
59 | };
|
---|
60 |
|
---|
61 | // get width for overlays
|
---|
62 | public int getWidth(int ref)
|
---|
63 | {
|
---|
64 | int res;
|
---|
65 | if(widthMode == WidthMode.ABSOLUTE)
|
---|
66 | res = width;
|
---|
67 | else if(widthMode == WidthMode.OFFSET)
|
---|
68 | res = ref + width;
|
---|
69 | else
|
---|
70 | {
|
---|
71 | if(width < 0)
|
---|
72 | res = 0;
|
---|
73 | else
|
---|
74 | res = ref*width/100;
|
---|
75 | }
|
---|
76 | return res <= 0 ? 1 : res;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public int compareTo(LineElemStyle s)
|
---|
80 | {
|
---|
81 | if(s.priority != priority)
|
---|
82 | return s.priority > priority ? 1 : -1;
|
---|
83 | if(!over && s.over)
|
---|
84 | return -1;
|
---|
85 | // we have no idea how to order other objects :-)
|
---|
86 | return 0;
|
---|
87 | }
|
---|
88 | }
|
---|