001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: import java.util.Date;
031:
032: import thinwire.ui.event.ActionEvent;
033:
034: /**
035: * A <code>DateBox</code> is a <code>Component</code> that displays a
036: * month-view calendar. The user can click the arrows in the header to change
037: * the currently displayed month. Clicking on a day, selects that day and fires
038: * a <code>PROPERTY_SELECTED_DATE</code> property change event.
039: * <p>
040: * <b>Example:</b> <br>
041: * <img src="doc-files/DateBox-1.png"> <br>
042: *
043: * <pre>
044: * final Dialog dlg = new Dialog("DateBox Test");
045: * dlg.setBounds(10, 10, 320, 240);
046: * DateBox db = new DateBox();
047: * db.setBounds(10, 10, dlg.getInnerWidth() - 20, dlg.getInnerHeight() - 20);
048: * dlg.getChildren().add(db);
049: * dlg.setVisible(true);
050: * </pre>
051: *
052: * </p>
053: * <p>
054: * <b>Keyboard Navigation:</b><br>
055: * <table border="1">
056: * <tr>
057: * <td>KEY</td>
058: * <td>RESPONSE</td>
059: * <td>NOTE</td>
060: * </tr>
061: * </table>
062: * </p>
063: * @author Ted C. Howard
064: */
065: public class DateBox extends AbstractComponent {
066: public static final String PROPERTY_SELECTED_DATE = "selectedDate";
067:
068: private Date selectedDate;
069:
070: public DateBox() {
071: this (new Date());
072: }
073:
074: /**
075: * Creates a new <code>DateBox</code> with the specified <code>selectedDate</code>.
076: * @param selectedDate the <code>Date</code> to be initially selected in the component
077: */
078: public DateBox(Date selectedDate) {
079: setSelectedDate(selectedDate);
080: }
081:
082: /**
083: * Returns the currently selected date.
084: * @return a <code>Date</code> object representing the currently selected date
085: */
086: public Date getSelectedDate() {
087: return selectedDate;
088: }
089:
090: /**
091: * Sets the selected date in the component.
092: * @param selectedDate the new <code>Date</code> to be selected in the component
093: */
094: public void setSelectedDate(Date selectedDate) {
095: Date oldDate = this .selectedDate;
096: this .selectedDate = selectedDate;
097: firePropertyChange(this , PROPERTY_SELECTED_DATE, oldDate,
098: this .selectedDate);
099: }
100:
101: public void fireAction(ActionEvent ev) {
102: if (ev == null)
103: throw new IllegalArgumentException("ev == null");
104: if (!(ev.getSource() instanceof Date))
105: throw new IllegalArgumentException(
106: "!(ev.getSource() instanceof Date)");
107: setSelectedDate((Date) ev.getSource());
108: super.fireAction(ev);
109: }
110: }
|