[Schmitzm-commits] r516 - in branches/1.0-gt2-2.6: dist src/gtmig/org/geotools/swing src/schmitzm/geotools/feature src/schmitzm/geotools/gui src/schmitzm/geotools/styling src/schmitzm/swing src/skrueger/geotools src/skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 11 22:17:35 CET 2009


Author: alfonx
Date: 2009-11-11 22:17:33 +0100 (Wed, 11 Nov 2009)
New Revision: 516

Modified:
   branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
   branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GeoMapPane.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
* Extended schmitzm.JPanel to generally set its background to white when printed, by overwriting the print() method.
* Simplified the creation and update logic of ((Design)Atlas)MapLegend and ((Design)Atlas)MapLayerLegend. Besides other things there now is a LegendHelper class in AtlasProject... 
* Orginized Imports
* Removed a lot of DEBUG messages...

Modified: branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
===================================================================
(Binary files differ)

Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -1520,7 +1520,7 @@
 	private BufferedImage getBgImage() {
 
 		if (bgImage == null) {
-			LOGGER.debug("creating a new background image");
+//			LOGGER.debug("creating a new background image");
 
 			Rectangle curPaintArea = getVisibleRect();
 			// allow a single pixel margin at the right and bottom edges
@@ -1566,7 +1566,7 @@
 	private BufferedImage getLocalImage() {
 
 		if (localImage == null) {
-			LOGGER.debug("creating a new local image");
+//			LOGGER.debug("creating a new local image");
 
 			Rectangle curPaintArea = getVisibleRect();
 			// allow a single pixel margin at the right and bottom edges
@@ -1615,12 +1615,8 @@
 	 * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
 	 */
 	public void onRenderingCompleted() {
-		System.out.println("onRenderingCompleted");
-
 		updateFinalImage();
-
 		repaint();
-
 	}
 
 	/**
@@ -2031,6 +2027,8 @@
 	public void dispose() {
 		if (isDisposed())
 			return;
+		
+		setPainting(false);
 
 		disposed = true;
 

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -366,7 +366,7 @@
 			style = createLineStyle(Color.BLUE, 1);
 
 		style.setName(DEFAULT_VECTOR_STYLE_NAME);
-
+		
 		// 26 style.setTitle(DEFAULT_VECTOR_STYLE_NAME);
 		style.getDescription().setTitle(
 				new SimpleInternationalString(DEFAULT_VECTOR_STYLE_NAME));

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GeoMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GeoMapPane.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/GeoMapPane.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -295,6 +295,7 @@
 		scalePane=null;
 		horGrid=null;
 		vertGrid=null;
+		getMapContext().clearLayerList();
 		mapPane.dispose();
 		removeAll();
 		disposed = true;

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -151,14 +151,6 @@
 	 */
 	public static final int NONE = 100;
 
-	// /** Wenn true, dann werden RasterLayer waehrend des Panning auf
-	// setVisible(false) gesetzt **/
-	// protected boolean hideRasterLayersDuringPan = false;
-	// /** Remebers the layers that are hidden during a PAN action **/
-	// protected List<MapLayer> hiddenForPanning = new LinkedList<MapLayer>();
-
-	// private MouseInputAdapter dragWaitCursorListener;
-
 	/**
 	 * Erzeugt ein neues MapPane.
 	 * 
@@ -223,10 +215,6 @@
 			Map<Object, Object> rendererHints) {
 		super(null, rendererHints);
 
-		//
-		// // Having problems with StreamingRendere!
-		// getRenderer().setContext(getContext());
-
 		// Dieser Hint sorgt wohl dafuer, dass die Rasterpixel nicht
 		// interpoliert werden
 		// Ueber die Methode enableAntiAliasing(boolean) kann das
@@ -234,7 +222,73 @@
 		// werden
 		RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT;
 		setJava2dHints(hintsJava2d);
-		
+
+		//
+		// // CRS wird immer vom ersten in die Karte eingefuegten Layer
+		// uebernommen
+		// // Wenn noch keine MapArea gesetzt wurde, wird diese vom Layer
+		// // uebernommen
+		// getLocalContext().addMapLayerListListener(new MapLayerListAdapter() {
+		// public void layerAdded(MapLayerListEvent e) {
+		// if (getLocalContext().getLayerCount() == 1) {
+		// CoordinateReferenceSystem crs = null;
+		// // CRS aus Layer ermitteln
+		// try {
+		// crs = e.getLayer().getFeatureSource().getSchema()
+		// .getGeometryDescriptor()
+		// .getCoordinateReferenceSystem();
+		// // wenn noch keine MapArea gesetzt wurde, den
+		// // Ausdehnungsbereich des ersten Layers
+		// // verwenden, so dass die erste
+		// // Karte komplett angezeigt wird
+		// if (getMapArea() == null) {
+		// // Envelope newMapArea = new Envelope(e.getLayer()
+		// // .getFeatureSource().getBounds());
+		// Envelope newMapArea = getMaxExtend();
+		// setMapArea(newMapArea);
+		// // in layerAdded(.) der Oberklasse wird
+		// // mapArea nochmal neu gesetzt, wenn das
+		// // erste Layer
+		// // eingefuegt wird
+		// // >> hier nur die AreaOfInterest setzen
+		// getLocalContext().setAreaOfInterest(newMapArea, crs);
+		// }
+		// } catch (Exception err) {
+		// LOGGER
+		// .warn("CRS could not be determined from map layer. "
+		// + GeoImportUtil.getDefaultCRS()
+		// .getName() + "  used.");
+		// // err.printStackTrace();
+		// crs = GeoImportUtil.getDefaultCRS();
+		// }
+		// // CRS dem MapContext zuweisen
+		// try {
+		// getLocalContext().setCoordinateReferenceSystem(crs);
+		// // LOGGER.debug("MapContext-CRS set to: "+crs);
+		// } catch (Exception err) {
+		// LOGGER.error(
+		// "CRS could not be assigned to map context.",
+		// err);
+		// }
+		// }
+		// }
+		// });
+
+		// Solved without just with the access methods
+		// // The default is to regard a layer on selection
+		// // actions
+		// getContext().addMapLayerListListener(
+		// new MapLayerListAdapter() {
+		// @Override
+		// public void layerAdded(MapLayerListEvent e) {
+		// setMapLayerSelectable(e.getLayer(),true);
+		// }
+		// @Override
+		// public void layerRemoved(MapLayerListEvent e) {
+		// // remove reference to layer
+		// mapLayerSelectable.remove(e.getLayer());
+		// }
+		// });
 		/**
 		 * Adding the #selectionMapPaneMouseListener  
 		 */
@@ -541,41 +595,11 @@
 	}
 
 	/**
-	 * Setzt den Modus fuer Window-Selektion. Default ist {@link #ZOOM_IN}.
-	 * 
-	 * 
-	 * <ul>
-	 * <li>{@link #ZOOM_IN}: Zoom auf selektierten Bereich</li>
-	 * <li>{@link #SELECT_TOP}: Auswahl der Features im selektierten Bereich des
-	 * <b>obersten</b> (sichtbaren) Layers</li>
-	 * <li>{@link #SELECT_ALL} Auswahl der Features im selektierten ueber alle
-	 * Layer</li>
-	 * <li>{@link #NONE} Nichts machen</li>
-	 * </ul>
-	 * 
 	 * @param state
 	 *            Modus fuer Window-Selektion
 	 */
 	public void setState(final int state) {
-
-		// if (newSelState != NONE && newSelState != ZOOM_IN
-		// && newSelState != SELECT_TOP && newSelState != SELECT_ALL
-		// && newSelState != SELECT_ONE_FROM_TOP)
-		// throw new IllegalArgumentException(
-		// "Unknown selection state for window selection: "+newSelState);
-
-		// // Den selTracker bei Wechsel zu NONE deaktivieren (SK), damit
-		// // Selektionsfenster beim Draggen nicht mehr gezeichnet wird
-		// if ((state == NONE) && (getState() != NONE)) {
-		// this.removeMouseListener(selTracker);
-		// } else
-		// // Den selTracker bei Wechsel von NONE aktivieren (SK)
-		// if ((state != NONE) && (getState() == NONE)) {
-		// this.addMouseListener(selTracker);
-		// }
-		//		
 		selectMapPaneMouseListener.setEnabled((state == SELECT_ALL || state == SELECT_ONE_FROM_TOP || state == SELECT_TOP));
-
 		super.setState(state);
 	}
 
@@ -675,17 +699,6 @@
 	 */
 	public boolean featureLayerIntersectsEnvelope(MapLayer layer, Envelope env) {
 		try {
-			// // BB umrechnen von Map-CRS in Layer-CRS
-			// Envelope env_LayerCRS = JTSUtil.transformEnvelope(env,
-			// getContext()
-			// .getCoordinateReferenceSystem(), layer.getFeatureSource()
-			// .getSchema().getDefaultGeometry().getCoordinateSystem());
-			// GeometryFilterImpl filter =
-			// createBoundingBoxFilter(env_LayerCRS);
-			// Expression geometry = ff.createAttributeExpression(layer
-			// .getFeatureSource().getSchema().getDefaultGeometry()
-			// .getLocalName());
-			// filter.setExpression1(geometry);
 			FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>) layer
 					.getFeatureSource();
 			GeometryFilterImpl filter = new BoundingBoxFilterGenerator(env,
@@ -773,11 +786,7 @@
 				LOGGER.error("Looking for features:", err);
 			}
 
-			// for ( FeatureCollection fc1 : result.values() )
-			// LOGGER.debug("A  "+fc1+"    "+fc1.isEmpty());
 		}
-		// for ( FeatureCollection fc1 : result.values() )
-		// LOGGER.debug("B   "+fc1+"    "+fc1.isEmpty());
 
 		return result;
 	}
@@ -822,21 +831,6 @@
 					.getWrappedGeoObject((FeatureSource<SimpleFeatureType, SimpleFeature>) layer
 							.getFeatureSource());
 
-			// LOGGER.info("layerObj = "+layerObj.getClass().getSimpleName());
-
-			// SK 29.9.2007 Vorher:
-			// // Bei einem Nicht-Raster-Layer, das den Punkt beinhaltet,
-			// abbrechen, wenn nur im
-			// // obersten (sichtbaren) Layer gesucht wird.
-			// // Ansonsten Nicht-Raster-Layer einfach uebergehen.
-			// if ( !(layerObj instanceof GridCoverage2D) ) {
-			// if ( mode == SELECT_TOP &&
-			// featureLayerIntersectsEnvelope(layer,new
-			// Envelope(point.getX(),point.getX(),point.getY(),point.getY())) )
-			// break;
-			// continue;
-			// }
-
 			// Bei einem Nicht-Raster-Layer, das den Punkt beinhaltet,
 			// abbrechen, wenn nur im
 			// obersten (sichtbaren) Layer gesucht wird.
@@ -881,8 +875,6 @@
 				sourceGrid = (GridCoverage2D) layerObj;
 			}
 
-			// vorher: double[] value = new double[2];
-
 			// getNumSampleDimensions gibt die Anzahl der Baender des Rasters
 			// zurueck.
 			double[] values = new double[sourceGrid.getNumSampleDimensions()];
@@ -898,10 +890,6 @@
 				continue;
 			}
 
