001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2023
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 */
028package edu.wisc.ssec.mcidasv.data.dateChooser;
029
030import com.toedter.components.JSpinField;
031
032import java.util.Calendar;
033
034import javax.swing.JFrame;
035
036
037/**
038 * JYearChooser is a bean for choosing a year.
039 *
040 * @version $LastChangedRevision: 85 $
041 * @version $LastChangedDate: 2006-04-28 13:50:52 +0200 (Fr, 28 Apr 2006) $
042 */
043public class JYearChooser extends JSpinField {
044    private static final long serialVersionUID = 2648810220491090064L;
045    protected JDayChooser dayChooser;
046    protected int oldYear;
047    protected int startYear;
048    protected int endYear;
049
050    /**
051     * Default JCalendar constructor.
052     */
053    public JYearChooser() {
054        setName("JYearChooser");
055        Calendar calendar = Calendar.getInstance();
056        dayChooser = null;
057        setMinimum(calendar.getMinimum(Calendar.YEAR));
058        setMaximum(calendar.getMaximum(Calendar.YEAR));
059        setValue(calendar.get(Calendar.YEAR));
060    }
061
062    /**
063     * Sets the year. This is a bound property.
064     *
065     * @param y the new year
066     *
067     * @see #getYear
068     */
069    public void setYear(int y) {
070        super.setValue(y, true, false);
071
072        if (dayChooser != null) {
073            dayChooser.setYear(value);
074        }
075
076        spinner.setValue(new Integer(value));
077        firePropertyChange("year", oldYear, value);
078        oldYear = value;
079    }
080
081    /**
082     * Sets the year value.
083     *
084     * @param value the year value
085     */
086    public void setValue(int value) {
087        setYear(value);
088    }
089
090    /**
091     * Returns the year.
092     *
093     * @return the year
094     */
095    public int getYear() {
096        return super.getValue();
097    }
098
099    /**
100     * Convenience method set a day chooser that might be updated directly.
101     *
102     * @param dayChooser the day chooser
103     */
104    public void setDayChooser(JDayChooser dayChooser) {
105        this.dayChooser = dayChooser;
106    }
107
108    /**
109     * Returns the endy ear.
110     *
111     * @return the end year
112     */
113    public int getEndYear() {
114        return getMaximum();
115    }
116
117    /**
118     * Sets the end ear.
119     *
120     * @param endYear the end year
121     */
122    public void setEndYear(int endYear) {
123        setMaximum(endYear);
124    }
125
126    /**
127     * Returns the start year.
128     *
129     * @return the start year.
130     */
131    public int getStartYear() {
132        return getMinimum();
133    }
134
135    /**
136     * Sets the start year.
137     *
138     * @param startYear the start year
139     */
140    public void setStartYear(int startYear) {
141        setMinimum(startYear);
142    }
143
144    /**
145     * Creates a JFrame with a JYearChooser inside and can be used for testing.
146     *
147     * @param s command line arguments
148     */
149    static public void main(String[] s) {
150        JFrame frame = new JFrame("JYearChooser");
151        frame.getContentPane().add(new JYearChooser());
152        frame.pack();
153        frame.setVisible(true);
154    }
155}