[Schmitzm-commits] r1094 - in trunk: src/schmitzm/swing src_junit/schmitzm/geotools/styling src_junit/schmitzm/jfree/feature/style src_junit/schmitzm/lang src_junit/schmitzm/swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Oct 10 21:47:28 CEST 2010
Author: alfonx
Date: 2010-10-10 21:47:27 +0200 (Sun, 10 Oct 2010)
New Revision: 1094
Added:
trunk/src_junit/schmitzm/swing/TestingUtil.java
Removed:
trunk/src/schmitzm/swing/TestingUtil.java
trunk/src_junit/schmitzm/geotools/styling/TestingUtil2.java
Modified:
trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
trunk/src_junit/schmitzm/lang/ResourceProviderTest.java
Log:
merged TestingUtil and TestingUtil2 (into src_junit), since maven can now deal with -test.jar dependencies.
Deleted: trunk/src/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src/schmitzm/swing/TestingUtil.java 2010-10-10 17:27:19 UTC (rev 1093)
+++ trunk/src/schmitzm/swing/TestingUtil.java 2010-10-10 19:47:27 UTC (rev 1094)
@@ -1,242 +0,0 @@
-package schmitzm.swing;
-
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Dialog.ModalExclusionType;
-import java.awt.Graphics2D;
-import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.Rectangle;
-import java.awt.Window;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.swing.ImageIcon;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-import org.geotools.data.DataUtilities;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.geotools.map.DefaultMapContext;
-import org.geotools.map.DefaultMapLayer;
-import org.geotools.renderer.lite.StreamingRenderer;
-
-import schmitzm.io.IOUtil;
-import schmitzm.lang.LangUtil;
-
-/**
- * Helpers to test Swing applications
- *
- * @author stefan tzeggai
- */
-public class TestingUtil {
-
- public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
-
- /**
- * Opens a {@link JFrame} and shows the passed {@link JComponent}. If a
- * {@link ExceptionDialog} is opens in the GUI, an exception is thrown.<br/>
- * The test is skipped if the JVM is running headless.
- *
- * @param gui
- * @param title
- * can be used to explain the tests what to check
- * @param waitMax
- * Maximum seconds to wait until the GUI should automatically
- * close, set -1 for unlimieted
- */
- public static void testGui(Component gui, String title, int waitMax)
- throws Throwable {
-
- if (GraphicsEnvironment.isHeadless())
- return;
-
- final AtomicBoolean stopFlag = new AtomicBoolean(false);
-
- final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
-
- ExceptionDialog.addListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- err.set((Throwable) e.getSource());
- stopFlag.set(true);
- }
- });
-
- Window w = null;
- if (gui instanceof Window) {
- w = (Window) gui;
- } else if (gui instanceof JComponent) {
- JFrame f = new JFrame(title);
- f.setContentPane((JComponent) gui);
- f.pack();
- w = f;
- }
-
- // If it is a modal dialog, unmodalize it
- w.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
- w.setVisible(true);
- int countWait = 0;
- while (w.isVisible() && !stopFlag.get()) {
- LangUtil.sleepExceptionless(100);
- if (waitMax > 0 && countWait++ > waitMax * 10)
- break;
- }
- w.dispose();
-
- if (stopFlag.get()) {
- throw err.get();
- }
-
- }
-
- public static void testGui(Component gui, int waitMax) throws Throwable {
- testGui(gui, gui.getClass().getSimpleName(), waitMax);
- }
-
- public static void testGui(Image image, int waitMax) throws Throwable {
-
- if (GraphicsEnvironment.isHeadless())
- return;
-
- JLabel imgLabel = new JLabel(new ImageIcon(image));
- testGui(imgLabel, imgLabel.getClass().getSimpleName(), waitMax);
- }
-
- /**
- * Checks whether an image has a specific color/transparency at a special
- * pixel position.
- */
- public static boolean checkPixel(BufferedImage bi, int x, int y,
- Float... colorParts) {
-
- Color expectedColor = new Color(colorParts[0], colorParts[1],
- colorParts[2], colorParts[3]);
-
- return checkPixel(bi, x, y, expectedColor);
-
- }
-
- private static boolean checkPixel(BufferedImage bi, int x, int y,
- Color expected) {
- final int rgb = bi.getRGB(x, y);
-
- final Color found = new Color(rgb, true);
-
- final boolean equals = expected.equals(found);
-
- if (!equals) {
- System.err.println("At pixel (" + x + "/" + y + ") expected "
- + expected + " but found " + found);
- }
-
- return equals;
- }
-
- public static boolean checkPixel(BufferedImage bi, int x, int y,
- int... colorParts) {
-
- Color expectedColor;
-
- if (colorParts.length == 4) {
- expectedColor = new Color(colorParts[0], colorParts[1],
- colorParts[2], colorParts[3]);
- } else {
- expectedColor = new Color(colorParts[0], colorParts[1],
- colorParts[2]);
- }
-
- return checkPixel(bi, x, y, expectedColor);
- }
-
- public static void testGui(JPanel jPanel, String title) throws Throwable {
- testGui(jPanel, title, 3);
- }
-
- public static void testGui(Component gui) throws Throwable {
- testGui(gui, 3);
- }
-
- public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
- DefaultMapContext mc = new DefaultMapContext(dml.getFeatureSource()
- .getSchema().getCoordinateReferenceSystem());
-
- mc.addLayer(dml);
-
- StreamingRenderer sr = new StreamingRenderer();
- sr.setContext(mc);
-
- final BufferedImage bi = new BufferedImage(100, 100,
- BufferedImage.TYPE_4BYTE_ABGR);
- Graphics2D g2d = bi.createGraphics();
- ReferencedEnvelope geoArea = new ReferencedEnvelope(dml
- .getFeatureSource().getBounds());
- sr.paint(g2d, new Rectangle(100, 100), geoArea);
- g2d.dispose();
-
- TestingUtil.testGui(bi, 1);
-
- return bi;
- }
-
- /**
- * Takes a URL to a shapefile, that may be inside a jar. The retuned UTL
- * points to a version of the shapefile copied to the tmp dir.
- *
- * @throws IOException
- * @throws URISyntaxException
- */
- public static URL copyShapefileToTemp(URL urlToShape) throws IOException,
- URISyntaxException {
- File tempDir = new File(IOUtil.getTempDir(), "shape"
- + (System.currentTimeMillis()));
- tempDir.mkdir();
-
- /**
- * SHP file!
- */
- final URL shpURL = IOUtil.changeUrlExt(urlToShape, "shp");
- String fileName = shpURL.getPath();
- if (shpURL.getPath().lastIndexOf("/") > 0)
- fileName = shpURL.getPath().substring(
- shpURL.getPath().lastIndexOf("/"));
-
- IOUtil.copyUrl(shpURL, tempDir, false);
-
- final URL shxURL = IOUtil.changeUrlExt(urlToShape, "shx");
- IOUtil.copyUrl(shxURL, tempDir, false);
-
- final URL grxURL = IOUtil.changeUrlExt(urlToShape, "grx");
- IOUtil.copyURLNoException(grxURL, tempDir, false);
-
- final URL fixURL = IOUtil.changeUrlExt(urlToShape, "fix");
- IOUtil.copyURLNoException(fixURL, tempDir, false);
-
- final URL qixURL = IOUtil.changeUrlExt(urlToShape, "qix");
- IOUtil.copyURLNoException(qixURL, tempDir, false);
-
- final URL xmlURL = IOUtil.changeUrlExt(urlToShape, "shp.xml");
- IOUtil.copyURLNoException(xmlURL, tempDir, false);
-
- final URL dbfURL = IOUtil.changeUrlExt(urlToShape, "dbf");
- IOUtil.copyUrl(dbfURL, tempDir, false);
-
- /**
- * Optionally copy a .cpg file that describes the
- */
- final URL cpgURL = IOUtil.changeUrlExt(urlToShape, "cpg");
- IOUtil.copyURLNoException(cpgURL, tempDir, false);
-
- return DataUtilities.fileToURL(new File(tempDir, fileName));
- }
-}
Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-10-10 17:27:19 UTC (rev 1093)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java 2010-10-10 19:47:27 UTC (rev 1094)
@@ -54,7 +54,7 @@
@Test
public void testSelectionStyles() throws Throwable {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
.getTestFeatures();
JPanel jPanel = new JPanel();
Deleted: trunk/src_junit/schmitzm/geotools/styling/TestingUtil2.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/TestingUtil2.java 2010-10-10 17:27:19 UTC (rev 1093)
+++ trunk/src_junit/schmitzm/geotools/styling/TestingUtil2.java 2010-10-10 19:47:27 UTC (rev 1094)
@@ -1,41 +0,0 @@
-package schmitzm.geotools.styling;
-
-import java.io.IOException;
-import java.net.URL;
-
-import org.geotools.feature.FeatureCollection;
-import org.junit.Ignore;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-
-import schmitzm.geotools.io.GeoImportUtil;
-import schmitzm.jfree.feature.style.FeatureChartStyle;
-
- at Ignore
-public class TestingUtil2 {
-
- final static String resLocation = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
-
- /**
- * Stellt Test-Features zur Verfügung, WENN die Anwendung im maven scope
- * <code>test</code> läuft.
- */
- public static FeatureCollection<SimpleFeatureType, SimpleFeature> getTestFeatures()
- throws IOException {
- // Testdatenshape einlesen
- URL resourceUrl = FeatureChartStyle.class.getResource(resLocation);
-
- if (resourceUrl == null)
- throw new IllegalStateException(resLocation
- + " wurde nicht gefunden!");
-
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil
- .readFeaturesFromShapeURL(resourceUrl);
-
- if (testFeatures == null)
- throw new IllegalStateException(
- "Testfeatures konnten nicht gelesen werden");
-
- return testFeatures;
- }
-}
Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-10-10 17:27:19 UTC (rev 1093)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-10-10 19:47:27 UTC (rev 1094)
@@ -38,7 +38,6 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
-import schmitzm.geotools.styling.TestingUtil2;
import schmitzm.io.IOUtil;
import schmitzm.jfree.chart.style.BasicChartStyle;
import schmitzm.jfree.chart.style.ChartAxisStyle;
@@ -50,6 +49,7 @@
import schmitzm.jfree.chart.style.ChartType;
import schmitzm.jfree.table.AggregationFunction;
import schmitzm.swing.SwingUtil;
+import schmitzm.swing.TestingUtil;
public class FeatureChartStyleTest {
private static Logger log = Logger.getLogger(FeatureChartStyleTest.class);
@@ -61,7 +61,7 @@
public void testChartStyleCopyToWithScatterChartStyle() throws IOException, CQLException,
InterruptedException {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2.getTestFeatures();
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.getTestFeatures();
FeatureChartStyle style1 = new FeatureScatterChartStyle("1");
style1.setAttributeName(0, "jahr");
style1.setAttributeName(1, "w_bev");
@@ -69,14 +69,12 @@
assertNotNull("applyToFeatureCollection lieferte null!", chart);
assertXMLOutputAndInput(xmlFactoryFeature, style1, "testCopyTo_01");
-
FeatureChartStyle style2 = new FeatureScatterChartStyle(style1.getID());
style1.copyTo( style2 );
assertXMLOutputAndInput(xmlFactoryFeature, style2, "testCopyTo_02");
assertXMLEqual(xmlFactoryFeature, style1, style2, "testCopyTo_Eq");
-
if (INTERACTIVE) {
ChartFrame chartFrame = new ChartFrame(
"Sechs Linien (3x2), Zwei Achsen", chart);
@@ -92,7 +90,7 @@
public void testChartStyleCopyToWithBasicChartStyle() throws IOException, CQLException,
InterruptedException {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2.getTestFeatures();
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.getTestFeatures();
FeatureChartStyle style1 = new FeatureBasicChartStyle("1", ChartType.BAR);
style1.setAttributeName(0, "jahr");
style1.setAttributeName(1, "w_bev");
@@ -124,7 +122,7 @@
public void testLineChartDualAxis() throws IOException, CQLException,
InterruptedException {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
.getTestFeatures();
// Daten auf korrektheit überprüfen
@@ -358,7 +356,7 @@
String yAxisAttName2 = "w_bev";
String groupAttName = "jahr";
- FeatureCollection<SimpleFeatureType, SimpleFeature> features = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> features = TestingUtil
.getTestFeatures();
log.info("BarChart für " + features.size() + " Features wird erstellt");
@@ -446,7 +444,7 @@
public void testBarChartDualAxis() throws IOException, CQLException,
InterruptedException {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
.getTestFeatures();
// Daten auf korrektheit überprüfen
@@ -555,7 +553,7 @@
public void testBarChartSortedSeries() throws IOException,
InterruptedException {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
.getTestFeatures();
// Daten auf korrektheit überprüfen
@@ -668,7 +666,7 @@
InterruptedException {
// Testdatenshape einlesen
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
.getTestFeatures();
// Daten auf korrektheit überprüfen
@@ -746,7 +744,7 @@
public void testLineChartAsCategories() throws IOException, CQLException,
InterruptedException {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
.getTestFeatures();
// Daten auf korrektheit überprüfen
@@ -873,7 +871,7 @@
public void testLineChartNOTCategories() throws IOException, CQLException,
InterruptedException {
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
.getTestFeatures();
// Daten auf korrektheit überprüfen
Modified: trunk/src_junit/schmitzm/lang/ResourceProviderTest.java
===================================================================
--- trunk/src_junit/schmitzm/lang/ResourceProviderTest.java 2010-10-10 17:27:19 UTC (rev 1093)
+++ trunk/src_junit/schmitzm/lang/ResourceProviderTest.java 2010-10-10 19:47:27 UTC (rev 1094)
@@ -7,7 +7,6 @@
import java.util.Locale;
import java.util.Set;
-import org.junit.Ignore;
import org.junit.Test;
public class ResourceProviderTest {
Copied: trunk/src_junit/schmitzm/swing/TestingUtil.java (from rev 1093, trunk/src/schmitzm/swing/TestingUtil.java)
===================================================================
--- trunk/src/schmitzm/swing/TestingUtil.java 2010-10-10 17:27:19 UTC (rev 1093)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-10-10 19:47:27 UTC (rev 1094)
@@ -0,0 +1,273 @@
+package schmitzm.swing;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dialog.ModalExclusionType;
+import java.awt.Graphics2D;
+import java.awt.GraphicsEnvironment;
+import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.geotools.data.DataUtilities;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.map.DefaultMapContext;
+import org.geotools.map.DefaultMapLayer;
+import org.geotools.renderer.lite.StreamingRenderer;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+import schmitzm.geotools.io.GeoImportUtil;
+import schmitzm.io.IOUtil;
+import schmitzm.jfree.feature.style.FeatureChartStyle;
+import schmitzm.lang.LangUtil;
+
+/**
+ * Helpers to test Swing applications
+ *
+ * @author stefan tzeggai
+ */
+public class TestingUtil {
+
+ public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
+
+ /**
+ * Opens a {@link JFrame} and shows the passed {@link JComponent}. If a
+ * {@link ExceptionDialog} is opens in the GUI, an exception is thrown.<br/>
+ * The test is skipped if the JVM is running headless.
+ *
+ * @param gui
+ * @param title
+ * can be used to explain the tests what to check
+ * @param waitMax
+ * Maximum seconds to wait until the GUI should automatically
+ * close, set -1 for unlimieted
+ */
+ public static void testGui(Component gui, String title, int waitMax)
+ throws Throwable {
+
+ if (GraphicsEnvironment.isHeadless())
+ return;
+
+ final AtomicBoolean stopFlag = new AtomicBoolean(false);
+
+ final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
+
+ ExceptionDialog.addListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ err.set((Throwable) e.getSource());
+ stopFlag.set(true);
+ }
+ });
+
+ Window w = null;
+ if (gui instanceof Window) {
+ w = (Window) gui;
+ } else if (gui instanceof JComponent) {
+ JFrame f = new JFrame(title);
+ f.setContentPane((JComponent) gui);
+ f.pack();
+ w = f;
+ }
+
+ // If it is a modal dialog, unmodalize it
+ w.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
+ w.setVisible(true);
+ int countWait = 0;
+ while (w.isVisible() && !stopFlag.get()) {
+ LangUtil.sleepExceptionless(100);
+ if (waitMax > 0 && countWait++ > waitMax * 10)
+ break;
+ }
+ w.dispose();
+
+ if (stopFlag.get()) {
+ throw err.get();
+ }
+
+ }
+
+ public static void testGui(Component gui, int waitMax) throws Throwable {
+ testGui(gui, gui.getClass().getSimpleName(), waitMax);
+ }
+
+ public static void testGui(Image image, int waitMax) throws Throwable {
+
+ if (GraphicsEnvironment.isHeadless())
+ return;
+
+ JLabel imgLabel = new JLabel(new ImageIcon(image));
+ testGui(imgLabel, imgLabel.getClass().getSimpleName(), waitMax);
+ }
+
+ /**
+ * Checks whether an image has a specific color/transparency at a special
+ * pixel position.
+ */
+ public static boolean checkPixel(BufferedImage bi, int x, int y,
+ Float... colorParts) {
+
+ Color expectedColor = new Color(colorParts[0], colorParts[1],
+ colorParts[2], colorParts[3]);
+
+ return checkPixel(bi, x, y, expectedColor);
+
+ }
+
+ private static boolean checkPixel(BufferedImage bi, int x, int y,
+ Color expected) {
+ final int rgb = bi.getRGB(x, y);
+
+ final Color found = new Color(rgb, true);
+
+ final boolean equals = expected.equals(found);
+
+ if (!equals) {
+ System.err.println("At pixel (" + x + "/" + y + ") expected "
+ + expected + " but found " + found);
+ }
+
+ return equals;
+ }
+
+ public static boolean checkPixel(BufferedImage bi, int x, int y,
+ int... colorParts) {
+
+ Color expectedColor;
+
+ if (colorParts.length == 4) {
+ expectedColor = new Color(colorParts[0], colorParts[1],
+ colorParts[2], colorParts[3]);
+ } else {
+ expectedColor = new Color(colorParts[0], colorParts[1],
+ colorParts[2]);
+ }
+
+ return checkPixel(bi, x, y, expectedColor);
+ }
+
+ public static void testGui(JPanel jPanel, String title) throws Throwable {
+ testGui(jPanel, title, 3);
+ }
+
+ public static void testGui(Component gui) throws Throwable {
+ testGui(gui, 3);
+ }
+
+ public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
+ DefaultMapContext mc = new DefaultMapContext(dml.getFeatureSource()
+ .getSchema().getCoordinateReferenceSystem());
+
+ mc.addLayer(dml);
+
+ StreamingRenderer sr = new StreamingRenderer();
+ sr.setContext(mc);
+
+ final BufferedImage bi = new BufferedImage(100, 100,
+ BufferedImage.TYPE_4BYTE_ABGR);
+ Graphics2D g2d = bi.createGraphics();
+ ReferencedEnvelope geoArea = new ReferencedEnvelope(dml
+ .getFeatureSource().getBounds());
+ sr.paint(g2d, new Rectangle(100, 100), geoArea);
+ g2d.dispose();
+
+ TestingUtil.testGui(bi, 1);
+
+ return bi;
+ }
+
+ /**
+ * Takes a URL to a shapefile, that may be inside a jar. The retuned UTL
+ * points to a version of the shapefile copied to the tmp dir.
+ *
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public static URL copyShapefileToTemp(URL urlToShape) throws IOException,
+ URISyntaxException {
+ File tempDir = new File(IOUtil.getTempDir(), "shape"
+ + (System.currentTimeMillis()));
+ tempDir.mkdir();
+
+ /**
+ * SHP file!
+ */
+ final URL shpURL = IOUtil.changeUrlExt(urlToShape, "shp");
+ String fileName = shpURL.getPath();
+ if (shpURL.getPath().lastIndexOf("/") > 0)
+ fileName = shpURL.getPath().substring(
+ shpURL.getPath().lastIndexOf("/"));
+
+ IOUtil.copyUrl(shpURL, tempDir, false);
+
+ final URL shxURL = IOUtil.changeUrlExt(urlToShape, "shx");
+ IOUtil.copyUrl(shxURL, tempDir, false);
+
+ final URL grxURL = IOUtil.changeUrlExt(urlToShape, "grx");
+ IOUtil.copyURLNoException(grxURL, tempDir, false);
+
+ final URL fixURL = IOUtil.changeUrlExt(urlToShape, "fix");
+ IOUtil.copyURLNoException(fixURL, tempDir, false);
+
+ final URL qixURL = IOUtil.changeUrlExt(urlToShape, "qix");
+ IOUtil.copyURLNoException(qixURL, tempDir, false);
+
+ final URL xmlURL = IOUtil.changeUrlExt(urlToShape, "shp.xml");
+ IOUtil.copyURLNoException(xmlURL, tempDir, false);
+
+ final URL dbfURL = IOUtil.changeUrlExt(urlToShape, "dbf");
+ IOUtil.copyUrl(dbfURL, tempDir, false);
+
+ /**
+ * Optionally copy a .cpg file that describes the
+ */
+ final URL cpgURL = IOUtil.changeUrlExt(urlToShape, "cpg");
+ IOUtil.copyURLNoException(cpgURL, tempDir, false);
+
+ return DataUtilities.fileToURL(new File(tempDir, fileName));
+ }
+
+
+ final static String resLocation = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
+
+ /**
+ * Stellt Test-Features zur Verfügung, WENN die Anwendung im maven scope
+ * <code>test</code> läuft.
+ */
+ public static FeatureCollection<SimpleFeatureType, SimpleFeature> getTestFeatures()
+ throws IOException {
+ // Testdatenshape einlesen
+ URL resourceUrl = FeatureChartStyle.class.getResource(resLocation);
+
+ if (resourceUrl == null)
+ throw new IllegalStateException(resLocation
+ + " wurde nicht gefunden!");
+
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil
+ .readFeaturesFromShapeURL(resourceUrl);
+
+ if (testFeatures == null)
+ throw new IllegalStateException(
+ "Testfeatures konnten nicht gelesen werden");
+
+ return testFeatures;
+ }
+}
Property changes on: trunk/src_junit/schmitzm/swing/TestingUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
More information about the Schmitzm-commits
mailing list