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