[Schmitzm-commits] r1267 - in trunk: src/schmitzm/geotools/feature src/skrueger/geotools src/skrueger/swing src_junit/schmitzm/geotools/feature src_junit/schmitzm/swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Nov 13 02:11:12 CET 2010


Author: alfonx
Date: 2010-11-13 02:11:10 +0100 (Sat, 13 Nov 2010)
New Revision: 1267

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/skrueger/geotools/StyledFeaturesInterface.java
   trunk/src/skrueger/swing/CancellableDialogAdapter.java
   trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
   trunk/src_junit/schmitzm/swing/TestingUtil.java
Log:
Hardcore refactored and worked on the new AtlasStyler features. It will be so much more powerfull. The code will be so much cleaner. It will be so much mre work ;-)

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-11-12 19:18:35 UTC (rev 1266)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-11-13 01:11:10 UTC (rev 1267)
@@ -41,6 +41,7 @@
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -2407,7 +2408,7 @@
 				// Byte.class
 				// || c == BigInteger.class || c == BigDecimal.class
 				// || c == Float.class || c == Short.class || c == Long.class) {
-				if (validOnly && !pd.getLocalName().matches("\\w+")){
+				if (validOnly && !pd.getLocalName().matches("\\w+")) {
 					LOGGER.info("Hidden attribut " + pd.getLocalName()
 							+ " in getNumericalFieldNames");
 				} else {
@@ -2545,7 +2546,7 @@
 						.getLocalPart());
 			}
 		}
-		
+
 		// Checking for exact match, after all non ASCII characters have been
 		// transformed to � characters in both strings.
 		for (AttributeDescriptor d : attributeDescriptors) {
@@ -2555,12 +2556,16 @@
 						.getLocalPart());
 			}
 		}
-		
-		// Checking for IGNORECASE match, after all non ASCII characters have been
+
+		// Checking for IGNORECASE match, after all non ASCII characters have
+		// been
 		// transformed to � characters in both strings.
 		for (AttributeDescriptor d : attributeDescriptors) {
-			if (d.getName().getLocalPart().replaceAll("[^\\p{ASCII}]", "�")
-					.equalsIgnoreCase(localName.replaceAll("[^\\p{ASCII}]", "�"))) {
+			if (d.getName()
+					.getLocalPart()
+					.replaceAll("[^\\p{ASCII}]", "�")
+					.equalsIgnoreCase(
+							localName.replaceAll("[^\\p{ASCII}]", "�"))) {
 				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
 						.getLocalPart());
 			}
@@ -2601,15 +2606,15 @@
 			Pattern compile = Pattern.compile(s3);
 			Matcher matcher = compile.matcher(d.getLocalName());
 
-			LOGGER.debug("New Matching Debug " + " " + s2 + " " + s3
-					+ " " + localName + " " + d.getLocalName());
+			LOGGER.debug("New Matching Debug " + " " + s2 + " " + s3 + " "
+					+ localName + " " + d.getLocalName());
 
 			if (matcher.find()) {
 				Log.info("New Matching Debug " + localName + " zu "
 						+ d.getLocalName());
 
-				LOGGER.debug("New Matching Debug !!! " + localName
-						+ " zu " + d.getLocalName());
+				LOGGER.debug("New Matching Debug !!! " + localName + " zu "
+						+ d.getLocalName());
 
 				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
 						.getLocalPart());
@@ -2828,4 +2833,125 @@
 	// return gcArr;
 	// }
 
+	/**
+	 * @return A {@link List} of {@link String}s representing VALUE field, e.g.
+	 *         fields that are not of any geometry type.
+	 * 
+	 * @param featureSource
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
+	 */
+	public static Vector<String> getValueFieldNames(
+			final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource,
+			final boolean empty, boolean validOnly) {
+
+		return getValueFieldNames(featureSource.getSchema(), empty, validOnly);
+	}
+
+	/**
+	 * Returns a {@link Vector} of Attribute LocalNames, excluding any Geometry
+	 * columns
+	 */
+	public static Vector<String> getValueFieldNames(
+			final SimpleFeatureType schema) {
+		return getValueFieldNames(schema, false, true);
+	}
+
+	/**
+	 * @return A {@link List} of {@link String}s representing VALUE field, e.g.
+	 *         fields that are not of any geometry or complex type.
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
+	 */
+	public static Vector<String> getValueFieldNames(
+			final SimpleFeatureType featureType, final boolean empty,
+			boolean validOnly) {
+
+		final Vector<String> fieldNames = new Vector<String>();
+
+		final List<AttributeDescriptor> attributeDescs = featureType
+				.getAttributeDescriptors();
+
+		for (final AttributeDescriptor ad : attributeDescs) {
+
+			/** Ignore geometry columns **/
+			if (ad instanceof GeometryDescriptor)
+				continue;
+
+			/** Ignore names that do contain non ascii charaters **/
+			if (validOnly) {
+				// Only "normal" characters, digits and '_' allowed
+				if (!ad.getLocalName().matches("\\w+"))
+					continue;
+			}
+
+			fieldNames.add(ad.getLocalName());
+
+		}
+
+		if (empty)
+			fieldNames.add(0, "");
+
+		return fieldNames;
+	}
+
+	/**
+	 * Returns an list of simple attribute names, ordered by: numerical
+	 * attributes first. * @param validOnly if <code>true</code>, the list is
+	 * filtered for attribute names that do not contain any special characters
+	 */
+	public static Vector<String> getValueFieldNamesPrefereNumerical(
+			final SimpleFeatureType schema, final boolean empty,
+			boolean validOnly) {
+		final Vector<String> result = new Vector<String>();
+
+		if (empty)
+			result.add("");
+
+		final Vector<String> numericalFieldNames = FeatureUtil
+				.getNumericalFieldNames(schema, false, validOnly);
+		result.addAll(numericalFieldNames);
+		final Vector<String> valueFieldNames = getValueFieldNames(schema,
+				false, validOnly);
+		for (final String vaString : valueFieldNames) {
+			if (!result.contains(vaString)) {
+				result.add(vaString);
+			}
+		}
+
+		return result;
+	}
+
+	/**
+	 * Returns an list of simple attribute names, ordered by: text attributes
+	 * first. The list is filtered for attribute names that do not contain any
+	 * special characters.
+	 */
+	public static Vector<String> getValueFieldNamesPrefereStrings(
+			final SimpleFeatureType schema, final boolean empty) {
+		return getValueFieldNamesPrefereStrings(schema, empty, true);
+	}
+
+	/**
+	 * Returns an list of simple attribute names, ordered by: text attributes
+	 * first
+	 * 
+	 * @param validOnly
+	 *            if <code>true</code>, the list is filtered for attribute names
+	 *            that do not contain any special characters
+	 */
+	public static Vector<String> getValueFieldNamesPrefereStrings(
+			final SimpleFeatureType schema, final boolean empty,
+			boolean validOnly) {
+
+		final Vector<String> result = getValueFieldNamesPrefereNumerical(
+				schema, false, validOnly);
+		Collections.reverse(result);
+
+		if (empty)
+			result.add(0, "");
+
+		return result;
+	}
+
 }

