| 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 int 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 | }
|
|---|
| 33 |
|
|---|
| 34 | public LineElemStyle(LineElemStyle s, Collection<LineElemStyle> overlays) {
|
|---|
| 35 | this.width = s.width;
|
|---|
| 36 | this.realWidth = s.realWidth;
|
|---|
| 37 | this.color = s.color;
|
|---|
| 38 | this.dashed = s.dashed;
|
|---|
| 39 | this.dashedColor = s.dashedColor;
|
|---|
| 40 | this.over = s.over;
|
|---|
| 41 | this.widthMode = s.widthMode;
|
|---|
| 42 |
|
|---|
| 43 | this.priority = s.priority;
|
|---|
| 44 | this.maxScale = s.maxScale;
|
|---|
| 45 | this.minScale = s.minScale;
|
|---|
| 46 |
|
|---|
| 47 | this.overlays = overlays;
|
|---|
| 48 | this.code = s.code;
|
|---|
| 49 | for (LineElemStyle o : overlays)
|
|---|
| 50 | this.code += o.code;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | public LineElemStyle() { init(); }
|
|---|
| 54 |
|
|---|
| 55 | public void init()
|
|---|
| 56 | {
|
|---|
| 57 | width = 1;
|
|---|
| 58 | realWidth = 0;
|
|---|
| 59 | dashed = 0;
|
|---|
| 60 | dashedColor = null;
|
|---|
| 61 | priority = 0;
|
|---|
| 62 | color = null;
|
|---|
| 63 | over = true; // only used for line modifications
|
|---|
| 64 | widthMode = WidthMode.ABSOLUTE;
|
|---|
| 65 | overlays = null;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | // get width for overlays
|
|---|
| 69 | public int getWidth(int ref)
|
|---|
| 70 | {
|
|---|
| 71 | int res;
|
|---|
| 72 | if(widthMode == WidthMode.ABSOLUTE)
|
|---|
| 73 | res = width;
|
|---|
| 74 | else if(widthMode == WidthMode.OFFSET)
|
|---|
| 75 | res = ref + width;
|
|---|
| 76 | else
|
|---|
| 77 | {
|
|---|
| 78 | if(width < 0)
|
|---|
| 79 | res = 0;
|
|---|
| 80 | else
|
|---|
| 81 | res = ref*width/100;
|
|---|
| 82 | }
|
|---|
| 83 | return res <= 0 ? 1 : res;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | public int compareTo(LineElemStyle s)
|
|---|
| 87 | {
|
|---|
| 88 | if(s.priority != priority)
|
|---|
| 89 | return s.priority > priority ? 1 : -1;
|
|---|
| 90 | if(!over && s.over)
|
|---|
| 91 | return -1;
|
|---|
| 92 | // we have no idea how to order other objects :-)
|
|---|
| 93 | return 0;
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|