1 |
mojays |
2 |
package skrueger.geotools; |
2 |
|
|
|
3 |
|
|
import javax.swing.ImageIcon; |
4 |
|
|
|
5 |
|
|
import org.apache.log4j.Logger; |
6 |
|
|
import org.geotools.styling.Style; |
7 |
|
|
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
8 |
|
|
|
9 |
|
|
import schmitzm.lang.LangUtil; |
10 |
|
|
import skrueger.i8n.Translation; |
11 |
|
|
|
12 |
|
|
import com.vividsolutions.jts.geom.Envelope; |
13 |
|
|
|
14 |
|
|
/** |
15 |
|
|
* This class is a default implementation of {@link StyledMapInterface}. |
16 |
|
|
* {@link StyledMapInterface#dispose()} and {@link StyledMapInterface#uncache()} |
17 |
|
|
* must be implemented by the sub class. This class only implements the "hold" |
18 |
|
|
* of an geo object of type {@code <E>}. |
19 |
|
|
* @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany) |
20 |
|
|
* @version 1.0 |
21 |
|
|
*/ |
22 |
|
|
public abstract class AbstractStyledMap<E> implements StyledMapInterface<E> { |
23 |
|
|
/** Logger for warning- and error messages. */ |
24 |
|
|
protected Logger LOGGER = LangUtil.createLogger(this); |
25 |
|
|
|
26 |
|
|
/** Holds the unique ID of the geo object. */ |
27 |
|
|
protected String id = null; |
28 |
|
|
/** Holds a short (language-specific) description of the geo object. */ |
29 |
|
|
protected Translation title = null; |
30 |
|
|
/** Holds a long (language-specific) description of the geo object. */ |
31 |
|
|
protected Translation desc = null; |
32 |
|
|
/** Holds the (language-specific) keywords to describe the geo object. */ |
33 |
|
|
protected Translation keywords = null; |
34 |
|
|
/** Holds an icon to represent the geo object */ |
35 |
|
|
protected ImageIcon icon = null; |
36 |
|
|
/** Holds the geo object represeneted by the map */ |
37 |
|
|
protected E geoObject = null; |
38 |
|
|
/** Holds the CRS of the geo object */ |
39 |
|
|
protected CoordinateReferenceSystem crs = null; |
40 |
|
|
/** Holds the bounds of the geo object */ |
41 |
|
|
protected Envelope envelope = null; |
42 |
|
|
/** Holds the display style for the geo object */ |
43 |
|
|
protected Style style = null; |
44 |
|
|
|
45 |
|
|
/** |
46 |
|
|
* Creates a language specific styled map. |
47 |
|
|
* @param geoObject the geo object |
48 |
|
|
* @param envelope the bounds of the geo object |
49 |
|
|
* @param crs the CRS of the geo object |
50 |
|
|
* @param id a unique ID for the geo object |
51 |
|
|
* @param title a (language-specific) short description |
52 |
|
|
* @param desc a (language-specific) long description |
53 |
|
|
* @param keywords (language-specific) keywords for the geo objects |
54 |
|
|
* @param style a display style |
55 |
|
|
* @param icon an icon for the object |
56 |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID or |
57 |
|
|
* geo object |
58 |
|
|
*/ |
59 |
|
|
public AbstractStyledMap(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, Translation title, Translation desc, Translation keywords, Style style, ImageIcon icon) { |
60 |
|
|
if ( id == null ) |
61 |
|
|
throw new IllegalArgumentException("ID is not allowed to be null!"); |
62 |
|
|
if ( geoObject == null ) |
63 |
|
|
throw new IllegalArgumentException("The GeoObject is not allowed to be null!"); |
64 |
|
|
this.id = id; |
65 |
|
|
this.geoObject = geoObject; |
66 |
|
|
this.crs = crs; |
67 |
|
|
this.envelope = envelope; |
68 |
|
|
setTitle( title ); |
69 |
|
|
setDesc( desc ); |
70 |
|
|
setKeywords( keywords ); |
71 |
|
|
setStyle( style ); |
72 |
|
|
setImageIcon( icon ); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
/** |
76 |
|
|
* Creates a non-translated styled map. |
77 |
|
|
* @param geoObject the geo object |
78 |
|
|
* @param envelope the bounds of the geo object |
79 |
|
|
* @param crs the CRS of the geo object |
80 |
|
|
* @param id a unique ID for the geo object |
81 |
|
|
* @param title a short description |
82 |
|
|
* @param desc a long description |
83 |
|
|
* @param keywords keywords for the geo objects |
84 |
|
|
* @param style a display style |
85 |
|
|
* @param icon an icon for the object |
86 |
|
|
* @exception IllegalArgumentException if {@code null} is given as ID |
87 |
|
|
*/ |
88 |
|
|
public AbstractStyledMap(E geoObject, Envelope envelope, CoordinateReferenceSystem crs, String id, String title, String desc, String keywords, Style style, ImageIcon icon ) { |
89 |
|
|
this(geoObject, envelope, crs, id, (Translation)null, null, null, style, icon); |
90 |
|
|
setTitle( title ); |
91 |
|
|
setDesc( desc ); |
92 |
|
|
setKeywords( keywords ); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
/** |
96 |
|
|
* Returns a ID for the geo object. The ID should be unique in a map ob |
97 |
|
|
* {@linkplain StyledMapInterface styled map objects} |
98 |
|
|
*/ |
99 |
|
|
public String getId() { |
100 |
|
|
return id; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
/** |
104 |
|
|
* Returns a short (language-specific) description of the geo object. |
105 |
|
|
*/ |
106 |
|
|
public Translation getTitle() { |
107 |
|
|
return title; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
/** |
111 |
|
|
* Sets a short (language-specific) description of the geo object. |
112 |
|
|
* If {@code title} is {@code null} an untranslated default title is set, so |
113 |
|
|
* {@link #getTitle()} never returns {@code null}. |
114 |
|
|
* @param title new description for the geo object |
115 |
|
|
*/ |
116 |
|
|
public void setTitle(Translation title) { |
117 |
|
|
this.title = (title != null) ? title : new Translation("untitled"); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* Sets a short (non-translated) description of the geo object. |
122 |
|
|
* If {@code title} is {@code null} an untranslated default title is set, so |
123 |
|
|
* {@link #getTitle()} never returns {@code null}. |
124 |
|
|
* @param title new description for the geo object |
125 |
|
|
*/ |
126 |
|
|
public void setTitle(String title) { |
127 |
|
|
setTitle( title != null ? new Translation(title): (Translation)null ); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/** |
131 |
|
|
* Returns a long (language-specific) description of the object. |
132 |
|
|
*/ |
133 |
|
|
public Translation getDesc() { |
134 |
|
|
return desc; |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
/** |
138 |
|
|
* Sets a long (language-specific) description of the object. |
139 |
|
|
* If {@code desc} is {@code null} an (untranslated) empty description is set, so |
140 |
|
|
* {@link #getDesc()} never returns {@code null}. |
141 |
|
|
* @param desc new description for the geo object |
142 |
|
|
*/ |
143 |
|
|
public void setDesc(Translation desc) { |
144 |
|
|
this.desc = (desc != null) ? desc : new Translation(""); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/** |
148 |
|
|
* Sets a long (non-translated) description of the object. |
149 |
|
|
* If {@code desc} is {@code null} an (untranslated) empty description is set, so |
150 |
|
|
* {@link #getDesc()} never returns {@code null}. |
151 |
|
|
* @param desc new description for the geo object |
152 |
|
|
*/ |
153 |
|
|
public void setDesc(String desc) { |
154 |
|
|
setDesc( desc != null ? new Translation(desc) : (Translation)null); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
/** |
158 |
|
|
* Returns a (language-specific) key word sequence for the geo object. |
159 |
|
|
*/ |
160 |
|
|
public Translation getKeywords() { |
161 |
|
|
return keywords; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
/** |
165 |
|
|
* Sets a (language-specific) key word sequence for the geo object. |
166 |
|
|
* If {@code keywords} is {@code null} an (untranslated) empty string is set, so |
167 |
|
|
* {@link #getKeywords()} never returns {@code null}. |
168 |
|
|
* @param keywords Keywords |
169 |
|
|
*/ |
170 |
|
|
public void setKeywords(Translation keywords) { |
171 |
|
|
this.keywords = (keywords != null) ? keywords : new Translation(""); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
/** |
175 |
|
|
* Sets a (non-translated) key word sequence for the geo object. |
176 |
|
|
* If {@code keywords} is {@code null} an (untranslated) empty string is set, so |
177 |
|
|
* {@link #getKeywords()} never returns {@code null}. |
178 |
|
|
* @param keywords Keywords |
179 |
|
|
*/ |
180 |
|
|
public void setKeywords(String keywords) { |
181 |
|
|
setKeywords( keywords != null ? new Translation(keywords) : (Translation)null); |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
/** |
185 |
|
|
* Returns the geo object representet in the map. Sub classes must override |
186 |
|
|
* this method to implement "late loading" on first call. |
187 |
|
|
* @return {@link #geoObject} |
188 |
|
|
*/ |
189 |
|
|
public E getGeoObject() { |
190 |
|
|
return geoObject; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
/** |
194 |
|
|
* Returns the bounds of the geo object. |
195 |
|
|
*/ |
196 |
|
|
public Envelope getEnvelope() { |
197 |
|
|
return envelope; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
/** |
201 |
|
|
* Returns the {@link CoordinateReferenceSystem} of the geo object. |
202 |
|
|
*/ |
203 |
|
|
public CoordinateReferenceSystem getCrs() { |
204 |
|
|
return crs; |
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
/** |
208 |
|
|
* Returns {@link #crs CoordinateReferenceSystem.toString()}. This method |
209 |
|
|
* can be overriden to create a "nicer" description. |
210 |
|
|
*/ |
211 |
|
|
public String getCRSString() { |
212 |
|
|
return crs.toString(); |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
/** |
216 |
|
|
* Returns an icon, which represents the geo object. |
217 |
|
|
*/ |
218 |
|
|
public ImageIcon getImageIcon() { |
219 |
|
|
return null; |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
/** |
223 |
|
|
* Sets an icon, which represents the geo object. |
224 |
|
|
* @param icon an icon |
225 |
|
|
*/ |
226 |
|
|
public void setImageIcon(ImageIcon icon) { |
227 |
|
|
this.icon = icon; |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
/** |
231 |
|
|
* Returns the display style for the geo object. |
232 |
|
|
*/ |
233 |
|
|
public Style getStyle() { |
234 |
|
|
return style; |
235 |
|
|
} |
236 |
|
|
|
237 |
|
|
/** |
238 |
|
|
* Sets the display style for the geo object. |
239 |
|
|
* If {@code style} is {@code null} an default style is set, so |
240 |
|
|
* {@link #getStyle()} never returns {@code null}. |
241 |
|
|
* @see #createDefaultStyle() |
242 |
|
|
*/ |
243 |
|
|
public void setStyle(Style style) { |
244 |
|
|
this.style = (style != null) ? style : createDefaultStyle(); |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
/** |
248 |
|
|
* Creates a default style for the geo object. This style is used whenever |
249 |
|
|
* the style is set to {@code null}. |
250 |
|
|
* @see #setStyle(Style) |
251 |
|
|
*/ |
252 |
|
|
protected abstract Style createDefaultStyle(); |
253 |
|
|
} |