[Schmitzm-commits] r154 - in trunk/src: schmitzm/geotools/feature schmitzm/geotools/gui schmitzm/geotools/styling skrueger/geotools skrueger/geotools/labelsearch

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jun 22 11:54:10 CEST 2009


Author: alfonx
Date: 2009-06-22 11:54:07 +0200 (Mon, 22 Jun 2009)
New Revision: 154

Added:
   trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java
Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/gui/GeoMapPane.java
   trunk/src/schmitzm/geotools/gui/JMapPane.java
   trunk/src/schmitzm/geotools/gui/LayeredEditorFrame.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/skrueger/geotools/MapView.java
   trunk/src/skrueger/geotools/labelsearch/SearchResult.java
Log:
* Results of Sunday evening hacking in Bolsena
** Rendering of big Shapefiles about 5-10 times faster now!
** Icon sizes in AtlasStyler correct again.
** Moved two functions from AtlasFramework to schmitzm

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -1136,7 +1136,37 @@
       throw new UnsupportedOperationException("No AutoValueGenerator registered for attribute type: "+aType.getLocalName());
     return avg.getNextValue();
   }
+  
 
+	/**
+	 * Creates a sample Feature instance of the given {@link FeatureType}
+	 * 
+	 * @param schema
+	 *            the schema for which to create a sample Feature instance
+	 *            
+	 * @author SK
+	 * 
+	 * @throws IllegalAttributeException
+	 * 
+	 */
+	public static Feature createSampleFeature(FeatureType schema) {
+		Feature sampleFeature;
+
+		Object[] attributes = getDefaultAttributeValues(schema);
+
+		try {
+			sampleFeature = schema.create(attributes);
+		} catch (IllegalAttributeException e) {
+			// Thrown if the FeatureType does not validate the attributes
+			// Not very likely if we just create a sample feature, so we make it
+			// a runtime exception.
+			throw new RuntimeException(e);
+		}
+
+		return sampleFeature;
+	}
+
+
 //  /**
 //   * Extrahiert alle Geometrien aus einer FeatureCollection. Fuer jedes
 //   * Geometry-Attribut der FeatureCollection wird eine GeometrieCollection

Modified: trunk/src/schmitzm/geotools/gui/GeoMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/GeoMapPane.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/schmitzm/geotools/gui/GeoMapPane.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -22,6 +22,9 @@
 import javax.swing.BorderFactory;
 
 import org.geotools.map.MapContext;
+import org.geotools.renderer.GTRenderer;
+import org.geotools.renderer.lite.StreamingRenderer;
+import org.geotools.renderer.shape.ShapefileRenderer;
 
 import schmitzm.geotools.map.event.JMapPaneEvent;
 import schmitzm.geotools.map.event.JMapPaneListener;
