~ubuntu-branches/ubuntu/trusty/libswingx-java/trusty

« back to all changes in this revision

Viewing changes to src/test/org/jdesktop/swingx/plaf/basic/BasicMonthViewUIIssues.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-06 00:28:45 UTC
  • mfrom: (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110306002845-escned3cbqp5qx0t
Tags: 1:1.6.2-1
* New upstream release.
* Switch to maven as build system:
  - d/control: drop ant, add maven-debian-helper
  - d/rules: use maven.mk
* d/patches/pom.diff: drop, uneeded since upstream fixed its dependencies.
* d/watch: update to use java.net directly.
* d/rules: force debian version for JARs (Closes: #603495).
* d/copyright: Update to lastest DEP-5 r166.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: BasicMonthViewUIIssues.java 3396 2009-07-20 12:20:34Z kleopatra $
3
 
 *
4
 
 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
5
 
 * Santa Clara, California 95054, U.S.A. All rights reserved.
6
 
 *
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.
11
 
 * 
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.
16
 
 * 
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
20
 
 *
21
 
 */
22
 
package org.jdesktop.swingx.plaf.basic;
23
 
 
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;
29
 
 
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;
34
 
 
35
 
/**
36
 
 * Tests to expose known issues of BasicMonthViewUI.
37
 
 * 
38
 
 * @author Jeanette Winzenburg
39
 
 */
40
 
public class BasicMonthViewUIIssues extends InteractiveTestCase {
41
 
    @SuppressWarnings("all")
42
 
    private static final Logger LOG = Logger
43
 
            .getLogger(BasicMonthViewUIIssues.class.getName());
44
 
 
45
 
    public static void main(String[] args) {
46
 
//      setSystemLF(true);
47
 
      BasicMonthViewUIIssues  test = new BasicMonthViewUIIssues();
48
 
      try {
49
 
          test.runInteractiveTests();
50
 
//        test.runInteractiveTests(".*Simple.*");
51
 
      } catch (Exception e) {
52
 
          System.err.println("exception when executing interactive tests:");
53
 
          e.printStackTrace();
54
 
      }
55
 
  }
56
 
 
57
 
    /**
58
 
     * Issue #786-swingx: IllegalStateException when paintDays of April 2008.
59
 
     * 
60
 
     * Set the default timezone and get the default calendar.
61
 
     * 
62
 
     */
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));
78
 
            }
79
 
            assertTrue("must be start of week " + calendar.getTime(),
80
 
                    CalendarUtils.isStartOfWeek(calendar));
81
 
        }
82
 
    }
83
 
    
84
 
    /**
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
87
 
     * first!
88
 
     */
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");
93
 
            return;
94
 
        }
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()));
104
 
    }
105
 
 
106
 
 
107
 
    /**
108
 
     * Returns the ui of a realized JXMonthView with 2 columns and the 
109
 
     * given componentOrientation without showingWeekNumbers.
110
 
     * 
111
 
     * NOTE: this must not be used in a headless environment.
112
 
     * 
113
 
     * @param co
114
 
     * @return
115
 
     */
116
 
    private BasicMonthViewUI getRealizedMonthViewUI(ComponentOrientation co) {
117
 
        return getRealizedMonthViewUI(co, false);
118
 
    }
119
 
 
120
 
    /**
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)
125
 
     * 
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. 
128
 
     * 
129
 
     * 
130
 
     * 
131
 
     * NOTE: this must not be used in a headless environment.
132
 
     * 
133
 
     * @param co the componentOrientation to use
134
 
     * @return
135
 
     */
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);
148
 
        frame.pack();
149
 
        frame.setSize(frame.getWidth() + 40, frame.getHeight() + 40);
150
 
        frame.setVisible(true);
151
 
        BasicMonthViewUI ui = (BasicMonthViewUI) monthView.getUI();
152
 
        return ui;
153
 
    }
154
 
 
155
 
    
156
 
    /**
157
 
     * Do nothing - just to keep the test runner from complaining 
158
 
     * if there are no issues.
159
 
     *
160
 
     */
161
 
    public void testDummy() {
162
 
        
163
 
    }
164
 
}