[Schmitzm-commits] r517 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/styling skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Nov 12 11:12:40 CET 2009
Author: alfonx
Date: 2009-11-12 11:12:39 +0100 (Thu, 12 Nov 2009)
New Revision: 517
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
Log:
* Two new utility methods dealing with the selection FTS in StyledLayerUtil and StylingUtil
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java 2009-11-11 21:17:33 UTC (rev 516)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java 2009-11-12 10:12:39 UTC (rev 517)
@@ -188,34 +188,6 @@
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 Stroke SELECTION_STROKE1 =
- // //
- // STYLE_FACTORY.createStroke(STYLE_BUILDER.colorExpression(Color.YELLOW),
- // // size2);
- //
- // static final Stroke SELECTION_STROKE1 = STYLE_FACTORY.createStroke(
- // STYLE_BUILDER.colorExpression(Color.YELLOW.brighter()),
- // FeatureUtil.FILTER_FACTORY2.literal(4), FeatureUtil.FILTER_FACTORY2
- // .literal(1.), FILTER_FACTORY.literal("round"),
- // FILTER_FACTORY.literal("round"), new float[0],
- // FeatureUtil.FILTER_FACTORY2.literal(0), null, null);
- //
- // static final Stroke SELECTION_STROKE2 = STYLE_FACTORY.createStroke(
- // STYLE_BUILDER.colorExpression(Color.BLACK),
- // FeatureUtil.FILTER_FACTORY2.literal(1.5),
- // FeatureUtil.FILTER_FACTORY2.literal(1.), FILTER_FACTORY
- // .literal("round"), FILTER_FACTORY.literal("round"),
- // new float[] { 3f, 3f }, FeatureUtil.FILTER_FACTORY2.literal(0),
- // null, null);
- //
- // static final Stroke SELECTION_STROKE3 = STYLE_FACTORY.createStroke(
- // STYLE_BUILDER.colorExpression(Color.WHITE),
- // FeatureUtil.FILTER_FACTORY2.literal(1.5),
- // FeatureUtil.FILTER_FACTORY2.literal(1.), FILTER_FACTORY
- // .literal("round"), FILTER_FACTORY.literal("round"),
- // new float[] { 3f, 3f }, FeatureUtil.FILTER_FACTORY2.literal(3),
- // null, null);
static final Graphic SELECTION_GRAPHIC1 = STYLE_FACTORY.createGraphic(
new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
@@ -1151,8 +1123,35 @@
return cleanStyle;
}
+
/**
+ * Returns <code>null</code> or any {@link FeatureTypeStyle} that is SELECTION related.
+ *
+ * @see {@link FeatureMapLayerSelectionSynchronizer#SELECTION_STYLING_FTS_NAME}
+ */
+ public static FeatureTypeStyle getSelectionFeatureTypeStyle(final Style style) {
+
+ if (style == null) return null;
+
+ // Remove any selection-FeatureTypeStyle from the new Style
+ for (int ii = 0; ii < style.featureTypeStyles().size(); ii++) {
+
+ FeatureTypeStyle fts = style.featureTypeStyles().get(ii);
+
+ if (fts.getName() != null
+ && fts
+ .getName()
+ .equals(
+ FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
+ return style.featureTypeStyles().get(ii);
+ }
+ }
+
+ return null;
+ }
+
+ /**
* Compares a given Style and a {@link File} containg a {@link Style}.
*
* @param style1
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java 2009-11-11 21:17:33 UTC (rev 516)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java 2009-11-12 10:12:39 UTC (rev 517)
@@ -909,7 +909,7 @@
final List<FeatureTypeStyle> list = style.featureTypeStyles();
- final JPanel panel = new JPanel(new MigLayout("wrap 2","[]:3:[]"));
+ final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));
if (style == null) {
// No Style => no legend
@@ -937,16 +937,16 @@
final ImageIcon legendIcon = new ImageIcon(imageForRule);
final JLabel iconLabel = new JLabel(legendIcon);
- panel.add(iconLabel,"sgx1");
-// hbox.setAlignmentX(0f);
-// hbox.add(iconLabel);
-// hbox.add(Box.createHorizontalStrut(3));
+ panel.add(iconLabel, "sgx1");
+ // hbox.setAlignmentX(0f);
+ // hbox.add(iconLabel);
+ // hbox.add(Box.createHorizontalStrut(3));
final Translation labelT = new Translation();
labelT.fromOneLine(rule.getDescription().getTitle());
final JLabel classTitleLabel = new JLabel(labelT.toString());
-
- panel.add(classTitleLabel,"sgx2");
+
+ panel.add(classTitleLabel, "sgx2");
classTitleLabel.setLabelFor(iconLabel);
}
}
@@ -1000,12 +1000,12 @@
// ****************************************************************************
final BufferedImage buffImage = new BufferedImage(iconWidth,
iconHeight, BufferedImage.TYPE_INT_ARGB);
-
+
final Graphics2D graphics = buffImage.createGraphics();
if (colorModel != null) {
// The colors come from the ColorModel!
-
+
try {
Object inData = null;
switch (colorModel.getTransferType()) {
@@ -1075,16 +1075,17 @@
}
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage));
-// hbox.setAlignmentX(0f);
- panel.add(iconLabel,"sgx1");
-// hbox.add(Box.createHorizontalStrut(3));
+ // hbox.setAlignmentX(0f);
+ panel.add(iconLabel, "sgx1");
+ // hbox.add(Box.createHorizontalStrut(3));
final Translation labelT = rasterLegendData.get(rValue);
final JLabel classTitleLabel = new JLabel(labelT.toString());
- panel.add(classTitleLabel,"sgx2" + (rasterLegendData.getPaintGaps()? ", gapy 0 3":""));
+ panel.add(classTitleLabel, "sgx2"
+ + (rasterLegendData.getPaintGaps() ? ", gapy 0 3" : ""));
classTitleLabel.setLabelFor(iconLabel);
-// box.add(hbox);
+ // box.add(hbox);
if (rasterLegendData.getPaintGaps()) {
iconLabel
@@ -1154,4 +1155,41 @@
return true;
return false;
}
+
+ /**
+ * Set the given Style as the Style of the {@link MapLayer}, unless the
+ * styles are the same (not comparing selection stuff). If the
+ * {@link MapLayer}s {@link Style} is changed, the selection FTS is kept.<br/>
+ * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a
+ * repaint, so only use it when needed.
+ *
+ * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has been changed.
+ */
+ public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer,
+ Style style2) {
+
+ Style mapLayerStyleCleaned = StylingUtil
+ .removeSelectionFeatureTypeStyle(mapLayer.getStyle());
+
+ Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2);
+
+ if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned,
+ newStyleCleaned)) {
+
+ // They are different when compared without SELECTION FTS!
+
+ // Now let's copy any SELECTION FTS to the now style
+ FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle( mapLayer.getStyle() );
+ if (selectionFeatureTypeStyle != null) {
+ newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle);
+ // newStyleCleaned is not so clean anymore... We just alled a selcetion FTS
+ }
+
+ mapLayer.setStyle(newStyleCleaned);
+
+ return true;
+
+ } else return false;
+ }
+
}
More information about the Schmitzm-commits
mailing list