@@ -30,10 +33,11 @@
 import schmitzm.swing.JPanel;
 
 /**
- * Das {@code GeoMapPane} erweitert das {@link JMapPane} um einen Massstab-Balken,
- * sowie ein horizontales und vertikales Koordinaten-Raster (Grid), in dem
- * die Geo-Referenz des angezeigten Karten-Bereichs in Welt-Koordinaten (Grad, Minuten)
- * dargestellt ist.
+ * Das {@code GeoMapPane} erweitert das {@link JMapPane} um einen
+ * Massstab-Balken, sowie ein horizontales und vertikales Koordinaten-Raster
+ * (Grid), in dem die Geo-Referenz des angezeigten Karten-Bereichs in
+ * Welt-Koordinaten (Grad, Minuten) dargestellt ist.
+ * 
  * @see ScalePane
  * @see GridPanel
  * @author Martin Schmitz
@@ -41,206 +45,266 @@
  */
 public class GeoMapPane extends JPanel {
 
-  /** Konstante fuer das vertikale Koordinaten-Grid.
-  *  @see #layoutConstraints */
-  public static final String DLC_VGRID = "vertGrid";
-  /** Konstante fuer das horizontale Koordinaten-Grid.
-  *  @see #layoutConstraints */
-  public static final String DLC_HGRID = "horGrid";
-  /** Konstante fuer die Karte.
-  *  @see #layoutConstraints */
-  public static final String DLC_MAP   = "mapPane";
-  /** Konstante fuer den Massstab-Balken.
-   *  @see #layoutConstraints */
-  public static final String DLC_SCALE = "scalePane";
-  /** Werte fuer die grafische Anordnung der Layout-Komponenten.
-   *  Ueber die Konstanten {@link #DLC_MAP}, {@link #DLC_VGRID}, {@link #DLC_HGRID}
-   *  und {@link #DLC_SCALE} koennen die Constraints (am Anfang von {@link #guiInit()})
-   *  veraendert oder erweitert werden. */
-  protected HashMap<String,GridBagConstraints> layoutConstraints = new HashMap<String,GridBagConstraints>();
+	/**
+	 * Konstante fuer das vertikale Koordinaten-Grid.
+	 * 
+	 * @see #layoutConstraints
+	 */
+	public static final String DLC_VGRID = "vertGrid";
+	/**
+	 * Konstante fuer das horizontale Koordinaten-Grid.
+	 * 
+	 * @see #layoutConstraints
+	 */
+	public static final String DLC_HGRID = "horGrid";
+	/**
+	 * Konstante fuer die Karte.
+	 * 
+	 * @see #layoutConstraints
+	 */
+	public static final String DLC_MAP = "mapPane";
+	/**
+	 * Konstante fuer den Massstab-Balken.
+	 * 
+	 * @see #layoutConstraints
+	 */
+	public static final String DLC_SCALE = "scalePane";
+	/**
+	 * Werte fuer die grafische Anordnung der Layout-Komponenten. Ueber die
+	 * Konstanten {@link #DLC_MAP}, {@link #DLC_VGRID}, {@link #DLC_HGRID} und
+	 * {@link #DLC_SCALE} koennen die Constraints (am Anfang von
+	 * {@link #guiInit()}) veraendert oder erweitert werden.
+	 */
+	protected HashMap<String, GridBagConstraints> layoutConstraints = new HashMap<String, GridBagConstraints>();
 
-  /** Karten-Bereich des {@code GeoMapPane}. */
-  protected JMapPane mapPane = null;
-  /** Massstab-Balken */
-  protected ScalePane scalePane = null;
-  /** Vertikale Koordinaten-Leiste (Grid). Zeigt die Latitude-Koordinate in
-   *  Grad und Minutenm an. */
-  protected GridPanel vertGrid = null;
-  /** Horizontale Koordinaten-Leiste (Grid). Zeigt die Longitude-Koordinate in
-   *  Grad und Minutenm an. */
-  protected GridPanel horGrid = null;
+	/** Karten-Bereich des {@code GeoMapPane}. */
+	protected JMapPane mapPane = null;
+	/** Massstab-Balken */
+	protected ScalePane scalePane = null;
+	/**
+	 * Vertikale Koordinaten-Leiste (Grid). Zeigt die Latitude-Koordinate in
+	 * Grad und Minutenm an.
+	 */
+	protected GridPanel vertGrid = null;
+	/**
+	 * Horizontale Koordinaten-Leiste (Grid). Zeigt die Longitude-Koordinate in
+	 * Grad und Minutenm an.
+	 */
+	protected GridPanel horGrid = null;
 
-  /** A flag indicating if dispose() was already called. If true, then further use of this {@link GeoMapPane} is undefined.  */
-  private boolean disposed = false;
+	/**
+	 * A flag indicating if dispose() was already called. If true, then further
+	 * use of this {@link GeoMapPane} is undefined.
+	 */
+	private boolean disposed = false;
 
-  /**
-   * Erzeugt ein neues {@code GeoMapPane}.
-   */
-  public GeoMapPane() {
-    this( null, null, null, null );
-  }
+	/**
+	 * Erzeugt ein neues {@code GeoMapPane}.
+	 */
+	public GeoMapPane() {
+		this(null, null, null, null, null);
+	}
 
-  /**
-   * Erzeugt ein neues {@code GeoMapPane}. Dieser Konstruktor bietet die
-   * Moeglichkeit, alternative Implementierungen der einzelnen Komponenten
-   * darzustellen. <b>Die uebergebenen Parameter koennen {@code null} sein!
-   * In diesem Fall wird die entsprechende Standard-Implementierung verwendet.</b>
-   * @param mapPane   Karten-Bereich
-   * @param vGrid     vertikales Koordinaten-Raster
-   * @param hGrid     horizontales Koordinaten-Raster
-   * @param scalePane Massstab-Balken
-   */
-  public GeoMapPane(JMapPane mapPane, GridPanel vGrid, GridPanel hGrid, ScalePane scalePane) {
-    super();
+	/**
+	 * Erzeugt ein neues {@code GeoMapPane}. Dieser Konstruktor bietet die
+	 * Moeglichkeit, alternative Implementierungen der einzelnen Komponenten
+	 * darzustellen. <b>Die uebergebenen Parameter koennen {@code null} sein! In
+	 * diesem Fall wird die entsprechende Standard-Implementierung
+	 * verwendet.</b>
+	 * 
+	 * @param mapPane
+	 *            Karten-Bereich
+	 * @param vGrid
+	 *            vertikales Koordinaten-Raster
+	 * @param hGrid
+	 *            horizontales Koordinaten-Raster
+	 * @param scalePane
+	 *            Massstab-Balken
+	 * @param renderer
+	 *            Allows you to choose between the {@link StreamingRenderer}
+	 *            which is cool for creating PDF, SVG.. And the much faster
+	 *            {@link ShapefileRenderer}.
+	 */
+	public GeoMapPane(JMapPane mapPane, GridPanel vGrid, GridPanel hGrid,
+			ScalePane scalePane, GTRenderer renderer) {
+		super();
 
-    if ( vGrid != null && !vGrid.isVertical() )
-      throw new IllegalArgumentException("GridPanel for vertical grid must be of type GridPanel.VERTICAL!!");
-    if ( hGrid != null && !hGrid.isHorizontal() )
-      throw new IllegalArgumentException("GridPanel for horizontal grid must be of type GridPanel.HORIZONTAL!!");
+		if (vGrid != null && !vGrid.isVertical())
+			throw new IllegalArgumentException(
+					"GridPanel for vertical grid must be of type GridPanel.VERTICAL!!");
+		if (hGrid != null && !hGrid.isHorizontal())
+			throw new IllegalArgumentException(
+					"GridPanel for horizontal grid must be of type GridPanel.HORIZONTAL!!");
 
-    // Karte
-    this.mapPane =  ( mapPane   != null ) ? mapPane : new JMapPane();
-    // Koordinaten-Leisten
-    this.vertGrid = ( vGrid != null ) ? vGrid : new GridPanel( GridPanel.VERTICAL, this.mapPane );
-    this.horGrid  = ( hGrid != null ) ? hGrid : new GridPanel( GridPanel.HORIZONTAL, this.mapPane );
-    // Massstab-Balken
-    this.scalePane = ( scalePane != null ) ? scalePane : new ScalePane();
+		// Karte
+		this.mapPane = (mapPane != null) ? mapPane : new JMapPane(null,null,renderer, null);
+		// Koordinaten-Leisten
+		this.vertGrid = (vGrid != null) ? vGrid : new GridPanel(
+				GridPanel.VERTICAL, this.mapPane);
+		this.horGrid = (hGrid != null) ? hGrid : new GridPanel(
+				GridPanel.HORIZONTAL, this.mapPane);
+		// Massstab-Balken
+		this.scalePane = (scalePane != null) ? scalePane : new ScalePane();
 
-    // Standard-Werte fuer GUI-Anordnung setzen
-    layoutConstraints.put(DLC_MAP,   new GridBagConstraints(1,0,1,1,1.0,1.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0));
-    layoutConstraints.put(DLC_VGRID, new GridBagConstraints(0,0,1,1,0.0,1.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0));
-    layoutConstraints.put(DLC_HGRID, new GridBagConstraints(1,1,1,1,1.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0));
-    layoutConstraints.put(DLC_SCALE, new GridBagConstraints(1,2,1,1,0.0,0.0,GridBagConstraints.WEST,  GridBagConstraints.BOTH,new Insets(2,5,2,5),0,0));
-    // GUI initialisieren
-    guiInit();
-  }
+		// Standard-Werte fuer GUI-Anordnung setzen
+		layoutConstraints.put(DLC_MAP, new GridBagConstraints(1, 0, 1, 1, 1.0,
+				1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
+				new Insets(0, 0, 0, 0), 0, 0));
+		layoutConstraints.put(DLC_VGRID, new GridBagConstraints(0, 0, 1, 1,
+				0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
+				new Insets(0, 0, 0, 0), 0, 0));
+		layoutConstraints.put(DLC_HGRID, new GridBagConstraints(1, 1, 1, 1,
+				1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
+				new Insets(0, 0, 0, 0), 0, 0));
+		layoutConstraints.put(DLC_SCALE, new GridBagConstraints(1, 2, 1, 1,
+				0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
+				new Insets(2, 5, 2, 5), 0, 0));
+		// GUI initialisieren
+		guiInit();
+	}
 
-  /**
-   * Wird vom Konstruktor aufgerufen und initialisiert die grafische Darstellung/Anordnung
-   * der einzelnen GUI-Komponenten in einem {@link GridBagLayout}. Die Constraints
-   * fuer die Anordnung der Komponenten sind in {@link #layoutConstraints}
-   * hinterlegt und koennen zu beginn dieser Methode ueberschrieben oder erweitert
-   * werden.
-   */
-  protected void guiInit() {
-    this.setLayout( new GridBagLayout() );
+	/**
+	 * Wird vom Konstruktor aufgerufen und initialisiert die grafische
+	 * Darstellung/Anordnung der einzelnen GUI-Komponenten in einem
+	 * {@link GridBagLayout}. Die Constraints fuer die Anordnung der Komponenten
+	 * sind in {@link #layoutConstraints} hinterlegt und koennen zu beginn
+	 * dieser Methode ueberschrieben oder erweitert werden.
+	 */
+	protected void guiInit() {
+		this.setLayout(new GridBagLayout());
 
-    // Karten-Darestellung initialisieren
-    this.mapPane.setBorder(BorderFactory.createLoweredBevelBorder());
-    this.mapPane.setPreferredSize( new Dimension(200, mapPane.getPreferredSize().height) );
+		// Karten-Darestellung initialisieren
+		this.mapPane.setBorder(BorderFactory.createLoweredBevelBorder());
+		this.mapPane.setPreferredSize(new Dimension(200, mapPane
+				.getPreferredSize().height));
 
-    // MapListener that listens to Scale and MapArea changes
-    this.mapPane.addMapPaneListener(new JMapPaneListener() {
-      public void performMapPaneEvent(JMapPaneEvent e) {
-        if (e instanceof ScaleChangedEvent) {
-          ScaleChangedEvent sce = (ScaleChangedEvent) e;
-          scalePane.setScale(sce.getNewScale());
-        }
-        if (e instanceof MapAreaChangedEvent) {
-          vertGrid.repaint();
-          horGrid.repaint();
-        }
-      }
-    });
+		// MapListener that listens to Scale and MapArea changes
+		this.mapPane.addMapPaneListener(new JMapPaneListener() {
+			public void performMapPaneEvent(JMapPaneEvent e) {
+				if (e instanceof ScaleChangedEvent) {
+					ScaleChangedEvent sce = (ScaleChangedEvent) e;
+					scalePane.setScale(sce.getNewScale());
+				}
+				if (e instanceof MapAreaChangedEvent) {
+					vertGrid.repaint();
+					horGrid.repaint();
+				}
+			}
+		});
 
-    // Komponenten in Layout anordnen
-    this.add(vertGrid,  layoutConstraints.get(DLC_VGRID));
-    this.add(horGrid,   layoutConstraints.get(DLC_HGRID));
-    this.add(scalePane, layoutConstraints.get(DLC_SCALE));
-    // WICHTIG: mapPane als LETZTES einfuegen, damit es beim Re-Paint ALS ERSTES
-    //          aktualisiert wird und die Aenderungen (Area, Scale) im
-    //          Update des Massstab-Balken und der der Koordinaten-Leiste
-    //          bereits zur Verfuegung stehen!
-    this.add(mapPane,   layoutConstraints.get(DLC_MAP));
+		// Komponenten in Layout anordnen
+		this.add(vertGrid, layoutConstraints.get(DLC_VGRID));
+		this.add(horGrid, layoutConstraints.get(DLC_HGRID));
+		this.add(scalePane, layoutConstraints.get(DLC_SCALE));
+		// WICHTIG: mapPane als LETZTES einfuegen, damit es beim Re-Paint ALS
+		// ERSTES
+		// aktualisiert wird und die Aenderungen (Area, Scale) im
+		// Update des Massstab-Balken und der der Koordinaten-Leiste
+		// bereits zur Verfuegung stehen!
+		this.add(mapPane, layoutConstraints.get(DLC_MAP));
 
-//    // Hintergrundfarbe aller enthaltenen Komponenten auf Weiss setzen
-//    setBackground(BGCOLOR, true);
-  }
+		// // Hintergrundfarbe aller enthaltenen Komponenten auf Weiss setzen
+		// setBackground(BGCOLOR, true);
+	}
 
-  /**
-   * Aktualisiert die Karten-Darstellung.
-   * @see JMapPane#refresh()
-   */
-  public void refreshMap() {
-    mapPane.refresh();
-  }
+	/**
+	 * Aktualisiert die Karten-Darstellung.
+	 * 
+	 * @see JMapPane#refresh()
+	 */
+	public void refreshMap() {
+		mapPane.refresh();
+	}
 
-  /**
-   * Nach dem {@code super}-Aufruf, wird der Massstab neu gesetzt (und somit
-   * neu angezeigt), falls sich der Massstab der Karte geaendert hat.
-   * Dies ist ein Workaround, damit der Massstab auch beim allerersten anzeigen
-   * korrekt angezeigt wird (ohne {@link ScaleChangedEvent}).
-   */
-  public void paint(Graphics g) {
-    super.paint(g);
-    if ( scalePane.getScaleInMeters() != mapPane.getScale() && mapPane.getScale() > 0 )
-      scalePane.setScale( mapPane.getScale() );
-  }
+	/**
+	 * Nach dem {@code super}-Aufruf, wird der Massstab neu gesetzt (und somit
+	 * neu angezeigt), falls sich der Massstab der Karte geaendert hat. Dies ist
+	 * ein Workaround, damit der Massstab auch beim allerersten anzeigen korrekt
+	 * angezeigt wird (ohne {@link ScaleChangedEvent}).
+	 */
+	public void paint(Graphics g) {
+		super.paint(g);
+		if (scalePane.getScaleInMeters() != mapPane.getScale()
+				&& mapPane.getScale() > 0)
+			scalePane.setScale(mapPane.getScale());
+	}
 
-  /**
-   * Liefert das {@link JMapPane}, in dem die Karten dargestellt werden.
-   */
-  public final JMapPane getMapPane() {
-    return mapPane;
-  }
+	/**
+	 * Liefert das {@link JMapPane}, in dem die Karten dargestellt werden.
+	 */
+	public final JMapPane getMapPane() {
+		return mapPane;
+	}
 
-  /**
-   * Liefert den {@link MapContext} der die einzelnen Karten-Layer verwaltet.
-   */
-  public final MapContext getMapContext() {
-    return mapPane.getContext();
-  }
+	/**
+	 * Liefert den {@link MapContext} der die einzelnen Karten-Layer verwaltet.
+	 */
+	public final MapContext getMapContext() {
+		return mapPane.getContext();
+	}
 
-  /**
-   * Setzt die Hintergrundfarbe des kompletten {@link GeoMapPane}.
-   * @param color Hintergrundfarbe
-   */
-  public void setBackground(Color color) {
-    setBackground(color,true);
-  }
+	/**
+	 * Setzt die Hintergrundfarbe des kompletten {@link GeoMapPane}.
+	 * 
+	 * @param color
+	 *            Hintergrundfarbe
+	 */
+	public void setBackground(Color color) {
+		setBackground(color, true);
+	}
 
-  /**
-   * @return If dispose() has been called. If <code>true<(code>, further use of this {@link GeoMapPane} is undefined
-   *
-   *  @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
-   */
-  public boolean isDisposed() {
-	return disposed ;
-  }
+	/**
+	 * @return If dispose() has been called. If
+	 *         <code>true<(code>, further use of this {@link GeoMapPane} is undefined
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public boolean isDisposed() {
+		return disposed;
+	}
 
-  /**
-   * Should be called when the {@link GeoMapPane} is not needed no more to help the GarbageCollector
-   *
-   *  @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
-   */
-  public void dispose() {
-    if (isDisposed())
-      return;
-    mapPane.dispose();
-    removeAll();
-    disposed = true;
-  }
+	/**
+	 * Should be called when the {@link GeoMapPane} is not needed no more to
+	 * help the GarbageCollector
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public void dispose() {
+		if (isDisposed())
+			return;
+		mapPane.dispose();
+		removeAll();
+		disposed = true;
+	}
 
-//  /**
-//   * Trying to reproduce a bug #37
-//   *
-//   *  for explanation and screenshots see the xulu trac
-//   *
-//   * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
-//   */
-//  public static void main(String[] args) throws Exception {
-//	JFrame f = new JFrame();
-//	f.pack();
-//	f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
-//	GeoMapPane gmp = new GeoMapPane();
-////	FeatureCollection shape = GeoImportUtil.readFeaturesFromShapeFile( new File("/home/stefan/Desktop/AtlasData/benin_karte_UTM31/admin_boundary_benin_utm.shp") );
-//        FeatureCollection shape = GeoImportUtil.readFeaturesFromShapeFile( new File("F:\\Arbeit\\Impetus - ZFL\\Daten\\Neuer Ordner\\admin_boundary_benin_utm.shp") );
-//        gmp.getMapContext().addLayer( shape, FeatureUtil.createDefaultStyle(shape) );
-//	f.add( gmp);
-//	gmp.getMapPane().setPreferredSize( new Dimension(400,400));
-//	gmp.refreshMap();
-//	f.pack();
-//	f.setVisible(true);
-//  }
+	// /**
+	// * Trying to reproduce a bug #37
+	// *
+	// * for explanation and screenshots see the xulu trac
+	// *
+	// * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	// Kr&uuml;ger</a>
+	// */
+	// public static void main(String[] args) throws Exception {
+	// JFrame f = new JFrame();
+	// f.pack();
+	// f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
+	// GeoMapPane gmp = new GeoMapPane();
+	// // FeatureCollection shape = GeoImportUtil.readFeaturesFromShapeFile( new
+	// File("/home/stefan/Desktop/AtlasData/benin_karte_UTM31/admin_boundary_benin_utm.shp")
+	// );
+	// FeatureCollection shape = GeoImportUtil.readFeaturesFromShapeFile( new
+	// File("F:\\Arbeit\\Impetus - ZFL\\Daten\\Neuer Ordner\\admin_boundary_benin_utm.shp")
+	// );
+	// gmp.getMapContext().addLayer( shape,
+	// FeatureUtil.createDefaultStyle(shape) );
+	// f.add( gmp);
+	// gmp.getMapPane().setPreferredSize( new Dimension(400,400));
+	// gmp.refreshMap();
+	// f.pack();
+	// f.setVisible(true);
+	// }
 
 }

