001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/portal/portlet/jsp/taglib/IGeoPortalPanButtonTag.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.portlet.jsp.taglib;
037    
038    import java.io.IOException;
039    import java.util.ArrayList;
040    
041    import javax.servlet.jsp.JspException;
042    import javax.servlet.jsp.JspWriter;
043    import javax.servlet.jsp.tagext.TagSupport;
044    
045    import org.deegree.framework.util.StringTools;
046    
047    /**
048     *
049     *
050     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
051     * @author last edited by: $Author: mschneider $
052     *
053     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
054     */
055    public class IGeoPortalPanButtonTag extends TagSupport {
056    
057        /**
058         *
059         */
060        private static final long serialVersionUID = -8722131286601433700L;
061    
062        private String direction = null;
063    
064        private String imageBase = "./igeoportal/images/";
065    
066        private int width;
067    
068        private int height;
069    
070        /**
071         * @return direction
072         */
073        public String getDirection() {
074            return direction;
075        }
076    
077        /**
078         *
079         * @param direction
080         */
081        public void setDirection( String direction ) {
082            this.direction = direction;
083        }
084    
085        /**
086         *
087         * @return imageBase
088         */
089        public String getImageBase() {
090            return imageBase;
091        }
092    
093        /**
094         *
095         * @param imageBase
096         */
097        public void setImageBase( String imageBase ) {
098            this.imageBase = imageBase;
099        }
100    
101        @Override
102        public int doStartTag()
103                                throws JspException {
104    
105            ArrayList list = (ArrayList) pageContext.getRequest().getAttribute( "PANBUTTONS" );
106            String portletID = (String) pageContext.getRequest().getAttribute( "PORTLETID" );
107            portletID = StringTools.replace( portletID, "-", "", true );
108            if ( list.contains( direction ) ) {
109                try {
110                    pageContext.getOut().flush();
111    
112                    String img = StringTools.concat( 300, "<a href=\"javascript:mapWindowPortlet", portletID, '.',
113                                                     "pan( '$2', 25 );\" ><img src='./igeoportal/images/$1Arrow.gif' ",
114                                                     "border='0'" );
115                    StringBuffer sb = new StringBuffer( img );
116                    if ( width > 0 ) {
117                        sb.append( " width='" ).append( width ).append( "' " );
118                    }
119                    if ( height > 0 ) {
120                        sb.append( " height='" ).append( height ).append( "' " );
121                    }
122    
123                    // sb.append( " title='pan $1'/></a>" );
124    
125                    String pan = IGeoPortalL10nTag.getMessage( "MapWindow.pan" + direction );
126    
127                    sb.append( " title='" ).append( pan ).append( "'/></a>" );
128    
129                    img = sb.toString();
130                    if ( direction.equals( "NORTH" ) ) {
131                        img = StringTools.replace( img, "$1", "north", true );
132                        img = StringTools.replace( img, "$2", "N", true );
133                    } else if ( direction.equals( "NORTHEAST" ) ) {
134                        img = StringTools.replace( img, "$1", "northEast", true );
135                        img = StringTools.replace( img, "$2", "NE", true );
136                    } else if ( direction.equals( "NORTHWEST" ) ) {
137                        img = StringTools.replace( img, "$1", "northWest", true );
138                        img = StringTools.replace( img, "$2", "NW", true );
139                    } else if ( direction.equals( "WEST" ) ) {
140                        img = StringTools.replace( img, "$1", "west", true );
141                        img = StringTools.replace( img, "$2", "W", true );
142                    } else if ( direction.equals( "EAST" ) ) {
143                        img = StringTools.replace( img, "$1", "east", true );
144                        img = StringTools.replace( img, "$2", "E", true );
145                    } else if ( direction.equals( "SOUTH" ) ) {
146                        img = StringTools.replace( img, "$1", "south", true );
147                        img = StringTools.replace( img, "$2", "S", true );
148                    } else if ( direction.equals( "SOUTHEAST" ) ) {
149                        img = StringTools.replace( img, "$1", "southEast", true );
150                        img = StringTools.replace( img, "$2", "SE", true );
151                    } else if ( direction.equals( "SOUTHWEST" ) ) {
152                        img = StringTools.replace( img, "$1", "southWest", true );
153                        img = StringTools.replace( img, "$2", "SW", true );
154                    }
155    
156                    JspWriter pw = pageContext.getOut();
157                    pw.print( img.toString() );
158                } catch ( IOException e ) {
159                    e.printStackTrace();
160                    String message = "Error processing name '" + direction + "'.";
161                    try {
162                        pageContext.getOut().print( message );
163                    } catch ( java.io.IOException ioe ) {
164                        //nottin
165                    }
166                }
167            }
168    
169            return SKIP_BODY;
170        }
171    
172        /**
173         * @return width
174         */
175        public int getWidth() {
176            return width;
177        }
178    
179        /**
180         * @param width
181         */
182        public void setWidth( int width ) {
183            this.width = width;
184        }
185    
186        /**
187         * @return height
188         */
189        public int getHeight() {
190            return height;
191        }
192    
193        /**
194         * @param height
195         */
196        public void setHeight( int height ) {
197            this.height = height;
198        }
199    }