[Schmitzm-commits] r580 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/gui schmitzm/swing skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Nov 25 21:30:04 CET 2009
Author: alfonx
Date: 2009-11-25 21:30:02 +0100 (Wed, 25 Nov 2009)
New Revision: 580
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java
branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
Log:
* Reeduced the flickering while zooming in/out
* scaled previews are not only used if the last rendering took quite long
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java 2009-11-25 19:14:40 UTC (rev 579)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java 2009-11-25 20:30:02 UTC (rev 580)
@@ -67,7 +67,6 @@
import org.geotools.renderer.GTRenderer;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.resources.image.ImageUtilities;
-import org.geotools.swing.utils.MapLayerUtils;
import org.opengis.coverage.CannotEvaluateException;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
@@ -656,7 +655,7 @@
* Krüger</a>
*/
@Override
- public boolean setMapArea(Envelope newMapArea) {
+ public boolean setMapArea(ReferencedEnvelope newMapArea) {
double oldScale = getScale();
boolean b = super.setMapArea(newMapArea);
Modified: branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java 2009-11-25 19:14:40 UTC (rev 579)
+++ branches/1.0-gt2-2.6/src/schmitzm/swing/SwingUtil.java 2009-11-25 20:30:02 UTC (rev 580)
@@ -1098,7 +1098,10 @@
* it intersects with the paintArea.
*/
public static void clearAround(Graphics2D graphics, Rectangle paintArea,
- Rectangle clearArea) {
+ Rectangle clearArea, Color bgColor) {
+
+ if (bgColor != null)
+ graphics.setBackground(bgColor);
// Clear left of the painted area if needed
if (clearArea.getMinX() < paintArea.getMinX()) {
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java 2009-11-25 19:14:40 UTC (rev 579)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java 2009-11-25 20:30:02 UTC (rev 580)
@@ -121,6 +121,7 @@
@Override
public void run() {
+ long startT = System.currentTimeMillis();
try {
renderer.addRenderListener(this);
LOGGER.debug("start rendering...");
@@ -135,7 +136,7 @@
// Kill the reference to this Thread so #isRunning will say
// false directly
renderThread = null;
- mapPane.onRenderingCompleted();
+ mapPane.onRenderingCompleted(startT-System.currentTimeMillis());
} catch (Exception e) {
mapPane.onRenderingFailed(e);
} finally {
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java 2009-11-25 19:14:40 UTC (rev 579)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java 2009-11-25 20:30:02 UTC (rev 580)
@@ -26,7 +26,6 @@
import java.util.Map;
import java.util.Vector;
-import javax.jws.soap.SOAPBinding.Style;
import javax.swing.Timer;
import javax.swing.border.Border;
@@ -97,8 +96,11 @@
*/
public class XMapPane extends JPanel {
- private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
- private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB;
+ // private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
+ // private static final int IMAGETYPE_withAlpha =
+ // BufferedImage.TYPE_INT_ARGB;
+ private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;
+ private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR;
private final static Logger LOGGER = Logger.getLogger(XMapPane.class);
@@ -217,7 +219,7 @@
*
* @see #addGadgets(Graphics2D, boolean)
*/
- final static Font waitFont = new Font("Arial", Font.BOLD, 30);
+ final static Font waitFont = new Font("Arial", Font.BOLD, 28);
/**
* {@link Font} used to paint error messages into the map
@@ -227,6 +229,12 @@
final static Font errorFont = new Font("Arial", Font.BOLD, 13);
/**
+ * If last average last two renderings took more than that many ms, show the
+ * user a scaled preview
+ **/
+ private static final long PRESCALE_MINTIME = 1000;
+
+ /**
* The wait message painted into the map while rendering is going on on
* another thread.
*
@@ -621,19 +629,19 @@
// LOGGER.debug("resizeTimer performed");
-// final Rectangle bounds = getVisibleRect();
+ // final Rectangle bounds = getVisibleRect();
//
// System.out.println("\n\ntimer performs with bounds = "
// + bounds);
-// final Envelope geoMapArea = tranformWindowToGeo(
-// bounds.x, bounds.y, bounds.x + bounds.width,
-// bounds.y + bounds.height);
+ // final Envelope geoMapArea = tranformWindowToGeo(
+ // bounds.x, bounds.y, bounds.x + bounds.width,
+ // bounds.y + bounds.height);
paneResized = true;
-
+
if (setMapArea(getMapArea())) {
-
+
}
}
});
@@ -1038,7 +1046,8 @@
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2
- yy1);
- SwingUtil.clearAround(graphics, painedArea, visibleArea);
+ SwingUtil.clearAround(graphics, painedArea, visibleArea,
+ getMapBackgroundColor());
addGadgets(graphics, true);
@@ -1046,8 +1055,6 @@
repaintTimer.restart();
- graphics.dispose();
-
// Something has been drawn
return true;
}
@@ -1414,7 +1421,7 @@
|| (getState() == XMapPane.SELECT_TOP)) {
// Draws a rectangle
- final Graphics graphics = getGraphics();
+ final Graphics2D graphics = (Graphics2D) getGraphics();
drawRectangle(graphics, startPos, event.getPoint());
if ((lastPos.x > 0) && (lastPos.y > 0))
drawRectangle(graphics, startPos, lastPos);
@@ -1433,9 +1440,13 @@
/**
* Called by the {@link RenderingExecutor} when rendering has been
* completed.
+ *
+ * @param l
+ * long ms the rendering took
*/
- public void onRenderingCompleted() {
+ public void onRenderingCompleted(long l) {
// LOGGER.debug("complete");
+ lastRenderingDuration = lastRenderingDuration + l / 2;
repaintTimer.stop();
@@ -1487,12 +1498,12 @@
if (!isWellDefined())
return;
-
+
if (paneResized) {
- ((Graphics2D)g).setBackground(getMapBackgroundColor());
+ ((Graphics2D) g).setBackground(getMapBackgroundColor());
g.clearRect(0, 0, getVisibleRect().width, getVisibleRect().height);
+ return;
}
-
// super.paintComponent(g); // candidate for removal
@@ -1505,7 +1516,8 @@
// If the new mapArea and the oldMapArea intersect, we can draw some
// quick scaled preview to make the user feel that something is
// happening.
- if (mapAreaChanged && oldMapArea != null
+ if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged
+ && oldMapArea != null
&& getMapArea().intersects(oldMapArea)
& !getMapArea().equals(oldMapArea) && !paneResized) {
@@ -1525,8 +1537,6 @@
g.drawImage(getFinalImage(), 0, 0, null);
- g.dispose(); // cand. for removal
-
paintedSomething = true; // cand. for removal
}
@@ -1909,7 +1919,7 @@
}
// /** Stored the time used for the last real rendering in ms. **/
- // private long lastRenderingDuration = Long.MAX_VALUE;
+ private long lastRenderingDuration = 1000;
/**
* Set the minimum (nearest) allowed zoom scale. This is the bigger number
@@ -2173,13 +2183,14 @@
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,
getMapBackgroundColor(), null);
- final int finalImageHeight = getFinalImage().getHeight(null);
- final int finalImageWidth = getFinalImage().getWidth(null);
+ // What was it good for?
+ // final int finalImageHeight = getFinalImage().getHeight();
+ // final int finalImageWidth = getFinalImage().getWidth();
+ // final Rectangle painedArea = new Rectangle(imageOrigin.x,
+ // imageOrigin.y, finalImageWidth, finalImageHeight);
+ // SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
+ // getMapBackgroundColor());
- final Rectangle painedArea = new Rectangle(imageOrigin.x,
- imageOrigin.y, finalImageWidth, finalImageHeight);
- SwingUtil.clearAround(finalG, painedArea, getVisibleRect());
-
addGadgets(finalG, false);
finalG.dispose();
@@ -2227,7 +2238,7 @@
graphics.setColor(c);
- y += 24;
+ y += 21;
}
if (!renderingErrors.isEmpty() && isShowExceptions()) {
More information about the Schmitzm-commits
mailing list