001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/portal/context/MapParameter.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstr. 19
030 53115 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042
043 ---------------------------------------------------------------------------*/
044 package org.deegree.portal.context;
045
046 import java.util.ArrayList;
047
048 /**
049 * encapsulates the part of the general web map context extension parameters that targets the map
050 * operation and feature info format options. These are informations about the possible values and
051 * the current selected value for each of the encapsulated parameters: <p/> feature info formats<p/>
052 * pan factors (% of the map size) <p/> zoom factors (% of the map factors) <p/> minimum displayable
053 * scale (WMS scale definition) <p/> maximum displayable scale (WMS scale definition) <p/>
054 *
055 * @version $Revision: 9346 $
056 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
057 */
058 public class MapParameter {
059 private ArrayList<Format> offeredInfoFormats = new ArrayList<Format>();
060
061 private ArrayList<MapOperationFactor> offeredPanFactors = new ArrayList<MapOperationFactor>();
062
063 private ArrayList<MapOperationFactor> offeredZoomFactors = new ArrayList<MapOperationFactor>();
064
065 private double maxScale = 0;
066
067 private double minScale = 0;
068
069 /**
070 * Creates a new MapParameter object.
071 *
072 * @param offeredInfoFormats
073 * feature info formats
074 * @param offeredPanFactors
075 * pan factors (% of the map size)
076 * @param offeredZoomFactors
077 * pan factors (% of the map size)
078 * @param minScale
079 * minimum displayable scale (WMS scale definition)
080 * @param maxScale
081 * maximum displayable scale (WMS scale definition)
082 */
083 public MapParameter( Format[] offeredInfoFormats, MapOperationFactor[] offeredPanFactors,
084 MapOperationFactor[] offeredZoomFactors, double minScale, double maxScale ) {
085 setOfferedInfoFormats( offeredInfoFormats );
086 setOfferedPanFactors( offeredPanFactors );
087 setOfferedZoomFactors( offeredZoomFactors );
088 setMinScale( minScale );
089 setMaxScale( maxScale );
090 }
091
092 /**
093 * sets the offered pan factors (% of the map size) for a map context
094 *
095 * @param panFactors
096 */
097 public void setOfferedPanFactors( MapOperationFactor[] panFactors ) {
098 offeredPanFactors.clear();
099
100 if ( panFactors != null ) {
101 for ( int i = 0; i < panFactors.length; i++ ) {
102 addPanFactor( panFactors[i] );
103 }
104 }
105 }
106
107 /**
108 * add a pan factor to a map context
109 *
110 * @param panFactor
111 */
112 public void addPanFactor( MapOperationFactor panFactor ) {
113 offeredPanFactors.add( panFactor );
114 }
115
116 /**
117 * returns the list of pan factors offered by this map context
118 *
119 * @return list of pan factors offered by this map context
120 */
121 public MapOperationFactor[] getOfferedPanFactors() {
122 MapOperationFactor[] ms = new MapOperationFactor[0];
123
124 if ( offeredPanFactors.size() == 0 ) {
125 ms = null;
126 } else {
127 ms = new MapOperationFactor[offeredPanFactors.size()];
128 ms = offeredPanFactors.toArray( ms );
129 }
130
131 return ms;
132 }
133
134 /**
135 * returns the pan factor that is marked as selected. If no pan factor is marked, the first pan
136 * factor will be returned.
137 *
138 * @return pan factor that is marked as selected
139 */
140 public MapOperationFactor getSelectedPanFactor() {
141 MapOperationFactor ms = offeredPanFactors.get( 0 );
142
143 for ( int i = 0; i < offeredPanFactors.size(); i++ ) {
144 MapOperationFactor tmp = offeredPanFactors.get( i );
145 if ( tmp.isSelected() ) {
146 ms = tmp;
147 break;
148 }
149 }
150
151 return ms;
152 }
153
154 /**
155 * removes a pan factor from a context
156 *
157 * @param panFactor
158 */
159 public void removePanFactor( MapOperationFactor panFactor )
160 throws ContextException {
161 for ( int i = 0; i < offeredPanFactors.size(); i++ ) {
162 MapOperationFactor mof = offeredPanFactors.get( i );
163 if ( mof.getFactor() == panFactor.getFactor() ) {
164 if ( mof.isSelected() ) {
165 throw new ContextException( "The PanFactor can't be removed "
166 + "from the context because it is the " + "current one" );
167 }
168 }
169 }
170 }
171
172 /**
173 * sets the offered zoom factors (% of the map size) for a map context
174 *
175 * @param zoomFactors
176 */
177 public void setOfferedZoomFactors( MapOperationFactor[] zoomFactors ) {
178 offeredZoomFactors.clear();
179
180 if ( zoomFactors != null ) {
181 for ( int i = 0; i < zoomFactors.length; i++ ) {
182 addZoomFactor( zoomFactors[i] );
183 }
184 }
185 }
186
187 /**
188 * adds a zoom factor to a map context
189 *
190 * @param zoomFactor
191 */
192 public void addZoomFactor( MapOperationFactor zoomFactor ) {
193 offeredZoomFactors.add( zoomFactor );
194 }
195
196 /**
197 * returns the list of zoom factors offered by the map context
198 *
199 * @return list of zoom factors offered by the map context
200 */
201 public MapOperationFactor[] getOfferedZoomFactors() {
202 MapOperationFactor[] ms = new MapOperationFactor[0];
203
204 if ( offeredZoomFactors.size() == 0 ) {
205 ms = null;
206 } else {
207 ms = new MapOperationFactor[offeredZoomFactors.size()];
208 ms = offeredZoomFactors.toArray( ms );
209 }
210
211 return ms;
212 }
213
214 /**
215 * returns the zoom factor that is marked as selected. If no zoom factor is marked, the first
216 * zoom factor will be returned.
217 *
218 * @return zoom factor that is marked as selected
219 */
220 public MapOperationFactor getSelectedZoomFactor() {
221 MapOperationFactor ms = offeredZoomFactors.get( 0 );
222
223 for ( int i = 0; i < offeredPanFactors.size(); i++ ) {
224 MapOperationFactor tmp = offeredZoomFactors.get( i );
225
226 if ( tmp.isSelected() ) {
227 ms = tmp;
228 break;
229 }
230 }
231
232 return ms;
233 }
234
235 /**
236 * removes a zomm factor from a map context
237 *
238 * @param zoomFactor
239 */
240 public void removeZoomFactor( MapOperationFactor zoomFactor )
241 throws ContextException {
242 for ( int i = 0; i < offeredZoomFactors.size(); i++ ) {
243 MapOperationFactor mof = offeredZoomFactors.get( i );
244 if ( mof.getFactor() == zoomFactor.getFactor() ) {
245 if ( mof.isSelected() ) {
246 throw new ContextException( "The ZoomFactor can't be removed "
247 + "from the context because it is the current one" );
248 }
249 }
250 }
251 }
252
253 /**
254 * sets the info formats offered by a map context
255 *
256 * @param infoFormats
257 */
258 public void setOfferedInfoFormats( Format[] infoFormats ) {
259 offeredInfoFormats.clear();
260
261 if ( infoFormats != null ) {
262 for ( int i = 0; i < infoFormats.length; i++ ) {
263 addInfoFormat( infoFormats[i] );
264 }
265 }
266 }
267
268 /**
269 * adds an info format to a map context
270 *
271 * @param infoFormat
272 */
273 public void addInfoFormat( Format infoFormat ) {
274 offeredInfoFormats.add( infoFormat );
275 }
276
277 /**
278 * returns the list of map formats offered by the map context
279 *
280 * @return list of map formats offered by the map context
281 */
282 public Format[] getOfferedInfoFormats() {
283 Format[] ms = new Format[0];
284
285 if ( offeredInfoFormats.size() == 0 ) {
286 ms = null;
287 } else {
288 ms = new Format[offeredInfoFormats.size()];
289 ms = offeredInfoFormats.toArray( ms );
290 }
291
292 return ms;
293 }
294
295 /**
296 * returns the info format that is marked as selected. If no info format is marked, the first
297 * info format will be returned.
298 *
299 * @return info format that is marked as selected
300 */
301 public Format getSelectedInfoFormat() {
302 Format ms = offeredInfoFormats.get( 0 );
303 for ( int i = 0; i < offeredInfoFormats.size(); i++ ) {
304 Format tmp = offeredInfoFormats.get( i );
305
306 if ( tmp.isCurrent() ) {
307 ms = tmp;
308 break;
309 }
310 }
311
312 return ms;
313 }
314
315 /**
316 * removes an info format from a map context
317 *
318 * @param format
319 */
320 public void removeInfoFormat( Format format )
321 throws ContextException {
322 for ( int i = 0; i < offeredInfoFormats.size(); i++ ) {
323 Format frmt = offeredInfoFormats.get( i );
324 if ( frmt.getName() == format.getName() ) {
325 if ( format.isCurrent() ) {
326 throw new ContextException( "The Info Format can't be removed "
327 + "from the context because it is the " + "current one" );
328 }
329 }
330 }
331 }
332
333 /**
334 * returns the minimum map scale as defined at the OGC WMS specs that is offered by the map
335 * context
336 *
337 * @return minimum scale
338 */
339 public double getMinScale() {
340 return minScale;
341 }
342
343 /**
344 * sets the minimum map scale as defined at the OGC WMS specs that is offered by the map context
345 *
346 * @param minScale
347 */
348 public void setMinScale( double minScale ) {
349 this.minScale = minScale;
350 }
351
352 /**
353 * returns the maximum map scale as defined at the OGC WMS specs that is offered by the map
354 * context
355 *
356 * @return maximum scale
357 */
358 public double getMaxScale() {
359 return maxScale;
360 }
361
362 /**
363 * sets the maximum map scale as defined at the OGC WMS specs that is offered by the map context
364 *
365 * @param maxScale
366 */
367 public void setMaxScale( double maxScale ) {
368 this.maxScale = maxScale;
369 }
370
371 /**
372 *
373 *
374 * @return XML coded
375 */
376 public String exportAsXML() {
377 return null;
378 }
379 }