001: /*
002: * 02/02/2002 - 20:54:54
003: *
004: * JYearChooser.java - A bean for choosing a year
005: * Copyright (C) 2002 Kai Toedter
006: * kai@toedter.com
007: * www.toedter.com
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
022: */
023:
024: package com.toedter.calendar;
025:
026: import java.util.Calendar;
027:
028: import javax.swing.JFrame;
029:
030: import com.toedter.components.JSpinField;
031:
032: /**
033: * JYearChooser is a bean for choosing a year.
034: *
035: * @version 1.1 02/04/02
036: * @author Kai Toedter
037: */
038: public class JYearChooser extends JSpinField {
039: /**
040: *
041: */
042: private static final long serialVersionUID = 3257001072915984952L;
043:
044: /**
045: * Default JCalendar constructor.
046: */
047: public JYearChooser() {
048: Calendar calendar = Calendar.getInstance();
049: dayChooser = null;
050: setMinimum(calendar.getMinimum(Calendar.YEAR));
051: setMaximum(calendar.getMaximum(Calendar.YEAR));
052: setValue(calendar.get(Calendar.YEAR));
053: }
054:
055: protected void setValue(int newValue, boolean updateTextField,
056: boolean updateScrollbar) {
057: int oldYear = year;
058: year = newValue;
059: super .setValue(newValue, updateTextField, updateScrollbar);
060: if (dayChooser != null)
061: dayChooser.setYear(newValue);
062: firePropertyChange("year", oldYear, year);
063: }
064:
065: /**
066: * Sets the year.
067: * This is a bound property.
068: *
069: * @see #getYear
070: * @param y the new year
071: */
072: public void setYear(int y) {
073: super .setValue(y);
074: }
075:
076: /**
077: * Returns the year.
078: */
079: public int getYear() {
080: return year;
081: }
082:
083: /**
084: * Convenience method set a day chooser.
085: *
086: * @param dayChooser the day chooser
087: */
088: public void setDayChooser(JDayChooser dayChooser) {
089: this .dayChooser = dayChooser;
090: }
091:
092: /**
093: * Creates a JFrame with a JYearChooser inside and can be used for testing.
094: */
095: static public void main(String[] s) {
096: JFrame frame = new JFrame("JYearChooser");
097: frame.getContentPane().add(new JYearChooser());
098: frame.pack();
099: frame.setVisible(true);
100: }
101:
102: private JDayChooser dayChooser;
103: private int year;
104: }
|