Modified: trunk/src/skrueger/geotools/StyledFeaturesInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeaturesInterface.java	2010-11-12 19:18:35 UTC (rev 1266)
+++ trunk/src/skrueger/geotools/StyledFeaturesInterface.java	2010-11-13 01:11:10 UTC (rev 1267)
@@ -99,6 +99,10 @@
 	 */
 	public abstract SimpleFeatureType getSchema();
 
+	/**
+	 * @return can returns {@link GeometryForm#ANY} if the source is e.g. a GML
+	 *         mixed geometry collection.
+	 */
 	public abstract GeometryForm getGeometryForm();
 
 }

Modified: trunk/src/skrueger/swing/CancellableDialogAdapter.java
===================================================================
--- trunk/src/skrueger/swing/CancellableDialogAdapter.java	2010-11-12 19:18:35 UTC (rev 1266)
+++ trunk/src/skrueger/swing/CancellableDialogAdapter.java	2010-11-13 01:11:10 UTC (rev 1267)
@@ -19,23 +19,23 @@
  * the real object and restore it's state when the user cancels the
  * {@link JDialog}.
  * 
- * Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort .  
+ * Pressing ESC or clicking the "Close X" results in asking the user whether to
+ * Save/Cancel/Abort .
  */
 public abstract class CancellableDialogAdapter extends AtlasDialog implements
 		CancellableDialog {
-	
-	protected static ResourceProvider RESOURCE = ResourceProvider.newInstance(LangUtil
-			.extendPackagePath(SwingUtil.class,
+
+	protected static ResourceProvider RESOURCE = ResourceProvider.newInstance(
+			LangUtil.extendPackagePath(SwingUtil.class,
 					"resource.locales.SwingResourceBundle"), Locale.ENGLISH);
 
-
-	/** Has this dialog been canceled ?**/
+	/** Has this dialog been canceled ? **/
 	protected boolean cancelled = false;
 
 	private OkButton okButton;
-	
+
 	private CancelButton cancelButton;
-	
+
 	public CancellableDialogAdapter(Component parentWindow) {
 		super(parentWindow);
 	}
@@ -53,22 +53,26 @@
 	 * Allows to close the {@link JDialog} from "outside". The user will be
 	 * asked and she may cancel the close process.
 	 */
+	@Override
 	public boolean close() {
-		int showConfirmDialog = JOptionPane.showConfirmDialog(
-				CancellableDialogAdapter.this, 
-				RESOURCE.getString("CancellableDialogAdapter.close.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
+		int showConfirmDialog = JOptionPane
+				.showConfirmDialog(
+						CancellableDialogAdapter.this,
+						RESOURCE.getString(
+								"CancellableDialogAdapter.close.save.msg",
+								getTitle()),
+						RESOURCE.getString("CancellableDialogAdapter.close.save.title"),
+						JOptionPane.YES_NO_CANCEL_OPTION);
 
 		if (showConfirmDialog == JOptionPane.YES_OPTION) {
 			return okClose();
-		}
-		else if (showConfirmDialog == JOptionPane.NO_OPTION) {
+		} else if (showConfirmDialog == JOptionPane.NO_OPTION) {
 			cancelClose();
 			return true;
 		}
-		
+
 		return false;
 	}
-	
 
 	/**
 	 * This method can be called from "outside" to force a close of this
@@ -77,17 +81,21 @@
 	 */
 	public void forceClose() {
 
-		int res = JOptionPane.showConfirmDialog(
-				CancellableDialogAdapter.this,
-				RESOURCE.getString("CancellableDialogAdapter.forceClose.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_OPTION); 
-		
+		int res = JOptionPane
+				.showConfirmDialog(
+						CancellableDialogAdapter.this,
+						RESOURCE.getString(
+								"CancellableDialogAdapter.forceClose.save.msg",
+								getTitle()),
+						RESOURCE.getString("CancellableDialogAdapter.close.save.title"),
+						JOptionPane.YES_NO_OPTION);
+
 		if (res == JOptionPane.YES_OPTION) {
 			okClose();
 		} else {
 			cancelClose();
 		}
 	}
-	
 
 	/**
 	 * Default implementation that calls {@link #cancel()} and
@@ -107,6 +115,7 @@
 	 * This method is called when the dialog is closed and not canceled. Can be
 	 * overwritten to do anything when the dialog has been accepted. For example
 	 * checking for any {@link Checkable} components. <br/>
+	 * Call super.okClose() at the end.
 	 * 
 	 * @Return <code>false</code>, if the ok has been vetoed.
 	 */
@@ -121,7 +130,7 @@
 	protected OkButton getOkButton() {
 		if (okButton == null) {
 			okButton = new OkButton(new AbstractAction() {
-				
+
 				@Override
 				public void actionPerformed(ActionEvent e) {
 					okClose();
@@ -130,7 +139,6 @@
 		}
 		return okButton;
 	}
-	
 
 	/**
 	 * @return a default CancelButton that will call {@link #cancelClose()}
@@ -138,7 +146,7 @@
 	protected CancelButton getCancelButton() {
 		if (cancelButton == null) {
 			cancelButton = new CancelButton(new AbstractAction() {
-				
+
 				@Override
 				public void actionPerformed(ActionEvent e) {
 					cancelClose();

Modified: trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java	2010-11-12 19:18:35 UTC (rev 1266)
+++ trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java	2010-11-13 01:11:10 UTC (rev 1267)
@@ -26,7 +26,6 @@
 
 import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
 import schmitzm.geotools.io.GeoImportUtil;
-import schmitzm.swing.TestingUtil;
 import schmitzm.swing.TestingUtil.TestDatasetsVector;
 
 import com.vividsolutions.jts.geom.Geometry;
@@ -92,8 +91,8 @@
 	@Test
 	public void testModifyFeatureSource() throws Exception {
 
-		FeatureSource<SimpleFeatureType, SimpleFeature> sourceFs = TestingUtil
-				.getTestFeatureSource(TestDatasetsVector.arabicInHeader);
+		FeatureSource<SimpleFeatureType, SimpleFeature> sourceFs = TestDatasetsVector.arabicInHeader
+				.getFeatureSource();
 		assertEquals(4, sourceFs.getSchema().getAttributeCount());
 		assertEquals("the_geom", sourceFs.getSchema().getDescriptor(0)
 				.getLocalName());

Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-11-12 19:18:35 UTC (rev 1266)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-11-13 01:11:10 UTC (rev 1267)
@@ -28,10 +28,7 @@
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 
-import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
 import org.geotools.coverage.grid.GridCoverage2D;
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
 import org.geotools.data.DataStore;



More information about the Schmitzm-commits mailing list