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

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

fixed NPE

  • Property svn:eol-style set to native
File size: 2.3 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 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 this.code = s.code;
46 for (LineElemStyle o : overlays)
47 this.code += o.code;
48 }
49
50 public LineElemStyle() { init(); }
51
52 public void init()
53 {
54 width = 1;
55 realWidth = 0;
56 dashed = false;
57 priority = 0;
58 color = null;
59 over = true; // only used for line modifications
60 widthMode = WidthMode.ABSOLUTE;
61 overlays = null;
62 }
63
64 // get width for overlays
65 public int getWidth(int ref)
66 {
67 int res;
68 if(widthMode == WidthMode.ABSOLUTE)
69 res = width;
70 else if(widthMode == WidthMode.OFFSET)
71 res = ref + width;
72 else
73 {
74 if(width < 0)
75 res = 0;
76 else
77 res = ref*width/100;
78 }
79 return res <= 0 ? 1 : res;
80 }
81
82 public int compareTo(LineElemStyle s)
83 {
84 if(s.priority != priority)
85 return s.priority > priority ? 1 : -1;
86 if(!over && s.over)
87 return -1;
88 // we have no idea how to order other objects :-)
89 return 0;
90 }
91}
Note: See TracBrowser for help on using the repository browser.