2
* $Id: BasicMonthViewUIIssues.java 3396 2009-07-20 12:20:34Z kleopatra $
4
* Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
5
* Santa Clara, California 95054, U.S.A. All rights reserved.
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
package org.jdesktop.swingx.plaf.basic;
24
import java.awt.ComponentOrientation;
25
import java.awt.GraphicsEnvironment;
26
import java.util.Calendar;
27
import java.util.TimeZone;
28
import java.util.logging.Logger;
30
import org.jdesktop.swingx.InteractiveTestCase;
31
import org.jdesktop.swingx.JXFrame;
32
import org.jdesktop.swingx.JXMonthView;
33
import org.jdesktop.swingx.calendar.CalendarUtils;
36
* Tests to expose known issues of BasicMonthViewUI.
38
* @author Jeanette Winzenburg
40
public class BasicMonthViewUIIssues extends InteractiveTestCase {
41
@SuppressWarnings("all")
42
private static final Logger LOG = Logger
43
.getLogger(BasicMonthViewUIIssues.class.getName());
45
public static void main(String[] args) {
47
BasicMonthViewUIIssues test = new BasicMonthViewUIIssues();
49
test.runInteractiveTests();
50
// test.runInteractiveTests(".*Simple.*");
51
} catch (Exception e) {
52
System.err.println("exception when executing interactive tests:");
58
* Issue #786-swingx: IllegalStateException when paintDays of April 2008.
60
* Set the default timezone and get the default calendar.
63
public void testTimeZoneCairoCalendarUtils() {
64
TimeZone cairo = TimeZone.getTimeZone("Africa/Cairo");
65
Calendar calendar = Calendar.getInstance(cairo);
66
assertEquals(cairo, calendar.getTimeZone());
67
calendar.set(2008, Calendar.MARCH, 31);
68
CalendarUtils.startOfMonth(calendar);
69
calendar.add(Calendar.MONTH, 1);
70
assertTrue(CalendarUtils.isStartOfMonth(calendar));
71
CalendarUtils.startOfWeek(calendar);
72
// simulate the painting loop
73
for (int week = 0; week < 6; week++) {
74
for (int day = 0; day < 7; day++) {
75
calendar.add(Calendar.DAY_OF_MONTH, 1);
76
assertTrue("must be start of day " + calendar.getTime(),
77
CalendarUtils.isStartOfDay(calendar));
79
assertTrue("must be start of week " + calendar.getTime(),
80
CalendarUtils.isStartOfWeek(calendar));
85
* Test getDayBounds(Date) for leading dates are null. The assumption is
86
* wrong for a leading date in the second month - it's contained in the
89
public void testDayBoundsLeadingDatesNull() {
90
// This test will not work in a headless configuration.
91
if (GraphicsEnvironment.isHeadless()) {
92
LOG.fine("cannot run test - headless environment");
95
BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.LEFT_TO_RIGHT);
96
// the ui's calendar is configured to the first displayed day
97
Calendar calendar = ui.getCalendar();
98
calendar.add(Calendar.MONTH, 1);
99
int month = calendar.get(Calendar.MONTH);
100
CalendarUtils.startOfWeek(calendar);
101
assertFalse("sanity - we have leading dates in the month", month == calendar.get(Calendar.MONTH));
102
assertEquals("leading dates must return null bounds", null,
103
ui.getDayBounds(calendar.getTime()));
108
* Returns the ui of a realized JXMonthView with 2 columns and the
109
* given componentOrientation without showingWeekNumbers.
111
* NOTE: this must not be used in a headless environment.
116
private BasicMonthViewUI getRealizedMonthViewUI(ComponentOrientation co) {
117
return getRealizedMonthViewUI(co, false);
121
* Returns the ui of a realized JXMonthView with
122
* given componentOrientation and showingWeekNumbers flag.
123
* It's prefColumns/Rows are set to 2. The first displayedDate is
124
* 20. Feb. 2008 (to have fixed leading/trailing dates)
126
* The frame is packed and it's size extended by 40, 40 to
127
* give a slight off-position (!= 0) of the months shown.
131
* NOTE: this must not be used in a headless environment.
133
* @param co the componentOrientation to use
136
private BasicMonthViewUI getRealizedMonthViewUI(ComponentOrientation co,
137
boolean isShowingWeekNumbers) {
138
JXMonthView monthView = new JXMonthView();
139
monthView.setPreferredColumnCount(2);
140
monthView.setPreferredRowCount(2);
141
monthView.setComponentOrientation(co);
142
monthView.setShowingWeekNumber(isShowingWeekNumbers);
143
Calendar calendar = monthView.getCalendar();
144
calendar.set(2008, Calendar.FEBRUARY, 20);
145
monthView.setFirstDisplayedDay(calendar.getTime());
146
JXFrame frame = new JXFrame();
147
frame.add(monthView);
149
frame.setSize(frame.getWidth() + 40, frame.getHeight() + 40);
150
frame.setVisible(true);
151
BasicMonthViewUI ui = (BasicMonthViewUI) monthView.getUI();
157
* Do nothing - just to keep the test runner from complaining
158
* if there are no issues.
161
public void testDummy() {