001    /*
002     * This file is part of McIDAS-V
003     *
004     * Copyright 2007-2013
005     * Space Science and Engineering Center (SSEC)
006     * University of Wisconsin - Madison
007     * 1225 W. Dayton Street, Madison, WI 53706, USA
008     * https://www.ssec.wisc.edu/mcidas
009     * 
010     * All Rights Reserved
011     * 
012     * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013     * some McIDAS-V source code is based on IDV and VisAD source code.  
014     * 
015     * McIDAS-V is free software; you can redistribute it and/or modify
016     * it under the terms of the GNU Lesser Public License as published by
017     * the Free Software Foundation; either version 3 of the License, or
018     * (at your option) any later version.
019     * 
020     * McIDAS-V is distributed in the hope that it will be useful,
021     * but WITHOUT ANY WARRANTY; without even the implied warranty of
022     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023     * GNU Lesser Public License for more details.
024     * 
025     * You should have received a copy of the GNU Lesser Public License
026     * along with this program.  If not, see http://www.gnu.org/licenses.
027     */
028    
029    package edu.wisc.ssec.mcidasv.data;
030    
031    import ucar.unidata.geoloc.ProjectionImpl;
032    import ucar.unidata.geoloc.ProjectionRect;
033    import ucar.unidata.geoloc.projection.LatLonProjection;
034    
035    /**
036     * An extension of <tt>LatLonProjection</tt> that adds properties for 
037     * the center point and dimensions of the projection box.  Appropriate
038     * getters and setters are added so they will be picked up by the
039     * <tt>ProjectionImpl</tt> and thereby editable by the user.
040     * 
041     * @author McIDAS-V Dev Team, UW SSEC
042     * @version $Id$
043     */
044    public class McIDASVLatLonProjection extends LatLonProjection {
045    
046            private static final long serialVersionUID = -4939597425144220140L;
047    
048            public McIDASVLatLonProjection() {
049                    this("");
050            }
051    
052            public McIDASVLatLonProjection(String name) {
053                    this(name, new ProjectionRect(-180, -90, 180, 90));
054            }
055    
056            public McIDASVLatLonProjection(String name, ProjectionRect mapArea) {
057            addParameter("grid_mapping_name", "McVLatLon");
058            this.name = name;
059            defaultMapArea = mapArea;
060            }
061            
062        /**
063         * Get the class name
064         * @return class name
065         */
066        public String getClassName() {
067            return "McVLatLon";
068        }
069    
070    
071        /**
072         * Get the label to be used in the gui for this type of projection
073         *
074         * @return Type label
075         */
076        public String getProjectionTypeLabel() {
077            return "McV Lat/Lon";
078        }
079            
080            /**
081             * Set the center of the projection box X coord.
082             * @param x
083             */
084            public void setCenterX(double x) {
085                    defaultMapArea.x = x - defaultMapArea.width/2;
086            }
087            
088            /**
089             * Set the center of the projection box Y coord.
090             * @param y
091             */
092            public void setCenterY(double y) {
093                    defaultMapArea.y = y - defaultMapArea.height/2;
094            }
095            
096            /**
097             * Set the overall width of the projection box.
098             * @param w
099             */
100            public void setLonWidth(double w) {
101                    defaultMapArea.width = w;
102            }
103            
104            /**
105             * Set the overall height of the projection box
106             * @param h
107             */
108            public void setLatHeight(double h) {
109                    defaultMapArea.height = h;
110            }
111            
112            public double getCenterX() {
113                    return defaultMapArea.x + defaultMapArea.width/2;
114            }
115            
116            public double getCenterY() {
117                    return defaultMapArea.y + defaultMapArea.height/2;
118            }
119    
120            public double getLonWidth() {
121                    return defaultMapArea.width;
122            }
123            
124            public double getLatHeight() {
125                    return defaultMapArea.height;
126            }
127            
128        /**
129         * Make the default display projection
130         * @return Default display projection
131         */
132        protected ProjectionImpl makeDefaultProjection() {
133            return new McIDASVLatLonProjection("World",
134                                        new ProjectionRect(-180., -180., 180.,
135                                            180.));
136        }
137            
138    }