PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/ui/panels/calendar/ScheduleYearChooser.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 149 lines | 56 code | 17 blank | 76 comment | 2 complexity | 5631915e27d23209a2a61e5f3f4b190b MD5 | raw file
  1/*
  2 *  JYearChooser.java  - A bean for choosing a year
  3 *  Copyright (C) 2004 Kai Toedter
  4 *  kai@toedter.com
  5 *  www.toedter.com
  6 *
  7 *  This program is free software; you can redistribute it and/or
  8 *  modify it under the terms of the GNU General Public License
  9 *  as published by the Free Software Foundation; either version 2
 10 *  of the License, or (at your option) any later version.
 11 *
 12 *  This program is distributed in the hope that it will be useful,
 13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 *  GNU General Public License for more details.
 16 *
 17 *  You should have received a copy of the GNU General Public License
 18 *  along with this program; if not, write to the Free Software
 19 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 20 */
 21package mpv5.ui.panels.calendar;
 22
 23import com.toedter.components.JSpinField;
 24
 25import java.util.Calendar;
 26
 27import javax.swing.JFrame;
 28
 29
 30/**
 31 * JYearChooser is a bean for choosing a year.
 32 *
 33 * @version $LastChangedRevision: 85 $
 34 * @version $LastChangedDate: 2006-04-28 13:50:52 +0200 (Fr, 28 Apr 2006) $
 35 */
 36public class ScheduleYearChooser extends JSpinField {
 37    private static final long serialVersionUID = 2648810220491090064L;
 38    protected ScheduleCalendarDayChooser dayChooser;
 39    protected int oldYear;
 40    protected int startYear;
 41    protected int endYear;
 42
 43    /**
 44     * Default JCalendar constructor.
 45     */
 46    public ScheduleYearChooser() {
 47        setName("JYearChooser");
 48        Calendar calendar = Calendar.getInstance();
 49        dayChooser = null;
 50        setMinimum(calendar.getMinimum(Calendar.YEAR));
 51        setMaximum(calendar.getMaximum(Calendar.YEAR));
 52        setValue(calendar.get(Calendar.YEAR));
 53    }
 54
 55    /**
 56     * Sets the year. This is a bound property.
 57     *
 58     * @param y the new year
 59     *
 60     * @see #getYear
 61     */
 62    public void setYear(int y) {
 63        super.setValue(y, true, false);
 64
 65        if (dayChooser != null) {
 66            dayChooser.setYear(value);
 67        }
 68
 69        spinner.setValue(new Integer(value));
 70        firePropertyChange("year", oldYear, value);
 71        oldYear = value;
 72    }
 73
 74    /**
 75     * Sets the year value.
 76     *
 77     * @param value the year value
 78     */
 79    @Override
 80    public final void setValue(int value) {
 81        setYear(value);
 82    }
 83
 84    /**
 85     * Returns the year.
 86     *
 87     * @return the year
 88     */
 89    public int getYear() {
 90        return super.getValue();
 91    }
 92
 93    /**
 94     * Convenience method set a day chooser that might be updated directly.
 95     *
 96     * @param dayChooser the day chooser
 97     */
 98    public void setDayChooser(ScheduleCalendarDayChooser dayChooser) {
 99        this.dayChooser = dayChooser;
100    }
101
102    /**
103     * Returns the endy ear.
104     *
105     * @return the end year
106     */
107    public int getEndYear() {
108        return getMaximum();
109    }
110
111    /**
112     * Sets the end ear.
113     *
114     * @param endYear the end year
115     */
116    public void setEndYear(int endYear) {
117        setMaximum(endYear);
118    }
119
120    /**
121     * Returns the start year.
122     *
123     * @return the start year.
124     */
125    public int getStartYear() {
126        return getMinimum();
127    }
128
129    /**
130     * Sets the start year.
131     *
132     * @param startYear the start year
133     */
134    public void setStartYear(int startYear) {
135        setMinimum(startYear);
136    }
137
138    /**
139     * Creates a JFrame with a JYearChooser inside and can be used for testing.
140     *
141     * @param s command line arguments
142     */
143    static public void main(String[] s) {
144        JFrame frame = new JFrame("JYearChooser");
145        frame.getContentPane().add(new ScheduleYearChooser());
146        frame.pack();
147        frame.setVisible(true);
148    }
149}