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: DateChooserDialog.java,v $
023   Revision 1.11  2004/05/31 07:43:52  markl
024   javadoc updates
025
026   Revision 1.10  2004/05/12 18:12:45  markl
027   added setCellSize() method
028
029   Revision 1.9  2004/03/16 06:43:39  markl
030   LocaleManager method change
031
032   Revision 1.8  2003/01/19 09:38:51  markl
033   Added new constructors that take a parent dialog.
034
035   Revision 1.7  2001/03/20 00:54:54  markl
036   Fixed deprecated calls.
037
038   Revision 1.6  2001/03/12 05:19:57  markl
039   Source code cleanup.
040
041   Revision 1.5  1999/08/03 04:49:29  markl
042   Added some methods to complete the API.
043
044   Revision 1.4  1999/07/26 11:06:16  markl
045   API fix.
046
047   Revision 1.3  1999/04/19 06:05:14  markl
048   I18N changes, new constructor.
049
050   Revision 1.2  1999/02/28 11:46:23  markl
051   Minor fixes.
052   ----------------------------------------------------------------------------
053*/
054
055package kiwi.ui.dialog;
056
057import java.awt.*;
058import java.awt.event.*;
059import java.util.*;
060import javax.swing.*;
061
062import kiwi.ui.*;
063import kiwi.util.*;
064
065/** A dialog window that displays a <code>DateChooser</code>.
066  *
067  * <p><center>
068  * <img src="snapshot/DateChooserDialog.gif"><br>
069  * <i>An example DateChooserDialog.</i>
070  * </center>
071  *
072  * @see kiwi.ui.DateChooser
073  *
074  * @author Mark Lindner
075  */
076
077public class DateChooserDialog extends ComponentDialog
078  {
079  private DateChooser cal;
080  private Calendar v_date = null;
081
082  /** Construct a new <code>DateChooserDialog</code> with a default title.
083    *
084    * @param parent The parent window for the dialog.
085    * @param modal A flag specifying whether this dialog will be modal.
086    */
087
088  public DateChooserDialog(Frame parent, boolean modal)
089    {
090    this(parent, "", modal);
091    }
092
093  /** Construct a new <code>DateChooserDialog</code> with a default title.
094    *
095    * @param parent The parent window for the dialog.
096    * @param modal A flag specifying whether this dialog will be modal.
097    *
098    * @since Kiwi 1.4
099    */
100
101  public DateChooserDialog(Dialog parent, boolean modal)
102    {
103    this(parent, "", modal);
104    }
105  
106  /** Construct a new <code>DateChooserDialog</code>.
107    *
108    * @param parent The parent window for the dialog.
109    * @param title The title for the dialog.
110    * @param modal A flag specifying whether this dialog will be modal.
111    */
112
113  public DateChooserDialog(Frame parent, String title, boolean modal)
114    {
115    super(parent, title, modal);
116    setResizable(false);
117    }
118
119  /** Construct a new <code>DateChooserDialog</code>.
120    *
121    * @param parent The parent window for the dialog.
122    * @param title The title for the dialog.
123    * @param modal A flag specifying whether this dialog will be modal.
124    *
125    * @since Kiwi 1.4
126    */
127
128  public DateChooserDialog(Dialog parent, String title, boolean modal)
129    {
130    super(parent, title, modal);
131    setResizable(false);
132    }
133  
134  /** Build the dialog user interface. */
135
136  protected Component buildDialogUI()
137    {
138    LocaleData loc = LocaleManager.getDefault().getLocaleData("KiwiDialogs");
139    
140    setComment(loc.getMessage("kiwi.dialog.prompt.date_select"));
141    if(getTitle().length() == 0)
142      setTitle(loc.getMessage("kiwi.dialog.title.date_select"));
143
144    return(cal = new DateChooser());
145    }
146
147  /** Show or hide the dialog. */
148
149  public void setVisible(boolean flag)
150    {
151    if(flag)
152      v_date = null;
153    super.setVisible(flag);
154    }
155
156  /** Accept the input. Always returns <code>true</code>. */
157
158  protected boolean accept()
159    {
160    v_date = cal.getSelectedDate();
161    return(true);
162    }
163
164  /** Get the selected date.
165    *
166    * @return The date selected, as a <code>Calendar</code> object, or
167    * <code>null</code> if the dialog was cancelled.
168    */
169
170  public Calendar getDate()
171    {
172    return(v_date);
173    }
174
175  /** Set the selected date.
176   *
177   * @param date The new date.
178   */
179  
180  public void setDate(Calendar date)
181    {
182    cal.setSelectedDate(date);
183    }
184
185  /** Get the latest selectable date for the chooser.
186   *
187   * @return  The maximum selectable date, or <code>null</code> if there is no
188   * maximum date currently set.
189   */
190  
191  public Calendar getMaximumDate()
192    {
193    return(cal.getMaximumDate());
194    }
195  
196  /** Set the latest selectable date for the chooser.
197   *
198   * @param date The (possibly <code>null</code>) maximum selectable date.
199   */
200   
201  public void setMaximumDate(Calendar date)
202    {
203    cal.setMaximumDate(date);
204    }
205
206  /** Get the earliest selectable date for the chooser.
207   *
208   * @return  The minimum selectable date, or <code>null</code> if there is no
209   * minimum date currently set.
210   */
211  
212  public Calendar getMinimumDate()
213    {
214    return(cal.getMinimumDate());
215    }
216  
217  /** Set the earliest selectable date for the chooser.
218   *
219   * @param date The (possibly <code>null</code>) minimum selectable date.
220   */
221  
222  public void setMinimumDate(Calendar date)
223    {
224    cal.setMinimumDate(date);
225    }
226
227  /** Set the size of date cells in the calendar pane.
228   *
229   * @param size The width and height, in pixels, of a cell.
230   *
231   * @since Kiwi 2.0
232   */
233
234  public void setCellSize(int size)
235    {
236    cal.setCellSize(size);
237    pack();
238    }
239  
240  }
241
242/* end of source file */