My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
* Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.user.datepicker.client;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
import com.google.gwt.user.datepicker.client.DefaultCalendarView.CellGrid.DateCell;

import java.util.Date;

/**
* Simple calendar view. Not extensible as we wish to evolve it freely over
* time.
*/

@SuppressWarnings(/* Date manipulation required */{"deprecation"})
public final class DefaultCalendarView extends CalendarView {

/**
* Cell grid.
*/
// Javac bug requires that date be fully specified here.
class CellGrid extends CellGridImpl<java.util.Date> {
/**
* A cell representing a date.
*/
class DateCell extends Cell {
private String cellStyle;
private String dateStyle;

DateCell(Element td, boolean isWeekend) {
super(td, new Date());
cellStyle = css().day();
if (isWeekend) {
cellStyle += " " + css().dayIsWeekend();
}
}

@Override
public void addStyleName(String styleName) {
if (dateStyle.indexOf(" " + styleName + " ") == -1) {
dateStyle += styleName + " ";
}
updateStyle();
}

public boolean isFiller() {
return !getModel().isInCurrentMonth(getValue());
}

@Override
public void onHighlighted(boolean highlighted) {
setHighlightedDate(getValue());
updateStyle();
}

@Override
public void onSelected(boolean selected) {
if (selected) {
getDatePicker().setValue(getValue(), true);
if (isFiller()) {
getDatePicker().setCurrentMonth(getValue());
}
}
updateStyle();
}

@Override
public void removeStyleName(String styleName) {
dateStyle = dateStyle.replace(" " + styleName + " ", " ");
updateStyle();
}

public void update(Date current) {
setEnabled(true);
getValue().setTime(current.getTime());
String value = getModel().formatDayOfMonth(getValue());
setText(value);
dateStyle = cellStyle;
if (isFiller()) {
dateStyle += " " + css().dayIsFiller();
} else {
String extraStyle = getDatePicker().getStyleOfDate(current);
if (extraStyle != null) {
dateStyle += " " + extraStyle;
}
}
// We want to certify that all date styles have " " before and after
// them for ease of adding to and replacing them.
dateStyle += " ";
updateStyle();
}

@Override
public void updateStyle() {
String accum = dateStyle;

if (isHighlighted()) {
accum += " " + css().dayIsHighlighted();

if (isHighlighted() && isSelected()) {
accum += " " + css().dayIsValueAndHighlighted();
}
}
if (!isEnabled()) {
accum += " " + css().dayIsDisabled();
}
setStyleName(accum);
}

private void setText(String value) {
DOM.setInnerText(getElement(), value);
}
}

CellGrid() {
resize(CalendarModel.WEEKS_IN_MONTH + 1, CalendarModel.DAYS_IN_WEEK);
}

@Override
protected void onSelected(Cell lastSelected, Cell cell) {
}
}

private CellGrid grid = new CellGrid();

private Date firstDisplayed;

private Date lastDisplayed = new Date();

/**
* Constructor.
*/
public DefaultCalendarView() {
}

@Override
public void addStyleToDate(String styleName, Date date) {
assert getDatePicker().isDateVisible(date) : "You tried to add style " + styleName + " to "
+ date + ". The calendar is currently showing " + getFirstDate()
+ " to " + getLastDate();
getCell(date).addStyleName(styleName);
}

@Override
public Date getFirstDate() {
return firstDisplayed;
}

@Override
public Date getLastDate() {
return lastDisplayed;
}

@Override
public boolean isDateEnabled(Date d) {
return getCell(d).isEnabled();
}

@Override
public void refresh() {
firstDisplayed = getModel().getCurrentFirstDayOfFirstWeek();

if (firstDisplayed.getDate() == 1) {
// show one empty week if date is Monday is the first in month.
CalendarUtil.addDaysToDate(firstDisplayed, -7);
}

lastDisplayed.setTime(firstDisplayed.getTime());

for (int i = 0; i < grid.getNumCells(); i++) {
if (i != 0) {
CalendarUtil.addDaysToDate(lastDisplayed, 1);
}
DateCell cell = (DateCell) grid.getCell(i);
cell.update(lastDisplayed);
}
}

@Override
public void removeStyleFromDate(String styleName, Date date) {
getCell(date).removeStyleName(styleName);
}

@Override
public void setEnabledOnDate(boolean enabled, Date date) {
getCell(date).setEnabled(enabled);
}

@Override
public void setup() {
// Preparation
CellFormatter formatter = grid.getCellFormatter();
int weekendStartColumn = -1;
int weekendEndColumn = -1;

// Set up the day labels.
for (int i = 0; i < CalendarModel.DAYS_IN_WEEK; i++) {
int shift = CalendarUtil.getStartingDayOfWeek();
int dayIdx = i + shift < CalendarModel.DAYS_IN_WEEK ? i + shift : i
+ shift - CalendarModel.DAYS_IN_WEEK;
grid.setText(0, i, getModel().formatDayOfWeek(dayIdx));

if (CalendarUtil.isWeekend(dayIdx)) {
formatter.setStyleName(0, i, css().weekendLabel());
if (weekendStartColumn == -1) {
weekendStartColumn = i;
} else {
weekendEndColumn = i;
}
} else {
formatter.setStyleName(0, i, css().weekdayLabel());
}
}

// Set up the calendar grid.
for (int row = 1; row <= CalendarModel.WEEKS_IN_MONTH; row++) {
for (int column = 0; column < CalendarModel.DAYS_IN_WEEK; column++) {
// set up formatter.
Element e = formatter.getElement(row, column);
grid.new DateCell(e, column == weekendStartColumn
|| column == weekendEndColumn);
}
}
initWidget(grid);
grid.setStyleName(css().days());
}

private DateCell getCell(Date d) {
int index = CalendarUtil.getDaysBetween(firstDisplayed, d);
assert (index >= 0);

DateCell cell = (DateCell) grid.getCell(index);
if (cell.getValue().getDate() != d.getDate()) {
throw new IllegalStateException(d + " cannot be associated with cell "
+ cell + " as it has date " + cell.getValue());
}
return cell;
}
}

Change log

r6510 by sco...@google.com on Oct 28, 2009   Diff
Fixing svn props on many java files where
this was missing.

Go to: 
Project members, sign in to write a code review

Older revisions

r4367 by j...@google.com on Dec 23, 2008   Diff
Merge from releases/1.6:r4198:4268,426
9:4297,4299:4320:4321:4366 into trunk

svn merge -r4198:4269 https://google-
web-toolkit.googlecode.com/svn/release
...
r4264 by e...@google.com on Dec 8, 2008   Diff
Merging in date picker branch into
1.6.
r4245 by rj...@google.com on Dec 3, 2008   Diff
Renames some methods to reduce the
confusion between global and not
global styles.  Also fixes various
varargs methods, which weren't
really working.
...
All revisions of this file

File info

Size: 7152 bytes, 254 lines

File properties

svn:mime-type
text/x-java
svn:eol-style
native
Powered by Google Project Hosting