[Schmitzm-commits] r680 - in branches/2.0-RC2/src: schmitzm/geotools/styling skrueger/geotools skrueger/geotools/resource/locales
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Feb 5 20:46:11 CET 2010
Author: alfonx
Date: 2010-02-05 20:46:10 +0100 (Fri, 05 Feb 2010)
New Revision: 680
Modified:
branches/2.0-RC2/src/schmitzm/geotools/styling/StylingUtil.java
branches/2.0-RC2/src/skrueger/geotools/MapPaneToolBar.java
branches/2.0-RC2/src/skrueger/geotools/XMapPane.java
branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar.properties
branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_de.properties
branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_fr.properties
Log:
added a cool blink(FeatureCollection) method
Modified: branches/2.0-RC2/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/geotools/styling/StylingUtil.java 2010-02-05 15:25:25 UTC (rev 679)
+++ branches/2.0-RC2/src/schmitzm/geotools/styling/StylingUtil.java 2010-02-05 19:46:10 UTC (rev 680)
@@ -153,12 +153,7 @@
/** transparent color */
public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
- /**
- * Standard-Instanz eines {@link StyleBuilder}.
- *
- * @Deprecated Bitte nicht benutzen. Ich habe schlechte Efahrungen damit.
- * Zumindest uin 2.4.
- */
+ /** Standard-Instanz eines {@link StyleBuilder}. */
public static final StyleBuilder STYLE_BUILDER = new StyleBuilder();
/** Standard-Instanz eines {@link SLDTransformer}. */
@@ -167,13 +162,6 @@
SLDTRANSFORMER.setEncoding(Charset.defaultCharset());
}
- // /**
- // * Standard-Instanz eines {@link StyleBuilder}.
- // *
- // * @deprecated wurde ersetzt durch {@link #STYLE_BUILDER}
- // */
- // public static final StyleBuilder builder = STYLE_BUILDER;
-
/** Standard-Instanz einer {@link StyleFactory} */
public static final StyleFactory STYLE_FACTORY = CommonFactoryFinder
.getStyleFactory(GeoTools.getDefaultHints());
@@ -191,11 +179,13 @@
* document them. This is still under construction. TODO SK
*/
- static final Literal size0 = FeatureUtil.FILTER_FACTORY2.literal(13);
+ static final Literal size0 = FeatureUtil.FILTER_FACTORY2.literal(26);
+
static final Literal size1 = FeatureUtil.FILTER_FACTORY2.literal(9);
static final Literal size2 = FeatureUtil.FILTER_FACTORY2.literal(7);
static final Literal size3 = FeatureUtil.FILTER_FACTORY2.literal(3);
static final Literal zeroLit = FeatureUtil.FILTER_FACTORY2.literal(0);
+ static final Literal halfLit = FeatureUtil.FILTER_FACTORY2.literal(.5);
static final Graphic SELECTION_GRAPHIC1 = STYLE_FACTORY.createGraphic(
new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
@@ -205,6 +195,14 @@
new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2
.literal(1), size1, zeroLit);
+ static final Graphic BLINK_GRAPHIC1 = STYLE_FACTORY.createGraphic(
+ new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
+ FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
+ STYLE_FACTORY.createFill(STYLE_BUILDER
+ .colorExpression(Color.WHITE)), size0, halfLit) },
+ new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2
+ .literal(1), size0, zeroLit);
+
static final Graphic SELECTION_GRAPHIC2 = STYLE_FACTORY.createGraphic(
new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
@@ -1036,7 +1034,10 @@
styles = stylereader.readXML();
return styles;
} catch (Exception e) {
- LOGGER.warn(" ... no styles recognized. Return 'new Style[] { null }' ",e);
+ LOGGER
+ .warn(
+ " ... no styles recognized. Return 'new Style[] { null }' ",
+ e);
return new Style[] { null };
}
@@ -1086,8 +1087,8 @@
File exportFile, Charset charset) throws TransformerException,
IOException {
SLDTRANSFORMER.setIndentation(2);
-// LOGGER.debug("default charset = "+ Charset.defaultCharset());
-// SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
+ // LOGGER.debug("default charset = "+ Charset.defaultCharset());
+ // SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
Style exportStyle = removeSelectionFeatureTypeStyle(origStyle);
@@ -1174,7 +1175,7 @@
*/
public static boolean isStyleDifferent(Style style1, File style2file) {
SLDTRANSFORMER.setIndentation(2);
-
+
try {
if (!style2file.exists())
@@ -1203,7 +1204,7 @@
*/
public static boolean isStyleDifferent(Style style1, Style style2) {
try {
-// SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
+ // SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
// Transforming style2 to an XML String
String style1string = SLDTRANSFORMER.transform(style1);
String style2string = SLDTRANSFORMER.transform(style2);
@@ -2513,34 +2514,36 @@
return ff.property(correctedName);
}
-// if (expression instanceof AttributeExpression) {
-// AttributeExpression aExpression = (AttributeExpression) expression;
-// Name correctedName = FeatureUtil
-// .findBestMatchingAttributeFallBackFirst(schema,
-// aExpression.getPropertyName());
-//
-// return new AttributeExpressionImpl(correctedName
-// .getLocalPart());
-// }
+ // if (expression instanceof AttributeExpression) {
+ // AttributeExpression aExpression = (AttributeExpression)
+ // expression;
+ // Name correctedName = FeatureUtil
+ // .findBestMatchingAttributeFallBackFirst(schema,
+ // aExpression.getPropertyName());
+ //
+ // return new AttributeExpressionImpl(correctedName
+ // .getLocalPart());
+ // }
return super.copy(expression);
}
-
+
@Override
protected Filter copy(Filter filter) {
-
+
if (filter instanceof BinaryComparisonAbstract) {
- BinaryComparisonAbstract binFilter = (BinaryComparisonAbstract)filter;
+ BinaryComparisonAbstract binFilter = (BinaryComparisonAbstract) filter;
binFilter.setExpression1(copy(binFilter.getExpression1()));
binFilter.setExpression2(copy(binFilter.getExpression2()));
// TODO noch viel mehr faelle!!
if (filter instanceof IsBetweenImpl) {
- IsBetweenImpl isbetween = (IsBetweenImpl)filter;
- isbetween.setExpression(copy(isbetween.getExpression()));
+ IsBetweenImpl isbetween = (IsBetweenImpl) filter;
+ isbetween
+ .setExpression(copy(isbetween.getExpression()));
}
-
+
}
- return (Filter)super.copy(filter);
+ return (Filter) super.copy(filter);
}
};
@@ -2694,4 +2697,96 @@
}
}
+ /**
+ * @return A {@link FeatureTypeStyle} that can be used style the given
+ * geoObject during a blink or highlight process.
+ */
+ public static FeatureTypeStyle createBlinkFeatureTypeStyle(Object geoObject) {
+ if (geoObject instanceof GridCoverage2D
+ || geoObject instanceof org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) {
+ // Wenn irgendwann mal selection für raster möglich ist, dann hier
+ // einen schöneren style erstellen.
+ return GridUtil.createDefaultStyle().featureTypeStyles().get(0);
+ }
+
+ // We have vector-data. Now let's determine the type...
+ GeometryForm geometryForm = null;
+ if (geoObject instanceof FeatureCollection) {
+ geometryForm = FeatureUtil
+ .getGeometryForm((FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject);
+ } else if (geoObject instanceof GeometryAttributeType) {
+ geometryForm = FeatureUtil
+ .getGeometryForm((GeometryAttributeType) geoObject);
+ } else if (geoObject instanceof FeatureSource) {
+ geometryForm = FeatureUtil
+ .getGeometryForm((FeatureSource<SimpleFeatureType, SimpleFeature>) geoObject);
+ }
+
+ Symbolizer[] symbolizers = new Symbolizer[0];
+
+ Graphic bg2;
+ switch (geometryForm) {
+
+ case POINT:
+
+ Literal size0 = FeatureUtil.FILTER_FACTORY2.literal(26);
+ Literal size1 = FeatureUtil.FILTER_FACTORY2.literal(28);
+
+ Graphic bg1 = STYLE_FACTORY.createGraphic(new ExternalGraphic[0],
+ new Mark[] { STYLE_FACTORY.createMark(
+ FeatureUtil.FILTER_FACTORY2.literal("circle"),
+ STYLE_BUILDER.createStroke(Color.red, 2.),null, size1,
+ halfLit) }, new org.geotools.styling.Symbol[0],
+ FeatureUtil.FILTER_FACTORY2.literal(1), size1, zeroLit);
+
+ PointSymbolizer ps1 = STYLE_FACTORY.createPointSymbolizer();
+ ps1.setGraphic(bg1);
+ symbolizers = LangUtil.extendArray(symbolizers, ps1);
+
+ bg2 = STYLE_FACTORY.createGraphic(new ExternalGraphic[0],
+ new Mark[] { STYLE_FACTORY.createMark(
+ FeatureUtil.FILTER_FACTORY2.literal("circle"),
+ STYLE_BUILDER.createStroke(Color.black, 2.),
+ STYLE_BUILDER.createFill(Color.WHITE, 0.3), size0,
+ halfLit) }, new org.geotools.styling.Symbol[0],
+ FeatureUtil.FILTER_FACTORY2.literal(1), size0, zeroLit);
+
+ PointSymbolizer ps2 = STYLE_FACTORY.createPointSymbolizer();
+ ps2.setGraphic(bg2);
+
+ symbolizers = LangUtil.extendArray(symbolizers, ps2);
+ break;
+ case POLYGON:
+
+ PolygonSymbolizer pol1 = STYLE_BUILDER.createPolygonSymbolizer(STYLE_BUILDER.createStroke(Color.red, 4),null);
+ symbolizers = LangUtil.extendArray(symbolizers, pol1);
+
+ PolygonSymbolizer pol2 = STYLE_BUILDER.createPolygonSymbolizer(STYLE_BUILDER.createStroke(Color.black, 2),STYLE_BUILDER.createFill(Color.WHITE, .5));
+ symbolizers = LangUtil.extendArray(symbolizers, pol2);
+
+ break;
+
+ case LINE:
+
+ LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(Color.red,
+ 6.);
+ symbolizers = LangUtil.extendArray(symbolizers, ls);
+
+ LineSymbolizer ls2 = STYLE_BUILDER.createLineSymbolizer(
+ Color.black, 4.);
+ symbolizers = LangUtil.extendArray(symbolizers, ls2);
+
+ LineSymbolizer ls3 = STYLE_BUILDER.createLineSymbolizer(
+ Color.white, 2.);
+ symbolizers = LangUtil.extendArray(symbolizers, ls3);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Provide a suitable object.");
+ }
+
+ return STYLE_BUILDER.createFeatureTypeStyle(symbolizers, Double.NaN,
+ Double.NaN);
+ }
+
}
Modified: branches/2.0-RC2/src/skrueger/geotools/MapPaneToolBar.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/MapPaneToolBar.java 2010-02-05 15:25:25 UTC (rev 679)
+++ branches/2.0-RC2/src/skrueger/geotools/MapPaneToolBar.java 2010-02-05 19:46:10 UTC (rev 680)
@@ -96,6 +96,7 @@
/** Constant for the tool "Zoom In" (110). */
public static final int TOOL_ZOOMIN = 110;
+ public static final int ACTION_ZOOM_DEFAULT = 150;
/** Constant for the tool "Zoom Out" (120). */
public static final int TOOL_ZOOMOUT = 120;
/** Constant for the action "Zoom back" (130). */
@@ -318,7 +319,7 @@
// MapView.class.getResource("resource/icons/info.png")),
// R("MapPaneButtons.Info.TT")), false);
addTool(new MapPaneToolBarAction(TOOL_INFO, this, XMapPaneTool.INFO), false);
-
+
// Zoom in
addTool(new MapPaneToolBarAction(TOOL_ZOOMIN, this, XMapPaneTool.ZOOM_IN), false);
@@ -491,7 +492,7 @@
protected void performActionButton(int action, ActionEvent e) {
if (mapPane == null)
return;
-
+
// Perform the action "Zoom back": Revert the last zoom
if (action == ACTION_ZOOM_BACK) {
if (zoomBackIndex <= 1)
Modified: branches/2.0-RC2/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/XMapPane.java 2010-02-05 15:25:25 UTC (rev 679)
+++ branches/2.0-RC2/src/skrueger/geotools/XMapPane.java 2010-02-05 19:46:10 UTC (rev 680)
@@ -36,6 +36,7 @@
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
+import org.geotools.map.DefaultMapLayer;
import org.geotools.map.MapContext;
import org.geotools.map.MapLayer;
import org.geotools.map.event.MapLayerEvent;
@@ -49,6 +50,7 @@
import org.geotools.renderer.lite.RendererUtilities;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.resources.image.ImageUtilities;
+import org.geotools.styling.Style;
import org.geotools.swing.JMapPane;
import org.geotools.swing.event.MapMouseEvent;
import org.geotools.swing.event.MapPaneEvent;
@@ -66,6 +68,7 @@
import schmitzm.geotools.io.GeoImportUtil;
import schmitzm.geotools.map.event.JMapPaneListener;
import schmitzm.geotools.map.event.MapLayerAdapter;
+import schmitzm.geotools.styling.StylingUtil;
import schmitzm.lang.LangUtil;
import schmitzm.swing.JPanel;
import schmitzm.swing.SwingUtil;
@@ -610,7 +613,10 @@
*/
public XMapPane(final MapContext localContext_,
final Map<Object, Object> rendererHints) {
+
super(true);
+
+ blinkTimer = initBlinkTimer();
// A default setting
RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT;
@@ -741,6 +747,7 @@
}
+
/**
* Fuegt der Map einen Listener hinzu.
*
@@ -817,24 +824,27 @@
final Envelope maxAllowedExtend = getMaxExtend();
+ // This variable is used to break the loop if it runs forever...
+ Envelope lastCalculatedArea = null;
/*
* If a maxAllowedExtend is set, we have to honour that...
*/
- Envelope lastCalculatedArea = null;
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
&& newArea != null && !newArea.isNull()
&& !Double.isNaN(newArea.getMinX())
&& !Double.isNaN(newArea.getMaxX())
&& !Double.isNaN(newArea.getMinY())
- && !Double.isNaN(newArea.getMaxY())
- ) // Due to Double precision problems, this may iterate for ever
+ && !Double.isNaN(newArea.getMaxY())) // Due to Double precision
+ // problems, this may
+ // iterate for ever
{
-
+
if (newArea.equals(lastCalculatedArea))
break;
- // Check that we are not iterating for ever due to double precision rounding errors
+ // Check that we are not iterating for ever due to double precision
+ // rounding errors
lastCalculatedArea = newArea;
-
+
// Exceeds top? Move down and maybe cut
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
final double divY = newArea.getMaxY()
@@ -938,8 +948,7 @@
.getCoordinateReferenceSystem()), false);
}
}
-
-
+
}
return new ReferencedEnvelope(newArea, env
@@ -1255,8 +1264,8 @@
return null;
}
- return JTSUtil
- .fixAspectRatio(getVisibleRect(), addDefaultMargin(layerBounds), true);
+ return JTSUtil.fixAspectRatio(getVisibleRect(),
+ addDefaultMargin(layerBounds), true);
}
return maxExtend;
@@ -1957,6 +1966,8 @@
private long lastRenderingDuration = 1000;
private XMapPaneTool tool = null;
+ private Timer blinkTimer ;
+
/**
* Set the minimum (nearest) allowed zoom scale. This is the bigger number
* value of the two. If <code>null</code> is passed, Double.MAXVALUE are
@@ -2109,9 +2120,6 @@
* X-Koordinate der BIS-Position
* @param py
* Y-Koordinate der BIS-Position
- * @param winToGeotransform
- * Eine Window to Geo transform. If <code>null</code>,
- * {@link #getScreenToWorld()} is used.
*/
public Envelope tranformGeoToWindow(final double ox, final double oy,
final double px, final double py) {
@@ -2128,6 +2136,19 @@
}
/**
+ * Transformiert einen Geo-Koordinate in eine Fenster-Koordinaten.
+ *
+ * @param x
+ * X-Koordinate der VON-Position
+ * @param y
+ * Y-Koordinate der VON-Position
+ */
+ public Point2D tranformGeoToWindow(final double x, final double y) {
+ return getWorldToScreenTransform().transform(new Point2D.Double(x, y),
+ null);
+ }
+
+ /**
* Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten.
*
* @param ox
@@ -2250,7 +2271,7 @@
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
getMapBackgroundColor());
- addGadgets(finalG, false);
+ addGadgets(finalG, false);
finalG.dispose();
@@ -2686,5 +2707,59 @@
public double getDefaultMaxMapExtendMode() {
return defaultMaxMapExtendMode;
}
+
+ final static int BLINK_TIMER_DEPLAY = 800;
+
+ private Timer initBlinkTimer() {
+ Timer timer = new Timer(BLINK_TIMER_DEPLAY, new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ XMapPane.this.repaint(300);
+ }
+ });
+ timer.setDelay(BLINK_TIMER_DEPLAY);
+ timer.setRepeats(false);
+ return timer;
+ }
+
+ /**
+ * Makes the given {@link FeatureCollection} bink in the map for a moment
+ */
+ public void blink(
+ FeatureCollection<SimpleFeatureType, SimpleFeature> features) {
+ {
+ blinkTimer.stop();
+ repaint();
+ blinkTimer = initBlinkTimer();
+
+ DefaultMapContext mc = new DefaultMapContext(getMapContext()
+ .getCoordinateReferenceSystem());
+
+ Style style = StylingUtil.STYLE_FACTORY.createStyle();
+ style.featureTypeStyles().add(
+ StylingUtil.createBlinkFeatureTypeStyle(features));
+
+ // style = StylingUtil.createStyleSimple(features, Color.pink,
+ // Color.WHITE);
+
+ DefaultMapLayer dml = new DefaultMapLayer(features, style);
+ mc.addLayer(dml);
+
+ GTRenderer renderer = new StreamingRenderer();
+
+ renderer.setJava2DHints(getJava2dHints());
+
+ renderer.setContext(mc);
+
+ Graphics2D g2d = (Graphics2D) getGraphics();
+ renderer.paint(g2d, getVisibleRect(), getMapArea());
+
+ blinkTimer.start();
+
+ }
+
+ }
+
}
Modified: branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar.properties
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar.properties 2010-02-05 15:25:25 UTC (rev 679)
+++ branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar.properties 2010-02-05 19:46:10 UTC (rev 680)
@@ -63,3 +63,4 @@
MapPaneButtons.Selection.SetSelection.TT=Select objects to be selected
MapPaneButtons.Selection.AddSelection.TT=Add objects to current selection
MapPaneButtons.Selection.RemoveSelection.TT=Remove objects from current selection
+
Modified: branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_de.properties
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_de.properties 2010-02-05 15:25:25 UTC (rev 679)
+++ branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_de.properties 2010-02-05 19:46:10 UTC (rev 680)
@@ -63,3 +63,4 @@
MapPaneButtons.Selection.AddSelection.TT=F\u00fcgt Objekte zur Selektion hinzu
MapPaneButtons.Selection.RemoveSelection.TT=Entfernt Objekte aus der Selektion
MapPaneButtons.Selection.SetSelection.TT=Setzt die Selektion auf die ausgew\u00e4hlten Objekte
+
Modified: branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_fr.properties
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_fr.properties 2010-02-05 15:25:25 UTC (rev 679)
+++ branches/2.0-RC2/src/skrueger/geotools/resource/locales/mapPaneToolbar_fr.properties 2010-02-05 19:46:10 UTC (rev 680)
@@ -63,3 +63,4 @@
MapPaneButtons.Selection.SetSelection.TT=Marquer les objects \u00e0 s\u00e9lectionner
MapPaneButtons.Selection.AddSelection.TT=Ajouter des objets \u00e0 la s\u00e9lection actuelle
MapPaneButtons.Selection.RemoveSelection.TT=D\u00e9placer les objects de la s\u00e9lection actuelle
+
More information about the Schmitzm-commits
mailing list