001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: DateRangeHelper.java,v $
023   Revision 1.5  2004/05/12 19:01:47  markl
024   comment block updates
025
026   Revision 1.4  2003/01/19 09:50:53  markl
027   Javadoc & comment header updates.
028
029   Revision 1.3  2001/03/12 09:27:54  markl
030   Source code and Javadoc cleanup.
031
032   Revision 1.2  1999/07/26 08:51:50  markl
033   Javadoc.
034
035   Revision 1.1  1999/07/26 08:11:27  markl
036   Initial revision
037   ----------------------------------------------------------------------------
038*/
039
040package kiwi.ui;
041
042import java.awt.*;
043import java.awt.event.*;
044import java.util.*;
045
046/** A helper class for coordinating two <code>DateChooser</code>s for the
047 * purpose of entering a date range. <code>DateRangeHelper</code> constrains
048 * two <code>DateChooser</code>s in such a way that only a valid date range
049 * may be selected using the two choosers. To this end, an end date must be
050 * entered that is on or after the start date. The date range selection can
051 * be further constrained by specifing a minimum and maximum date; in this
052 * case input is limited so that the selected date range will fall within
053 * the constrained range.
054 *
055 * <p><center>
056 * <img src="snapshot/DateRangeHelper.gif"><br>
057 * <i>DateRangeHelper in action.</i>
058 * </center>
059 * 
060 * @author Mark Lindner
061 */
062
063public class DateRangeHelper implements ActionListener
064  {
065  private DateChooser startChooser, endChooser;
066
067  /** Construct a new <code>DateRangeHelper</code> for the specified start and
068   * end date choosers.
069   *
070   * @param startChooser The <code>DateChooser</code> for selecting a start
071   * date.
072   * @param endChooser The <code>DateChooser</code> for selecting an end
073   * date.
074   */
075  
076  public DateRangeHelper(DateChooser startChooser, DateChooser endChooser)
077    {
078    this.startChooser = startChooser;
079    this.endChooser = endChooser;
080
081    startChooser.addActionListener(this);
082    endChooser.addActionListener(this);
083    }
084
085  /** Set the minimum selectable date for this date range.
086   *
087   * @param date The minimum date.
088   */
089  
090  public void setMinimumDate(Calendar date)
091    {
092    startChooser.setMinimumDate(date);
093    endChooser.setMinimumDate(date);
094    }
095
096  /** Set the maximum selectable date for this date range.
097   *
098   * @param date The maximum date.
099   */
100
101  public void setMaximumDate(Calendar date)
102    {
103    startChooser.setMaximumDate(date);
104    endChooser.setMaximumDate(date);
105    }
106
107  /** Get the currently selected start date.
108   *
109   * @return The start date.
110   */
111  
112  public Calendar getStartDate()
113    {
114    return(startChooser.getSelectedDate());
115    }
116
117  /** Get the currently selected end date.
118   *
119   * @return The end date.
120   */
121  
122  public Calendar getEndDate()
123    {
124    return(endChooser.getSelectedDate());
125    }
126
127  /** Set the start date.
128   *
129   * @param date The new end date.
130   */
131  
132  public void setStartDate(Calendar date)
133    {
134    startChooser.setSelectedDate(date);
135    }
136
137  /** Set the end date.
138   *
139   * @param date The new end date.
140   */
141  
142  public void setEndDate(Calendar date)
143    {
144    endChooser.setSelectedDate(date);
145    }
146
147  /** Handle events. This method is public as an implementation side-effect. */
148  
149  public void actionPerformed(ActionEvent evt)
150    {
151    Object o = evt.getSource();
152
153    if(o == startChooser)
154      endChooser.setMinimumDate(startChooser.getSelectedDate());
155
156    else if(o == endChooser)
157      startChooser.setMaximumDate(endChooser.getSelectedDate());
158    }   
159
160  }
161
162/* end of source file */