source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java@ 2392

Last change on this file since 2392 was 1747, checked in by stoecker, 16 years ago

close #2874 (NPE), improved external style handling

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1package org.openstreetmap.josm.gui.mappaint;
2
3import java.awt.Color;
4import java.util.Collection;
5
6public 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 float[] dashed;
12 public Color dashedColor;
13
14 public boolean over;
15 public enum WidthMode { ABSOLUTE, PERCENT, OFFSET }
16 public WidthMode widthMode;
17
18 public Collection<LineElemStyle> overlays;
19
20 public LineElemStyle(LineElemStyle s, long maxScale, long minScale) {
21 this.width = s.width;
22 this.realWidth = s.realWidth;
23 this.color = s.color;
24 this.dashed = s.dashed;
25 this.dashedColor = s.dashedColor;
26 this.over = s.over;
27 this.widthMode = s.widthMode;
28
29 this.priority = s.priority;
30 this.maxScale = maxScale;
31 this.minScale = minScale;
32 this.rules = s.rules;
33 }
34
35 public LineElemStyle(LineElemStyle s, Collection<LineElemStyle> overlays) {
36 this.width = s.width;
37 this.realWidth = s.realWidth;
38 this.color = s.color;
39 this.dashed = s.dashed;
40 this.dashedColor = s.dashedColor;
41 this.over = s.over;
42 this.widthMode = s.widthMode;
43
44 this.priority = s.priority;
45 this.maxScale = s.maxScale;
46 this.minScale = s.minScale;
47 this.rules = s.rules;
48
49 this.overlays = overlays;
50 this.code = s.code;
51 for (LineElemStyle o : overlays)
52 this.code += o.code;
53 }
54
55 public LineElemStyle() { init(); }
56
57 public void init()
58 {
59 width = 1;
60 realWidth = 0;
61 dashed = new float[0];
62 dashedColor = null;
63 priority = 0;
64 color = null;
65 over = true; // only used for line modifications
66 widthMode = WidthMode.ABSOLUTE;
67 overlays = null;
68 }
69
70 // get width for overlays
71 public int getWidth(int ref)
72 {
73 int res;
74 if(widthMode == WidthMode.ABSOLUTE)
75 res = width;
76 else if(widthMode == WidthMode.OFFSET)
77 res = ref + width;
78 else
79 {
80 if(width < 0)
81 res = 0;
82 else
83 res = ref*width/100;
84 }
85 return res <= 0 ? 1 : res;
86 }
87
88 public int compareTo(LineElemStyle s)
89 {
90 if(s.priority != priority)
91 return s.priority > priority ? 1 : -1;
92 if(!over && s.over)
93 return -1;
94 // we have no idea how to order other objects :-)
95 return 0;
96 }
97}
Note: See TracBrowser for help on using the repository browser.