001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/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,
084: MapOperationFactor[] offeredPanFactors,
085: MapOperationFactor[] offeredZoomFactors, double minScale,
086: double maxScale) {
087: setOfferedInfoFormats(offeredInfoFormats);
088: setOfferedPanFactors(offeredPanFactors);
089: setOfferedZoomFactors(offeredZoomFactors);
090: setMinScale(minScale);
091: setMaxScale(maxScale);
092: }
093:
094: /**
095: * sets the offered pan factors (% of the map size) for a map context
096: *
097: * @param panFactors
098: */
099: public void setOfferedPanFactors(MapOperationFactor[] panFactors) {
100: offeredPanFactors.clear();
101:
102: if (panFactors != null) {
103: for (int i = 0; i < panFactors.length; i++) {
104: addPanFactor(panFactors[i]);
105: }
106: }
107: }
108:
109: /**
110: * add a pan factor to a map context
111: *
112: * @param panFactor
113: */
114: public void addPanFactor(MapOperationFactor panFactor) {
115: offeredPanFactors.add(panFactor);
116: }
117:
118: /**
119: * returns the list of pan factors offered by this map context
120: *
121: * @return list of pan factors offered by this map context
122: */
123: public MapOperationFactor[] getOfferedPanFactors() {
124: MapOperationFactor[] ms = new MapOperationFactor[0];
125:
126: if (offeredPanFactors.size() == 0) {
127: ms = null;
128: } else {
129: ms = new MapOperationFactor[offeredPanFactors.size()];
130: ms = offeredPanFactors.toArray(ms);
131: }
132:
133: return ms;
134: }
135:
136: /**
137: * returns the pan factor that is marked as selected. If no pan factor is marked, the first pan
138: * factor will be returned.
139: *
140: * @return pan factor that is marked as selected
141: */
142: public MapOperationFactor getSelectedPanFactor() {
143: MapOperationFactor ms = offeredPanFactors.get(0);
144:
145: for (int i = 0; i < offeredPanFactors.size(); i++) {
146: MapOperationFactor tmp = offeredPanFactors.get(i);
147: if (tmp.isSelected()) {
148: ms = tmp;
149: break;
150: }
151: }
152:
153: return ms;
154: }
155:
156: /**
157: * removes a pan factor from a context
158: *
159: * @param panFactor
160: */
161: public void removePanFactor(MapOperationFactor panFactor)
162: throws ContextException {
163: for (int i = 0; i < offeredPanFactors.size(); i++) {
164: MapOperationFactor mof = offeredPanFactors.get(i);
165: if (mof.getFactor() == panFactor.getFactor()) {
166: if (mof.isSelected()) {
167: throw new ContextException(
168: "The PanFactor can't be removed "
169: + "from the context because it is the "
170: + "current one");
171: }
172: }
173: }
174: }
175:
176: /**
177: * sets the offered zoom factors (% of the map size) for a map context
178: *
179: * @param zoomFactors
180: */
181: public void setOfferedZoomFactors(MapOperationFactor[] zoomFactors) {
182: offeredZoomFactors.clear();
183:
184: if (zoomFactors != null) {
185: for (int i = 0; i < zoomFactors.length; i++) {
186: addZoomFactor(zoomFactors[i]);
187: }
188: }
189: }
190:
191: /**
192: * adds a zoom factor to a map context
193: *
194: * @param zoomFactor
195: */
196: public void addZoomFactor(MapOperationFactor zoomFactor) {
197: offeredZoomFactors.add(zoomFactor);
198: }
199:
200: /**
201: * returns the list of zoom factors offered by the map context
202: *
203: * @return list of zoom factors offered by the map context
204: */
205: public MapOperationFactor[] getOfferedZoomFactors() {
206: MapOperationFactor[] ms = new MapOperationFactor[0];
207:
208: if (offeredZoomFactors.size() == 0) {
209: ms = null;
210: } else {
211: ms = new MapOperationFactor[offeredZoomFactors.size()];
212: ms = offeredZoomFactors.toArray(ms);
213: }
214:
215: return ms;
216: }
217:
218: /**
219: * returns the zoom factor that is marked as selected. If no zoom factor is marked, the first
220: * zoom factor will be returned.
221: *
222: * @return zoom factor that is marked as selected
223: */
224: public MapOperationFactor getSelectedZoomFactor() {
225: MapOperationFactor ms = offeredZoomFactors.get(0);
226:
227: for (int i = 0; i < offeredPanFactors.size(); i++) {
228: MapOperationFactor tmp = offeredZoomFactors.get(i);
229:
230: if (tmp.isSelected()) {
231: ms = tmp;
232: break;
233: }
234: }
235:
236: return ms;
237: }
238:
239: /**
240: * removes a zomm factor from a map context
241: *
242: * @param zoomFactor
243: */
244: public void removeZoomFactor(MapOperationFactor zoomFactor)
245: throws ContextException {
246: for (int i = 0; i < offeredZoomFactors.size(); i++) {
247: MapOperationFactor mof = offeredZoomFactors.get(i);
248: if (mof.getFactor() == zoomFactor.getFactor()) {
249: if (mof.isSelected()) {
250: throw new ContextException(
251: "The ZoomFactor can't be removed "
252: + "from the context because it is the current one");
253: }
254: }
255: }
256: }
257:
258: /**
259: * sets the info formats offered by a map context
260: *
261: * @param infoFormats
262: */
263: public void setOfferedInfoFormats(Format[] infoFormats) {
264: offeredInfoFormats.clear();
265:
266: if (infoFormats != null) {
267: for (int i = 0; i < infoFormats.length; i++) {
268: addInfoFormat(infoFormats[i]);
269: }
270: }
271: }
272:
273: /**
274: * adds an info format to a map context
275: *
276: * @param infoFormat
277: */
278: public void addInfoFormat(Format infoFormat) {
279: offeredInfoFormats.add(infoFormat);
280: }
281:
282: /**
283: * returns the list of map formats offered by the map context
284: *
285: * @return list of map formats offered by the map context
286: */
287: public Format[] getOfferedInfoFormats() {
288: Format[] ms = new Format[0];
289:
290: if (offeredInfoFormats.size() == 0) {
291: ms = null;
292: } else {
293: ms = new Format[offeredInfoFormats.size()];
294: ms = offeredInfoFormats.toArray(ms);
295: }
296:
297: return ms;
298: }
299:
300: /**
301: * returns the info format that is marked as selected. If no info format is marked, the first
302: * info format will be returned.
303: *
304: * @return info format that is marked as selected
305: */
306: public Format getSelectedInfoFormat() {
307: Format ms = offeredInfoFormats.get(0);
308: for (int i = 0; i < offeredInfoFormats.size(); i++) {
309: Format tmp = offeredInfoFormats.get(i);
310:
311: if (tmp.isCurrent()) {
312: ms = tmp;
313: break;
314: }
315: }
316:
317: return ms;
318: }
319:
320: /**
321: * removes an info format from a map context
322: *
323: * @param format
324: */
325: public void removeInfoFormat(Format format) throws ContextException {
326: for (int i = 0; i < offeredInfoFormats.size(); i++) {
327: Format frmt = offeredInfoFormats.get(i);
328: if (frmt.getName() == format.getName()) {
329: if (format.isCurrent()) {
330: throw new ContextException(
331: "The Info Format can't be removed "
332: + "from the context because it is the "
333: + "current one");
334: }
335: }
336: }
337: }
338:
339: /**
340: * returns the minimum map scale as defined at the OGC WMS specs that is offered by the map
341: * context
342: *
343: * @return minimum scale
344: */
345: public double getMinScale() {
346: return minScale;
347: }
348:
349: /**
350: * sets the minimum map scale as defined at the OGC WMS specs that is offered by the map context
351: *
352: * @param minScale
353: */
354: public void setMinScale(double minScale) {
355: this .minScale = minScale;
356: }
357:
358: /**
359: * returns the maximum map scale as defined at the OGC WMS specs that is offered by the map
360: * context
361: *
362: * @return maximum scale
363: */
364: public double getMaxScale() {
365: return maxScale;
366: }
367:
368: /**
369: * sets the maximum map scale as defined at the OGC WMS specs that is offered by the map context
370: *
371: * @param maxScale
372: */
373: public void setMaxScale(double maxScale) {
374: this .maxScale = maxScale;
375: }
376:
377: /**
378: *
379: *
380: * @return XML coded
381: */
382: public String exportAsXML() {
383: return null;
384: }
385: }
|