Modified: trunk/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -355,7 +355,7 @@
 	 * @param isDoubleBuffered
 	 *            siehe Konstruktor der
 	 *            {@linkplain org.geotools.gui.swing.JMapPane#JMapPane(LayoutManager,boolean,GTRenderer,MapContext)
-	 *            Oberklasse}
+	 *            Oberklasse}. Bei <code>null</code> wird <code>true</code> andgenommen.
 	 * @param renderer
 	 *            Renderer fuer die graphische Darestellung (z.B.
 	 *            {@link StreamingRenderer})
@@ -363,9 +363,9 @@
 	 *            Verwaltung der einzelnen Layer (z.B. {@link DefaultMapContext}
 	 *            ).
 	 */
-	public JMapPane(LayoutManager layout, boolean isDoubleBuffered,
+	public JMapPane(LayoutManager layout, Boolean isDoubleBuffered,
 			GTRenderer renderer, MapContext context) {
-		super(layout != null ? layout : new BorderLayout(), isDoubleBuffered,
+		super(layout != null ? layout : new BorderLayout(), isDoubleBuffered != null ? isDoubleBuffered : true,
 				renderer != null ? renderer : new StreamingRenderer(),
 				context != null ? context : new DefaultMapContext(GTUtil.WGS84));
 

Modified: trunk/src/schmitzm/geotools/gui/LayeredEditorFrame.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/LayeredEditorFrame.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/schmitzm/geotools/gui/LayeredEditorFrame.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -62,7 +62,7 @@
    *            {@code null} wird eine neue {@link LayeredMapPane}-Instanz erzeugt)
    */
   public LayeredEditorFrame(LayeredMapPane lmp, String title) {
-    super( lmp != null ? lmp : new LayeredMapPane(new GeoMapPane(new JEditorPane(),null,null,null)),title);
+    super( lmp != null ? lmp : new LayeredMapPane(new GeoMapPane(new JEditorPane(),null,null,null, null)),title);
     if ( !(layeredMapPane.geoMapPane.mapPane instanceof JEditorPane) )
       throw new IllegalArgumentException("LayeredMapPane must contain a JEditorPane to use in LayeredEditorFrame.");
     this.toolBar  = new JEditorToolBar( (JEditorPane)layeredMapPane.geoMapPane.mapPane );

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -12,6 +12,8 @@
 package schmitzm.geotools.styling;
 
 import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -29,6 +31,9 @@
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import javax.swing.Box;
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
 import javax.units.Unit;
 import javax.xml.transform.TransformerException;
 
@@ -46,6 +51,7 @@
 import org.geotools.factory.GeoTools;
 import org.geotools.feature.Feature;
 import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureType;
 import org.geotools.feature.GeometryAttributeType;
 import org.geotools.filter.ConstantExpression;
 import org.geotools.gui.swing.ExceptionMonitor;
@@ -92,6 +98,8 @@
 import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
 import schmitzm.geotools.grid.GridUtil;
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.LegendIconFeatureRenderer;
+import skrueger.i8n.Translation;
 
 import com.sun.xml.bind.StringInputStream;
 import com.vividsolutions.jts.geom.Geometry;
@@ -1649,7 +1657,85 @@
 		return style;
 
 	}
+	
 
+	/**
+	 * Creates a {@link Box} that shows a legend for a list of
+	 * {@link FeatureTypeStyle}s and a targeted featureType
+	 * 
+	 * @param featureType If this a legend for Point, Polygon or Line?
+	 * @param featureTypeStyles The Styles to presen in this legend
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public static Box createLegendPanel(
+			FeatureTypeStyle[] featureTypeStyles, FeatureType featureType) {
+
+		Box box = Box.createVerticalBox();
+
+		for (FeatureTypeStyle ftStyle : featureTypeStyles) {
+
+			// One child-node for every rule
+			Rule[] rules = ftStyle.getRules();
+			for (Rule rule : rules) {
+
+				/**
+				 * Let's not create a hbox for Rules that only contain
+				 * TextSymbolizers
+				 */
+				if (StylingUtil.getTextSymbolizers(rule.getSymbolizers())
+						.size() == rule.getSymbolizers().length)
+					continue;
+
+				Box hbox = Box.createHorizontalBox();
+
+				/**
+				 * 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(23, fontHeight > 5 ? fontHeight : 5);
+
+
+				// ****************************************************************************
+				// Create the actual icon
+				// ****************************************************************************
+				final BufferedImage imageForRule = LegendIconFeatureRenderer
+						.getInstance().createImageForRule(rule, featureType,
+								ICON_SIZE);
+
+				// LOGGER.debug("Creating a new Legend Image for RUle name =
+				// "+rule.getName());
+
+				ImageIcon legendIcon = new ImageIcon(imageForRule);
+
+				final JLabel iconLabel = new JLabel(legendIcon);
+				hbox.setAlignmentX(0f);
+				hbox.add(iconLabel);
+				hbox.add(Box.createHorizontalStrut(3));
+
+				// ****************************************************************************
+				// The labeltext is read from the SLD. Its either the title
+				// directly, or interpreted as OneLine Code
+				// ****************************************************************************
+				final String rawText = rule.getTitle();
+
+				Translation labelT = new Translation();
+				labelT.fromOneLine(rawText);
+
+				final JLabel classTitleLabel = new JLabel(labelT.toString());
+				hbox.add(classTitleLabel);
+				classTitleLabel.setLabelFor(iconLabel); // Whatever it is good for
+
+				box.add(hbox);
+
+			}
+		}
+
+		return box;
+	}
+
+
 	//
 	// /**
 	// * Doubles the number of palettes by adding the reverse palette to every

Added: trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java
===================================================================
--- trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -0,0 +1,549 @@
+/** 
+ Copyright 2008 Stefan Alfons Krüger and parts from some Geotools code  
+ 
+ atlas-framework - This file is part of the Atlas Framework
+
+ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+ Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+ Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+ Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+package skrueger.geotools;
+
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.awt.image.ImageObserver;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import org.apache.log4j.Logger;
+import org.geotools.factory.GeoTools;
+import org.geotools.factory.Hints;
+import org.geotools.feature.AttributeType;
+import org.geotools.feature.Feature;
+import org.geotools.feature.FeatureType;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.geometry.jts.LiteShape2;
+import org.geotools.renderer.lite.StyledShapePainter;
+import org.geotools.renderer.style.SLDStyleFactory;
+import org.geotools.renderer.style.Style2D;
+import org.geotools.styling.LineSymbolizer;
+import org.geotools.styling.PointSymbolizer;
+import org.geotools.styling.PolygonSymbolizer;
+import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.Rule;
+import org.geotools.styling.Style;
+import org.geotools.styling.Symbolizer;
+import org.geotools.styling.TextSymbolizer;
+import org.geotools.util.NumberRange;
+
+import schmitzm.geotools.feature.FeatureUtil;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.Polygon;
+
+/**
+ * Based on geoserver!
+ * <hr>
+ * <b>Changes by <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a></b>
+ * <br>
+ * <ul>
+ * <li>07.02.2008:<br>
+ * Determining the default values of a {@link FeatureType} by
+ * {@link FeatureUtil#getDefaultAttributeValues(FeatureType)} instead of using
+ * {@link AttributeType#createDefaultValue()} directly, because the latter
+ * returns {@code null} even though the attribut is not nillable.</li>
+ * </ul>
+ * 
+ * @author Stefan Alfons Krüger
+ */
+public class LegendIconFeatureRenderer extends DefaultTreeCellRenderer {
+	private static final Dimension SIZE = new Dimension(30,20);
+
+	Logger LOGGER = Logger.getLogger(LegendIconFeatureRenderer.class);
+
+	/**
+	 * This is a static class
+	 */
+	private LegendIconFeatureRenderer() {
+	}
+
+	final static LegendIconFeatureRenderer instance = new LegendIconFeatureRenderer();
+
+	public static LegendIconFeatureRenderer getInstance() {
+		// In GT 2.4.5 it we have to create a new one all the time!
+		return new LegendIconFeatureRenderer();
+//		 return instance;
+	}
+
+	/** The image produced at <code>produceLegendGraphic</code> */
+	private BufferedImage legendGraphic;
+
+	/**
+	 * used to create sample point shapes with LiteShape (not lines nor
+	 * polygons)
+	 */
+	private static final GeometryFactory geomFac = new GeometryFactory();
+
+	/** padding percentage factor at both sides of the legend. */
+	private static final float hpaddingFactor = 0.11f; // was 0.15
+
+	/** top & bottom padding percentage factor for the legend */
+	private static final float vpaddingFactor = 0.08f; // was 0.15
+
+	/**
+	 * Image observer to help in creating the stack like legend graphic from the
+	 * images created for each rule
+	 */
+	private static final ImageObserver imgObs = new Canvas();
+
+	/**
+	 * Just a holder to avoid creating many polygon shapes from inside
+	 * <code>getSampleShape()</code>
+	 */
+	private LiteShape2 sampleRect;
+
+	/**
+	 * Just a holder to avoid creating many line shapes from inside
+	 * <code>getSampleShape()</code>
+	 */
+	private LiteShape2 sampleLine;
+
+	/**
+	 * Just a holder to avoid creating many point shapes from inside
+	 * <code>getSampleShape()</code>
+	 */
+	private LiteShape2 samplePoint;
+
+	private Hints hints;
+
+	/**
+	 * Returns a <code>java.awt.Shape</code> appropiate to render a legend
+	 * graphic given the symbolizer type and the legend dimensions.
+	 * 
+	 * @param symbolizer
+	 *            the Symbolizer for whose type a sample shape will be created
+	 * @param legendWidth
+	 *            the requested width, in output units, of the legend graphic
+	 * @param legendHeight
+	 *            the requested height, in output units, of the legend graphic
+	 * 
+	 * @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the
+	 *         symbolizer, wether it is a LineSymbolizer, a PolygonSymbolizer,
+	 *         or a Point ot Text Symbolizer
+	 * 
+	 * @throws IllegalArgumentException
+	 *             if an unknown symbolizer impl was passed in.
+	 */
+	private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth,
+			int legendHeight) {
+		LiteShape2 sampleShape;
+		final float hpad = (legendWidth * hpaddingFactor);
+		final float vpad = (legendHeight * vpaddingFactor);
+
+		if (symbolizer instanceof LineSymbolizer) {
+			if (this.sampleLine == null) {
+				Coordinate[] coords = {
+						new Coordinate(hpad, legendHeight - vpad),
+						new Coordinate(legendWidth - hpad, vpad) };
+				LineString geom = geomFac.createLineString(coords);
+
+				try {
+					this.sampleLine = new LiteShape2(geom, null, null, false);
+				} catch (Exception e) {
+					this.sampleLine = null;
+				}
+			}
+
+			sampleShape = this.sampleLine;
+		} else if ((symbolizer instanceof PolygonSymbolizer)
+				|| (symbolizer instanceof RasterSymbolizer)) {
+			if (this.sampleRect == null) {
+				final float w = legendWidth - (2 * hpad);
+				final float h = legendHeight - (2 * vpad);
+
+				Coordinate[] coords = { new Coordinate(hpad, vpad),
+						new Coordinate(hpad, vpad + h),
+						new Coordinate(hpad + w, vpad + h),
+						new Coordinate(hpad + w, vpad),
+						new Coordinate(hpad, vpad) };
+				LinearRing shell = geomFac.createLinearRing(coords);
+				Polygon geom = geomFac.createPolygon(shell, null);
+
+				try {
+					this.sampleRect = new LiteShape2(geom, null, null, false);
+				} catch (Exception e) {
+					this.sampleRect = null;
+				}
+			}
+
+			sampleShape = this.sampleRect;
+		} else if (symbolizer instanceof PointSymbolizer
+				|| symbolizer instanceof TextSymbolizer) {
+			if (this.samplePoint == null) {
+				Coordinate coord = new Coordinate(legendWidth / 2,
+						legendHeight / 2);
+
+				try {
+					this.samplePoint = new LiteShape2(geomFac
+							.createPoint(coord), null, null, false);
+				} catch (Exception e) {
+					this.samplePoint = null;
+				}
+			}
+
+			sampleShape = this.samplePoint;
+		} else {
+			throw new IllegalArgumentException("Unknown symbolizer: "
+					+ symbolizer);
+		}
+
+		return sampleShape;
+	}
+
+	/**
+	 * Puts a BufferedImage into this.legendGraphic
+	 */
+	public void produceLegendGraphic(FeatureType 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 FeatureType}
+	 * 
+	 * @param rule
+	 *            {@link Rule} that provides the text and the style to present
+	 * @param featureType
+	 *            Schema that describes the kind of the sample {@link Feature}
+	 *            that will be rendered with the {@link Style}
+	 * @param bg
+	 *            Background {@link Color} or <code>null</code>
+	 * 
+	 * @throws IllegalAttributeException
+	 */
+	public BufferedImage createImageForRule(Rule rule, FeatureType featureType,
+			Dimension size, Color bg) {
+
+		Symbolizer[] symbolizers = rule.getSymbolizers();
+
+		BufferedImage buffImage = new BufferedImage(size.width, size.height,
+				BufferedImage.TYPE_INT_ARGB);
+		Graphics2D graphics = buffImage.createGraphics();
+
+		if (bg != null) {
+			// ****************************************************************************
+			// The following lines define the backgroup color for the rendered
+			// images
+			// ****************************************************************************
+			graphics.setBackground(bg);
+			graphics.setColor(bg);
+			graphics.fillRect(0, 0, size.width, size.height);
+		}
+
+		// Enable anti-aliasing for the legend symbols
+		graphics.setRenderingHints(getHints());
+
+		// TODO scaleDenominator = 100000000000000000000000000000d; Was ist das
+		// fuer ein Quatsch?
+		final double scaleDenominator = 100000000000000000000000000000d;
+		final NumberRange scaleRange = new NumberRange(scaleDenominator,
+				scaleDenominator);
+
+		try {
+
+			for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
+				Symbolizer symbolizer = symbolizers[sIdx];
+
+				if (symbolizer instanceof TextSymbolizer) {
+					LOGGER
+							.warn("createImageForRule for a TextSymbolizer. Sure we want that?");
+					continue;
+				}
+
+				// if (symbolizer instanceof RasterSymbolizer) {
+				// log.warn("createImageForRule method can't be used for
+				// RasterSymbolizers..");
+				// }
+				// else
+				final Feature sampleFeature = FeatureUtil.createSampleFeature(featureType);
+
+				// The SLDStyleFactory has to be recreated, as it seams to cache
+				// some stuff.
+				SLDStyleFactory sldStyleFactory = new SLDStyleFactory();
+				Style2D style2d = sldStyleFactory.createStyle(sampleFeature,
+						symbolizer, scaleRange);
+
+				LiteShape2 shape = getSampleShape(symbolizer, size.width,
+						size.height);
+
+				if (style2d != null) {
+					new StyledShapePainter(null).paint(graphics, shape,
+							style2d, scaleDenominator);
+				}
+			}
+		} catch (Exception e) {
+			LOGGER
+					.error(
+							"Error during createImageForRule, returning empty Image",
+							e);
+		}
+		return buffImage;
+	}
+
+	/**
+	 * Define Java2D and other Hints
+	 * 
+	 * @param hints
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public void setHints(Hints hints) {
+		getHints().add(hints);
+	}
+
+	private Hints getHints() {
+		if (hints == null) {
+			hints = GeoTools.getDefaultHints();
+			hints.put(RenderingHints.KEY_ANTIALIASING,
+					RenderingHints.VALUE_ANTIALIAS_ON);
+			hints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
+					RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
+			hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
+					RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+			hints.put(RenderingHints.KEY_RENDERING,
+					RenderingHints.VALUE_RENDER_QUALITY);
+			hints.put(RenderingHints.KEY_COLOR_RENDERING,
+					RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+		}
+		return hints;
+	}
+
+	/**
+	 * Creates a little BufferedImage that presents the Style/Symbols used by
+	 * the {@link MapLegend} to show a legend for the {@link FeatureType}
+	 * 
+	 * @param rule
+	 *            {@link Rule} that provides the text and the style to present
+	 * @param featureType
+	 *            Schema that describes the kind of the sample {@link Feature}
+	 *            that will be rendered with the {@link Style}
+	 * 
+	 * @throws IllegalAttributeException
+	 */
+	// TODO Keine Ex, sondern default bild
+	public BufferedImage createImageForRule(final Rule rule,
+			final FeatureType featureType, final Dimension size) {
+		return createImageForRule(rule, featureType, size, null);
+	}
+
+}

