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; |
100 |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
101 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
102 |
|
|
103 |
private static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
104 |
|
|
105 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
106 |
|
|
135 |
* The initial delay in milliseconds until the {@link #finalImage} is |
* The initial delay in milliseconds until the {@link #finalImage} is |
136 |
* updated the first time. |
* updated the first time. |
137 |
*/ |
*/ |
138 |
public static final int INITIAL_REPAINT_DELAY = 1000; |
public static final int INITIAL_REPAINT_DELAY = 900; |
139 |
|
|
140 |
/** |
/** |
141 |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
152 |
*/ |
*/ |
153 |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
154 |
|
|
155 |
|
/** |
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 |
private final Timer resizeTimer; |
private final Timer resizeTimer; |
162 |
|
|
163 |
|
/** |
164 |
|
* Flag for no-tool. |
165 |
|
*/ |
166 |
public static final int NONE = -123; |
public static final int NONE = -123; |
167 |
|
|
168 |
/** |
/** |
174 |
public static final int PAN = 1; |
public static final int PAN = 1; |
175 |
|
|
176 |
/** |
/** |
177 |
|
* 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 |
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
193 |
* |
* |
194 |
* @see #setState(int) |
* @see #setState(int) |
212 |
*/ |
*/ |
213 |
public static final int SELECT_TOP = 4; |
public static final int SELECT_TOP = 4; |
214 |
|
|
|
public static final Cursor WAIT_CURSOR = Cursor |
|
|
.getPredefinedCursor(Cursor.WAIT_CURSOR); |
|
|
|
|
215 |
/** |
/** |
216 |
* {@link Font} used to paint the wait messages into the map |
* {@link Font} used to paint the wait messages into the map |
217 |
* |
* |
235 |
final String waitMsg = SwingUtil.R("WaitMess"); |
final String waitMsg = SwingUtil.R("WaitMess"); |
236 |
|
|
237 |
/** |
/** |
|
* Flag fuer Modus "Heran zoomen". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int ZOOM_IN = 2; |
|
|
|
|
|
/** |
|
|
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
|
|
* |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int ZOOM_OUT = 3; |
|
|
|
|
|
/** |
|
238 |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
239 |
* Karten-Koordinaten. |
* Karten-Koordinaten. |
240 |
* |
* |
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 changes?! |
getLocalRenderer().setContext(getMapContext()); // betters for SLD |
436 |
|
// changes?! |
437 |
requestStartRendering(); |
requestStartRendering(); |
438 |
} |
} |
439 |
|
|
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 |
513 |
* A flag indicating, that the image size has changed and the buffered |
* A flag indicating, that the image size has changed and the buffered |
514 |
* images are not big enough any more |
* images are not big enough any more |
515 |
**/ |
**/ |
516 |
protected boolean paneResized = false; |
protected boolean paneResized = true; |
517 |
|
|
518 |
private BufferedImage preFinalImage; |
private BufferedImage preFinalImage; |
519 |
|
|
520 |
// if null, no quick preview will be shown |
// ** if 0, no quick preview will be shown **/ |
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 |
565 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
566 |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
567 |
|
|
568 |
// /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet |
/** |
569 |
// defined, but we are **/ |
* If <code>true</code>, then rendering exceptions are rendererd into the |
570 |
// private Envelope mapAreaCondidate = null; |
* map pane |
571 |
|
**/ |
572 |
|
private boolean showExceptions = false; |
573 |
|
|
574 |
public XMapPane() { |
public XMapPane() { |
575 |
this(null, null); |
this(null, null); |
619 |
if (!isWellDefined()) |
if (!isWellDefined()) |
620 |
return; |
return; |
621 |
|
|
622 |
|
LOGGER.debug("resizeTimer performed"); |
623 |
|
|
624 |
final Rectangle bounds = getVisibleRect(); |
final Rectangle bounds = getVisibleRect(); |
625 |
// |
// |
626 |
// System.out.println("\n\ntimer performs with bounds = " |
// System.out.println("\n\ntimer performs with bounds = " |
630 |
bounds.x, bounds.y, bounds.x + bounds.width, |
bounds.x, bounds.y, bounds.x + bounds.width, |
631 |
bounds.y + bounds.height); |
bounds.y + bounds.height); |
632 |
|
|
633 |
if (setMapArea(geoMapArea)) |
if (setMapArea(geoMapArea)) { |
634 |
|
LOGGER.debug(" maparea changed"); |
635 |
paneResized = true; |
paneResized = true; |
636 |
// else |
} else |
637 |
// syso |
LOGGER.debug(" maparea NOT changed"); |
638 |
} |
} |
639 |
}); |
}); |
640 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
641 |
|
|
642 |
this.addComponentListener(new ComponentAdapter() { |
this.addComponentListener(new ComponentAdapter() { |
643 |
|
|
644 |
|
private Rectangle oldVisibleRect; |
645 |
|
|
646 |
@Override |
@Override |
647 |
public void componentResized(final ComponentEvent e) { |
public void componentResized(final ComponentEvent e) { |
648 |
|
|
649 |
// Already cancel the tasks... |
// Seems to be called twice with the same size.. |
650 |
if (bgExecuter != null) |
if (oldVisibleRect != null |
651 |
bgExecuter.cancelTask(); |
&& oldVisibleRect.equals(getVisibleRect())) { |
652 |
if (localExecuter != null) |
LOGGER.debug("skipping resize."); |
653 |
localExecuter.cancelTask(); |
return; |
654 |
|
} |
655 |
|
|
656 |
|
LOGGER.debug("resized: " + getVisibleRect()); |
657 |
resizeTimer.restart(); |
resizeTimer.restart(); |
658 |
|
oldVisibleRect = getVisibleRect(); |
659 |
} |
} |
660 |
|
|
661 |
}); |
}); |
667 |
|
|
668 |
@Override |
@Override |
669 |
public void actionPerformed(final ActionEvent e) { |
public void actionPerformed(final ActionEvent e) { |
670 |
if ((localExecuter != null && !localExecuter.isRunning()) |
if ((!localExecuter.isRunning()) |
671 |
&& (bgExecuter != null && !bgExecuter.isRunning())) { |
&& (bgExecuter != null && !bgExecuter.isRunning())) { |
672 |
repaintTimer.stop(); |
repaintTimer.stop(); |
673 |
} else { |
} else { |
674 |
updateFinalImage(); |
updateFinalImage(); |
675 |
XMapPane.this.repaint(100); |
XMapPane.this.repaint(100); |
676 |
|
|
677 |
} |
} |
678 |
} |
} |
679 |
}); |
}); |
680 |
|
|
681 |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
682 |
repaintTimer.setRepeats(true); |
repaintTimer.setRepeats(true); |
683 |
|
|
695 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
696 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
697 |
} else { |
} else { |
|
|
|
698 |
// Stupidly, but we have to recheck the |
// Stupidly, but we have to recheck the |
699 |
setMapArea(getMapArea()); |
setMapArea(getMapArea()); |
700 |
requestStartRendering = false; |
requestStartRendering = false; |
783 |
} |
} |
784 |
|
|
785 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
786 |
|
|
787 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
788 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
789 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
928 |
bgExecuter.dispose(); |
bgExecuter.dispose(); |
929 |
} |
} |
930 |
|
|
931 |
if (localExecuter != null) { |
if (localExecuter.isRunning()) { |
932 |
int i = 0; |
int i = 0; |
933 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
934 |
while (i++ < 10 && localExecuter.isRunning()) { |
while (i++ < 10 && localExecuter.isRunning()) { |
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 |
|
|
1187 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1188 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1189 |
// Commented-out because it takes soo much time! |
// Commented-out because it takes soo much time! |
1190 |
// |
// |
1191 |
// long start = System.currentTimeMillis(); |
// long start = System.currentTimeMillis(); |
1192 |
// final ReferencedEnvelope layerBounds = GTUtil |
// final ReferencedEnvelope layerBounds = GTUtil |
1193 |
// .getVisibleLayoutBounds(localContext); |
// .getVisibleLayoutBounds(localContext); |
1194 |
// |
// |
1195 |
// LOGGER.info( (System.currentTimeMillis()-start)+"m to get maxExtend"); |
// LOGGER.info( |
1196 |
// |
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
1197 |
// if (layerBounds == null) { |
// |
1198 |
// // TODO Last fallback could be the CRS valid area |
// if (layerBounds == null) { |
1199 |
// return null; |
// // TODO Last fallback could be the CRS valid area |
1200 |
// } |
// return null; |
1201 |
// |
// } |
1202 |
// // Kartenbereich um 10% vergroessern |
// |
1203 |
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
// // Kartenbereich um 10% vergroessern |
1204 |
// .expandEnvelope(layerBounds, 0.1), true); |
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
1205 |
|
// .expandEnvelope(layerBounds, 0.1), true); |
1206 |
} |
} |
1207 |
return maxExtend; |
return maxExtend; |
1208 |
} |
} |
1333 |
return true; |
return true; |
1334 |
} |
} |
1335 |
|
|
1336 |
|
/** |
1337 |
|
* Called from the listeners while the mouse is dragging, this method either |
1338 |
|
* paints a translated (moved/panned) version of the image, or a rectangle. |
1339 |
|
* |
1340 |
|
* @param startPos |
1341 |
|
* in screen coordinates |
1342 |
|
* @param lastPos |
1343 |
|
* in screen coordinates |
1344 |
|
* @param event |
1345 |
|
* the {@link MouseEvent} to read the mouse buttons from |
1346 |
|
*/ |
1347 |
public void mouseDragged(final Point startPos, final Point lastPos, |
public void mouseDragged(final Point startPos, final Point lastPos, |
1348 |
final MouseEvent event) { |
final MouseEvent event) { |
1349 |
|
|
1350 |
if ((getState() == XMapPane.PAN) |
if ((getState() == XMapPane.PAN) |
1351 |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
1352 |
|
|
1353 |
|
// Panning needs a panning coursor |
1354 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1355 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1356 |
|
|
1357 |
// While panning, we deactivate the rendering. So the tasts are |
// While panning, we deactivate the rendering. So the tasks are |
1358 |
// ready to start when the panning os done. |
// ready to start when the panning is finished. |
1359 |
if (bgExecuter != null) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1360 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1361 |
if (localExecuter != null) |
if (localExecuter.isRunning()) |
1362 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1363 |
} |
} |
1364 |
|
|
1405 |
} else if ((getState() == XMapPane.ZOOM_IN) |
} else if ((getState() == XMapPane.ZOOM_IN) |
1406 |
|| (getState() == XMapPane.ZOOM_OUT) |
|| (getState() == XMapPane.ZOOM_OUT) |
1407 |
|| (getState() == XMapPane.SELECT_ALL) |
|| (getState() == XMapPane.SELECT_ALL) |
1408 |
|| (getState() == XMapPane.SELECT_TOP) |
|| (getState() == XMapPane.SELECT_TOP)) { |
|
// || (getState() == XMapPane.SELECT_ONE_FROM_TOP) |
|
|
) { |
|
|
final Graphics graphics = getGraphics(); |
|
1409 |
|
|
1410 |
|
// Draws a rectangle |
1411 |
|
final Graphics graphics = getGraphics(); |
1412 |
drawRectangle(graphics, startPos, event.getPoint()); |
drawRectangle(graphics, startPos, event.getPoint()); |
1413 |
|
if ((lastPos.x > 0) && (lastPos.y > 0)) |
|
if ((lastPos.x > 0) && (lastPos.y > 0)) { |
|
1414 |
drawRectangle(graphics, startPos, lastPos); |
drawRectangle(graphics, startPos, lastPos); |
|
} |
|
|
|
|
1415 |
graphics.dispose(); |
graphics.dispose(); |
|
|
|
1416 |
} |
} |
|
|
|
1417 |
} |
} |
1418 |
|
|
1419 |
/** |
/** |
1429 |
* completed. |
* completed. |
1430 |
*/ |
*/ |
1431 |
public void onRenderingCompleted() { |
public void onRenderingCompleted() { |
1432 |
|
LOGGER.debug("complete"); |
1433 |
|
|
1434 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1435 |
updateFinalImage(); |
|
1436 |
repaint(); |
// We "forget" about an exception every time we complete a rendering |
1437 |
|
// thread successfully |
1438 |
if (renderingErrors.size() > 0) |
if (renderingErrors.size() > 0) |
1439 |
renderingErrors.remove(0); |
renderingErrors.remove(0); |
1440 |
|
|
1441 |
|
updateFinalImage(); |
1442 |
|
repaint(); |
1443 |
} |
} |
1444 |
|
|
1445 |
/** |
/** |
1453 |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
1454 |
*/ |
*/ |
1455 |
public void onRenderingFailed(final Exception renderingError) { |
public void onRenderingFailed(final Exception renderingError) { |
1456 |
this.renderingErrors.add(renderingError); |
|
1457 |
|
// Store the exceptions so we can show it to the user: |
1458 |
|
if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError |
1459 |
|
.getMessage().equals( |
1460 |
|
"Argument \"sourceCRS\" should not be null."))) |
1461 |
|
this.renderingErrors.add(renderingError); |
1462 |
if (renderingErrors.size() > 3) |
if (renderingErrors.size() > 3) |
1463 |
renderingErrors.remove(0); |
renderingErrors.remove(0); |
1464 |
|
|
1465 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1466 |
|
|
1467 |
LOGGER.warn("Rendering failed", renderingError); |
LOGGER.warn("Rendering failed", renderingError); |
1468 |
updateFinalImage(); |
updateFinalImage(); |
1469 |
repaint(); |
repaint(); |
1470 |
|
|
1471 |
} |
} |
1472 |
|
|
|
public void onRenderingPending() { |
|
|
// LOGGER.debug("Pending rendering updates the preview..."); |
|
|
updateFinalImage(); |
|
|
repaint(); |
|
|
} |
|
|
|
|
1473 |
@Override |
@Override |
1474 |
protected void paintComponent(final Graphics g) { |
protected void paintComponent(final Graphics g) { |
1475 |
|
|
1476 |
|
// Maybe update the cursor and maybe stop the repainting timer |
1477 |
|
updateCursor(); |
1478 |
|
|
1479 |
if (!acceptsRepaintCalls) |
if (!acceptsRepaintCalls) |
1480 |
return; |
return; |
1481 |
|
|
1482 |
// Maybe update the cursor and maybe stop the repainting timer |
if (!isWellDefined()) |
1483 |
updateCursor(); |
return; |
1484 |
|
|
1485 |
// super.paintComponent(g); // candidate for removal |
// super.paintComponent(g); // candidate for removal |
1486 |
|
|
1487 |
boolean paintedSomething = false; |
boolean paintedSomething = false; |
1488 |
|
|
1500 |
mapAreaChanged = false; |
mapAreaChanged = false; |
1501 |
|
|
1502 |
if (getMapArea().covers(oldMapArea)) { |
if (getMapArea().covers(oldMapArea)) { |
1503 |
setQuickPreviewHint(ZOOM_OUT); |
quickPreviewHint = ZOOM_OUT; |
1504 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1505 |
} else if (oldMapArea.covers(getMapArea())) { |
} else if (oldMapArea.covers(getMapArea())) { |
1506 |
setQuickPreviewHint(ZOOM_IN); |
quickPreviewHint = ZOOM_IN; |
1507 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1508 |
} |
} |
|
|
|
1509 |
} |
} |
|
|
|
|
// if (paneResized) { |
|
|
// paneResized = false; |
|
|
// disposeImages(); |
|
|
// } |
|
|
// |
|
|
// // Start the Threads and Timers to render the image |
|
|
// requestStartRendering(); |
|
|
|
|
1510 |
} |
} |
1511 |
|
|
1512 |
if (!paintedSomething) { |
if (!paintedSomething) { |
1594 |
setCursor(SwingUtil.PAN_CURSOR); |
setCursor(SwingUtil.PAN_CURSOR); |
1595 |
} |
} |
1596 |
|
|
|
// |
|
|
// /** |
|
|
// * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot |
|
|
// gemacht |
|
|
// * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
|
|
// * |
|
|
// * @author <a href="mailto:[email protected]">Stefan Alfons |
|
|
// * Krüger</a> |
|
|
// */ |
|
|
// @Override |
|
|
// public void print(final Graphics g) { |
|
|
// final Color orig = getBackground(); |
|
|
// setBackground(Color.WHITE); |
|
|
// |
|
|
// // wrap in try/finally so that we always restore the state |
|
|
// try { |
|
|
// super.print(g); |
|
|
// } finally { |
|
|
// setBackground(orig); |
|
|
// } |
|
|
// } |
|
|
|
|
1597 |
/** |
/** |
1598 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1599 |
* |
* |
1612 |
private void requestStartRendering() { |
private void requestStartRendering() { |
1613 |
if (bgExecuter != null) |
if (bgExecuter != null) |
1614 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1615 |
if (localExecuter != null) |
|
1616 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1617 |
|
|
1618 |
mapImageInvalid = true; |
mapImageInvalid = true; |
1619 |
if (paneResized) { |
if (paneResized) { |
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. |
1769 |
*/ |
*/ |
1770 |
public boolean setMapArea(final ReferencedEnvelope newMapArea) { |
public boolean setMapArea(final ReferencedEnvelope newMapArea) { |
|
// |
|
|
// if (getVisibleRect().getWidth() == 0 || (!isVisible()) || |
|
|
// getVisibleRect().getHeight() == 0) { |
|
|
// // The window is not yet defined.. so we can not really determine the |
|
|
// asepect ratio for the mapPane. We store this as a candidate mappane |
|
|
// and handle it when the component resizes or becomes visible) |
|
|
// mapAreaCondidate = newMapArea; |
|
|
// } |
|
1771 |
|
|
1772 |
if (newMapArea == null |
if (newMapArea == null |
1773 |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
1825 |
|
|
1826 |
mapAreaChanged = true; |
mapAreaChanged = true; |
1827 |
|
|
1828 |
repaint(100); |
repaint(200); // Do not remove it! |
1829 |
|
|
1830 |
requestStartRendering(); |
requestStartRendering(); |
1831 |
|
|
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 |
|
|
1912 |
} |
} |
1913 |
|
|
1914 |
/** |
/** |
1915 |
* |
* If <code>true</code>, allow the {@link XMapPane} to process #repaint() |
1916 |
* @param b |
* requests. Otherwise the map will not paint anything and not start any |
1917 |
|
* rendering {@link Thread}s. |
1918 |
*/ |
*/ |
1919 |
public void setPainting(final boolean b) { |
public void setPainting(final boolean b) { |
1920 |
acceptsRepaintCalls = b; |
acceptsRepaintCalls = b; |
1921 |
} |
if (acceptsRepaintCalls == true) |
1922 |
|
repaint(); |
|
// /** |
|
|
// * Returns in milli seconds the time the last rending of the |
|
|
// * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has |
|
|
// not |
|
|
// * been rendered yet. |
|
|
// */ |
|
|
// public long getLastRenderingDuration() { |
|
|
// return lastRenderingDuration; |
|
|
// } |
|
|
|
|
|
public void setQuickPreviewHint(final int quickPreviewHint) { |
|
|
this.quickPreviewHint = quickPreviewHint; |
|
|
|
|
1923 |
} |
} |
1924 |
|
|
1925 |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
1965 |
private void startRendering() { |
private void startRendering() { |
1966 |
|
|
1967 |
if (!isWellDefined() || !acceptsRepaintCalls) { |
if (!isWellDefined() || !acceptsRepaintCalls) { |
1968 |
|
// if we are not ready to start rendering, try it again the next |
1969 |
|
// time the timer is chacking the flag. |
1970 |
requestStartRendering = true; |
requestStartRendering = true; |
1971 |
return; |
return; |
1972 |
} |
} |
1976 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1977 |
} |
} |
1978 |
|
|
1979 |
if (localExecuter != null) { |
localExecuter.cancelTask(); |
|
localExecuter.cancelTask(); |
|
|
} |
|
1980 |
|
|
1981 |
final Rectangle curPaintArea = getVisibleRect(); |
final Rectangle curPaintArea = getVisibleRect(); |
1982 |
|
|
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()); |
|
// , getWorldToScreenTransform() |
|
|
); |
|
2012 |
if (submitted) |
if (submitted) |
2013 |
repaintTimer.restart(); |
repaintTimer.restart(); |
2014 |
else |
else |
2083 |
// if the renderers have stopped, also stop the timer that is updating |
// if the renderers have stopped, also stop the timer that is updating |
2084 |
// the final image |
// the final image |
2085 |
if (bgExecuter != null && bgExecuter.isRunning() |
if (bgExecuter != null && bgExecuter.isRunning() |
2086 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2087 |
setCursor(WAIT_CURSOR); |
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
2088 |
return; |
return; |
2089 |
} else { |
} else { |
2090 |
// Allow one last rendering |
// Allow one last rendering |
2197 |
|
|
2198 |
// If the rendering process is still running, indicate this is the image |
// If the rendering process is still running, indicate this is the image |
2199 |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
2200 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2201 |
|
|
2202 |
y += 8; |
y += 8; |
2203 |
|
|
2216 |
y += 24; |
y += 24; |
2217 |
} |
} |
2218 |
|
|
2219 |
if (renderingErrors != null) { |
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
2220 |
|
|
2221 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2222 |
graphics.setFont(errorFont); |
graphics.setFont(errorFont); |
2223 |
|
|
2224 |
for (Exception ex : renderingErrors) { |
for (Exception ex : renderingErrors) { |
2225 |
|
|
|
if (ex instanceof java.lang.IllegalArgumentException |
|
|
&& ex.getMessage().equals( |
|
|
"Argument \"sourceCRS\" should not be null.")) |
|
|
continue; |
|
|
|
|
2226 |
String errStr = ex.getLocalizedMessage(); |
String errStr = ex.getLocalizedMessage(); |
2227 |
|
|
2228 |
if (errStr == null) |
if (errStr == null) |
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); |
2263 |
ReferencedEnvelope _mapArea; |
ReferencedEnvelope _mapArea; |
2264 |
if (mapArea == null) |
if (mapArea == null) |
2265 |
_mapArea = features.getBounds(); |
_mapArea = features.getBounds(); |
2266 |
else _mapArea = getMapArea(); |
else |
2267 |
|
_mapArea = getMapArea(); |
2268 |
double width = _mapArea.getWidth(); |
double width = _mapArea.getWidth(); |
2269 |
double height = _mapArea.getHeight(); |
double height = _mapArea.getHeight(); |
2270 |
final double ratio = height / width; |
final double ratio = height / width; |
2385 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2386 |
} |
} |
2387 |
|
|
2388 |
|
/** |
2389 |
|
* Shall non-fatal rendering exceptions be reported in the mappane or be |
2390 |
|
* dropped quitely. |
2391 |
|
*/ |
2392 |
|
public void setShowExceptions(boolean showExceptions) { |
2393 |
|
this.showExceptions = showExceptions; |
2394 |
|
} |
2395 |
|
|
2396 |
|
/** |
2397 |
|
* Shall exceptions be reported in the mappane? |
2398 |
|
*/ |
2399 |
|
public boolean isShowExceptions() { |
2400 |
|
return showExceptions; |
2401 |
|
} |
2402 |
|
|
2403 |
|
public GTRenderer getLocalRenderer() { |
2404 |
|
return localRenderer; |
2405 |
|
} |
2406 |
|
|
2407 |
} |
} |