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

Last change on this file since 2659 was 2659, checked in by jttt, 14 years ago

Minor fixes in mappaint code

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1package org.openstreetmap.josm.gui.mappaint;
2
3import java.awt.Color;
4import java.util.Collection;
5
6import org.openstreetmap.josm.tools.I18n;
7
8public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle>
9{
10 public int width;
11 public int realWidth; //the real width of this line in meter
12 public Color color;
13 private float[] dashed;
14 public Color dashedColor;
15
16 public boolean over;
17 public enum WidthMode { ABSOLUTE, PERCENT, OFFSET }
18 public WidthMode widthMode;
19
20 public Collection<LineElemStyle> overlays;
21
22 public LineElemStyle(LineElemStyle s, long maxScale, long minScale) {
23 this.width = s.width;
24 this.realWidth = s.realWidth;
25 this.color = s.color;
26 this.dashed = s.dashed;
27 this.dashedColor = s.dashedColor;
28 this.over = s.over;
29 this.widthMode = s.widthMode;
30
31 this.priority = s.priority;
32 this.maxScale = maxScale;
33 this.minScale = minScale;
34 this.rules = s.rules;
35 }
36
37 public LineElemStyle(LineElemStyle s, Collection<LineElemStyle> overlays) {
38 this.width = s.width;
39 this.realWidth = s.realWidth;
40 this.color = s.color;
41 this.dashed = s.dashed;
42 this.dashedColor = s.dashedColor;
43 this.over = s.over;
44 this.widthMode = s.widthMode;
45
46 this.priority = s.priority;
47 this.maxScale = s.maxScale;
48 this.minScale = s.minScale;
49 this.rules = s.rules;
50
51 this.overlays = overlays;
52 this.code = s.code;
53 for (LineElemStyle o : overlays) {
54 this.code += o.code;
55 }
56 }
57
58 public LineElemStyle() { init(); }
59
60 public void init()
61 {
62 width = 1;
63 realWidth = 0;
64 dashed = new float[0];
65 dashedColor = null;
66 priority = 0;
67 color = null;
68 over = true; // only used for line modifications
69 widthMode = WidthMode.ABSOLUTE;
70 overlays = null;
71 }
72
73 // get width for overlays
74 public int getWidth(int ref)
75 {
76 int res;
77 if(widthMode == WidthMode.ABSOLUTE) {
78 res = width;
79 } else if(widthMode == WidthMode.OFFSET) {
80 res = ref + width;
81 } else
82 {
83 if(width < 0) {
84 res = 0;
85 } else {
86 res = ref*width/100;
87 }
88 }
89 return res <= 0 ? 1 : res;
90 }
91
92 public int compareTo(LineElemStyle s) {
93 if(s.priority != priority)
94 return s.priority > priority ? 1 : -1;
95 if(!over && s.over)
96 return -1;
97 // we have no idea how to order other objects :-)
98 return 0;
99 }
100
101 public float[] getDashed() {
102 return dashed;
103 }
104
105 public void setDashed(float[] dashed) {
106 if (dashed.length == 0) {
107 this.dashed = dashed;
108 return;
109 }
110
111 boolean found = false;
112 for (int i=0; i<dashed.length; i++) {
113 if (dashed[i] > 0) {
114 found = true;
115 }
116 if (dashed[i] < 0) {
117 System.out.println(I18n.tr("Illegal dash pattern, values must be positive"));
118 }
119 }
120 if (found) {
121 this.dashed = dashed;
122 } else {
123 System.out.println(I18n.tr("Illegal dash pattern, at least one value must be > 0"));
124 }
125 }
126}
Note: See TracBrowser for help on using the repository browser.