001    /*
002     * $Id: JYearChooser.java,v 1.3 2012/02/19 17:35:46 davep Exp $
003     *
004     * This file is part of McIDAS-V
005     *
006     * Copyright 2007-2012
007     * Space Science and Engineering Center (SSEC)
008     * University of Wisconsin - Madison
009     * 1225 W. Dayton Street, Madison, WI 53706, USA
010     * https://www.ssec.wisc.edu/mcidas
011     * 
012     * All Rights Reserved
013     * 
014     * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015     * some McIDAS-V source code is based on IDV and VisAD source code.  
016     * 
017     * McIDAS-V is free software; you can redistribute it and/or modify
018     * it under the terms of the GNU Lesser Public License as published by
019     * the Free Software Foundation; either version 3 of the License, or
020     * (at your option) any later version.
021     * 
022     * McIDAS-V is distributed in the hope that it will be useful,
023     * but WITHOUT ANY WARRANTY; without even the implied warranty of
024     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025     * GNU Lesser Public License for more details.
026     * 
027     * You should have received a copy of the GNU Lesser Public License
028     * along with this program.  If not, see http://www.gnu.org/licenses.
029     */
030    package edu.wisc.ssec.mcidasv.data.dateChooser;
031    
032    import com.toedter.components.JSpinField;
033    
034    import java.util.Calendar;
035    
036    import javax.swing.JFrame;
037    
038    
039    /**
040     * JYearChooser is a bean for choosing a year.
041     *
042     * @version $LastChangedRevision: 85 $
043     * @version $LastChangedDate: 2006-04-28 13:50:52 +0200 (Fr, 28 Apr 2006) $
044     */
045    public class JYearChooser extends JSpinField {
046            private static final long serialVersionUID = 2648810220491090064L;
047            protected JDayChooser dayChooser;
048        protected int oldYear;
049        protected int startYear;
050        protected int endYear;
051    
052        /**
053         * Default JCalendar constructor.
054         */
055        public JYearChooser() {
056            setName("JYearChooser");
057            Calendar calendar = Calendar.getInstance();
058            dayChooser = null;
059            setMinimum(calendar.getMinimum(Calendar.YEAR));
060            setMaximum(calendar.getMaximum(Calendar.YEAR));
061            setValue(calendar.get(Calendar.YEAR));
062        }
063    
064        /**
065         * Sets the year. This is a bound property.
066         *
067         * @param y the new year
068         *
069         * @see #getYear
070         */
071        public void setYear(int y) {
072            super.setValue(y, true, false);
073    
074            if (dayChooser != null) {
075                dayChooser.setYear(value);
076            }
077    
078            spinner.setValue(new Integer(value));
079            firePropertyChange("year", oldYear, value);
080            oldYear = value;
081        }
082    
083        /**
084         * Sets the year value.
085         *
086         * @param value the year value
087         */
088        public void setValue(int value) {
089            setYear(value);
090        }
091    
092        /**
093         * Returns the year.
094         *
095         * @return the year
096         */
097        public int getYear() {
098            return super.getValue();
099        }
100    
101        /**
102         * Convenience method set a day chooser that might be updated directly.
103         *
104         * @param dayChooser the day chooser
105         */
106        public void setDayChooser(JDayChooser dayChooser) {
107            this.dayChooser = dayChooser;
108        }
109    
110        /**
111         * Returns the endy ear.
112         *
113         * @return the end year
114         */
115        public int getEndYear() {
116            return getMaximum();
117        }
118    
119        /**
120         * Sets the end ear.
121         *
122         * @param endYear the end year
123         */
124        public void setEndYear(int endYear) {
125            setMaximum(endYear);
126        }
127    
128        /**
129         * Returns the start year.
130         *
131         * @return the start year.
132         */
133        public int getStartYear() {
134            return getMinimum();
135        }
136    
137        /**
138         * Sets the start year.
139         *
140         * @param startYear the start year
141         */
142        public void setStartYear(int startYear) {
143            setMinimum(startYear);
144        }
145    
146        /**
147         * Creates a JFrame with a JYearChooser inside and can be used for testing.
148         *
149         * @param s command line arguments
150         */
151        static public void main(String[] s) {
152            JFrame frame = new JFrame("JYearChooser");
153            frame.getContentPane().add(new JYearChooser());
154            frame.pack();
155            frame.setVisible(true);
156        }
157    }