-			// SK: voher wurde nur der erste Wert zurueckgegeben
-			// result.put(layer,value[0]);
-			// jetzt werden alle werte zueuckgegeben
-
 			result.put(layer, values);
 			// Beim Modus "oberstes Layer selektieren" die Schleife beenden
 			if (mode == SELECT_TOP)
@@ -1045,10 +1033,6 @@
 			com.vividsolutions.jts.geom.Envelope jtsEnv = env;
 			org.geotools.geometry.Envelope2D gtEnv2D = JTS.getEnvelope2D(
 					jtsEnv, sourceGrid.getCoordinateReferenceSystem());
-			// org.opengis.spatialschema.geometry.Envelope gtGenEnv = new
-			// GeneralEnvelope
-			// ((org.opengis.spatialschema.geometry.Envelope)gtEnv2D); //
-			// gt2-2.3.4
 			org.opengis.geometry.Envelope gtGenEnv = new GeneralEnvelope(
 					(org.opengis.geometry.Envelope) gtEnv2D); // gt2-2.4.2
 
@@ -1113,7 +1097,6 @@
 		Hashtable<MapLayer, FeatureCollection<SimpleFeatureType, SimpleFeature>> result = new Hashtable<MapLayer, FeatureCollection<SimpleFeatureType, SimpleFeature>>();
 		if (filterGenerator == null)
 			throw new IllegalArgumentException("filterGenerator may not be null");
-//			return result;
 
 		// Je nach Modus: Alle oder nur das oberste Layer
 		MapContext context = getContext();
@@ -1142,8 +1125,6 @@
 					break;
 				continue;
 			}
-//			ReferencedEnvelope re;
-//			re.inter
 
 			// Filter an Layer koppeln
 			// WICHTIG: Dies darf erst geschehen, NACHDEM das
@@ -1197,21 +1178,13 @@
 			} catch (IOException err) {
 				LOGGER.error("applying the distanceWithin filter", err);
 			}
-
-			// for ( FeatureCollection fc1 : result.values() )
-			// LOGGER.debug("A  "+fc1+"    "+fc1.isEmpty());
 		}
-		// for ( FeatureCollection fc1 : result.values() )
-		// LOGGER.debug("B   "+fc1+"    "+fc1.isEmpty());
-
 		return result;
 	}
 	
 	@Override
 	public void mouseDragged(Point startPos, Point lastPos, MouseEvent event) {
-		
 		super.mouseDragged(startPos, lastPos, event);
-		
 	}
 
 	/**
@@ -1244,14 +1217,8 @@
 	}
 
 	/**
-	 * Prueft, ob es sich bei einem Layer um ein Raster-Layer handelt.
-	 * Raster-Layer zeichnen sich dadurch aus, dass die zugrunde liegende
-	 * {@link FeatureCollection} nur ein SimpleFeature enthaelt, das genau ein
-	 * Attribut mit dem Namen "GridCoverage" hat.
+	 * Prueft, ob es sich bei einem Layer um ein Raster-Layer handelt. VOn SK an eine GT Methode abgegeben.
 	 * 
-	 * SK: Pyramidenlayer aka AbstractGridCoverage2DReader geben auch true
-	 * zurück.
-	 * 
 	 * @param layer
 	 *            zu ueberpruefendes Layer
 	 */

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-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -1098,11 +1098,9 @@
 	 *            will be removed.
 	 * @param charset
 	 *            The charset to use for the XML, e.g. <?xml version="1.0"
-	 *            encoding="UTF-8"?>. If null, non is set, the default is used?!
+	 *            encoding="UTF-8"?>. If <code>null</code>, non is set and the
+	 *            system default is used.
 	 * 
-	 * @throws TransformerException
-	 * @throws IOException
-	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
 	 */
@@ -1120,15 +1118,14 @@
 
 		SLDTRANSFORMER.transform(exportStyle, new FileWriter(exportFile));
 
