source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java@ 3930

Last change on this file since 3930 was 3903, checked in by bastiK, 13 years ago

mapcss: minor fixes

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import static org.openstreetmap.josm.tools.Utils.equal;
5
6import java.awt.Font;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.data.osm.OsmPrimitive;
10import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
11import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
12import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat;
13
14abstract public class ElemStyle {
15
16 public float z_index;
17 public float object_z_index;
18 public boolean isModifier; // false, if style can serve as main style for the
19 // primitive; true, if it is a highlight or modifier
20
21 public ElemStyle(float z_index, float object_z_index, boolean isModifier) {
22 this.z_index = z_index;
23 this.object_z_index = object_z_index;
24 this.isModifier = isModifier;
25 }
26
27 protected ElemStyle(Cascade c) {
28 z_index = c.get("z-index", 0f, Float.class);
29 object_z_index = c.get("object-z-index", 0f, Float.class);
30 isModifier = c.get("modifier", false, Boolean.class);
31 }
32
33 public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member);
34
35 protected static Float getWidth(Cascade c, String key, Float relativeTo) {
36 Float width = c.get(key, null, Float.class, true);
37 if (width != null) {
38 if (width > 0)
39 return width;
40 } else {
41 String width_key = c.get(key, null, String.class, true);
42 if (equal(width_key, "thinnest"))
43 return 0f;
44 else if(equal(width_key, "default"))
45 return (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth();
46 else if (relativeTo != null) {
47 RelativeFloat width_rel = c.get(key, null, RelativeFloat.class, true);
48 if (width_rel != null)
49 return relativeTo + width_rel.val;
50 }
51 }
52 return null;
53 }
54
55 protected static Font getFont(Cascade c) {
56 String name = c.get("font-family", Main.pref.get("mappaint.font", "Helvetica"), String.class);
57 float size = c.get("font-size", (float) Main.pref.getInteger("mappaint.fontsize", 8), Float.class);
58 int weight = Font.PLAIN;
59 String weightStr = c.get("font-wheight", null, String.class);
60 if (equal(weightStr, "bold")) {
61 weight = Font.BOLD;
62 }
63 int style = Font.PLAIN;
64 String styleStr = c.get("font-style", null, String.class);
65 if (equal(styleStr, "italic")) {
66 style = Font.ITALIC;
67 }
68 return new Font(name, weight | style, Math.round(size));
69 }
70
71 @Override
72 public boolean equals(Object o) {
73 if (!(o instanceof ElemStyle))
74 return false;
75 ElemStyle s = (ElemStyle) o;
76 return z_index == s.z_index && object_z_index == s.object_z_index && isModifier == s.isModifier;
77 }
78
79 @Override
80 public int hashCode() {
81 int hash = 5;
82 hash = 41 * hash + Float.floatToIntBits(this.z_index);
83 hash = 41 * hash + Float.floatToIntBits(this.object_z_index);
84 hash = 41 * hash + (isModifier ? 1 : 0);
85 return hash;
86 }
87
88 @Override
89 public String toString() {
90 if (z_index != 0f || object_z_index != 0f)
91 return String.format("z_idx=%s/%s ", z_index, object_z_index) + (isModifier ? "modifier " : "");
92 return "";
93 }
94}
Note: See TracBrowser for help on using the repository browser.