View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: DateModel.java,v 1.4 2002/09/05 15:41:47 ludovicc Exp $ 37 */ 38 package samples.swing.combobox; 39 40 import java.util.*; 41 import org.scopemvc.core.ModelChangeEvent; 42 import org.scopemvc.core.Selector; 43 import org.scopemvc.model.basic.BasicModel; 44 45 /*** 46 * @author <A HREF="mailto:daniel.michalik@autel.cz">Daniel Michalik</A> 47 * @created 05 September 2002 48 * @version $Revision: 1.4 $ $Date: 2002/09/05 15:41:47 $ 49 */ 50 public class DateModel extends BasicModel { 51 52 /*** 53 * TODO: describe of the Field 54 */ 55 public final static Selector CURRENT_YEAR = Selector.fromString("currentYear"); 56 /*** 57 * TODO: describe of the Field 58 */ 59 public final static Selector CURRENT_MONTH = Selector.fromString("currentMonth"); 60 /*** 61 * TODO: describe of the Field 62 */ 63 public final static Selector CURRENT_DAY = Selector.fromString("currentDay"); 64 /*** 65 * TODO: describe of the Field 66 */ 67 public final static Selector DAYS = Selector.fromString("days"); 68 /*** 69 * TODO: describe of the Field 70 */ 71 public final static Selector YEARS = Selector.fromString("years"); 72 73 private Calendar currentDate = GregorianCalendar.getInstance(); 74 private Object[] years; 75 private Object[] months; 76 private Object[] days; 77 78 79 /*** 80 * Constructor for the DateModel object 81 */ 82 public DateModel() { 83 months = new Object[12]; 84 for (int i = 0; i < 12; i++) { 85 months[i] = new Integer(i + 1); 86 } 87 updateModels(); 88 } 89 90 91 /*** 92 * Returns interval of +-2 years from now. 93 * 94 * @return The years value 95 */ 96 public Object[] getYears() { 97 return years; 98 } 99 100 101 /*** 102 * Gets the months 103 * 104 * @return The months value 105 */ 106 public Object[] getMonths() { 107 return months; 108 } 109 110 111 /*** 112 * Gets the days 113 * 114 * @return The days value 115 */ 116 public Object[] getDays() { 117 return days; 118 } 119 120 121 /*** 122 * Gets the current year 123 * 124 * @return The currentYear value 125 */ 126 public int getCurrentYear() { 127 return currentDate.get(Calendar.YEAR); 128 } 129 130 131 /*** 132 * Gets the current month 133 * 134 * @return The currentMonth value 135 */ 136 public int getCurrentMonth() { 137 return currentDate.get(Calendar.MONTH) + 1; 138 } 139 140 141 /*** 142 * Gets the current day 143 * 144 * @return The currentDay value 145 */ 146 public int getCurrentDay() { 147 return currentDate.get(Calendar.DATE); 148 } 149 150 151 /*** 152 * Sets the current year 153 * 154 * @param n The new currentYear value 155 */ 156 public void setCurrentYear(int n) { 157 currentDate.set(Calendar.YEAR, n); 158 fireModelChange(ModelChangeEvent.VALUE_CHANGED, CURRENT_YEAR); 159 updateModels(); 160 } 161 162 163 /*** 164 * Sets the current month 165 * 166 * @param n The new currentMonth value 167 */ 168 public void setCurrentMonth(int n) { 169 currentDate.set(Calendar.MONTH, n - 1); 170 fireModelChange(ModelChangeEvent.VALUE_CHANGED, CURRENT_MONTH); 171 updateModels(); 172 } 173 174 175 /*** 176 * Sets the current day 177 * 178 * @param n The new currentDay value 179 */ 180 public void setCurrentDay(int n) { 181 currentDate.set(Calendar.DATE, n); 182 fireModelChange(ModelChangeEvent.VALUE_CHANGED, CURRENT_DAY); 183 updateModels(); 184 } 185 186 187 /*** 188 * Builds lists of choices for years and days based on current date 189 */ 190 private void updateModels() { 191 years = new Object[5]; 192 int n = getCurrentYear() - 2; 193 for (int i = 0; i < 5; i++) { 194 years[i] = new Integer(n + i); 195 } 196 n = currentDate.getActualMaximum(Calendar.DATE); 197 days = new Object[n]; 198 for (int i = 0; i < n; i++) { 199 days[i] = new Integer(i + 1); 200 } 201 fireModelChange(ModelChangeEvent.VALUE_CHANGED, YEARS); 202 fireModelChange(ModelChangeEvent.VALUE_CHANGED, DAYS); 203 } 204 }

This page was automatically generated by Maven