Modified: trunk/src/skrueger/geotools/MapView.java
===================================================================
--- trunk/src/skrueger/geotools/MapView.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/skrueger/geotools/MapView.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -9,6 +9,7 @@
 import javax.swing.JSplitPane;
 
 import org.apache.log4j.Logger;
+import org.geotools.renderer.shape.ShapefileRenderer;
 
 import schmitzm.geotools.gui.GeoMapPane;
 import schmitzm.geotools.gui.JMapPane;
@@ -30,9 +31,19 @@
 	
 	/**
 	 * Komponente, in der die Karten, der Massstab und das Koordinaten-Raster
-	 * dargestellt werden
+	 * dargestellt werden. 
 	 */
-	protected final GeoMapPane geoMapPane = new GeoMapPane();
+	
+	/**
+	 * SK: 21.6.09: ShapeFileRenderer is supposed to be about 5x faster on
+	 * ShapeFiles. The ShapeFileRenderer falls back to the
+	 * StreamingRenderer.
+	 */
+	// Old code:
+	//	protected final GeoMapPane geoMapPane = new GeoMapPane(null,null,null,null, new StreamingRenderer());
+	
+	// New Code uses Streaming renderer.
+	protected final GeoMapPane geoMapPane = new GeoMapPane(null,null,null,null, new ShapefileRenderer());
 
 	private MapPaneToolBar jToolBar;
 
