/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
ViewVC logotype

Annotation of /branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 578 - (hide annotations)
Wed Nov 25 14:43:57 2009 UTC (15 years, 3 months ago) by alfonx
File size: 71670 byte(s)
SwitchLanguageDialog now it's itself to visible or diasoss itself if not needed
RasterlegendData not implements Copyable
StylingUtil createLegendPanel manages the gaps better
1 alfonx 531 package skrueger.geotools;
2 mojays 2
3     import java.awt.Color;
4     import java.awt.Cursor;
5 alfonx 509 import java.awt.Font;
6 mojays 2 import java.awt.Graphics;
7     import java.awt.Graphics2D;
8 alfonx 509 import java.awt.Image;
9     import java.awt.Point;
10 mojays 2 import java.awt.Rectangle;
11 alfonx 505 import java.awt.RenderingHints;
12 alfonx 509 import java.awt.event.ActionEvent;
13     import java.awt.event.ActionListener;
14     import java.awt.event.ComponentAdapter;
15     import java.awt.event.ComponentEvent;
16 mojays 2 import java.awt.event.InputEvent;
17     import java.awt.event.MouseEvent;
18     import java.awt.event.MouseListener;
19 alfonx 505 import java.awt.geom.AffineTransform;
20 alfonx 509 import java.awt.geom.NoninvertibleTransformException;
21     import java.awt.geom.Point2D;
22 mojays 2 import java.awt.image.BufferedImage;
23     import java.io.IOException;
24 alfonx 533 import java.util.ArrayList;
25 mojays 2 import java.util.HashMap;
26     import java.util.Map;
27 alfonx 509 import java.util.Vector;
28 mojays 2
29 alfonx 560 import javax.jws.soap.SOAPBinding.Style;
30 alfonx 509 import javax.swing.Timer;
31 mojays 561 import javax.swing.border.Border;
32 mojays 2
33     import org.apache.log4j.Logger;
34 alfonx 509 import org.geotools.feature.FeatureCollection;
35     import org.geotools.geometry.jts.JTS;
36     import org.geotools.geometry.jts.ReferencedEnvelope;
37     import org.geotools.map.DefaultMapContext;
38 mojays 2 import org.geotools.map.MapContext;
39 alfonx 509 import org.geotools.map.MapLayer;
40     import org.geotools.map.event.MapLayerEvent;
41 mojays 2 import org.geotools.map.event.MapLayerListEvent;
42     import org.geotools.map.event.MapLayerListListener;
43 alfonx 509 import org.geotools.map.event.MapLayerListener;
44     import org.geotools.referencing.CRS;
45 mojays 2 import org.geotools.renderer.GTRenderer;
46 alfonx 336 import org.geotools.renderer.label.LabelCacheImpl;
47 mojays 2 import org.geotools.renderer.lite.LabelCache;
48 alfonx 539 import org.geotools.renderer.lite.RendererUtilities;
49 alfonx 529 import org.geotools.renderer.lite.StreamingRenderer;
50 alfonx 509 import org.geotools.swing.JMapPane;
51     import org.geotools.swing.event.MapMouseEvent;
52     import org.geotools.swing.event.MapPaneEvent;
53     import org.geotools.swing.event.MapPaneListener;
54     import org.opengis.feature.simple.SimpleFeature;
55     import org.opengis.feature.simple.SimpleFeatureType;
56     import org.opengis.referencing.FactoryException;
57 mojays 2 import org.opengis.referencing.crs.CoordinateReferenceSystem;
58 alfonx 509 import org.opengis.referencing.operation.MathTransform;
59     import org.opengis.referencing.operation.TransformException;
60 mojays 2
61 alfonx 509 import schmitzm.geotools.GTUtil;
62 mojays 436 import schmitzm.geotools.JTSUtil;
63 alfonx 509 import schmitzm.geotools.gui.SelectableXMapPane;
64 alfonx 533 import schmitzm.geotools.io.GeoImportUtil;
65 alfonx 509 import schmitzm.geotools.map.event.JMapPaneListener;
66     import schmitzm.geotools.map.event.MapLayerAdapter;
67 alfonx 529 import schmitzm.lang.LangUtil;
68 alfonx 530 import schmitzm.swing.JPanel;
69 mojays 2 import schmitzm.swing.SwingUtil;
70    
71     import com.vividsolutions.jts.geom.Coordinate;
72     import com.vividsolutions.jts.geom.Envelope;
73 alfonx 509 import com.vividsolutions.jts.geom.Geometry;
74 mojays 2
75 alfonx 530 /**
76     * The {@link XMapPane} class uses a Geotools {@link GTRenderer} to paint up to
77     * two {@link MapContext}s: a "local" {@link MapContext} and a "background"
78     * {@link MapContext}. The idea is, that rendering a background layer made up of
79     * e.g. OSM data, may take much longer than rendering local data.<br>
80     * Every {@link MapContext} is rendered on a {@link Thread} of it's own.
81     * Starting/ cancelling these threads is done by the {@link RenderingExecutor}.<br>
82     * <br>
83     * While the renderers are rending the map, a <br>
84     * The {@link XMapPane} is based on schmitzm {@link JPanel}, so
85     * {@link #print(Graphics)} will automatically set the background of components
86     * to pure white.
87     *
88     * The XMapPane has a {@link MouseListener} that manages zooming.<br>
89     * A logo/icon to float in the lower left corner may be set with
90     * {@link #setMapImage(BufferedImage)}<br>
91     *
92     * @see SelectableXMapPane - an extension of {@link XMapPane} that supports
93     * selecting features.
94     *
95     * @author stefan
96     *
97     */
98 alfonx 529 public class XMapPane extends JPanel {
99 alfonx 530
100     private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
101     private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;
102    
103 alfonx 555 private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
104 alfonx 153
105 alfonx 530 private boolean acceptsRepaintCalls = true;
106    
107 alfonx 509 /**
108 alfonx 530 * Main {@link MapContext} that holds all layers that are rendered into the
109     * {@link #localImage} by the {@link #localRenderer}
110 alfonx 509 */
111 alfonx 530 MapContext localContext;
112 mojays 2
113 alfonx 509 /**
114 alfonx 530 * {@link MapContext} holding the background layers. Use it for layers that
115     * CAN take very long for rendering, like layer from the Internet: WMS, WFS,
116     * OSM...<br>
117     * <code>null</code> by default.
118     *
119     * @see #setBgContext(MapContext)
120     * @see #getBgContext()
121 alfonx 509 */
122 alfonx 530 MapContext bgContext;
123 mojays 2
124 alfonx 509 /**
125 alfonx 530 * While threads are working, calls {@link XMapPane#updateFinalImage()}
126     * regularly and {@link #repaint()}. This {@link Timer} is stopped when all
127     * renderers have finished.
128 alfonx 509 *
129 alfonx 544 * @see INITIAL_REPAINT_DELAYAL
130 alfonx 530 * @see #REPEATING_REPAINT_DELAY
131 alfonx 509 */
132 alfonx 530 final private Timer repaintTimer;
133 mojays 2
134 alfonx 509 /**
135 alfonx 530 * The initial delay in milliseconds until the {@link #finalImage} is
136     * updated the first time.
137 alfonx 509 */
138 alfonx 555 public static final int INITIAL_REPAINT_DELAY = 900;
139 alfonx 530
140 alfonx 509 /**
141 alfonx 530 * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
142     * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
143     * with previews.
144 alfonx 509 */
145 alfonx 560 public static final int REPEATING_REPAINT_DELAY = 500;
146 alfonx 530
147 alfonx 509 /**
148 alfonx 530 * Default delay (milliseconds) before the map will be redrawn when resizing
149     * the pane. This is to avoid flickering while drag-resizing.
150 alfonx 544 *
151     * @see #resizeTimer
152 alfonx 509 */
153 alfonx 539 public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
154 alfonx 530
155 alfonx 555 /**
156     * This not-repeating {@link Timer} is re-started whenever the component is
157     * resized. That means => only if the component is not resizing for
158     * {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the
159     * {@link XMapPane} react.
160     */
161 alfonx 544 private final Timer resizeTimer;
162    
163 alfonx 555 /**
164     * Flag for no-tool.
165     */
166 alfonx 530 public static final int NONE = -123;
167    
168 alfonx 509 /**
169 alfonx 530 * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
170     * moeglich!
171 alfonx 509 *
172     * @see #setState(int)
173     */
174 alfonx 530 public static final int PAN = 1;
175    
176 alfonx 509 /**
177 alfonx 555 * Flag fuer Modus "Heran zoomen".
178     *
179     * @see #setState(int)
180     * @see #setState(int)
181     */
182     public static final int ZOOM_IN = 2;
183    
184     /**
185     * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
186     *
187     * @see #setState(int)
188     */
189     public static final int ZOOM_OUT = 3;
190    
191     /**
192 alfonx 509 * Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".
193     *
194     * @see #setState(int)
195     * @see #setState(int)
196     */
197     public static final int SELECT_ALL = 103;
198     /**
199     * Flag fuer Modus
200     * "Auswahl nur eines Features, das erste sichtbare von Oben".
201     *
202     * @see #setState(int)
203     * @see #setState(int)
204     */
205     public static final int SELECT_ONE_FROM_TOP = 104;
206 alfonx 524 /**
207 alfonx 530 * Flag fuer Modus
208     * "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer".
209     *
210     * @see #setState(int)
211     * @see #setState(int)
212 alfonx 524 */
213 alfonx 530 public static final int SELECT_TOP = 4;
214 alfonx 524
215 alfonx 544 /**
216     * {@link Font} used to paint the wait messages into the map
217     *
218     * @see #addGadgets(Graphics2D, boolean)
219     */
220 alfonx 530 final static Font waitFont = new Font("Arial", Font.BOLD, 30);
221 alfonx 544
222     /**
223     * {@link Font} used to paint error messages into the map
224     *
225     * @see #addGadgets(Graphics2D, boolean)
226     */
227 alfonx 533 final static Font errorFont = new Font("Arial", Font.BOLD, 13);
228 alfonx 524
229 alfonx 144 /**
230 alfonx 544 * The wait message painted into the map while rendering is going on on
231     * another thread.
232     *
233     * @see #addGadgets(Graphics2D, boolean)
234     */
235     final String waitMsg = SwingUtil.R("WaitMess");
236    
237     /**
238 alfonx 509 * Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in
239     * Karten-Koordinaten.
240     *
241     * @param e
242     * Maus-Ereignis
243 alfonx 144 */
244 alfonx 530 public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) {
245 alfonx 509 // aktuelle Geo-Position aus GeoMouseEvent ermitteln
246     if (e != null && e instanceof MapMouseEvent)
247     try {
248     return ((MapMouseEvent) e).getMapPosition().toPoint2D();
249 alfonx 530 } catch (final Exception err) {
250 alfonx 509 LOGGER
251     .error(
252     "return ((GeoMouseEvent) e).getMapCoordinate(null).toPoint2D();",
253     err);
254     }
255 mojays 2
256 alfonx 509 // aktuelle Geo-Position ueber Transformation des JMapPane berechnen
257     if (e != null && e.getSource() instanceof XMapPane) {
258 alfonx 513
259 alfonx 509 final XMapPane xMapPane = (XMapPane) e.getSource();
260 alfonx 513
261     if (!xMapPane.isWellDefined())
262     return null;
263    
264 alfonx 530 final AffineTransform at = xMapPane.getScreenToWorld();
265 alfonx 509 if (at != null)
266     return at.transform(e.getPoint(), null);
267     return null;
268     }
269     throw new IllegalArgumentException(
270     "MouseEvent has to be of instance MapMouseEvent or come from an XMapPane");
271     }
272 mojays 2
273 alfonx 509 /**
274 alfonx 530 * Listens to changes of the "background" {@link MapContext} and triggers
275     * repaints where needed.
276     */
277     private final MapLayerListListener bgContextListener = new MapLayerListListener() {
278    
279     @Override
280     public void layerAdded(final MapLayerListEvent event) {
281 alfonx 533 MapLayer layer = event.getLayer();
282     layer.addMapLayerListener(bgMapLayerListener);
283 alfonx 530 requestStartRendering();
284    
285     }
286    
287     @Override
288     public void layerChanged(final MapLayerListEvent event) {
289     requestStartRendering();
290     }
291    
292     @Override
293     public void layerMoved(final MapLayerListEvent event) {
294     requestStartRendering();
295     }
296    
297     @Override
298     public void layerRemoved(final MapLayerListEvent event) {
299     if (event.getLayer() != null)
300     event.getLayer().removeMapLayerListener(bgMapLayerListener);
301     requestStartRendering();
302     }
303     };
304    
305     /**
306 alfonx 543 * This {@link RenderingExecutor} manages the creation and cancellation of
307     * up to one {@link Thread} for rendering the {@link #localContext}.
308 alfonx 530 */
309 alfonx 543 private final RenderingExecutor localExecuter = new RenderingExecutor(this);
310 alfonx 530
311 alfonx 543 /**
312     * This {@link RenderingExecutor} manages the creation and cancellation of
313     * up to one {@link Thread} for rendering the {@link #bgContext}.
314     */
315 alfonx 530 protected RenderingExecutor bgExecuter;
316    
317     /**
318 alfonx 543 * The {@link #localRenderer} for the {@link #localContext} uses this
319     * {@link Image}.
320 alfonx 530 */
321     private BufferedImage localImage;
322    
323     /**
324 alfonx 543 * The {@link #bgRenderer} for the {@link #bgContext} uses this
325     * {@link Image}.
326 alfonx 530 */
327     private BufferedImage bgImage;
328 alfonx 544
329 alfonx 543 /**
330     * This {@link Image} is a merge of the {@link #bgImage},
331     * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
332     * updated with {@link #updateFinalImage()} and used for painting in
333     * {@link #paintComponent(Graphics)}
334     */
335     private BufferedImage finalImage;
336 alfonx 530
337     /**
338     * Optionally a transparent image to paint over the map in the lower right
339     * corner.
340     *
341     * @see #addGadgets(Graphics2D)
342     * @see #setMapImage(BufferedImage)
343     **/
344     private BufferedImage mapImage = null;
345    
346     /**
347     * Listens to each layer in the local {@link MapContext} for changes and
348     * triggers repaints.
349     */
350     protected MapLayerListener bgMapLayerListener = new MapLayerAdapter() {
351    
352     @Override
353     public void layerChanged(final MapLayerEvent event) {
354     requestStartRendering();
355     }
356    
357     @Override
358     public void layerHidden(final MapLayerEvent event) {
359     requestStartRendering();
360     }
361    
362     @Override
363     public void layerShown(final MapLayerEvent event) {
364     requestStartRendering();
365     }
366     };
367    
368     /**
369     * A flag indicating if dispose() was already called. If true, then further
370     * use of this {@link SelectableXMapPane} is undefined.
371     */
372     private boolean disposed = false;
373    
374     /**
375     * While dragging, the {@link #updateFinalImage()} method is translating the
376     * cached images while setting it together.
377     **/
378     Point imageOrigin = new Point(0, 0);
379     /**
380     * For every rendering thread started,
381     * {@link GTUtil#createGTRenderer(MapContext)} is called to create a new
382     * renderer. These Java2D rendering hints are passed to the
383     * {@link GTRenderer}. The java2dHints are the same for all renderers (bg
384     * and local).
385     */
386     private RenderingHints java2dHints;
387    
388     protected LabelCache labelCache = new LabelCacheImpl();
389    
390     /**
391     * Listens to changes of the "local" {@link MapContext} and triggers
392     * repaints where needed.
393     */
394     private final MapLayerListListener localContextListener = new MapLayerListListener() {
395    
396     @Override
397     public void layerAdded(final MapLayerListEvent event) {
398     event.getLayer().addMapLayerListener(localMapLayerListener);
399    
400 alfonx 560 getLocalRenderer().setContext(getMapContext());
401 alfonx 530 requestStartRendering();
402    
403     }
404    
405     @Override
406     public void layerChanged(final MapLayerListEvent event) {
407 alfonx 578 // localRenderer = GTUtil.createGTRenderer();
408 alfonx 560 getLocalRenderer().setContext(getMapContext());
409 alfonx 530 requestStartRendering();
410     }
411    
412     @Override
413     public void layerMoved(final MapLayerListEvent event) {
414 alfonx 560 getLocalRenderer().setContext(getMapContext());
415 alfonx 530 requestStartRendering();
416     }
417    
418     @Override
419     public void layerRemoved(final MapLayerListEvent event) {
420     if (event.getLayer() != null)
421     event.getLayer().removeMapLayerListener(localMapLayerListener);
422 alfonx 560 getLocalRenderer().setContext(getMapContext());
423 alfonx 530 requestStartRendering();
424     }
425     };
426    
427     /**
428     * Listens to each layer in the local {@link MapContext} for changes and
429     * triggers repaints.
430     */
431     protected MapLayerListener localMapLayerListener = new MapLayerAdapter() {
432    
433     @Override
434     public void layerChanged(final MapLayerEvent event) {
435 alfonx 560 getLocalRenderer().setContext(getMapContext()); // betters for SLD
436 alfonx 555 // changes?!
437 alfonx 530 requestStartRendering();
438     }
439    
440     @Override
441     public void layerHidden(final MapLayerEvent event) {
442     requestStartRendering();
443     }
444    
445     @Override
446     public void layerShown(final MapLayerEvent event) {
447     requestStartRendering();
448     }
449     };
450    
451 alfonx 560 final private GTRenderer localRenderer = GTUtil.createGTRenderer();
452 alfonx 533
453 alfonx 530 private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
454    
455     /**
456     * the area of the map to draw
457     */
458     protected Envelope mapArea = null;
459    
460     /**
461     * A flag set it {@link #setMapArea(Envelope)} to indicated the
462     * {@link #paintComponent(Graphics)} method, that the image on-screen is
463     * associated with {@link #oldMapArea} and may hence be scaled for a quick
464     * preview.<br>
465     * The flag is reset
466     **/
467     private boolean mapAreaChanged = false;
468    
469     /**
470     * This color is used as the default background color when painting a map.
471     */
472 alfonx 558 private Color mapBackgroundColor = null;
473 alfonx 530
474     /**
475 alfonx 509 * A flag indicating that the shown image is invalid and needs to be
476     * re-rendered.
477     */
478     protected boolean mapImageInvalid = true;
479 mojays 2
480 alfonx 530 /**
481     * Holds a flag for each layer, whether it is regarded or ignored on
482     * {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}
483     * actions.
484     */
485     final protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();
486 mojays 2
487 alfonx 414 /**
488 alfonx 530 * List of listeners of this {@link XMapPane}
489     */
490     protected Vector<JMapPaneListener> mapPaneListeners = new Vector<JMapPaneListener>();
491     /**
492 alfonx 509 * If not <code>null</code>, the {@link XMapPane} will not allow to zoom/pan
493 alfonx 414 * out of that area
494     **/
495     private Envelope maxExtend = null;
496 alfonx 530 private Double maxZoomScale = Double.MIN_VALUE;
497 alfonx 414
498 alfonx 509 private Double minZoomScale = Double.MAX_VALUE;
499 alfonx 414
500 alfonx 509 /**
501 alfonx 530 * We store the old mapArea for a moment to use it for the
502     * "quick scaled preview" in case of ZoomOut
503     **/
504     protected Envelope oldMapArea = null;
505 mojays 2
506 alfonx 509 /**
507 alfonx 530 * We store the old transform for a moment to use it for the
508     * "quick scaled preview" in case of ZoomIn
509     **/
510     protected AffineTransform oldScreenToWorld = null;
511 mojays 2
512 alfonx 509 /**
513     * A flag indicating, that the image size has changed and the buffered
514     * images are not big enough any more
515     **/
516 alfonx 555 protected boolean paneResized = true;
517 mojays 2
518 alfonx 530 private BufferedImage preFinalImage;
519    
520 alfonx 555 // ** if 0, no quick preview will be shown **/
521 alfonx 530 private int quickPreviewHint = 0;
522    
523 alfonx 533 private Map<Object, Object> rendererHints = GTUtil
524 alfonx 560 .getDefaultGTRendererHints(getLocalRenderer());
525 alfonx 530
526 alfonx 544 /**
527     * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
528     * start rendering {@link Thread}s
529     **/
530     private volatile Boolean requestStartRendering = false;
531 alfonx 530
532 alfonx 144 /**
533 alfonx 530 * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
534     * (lat/lon)
535     */
536     protected AffineTransform screenToWorld = null;
537    
538     /**
539 alfonx 544 * The flag {@link #requestStartRendering} can be set to true by events.
540 alfonx 509 * This {@link Timer} checks the flag regularly and starts one renderer
541     * thread.
542 alfonx 505 */
543 alfonx 509 final private Timer startRenderThreadsTimer;
544 alfonx 505
545 alfonx 530 /**
546     * The default state is ZOOM_IN, hence by default the
547     * {@link #zoomMapPaneMouseListener} is also enabled.
548     **/
549     private int state = ZOOM_IN;
550 alfonx 509
551 alfonx 530 /**
552     * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
553     * MapPane-Funktion
554     */
555     protected Cursor staticCursor = null;
556 mojays 2
557 alfonx 530 private AffineTransform worldToScreen;
558    
559 alfonx 144 /**
560 alfonx 530 * This {@link MouseListener} is managing all zoom related tasks
561 alfonx 144 */
562 alfonx 530 public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(
563     this);
564 alfonx 509
565 alfonx 533 /** Is set if a renderer has an error **/
566     protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
567    
568 alfonx 555 /**
569     * If <code>true</code>, then rendering exceptions are rendererd into the
570     * map pane
571     **/
572     private boolean showExceptions = false;
573 alfonx 544
574 alfonx 530 public XMapPane() {
575     this(null, null);
576 alfonx 144 }
577 mojays 2
578 alfonx 144 /**
579     * full constructor extending JPanel
580     *
581 alfonx 509 * @param rendererHints
582 alfonx 543 * may be <code>null</code>. Otherwise a {@link Map<Object,
583     * Object>} of {@link RenderingHints} to override the default
584     * from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)}
585 alfonx 509 *
586     * @param localContext
587 alfonx 543 * The main {@link MapContext} to use. If <code>null</code>, an
588     * empty {@link DefaultMapContext} will be created.
589 alfonx 144 */
590 alfonx 529 public XMapPane(final MapContext localContext_,
591 alfonx 530 final Map<Object, Object> rendererHints) {
592 alfonx 509 super(true);
593 mojays 2
594 alfonx 509 setRendererHints(rendererHints);
595 mojays 2
596 alfonx 509 setOpaque(true);
597 mojays 2
598 alfonx 529 if (localContext_ != null)
599     setLocalContext(localContext_);
600    
601 alfonx 509 /**
602     * Adding the #zoomMapPaneMouseListener
603     */
604     this.addMouseListener(zoomMapPaneMouseListener);
605     this.addMouseMotionListener(zoomMapPaneMouseListener);
606     this.addMouseWheelListener(zoomMapPaneMouseListener);
607    
608     /*
609     * We use a Timer object to avoid rendering delays and flickering when
610     * the user is drag-resizing the parent container of this map pane.
611     *
612     * Using a ComponentListener doesn't work because, unlike a JFrame, the
613     * pane receives a stream of events during drag-resizing.
614     */
615 alfonx 543 resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY,
616     new ActionListener() {
617 alfonx 509
618 alfonx 543 public void actionPerformed(final ActionEvent e) {
619     if (!isWellDefined())
620     return;
621 alfonx 509
622 alfonx 578 // LOGGER.debug("resizeTimer performed");
623 alfonx 555
624 alfonx 543 final Rectangle bounds = getVisibleRect();
625 alfonx 544 //
626     // System.out.println("\n\ntimer performs with bounds = "
627     // + bounds);
628 alfonx 509
629 alfonx 543 final Envelope geoMapArea = tranformWindowToGeo(
630     bounds.x, bounds.y, bounds.x + bounds.width,
631     bounds.y + bounds.height);
632 alfonx 509
633 alfonx 555 if (setMapArea(geoMapArea)) {
634 alfonx 578 // LOGGER.debug(" maparea changed");
635 alfonx 544 paneResized = true;
636 alfonx 578 }
637     // else
638     // LOGGER.debug(" maparea NOT changed");
639 alfonx 543 }
640     });
641 alfonx 509 resizeTimer.setRepeats(false);
642    
643 alfonx 544 this.addComponentListener(new ComponentAdapter() {
644    
645 alfonx 555 private Rectangle oldVisibleRect;
646    
647 alfonx 544 @Override
648     public void componentResized(final ComponentEvent e) {
649    
650 alfonx 556 // Seems to be called twice with the same size..
651 alfonx 555 if (oldVisibleRect != null
652 alfonx 556 && oldVisibleRect.equals(getVisibleRect())) {
653 alfonx 578 // LOGGER.debug("skipping resize.");
654 alfonx 555 return;
655     }
656 alfonx 544
657 alfonx 578 // LOGGER.debug("resized: " + getVisibleRect());
658 alfonx 544 resizeTimer.restart();
659 alfonx 555 oldVisibleRect = getVisibleRect();
660 alfonx 544 }
661    
662     });
663    
664 alfonx 530 /*
665     * Setting up the repaintTimer. Not started automatically.
666     */
667 alfonx 544 repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() {
668 alfonx 509
669 alfonx 544 @Override
670     public void actionPerformed(final ActionEvent e) {
671 alfonx 555 if ((!localExecuter.isRunning())
672 alfonx 544 && (bgExecuter != null && !bgExecuter.isRunning())) {
673     repaintTimer.stop();
674     } else {
675     updateFinalImage();
676     XMapPane.this.repaint(100);
677 alfonx 555
678 alfonx 544 }
679     }
680     });
681 alfonx 555
682 alfonx 530 repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
683     repaintTimer.setRepeats(true);
684 alfonx 509
685 alfonx 530 /*
686     * Setting up the startRenderThreadsTimer. This Timer starts
687     * automatically.
688     */
689 alfonx 524 startRenderThreadsTimer = new Timer(100, new ActionListener() {
690    
691 alfonx 509 @Override
692 alfonx 530 public void actionPerformed(final ActionEvent e) {
693 alfonx 544 synchronized (requestStartRendering) {
694     if (requestStartRendering && isWellDefined()) {
695 alfonx 529
696     if (localExecuter.isRunning()) {
697 alfonx 524 localExecuter.cancelTask();
698     } else {
699 alfonx 544 // Stupidly, but we have to recheck the
700     setMapArea(getMapArea());
701     requestStartRendering = false;
702 alfonx 524 startRendering();
703     }
704     }
705 alfonx 509 }
706     }
707     });
708     startRenderThreadsTimer.start();
709    
710 alfonx 144 }
711 mojays 2
712 alfonx 530 /**
713     * Fuegt der Map einen Listener hinzu.
714     *
715     * @param l
716     * neuer Listener
717     */
718     public void addMapPaneListener(final JMapPaneListener l) {
719     mapPaneListeners.add(l);
720 alfonx 509 }
721    
722 alfonx 144 /**
723 alfonx 530 * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
724     * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
725     * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br>
726     * Since 21. April 09: Before thecalculation starts, the aspect ratio is
727     * corrected. This change implies, that setMapArea() will most of the time
728     * not allow setting to a wrong aspectRatio.
729 alfonx 509 *
730 alfonx 530 * @author <a href="mailto:[email protected]">Stefan Alfons
731     * Kr&uuml;ger</a>
732 alfonx 144 */
733 alfonx 544 public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
734    
735 alfonx 530 if (getWidth() == 0)
736     return env;
737 alfonx 544
738 alfonx 530 if (env == null)
739     return null;
740 alfonx 509
741 alfonx 530 Envelope newArea = null;
742 alfonx 509
743 alfonx 530 /**
744     * Correct the aspect Ratio before we check the rest. Otherwise we might
745     * easily fail. We allow to grow here, because we don't check against
746     * the maxExtend
747     */
748     final Rectangle curPaintArea = getVisibleRect();
749 alfonx 509
750 alfonx 530 env = JTSUtil.fixAspectRatio(curPaintArea, env, true);
751 alfonx 509
752 alfonx 530 final double scale = env.getWidth() / getWidth();
753     final double centerX = env.getMinX() + env.getWidth() / 2.;
754     final double centerY = env.getMinY() + env.getHeight() / 2.;
755     double newWidth2 = 0;
756     double newHeight2 = 0;
757     if (scale < getMaxZoomScale()) {
758     // ****************************************************************************
759     // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
760     // ****************************************************************************
761     newWidth2 = getMaxZoomScale() * getWidth() / 2.;
762     newHeight2 = getMaxZoomScale() * getHeight() / 2.;
763     } else if (scale > getMinZoomScale()) {
764     // ****************************************************************************
765     // Wir zoomen weiter raus als erlaubt => Anpassen des envelope
766     // ****************************************************************************
767     newWidth2 = getMinZoomScale() * getWidth() / 2.;
768     newHeight2 = getMinZoomScale() * getHeight() / 2.;
769     } else {
770     // ****************************************************************************
771     // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
772     // ****************************************************************************
773     newArea = env;
774     }
775 alfonx 509
776 alfonx 530 if (newArea == null) {
777    
778     final Coordinate ll = new Coordinate(centerX - newWidth2, centerY
779     - newHeight2);
780     final Coordinate ur = new Coordinate(centerX + newWidth2, centerY
781     + newHeight2);
782    
783     newArea = new Envelope(ll, ur);
784     }
785    
786     final Envelope maxAllowedExtend = getMaxExtend();
787 alfonx 555
788 alfonx 530 while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
789     && newArea != null && !newArea.isNull()
790     && !Double.isNaN(newArea.getMinX())
791     && !Double.isNaN(newArea.getMaxX())
792     && !Double.isNaN(newArea.getMinY())
793     && !Double.isNaN(newArea.getMaxY())) {
794     /*
795     * If a maxExtend is set, we have to honour that...
796     */
797    
798     // Exceeds top? Move down and maybe cut
799     if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
800     final double divY = newArea.getMaxY()
801     - maxAllowedExtend.getMaxY();
802 alfonx 578 // LOGGER.debug("Moving area down by " + divY);
803 alfonx 530
804     newArea = new Envelope(new Coordinate(newArea.getMinX(),
805     newArea.getMinY() - divY), new Coordinate(newArea
806     .getMaxX(), newArea.getMaxY() - divY));
807    
808     if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
809     // LOGGER.debug("Now it exeeds the bottom border.. cut!");
810     // And cut the bottom if it moved out of the area
811     newArea = new Envelope(new Coordinate(newArea.getMinX(),
812     maxAllowedExtend.getMinY()), new Coordinate(newArea
813     .getMaxX(), newArea.getMaxY()));
814    
815     // LOGGER.debug("and fix aspect ratio");
816    
817 alfonx 544 newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
818     new ReferencedEnvelope(newArea, env
819     .getCoordinateReferenceSystem()), false);
820 alfonx 530 }
821 alfonx 509 }
822    
823 alfonx 530 // Exceeds bottom? Move up and maybe cut
824     if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
825     final double divY = newArea.getMinY()
826     - maxAllowedExtend.getMinY();
827     // LOGGER.debug("Moving area up by " + divY);
828    
829     newArea = new Envelope(new Coordinate(newArea.getMinX(),
830     newArea.getMinY() - divY), new Coordinate(newArea
831     .getMaxX(), newArea.getMaxY() - divY));
832    
833     if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
834     // LOGGER.debug("Now it exeeds the top border.. cut!");
835     // And cut the bottom if it moved out of the area
836     newArea = new Envelope(new Coordinate(newArea.getMinX(),
837     newArea.getMinY()), new Coordinate(newArea
838     .getMaxX(), maxAllowedExtend.getMaxY()));
839    
840     // LOGGER.debug("and fix aspect ratio");
841    
842 alfonx 544 newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
843     new ReferencedEnvelope(newArea, env
844     .getCoordinateReferenceSystem()), false);
845 alfonx 509 }
846     }
847    
848 alfonx 530 // Exceeds to the right? move and maybe cut
849     if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
850 alfonx 509
851 alfonx 530 // Move left..
852     final double divX = newArea.getMaxX()
853     - maxAllowedExtend.getMaxX();
854     // LOGGER.debug("Moving area left by " + divX);
855 alfonx 509
856 alfonx 530 newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
857     newArea.getMinY()), new Coordinate(newArea.getMaxX()
858     - divX, newArea.getMaxY()));
859 alfonx 509
860 alfonx 530 if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
861     // LOGGER.debug("Now it exeeds the left border.. cut!");
862     // And cut the left if it moved out of the area
863     newArea = new Envelope(new Coordinate(maxAllowedExtend
864     .getMinX(), newArea.getMinY()), new Coordinate(
865     newArea.getMaxX(), newArea.getMaxY()));
866 alfonx 509
867 alfonx 530 // LOGGER.debug("and fix aspect ratio");
868    
869 alfonx 544 newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
870     new ReferencedEnvelope(newArea, env
871     .getCoordinateReferenceSystem()), false);
872 alfonx 530 }
873 alfonx 509 }
874    
875 alfonx 530 // Exceeds to the left? move and maybe cut
876     if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
877 alfonx 509
878 alfonx 530 // Move right..
879     final double divX = newArea.getMinX()
880     - maxAllowedExtend.getMinX();
881     // LOGGER.debug("Moving area right by " + divX);
882    
883     newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
884     newArea.getMinY()), new Coordinate(newArea.getMaxX()
885     - divX, newArea.getMaxY()));
886    
887     if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
888     // LOGGER.debug("Now it exeeds the right border.. cut!");
889     // And cut the left if it moved out of the area
890     newArea = new Envelope(new Coordinate(newArea.getMinX(),
891     newArea.getMinY()), new Coordinate(maxAllowedExtend
892     .getMaxX(), newArea.getMaxY()));
893    
894     // LOGGER.debug("and fix aspect ratio");
895    
896 alfonx 544 newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
897     new ReferencedEnvelope(newArea, env
898     .getCoordinateReferenceSystem()), false);
899 alfonx 530 }
900     }
901 alfonx 509 }
902 mojays 2
903 alfonx 544 return new ReferencedEnvelope(newArea, env
904     .getCoordinateReferenceSystem());
905 alfonx 509 }
906 alfonx 414
907 alfonx 509 /**
908 alfonx 530 * Should be called when the {@link JMapPane} is not needed no more to help
909     * the GarbageCollector
910     *
911     * Removes all {@link JMapPaneListener}s that are registered
912     *
913     * @author <a href="mailto:[email protected]">Stefan Alfons
914     * Kr&uuml;ger</a>
915 alfonx 509 */
916 alfonx 530 public void dispose() {
917     if (isDisposed())
918     return;
919 alfonx 513
920 alfonx 530 setPainting(false);
921 alfonx 513
922 alfonx 530 resizeTimer.stop();
923     startRenderThreadsTimer.stop();
924    
925     disposed = true;
926    
927     if (bgExecuter != null) {
928     bgExecuter.cancelTask();
929     bgExecuter.dispose();
930 alfonx 504 }
931 alfonx 509
932 alfonx 555 if (localExecuter.isRunning()) {
933 alfonx 530 int i = 0;
934     localExecuter.cancelTask();
935     while (i++ < 10 && localExecuter.isRunning()) {
936     try {
937 alfonx 543 Thread.sleep(200);
938 alfonx 530 } catch (final InterruptedException e) {
939 alfonx 543 LOGGER
940     .warn(
941     "while XMapPane we are waiting for the localExcutor to stop",
942     e);
943 alfonx 530 }
944     }
945     if (localExecuter.isRunning()) {
946 alfonx 543 LOGGER
947     .warn("localExecutor Thread still running after 2s! Continuing anyways...");
948 alfonx 530 }
949     localExecuter.dispose();
950     }
951 alfonx 539
952 alfonx 530 disposeImages();
953 alfonx 509
954 alfonx 543 // Remove all mapPaneListeners that have registered with us
955 alfonx 530 mapPaneListeners.clear();
956 alfonx 509
957 alfonx 530 removeMouseMotionListener(zoomMapPaneMouseListener);
958     removeMouseListener(zoomMapPaneMouseListener);
959 alfonx 509
960 alfonx 530 if (localContext != null)
961 alfonx 551 getMapContext().clearLayerList();
962 alfonx 530 if (bgContext != null)
963     getBgContext().clearLayerList();
964    
965     removeAll();
966 alfonx 509 }
967    
968     /**
969 alfonx 530 * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
970     * given point. All in screen coordinates.
971 alfonx 509 */
972 alfonx 530 protected void drawRectangle(final Graphics graphics, final Point startPos,
973     final Point e) {
974 alfonx 509
975 alfonx 530 if (!isWellDefined())
976 alfonx 509 return;
977 alfonx 307
978 alfonx 530 // undraw last box/draw new box
979     final int left = Math.min(startPos.x, e.x);
980     final int right = Math.max(startPos.x, e.x);
981     final int top = Math.max(startPos.y, e.y);
982     final int bottom = Math.min(startPos.y, e.y);
983     final int width = right - left;
984     final int height = top - bottom;
985    
986     if (width == 0 && height == 0)
987 alfonx 509 return;
988 alfonx 414
989 alfonx 530 graphics.setXORMode(Color.WHITE);
990     graphics.drawRect(left, bottom, width, height);
991 alfonx 144 }
992 mojays 2
993 alfonx 509 /**
994 alfonx 530 * Diretly paints scaled preview into the {@link SelectableXMapPane}. Used
995     * to give the user something to look at while we are rendering. Method
996     * should be called after {@link #setMapArea(Envelope)} has been set to the
997     * new mapArea and transform has been reset.<br>
998     *
999     * @param g
1000     * Graphics2D to paint the preview into
1001     *
1002     * @param state
1003     * Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}
1004 alfonx 509 */
1005 alfonx 530 protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
1006 alfonx 509
1007 alfonx 543 // if (1 == 1)return false;
1008    
1009 alfonx 530 if (quickPreviewHint == 0)
1010     return false;
1011 alfonx 509
1012 alfonx 530 graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
1013     RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
1014     graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1015     RenderingHints.VALUE_ANTIALIAS_OFF);
1016     graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
1017     RenderingHints.VALUE_RENDER_SPEED);
1018 alfonx 509
1019 alfonx 530 if (oldMapArea == null)
1020     return false;
1021 mojays 2
1022 alfonx 530 final Rectangle visibleArea = getVisibleRect();
1023 alfonx 509
1024 alfonx 530 // Calculate the oldMapArea in the current WindowCoordinates:
1025     final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(),
1026     oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea
1027 alfonx 539 .getMaxY());
1028 alfonx 509
1029 alfonx 530 final int xx1 = (int) Math.round(oldMapWindow.getMinX());
1030     final int yy1 = (int) Math.round(oldMapWindow.getMinY());
1031     final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
1032     final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
1033 alfonx 509
1034 alfonx 530 graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
1035     (int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
1036     (int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
1037     getMapBackgroundColor(), null);
1038 alfonx 509
1039 alfonx 530 final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
1040     - yy1);
1041 alfonx 529
1042 alfonx 530 SwingUtil.clearAround(graphics, painedArea, visibleArea);
1043 alfonx 529
1044 alfonx 533 addGadgets(graphics, true);
1045 alfonx 509
1046 alfonx 530 quickPreviewHint = 0;
1047 alfonx 509
1048 alfonx 533 repaintTimer.restart();
1049    
1050 alfonx 530 graphics.dispose();
1051 alfonx 509
1052 alfonx 530 // Something has been drawn
1053     return true;
1054     }
1055 mojays 2
1056 alfonx 530 public MapContext getBgContext() {
1057     return bgContext;
1058     }
1059 mojays 2
1060 alfonx 530 /**
1061     * Lazyly initializes a {@link BufferedImage} for the background renderer.
1062     */
1063     private Image getBgImage() {
1064     //
1065     // if (bgImage == null) {
1066     // bgImage = createImage(getBounds().width, getBounds().height);
1067     // }
1068    
1069     return bgImage;
1070     }
1071    
1072 alfonx 551 public MapContext getMapContext() {
1073 alfonx 530 if (localContext == null) {
1074     setLocalContext(new DefaultMapContext());
1075 alfonx 144 }
1076 alfonx 530 return localContext;
1077     }
1078 mojays 2
1079 alfonx 530 private BufferedImage getFinalImage() {
1080     //
1081     if (finalImage == null) {
1082     // Rectangle curPaintArea = getVisibleRect();
1083 alfonx 540 finalImage = new BufferedImage(getVisibleRect().width,
1084     getVisibleRect().height, IMAGETYPE);
1085 alfonx 530
1086 alfonx 509 requestStartRendering();
1087 alfonx 144 }
1088 alfonx 530 return finalImage;
1089     }
1090 alfonx 509
1091 alfonx 530 public RenderingHints getJava2dHints() {
1092     return java2dHints;
1093     }
1094    
1095 alfonx 509 /**
1096 alfonx 530 * Lazyly initializes a {@link BufferedImage} for the background renderer.
1097 alfonx 509 */
1098 alfonx 530 private BufferedImage getLocalImage() {
1099 alfonx 509
1100 alfonx 530 if (localImage == null) {
1101 alfonx 540 localImage = new BufferedImage(getVisibleRect().width,
1102     getVisibleRect().height, IMAGETYPE_withAlpha);
1103 alfonx 530 }
1104 alfonx 509
1105 alfonx 530 return localImage;
1106     }
1107    
1108     /**
1109     * Returns a copy of the mapArea
1110     *
1111     * @return
1112     */
1113 alfonx 533 public ReferencedEnvelope getMapArea() {
1114 alfonx 530 if (mapArea == null) {
1115     ReferencedEnvelope mapArea_ = null;
1116     try {
1117     mapArea_ = localContext.getLayerBounds();
1118     } catch (final IOException e) {
1119 alfonx 544 LOGGER.warn("localContext.getLayerBounds()", e);
1120 alfonx 509 }
1121    
1122 alfonx 544 if (mapArea_ == null && bgContext != null) {
1123     try {
1124     mapArea_ = bgContext.getLayerBounds();
1125     } catch (final IOException e) {
1126     LOGGER.warn("bgContext.getLayerBounds()", e);
1127     }
1128     }
1129    
1130 alfonx 530 if (mapArea_ != null) {
1131     mapArea = bestAllowedMapArea(mapArea_);
1132 alfonx 544 requestStartRendering();
1133 alfonx 530 }
1134 alfonx 509 }
1135    
1136 alfonx 530 if (mapArea == null)
1137     return null;
1138 alfonx 509
1139 alfonx 539 // TODO is needed at all, this should go to setMapArea maybe
1140 alfonx 533 if (localContext.getCoordinateReferenceSystem() == null)
1141     try {
1142     localContext.setCoordinateReferenceSystem(GeoImportUtil
1143     .getDefaultCRS());
1144 alfonx 539 } catch (Exception e) {
1145     throw new RuntimeException("setting context CRS:", e);
1146 alfonx 533 }
1147    
1148     return new ReferencedEnvelope(mapArea, localContext
1149     .getCoordinateReferenceSystem());
1150 alfonx 530 }
1151 alfonx 509
1152 alfonx 530 /**
1153 alfonx 557 * Returns the background {@link Color} of the map pane. If not set, the
1154     * methods looks for a parent component and will use its background color.
1155     * If no parent component is available, WHITE is returned.
1156 alfonx 530 **/
1157     public Color getMapBackgroundColor() {
1158 alfonx 560 if (mapBackgroundColor == null) {
1159     if (getParent() != null)
1160     return getParent().getBackground();
1161     else
1162     return Color.WHITE;
1163 alfonx 557 }
1164 alfonx 530 return mapBackgroundColor;
1165     }
1166 alfonx 509
1167     /**
1168 alfonx 530 * Get the BufferedImage to use as a flaoting icon in the lower right
1169     * corner.
1170     *
1171     * @return <code>null</code> if the feature is deactivated.
1172 alfonx 509 */
1173 alfonx 530 public BufferedImage getMapImage() {
1174     return mapImage;
1175     }
1176 alfonx 509
1177 alfonx 530 /**
1178     * Returns the evelope of the viewable area. The JMapPane will never show
1179     * anything outside of this extend. If this has been set to
1180     * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
1181     * quickly the context's bounds. It it takes to long to determine the
1182     * context bounds, <code>null</code> is returned.
1183     *
1184     * @param maxExtend
1185     * <code>null</code> to not have this restriction.
1186     */
1187 alfonx 509
1188 alfonx 530 public Envelope getMaxExtend() {
1189     if (maxExtend == null) {
1190 alfonx 578
1191     // The next command may take long time!
1192 alfonx 555 // long start = System.currentTimeMillis();
1193 alfonx 578 final ReferencedEnvelope layerBounds = GTUtil
1194     .getVisibleLayoutBounds(localContext);
1195 alfonx 555 //
1196     // LOGGER.info(
1197     // (System.currentTimeMillis()-start)+"m to get maxExtend");
1198     //
1199 alfonx 578 if (layerBounds == null) {
1200     // // TODO Last fallback could be the CRS valid area
1201     return null;
1202     }
1203    
1204    
1205     // Vergrößerung um 10% nochmal rausgenommen
1206     // // // Kartenbereich um 10% vergroessern
1207     // return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
1208     // .expandEnvelope(layerBounds, 0.1), true);
1209    
1210     return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true);
1211 alfonx 509 }
1212 alfonx 530 return maxExtend;
1213     }
1214 alfonx 509
1215     /**
1216 alfonx 530 * Retuns the maximum allowed zoom scale. This is the smaller number value
1217     * of the two. Defaults to {@link Double}.MIN_VALUE
1218     *
1219     * @author <a href="mailto:[email protected]">Stefan Alfons
1220     * Kr&uuml;ger</a>
1221 alfonx 509 */
1222 alfonx 530 public Double getMaxZoomScale() {
1223     return maxZoomScale;
1224     }
1225 alfonx 509
1226 alfonx 530 /**
1227     * Retuns the minimum allowed zoom scale. This is the bigger number value of
1228     * the two. Defaults to {@link Double}.MAX_VALUE
1229     *
1230     * @author <a href="mailto:[email protected]">Stefan Alfons
1231     * Kr&uuml;ger</a>
1232     */
1233     public Double getMinZoomScale() {
1234     return minZoomScale;
1235     }
1236 alfonx 509
1237 alfonx 530 private Image getPreFinalImage() {
1238     // if (preFinalImage == null) {
1239     //
1240     // // Rectangle curPaintArea = getVisibleRect();
1241     // // preFinalImage = new BufferedImage(curPaintArea.width,
1242     // // curPaintArea.height, BufferedImage.TYPE_INT_RGB);
1243     //
1244     // preFinalImage = createImage(getBounds().width, getBounds().height);
1245     //
1246     // requestStartRendering();
1247     // }
1248     return preFinalImage;
1249     }
1250 alfonx 509
1251 alfonx 530 public Map<Object, Object> getRendererHints() {
1252 alfonx 533 // Clear label cache
1253     labelCache.clear();
1254     rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
1255    
1256 alfonx 530 return rendererHints;
1257     }
1258 alfonx 509
1259     /**
1260     * Liefert eine affine Transformation, um von den Fenster-Koordinaten in die
1261     * Karten-Koordinaten (Lat/Lon) umzurechnen.
1262     *
1263     * @return eine Kopie der aktuellen Transformation; <code>null</code> wenn
1264     * noch keine Karte angezeigt wird
1265     */
1266     public AffineTransform getScreenToWorld() {
1267     if (screenToWorld == null)
1268     resetTransforms();
1269     // nur Kopie der Transformation zurueckgeben!
1270     if (screenToWorld == null)
1271     return null;
1272     return new AffineTransform(screenToWorld);
1273 alfonx 144 }
1274 mojays 2
1275 alfonx 530 public int getState() {
1276     return state;
1277     }
1278    
1279     /**
1280     * Liefert den statisch eingestellten Cursor, der unabhaengig von der
1281     * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
1282     *
1283     * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der
1284     * Cursor automatisch je nach MapPane-Aktion eingestellt wird.
1285     */
1286     public Cursor getStaticCursor() {
1287     return this.staticCursor;
1288     }
1289    
1290 alfonx 509 public AffineTransform getWorldToScreenTransform() {
1291     if (worldToScreen == null) {
1292     resetTransforms();
1293     }
1294     // nur Kopie der Transformation zurueckgeben!
1295     return new AffineTransform(worldToScreen);
1296 alfonx 144 }
1297 mojays 2
1298 alfonx 530 /**
1299     * A flag indicating if dispose() has already been called. If true, then
1300     * further use of this {@link SelectableXMapPane} is undefined.
1301     */
1302     private boolean isDisposed() {
1303     return disposed;
1304     }
1305    
1306     /**
1307     * Returns whether a layer is regarded or ignored on {@link #SELECT_TOP},
1308     * {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP} actions. Returns
1309     * <code>true</code> if the selectability has not been defined.
1310     *
1311     * @param layer
1312     * a layer
1313     */
1314     public boolean isMapLayerSelectable(final MapLayer layer) {
1315     final Boolean selectable = mapLayerSelectable.get(layer);
1316     return selectable == null ? true : selectable;
1317     }
1318    
1319     /**
1320     * Return <code>true</code> if a CRS and a {@link #mapArea} are set and the
1321     * {@link XMapPane} is visible and has bounds set.
1322     */
1323     public boolean isWellDefined() {
1324     try {
1325 alfonx 551 if (getMapContext() == null)
1326 alfonx 530 return false;
1327 alfonx 551 if (getMapContext().getLayerCount() <= 0)
1328 alfonx 530 return false;
1329 alfonx 544 if (getVisibleRect().getWidth() == 0)
1330 alfonx 530 return false;
1331 alfonx 544 if (getVisibleRect().getHeight() == 0)
1332 alfonx 530 return false;
1333 alfonx 544 // if (getMapArea() == null)
1334     // return false;
1335 alfonx 530 } catch (final Exception e) {
1336     return false;
1337 alfonx 509 }
1338 alfonx 530 return true;
1339 alfonx 144 }
1340 mojays 2
1341 alfonx 555 /**
1342     * Called from the listeners while the mouse is dragging, this method either
1343     * paints a translated (moved/panned) version of the image, or a rectangle.
1344     *
1345     * @param startPos
1346     * in screen coordinates
1347     * @param lastPos
1348     * in screen coordinates
1349     * @param event
1350     * the {@link MouseEvent} to read the mouse buttons from
1351     */
1352 alfonx 530 public void mouseDragged(final Point startPos, final Point lastPos,
1353     final MouseEvent event) {
1354    
1355     if ((getState() == XMapPane.PAN)
1356     || ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) {
1357    
1358 alfonx 555 // Panning needs a panning coursor
1359 alfonx 530 if (getCursor() != SwingUtil.PANNING_CURSOR) {
1360     setCursor(SwingUtil.PANNING_CURSOR);
1361    
1362 alfonx 555 // While panning, we deactivate the rendering. So the tasks are
1363     // ready to start when the panning is finished.
1364     if (bgExecuter != null && bgExecuter.isRunning())
1365 alfonx 530 bgExecuter.cancelTask();
1366 alfonx 555 if (localExecuter.isRunning())
1367 alfonx 530 localExecuter.cancelTask();
1368     }
1369    
1370     if (lastPos.x > 0 && lastPos.y > 0) {
1371     final int dx = event.getX() - lastPos.x;
1372     final int dy = event.getY() - lastPos.y;
1373    
1374     // TODO Stop dragging when the drag would not be valid...
1375     // boolean dragValid = true;
1376     // // check if this panning results in a valid mapArea
1377     // {
1378     // Rectangle winBounds = xMapPane.getBounds();
1379     // winBounds.translate(xMapPane.imageOrigin.x,
1380     // -xMapPane.imageOrigin.y);
1381     // Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo(
1382     // winBounds.x, winBounds.y, winBounds.x
1383     // + winBounds.width, winBounds.y
1384     // + winBounds.height);
1385     //
1386     //
1387     // winBounds = xMapPane.getBounds();
1388     // Point testIng = new Point(xMapPane.imageOrigin);
1389     // testIng.translate(dx, dy);
1390     // winBounds.translate(testIng.x, -testIng.y);
1391     // Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo(
1392     // winBounds.x, winBounds.y, winBounds.x
1393     // + winBounds.width, winBounds.y
1394     // + winBounds.height);
1395     //
1396     // // If the last drag doesn't change the MapArea anymore cancel
1397     // it.
1398     // if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals(
1399     // xMapPane.bestAllowedMapArea(newMapAreaBefore))){
1400     // dragValid = false;
1401     // return;
1402     // }
1403     // }
1404    
1405     imageOrigin.translate(dx, dy);
1406     updateFinalImage();
1407     repaint();
1408     }
1409    
1410     } else if ((getState() == XMapPane.ZOOM_IN)
1411     || (getState() == XMapPane.ZOOM_OUT)
1412     || (getState() == XMapPane.SELECT_ALL)
1413 alfonx 555 || (getState() == XMapPane.SELECT_TOP)) {
1414    
1415     // Draws a rectangle
1416 alfonx 530 final Graphics graphics = getGraphics();
1417     drawRectangle(graphics, startPos, event.getPoint());
1418 alfonx 555 if ((lastPos.x > 0) && (lastPos.y > 0))
1419 alfonx 530 drawRectangle(graphics, startPos, lastPos);
1420     graphics.dispose();
1421     }
1422 alfonx 144 }
1423 mojays 2
1424 alfonx 509 /**
1425 alfonx 530 * Called by the {@link RenderingExecutor} when rendering was cancelled.
1426     */
1427     public void onRenderingCancelled() {
1428 alfonx 578 // LOGGER.debug("Rendering cancelled");
1429 alfonx 530 repaintTimer.stop();
1430     }
1431    
1432     /**
1433     * Called by the {@link RenderingExecutor} when rendering has been
1434     * completed.
1435     */
1436     public void onRenderingCompleted() {
1437 alfonx 578 // LOGGER.debug("complete");
1438 alfonx 555
1439 alfonx 530 repaintTimer.stop();
1440 alfonx 555
1441     // We "forget" about an exception every time we complete a rendering
1442     // thread successfully
1443     if (renderingErrors.size() > 0)
1444     renderingErrors.remove(0);
1445    
1446 alfonx 530 updateFinalImage();
1447     repaint();
1448     }
1449    
1450     /**
1451     * Called by the {@linkplain XMapPane.RenderingTask} when rendering failed.
1452     * Publishes a {@linkplain MapPaneEvent} of type {@code
1453     * MapPaneEvent.Type.RENDERING_STOPPED} to listeners.
1454 alfonx 509 *
1455 alfonx 530 * @param renderingError
1456     * The error that occured during rendering
1457     *
1458     * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
1459 alfonx 509 */
1460 alfonx 530 public void onRenderingFailed(final Exception renderingError) {
1461 alfonx 553
1462     // Store the exceptions so we can show it to the user:
1463 alfonx 555 if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError
1464     .getMessage().equals(
1465 alfonx 553 "Argument \"sourceCRS\" should not be null.")))
1466     this.renderingErrors.add(renderingError);
1467 alfonx 533 if (renderingErrors.size() > 3)
1468     renderingErrors.remove(0);
1469 alfonx 555
1470 alfonx 530 repaintTimer.stop();
1471 alfonx 555
1472 alfonx 530 LOGGER.warn("Rendering failed", renderingError);
1473     updateFinalImage();
1474     repaint();
1475 mojays 2
1476 alfonx 530 }
1477    
1478     @Override
1479     protected void paintComponent(final Graphics g) {
1480 alfonx 544
1481 alfonx 555 // Maybe update the cursor and maybe stop the repainting timer
1482     updateCursor();
1483    
1484 alfonx 530 if (!acceptsRepaintCalls)
1485     return;
1486    
1487 alfonx 555 if (!isWellDefined())
1488     return;
1489 alfonx 530
1490 alfonx 578 // super.paintComponent(g); // candidate for removal
1491 alfonx 530
1492     boolean paintedSomething = false;
1493    
1494     if (mapImageInvalid) { /* if the map changed then redraw */
1495    
1496     mapImageInvalid = false; // Reset for next round
1497    
1498     // If the new mapArea and the oldMapArea intersect, we can draw some
1499     // quick scaled preview to make the user feel that something is
1500     // happening.
1501     if (mapAreaChanged && oldMapArea != null
1502     && getMapArea().intersects(oldMapArea)
1503 alfonx 544 & !getMapArea().equals(oldMapArea) && !paneResized) {
1504 alfonx 530
1505     mapAreaChanged = false;
1506    
1507     if (getMapArea().covers(oldMapArea)) {
1508 alfonx 555 quickPreviewHint = ZOOM_OUT;
1509 alfonx 530 paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1510     } else if (oldMapArea.covers(getMapArea())) {
1511 alfonx 555 quickPreviewHint = ZOOM_IN;
1512 alfonx 530 paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
1513     }
1514 alfonx 509 }
1515     }
1516 mojays 2
1517 alfonx 530 if (!paintedSomething) {
1518 mojays 2
1519 alfonx 530 g.drawImage(getFinalImage(), 0, 0, null);
1520 alfonx 529
1521 alfonx 530 g.dispose(); // cand. for removal
1522 alfonx 509
1523 alfonx 530 paintedSomething = true; // cand. for removal
1524     }
1525 alfonx 529
1526 alfonx 530 }
1527 alfonx 509
1528 alfonx 530 /**
1529     * Heavily works on releasing all resources related to the four
1530     * {@link Image}s used to cache the results of the different renderers.<br>
1531     * In November 2009 i had some memory leaking problems with {@link XMapPane}
1532     * . The resources of the buffered images were never released. It seem to be
1533     * important to call the GC right after flushing the images.<br>
1534     * Hence this method may take a while, because it calls the GC up to four
1535     * times.
1536     */
1537     private void disposeImages() {
1538    
1539     // System.out.println("vorher = "
1540     // + new MbDecimalFormatter().format(LangUtil.gcTotal()));
1541     // bi.flush();
1542     // return bi = null;
1543     // System.out.println("nacher = "
1544     // + new MbDecimalFormatter().format(LangUtil.gcTotal()));
1545     //
1546     // System.out.println("\n");
1547    
1548     if (preFinalImage != null) {
1549     preFinalImage.flush();
1550     preFinalImage = null;
1551     LangUtil.gc();
1552 alfonx 509 }
1553 alfonx 530 if (finalImage != null) {
1554     finalImage.flush();
1555     finalImage = null;
1556     LangUtil.gc();
1557     }
1558     if (localImage != null) {
1559     localImage.flush();
1560     localImage = null;
1561     LangUtil.gc();
1562     }
1563     if (bgImage != null) {
1564     bgImage.flush();
1565     bgImage = null;
1566     LangUtil.gc();
1567     }
1568 alfonx 509
1569 alfonx 144 }
1570 mojays 2
1571 alfonx 530 /**
1572     * Performs a {@value #PAN} action. During panning, the displacement is
1573     * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will
1574     * reset the offset and call {@link #setMapArea(Envelope)}.
1575     */
1576     public void performPan() {
1577    
1578 alfonx 540 Rectangle winBounds = getVisibleRect();
1579 alfonx 543
1580 alfonx 530 winBounds.translate(-imageOrigin.x, -imageOrigin.y);
1581     final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
1582     winBounds.y, winBounds.x + winBounds.width, winBounds.y
1583     + winBounds.height);
1584    
1585     imageOrigin.x = 0;
1586     imageOrigin.y = 0;
1587    
1588     if (!setMapArea(newMapArea)) {
1589     /**
1590     * If setMapArea returns true, the finalImage is updated anyways.
1591     * This if-case exists to ensure that we repaint a correct image
1592     * even if the new panning area has been denied.
1593     */
1594     updateFinalImage();
1595     repaint();
1596     }
1597    
1598     if (getCursor() == SwingUtil.PANNING_CURSOR)
1599     setCursor(SwingUtil.PAN_CURSOR);
1600     }
1601    
1602     /**
1603     * Entfernt einen Listener von der Map.
1604     *
1605     * @param l
1606     * zu entfernender Listener
1607     */
1608     public void removeMapPaneListener(final JMapPaneListener l) {
1609     mapPaneListeners.remove(l);
1610     }
1611    
1612     /**
1613     * Cancels all running renderers and sets the flag to start new ones. <br>
1614     *
1615     * @see #startRenderThreadsTimer
1616     */
1617     private void requestStartRendering() {
1618     if (bgExecuter != null)
1619     bgExecuter.cancelTask();
1620    
1621 alfonx 555 localExecuter.cancelTask();
1622    
1623 alfonx 544 mapImageInvalid = true;
1624     if (paneResized) {
1625     paneResized = false;
1626     disposeImages();
1627     }
1628     requestStartRendering = true;
1629    
1630 alfonx 530 }
1631    
1632 alfonx 539 /**
1633     * Calculate the affine transforms used to convert between world and pixel
1634     * coordinates. The calculations here are very basic and assume a cartesian
1635     * reference system.
1636     * <p>
1637     * Tne transform is calculated such that {@code envelope} will be centred in
1638     * the display
1639     *
1640     * @param envelope
1641     * the current map extent (world coordinates)
1642     * @param paintArea
1643     * the current map pane extent (screen units)
1644     */
1645     private void resetTransforms() {
1646     ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
1647 alfonx 551 getMapContext().getCoordinateReferenceSystem());
1648 alfonx 540
1649 alfonx 544 // System.out
1650     // .println("paintArea in resetTeansofrms = " + getVisibleRect());
1651     if (!isWellDefined())
1652     return;
1653 alfonx 543
1654 alfonx 539 worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
1655 alfonx 544 getVisibleRect());
1656 alfonx 530
1657 alfonx 539 try {
1658     screenToWorld = worldToScreen.createInverse();
1659 alfonx 530
1660 alfonx 539 } catch (NoninvertibleTransformException ex) {
1661 alfonx 544 LOGGER
1662     .error("can't invert worldToScreen to get screenToWorld!",
1663     ex);
1664 alfonx 539 }
1665     }
1666 alfonx 536
1667 alfonx 509 public void setBgContext(final MapContext context) {
1668 mojays 2
1669 alfonx 509 // Remove the default listener from the old context
1670     if (this.bgContext != null) {
1671     this.bgContext.removeMapLayerListListener(bgContextListener);
1672    
1673     // adding listener to all layers
1674 alfonx 530 for (final MapLayer mapLayer : bgContext.getLayers()) {
1675 alfonx 509 mapLayer.removeMapLayerListener(bgMapLayerListener);
1676     }
1677 alfonx 144 }
1678 mojays 2
1679 alfonx 509 this.bgContext = context;
1680 mojays 2
1681 alfonx 509 if (context != null) {
1682 alfonx 544 // setMapArea(bgContext.getAreaOfInterest());
1683 alfonx 509
1684     this.bgContext.addMapLayerListListener(bgContextListener);
1685    
1686     // adding listener to all layers
1687 alfonx 530 for (final MapLayer mapLayer : bgContext.getLayers()) {
1688 alfonx 509 mapLayer.addMapLayerListener(bgMapLayerListener);
1689 alfonx 144 }
1690 alfonx 509 }
1691 alfonx 544
1692     requestStartRendering();
1693 alfonx 509 }
1694 mojays 2
1695 alfonx 530 public void setJava2dHints(final RenderingHints java2dHints) {
1696     this.java2dHints = java2dHints;
1697     }
1698    
1699     public void setLocalContext(final MapContext context) {
1700     // Remove the default listener from the old context
1701     if (this.localContext != null) {
1702     this.localContext.removeMapLayerListListener(localContextListener);
1703    
1704     // adding listener to all layers
1705     for (final MapLayer mapLayer : localContext.getLayers()) {
1706     mapLayer.removeMapLayerListener(localMapLayerListener);
1707 alfonx 509 }
1708 alfonx 530 }
1709 alfonx 509
1710 alfonx 530 this.localContext = context;
1711    
1712     if (context != null) {
1713    
1714 alfonx 544 // setMapArea(localContext.getAreaOfInterest());
1715 alfonx 530
1716 alfonx 560 getLocalRenderer().setContext(localContext);
1717 alfonx 530
1718     this.localContext.addMapLayerListListener(localContextListener);
1719    
1720     // adding listener to all layers
1721     for (final MapLayer mapLayer : localContext.getLayers()) {
1722     mapLayer.addMapLayerListener(localMapLayerListener);
1723 alfonx 144 }
1724     }
1725 mojays 2
1726 alfonx 544 requestStartRendering();
1727    
1728 alfonx 509 }
1729 alfonx 578
1730 mojays 561 public void setBorder(Border b) {
1731 alfonx 578 super.setBorder(b);
1732 mojays 561 }
1733 alfonx 509
1734 alfonx 560 /**
1735     * Triggers to repaint (fast) and re-render (slow) the JMapPane.
1736     */
1737     public void refresh() {
1738     mapImageInvalid = true;
1739     repaint();
1740     }
1741    
1742     // /**
1743     // * Triggers to use new {@link GTRenderer} and refresh the map. Should be
1744     // * called after {@link Style}s have been changed because GTRenderer is
1745     // * otherwise not working well.
1746     // */
1747     // public void refreshRenderers() {
1748     // localRenderer = GTUtil.createGTRenderer();
1749     // setLocalContext(getMapContext());
1750     // mapImageInvalid = true;
1751     // repaint();
1752     // }
1753    
1754 alfonx 578 /**
1755     * Set the new map area.
1756     *
1757     * @param newMapArea
1758     * @return <code>true</code> if the mapArea has been changed and a repaint
1759     * has been triggered.
1760     */
1761 alfonx 544 public boolean setMapArea(final Envelope newMapArea) {
1762 alfonx 556 if (newMapArea == null)
1763     return false;
1764 alfonx 560 if (getMapContext().getCoordinateReferenceSystem() == null)
1765     return false;
1766 alfonx 551 return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext()
1767 alfonx 544 .getCoordinateReferenceSystem()));
1768     }
1769    
1770 alfonx 509 /**
1771 alfonx 578 * Set the new map area.
1772     *
1773 alfonx 509 * @param newMapArea
1774     * @return <code>true</code> if the mapArea has been changed and a repaint
1775     * has been triggered.
1776     */
1777 alfonx 544 public boolean setMapArea(final ReferencedEnvelope newMapArea) {
1778 alfonx 509
1779     if (newMapArea == null
1780     || bestAllowedMapArea(newMapArea).equals(mapArea)) {
1781     // No change.. no need to repaint
1782     return false;
1783 alfonx 144 }
1784 mojays 2
1785 alfonx 513 // Testing, whether NaN or Infinity are used in the newMapArea
1786     if (newMapArea.isNull() || Double.isInfinite(newMapArea.getMaxX())
1787     || Double.isInfinite(newMapArea.getMaxY())
1788     || Double.isInfinite(newMapArea.getMinX())
1789     || Double.isInfinite(newMapArea.getMinY())) {
1790     // No change.. ugly new values
1791     LOGGER.warn("setMapArea has been called with newArea = "
1792     + newMapArea);
1793     return false;
1794     }
1795    
1796 alfonx 539 final Envelope candNew = bestAllowedMapArea(newMapArea);
1797    
1798 alfonx 513 // Testing, whether the difference if just minimal
1799 alfonx 509 if (mapArea != null) {
1800 alfonx 530 final double tolX = mapArea.getWidth() / 1000.;
1801     final double tolY = mapArea.getHeight() / 1000.;
1802 alfonx 509 if ((candNew.getMinX() - tolX < mapArea.getMinX())
1803     && (mapArea.getMinX() < candNew.getMinX() + tolX)
1804     && (candNew.getMaxX() - tolX < mapArea.getMaxX())
1805     && (mapArea.getMaxX() < candNew.getMaxX() + tolX)
1806 mojays 2
1807 alfonx 509 && (candNew.getMinY() - tolY < mapArea.getMinY())
1808     && (mapArea.getMinY() < candNew.getMinY() + tolY)
1809     && (candNew.getMaxY() - tolY < mapArea.getMaxY())
1810     && (mapArea.getMaxY() < candNew.getMaxY() + tolY)
1811 mojays 2
1812 alfonx 509 ) {
1813     // The two mapAreas only differ my 1/1000th.. ignore
1814 alfonx 505
1815 alfonx 509 return false;
1816     }
1817     }
1818 mojays 2
1819 alfonx 539 // New map are is accepted:
1820 alfonx 509 oldMapArea = mapArea;
1821 alfonx 539 mapArea = candNew;
1822     resetTransforms();
1823 mojays 2
1824 alfonx 509 if (localContext != null) {
1825     localContext.setAreaOfInterest(mapArea, localContext
1826     .getCoordinateReferenceSystem());
1827 alfonx 144 }
1828 alfonx 509 if (bgContext != null) {
1829     bgContext.setAreaOfInterest(mapArea, localContext
1830     .getCoordinateReferenceSystem());
1831     }
1832 alfonx 544
1833 alfonx 509 mapAreaChanged = true;
1834 alfonx 513
1835 alfonx 555 repaint(200); // Do not remove it!
1836 alfonx 544
1837     requestStartRendering();
1838    
1839 alfonx 509 return true;
1840     }
1841 mojays 2
1842 alfonx 509 /**
1843 alfonx 530 * Set the background color of the map.
1844 alfonx 509 *
1845 alfonx 530 * @param if <code>null</code>, white is used.
1846 alfonx 509 */
1847 alfonx 530 public void setMapBackgroundColor(Color bgColor) {
1848     this.mapBackgroundColor = bgColor;
1849 alfonx 509 }
1850 mojays 2
1851 alfonx 509 /**
1852 alfonx 530 * Set the BufferedImage to use as a flaoting icon in the lower right corner
1853     *
1854     * @param mapImageIcon
1855     * <code>null</code> is allowed and deactivates this icon.
1856 alfonx 529 */
1857 alfonx 530 public void setMapImage(final BufferedImage mapImage) {
1858     this.mapImage = mapImage;
1859     }
1860 alfonx 529
1861     /**
1862 alfonx 530 * Sets whether a layer is regarded or ignored on {@link #SELECT_TOP},
1863     * {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP} actions.
1864     *
1865     * @param layer
1866     * a layer
1867     * @param selectable
1868     * if {@code false} the layer is ignored during the upper
1869     * mentioned actions. If <code>null</code>, the default (true)
1870     * will be used.
1871 alfonx 529 */
1872 alfonx 530 public void setMapLayerSelectable(final MapLayer layer,
1873     final Boolean selectable) {
1874     if (selectable == null)
1875     mapLayerSelectable.remove(layer);
1876     else
1877     mapLayerSelectable.put(layer, selectable);
1878 alfonx 144 }
1879 mojays 2
1880 alfonx 509 /**
1881 alfonx 530 * Defines an evelope of the viwable area. The JMapPane will never show
1882     * anything outside of this extend.
1883 alfonx 509 *
1884 alfonx 530 * @param maxExtend
1885     * <code>null</code> to not have this restriction.
1886 alfonx 509 */
1887 alfonx 530 public void setMaxExtend(final Envelope maxExtend) {
1888     this.maxExtend = maxExtend;
1889 alfonx 144 }
1890 mojays 2
1891 alfonx 509 /**
1892 alfonx 530 * Set the maximum allowed zoom scale. This is the smaller number value of
1893     * the two. If <code>null</code> is passed, Double.MINVALUE are used which
1894     * mean there is no restriction.
1895 alfonx 509 *
1896 alfonx 530 * @author <a href="mailto:[email protected]">Stefan Alfons
1897     * Kr&uuml;ger</a>
1898 alfonx 509 */
1899 alfonx 530 public void setMaxZoomScale(final Double maxZoomScale) {
1900     this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE
1901     : maxZoomScale;
1902 alfonx 144 }
1903 mojays 2
1904 alfonx 530 // /** Stored the time used for the last real rendering in ms. **/
1905     // private long lastRenderingDuration = Long.MAX_VALUE;
1906    
1907 alfonx 509 /**
1908 alfonx 530 * Set the minimum (nearest) allowed zoom scale. This is the bigger number
1909     * value of the two. If <code>null</code> is passed, Double.MAXVALUE are
1910     * used which mean there is no restriction.
1911 alfonx 509 *
1912 alfonx 530 *
1913     * @author <a href="mailto:[email protected]">Stefan Alfons
1914     * Kr&uuml;ger</a>
1915 alfonx 509 */
1916 alfonx 530 public void setMinZoomScale(final Double minZoomScale) {
1917     this.minZoomScale = minZoomScale == null ? Double.MAX_VALUE
1918     : minZoomScale;
1919 alfonx 144 }
1920 mojays 2
1921 alfonx 509 /**
1922 alfonx 555 * If <code>true</code>, allow the {@link XMapPane} to process #repaint()
1923     * requests. Otherwise the map will not paint anything and not start any
1924     * rendering {@link Thread}s.
1925 alfonx 509 */
1926 alfonx 530 public void setPainting(final boolean b) {
1927     acceptsRepaintCalls = b;
1928 alfonx 555 if (acceptsRepaintCalls == true)
1929     repaint();
1930 alfonx 530 }
1931 mojays 2
1932 alfonx 530 private void setRendererHints(final Map<Object, Object> rendererHints) {
1933 alfonx 533 if (rendererHints != null)
1934     this.rendererHints = rendererHints;
1935 alfonx 144 }
1936 alfonx 513
1937 alfonx 509 /**
1938 alfonx 530 * Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the
1939     * repaint Timer if
1940     *
1941     * @param state
1942 alfonx 509 */
1943 alfonx 530 public void setState(final int state) {
1944     this.state = state;
1945 mojays 2
1946 alfonx 530 zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN
1947     || state == ZOOM_OUT || state == PAN));
1948 alfonx 509
1949 alfonx 530 // Je nach Aktion den Cursor umsetzen
1950     updateCursor();
1951 alfonx 509 }
1952 alfonx 504
1953 alfonx 509 /**
1954 alfonx 530 * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,
1955     * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
1956     * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
1957     * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
1958     * {@code null} als Parameter uebergeben werden
1959 alfonx 509 *
1960 alfonx 530 * @param cursor
1961     * Cursor
1962 alfonx 509 */
1963 alfonx 530 public void setStaticCursor(final Cursor cursor) {
1964     this.staticCursor = cursor;
1965     if (cursor != null)
1966     super.setCursor(cursor);
1967 alfonx 509 }
1968 alfonx 431
1969 alfonx 509 /**
1970     * Starts rendering on one or two threads
1971     */
1972     private void startRendering() {
1973    
1974 alfonx 544 if (!isWellDefined() || !acceptsRepaintCalls) {
1975 alfonx 555 // if we are not ready to start rendering, try it again the next
1976     // time the timer is chacking the flag.
1977 alfonx 544 requestStartRendering = true;
1978 alfonx 509 return;
1979 alfonx 544 }
1980 alfonx 509
1981 alfonx 529 if (bgExecuter != null) {
1982 alfonx 509 // Stop all renderers
1983     bgExecuter.cancelTask();
1984 alfonx 524 }
1985 alfonx 509
1986 alfonx 555 localExecuter.cancelTask();
1987 alfonx 529
1988 alfonx 530 final Rectangle curPaintArea = getVisibleRect();
1989 mojays 2
1990 alfonx 509 /**
1991     * We have to set new renderer
1992     */
1993    
1994     if (getBgContext() != null) {
1995 alfonx 533 bgRenderer.setJava2DHints(getJava2dHints());
1996     bgRenderer.setRendererHints(getRendererHints());
1997    
1998 alfonx 529 // bgExecuter = new RenderingExecutor();
1999     // LOGGER.debug("starting bg renderer:");
2000     // // /* System.out.println("rendering"); */
2001     // final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
2002     // bgContext, getRendererHints());
2003     // createGTRenderer.setJava2DHints(getJava2dHints());
2004     // bgExecuter.submit(getBgContext().getAreaOfInterest(),
2005     // curPaintArea,
2006     // (Graphics2D) getBgImage().getGraphics(), createGTRenderer);
2007 alfonx 509 }
2008    
2009 alfonx 551 if (getMapContext() != null) {
2010 alfonx 529 // localExecuter = new RenderingExecutor(this, 150l);
2011 alfonx 530 // LOGGER.debug("starting local renderer:");
2012    
2013 alfonx 560 getLocalRenderer().setJava2DHints(getJava2dHints());
2014     getLocalRenderer().setRendererHints(getRendererHints());
2015 alfonx 529
2016 alfonx 544 final boolean submitted = localExecuter.submit(getMapArea(),
2017 alfonx 533 curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
2018 alfonx 560 getLocalRenderer());
2019 alfonx 530 if (submitted)
2020     repaintTimer.restart();
2021     else
2022 alfonx 544 requestStartRendering = true; // Try to start rendering
2023     // again in
2024 alfonx 530 // a moment
2025 alfonx 509 }
2026    
2027 alfonx 514 updateCursor();
2028 alfonx 144 }
2029 mojays 2
2030 alfonx 509 /**
2031 alfonx 530 * Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten.
2032 alfonx 509 *
2033 alfonx 530 * @param ox
2034     * X-Koordinate der VON-Position
2035     * @param oy
2036     * Y-Koordinate der VON-Position
2037     * @param px
2038     * X-Koordinate der BIS-Position
2039     * @param py
2040     * Y-Koordinate der BIS-Position
2041     * @param winToGeotransform
2042     * Eine Window to Geo transform. If <code>null</code>,
2043     * {@link #getScreenToWorld()} is used.
2044 alfonx 509 */
2045 alfonx 530 public Envelope tranformGeoToWindow(final double ox, final double oy,
2046 alfonx 539 final double px, final double py) {
2047     final AffineTransform at = getWorldToScreenTransform();
2048 alfonx 530 Point2D geoO;
2049 alfonx 539 // try {
2050     geoO = at.transform(new Point2D.Double(ox, oy), null);
2051     final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2052     return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
2053     // } catch (final NoninvertibleTransformException e) {
2054     // LOGGER.error(e);
2055     // return new Envelope(ox, oy, px, py);
2056     // }
2057 alfonx 144 }
2058 mojays 2
2059 alfonx 509 /**
2060 alfonx 530 * Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten.
2061 alfonx 509 *
2062 alfonx 530 * @param ox
2063     * X-Koordinate der VON-Position
2064     * @param oy
2065     * Y-Koordinate der VON-Position
2066     * @param px
2067     * X-Koordinate der BIS-Position
2068     * @param py
2069     * Y-Koordinate der BIS-Position
2070 alfonx 509 */
2071 alfonx 530 public Envelope tranformWindowToGeo(final int ox, final int oy,
2072     final int px, final int py) {
2073     final AffineTransform at = getScreenToWorld();
2074     final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
2075     final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
2076 alfonx 543
2077 alfonx 539 // Mmmmm... don't really understand why its x,x,y,y
2078 alfonx 543 // return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(),
2079     // geoP.getY());
2080     return new Envelope(new Coordinate(geoO.getX(), geoO.getY()),
2081     new Coordinate(geoP.getX(), geoP.getY()));
2082 alfonx 144 }
2083 mojays 2
2084 alfonx 509 /**
2085 alfonx 530 * Will update the cursor. If all rendering is finished also stops the
2086     * {@link #repaintTimer}
2087 alfonx 509 */
2088 alfonx 530 public void updateCursor() {
2089 mojays 2
2090 alfonx 530 // if the renderers have stopped, also stop the timer that is updating
2091     // the final image
2092     if (bgExecuter != null && bgExecuter.isRunning()
2093 alfonx 555 || localExecuter.isRunning()) {
2094     setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
2095 alfonx 530 return;
2096     } else {
2097     // Allow one last rendering
2098     if (repaintTimer.isRunning()) {
2099 alfonx 544 // System.out.println("one last rendering....");
2100 alfonx 530 repaintTimer.stop();
2101     updateFinalImage();
2102     repaint();
2103     }
2104 alfonx 144 }
2105 mojays 2
2106 alfonx 530 // wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
2107     // von der aktuellen Aktion
2108     if (this.staticCursor != null) {
2109     setCursor(staticCursor);
2110     return;
2111     }
2112     if (getCursor() == SwingUtil.PANNING_CURSOR) {
2113     // This cursor will reset itself
2114     return;
2115     }
2116 mojays 2
2117 alfonx 530 // Set the cursor depending on what tool is in use...
2118     switch (state) {
2119     case SELECT_TOP:
2120     case SELECT_ONE_FROM_TOP:
2121     case SELECT_ALL:
2122     setCursor(SwingUtil.CROSSHAIR_CURSOR);
2123     break;
2124     case ZOOM_IN:
2125     setCursor(SwingUtil.ZOOMIN_CURSOR);
2126     break;
2127     case ZOOM_OUT:
2128     setCursor(SwingUtil.ZOOMOUT_CURSOR);
2129     break;
2130     case PAN:
2131     setCursor(SwingUtil.PAN_CURSOR);
2132     break;
2133     default:
2134     setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
2135     break;
2136     }
2137 alfonx 144 }
2138 mojays 2
2139 alfonx 509 /**
2140 alfonx 530 * The renderers are all rendering into their own {@link Image}s. This
2141     * method combines all images to one {@link #finalImage}. The
2142     * {@link #repaintTimer} is calling this method regularely to update the
2143     * {@link #finalImage} even if the renderers are still working.
2144 alfonx 509 */
2145 alfonx 530 synchronized protected Image updateFinalImage() {
2146 mojays 2
2147 alfonx 530 // Render the two map images first, into the preFinalImage
2148     if (bgExecuter != null) {
2149     final Graphics2D preFinalG = (Graphics2D) getPreFinalImage()
2150     .getGraphics();
2151     preFinalG.setBackground(getMapBackgroundColor());
2152 mojays 2
2153 alfonx 530 preFinalG.drawImage(getBgImage(), 0, 0, getMapBackgroundColor(),
2154     null);
2155 mojays 2
2156 alfonx 530 // // Draw the local layers image
2157     preFinalG.drawImage(getLocalImage(), 0, 0, null);
2158     preFinalG.dispose();
2159 mojays 2
2160 alfonx 76 } else {
2161 alfonx 530 preFinalImage = getLocalImage();
2162 alfonx 76 }
2163 mojays 2
2164 alfonx 530 final Graphics2D finalG = getFinalImage().createGraphics();
2165     finalG.setBackground(getMapBackgroundColor());
2166     finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,
2167     getMapBackgroundColor(), null);
2168 mojays 2
2169 alfonx 530 final int finalImageHeight = getFinalImage().getHeight(null);
2170     final int finalImageWidth = getFinalImage().getWidth(null);
2171 alfonx 414
2172 alfonx 530 final Rectangle painedArea = new Rectangle(imageOrigin.x,
2173     imageOrigin.y, finalImageWidth, finalImageHeight);
2174     SwingUtil.clearAround(finalG, painedArea, getVisibleRect());
2175 alfonx 414
2176 alfonx 533 addGadgets(finalG, false);
2177 alfonx 414
2178 alfonx 530 finalG.dispose();
2179 alfonx 414
2180 alfonx 530 return finalImage;
2181 alfonx 76 }
2182    
2183 alfonx 144 /**
2184 alfonx 530 * Paints some optional stuff into the given {@link Graphics2D}. Usually
2185     * called as the last layer when {@link #updateFinalImage()}
2186 alfonx 533 *
2187     * @param forceWait
2188     * if <code>true</code>, a Wait-message will be painted even
2189     * though the rendering threads may not yet have started. If
2190     * <code>false</code>, it will only depend on
2191     * {@link #localExecuter.isRunning} and #bgExecuter.isRunning
2192 alfonx 144 */
2193 alfonx 533 private void addGadgets(final Graphics2D graphics, boolean forceWait) {
2194 mojays 2
2195 alfonx 530 // Paint a logo to the bottom right if available
2196     if (mapImage != null) {
2197 alfonx 540 Rectangle visibleRect = getVisibleRect();
2198     graphics.drawImage(mapImage, visibleRect.width
2199     - mapImage.getWidth() - 10, getVisibleRect().height
2200 alfonx 530 - mapImage.getHeight() - 10, null);
2201     }
2202 alfonx 539
2203 alfonx 533 int y = 17;
2204 mojays 2
2205 alfonx 530 // If the rendering process is still running, indicate this is the image
2206 alfonx 533 if (forceWait || bgExecuter != null && bgExecuter.isRunning()
2207 alfonx 555 || localExecuter.isRunning()) {
2208 mojays 2
2209 alfonx 539 y += 8;
2210    
2211 alfonx 530 final Color c = graphics.getColor();
2212     graphics.setFont(waitFont);
2213 alfonx 533
2214     graphics.setColor(getMapBackgroundColor());
2215     graphics.drawString(waitMsg, 5, y);
2216     graphics.setColor(getMapBackgroundColor());
2217 alfonx 539 graphics.drawString(waitMsg, 7, y + 2);
2218 alfonx 530 graphics.setColor(Color.BLACK);
2219 alfonx 539 graphics.drawString(waitMsg, 6, y + 1);
2220 mojays 2
2221 alfonx 530 graphics.setColor(c);
2222 alfonx 539
2223 alfonx 533 y += 24;
2224 alfonx 418 }
2225 alfonx 414
2226 alfonx 555 if (!renderingErrors.isEmpty() && isShowExceptions()) {
2227 alfonx 533
2228     final Color c = graphics.getColor();
2229     graphics.setFont(errorFont);
2230    
2231     for (Exception ex : renderingErrors) {
2232    
2233     String errStr = ex.getLocalizedMessage();
2234    
2235 alfonx 544 if (errStr == null)
2236     errStr = ex.getMessage();
2237     if (errStr == null)
2238     errStr = "unknown error: " + ex.getClass().getSimpleName();
2239    
2240 alfonx 560 graphics.setColor(getMapBackgroundColor());
2241 alfonx 533 graphics.drawString(errStr, 5, y);
2242     graphics.setColor(Color.RED);
2243     graphics.drawString(errStr, 6, y + 1);
2244    
2245     y += 19;
2246     }
2247    
2248     graphics.setColor(c);
2249     }
2250    
2251 alfonx 505 }
2252    
2253     /**
2254 alfonx 533 * Sets the {@link #mapArea} to best possibly present the given features. If
2255     * only one single point is given, the window is moved over the point.
2256 alfonx 509 *
2257 alfonx 530 * @param features
2258     * if <code>null</code> or size==0, the function doesn nothing.
2259 alfonx 509 */
2260 alfonx 530 public void zoomTo(
2261     final FeatureCollection<SimpleFeatureType, SimpleFeature> features) {
2262 alfonx 509
2263 alfonx 551 // if (!isWellDefined()) return;
2264    
2265     final CoordinateReferenceSystem mapCRS = getMapContext()
2266 alfonx 530 .getCoordinateReferenceSystem();
2267     final CoordinateReferenceSystem fCRS = features.getSchema()
2268     .getGeometryDescriptor().getCoordinateReferenceSystem();
2269 alfonx 509
2270 alfonx 551 ReferencedEnvelope _mapArea;
2271     if (mapArea == null)
2272     _mapArea = features.getBounds();
2273 alfonx 555 else
2274     _mapArea = getMapArea();
2275 alfonx 551 double width = _mapArea.getWidth();
2276     double height = _mapArea.getHeight();
2277 alfonx 530 final double ratio = height / width;
2278 alfonx 509
2279 alfonx 530 if (features == null || features.size() == 0) {
2280     // feature count == 0 Zoom to the full extend
2281 alfonx 509 return;
2282 alfonx 530 } else if (features.size() == 1) {
2283 alfonx 529
2284 alfonx 530 // feature count == 1 Just move the window to the point and zoom 'a
2285     // bit'
2286     final SimpleFeature singleFeature = features.iterator().next();
2287 alfonx 509
2288 alfonx 530 if (((Geometry) singleFeature.getDefaultGeometry())
2289     .getCoordinates().length > 1) {
2290     // System.out.println("Zoomed to only pne poylgon");
2291     // Poly
2292     // TODO max width vs. height
2293     width = features.getBounds().getWidth() * 3;
2294     height = ratio * width;
2295     } else {
2296     // System.out.println("Zoomed in a bit becasue only one point");
2297     // width *= .9;
2298     // height *= .9;
2299     }
2300 alfonx 509
2301 alfonx 530 Coordinate centre = features.getBounds().centre();
2302     if (!mapCRS.equals(fCRS)) {
2303     // only to calculations if the CRS differ
2304 alfonx 529 try {
2305 alfonx 530 MathTransform fToMap;
2306     fToMap = CRS.findMathTransform(fCRS, mapCRS);
2307     // centre is transformed to the mapCRS
2308     centre = JTS.transform(centre, null, fToMap);
2309     } catch (final FactoryException e) {
2310     LOGGER.error("Looking for a Math transform", e);
2311     } catch (final TransformException e) {
2312     LOGGER.error("Looking for a Math transform", e);
2313 alfonx 529 }
2314     }
2315 alfonx 509
2316 alfonx 530 final Coordinate newLeftBottom = new Coordinate(centre.x - width
2317     / 2., centre.y - height / 2.);
2318     final Coordinate newTopRight = new Coordinate(
2319     centre.x + width / 2., centre.y + height / 2.);
2320 alfonx 509
2321 alfonx 530 final Envelope newMapArea = new Envelope(newLeftBottom, newTopRight);
2322 alfonx 509
2323 alfonx 530 setMapArea(newMapArea);
2324 alfonx 529
2325 alfonx 530 } else {
2326     final ReferencedEnvelope fBounds = features.getBounds();
2327 alfonx 529
2328 alfonx 551 ReferencedEnvelope bounds;
2329 alfonx 530 if (!mapCRS.equals(fCRS)) {
2330 alfonx 551 bounds = JTSUtil.transformEnvelope(fBounds, mapCRS);
2331 alfonx 530 } else {
2332     bounds = fBounds;
2333     }
2334     // BB umrechnen von Layer-CRS in Map-CRS
2335 alfonx 529
2336 alfonx 530 // Expand a bit
2337     bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.);
2338 alfonx 509
2339 alfonx 530 setMapArea(bounds);
2340     }
2341 alfonx 509 }
2342    
2343     /**
2344 alfonx 530 * Zooms towards a point.
2345     *
2346     * @param center
2347     * position in window coordinates
2348     * @param zoomFactor
2349     * > 1 for zoom in, < 1 for zoom out. Default is 1.33
2350 alfonx 509 */
2351 alfonx 530 public void zoomTo(final Point center) {
2352     zoomTo(center, null);
2353 alfonx 509 }
2354    
2355     /**
2356     * Zooms towards a point.
2357     *
2358     * @param center
2359     * position in window coordinates
2360     * @param zoomFaktor
2361     * > 1 for zoom in, < 1 for zoom out. Default is 1.33.
2362     */
2363     public void zoomTo(Point center, Double zoomFaktor) {
2364     if (zoomFaktor == null || zoomFaktor == 0.)
2365     zoomFaktor = 2.;
2366    
2367 alfonx 530 final Point2D gcenter = getScreenToWorld().transform(center, null);
2368 alfonx 509 center = null;
2369 alfonx 513
2370     if (Double.isNaN(gcenter.getX()) || Double.isNaN(gcenter.getY())
2371     || Double.isInfinite(gcenter.getX())
2372     || Double.isInfinite(gcenter.getY())
2373    
2374 alfonx 509 ) {
2375     // Not inside valid CRS area! cancel
2376     return;
2377     }
2378    
2379     final Envelope mapArea = getMapArea();
2380 alfonx 513
2381 alfonx 530 final Envelope newMapArea = new Envelope(mapArea);
2382 alfonx 513 newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
2383     .getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
2384     .getHeight()) / 2.);
2385 alfonx 509
2386 alfonx 543 // TODO we actually want that
2387     // // Move the newMapArea above the new center
2388     // newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
2389     // .getY()
2390     // - mapArea.centre().y);
2391    
2392 alfonx 509 setMapArea(newMapArea);
2393     }
2394    
2395 alfonx 553 /**
2396     * Shall non-fatal rendering exceptions be reported in the mappane or be
2397     * dropped quitely.
2398     */
2399     public void setShowExceptions(boolean showExceptions) {
2400     this.showExceptions = showExceptions;
2401     }
2402    
2403     /**
2404     * Shall exceptions be reported in the mappane?
2405     */
2406     public boolean isShowExceptions() {
2407     return showExceptions;
2408     }
2409    
2410 alfonx 560 public GTRenderer getLocalRenderer() {
2411     return localRenderer;
2412     }
2413    
2414 mojays 2 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26