001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2003, 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.Color;
021: import java.awt.Component;
022: import java.awt.Graphics2D;
023: import java.awt.Polygon;
024: import java.awt.Rectangle;
025: import java.awt.geom.Rectangle2D;
026: import java.awt.image.RenderedImage;
027: import java.util.Locale;
028: import javax.swing.JFrame;
029:
030: // JAI dependencies
031: import javax.media.jai.operator.AddConstDescriptor;
032: import javax.media.jai.operator.ConstantDescriptor;
033: import javax.media.jai.operator.GradientMagnitudeDescriptor;
034: import javax.media.jai.operator.MultiplyConstDescriptor;
035:
036: // JUnit dependencies
037: import junit.framework.Test;
038: import junit.framework.TestCase;
039: import junit.framework.TestSuite;
040:
041: // Geotools dependencies
042: import org.geotools.measure.AngleFormat;
043: import org.geotools.resources.Arguments;
044: import org.geotools.resources.image.ColorUtilities;
045: import org.geotools.gui.swing.referencing.CoordinateChooser;
046: import org.geotools.gui.swing.image.OperationTreeBrowser;
047: import org.geotools.gui.swing.image.GradientKernelEditor;
048: import org.geotools.gui.swing.image.KernelEditor;
049: import org.geotools.gui.swing.image.ColorRamp;
050:
051: /**
052: * Tests a set of widgets. Widgets will be displayed only if the test is run from the main
053: * method. Otherwise (i.e. if run from Maven), widgets are invisibles.
054: *
055: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/test/java/org/geotools/gui/swing/MiscellaneousWidgetTest.java $
056: * @version $Id: MiscellaneousWidgetTest.java 20883 2006-08-07 13:48:09Z jgarnett $
057: * @author Martin Desruisseaux
058: */
059: public class MiscellaneousWidgetTest extends TestBase {
060: /**
061: * Constructs the test case.
062: */
063: public MiscellaneousWidgetTest(final String name) {
064: super (name);
065: }
066:
067: /**
068: * Run the test case from the command line.
069: */
070: public static void main(final String[] args) {
071: main(args, suite());
072: }
073:
074: /**
075: * Returns the suite of tests.
076: */
077: public static Test suite() {
078: return new TestSuite(MiscellaneousWidgetTest.class);
079: }
080:
081: /**
082: * Tests the {@link About} dialog.
083: */
084: public void testAbout() {
085: show(new About());
086: }
087:
088: /**
089: * Tests the {@link DisjointLists}.
090: */
091: public void testDisjointLists() {
092: final DisjointLists test = new DisjointLists();
093: test.addElements(Locale.getAvailableLocales());
094: show(test);
095: }
096:
097: /**
098: * Tests the {@link FormatChooser}.
099: */
100: public void testFormatChooser() {
101: FormatChooser test = new FormatChooser(new AngleFormat());
102: show(test);
103: }
104:
105: /**
106: * Tests the {@link CoordinateChooser}.
107: */
108: public void testCoordinateChooser() {
109: CoordinateChooser test = new CoordinateChooser();
110: show(test);
111: }
112:
113: /**
114: * Tests the {@link KernelEditor}.
115: */
116: public void testKernelEditor() {
117: KernelEditor test = new KernelEditor();
118: test.addDefaultKernels();
119: show(test);
120: }
121:
122: /**
123: * Tests the {@link GradientKernelEditor}.
124: */
125: public void testGradientKernelEditor() {
126: GradientKernelEditor test = new GradientKernelEditor();
127: test.addDefaultKernels();
128: show(test);
129: }
130:
131: /**
132: * Tests the {@link ColorRamp}.
133: */
134: public void testColorRamp() {
135: ColorRamp test = new ColorRamp();
136: final int[] ARGB = new int[256];
137: ColorUtilities.expand(new Color[] { Color.RED, Color.ORANGE,
138: Color.YELLOW, Color.CYAN }, ARGB, 0, ARGB.length);
139: test.setColors(ColorUtilities.getIndexColorModel(ARGB));
140: show(test);
141: }
142:
143: /**
144: * Tests the {@link Plot2D}.
145: */
146: // public void testPlot2D() {
147: // final Random random = new Random();
148: // Plot2D test = new Plot2D(true, false);
149: // test.newAxis(0, "Some x values");
150: // test.newAxis(1, "Some y values");
151: // for (int j=0; j<2; j++) {
152: // final float[] x = new float[800];
153: // final float[] y = new float[800];
154: // for (int i=0; i<x.length; i++) {
155: // x[i] = i/10f;
156: // y[i] = (float)random.nextGaussian();
157: // if (i!=0) {
158: // y[i] += y[i-1];
159: // }
160: // }
161: // test.addSeries("Random values", x, y);
162: // }
163: // test.setPaintingWhileAdjusting(true);
164: // show(test.createScrollPane());
165: // }
166: /**
167: * Tests the {@link ZoomPane}.
168: */
169: public void testZoomPane() {
170: final Rectangle rect = new Rectangle(100, 200, 100, 93);
171: final Polygon poly = new Polygon(new int[] { 125, 175, 150 },
172: new int[] { 225, 225, 268 }, 3);
173: final ZoomPane pane = new ZoomPane(ZoomPane.UNIFORM_SCALE
174: | ZoomPane.TRANSLATE_X | ZoomPane.TRANSLATE_Y
175: | ZoomPane.ROTATE | ZoomPane.RESET
176: | ZoomPane.DEFAULT_ZOOM) {
177: public Rectangle2D getArea() {
178: return rect;
179: }
180:
181: protected void paintComponent(final Graphics2D graphics) {
182: graphics.transform(zoom);
183: graphics.setColor(Color.RED);
184: graphics.fill(poly);
185: graphics.setColor(Color.BLUE);
186: graphics.draw(poly);
187: graphics.draw(rect);
188: }
189: };
190: pane.setPaintingWhileAdjusting(true);
191: show(pane, "ZoomPane");
192: }
193:
194: /**
195: * Tests the {@link OperationTreeBrowser}.
196: */
197: public void testOperationTree() {
198: RenderedImage image;
199: final Float size = new Float(200);
200: final Byte value = new Byte((byte) 10);
201: image = ConstantDescriptor.create(size, size,
202: new Byte[] { value }, null);
203: image = MultiplyConstDescriptor.create(image,
204: new double[] { 2 }, null);
205: image = GradientMagnitudeDescriptor.create(image, null, null,
206: null);
207: image = AddConstDescriptor.create(image, new double[] { 35 },
208: null);
209: show(new OperationTreeBrowser(image));
210: }
211: }
|