-		// LOGGER.info("Saved a Style with charset "
-		// + SLDTRANSFORMER.getEncoding().name() + " to " + exportFile);
-
 		return true;
 	}
 
 	/**
 	 * Creates a copy of the given {@link Style}, removing any
 	 * {@link FeatureTypeStyle}s that are only SELECTION related.
+	 * 
+	 * @see {@link FeatureMapLayerSelectionSynchronizer#SELECTION_STYLING_FTS_NAME}
 	 */
 	public static Style removeSelectionFeatureTypeStyle(final Style style) {
 
@@ -1139,8 +1136,14 @@
 
 		// Remove any selection-FeatureTypeStyle from the new Style
 		for (int ii = 0; ii < style.featureTypeStyles().size(); ii++) {
-			if (style.featureTypeStyles().get(ii).getName().equals(
-					FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING)) {
+
+			FeatureTypeStyle fts = style.featureTypeStyles().get(ii);
+
+			if (fts.getName() != null
+					&& fts
+							.getName()
+							.equals(
+									FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
 				cleanStyle.featureTypeStyles().remove(ii);
 				break;
 			}
@@ -1278,6 +1281,15 @@
 				final SimpleFeature feature = fcIt.next();
 
 				for (final FeatureTypeStyle fts : style.featureTypeStyles()) {
+
+					// Leave out FTSs that are selection related
+					if (fts.getName() != null
+							&& fts
+									.getName()
+									.equals(
+											FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
+						continue;
+
 					final List<Rule> rules = fts.rules();
 
 					for (final Rule rule : rules) {
@@ -1397,10 +1409,6 @@
 					for (final Rule r : fts.rules()) {
 
 						final Filter filter = r.getFilter();
-						//
-						// System.out.println(f);
-						// System.out.println(filter);
-						// System.out.println();
 
 						if (filter != null && (!filter.evaluate(f))) {
 							continue;
@@ -2285,22 +2293,22 @@
 	}
 
 	/**
-	 * Returns all {@link RasterSymbolizer} that are contained in this rule.
+	 * Returns all {@link RasterSymbolizer} that are contained in a
+	 * {@link Style}. {@link RasterSymbolizer} from {@link FeatureTypeStyle}s
+	 * that are selection related are ignored.
 	 */
 	public static List<RasterSymbolizer> getRasterSymbolizers(Style style) {
 		final List<RasterSymbolizer> rsList = new ArrayList<RasterSymbolizer>();
-		//		
-		// final DuplicatingStyleVisitor collectRSVisitor = new
-		// DuplicatingStyleVisitor() {
-		// @Override
-		// public void visit(RasterSymbolizer rs) {
-		// rsList.add(rs);
-		// };
-		// };
-		//		
-		// collectRSVisitor.visit(symb);
+		for (FeatureTypeStyle fts : style.featureTypeStyles()) {
 
-		for (FeatureTypeStyle fts : style.featureTypeStyles()) {
+			// Leave out FTSs that are selection related
+			if (fts.getName() != null
+					&& fts
+							.getName()
+							.equals(
+									FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
+				continue;
+
 			for (Rule r : fts.rules()) {
 				for (Symbolizer symb : r.getSymbolizers()) {
 					if (symb instanceof RasterSymbolizer) {

Modified: branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -32,6 +32,7 @@
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.FlowLayout;
+import java.awt.Graphics;
 import java.awt.LayoutManager;
 
 import javax.swing.BorderFactory;
@@ -137,5 +138,23 @@
         else
           c.setBackground(color);
   }
+  
 
+	/**
+	 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot
+	 * gemacht wird) wird. Dann werden wird der Hintergrund auf {@link Color#WHITE}
+	 * gesetzt.
+	 */
+	@Override
+	public void print(final Graphics g) {
+		final Color orig = getBackground();
+		setBackground(Color.WHITE, true);
+		// wrap in try/finally so that we always restore the state
+		try {
+			super.print(g);
+		} finally {
+			setBackground(orig, true);
+		}
+	}
+
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -234,212 +234,9 @@
 			throw new IllegalArgumentException("Unknown symbolizer: "
 					+ symbolizer);
 		}
-
 		return sampleShape;
 	}
-//
-//	/**
-//	 * Puts a BufferedImage into this.legendGraphic
-//	 */
-//	public void produceLegendGraphic(SimpleFeatureType featureType, Style gt2Style,
-//			Rule[] applicableRules) {
-//
-//		// final FeatureTypeStyle[] ftStyles = gt2Style.getFeatureTypeStyles();
-//
-//		// if (request.getRule() != null) {
-//		// applicableRules = new Rule[] { request.getRule() };
-//		// } else {
-//		// applicableRules = getApplicableRules(ftStyles, scaleDenominator);
-//		// }
-//
-//		final int ruleCount = applicableRules.length;
-//
-//		/**
-//		 * A legend graphic is produced for each applicable rule. They're being
-//		 * holded here until the process is done and then painted on a "stack"
-//		 * like legend.
-//		 */
-//		final List<BufferedImage> legendsStack = new ArrayList<BufferedImage>(
-//				ruleCount);
-//
-//		for (int i = 0; i < ruleCount; i++) {
-//			BufferedImage image = createImageForRule(applicableRules[i],
-//					featureType, SIZE);
-//			legendsStack.add(image);
-//		}
-//
-//		// this.legendGraphic =
-//		// scaleImage(mergeLegends(legendsStack,applicableRules), request);
-//		this.legendGraphic = mergeLegends(legendsStack, applicableRules);
-//	}
-//
-//	/**
-//	 * Recieves a list of <code>BufferedImages</code> and produces a new one
-//	 * which holds all the images in <code>imageStack</code> one above the
-//	 * other.
-//	 * 
-//	 * @param imageStack
-//	 *            the list of BufferedImages, one for each applicable Rule
-//	 * @param rules
-//	 *            The applicable rules, one for each image in the stack
-//	 * @param request
-//	 *            The request.
-//	 * 
-//	 * @return the stack image with all the images on the argument list.
-//	 * 
-//	 * @throws IllegalArgumentException
-//	 *             if the list is empty
-//	 */
-//	private static BufferedImage mergeLegends(List<BufferedImage> imageStack,
-//			Rule[] rules) {
-//		if (imageStack.size() == 0) {
-//			throw new IllegalArgumentException("No legend graphics passed");
-//		}
-//
-//		BufferedImage finalLegend = null;
-//
-//		if (imageStack.size() == 1) {
-//			finalLegend = (BufferedImage) imageStack.get(0);
-//		} else {
-//			final int imgCount = imageStack.size();
-//			final String[] labels = new String[imgCount];
-//
-//			BufferedImage img = ((BufferedImage) imageStack.get(0));
-//			FontMetrics fontMetrics = img.getGraphics().getFontMetrics();
-//
-//			final int rowHeight = Math.max(fontMetrics.getHeight(), img
-//					.getHeight());
-//
-//			// calculate the total dimensions of the image
-//			int totalHeight = rowHeight * imgCount;
-//			int totalWidth = 0;
-//
-//			for (int i = 0; i < imgCount; i++) {
-//				img = (BufferedImage) imageStack.get(i);
-//
-//				Rule rule = rules[i];
-//
-//				// does this rule have a label
-//				labels[i] = rule.getTitle();
-//
-//				if (labels[i] == null) {
-//					labels[i] = rule.getName();
-//				}
-//
-//				int w = img.getWidth();
-//
-//				if (labels[i] != null) {
-//					Graphics g = img.getGraphics();
-//					w += g.getFontMetrics().stringWidth(labels[i]);
-//				}
-//
-//				totalWidth = Math.max(w, totalWidth);
-//			}
-//
-//			// create the final image
-//			finalLegend = new BufferedImage(totalWidth, totalHeight,
-//					BufferedImage.TYPE_INT_ARGB);
-//
-//			Graphics2D finalGraphics = finalLegend.createGraphics();
-//
-//			finalGraphics.setColor(Color.white);
-//			finalGraphics.fillRect(0, 0, totalWidth, totalHeight);
-//
-//			int h = 0;
-//
-//			for (int i = 0; i < imgCount; i++) {
-//				img = (BufferedImage) imageStack.get(i);
-//
-//				// draw the image
-//				int y = h;
-//
-//				if (img.getHeight() < rowHeight) {
-//					// move the image to the center of the row
-//					y += (int) ((rowHeight - img.getHeight()) / 2d);
-//				}
-//
-//				finalGraphics.drawImage(img, 0, y, imgObs);
-//
-//				// draw the label
-//				if (labels[i] != null) {
-//					finalGraphics.setColor(Color.BLACK);
-//
-//					y = (h + rowHeight) - fontMetrics.getDescent();
-//
-//					if (fontMetrics.getHeight() < rowHeight) {
-//						// move the baseline to the center of the row
-//						y -= (int) ((rowHeight - fontMetrics.getHeight()) / 2d);
-//					}
-//
-//					finalGraphics.drawString(labels[i], img.getWidth(), y);
-//				}
-//
-//				h += rowHeight;
-//			}
-//		}
-//
-//		return finalLegend;
-//	}
-//
-//	/**
-//	 * DOCUMENT ME!
-//	 * 
-//	 * @return
-//	 * 
-//	 * @throws IllegalStateException
-//	 *             DOCUMENT ME!
-//	 */
-//	public BufferedImage getLegendGraphic() {
-//		if (this.legendGraphic == null) {
-//			throw new IllegalStateException();
-//		}
-//		return this.legendGraphic;
-//	}
-
-	// /**
-	// * Paints a little rectangle in the color defined by the
-	// * {@link ColorMapEntry}
-	// *
-	// * unused
-	// *
-	// * @param cme
-	// * {@link ColorMapEntry}
-	// * @param cm
-	// * {@link ColorMap} to determine type (VALUES, INTERVALL )
-	// * @param iconWidth
-	// * Size of the rectangle
-	// * @param iconHeight
-	// * Size of the rectangle
-	// * @return {@link ImageIcon} of that color, maybe with a white border
-	// * @author Stefan Alfons Krüger
-	// */
-	// public static ImageIcon createImageForColorMapEntry(ColorMapEntry cme,
-	// ColorMap cm, Integer iconWidth, Integer iconHeight) {
-	//
-	// BufferedImage imageForRule = new BufferedImage(iconWidth, iconHeight,
-	// BufferedImage.TYPE_INT_ARGB);
-	//
-	// final Color color = StylingUtil.getColorFromColorMapEntry(cme);
-	//
-	// // Paint a block
-	// for (int x = 0; x < iconWidth; x++) {
-	// for (int y = 0; y < iconHeight; y++) {
-	// int rgb = color.getRGB();
-	// int rand = 2;
-	//
-	// // Paint a white border if the type is VALUES
-	// if ((x < rand) || (x > iconWidth - rand) || (y < rand)
-	// || (y > iconHeight - rand)) {
-	// if (cm.getType() == ColorMap.TYPE_VALUES) {
-	// rgb = Color.white.getRGB();
-	// }
-	// }
-	// imageForRule.setRGB(x, y, rgb);
-	// }
-	// }
-	// return new ImageIcon(imageForRule);
-	// }
-
+	
 	/**
 	 * Creates a little BufferedImage that presents the Style/Symbols used by
 	 * the {@link MapLegend} to show a legend for the {@link SimpleFeatureType}

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/MapView.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -130,6 +130,7 @@
 		getSplitPane().add(newRight);
 
 		this.add(getSplitPane(), BorderLayout.CENTER);
+		
 	}
 
 	/**

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-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -31,7 +31,6 @@
 
 import java.awt.Color;
 import java.awt.Dimension;
-import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
@@ -48,11 +47,12 @@
 import java.util.Map;
 
 import javax.swing.BorderFactory;
-import javax.swing.Box;
-import javax.swing.BoxLayout;
 import javax.swing.ImageIcon;
+import javax.swing.JComponent;
 import javax.swing.JLabel;
 
+import net.miginfocom.swing.MigLayout;
+
 import org.apache.log4j.Logger;
 import org.geotools.coverage.grid.GeneralGridEnvelope;
 import org.geotools.coverage.grid.GridCoverage2D;
@@ -86,6 +86,7 @@
 import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.io.IOUtil;
 import schmitzm.lang.LangUtil;
+import schmitzm.swing.JPanel;
 import schmitzm.swing.SwingUtil;
 import skrueger.AttributeMetadata;
 import skrueger.RasterLegendData;
@@ -131,7 +132,7 @@
 	 *                if {@code null} is given as object or an error occurs
 	 *                during layer creation
 	 */
-	public static MapLayer createMapLayer(Object object) throws Exception {
+	public static MapLayer createMapLayer(final Object object) throws Exception {
 		return createMapLayer(object, null);
 	}
 
@@ -150,7 +151,7 @@
 	 *                if {@code null} is given as object or an error occurs
 	 *                during layer creation
 	 */
-	public static MapLayer createMapLayer(Object object, Style forcedStyle)
+	public static MapLayer createMapLayer(Object object, final Style forcedStyle)
 			throws Exception {
 		MapLayer layer = null;
 		Style style = null;
@@ -191,8 +192,8 @@
 	 *                if {@code null} is given as object or an error occurs
 	 *                during creation
 	 */
-	public static StyledLayerInterface<?> createStyledLayer(Object object,
-			String title) {
+	public static StyledLayerInterface<?> createStyledLayer(
+			final Object object, final String title) {
 		return createStyledLayer(object, title, null);
 	}
 
@@ -211,11 +212,12 @@
 	 *                if {@code null} is given as object or an error occurs
 	 *                during creation
 	 */
-	public static StyledLayerInterface<?> createStyledLayer(Object object,
-			String title, StyledLayerStyle style) {
+	public static StyledLayerInterface<?> createStyledLayer(
+			final Object object, final String title,
+			final StyledLayerStyle style) {
 		StyledLayerInterface<?> styledLayer = null;
 
-		String id = (title != null) ? title : "defaultID";
+		final String id = (title != null) ? title : "defaultID";
 
 		if (object instanceof GridCoverage2D)
 			styledLayer = new StyledGridCoverage((GridCoverage2D) object, id,
@@ -245,10 +247,10 @@
 	 *            returned
 	 */
 	public static AttributeMetadataMap getVisibleAttributeMetaData(
-			AttributeMetadataMap amdMap, boolean visible) {
-		
-		AttributeMetadataMap filteredMap = new AttributeMetadataMap();
-		for (AttributeMetadata amd : amdMap.values())
+			final AttributeMetadataMap amdMap, final boolean visible) {
+
+		final AttributeMetadataMap filteredMap = new AttributeMetadataMap();
+		for (final AttributeMetadata amd : amdMap.values())
 			if (amd.isVisible() == visible)
 				filteredMap.put(amd.getName(), amd);
 
@@ -264,9 +266,11 @@
 	 *            {@link Element} to parse
 	 */
 	public static AttributeMetadata parseAttributeMetaData(final Element element) {
-		final String namespace = String.valueOf(element.getAttributeValue("namespace"));
-		final String localname = String.valueOf(element.getAttributeValue("localname"));
-		final Name aName= new NameImpl(namespace,localname);
+		final String namespace = String.valueOf(element
+				.getAttributeValue("namespace"));
+		final String localname = String.valueOf(element
+				.getAttributeValue("localname"));
+		final Name aName = new NameImpl(namespace, localname);
 		final Boolean visible = Boolean.valueOf(element
 				.getAttributeValue("visible"));
 		final String unit = element.getAttributeValue("unit");
@@ -294,11 +298,11 @@
 	 */
 	public static AttributeMetadataMap parseAttributeMetaDataMap(
 			final Element element) {
-		AttributeMetadataMap metaData = new AttributeMetadataMap();
-		List<Element> attributesElements = element
+		final AttributeMetadataMap metaData = new AttributeMetadataMap();
+		final List<Element> attributesElements = element
 				.getChildren(ELEM_NAME_ATTRIBUTE);
-		for (Element attibuteElement : attributesElements) {
-			AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement);
+		for (final Element attibuteElement : attributesElements) {
+			final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement);
 			metaData.put(attrMetaData.getName(), attrMetaData);
 		}
 		return metaData;
@@ -313,7 +317,7 @@
 	 */
 	public static AttributeMetadataMap loadAttributeMetaDataMap(
 			final URL documentUrl) throws Exception {
-		Document document = SAX_BUILDER.build(documentUrl);
+		final Document document = SAX_BUILDER.build(documentUrl);
 		return parseAttributeMetaDataMap(document.getRootElement());
 	}
 
@@ -327,7 +331,8 @@
 	public static Element createAttributeMetaDataElement(
 			final AttributeMetadata amd) {
 		final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
-		element.setAttribute("namespace", String.valueOf(amd.getName().getNamespaceURI()));
+		element.setAttribute("namespace", String.valueOf(amd.getName()
+				.getNamespaceURI()));
 		element.setAttribute("localname", String.valueOf(amd.getLocalName()));
 		element.setAttribute("visible", String.valueOf(amd.isVisible()));
 		element.setAttribute("unit", amd.getUnit());
@@ -348,7 +353,7 @@
 	public static Element createAttributeMetaDataMapElement(
 			final AttributeMetadataMap amdMap) {
 		final Element element = new Element(ELEM_NAME_AMD, AMLURI);
-		for (AttributeMetadata amd : amdMap.values())
+		for (final AttributeMetadata amd : amdMap.values())
 			element.addContent(createAttributeMetaDataElement(amd));
 		return element;
 	}
@@ -379,14 +384,14 @@
 	 * @param element
 	 *            {@link Element} to parse
 	 */
-	public static RasterLegendData parseRasterLegendData(Element element) {
+	public static RasterLegendData parseRasterLegendData(final Element element) {
 
 		final boolean paintGaps = Boolean.valueOf(element
 				.getAttributeValue("paintGaps"));
 
-		RasterLegendData rld = new RasterLegendData(paintGaps);
+		final RasterLegendData rld = new RasterLegendData(paintGaps);
 
-		for (Element childElement : (List<Element>) element.getChildren()) {
+		for (final Element childElement : (List<Element>) element.getChildren()) {
 			final String name = childElement.getName();
 			// Cancel if it's an attribute
 			if (childElement.getChildren().size() == 0)
@@ -406,7 +411,7 @@
 				// id label element is missing, the translation is searched
 				// directly
 				// as childs of the rasterLegendItem element
-				Translation label = parseTranslation(labelElement != null ? labelElement
+				final Translation label = parseTranslation(labelElement != null ? labelElement
 						: childElement);
 				rld.put(value, label);
 			}
@@ -424,7 +429,7 @@
 	 */
 	public static RasterLegendData loadRasterLegendData(final URL documentUrl)
 			throws Exception {
-		Document document = SAX_BUILDER.build(documentUrl);
+		final Document document = SAX_BUILDER.build(documentUrl);
 		return parseRasterLegendData(document.getRootElement());
 	}
 
@@ -439,8 +444,8 @@
 			final RasterLegendData rld) {
 		final Element element = new Element(ELEM_NAME_RLD, AMLURI);
 		element.setAttribute("paintGaps", rld.isPaintGaps().toString());
-		for (Double key : rld.getSortedKeys()) {
-			Element item = new Element(ELEM_NAME_RASTERLEGEND, AMLURI);
+		for (final Double key : rld.getSortedKeys()) {
+			final Element item = new Element(ELEM_NAME_RASTERLEGEND, AMLURI);
 			item.setAttribute("value", key.toString());
 			item.addContent(createTranslationElement("label", rld.get(key)));
 			element.addContent(item);
@@ -460,13 +465,14 @@
 	 *            rounded to (null means no round; >= 0 means digits after
 	 *            comma; < 0 means digits before comma)
 	 */
-	public static RasterLegendData generateRasterLegendData(ColorMap colorMap,
-			boolean paintGaps, Integer digits) {
-		DecimalFormat decFormat = digits != null ? new DecimalFormat(SwingUtil
-				.getNumberFormatPattern(digits)) : null;
-		RasterLegendData rld = new RasterLegendData(paintGaps);
-		for (ColorMapEntry cme : colorMap.getColorMapEntries()) {
-			double value = StylingUtil.getQuantityFromColorMapEntry(cme);
+	public static RasterLegendData generateRasterLegendData(
+			final ColorMap colorMap, final boolean paintGaps,
+			final Integer digits) {
+		final DecimalFormat decFormat = digits != null ? new DecimalFormat(
+				SwingUtil.getNumberFormatPattern(digits)) : null;
+		final RasterLegendData rld = new RasterLegendData(paintGaps);
+		for (final ColorMapEntry cme : colorMap.getColorMapEntries()) {
+			final double value = StylingUtil.getQuantityFromColorMapEntry(cme);
 			String label = cme.getLabel();
 			// if no label is set (e.g. quantitative style),
 			// use the value as label
@@ -492,9 +498,9 @@
 	 *            rounded to (null means no round; >= 0 means digits after
 	 *            comma; < 0 means digits before comma)
 	 */
-	public static RasterLegendData generateRasterLegendData(Style style,
-			boolean paintGaps, Integer digits) {
-		ColorMap colorMap = StylingUtil.getColorMapFromStyle(style);
+	public static RasterLegendData generateRasterLegendData(final Style style,
+			final boolean paintGaps, final Integer digits) {
+		final ColorMap colorMap = StylingUtil.getColorMapFromStyle(style);
 		if (colorMap == null)
 			throw new IllegalArgumentException(
 					"Color map can not be determined from style!");
@@ -527,7 +533,7 @@
 	 *            {@link Element} to parse
 	 */
 	public final static Translation parseTranslation(final Element element) {
-		Translation trans = new Translation();
+		final Translation trans = new Translation();
 
 		if (element == null)
 			return trans;
@@ -569,9 +575,9 @@
 	 * @param translation
 	 *            Translation to store in the Element
 	 */
-	public final static Element createTranslationElement(String tagname,
-			Translation translation) {
-		Element element = new Element(tagname, AMLURI);
+	public final static Element createTranslationElement(final String tagname,
+			final Translation translation) {
+		final Element element = new Element(tagname, AMLURI);
 		if (translation == null)
 			throw new UnsupportedOperationException(
 					"Translation element can not be created from null!");
@@ -587,9 +593,9 @@
 
 		// add a <translation lang="..">..</tranlation> part to the element for
 		// all languages
-		for (String lang : translation.keySet()) {
-			Element translationElement = new Element(ELEM_NAME_TRANSLATION,
-					AMLURI);
+		for (final String lang : translation.keySet()) {
+			final Element translationElement = new Element(
+					ELEM_NAME_TRANSLATION, AMLURI);
 			translationElement.setAttribute("lang", lang);
 			String translationString = translation.get(lang);
 			if (translationString == null)
@@ -609,16 +615,18 @@
 	 * @param style
 	 *            a Style
 	 */
-	public static void setStyledLayerStyle(StyledLayerInterface styledObject,
-			StyledLayerStyle<?> style) {
+	public static void setStyledLayerStyle(
+			final StyledLayerInterface styledObject,
+			final StyledLayerStyle<?> style) {
 		// set SLD style
 		styledObject.setStyle(style.getGeoObjectStyle());
 		// set meta data
 		if (styledObject instanceof StyledGridCoverageInterface
 				&& (style.getMetaData() instanceof RasterLegendData || style
 						.getMetaData() == null)) {
-			RasterLegendData sourceRld = (RasterLegendData) style.getMetaData();
-			RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject)
+			final RasterLegendData sourceRld = (RasterLegendData) style
+					.getMetaData();
+			final RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject)
 					.getLegendMetaData();
 			if (destRld != null && sourceRld != null) {
 				destRld.setPaintGaps(sourceRld.isPaintGaps());
@@ -629,9 +637,9 @@
 		}
 		if (styledObject instanceof StyledFeatureCollectionInterface
 				&& (style.getMetaData() instanceof Map || style.getMetaData() == null)) {
-			AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style
+			final AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style
 					.getMetaData();
-			AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject)
+			final AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject)
 					.getAttributeMetaDataMap();
 			if (destAmd != null && sourceAmd != null) {
 				destAmd.clear();
@@ -661,7 +669,7 @@
 	 *         {@link StyledFeatureCollectionInterface}
 	 */
 	public static StyledLayerStyle<?> getStyledLayerStyle(
-			StyledLayerInterface styledObject) {
+			final StyledLayerInterface styledObject) {
 		if (styledObject instanceof StyledGridCoverageInterface)
 			return getStyledLayerStyle((StyledGridCoverageInterface) styledObject);
 		if (styledObject instanceof StyledFeatureCollectionInterface)
@@ -680,7 +688,7 @@
 	 *            a styled grid coverage
 	 */
 	public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(
-			StyledGridCoverageInterface styledGC) {
+			final StyledGridCoverageInterface styledGC) {
 		return new StyledLayerStyle<RasterLegendData>(styledGC.getStyle(),
 				styledGC.getLegendMetaData());
 	}
@@ -693,9 +701,9 @@
 	 *            a styled feature collection
 	 */
 	public static StyledLayerStyle<AttributeMetadataMap> getStyledLayerStyle(
-			StyledFeatureCollectionInterface styledFC) {
-		return new StyledLayerStyle<AttributeMetadataMap>(styledFC
-				.getStyle(), styledFC.getAttributeMetaDataMap());
+			final StyledFeatureCollectionInterface styledFC) {
+		return new StyledLayerStyle<AttributeMetadataMap>(styledFC.getStyle(),
+				styledFC.getAttributeMetaDataMap());
 	}
 
 	/**
@@ -712,17 +720,17 @@
 	 * @return {@code null} in case of any error
 	 */
 	public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
-			URL geoObjectURL, String sldExt, String rldExt) {
+			final URL geoObjectURL, final String sldExt, final String rldExt) {
 		RasterLegendData metaData = null;
 		Style sldStyle = null;
 		try {
-			Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
+			final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
 					geoObjectURL, sldExt));
 			// SLD must be present
 			if (styles == null || styles.length == 0)
 				return null;
 			sldStyle = styles[0];
-		} catch (Exception err) {
+		} catch (final Exception err) {
 			// SLD must be present
 			LangUtil.logDebugError(LOGGER, err);
 			return null;
@@ -731,9 +739,9 @@
 		try {
 			metaData = StyledLayerUtil.loadRasterLegendData(IOUtil
 					.changeUrlExt(geoObjectURL, rldExt));
-		} catch (FileNotFoundException err) {
+		} catch (final FileNotFoundException err) {
 			// ignore missing raster legend data
-		} catch (Exception err) {
+		} catch (final Exception err) {
 			// any other error during legend data creation leads to error
 			LangUtil.logDebugError(LOGGER, err);
 			return null;
@@ -756,7 +764,7 @@
 	 * @return {@code null} in case of any error
 	 */
 	public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
-			URL geoObjectURL) {
+			final URL geoObjectURL) {
 		return loadStyledRasterStyle(geoObjectURL, "sld", "rld");
 	}
 
@@ -774,17 +782,17 @@
 	 * @return {@code null} in case of any error
 	 */
 	public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
-			URL geoObjectURL, String sldExt, String rldExt) {
+			final URL geoObjectURL, final String sldExt, final String rldExt) {
 		AttributeMetadataMap metaData = null;
 		Style sldStyle = null;
 		try {
-			Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
+			final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
 					geoObjectURL, sldExt));
 			// SLD must be present
 			if (styles == null || styles.length == 0)
 				return null;
 			sldStyle = styles[0];
-		} catch (Exception err) {
+		} catch (final Exception err) {
 			// SLD must be present
 			LangUtil.logDebugError(LOGGER, err);
 			return null;
@@ -793,16 +801,15 @@
 		try {
 			metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil
 					.changeUrlExt(geoObjectURL, rldExt));
-		} catch (FileNotFoundException err) {
+		} catch (final FileNotFoundException err) {
 			// ignore missing attribute meta data
-		} catch (Exception err) {
+		} catch (final Exception err) {
 			// any other error during meta data creation leads to error
 			LangUtil.logDebugError(LOGGER, err);
 			return null;
 		}
 
-		return new StyledLayerStyle<AttributeMetadataMap>(sldStyle,
-				metaData);
+		return new StyledLayerStyle<AttributeMetadataMap>(sldStyle, metaData);
 	}
 
 	/**
@@ -820,7 +827,7 @@
 	 * @return {@code null} in case of any error
 	 */
 	public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
-			URL geoObjectURL) {
+			final URL geoObjectURL) {
 		return loadStyledFeatureStyle(geoObjectURL, "sld", "amd");
 	}
 
@@ -837,17 +844,18 @@
 	 * @param mdExt
 	 *            file extention for the meta-data file
 	 */
-	public static <T> void saveStyledLayerStyle(StyledLayerStyle<T> style,
-			URL geoObjectURL, String sldExt, String mdExt) throws Exception {
+	public static <T> void saveStyledLayerStyle(
+			final StyledLayerStyle<T> style, final URL geoObjectURL,
+			final String sldExt, final String mdExt) throws Exception {
 		// Store the SLD
-		Style sldStyle = style.getGeoObjectStyle();
+		final Style sldStyle = style.getGeoObjectStyle();
 		if (sldStyle != null) {
 			StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File(
 					geoObjectURL.toURI()), sldExt));
 		}
 
 		// Store the meta data
-		T metaData = style.getMetaData();
+		final T metaData = style.getMetaData();
 		if (metaData != null) {
 			if (metaData instanceof RasterLegendData) {
 				saveRasterLegendData((RasterLegendData) metaData, IOUtil
@@ -856,9 +864,8 @@
 				// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT
 				// KOMPILIERBAR!!
 			} else if (metaData instanceof Map) {
-				saveAttributeMetaDataMap(
-						(AttributeMetadataMap) metaData, IOUtil
-								.changeUrlExt(geoObjectURL, mdExt));
+				saveAttributeMetaDataMap((AttributeMetadataMap) metaData,
+						IOUtil.changeUrlExt(geoObjectURL, mdExt));
 			} else
 				throw new UnsupportedOperationException(
 						"Export for meta data not yet supported: "
@@ -876,8 +883,8 @@
 	 * @param geoObjectURL
 	 *            URL of the (already read) raster object
 	 */
-	public static void saveStyledLayerStyle(StyledLayerStyle<?> style,
-			URL geoObjectURL) throws Exception {
+	public static void saveStyledLayerStyle(final StyledLayerStyle<?> style,
+			final URL geoObjectURL) throws Exception {
 		if (style.getMetaData() instanceof RasterLegendData)
 			saveStyledLayerStyle(style, geoObjectURL, "sld", "rld");
 		else
@@ -885,7 +892,7 @@
 	}
 
 	/**
-	 * Creates a {@link Box} that shows a legend for a list of
+	 * Creates a {@link JPanel} that shows a legend for a list of
 	 * {@link FeatureTypeStyle}s and a targeted featureType
 	 * 
 	 * @param featureType
@@ -896,37 +903,24 @@
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
 	 */
-	public static Box createLegendPanel(List<FeatureTypeStyle> list,
-			SimpleFeatureType featureType, int iconWidth, int iconHeight) {
+	public static JPanel createLegendPanel(Style style,
+			final SimpleFeatureType featureType, final int iconWidth,
+			final int iconHeight) {
 
-		Box box = new Box(BoxLayout.Y_AXIS) {
+		final List<FeatureTypeStyle> list = style.featureTypeStyles();
 
-			/**
-			 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot
-			 * gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS
-			 * gesetzt.
-			 * 
-			 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
-			 *         Kr&uuml;ger</a>
-			 */
-			@Override
-			public void print(Graphics g) {
-				final Color orig = getBackground();
-				setBackground(Color.WHITE);
-				// wrap in try/finally so that we always restore the state
-				try {
-					super.print(g);
-				} finally {
-					setBackground(orig);
-				}
-			}
-		};
+		final JPanel panel = new JPanel(new MigLayout("wrap 2","[]:3:[]"));
 
-		for (FeatureTypeStyle ftStyle : list) {
+		if (style == null) {
+			// No Style => no legend
+			return panel;
+		}
 
+		for (final FeatureTypeStyle ftStyle : list) {
+
 			// One child-node for every rule
-			List<Rule> rules = ftStyle.rules();
-			for (Rule rule : rules) {
+			final List<Rule> rules = ftStyle.rules();
+			for (final Rule rule : rules) {
 
 				/**
 				 * Let's not create a hbox for Rules that only contain
@@ -936,154 +930,82 @@
 						.size() == rule.getSymbolizers().length)
 					continue;
 
-				Box hbox = new Box(BoxLayout.X_AXIS) {
-
-					/**
-					 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein
-					 * Screenshot gemacht wird) wird. Dann werden wird der
-					 * Hintergrund auf WEISS gesetzt.
-					 */
-					@Override
-					public void print(Graphics g) {
-						final Color orig = getBackground();
-						setBackground(Color.WHITE);
-						// wrap in try/finally so that we always restore the
-						// state
-						try {
-							super.print(g);
-						} finally {
-							setBackground(orig);
-						}
-					}
-				};
-
-				/**
-				 * The size of the legend Symbol is dependent on the size of the
-				 * font.
-				 */
-				final int fontHeight = new JLabel().getFontMetrics(
-						new JLabel().getFont()).getHeight();
-
-				final Dimension ICON_SIZE = new Dimension(iconWidth,
-						fontHeight > 5 ? fontHeight : iconHeight);
-
-				// ****************************************************************************
-				// Create the actual icon
-				// ****************************************************************************
 				final BufferedImage imageForRule = LegendIconFeatureRenderer
 						.getInstance().createImageForRule(rule, featureType,
-								ICON_SIZE);
+								new Dimension(iconWidth, iconHeight));
 
-				// LOGGER.debug("Creating a new Legend Image for RUle name =
-				// "+rule.getName());
+				final ImageIcon legendIcon = new ImageIcon(imageForRule);
 
-				ImageIcon legendIcon = new ImageIcon(imageForRule);
-
 				final JLabel iconLabel = new JLabel(legendIcon);
-				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));
 
-				Translation labelT = new Translation();
+				final Translation labelT = new Translation();
 				labelT.fromOneLine(rule.getDescription().getTitle());
-
 				final JLabel classTitleLabel = new JLabel(labelT.toString());
-				hbox.add(classTitleLabel);
+				
+				panel.add(classTitleLabel,"sgx2");
 				classTitleLabel.setLabelFor(iconLabel);
-
-				box.add(hbox);
-
 			}
 		}
 
-		return box;
+		return panel;
 	}
 
 	/**
-	 * Creates a
+	 * Creates a {@link JComponent} that contains a legend for a given
+	 * rasterLayer and a given {@link Style}.
 	 * 
-	 * @param styledRaster
-	 * @param iconHeight
-	 * @param iconWidth
-	 * @return
+	 * @param style
+	 *            if <code>null</code>, the default {@link Style} is extracetd
+	 *            from the {@link StyledRasterInterface}
 	 */
-	public static Box createLegendPanel(StyledRasterInterface<?> styledRaster,
-			int iconWidth, int iconHeight) {
+	public static JPanel createLegendPanel(
+			final StyledRasterInterface<?> styledRaster, Style style,
+			final int iconWidth, final int iconHeight) {
 
+		// If no style is given, we use the default style for this layer
+		if (style == null)
+			style = styledRaster.getStyle();
+
 		/**
 		 * Determine whether a Style is responsible for the coloring
 		 */
 		ColorModel colorModel = null;
 		if (!isStyleable(styledRaster)
-				|| (isStyleable(styledRaster) && styledRaster.getStyle() == null)) {
+				|| (isStyleable(styledRaster) && style == null)) {
 			colorModel = getColorModel(styledRaster);
 		}
 
-		RasterLegendData rasterLegendData = styledRaster.getLegendMetaData();
-		List<Double> legendRasterValues = rasterLegendData.getSortedKeys();
-		Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
+		final RasterLegendData rasterLegendData = styledRaster
+				.getLegendMetaData();
+		final List<Double> legendRasterValues = rasterLegendData
+				.getSortedKeys();
+		final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
 				.createSampleRasters();
 
-		Box box = new Box(BoxLayout.Y_AXIS) {
+		final JPanel panel = new JPanel(new MigLayout("wrap 2"));
 
-			/**
-			 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot
-			 * gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS
-			 * gesetzt.
-			 */
-			@Override
-			public void print(Graphics g) {
-				final Color orig = getBackground();
-				setBackground(Color.WHITE);
-				// wrap in try/finally so that we always restore the state
-				try {
-					super.print(g);
-				} finally {
-					setBackground(orig);
-				}
-			}
-		};
+		for (final Double rValue : legendRasterValues) {
 
-		for (Double rValue : legendRasterValues) {
+			// final Dimension ICON_SIZE = new Dimension(iconWidth,
+			// new JLabel().getFontMetrics(new JLabel().getFont())
+			// .getHeight() > 5 ? new JLabel().getFontMetrics(
+			// new JLabel().getFont()).getHeight() : iconHeight);
 
-			/**
-			 * 
-			 */
-			Box hbox = new Box(BoxLayout.X_AXIS) {
-
-				/**
-				 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein
-				 * Screenshot gemacht wird) wird. Dann werden wird der
-				 * Hintergrund auf WEISS gesetzt.
-				 */
-				@Override
-				public void print(Graphics g) {
-					final Color orig = getBackground();
-					setBackground(Color.WHITE);
-					// wrap in try/finally so that we always restore the
-					// state
-					try {
-						super.print(g);
-					} finally {
-						setBackground(orig);
-					}
-				}
-			};
-
-			final Dimension ICON_SIZE = new Dimension(iconWidth,
-					new JLabel().getFontMetrics(new JLabel().getFont())
-							.getHeight() > 5 ? new JLabel().getFontMetrics(
-							new JLabel().getFont()).getHeight() : iconHeight);
-
 			// ****************************************************************************
 			// Create the actual icon
 			// ****************************************************************************
-			BufferedImage buffImage = new BufferedImage(ICON_SIZE.width,
-					ICON_SIZE.height, BufferedImage.TYPE_INT_ARGB);
-			Graphics2D graphics = buffImage.createGraphics();
+			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()) {
@@ -1111,20 +1033,19 @@
 					final Color color = new Color(colorModel.getRGB(inData));
 					graphics.setBackground(color);
 					graphics.setColor(color);
-					graphics.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height);
-				} catch (Exception e) {
-					LOGGER.debug(
+					graphics.fillRect(0, 0, iconWidth, iconHeight);
+				} catch (final Exception e) {
+					LOGGER.info(
 							"Dann nehmen wir halt den GridCoverageRenderer", e);
 					colorModel = null;
 				}
-			}
+			} else {
+				// The colors come from the Style
 
-			if (colorModel == null) {
-
 				/**
 				 * The coverage contains only one value of value rValue
 				 */
-				GridCoverage2D sampleCov = sampleRasters.get(rValue);
+				final GridCoverage2D sampleCov = sampleRasters.get(rValue);
 				GridCoverageRenderer renderer;
 				try {
 					renderer = new GridCoverageRenderer(sampleCov
@@ -1132,61 +1053,47 @@
 							.createEnvelope(sampleCov.getEnvelope()),
 							new Rectangle(iconWidth, iconHeight),
 							(AffineTransform) null);
-				} catch (Exception e1) {
+				} catch (final Exception e1) {
 					throw new RuntimeException(
-							"Creating the GridCoverageRenderer:", e1);
+							"Creating a GridCoverageRenderer failed:", e1);
 				}
 
 				/**
 				 * Iterate over all FeatureTypeStyles.
 				 */
-				// for (FeatureTypeStyle ftStyle : styledGrid.getStyle()
-				// .featureTypeStyles()) {
-				// One child-node for every rule
-				// List<Rule> rules = ftStyle.rules();
-				// for (Rule rule : rules) {
-				final Style style = styledRaster.getStyle();
-				List<RasterSymbolizer> rSymbols = StylingUtil
+				final List<RasterSymbolizer> rSymbols = StylingUtil
 						.getRasterSymbolizers(style);
 
-				for (RasterSymbolizer symbolizer : rSymbols) {
-					// LOGGER.debug("Creating a new Legend Image for RUle
-					// name =
-					// "+rule.getName());
+				for (final RasterSymbolizer symbolizer : rSymbols) {
 					try {
 						renderer.paint(graphics, sampleCov, symbolizer);
-					} catch (Exception ee) {
+					} catch (final Exception ee) {
 						LOGGER.error("Unable to paint " + symbolizer
 								+ " into the legend image", ee);
 					}
-					// }
-					// }
 				}
 			}
 
-			ImageIcon legendIcon = new ImageIcon(buffImage);
+			final JLabel iconLabel = new JLabel(new ImageIcon(buffImage));
+//			hbox.setAlignmentX(0f);
+			panel.add(iconLabel,"sgx1");
+//			hbox.add(Box.createHorizontalStrut(3));
 
-			final JLabel iconLabel = new JLabel(legendIcon);
-			hbox.setAlignmentX(0f);
-			hbox.add(iconLabel);
-			hbox.add(Box.createHorizontalStrut(3));
-
-			Translation labelT = rasterLegendData.get(rValue);
+			final Translation labelT = rasterLegendData.get(rValue);
 			final JLabel classTitleLabel = new JLabel(labelT.toString());
-			hbox.add(classTitleLabel);
+			panel.add(classTitleLabel,"sgx2" + (rasterLegendData.getPaintGaps()? ", gapy 0 3":""));
 			classTitleLabel.setLabelFor(iconLabel);
 
-			box.add(hbox);
+//			box.add(hbox);
 
 			if (rasterLegendData.getPaintGaps()) {
 				iconLabel
 						.setBorder(BorderFactory.createLineBorder(Color.black));
-				box.add(Box.createVerticalStrut(3));
 			}
 
 		}
 
-		return box;
+		return panel;
 	}
 
 	/**
@@ -1194,33 +1101,34 @@
 	 * return <code>null</code> if the geoobject can not be accessed.
 	 */
 	@SuppressWarnings("unchecked")
-	public static ColorModel getColorModel(StyledRasterInterface<?> styledGrid) {
+	public static ColorModel getColorModel(
+			final StyledRasterInterface<?> styledGrid) {
 		ColorModel colorModel = null;
 		try {
-			Object geoObject = styledGrid.getGeoObject();
+			final Object geoObject = styledGrid.getGeoObject();
 			if (geoObject instanceof GridCoverage2D) {
-				GridCoverage2D cov = (GridCoverage2D) geoObject;
+				final GridCoverage2D cov = (GridCoverage2D) geoObject;
 				colorModel = cov.getRenderedImage().getColorModel();
 			} else if (styledGrid instanceof StyledRasterPyramidInterface) {
 
-				Parameter readGG = new Parameter(
+				final Parameter readGG = new Parameter(
 						AbstractGridFormat.READ_GRIDGEOMETRY2D);
 
-				ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope(
+				final ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope(
 						styledGrid.getEnvelope(), styledGrid.getCrs());
 
 				readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
 						new Rectangle(0, 0, 1, 1)), mapExtend));
 
-				FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
+				final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
 
 				final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil
 						.getWrappedGeoObject(rFc);
-				GridCoverage2D cov = (GridCoverage2D) aReader
+				final GridCoverage2D cov = (GridCoverage2D) aReader
 						.read(new GeneralParameterValue[] { readGG });
 				colorModel = cov.getRenderedImage().getColorModel();
 			}
-		} catch (Exception e) {
+		} catch (final Exception e) {
 			LOGGER.error("Error reading the colormodel from " + styledGrid, e);
 			return null;
 		}
@@ -1233,8 +1141,9 @@
 	 *         with their own {@link ColorModel} and will ignore any
 	 *         {@link RasterSymbolizer} = SLD.
 	 */
-	public static boolean isStyleable(StyledRasterInterface<?> styledRaster) {
-		ColorModel colorModel = getColorModel(styledRaster);
+	public static boolean isStyleable(
+			final StyledRasterInterface<?> styledRaster) {
+		final ColorModel colorModel = getColorModel(styledRaster);
 
 		LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
 				+ colorModel.getClass().getSimpleName());

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-11-09 18:51:54 UTC (rev 515)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-11-11 21:17:33 UTC (rev 516)
@@ -97,8 +97,15 @@
 public class FeatureMapLayerSelectionSynchronizer extends
 		StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
 		implements JMapPaneListener {
-	public static final String SELECTION_STYLING = "SELECTION";
+
 	/**
+	 * This constant is set as the {@link FeatureTypeStyle#getName()} attribute
+	 * in the {@link FeatureTypeStyle}s that only exist to present the selected
+	 * features
+	 **/
+	public static final String SELECTION_STYLING_FTS_NAME = "SELECTION";
+
+	/**
 	 * Holds the {@link MapLayer} to keep synchronized with the layer selection
 	 * model.
 	 */
@@ -189,7 +196,7 @@
 
 				for (FeatureTypeStyle fts : clone) {
 					if (fts.getName() != null
-							&& fts.getName().equals(SELECTION_STYLING)) {
+							&& fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
 						originalStyle.featureTypeStyles().remove(fts);
 
 						replaceRenderer();
@@ -218,7 +225,7 @@
 				FeatureTypeStyle selectionFTStyle = StylingUtil
 						.createSelectionStyle(styledLayer.getGeoObject());
 
-				selectionFTStyle.setName(SELECTION_STYLING);
+				selectionFTStyle.setName(SELECTION_STYLING_FTS_NAME);
 
 				/**
 				 * 
@@ -266,7 +273,7 @@
 				boolean foundAndReplaced = false;
 				for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
 					if (fts.getName() != null
-							&& fts.getName().equals(SELECTION_STYLING)) {
+							&& fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
 						foundAndReplaced = true;
 						fts.rules().clear();
 						fts.rules().addAll(selectionFTStyle.rules());
@@ -328,7 +335,7 @@
 		for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
 
 			if (fts.getName() != null
-					&& fts.getName().equals(SELECTION_STYLING)) {
+					&& fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
 
 				SELECTION_STYLING_foundInMapStyle = true;
 
@@ -394,41 +401,42 @@
 	}
 
 	/**
-	 * Replaces the local renderer 
+	 * Replaces the local renderer
 	 */
 	private void replaceRenderer() {
-//		//
-//		// // Has to be done before we apply the new Renderer
-//		// mapLayer.setStyle(style);
-//
-//		GTRenderer oldRenderer = mapPane.getLocalRenderer();
-//
-//		/**
-//		 * Explicitly putting a new instance of LabelCacheDefault into the
-//		 * renderer instance, so JMapPane doesn't reuse the old one. This is
-//		 * very useful when changing the TextSymbolizer with AtlasStyler<br/>
-//		 * SK 9.7.09: It's not enought to user LabelCache.clear(). We can not
-//		 * reuse the old Renderer - better to create a new one!
-//		 */
-//		final GTRenderer newRenderer = GTUtil.createGTRenderer();
-//
-//		final HashMap<Object, Object> rendererHints = defaultGTRenderingHints;
-//		rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY,
-//				new LabelCacheImpl());
-//
-//		newRenderer.setRendererHints(rendererHints);
-//		mapPane.setLocalRenderer(newRenderer);
-//
-//		if (oldRenderer != null) {
-//
-//			RenderingHints java2DHints = oldRenderer.getJava2DHints();
-//			if (java2DHints != null) {
-//				newRenderer.setJava2DHints(java2DHints);
-//			}
-//
-//			oldRenderer.setContext(null);
-//			oldRenderer = null;
-//		}
+		// //
+		// // // Has to be done before we apply the new Renderer
+		// // mapLayer.setStyle(style);
+		//
+		// GTRenderer oldRenderer = mapPane.getLocalRenderer();
+		//
+		// /**
+		// * Explicitly putting a new instance of LabelCacheDefault into the
+		// * renderer instance, so JMapPane doesn't reuse the old one. This is
+		// * very useful when changing the TextSymbolizer with AtlasStyler<br/>
+		// * SK 9.7.09: It's not enought to user LabelCache.clear(). We can not
+		// * reuse the old Renderer - better to create a new one!
+		// */
+		// final GTRenderer newRenderer = GTUtil.createGTRenderer();
+		//
+		// final HashMap<Object, Object> rendererHints =
+		// defaultGTRenderingHints;
+		// rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY,
+		// new LabelCacheImpl());
+		//
+		// newRenderer.setRendererHints(rendererHints);
+		// mapPane.setLocalRenderer(newRenderer);
+		//
+		// if (oldRenderer != null) {
+		//
+		// RenderingHints java2DHints = oldRenderer.getJava2DHints();
+		// if (java2DHints != null) {
+		// newRenderer.setJava2DHints(java2DHints);
+		// }
+		//
+		// oldRenderer.setContext(null);
+		// oldRenderer = null;
+		// }
 
 		mapPane.refresh();
 



More information about the Schmitzm-commits mailing list