1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.xml;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
|
---|
5 |
|
---|
6 | public class LinemodPrototype extends LinePrototype implements Comparable<LinemodPrototype> {
|
---|
7 |
|
---|
8 | public boolean over;
|
---|
9 |
|
---|
10 | public enum WidthMode { ABSOLUTE, PERCENT, OFFSET }
|
---|
11 | public WidthMode widthMode;
|
---|
12 |
|
---|
13 | public LinemodPrototype(LinemodPrototype s, long maxScale, long minScale) {
|
---|
14 | super(s, maxScale, minScale);
|
---|
15 | this.over = s.over;
|
---|
16 | this.widthMode = s.widthMode;
|
---|
17 | }
|
---|
18 |
|
---|
19 | public LinemodPrototype() { init(); }
|
---|
20 |
|
---|
21 | @Override
|
---|
22 | public void init()
|
---|
23 | {
|
---|
24 | super.init();
|
---|
25 | over = true;
|
---|
26 | widthMode = WidthMode.ABSOLUTE;
|
---|
27 | }
|
---|
28 |
|
---|
29 | // get width for overlays
|
---|
30 | public int getWidth(int ref)
|
---|
31 | {
|
---|
32 | int res;
|
---|
33 | if(widthMode == WidthMode.ABSOLUTE) {
|
---|
34 | res = width;
|
---|
35 | } else if(widthMode == WidthMode.OFFSET) {
|
---|
36 | res = ref + width;
|
---|
37 | } else
|
---|
38 | {
|
---|
39 | if(width < 0) {
|
---|
40 | res = 0;
|
---|
41 | } else {
|
---|
42 | res = ref*width/100;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | return res <= 0 ? 1 : res;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public int getWidth() {
|
---|
50 | throw new UnsupportedOperationException();
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public int compareTo(LinemodPrototype s) {
|
---|
55 | if(s.priority != priority)
|
---|
56 | return s.priority > priority ? 1 : -1;
|
---|
57 | if(!over && s.over)
|
---|
58 | return -1;
|
---|
59 | // we have no idea how to order other objects :-)
|
---|
60 | return 0;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * this method cannot be used for LinemodPrototypes
|
---|
65 | * - use createStyle(int) instead
|
---|
66 | */
|
---|
67 | @Override
|
---|
68 | public LineElemStyle createStyle() {
|
---|
69 | throw new UnsupportedOperationException();
|
---|
70 | }
|
---|
71 |
|
---|
72 | public LineElemStyle createStyle(int refWidth) {
|
---|
73 | return new LineElemStyle(minScale, maxScale, getWidth(refWidth), realWidth, color, dashed, dashedColor);
|
---|
74 | }
|
---|
75 | }
|
---|