| 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 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 | }
|
|---|