001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2002, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.gui.swing;
018:
019: // J2Se dependencies
020: import java.awt.HeadlessException;
021: import java.util.Locale;
022:
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: import org.geotools.resources.Arguments;
028: import org.geotools.util.ProgressListener;
029:
030: /**
031: * Test {@link ProgressWindow}. The window will be displayed only if this test
032: * is executed through its {@link #main main} method.
033: *
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/test/java/org/geotools/gui/swing/ProgressWindowTest.java $
035: * @version $Id: ProgressWindowTest.java 20883 2006-08-07 13:48:09Z jgarnett $
036: * @author Martin Desruisseaux
037: */
038: public class ProgressWindowTest extends TestCase {
039: /** The description, if any. */
040: private static String description;
041: /** The source, if any. */
042: private static String source;
043: /** Text to put in the margin, if any. */
044: private static String margin;
045: /** Warning to print, if any. */
046: private static String warning;
047: /** {@code true} for enabling display. */
048: private static boolean display;
049:
050: /**
051: * Construct the test case.
052: */
053: public ProgressWindowTest(final String name) {
054: super (name);
055: }
056:
057: /**
058: * Run the test case from the command line.
059: */
060: public static void main(final String[] args) throws Exception {
061: final Arguments arguments = new Arguments(args);
062: Locale.setDefault(arguments.locale);
063: description = arguments.getOptionalString("-description");
064: source = arguments.getOptionalString("-source");
065: margin = arguments.getOptionalString("-margin");
066: warning = arguments.getOptionalString("-warning");
067: display = true;
068: if (description == null)
069: description = "Some description";
070: if (source == null)
071: source = "Some source";
072: if (margin == null)
073: margin = "(1)";
074: if (warning == null)
075: warning = "Some warning";
076: junit.textui.TestRunner.run(suite());
077: }
078:
079: /**
080: * Returns the suite of tests.
081: */
082: public static Test suite() {
083: TestSuite suite = new TestSuite(ProgressWindowTest.class);
084: return suite;
085: }
086:
087: /**
088: * Test the progress listener with a progress ranging from 0 to 100%
089: */
090: public void testProgress() throws InterruptedException {
091: if (display)
092: try {
093: Thread.currentThread().setPriority(
094: Thread.NORM_PRIORITY - 2);
095: final ProgressListener progress = new ProgressWindow(
096: null);
097: progress.setDescription(description);
098: progress.started();
099: for (int i = 0; i <= 100; i++) {
100: progress.progress(i);
101: Thread.currentThread().sleep(20);
102: if ((i == 40 || i == 80) && warning != null) {
103: progress.warningOccurred(source, margin,
104: warning);
105: }
106: }
107: progress.complete();
108: } catch (HeadlessException e) {
109: // do nothing
110: }
111: }
112: }
|