|
From: <de...@us...> - 2012-10-05 22:45:21
|
Revision: 7723
http://fudaa.svn.sourceforge.net/fudaa/?rev=7723&view=rev
Author: deniger
Date: 2012-10-05 22:45:14 +0000 (Fri, 05 Oct 2012)
Log Message:
-----------
support fichier externe
Modified Paths:
--------------
trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigSaverHelper.java
trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigurationInfoHelper.java
trunk/soft/fudaa-crue/ui-common/src/test/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformerTest.java
trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerControllerSaverHelper.java
trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerImageControllerSaver.java
Removed Paths:
-------------
trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformer.java
Modified: trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigSaverHelper.java
===================================================================
--- trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigSaverHelper.java 2012-10-05 22:41:30 UTC (rev 7722)
+++ trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigSaverHelper.java 2012-10-05 22:45:14 UTC (rev 7723)
@@ -5,7 +5,8 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.fudaa.fudaa.crue.common.helper.PropertyToStringTransformer;
+import org.fudaa.ctulu.converter.AbstractPropertyToStringTransformer;
+import org.fudaa.ctulu.converter.ToStringTransformerFactory;
import org.openide.nodes.Node;
import org.openide.nodes.Node.Property;
import org.openide.nodes.Sheet;
@@ -61,12 +62,12 @@
public static LinkedHashMap<String, String> transform(LinkedHashMap<String, Property> in) {
LinkedHashMap<String, String> res = new LinkedHashMap<String, String>();
- Map<Class, PropertyToStringTransformer> createTransformers = PropertyToStringTransformer.createTransformers();
+ Map<Class, AbstractPropertyToStringTransformer> createTransformers = ToStringTransformerFactory.createTransformers();
for (Map.Entry<String, Property> entry : in.entrySet()) {
String string = entry.getKey();
Property property = entry.getValue();
final Class valueType = property.getValueType();
- PropertyToStringTransformer transformer = createTransformers.get(valueType);
+ AbstractPropertyToStringTransformer transformer = createTransformers.get(valueType);
if (transformer == null) {
Logger.getLogger(ConfigSaverHelper.class.getName()).log(Level.SEVERE, "no transformer for {0}", valueType);
}
Modified: trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigurationInfoHelper.java
===================================================================
--- trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigurationInfoHelper.java 2012-10-05 22:41:30 UTC (rev 7722)
+++ trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/config/ConfigurationInfoHelper.java 2012-10-05 22:45:14 UTC (rev 7723)
@@ -6,7 +6,8 @@
import org.fudaa.ctulu.CtuluLog;
import org.fudaa.ctulu.CtuluLogLevel;
import org.fudaa.dodico.crue.common.BusinessMessages;
-import org.fudaa.fudaa.crue.common.helper.PropertyToStringTransformer;
+import org.fudaa.ctulu.converter.AbstractPropertyToStringTransformer;
+import org.fudaa.ctulu.converter.ToStringTransformerFactory;
import org.fudaa.fudaa.crue.common.property.PropertyCrueUtils;
import org.openide.nodes.Node.Property;
import org.openide.nodes.PropertySupport;
@@ -48,7 +49,7 @@
public static CtuluLog setAndValidReadProperties(Map<String, String> properties, LinkedHashMap<String, Property> initProperties, CtuluLogLevel level) {
CtuluLog log = new CtuluLog(BusinessMessages.RESOURCE_BUNDLE);
log.setDesc("configEtu.load");
- Map<Class, PropertyToStringTransformer> createTransformers = PropertyToStringTransformer.createTransformers();
+ Map<Class, AbstractPropertyToStringTransformer> createTransformers = ToStringTransformerFactory.createTransformers();
for (Map.Entry<String, String> readProperties : properties.entrySet()) {
String key = readProperties.getKey();
String value = readProperties.getValue();
@@ -56,7 +57,7 @@
if (property == null) {
log.addRecord(level, "configEtu.unknownProperty.Error", key);
} else {
- PropertyToStringTransformer transformer = createTransformers.get(property.getValueType());
+ AbstractPropertyToStringTransformer transformer = createTransformers.get(property.getValueType());
if (transformer == null) {
log.addRecord(level, "configEtu.unknownType.Error", property.getValueType());
} else if (!transformer.isValid(value)) {
Deleted: trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformer.java
===================================================================
--- trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformer.java 2012-10-05 22:41:30 UTC (rev 7722)
+++ trunk/soft/fudaa-crue/ui-common/src/main/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformer.java 2012-10-05 22:45:14 UTC (rev 7723)
@@ -1,325 +0,0 @@
-package org.fudaa.fudaa.crue.common.helper;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.geom.Point2D;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.commons.lang.StringUtils;
-import org.openide.util.Exceptions;
-
-/**
- *
- * @author deniger ( genesis)
- */
-public abstract class PropertyToStringTransformer<T> {
-
- public String toString(T in) {
- if (in == null) {
- return "null";
- }
- return toStringSafe(in);
- }
-
- public static PropertyToStringTransformer<Point2D.Double[]> getPoint2dArrayTransformer() {
- return createTransformers().get(Point2D.Double[].class);
-
- }
-
- public static Map<Class, PropertyToStringTransformer> createTransformers() {
- Map<Class, PropertyToStringTransformer> res = new HashMap<Class, PropertyToStringTransformer>();
- res.put(String.class, new StringTransformer());
- res.put(Color.class, new ColorTransformer());
- res.put(Font.class, new FontTransformer());
- DoubleTransformer doubleTransformer = new DoubleTransformer();
- res.put(Double.TYPE, doubleTransformer);
- res.put(Double.class, doubleTransformer);
- FloatTransformer floatTransformer = new FloatTransformer();
- res.put(Float.TYPE, floatTransformer);
- res.put(Float.class, floatTransformer);
- IntegerTransformer integerTransformer = new IntegerTransformer();
- res.put(Integer.TYPE, integerTransformer);
- res.put(Integer.class, integerTransformer);
- BooleanTransformer booleanTransformer = new BooleanTransformer();
- res.put(Boolean.TYPE, booleanTransformer);
- res.put(Boolean.class, booleanTransformer);
-
- res.put(Point2D.Double.class, new Point2DDoubleTransformer());
- res.put(Point2D.Double[].class, new Point2DDoubleArrayTransformer());
- return res;
- }
-
- public abstract String toStringSafe(T in);
-
- public abstract boolean isValidSafe(String in);
-
- public boolean isValid(String in) {
- if (in == null) {
- return false;
- }
- return isValidSafe(in);
- }
-
- public T fromString(String in) {
- if (in == null || "null".equals(in)) {
- return null;
- }
- return fromStringSafe(in);
- }
-
- public abstract T fromStringSafe(String in);
-
- public static class IntegerTransformer extends PropertyToStringTransformer<Integer> {
-
- @Override
- public Integer fromStringSafe(String in) {
- try {
- return Integer.parseInt(in);
- } catch (NumberFormatException numberFormatException) {
- Exceptions.printStackTrace(numberFormatException);
- }
- return null;
- }
-
- @Override
- public boolean isValidSafe(String in) {
- try {
- Integer.parseInt(in);
- return true;
- } catch (NumberFormatException numberFormatException) {
- }
- return false;
- }
-
- @Override
- public String toStringSafe(Integer in) {
- return in.toString();
- }
- }
-
- public static class BooleanTransformer extends PropertyToStringTransformer<Boolean> {
-
- @Override
- public Boolean fromStringSafe(String in) {
- try {
- return Boolean.valueOf(in);
- } catch (NumberFormatException numberFormatException) {
- Exceptions.printStackTrace(numberFormatException);
- }
- return null;
- }
-
- @Override
- public boolean isValidSafe(String in) {
- return "false".equals(in) || "true".equals(in);
- }
-
- @Override
- public String toStringSafe(Boolean in) {
- return in.toString();
- }
- }
-
- public static class Point2DDoubleTransformer extends PropertyToStringTransformer<Point2D.Double> {
-
- @Override
- public Point2D.Double fromStringSafe(String in) {
- String[] split = StringUtils.split(in, ' ');
- if (split != null && split.length == 2) {
- try {
- double x = Double.parseDouble(split[0]);
- double y = Double.parseDouble(split[1]);
- return new Point2D.Double(x, y);
- } catch (NumberFormatException numberFormatException) {
- Exceptions.printStackTrace(numberFormatException);
- }
-
- }
- return null;
- }
-
- @Override
- public boolean isValidSafe(String in) {
- return fromString(in) != null;
- }
-
- @Override
- public String toStringSafe(Point2D.Double in) {
- return in.getX() + " " + in.getY();
- }
- }
-
- public static class Point2DDoubleArrayTransformer extends PropertyToStringTransformer<Point2D.Double[]> {
-
- @Override
- public Point2D.Double[] fromStringSafe(String in) {
- Point2DDoubleTransformer elemTransformer = new Point2DDoubleTransformer();
- String[] splitArray = StringUtils.split(in, ';');
- Point2D.Double[] res = new Point2D.Double[splitArray.length];
- int idx = 0;
- for (String item : splitArray) {
- Point2D.Double fromString = elemTransformer.fromString(item);
- if (fromString == null) {
- return null;
- }
- res[idx++] = fromString;
- }
- return res;
- }
-
- @Override
- public boolean isValidSafe(String in) {
- return fromString(in) != null;
- }
-
- @Override
- public String toStringSafe(Point2D.Double[] in) {
- Point2DDoubleTransformer elemTransformer = new Point2DDoubleTransformer();
- StringBuilder builder = new StringBuilder();
- boolean first = true;
- for (Point2D.Double doubleValue : in) {
- if (!first) {
- builder.append(';');
- }
- first = false;
- builder.append(elemTransformer.toString(doubleValue));
-
- }
- return builder.toString();
- }
- }
-
- public static class DoubleTransformer extends PropertyToStringTransformer<Double> {
-
- @Override
- public Double fromStringSafe(String in) {
- try {
- return Double.parseDouble(in);
- } catch (NumberFormatException numberFormatException) {
- Exceptions.printStackTrace(numberFormatException);
- }
- return null;
- }
-
- @Override
- public boolean isValidSafe(String in) {
- try {
- Double.parseDouble(in);
- return true;
- } catch (NumberFormatException numberFormatException) {
- }
- return false;
- }
-
- @Override
- public String toStringSafe(Double in) {
- return in.toString();
- }
- }
-
- public static class FloatTransformer extends PropertyToStringTransformer<Float> {
-
- @Override
- public Float fromStringSafe(String in) {
- try {
- return Float.parseFloat(in);
- } catch (NumberFormatException numberFormatException) {
- Exceptions.printStackTrace(numberFormatException);
- }
- return null;
- }
-
- @Override
- public boolean isValidSafe(String in) {
- try {
- Float.parseFloat(in);
- return true;
- } catch (NumberFormatException numberFormatException) {
- }
- return false;
- }
-
- @Override
- public String toStringSafe(Float in) {
- return in.toString();
- }
- }
-
- public static class ColorTransformer extends PropertyToStringTransformer<Color> {
-
- @Override
- public Color fromStringSafe(String in) {
- String[] split = StringUtils.split(in, ',');
- if (split.length != 3) {
- return null;
- }
- try {
- int r = Integer.parseInt(split[0]);
- int g = Integer.parseInt(split[1]);
- int b = Integer.parseInt(split[2]);
- return new Color(r, g, b);
- } catch (Exception exception) {
- Exceptions.printStackTrace(exception);
- }
- return null;
- }
-
- @Override
- public String toStringSafe(Color in) {
- return in.getRed() + "," + in.getGreen() + "," + in.getBlue();
- }
-
- @Override
- public boolean isValidSafe(String in) {
- return fromString(in) != null;
- }
- }
-
- public static class FontTransformer extends PropertyToStringTransformer<Font> {
-
- @Override
- public Font fromStringSafe(String in) {
- String[] split = StringUtils.split(in, ',');
- if (split.length != 3) {
- return null;
- }
- try {
- String family = split[0];
- int type = Integer.parseInt(split[1]);
- int size = Integer.parseInt(split[2]);
- return new Font(family, type, size);
- } catch (Exception exception) {
- Exceptions.printStackTrace(exception);
- }
- return null;
- }
-
- @Override
- public String toStringSafe(Font in) {
- return in.getFamily() + "," + in.getStyle() + "," + in.getSize();
- }
-
- @Override
- public boolean isValidSafe(String in) {
- return fromString(in) != null;
- }
- }
-
- public static class StringTransformer extends PropertyToStringTransformer<String> {
-
- @Override
- public String fromStringSafe(String in) {
- return in;
- }
-
- @Override
- public String toStringSafe(String in) {
- return in;
- }
-
- @Override
- public boolean isValidSafe(String in) {
- return true;
- }
- }
-}
Modified: trunk/soft/fudaa-crue/ui-common/src/test/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformerTest.java
===================================================================
--- trunk/soft/fudaa-crue/ui-common/src/test/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformerTest.java 2012-10-05 22:41:30 UTC (rev 7722)
+++ trunk/soft/fudaa-crue/ui-common/src/test/java/org/fudaa/fudaa/crue/common/helper/PropertyToStringTransformerTest.java 2012-10-05 22:45:14 UTC (rev 7723)
@@ -1,7 +1,9 @@
package org.fudaa.fudaa.crue.common.helper;
+import org.fudaa.ctulu.converter.AbstractPropertyToStringTransformer;
import java.awt.geom.Point2D;
import java.util.Map;
+import org.fudaa.ctulu.converter.ToStringTransformerFactory;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -16,8 +18,8 @@
@Test
public void testToStringPoint2D() {
- Map<Class, PropertyToStringTransformer> createTransformers = PropertyToStringTransformer.createTransformers();
- PropertyToStringTransformer transformer = createTransformers.get(String.class);
+ Map<Class, AbstractPropertyToStringTransformer> createTransformers = ToStringTransformerFactory.createTransformers();
+ AbstractPropertyToStringTransformer transformer = createTransformers.get(String.class);
assertNotNull(transformer);
transformer = createTransformers.get(Point2D.Double.class);
assertNotNull(transformer);
@@ -32,7 +34,7 @@
@Test
public void testToStringPoint2DArray() {
- PropertyToStringTransformer<Point2D.Double[]> transformer = PropertyToStringTransformer.getPoint2dArrayTransformer();
+ AbstractPropertyToStringTransformer<Point2D.Double[]> transformer = ToStringTransformerFactory.getPoint2dArrayTransformer();
assertNotNull(transformer);
Point2D.Double pt = new Point2D.Double();
pt.setLocation(100, 120);
Modified: trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerControllerSaverHelper.java
===================================================================
--- trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerControllerSaverHelper.java 2012-10-05 22:41:30 UTC (rev 7722)
+++ trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerControllerSaverHelper.java 2012-10-05 22:45:14 UTC (rev 7723)
@@ -15,7 +15,8 @@
import org.fudaa.ebli.calque.BCalque;
import org.fudaa.fudaa.crue.common.config.ConfigSaverHelper;
import org.fudaa.fudaa.crue.common.helper.CtuluUIForNetbeans;
-import org.fudaa.fudaa.crue.common.helper.PropertyToStringTransformer;
+import org.fudaa.ctulu.converter.AbstractPropertyToStringTransformer;
+import org.fudaa.ctulu.converter.ToStringTransformerFactory;
import org.fudaa.fudaa.crue.planimetry.action.SigFormatHelper;
import org.fudaa.fudaa.crue.planimetry.layer.PlanimetryAdditionalLayerContrat;
import org.fudaa.fudaa.sig.wizard.FSigFileLoadResult;
@@ -37,14 +38,14 @@
public static void restorVisibleProperty(Map<String, String> optionsBykey, BCalque layer) {
//on sauvegarde les propriétés graphiques:
- layer.setVisible((Boolean) PropertyToStringTransformer.createTransformers().get(Boolean.TYPE).fromString(optionsBykey.get(
+ layer.setVisible((Boolean) ToStringTransformerFactory.createTransformers().get(Boolean.TYPE).fromString(optionsBykey.get(
VISIBLE)));
}
public static String VISIBLE = "Visible";
public void addVisibleProperty(CrueEtudeExternDaoConfiguration.Ressource ressource, BCalque layer) {
//on sauvegarde les propriétés graphiques:
- ressource.getOptions().add(new Option(VISIBLE, PropertyToStringTransformer.createTransformers().get(Boolean.TYPE).toString(
+ ressource.getOptions().add(new Option(VISIBLE, ToStringTransformerFactory.createTransformers().get(Boolean.TYPE).toString(
layer.isVisible())));
}
@@ -150,7 +151,7 @@
restorVisibleProperty(optionsBykey, (BCalque) layer);
optionsBykey.remove(VISIBLE);
LinkedHashMap<String, Property> nodeProperties = ConfigSaverHelper.getNodeProperties(createSet);
- Map<Class, PropertyToStringTransformer> createTransformers = PropertyToStringTransformer.createTransformers();
+ Map<Class, AbstractPropertyToStringTransformer> createTransformers = ToStringTransformerFactory.createTransformers();
for (Map.Entry<String, String> readProperties : optionsBykey.entrySet()) {
String key = readProperties.getKey();
String value = readProperties.getValue();
@@ -158,7 +159,7 @@
if (property == null) {
log.addWarn("configEtu.unknownProperty.Error", key);
} else {
- PropertyToStringTransformer transformer = createTransformers.get(property.getValueType());
+ AbstractPropertyToStringTransformer transformer = createTransformers.get(property.getValueType());
if (transformer == null) {
log.addWarn("configEtu.unknownType.Error", property.getValueType());
} else if (!transformer.isValid(value)) {
Modified: trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerImageControllerSaver.java
===================================================================
--- trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerImageControllerSaver.java 2012-10-05 22:41:30 UTC (rev 7722)
+++ trunk/soft/fudaa-crue/ui-planimetry/src/main/java/org/fudaa/fudaa/crue/planimetry/save/LayerImageControllerSaver.java 2012-10-05 22:45:14 UTC (rev 7723)
@@ -11,7 +11,8 @@
import org.fudaa.dodico.crue.io.conf.Option;
import org.fudaa.ebli.calque.ZModeleStatiqueImageRaster;
import org.fudaa.fudaa.crue.common.config.ConfigSaverHelper;
-import org.fudaa.fudaa.crue.common.helper.PropertyToStringTransformer;
+import org.fudaa.ctulu.converter.AbstractPropertyToStringTransformer;
+import org.fudaa.ctulu.converter.ToStringTransformerFactory;
import org.fudaa.fudaa.crue.planimetry.configuration.ImageConfigurationInfo;
import org.fudaa.fudaa.crue.planimetry.controller.LayerImageController;
import org.fudaa.fudaa.crue.planimetry.layer.PlanimetryAdditionalLayerContrat;
@@ -39,7 +40,7 @@
//point image
Double[] ptImg = model.getPtImg();
Double[] ptReel = model.getPtReel();
- final PropertyToStringTransformer<Double[]> point2dArrayTransformer = PropertyToStringTransformer.getPoint2dArrayTransformer();
+ final AbstractPropertyToStringTransformer<Double[]> point2dArrayTransformer = ToStringTransformerFactory.getPoint2dArrayTransformer();
ressource.getOptions().add(new Option(POINTS_IMAGE_ID,
point2dArrayTransformer.toString(ptImg)));
ressource.getOptions().add(new Option(POINTS_REELS_ID, point2dArrayTransformer.toString(
@@ -68,7 +69,7 @@
if (image == null) {
return null;
}
- final PropertyToStringTransformer<Double[]> point2dArrayTransformer = PropertyToStringTransformer.getPoint2dArrayTransformer();
+ final AbstractPropertyToStringTransformer<Double[]> point2dArrayTransformer = ToStringTransformerFactory.getPoint2dArrayTransformer();
Double[] ptImg = point2dArrayTransformer.fromString(optionsBykey.remove(POINTS_IMAGE_ID));
if (ptImg == null || ptImg.length < 2) {
log.addError("externConfig.image.pointImage.error", ressource.getNom());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|