001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.form.wms;
006:
007: import org.apache.struts.action.ActionErrors;
008: import org.apache.struts.action.ActionForm;
009: import org.apache.struts.action.ActionMapping;
010: import org.vfny.geoserver.config.WMSConfig;
011: import java.util.ArrayList;
012: import java.util.List;
013: import javax.servlet.ServletContext;
014: import javax.servlet.http.HttpServletRequest;
015:
016: public class WMSRenderingForm extends ActionForm {
017: List svgRenderers;
018: String svgRenderer;
019: boolean svgAntiAlias;
020: List intTypes;
021: String allowInterpolation;
022:
023: /*
024: * Because of the way that STRUTS works, if the user does not check the enabled box,
025: * or unchecks it, setEnabled() is never called, thus we must monitor setEnabled()
026: * to see if it doesn't get called. This must be accessible, as ActionForms need to
027: * know about it -- there is no way we can tell whether we are about to be passed to
028: * an ActionForm or not.
029: *
030: * Probably a better way to do this, but I can't think of one.
031: * -rgould
032: *
033: * TODO: Hey richard Jody here - Struts knows that boolean properties are
034: * not set if the user does nothing. Apparently that is why the reset
035: * method exists.
036: * Reset is called *every* time on ActionForm. Before the populate
037: * process has a go at things.
038: *
039: * The problem is that reset() retrieves the WFS's config enabled value
040: * and uses that to pre-populate the form. Thus, if they deselect it, setEnabled is
041: * never called, and enabled still remains true. The way I have done it isn't simple,
042: * but it works just fine.
043: */
044: private boolean svgAntiAliasChecked = false;
045:
046: public WMSRenderingForm() {
047: svgRenderers = new ArrayList();
048: svgRenderers.add(WMSConfig.SVG_SIMPLE);
049: svgRenderers.add(WMSConfig.SVG_BATIK);
050: svgAntiAlias = true;
051: intTypes = new ArrayList();
052: intTypes.add(WMSConfig.INT_NEAREST);
053: intTypes.add(WMSConfig.INT_BIlINEAR);
054: intTypes.add(WMSConfig.INT_BICUBIC);
055: }
056:
057: public void reset(ActionMapping mapping, HttpServletRequest request) {
058: super .reset(mapping, request);
059:
060: ServletContext context = getServlet().getServletContext();
061: WMSConfig config = (WMSConfig) context
062: .getAttribute(WMSConfig.CONFIG_KEY);
063:
064: svgRenderer = config.getSvgRenderer();
065:
066: if (svgRenderer == null) {
067: svgRenderer = WMSConfig.SVG_SIMPLE;
068: }
069:
070: svgAntiAlias = config.getSvgAntiAlias();
071:
072: allowInterpolation = config.getAllowInterpolation();
073:
074: if (allowInterpolation == null) {
075: allowInterpolation = WMSConfig.INT_BIlINEAR;
076: }
077: }
078:
079: public ActionErrors validate(ActionMapping mapping,
080: HttpServletRequest request) {
081: ActionErrors errors = new ActionErrors();
082:
083: return errors;
084: }
085:
086: public void setSvgRenderer(String svgRenderer) {
087: this .svgRenderer = svgRenderer;
088: }
089:
090: public String getSvgRenderer() {
091: return svgRenderer;
092: }
093:
094: public List getSvgRenderers() {
095: return svgRenderers;
096: }
097:
098: /**
099: * @param svgAntiAlias anti alias hint.
100: */
101: public void setSvgAntiAlias(boolean svgAntiAlias) {
102: svgAntiAliasChecked = true;
103: this .svgAntiAlias = svgAntiAlias;
104: }
105:
106: /**
107: * @return The value of the anti aliasing rendering hint.
108: */
109: public boolean getSvgAntiAlias() {
110: return svgAntiAlias;
111: }
112:
113: /**
114: * DOCUMENT ME!
115: *
116: * @return
117: */
118: public boolean isSvgAntiAliasChecked() {
119: return svgAntiAliasChecked;
120: }
121:
122: /**
123: * @param allowInterpolation interpolation rendering hint.
124: */
125: public void setAllowInterpolation(String allowInterpolation) {
126: this .allowInterpolation = allowInterpolation;
127: }
128:
129: /**
130: * @return The value of the interpolation rendering hint.
131: */
132: public String getAllowInterpolation() {
133: return allowInterpolation;
134: }
135:
136: public List getIntTypes() {
137: return intTypes;
138: }
139:
140: /**
141: * DOCUMENT ME!
142: *
143: * @param b
144: */
145: public void setEnabledChecked(boolean svgAntiAliasChecked) {
146: this.svgAntiAliasChecked = svgAntiAliasChecked;
147: }
148: }
|