@@ -68,14 +79,13 @@
 	 */
 	public void initialize() {
 		// horizontales SplitPane initialisieren
-// SK 19.6.09: Removed because we are not using it. Probably a test. 
-//		// Status-Zeile
-//		statusBar = new MapPaneStatusBar(getGeoMapPane()
-//				.getMapPane());
-//		statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory
-//				.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,
-//				5, 2, 5)));
-//		this.add(statusBar, BorderLayout.SOUTH);
+		// Status-Line to show Coordinates and Rastervalues.
+		statusBar = new MapPaneStatusBar(getGeoMapPane()
+				.getMapPane());
+		statusBar.setBorder(BorderFactory.createCompoundBorder(BorderFactory
+				.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(2,
+				5, 2, 5)));
+		this.add(statusBar, BorderLayout.SOUTH);
 
 		splitPane.setDividerLocation(-1);
 		splitPane.setDividerSize(5);

Modified: trunk/src/skrueger/geotools/labelsearch/SearchResult.java
===================================================================
--- trunk/src/skrueger/geotools/labelsearch/SearchResult.java	2009-06-20 12:48:24 UTC (rev 153)
+++ trunk/src/skrueger/geotools/labelsearch/SearchResult.java	2009-06-22 09:54:07 UTC (rev 154)
@@ -1,5 +1,6 @@
 package skrueger.geotools.labelsearch;
 
+import java.util.Map;
 import org.geotools.feature.Feature;
 
 public interface SearchResult {



More information about the Schmitzm-commits mailing list