1 | // License: GPL. For details, see Readme.txt file.
|
---|
2 | package org.openstreetmap.gui.jmapviewer;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Font;
|
---|
6 | import java.awt.Graphics;
|
---|
7 | import java.awt.Point;
|
---|
8 | import java.awt.Stroke;
|
---|
9 |
|
---|
10 | import javax.swing.UIManager;
|
---|
11 |
|
---|
12 | public abstract class MapObjectImpl {
|
---|
13 | private Layer layer;
|
---|
14 | private String name;
|
---|
15 | private Style style;
|
---|
16 | private Boolean visible;
|
---|
17 |
|
---|
18 | public MapObjectImpl(String name) {
|
---|
19 | this(null, name, null);
|
---|
20 | }
|
---|
21 | public MapObjectImpl(Layer layer) {
|
---|
22 | this(layer, null, null);
|
---|
23 | }
|
---|
24 | public MapObjectImpl(Layer layer, String name, Style style) {
|
---|
25 | super();
|
---|
26 | this.layer = layer;
|
---|
27 | this.name = name;
|
---|
28 | this.style = style;
|
---|
29 | }
|
---|
30 | public Layer getLayer() {
|
---|
31 | return layer;
|
---|
32 | }
|
---|
33 | public void setLayer(Layer layer) {
|
---|
34 | this.layer = layer;
|
---|
35 | }
|
---|
36 | public Style getStyle(){
|
---|
37 | return style;
|
---|
38 | }
|
---|
39 | public Style getStyleAssigned(){
|
---|
40 | return style == null ? (layer == null ? null : layer.getStyle()) : style;
|
---|
41 | }
|
---|
42 | public void setStyle(Style style){
|
---|
43 | this.style = style;
|
---|
44 | }
|
---|
45 | public Color getColor() {
|
---|
46 | Style styleAssigned = getStyleAssigned();
|
---|
47 | return styleAssigned == null ? null : getStyleAssigned().getColor();
|
---|
48 | }
|
---|
49 | public void setColor(Color color) {
|
---|
50 | if(style==null&&color!=null) style=new Style();
|
---|
51 | if(style!=null) style.setColor(color);
|
---|
52 | }
|
---|
53 |
|
---|
54 | public Color getBackColor() {
|
---|
55 | Style styleAssigned = getStyleAssigned();
|
---|
56 | return styleAssigned == null ? null : getStyleAssigned().getBackColor();
|
---|
57 | }
|
---|
58 | public void setBackColor(Color backColor) {
|
---|
59 | if(style==null&&backColor!=null) style=new Style();
|
---|
60 | if(style!=null) style.setBackColor(backColor);
|
---|
61 | }
|
---|
62 |
|
---|
63 | public Stroke getStroke() {
|
---|
64 | Style styleAssigned = getStyleAssigned();
|
---|
65 | return styleAssigned == null ? null : getStyleAssigned().getStroke();
|
---|
66 | }
|
---|
67 | public void setStroke(Stroke stroke) {
|
---|
68 | if(style==null&&stroke!=null) style=new Style();
|
---|
69 | if(style!=null) style.setStroke(stroke);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public Font getFont() {
|
---|
73 | Style styleAssigned = getStyleAssigned();
|
---|
74 | return styleAssigned == null ? null : getStyleAssigned().getFont();
|
---|
75 | }
|
---|
76 | public void setFont(Font font) {
|
---|
77 | if(style==null&&font!=null) style=new Style();
|
---|
78 | if(style!=null) style.setFont(font);
|
---|
79 | }
|
---|
80 | private boolean isVisibleLayer(){
|
---|
81 | return layer==null||layer.isVisible()==null?true:layer.isVisible();
|
---|
82 | }
|
---|
83 | public boolean isVisible() {
|
---|
84 | return visible==null?isVisibleLayer():visible.booleanValue();
|
---|
85 | }
|
---|
86 | public void setVisible(Boolean visible) {
|
---|
87 | this.visible = visible;
|
---|
88 | }
|
---|
89 | public String getName() {
|
---|
90 | return name;
|
---|
91 | }
|
---|
92 | public void setName(String txt) {
|
---|
93 | this.name = txt;
|
---|
94 | }
|
---|
95 | public static Font getDefaultFont(){
|
---|
96 | Font f = UIManager.getDefaults().getFont("TextField.font");
|
---|
97 | return new Font(f.getName(), Font.BOLD, f.getSize());
|
---|
98 | }
|
---|
99 | public void paintText(Graphics g, Point position) {
|
---|
100 | if(name!=null && g!=null && position!=null){
|
---|
101 | if(getFont()==null){
|
---|
102 | Font f = getDefaultFont();
|
---|
103 | setFont(new Font(f.getName(), Font.BOLD, f.getSize()));
|
---|
104 | }
|
---|
105 | g.setColor(Color.DARK_GRAY);
|
---|
106 | g.setFont(getFont());
|
---|
107 | g.drawString(name, position.x+MapMarkerDot.DOT_RADIUS+2, position.y+MapMarkerDot.DOT_RADIUS);
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|