26 |
import java.util.Map; |
import java.util.Map; |
27 |
import java.util.Vector; |
import java.util.Vector; |
28 |
|
|
29 |
|
import javax.jws.soap.SOAPBinding.Style; |
30 |
import javax.swing.Timer; |
import javax.swing.Timer; |
31 |
|
import javax.swing.border.Border; |
32 |
|
|
33 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
34 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
142 |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
143 |
* with previews. |
* with previews. |
144 |
*/ |
*/ |
145 |
public static final int REPEATING_REPAINT_DELAY = 600; |
public static final int REPEATING_REPAINT_DELAY = 500; |
146 |
|
|
147 |
/** |
/** |
148 |
* Default delay (milliseconds) before the map will be redrawn when resizing |
* Default delay (milliseconds) before the map will be redrawn when resizing |
397 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
398 |
event.getLayer().addMapLayerListener(localMapLayerListener); |
event.getLayer().addMapLayerListener(localMapLayerListener); |
399 |
|
|
400 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
401 |
requestStartRendering(); |
requestStartRendering(); |
402 |
|
|
403 |
} |
} |
404 |
|
|
405 |
@Override |
@Override |
406 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
407 |
localRenderer.setContext(getMapContext()); |
// localRenderer = GTUtil.createGTRenderer(); |
408 |
|
getLocalRenderer().setContext(getMapContext()); |
409 |
requestStartRendering(); |
requestStartRendering(); |
410 |
} |
} |
411 |
|
|
412 |
@Override |
@Override |
413 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
414 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
415 |
requestStartRendering(); |
requestStartRendering(); |
416 |
} |
} |
417 |
|
|
419 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
420 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
421 |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
422 |
localRenderer.setContext(getMapContext()); |
getLocalRenderer().setContext(getMapContext()); |
423 |
requestStartRendering(); |
requestStartRendering(); |
424 |
} |
} |
425 |
}; |
}; |
432 |
|
|
433 |
@Override |
@Override |
434 |
public void layerChanged(final MapLayerEvent event) { |
public void layerChanged(final MapLayerEvent event) { |
435 |
localRenderer.setContext(getMapContext()); // betters for SLD |
getLocalRenderer().setContext(getMapContext()); // betters for SLD |
436 |
// changes?! |
// changes?! |
437 |
requestStartRendering(); |
requestStartRendering(); |
438 |
} |
} |
448 |
} |
} |
449 |
}; |
}; |
450 |
|
|
451 |
private final GTRenderer localRenderer = GTUtil.createGTRenderer(); |
final private GTRenderer localRenderer = GTUtil.createGTRenderer(); |
452 |
|
|
453 |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
454 |
|
|
469 |
/** |
/** |
470 |
* This color is used as the default background color when painting a map. |
* This color is used as the default background color when painting a map. |
471 |
*/ |
*/ |
472 |
private Color mapBackgroundColor = Color.WHITE; |
private Color mapBackgroundColor = null; |
473 |
|
|
474 |
/** |
/** |
475 |
* A flag indicating that the shown image is invalid and needs to be |
* A flag indicating that the shown image is invalid and needs to be |
521 |
private int quickPreviewHint = 0; |
private int quickPreviewHint = 0; |
522 |
|
|
523 |
private Map<Object, Object> rendererHints = GTUtil |
private Map<Object, Object> rendererHints = GTUtil |
524 |
.getDefaultGTRendererHints(localRenderer); |
.getDefaultGTRendererHints(getLocalRenderer()); |
525 |
|
|
526 |
/** |
/** |
527 |
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
619 |
if (!isWellDefined()) |
if (!isWellDefined()) |
620 |
return; |
return; |
621 |
|
|
622 |
LOGGER.info("resizeTimer performed"); |
LOGGER.debug("resizeTimer performed"); |
623 |
|
|
624 |
final Rectangle bounds = getVisibleRect(); |
final Rectangle bounds = getVisibleRect(); |
625 |
// |
// |
631 |
bounds.y + bounds.height); |
bounds.y + bounds.height); |
632 |
|
|
633 |
if (setMapArea(geoMapArea)) { |
if (setMapArea(geoMapArea)) { |
634 |
LOGGER.info(" maparea changed"); |
LOGGER.debug(" maparea changed"); |
635 |
paneResized = true; |
paneResized = true; |
636 |
} else |
} else |
637 |
LOGGER.info(" maparea NOT changed"); |
LOGGER.debug(" maparea NOT changed"); |
638 |
} |
} |
639 |
}); |
}); |
640 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
646 |
@Override |
@Override |
647 |
public void componentResized(final ComponentEvent e) { |
public void componentResized(final ComponentEvent e) { |
648 |
|
|
649 |
// Seems to be called twice with the same size.. |
// Seems to be called twice with the same size.. |
650 |
if (oldVisibleRect != null |
if (oldVisibleRect != null |
651 |
&& oldVisibleRect.equals(getVisibleRect())){ |
&& oldVisibleRect.equals(getVisibleRect())) { |
652 |
LOGGER.info("skipping resize."); |
LOGGER.debug("skipping resize."); |
653 |
return; |
return; |
654 |
} |
} |
655 |
|
|
656 |
LOGGER.info("resized: " + getVisibleRect()); |
LOGGER.debug("resized: " + getVisibleRect()); |
657 |
resizeTimer.restart(); |
resizeTimer.restart(); |
658 |
oldVisibleRect = getVisibleRect(); |
oldVisibleRect = getVisibleRect(); |
659 |
} |
} |
1149 |
} |
} |
1150 |
|
|
1151 |
/** |
/** |
1152 |
* Returns the background {@link Color} of the map pane. Default is white. |
* Returns the background {@link Color} of the map pane. If not set, the |
1153 |
|
* methods looks for a parent component and will use its background color. |
1154 |
|
* If no parent component is available, WHITE is returned. |
1155 |
**/ |
**/ |
1156 |
public Color getMapBackgroundColor() { |
public Color getMapBackgroundColor() { |
1157 |
|
if (mapBackgroundColor == null) { |
1158 |
|
if (getParent() != null) |
1159 |
|
return getParent().getBackground(); |
1160 |
|
else |
1161 |
|
return Color.WHITE; |
1162 |
|
} |
1163 |
return mapBackgroundColor; |
return mapBackgroundColor; |
1164 |
} |
} |
1165 |
|
|
1429 |
* completed. |
* completed. |
1430 |
*/ |
*/ |
1431 |
public void onRenderingCompleted() { |
public void onRenderingCompleted() { |
1432 |
LOGGER.info("complete"); |
LOGGER.debug("complete"); |
1433 |
|
|
1434 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1435 |
|
|
1482 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1483 |
return; |
return; |
1484 |
|
|
1485 |
// super.paintComponent(g); // candidate for removal |
// super.paintComponent(g); // candidate for removal |
1486 |
|
|
1487 |
boolean paintedSomething = false; |
boolean paintedSomething = false; |
1488 |
|
|
1708 |
|
|
1709 |
// setMapArea(localContext.getAreaOfInterest()); |
// setMapArea(localContext.getAreaOfInterest()); |
1710 |
|
|
1711 |
localRenderer.setContext(localContext); |
getLocalRenderer().setContext(localContext); |
1712 |
|
|
1713 |
this.localContext.addMapLayerListListener(localContextListener); |
this.localContext.addMapLayerListListener(localContextListener); |
1714 |
|
|
1721 |
requestStartRendering(); |
requestStartRendering(); |
1722 |
|
|
1723 |
} |
} |
1724 |
|
|
1725 |
|
public void setBorder(Border b) { |
1726 |
|
super.setBorder(b); |
1727 |
|
} |
1728 |
|
|
1729 |
|
/** |
1730 |
|
* Triggers to repaint (fast) and re-render (slow) the JMapPane. |
1731 |
|
*/ |
1732 |
|
public void refresh() { |
1733 |
|
mapImageInvalid = true; |
1734 |
|
repaint(); |
1735 |
|
} |
1736 |
|
|
1737 |
|
// /** |
1738 |
|
// * Triggers to use new {@link GTRenderer} and refresh the map. Should be |
1739 |
|
// * called after {@link Style}s have been changed because GTRenderer is |
1740 |
|
// * otherwise not working well. |
1741 |
|
// */ |
1742 |
|
// public void refreshRenderers() { |
1743 |
|
// localRenderer = GTUtil.createGTRenderer(); |
1744 |
|
// setLocalContext(getMapContext()); |
1745 |
|
// mapImageInvalid = true; |
1746 |
|
// repaint(); |
1747 |
|
// } |
1748 |
|
|
1749 |
|
/** |
1750 |
|
* Set the new map area. |
1751 |
|
* @param newMapArea |
1752 |
|
* @return <code>true</code> if the mapArea has been changed and a repaint |
1753 |
|
* has been triggered. |
1754 |
|
*/ |
1755 |
public boolean setMapArea(final Envelope newMapArea) { |
public boolean setMapArea(final Envelope newMapArea) { |
1756 |
|
if (newMapArea == null) |
1757 |
|
return false; |
1758 |
|
if (getMapContext().getCoordinateReferenceSystem() == null) |
1759 |
|
return false; |
1760 |
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
1761 |
.getCoordinateReferenceSystem())); |
.getCoordinateReferenceSystem())); |
1762 |
} |
} |
1763 |
|
|
1764 |
/** |
/** |
1765 |
|
* Set the new map area. |
1766 |
* @param newMapArea |
* @param newMapArea |
1767 |
* @return <code>true</code> if the mapArea has been changed and a repaint |
* @return <code>true</code> if the mapArea has been changed and a repaint |
1768 |
* has been triggered. |
* has been triggered. |
1838 |
* @param if <code>null</code>, white is used. |
* @param if <code>null</code>, white is used. |
1839 |
*/ |
*/ |
1840 |
public void setMapBackgroundColor(Color bgColor) { |
public void setMapBackgroundColor(Color bgColor) { |
|
if (bgColor == null) |
|
|
bgColor = Color.WHITE; |
|
1841 |
this.mapBackgroundColor = bgColor; |
this.mapBackgroundColor = bgColor; |
1842 |
} |
} |
1843 |
|
|
2003 |
// localExecuter = new RenderingExecutor(this, 150l); |
// localExecuter = new RenderingExecutor(this, 150l); |
2004 |
// LOGGER.debug("starting local renderer:"); |
// LOGGER.debug("starting local renderer:"); |
2005 |
|
|
2006 |
localRenderer.setJava2DHints(getJava2dHints()); |
getLocalRenderer().setJava2DHints(getJava2dHints()); |
2007 |
localRenderer.setRendererHints(getRendererHints()); |
getLocalRenderer().setRendererHints(getRendererHints()); |
2008 |
|
|
2009 |
final boolean submitted = localExecuter.submit(getMapArea(), |
final boolean submitted = localExecuter.submit(getMapArea(), |
2010 |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
2011 |
localRenderer); |
getLocalRenderer()); |
2012 |
if (submitted) |
if (submitted) |
2013 |
repaintTimer.restart(); |
repaintTimer.restart(); |
2014 |
else |
else |
2230 |
if (errStr == null) |
if (errStr == null) |
2231 |
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
2232 |
|
|
2233 |
graphics.setColor(Color.WHITE); |
graphics.setColor(getMapBackgroundColor()); |
2234 |
graphics.drawString(errStr, 5, y); |
graphics.drawString(errStr, 5, y); |
2235 |
graphics.setColor(Color.RED); |
graphics.setColor(Color.RED); |
2236 |
graphics.drawString(errStr, 6, y + 1); |
graphics.drawString(errStr, 6, y + 1); |
2400 |
return showExceptions; |
return showExceptions; |
2401 |
} |
} |
2402 |
|
|
2403 |
|
public GTRenderer getLocalRenderer() { |
2404 |
|
return localRenderer; |
2405 |
|
} |
2406 |
|
|
2407 |
} |
} |