[Schmitzm-commits] r506 - in branches/1.0-gt2-2.6/src: gtmig/org/geotools/swing schmitzm/geotools/gui
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Oct 31 13:15:39 CET 2009
Author: alfonx
Date: 2009-10-31 13:15:37 +0100 (Sat, 31 Oct 2009)
New Revision: 506
Modified:
branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java
Log:
* Cleaned up the new methods for drawing preview image when zooming.
Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java 2009-10-31 10:53:43 UTC (rev 505)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java 2009-10-31 12:15:37 UTC (rev 506)
@@ -113,9 +113,8 @@
*/
protected Rectangle oldRect = null;
- /**
- * the last map area drawn.
- */
+ /** We store the old mapArea for a moment to use it for the
+ "quick scaled preview" in case of ZoomOut **/
protected Envelope oldMapArea = null;
/**
@@ -365,9 +364,7 @@
// draw the map
renderer.paint(ig, dr, mapArea);
- // TODO nur machen, wenn panning beginnt
- panningImage = new BufferedImage(dr.width, dr.height,
- BufferedImage.TYPE_INT_RGB);
+ panningImage = new BufferedImage(dr.width, dr.height, BufferedImage.TYPE_INT_RGB);
}
@@ -618,8 +615,6 @@
// new edges
final double left = mapArea.getMinX() - deltaX1;
final double right = mapArea.getMaxX() - deltaX1;
-
- // now for Y
final double deltaY1 = endY - startY;
// System.out.println("deltaY " + deltaY1);
@@ -653,31 +648,6 @@
// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
- // sk.sc
- {
- // // SK tries to paint a preview of the zoom ;-9 aha.... well
-//
-// double reductionFactor = 1/8.;
-////
-//// BufferedImage reducedBaseImage = new BufferedImage((int)(baseImage.getWidth()*reductionFactor), (int)(baseImage.getHeight()*reductionFactor), BufferedImage.TYPE_INT_RGB);
-//// Graphics2D reducedG = (Graphics2D) reducedBaseImage.getGraphics();
-// AffineTransform reductionTransform =new AffineTransform();
-// reductionTransform.scale(reductionFactor, reductionFactor);
-//// reducedG.drawImage(baseImage, reductionTransform, null);
-//
-// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
-//// graphics.getTransform().scale(reductionFactor, reductionFactor);
-//
-// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
-// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
-// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-// RenderingHints.VALUE_ANTIALIAS_OFF);
-// graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
-// RenderingHints.VALUE_RENDER_SPEED);
-// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
-// JMapPane.this.getHeight(), x1, y1, x2, y2, null);
- }
- // xulu.ec
} else if (state == JMapPane.ZoomOut) {
drawRectangle(this.getGraphics());
@@ -742,45 +712,6 @@
return clickable;
}
- //
- // private org.geotools.styling.Style setupStyle(final int type, final Color
- // color) {
- // final StyleFactory sf = org.geotools.factory.CommonFactoryFinder
- // .getStyleFactory(null);
- // final StyleBuilder sb = new StyleBuilder();
- //
- // org.geotools.styling.Style s = sf.createStyle();
- // s.setTitle("selection");
- //
- // // TODO parameterise the color
- // final PolygonSymbolizer ps = sb.createPolygonSymbolizer(color);
- // ps.setStroke(sb.createStroke(color));
- //
- // final LineSymbolizer ls = sb.createLineSymbolizer(color);
- // final Graphic h = sb.createGraphic();
- // h.setMarks(new Mark[] { sb.createMark("square", color) });
- //
- // final PointSymbolizer pts = sb.createPointSymbolizer(h);
- //
- // // Rule r = sb.createRule(new Symbolizer[]{ps,ls,pts});
- // switch (type) {
- // case POLYGON:
- // s = sb.createStyle(ps);
- //
- // break;
- //
- // case POINT:
- // s = sb.createStyle(pts);
- //
- // break;
- //
- // case LINE:
- // s = sb.createStyle(ls);
- // }
- //
- // return s;
- // }
-
public void propertyChange(final PropertyChangeEvent evt) {
final String prop = evt.getPropertyName();
@@ -811,8 +742,7 @@
mapArea = context.getLayerBounds();
// xulu.ec
} catch (final IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOGGER.error(e);
}
reset = true;
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java 2009-10-31 10:53:43 UTC (rev 505)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java 2009-10-31 12:15:37 UTC (rev 506)
@@ -47,6 +47,7 @@
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.IOException;
+import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
@@ -168,6 +169,9 @@
* @version 1.0
*/
public class JMapPane extends gtmig.org.geotools.swing.JMapPane {
+
+ /** Stored the time used for the last real rendering in ms. **/
+ private long lastRenderingDuration = Long.MAX_VALUE;
/**
* SK: Nach dem Drag, soll die {@link GeoMapPane} erfahren, dass die Area
@@ -186,118 +190,96 @@
&& e.getButton() != 3)
return;
-
- /** We store the old transform for a moment to use it for the
- "quick scaled preview" in case of ZoomIn **/
- AffineTransform oldTransform = getTransform();
- /** We store the old mapArea for a moment to use it for the
- "quick scaled preview" in case of ZoomOut **/
- Envelope oldMapArea = getMapArea();
-
super.processDrag(x1, y1, x2, y2, e);
-
- if (getState() == JMapPane.ZOOM_IN) {
- // Draw a quick scaled preview image, so the user is not do bored
- drawScaledPreviewImage_ZoomIn(oldTransform);
-
- } else if (getState() == JMapPane.ZOOM_OUT) {
- drawScaledPreviewImage_ZoomOut(oldMapArea);
-// // Draw a quick scaled preview image, so the user is not do bored
-//
-// Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
-// Envelope gg = tranformGeoToWindow(mapArea.getMinX(), mapArea.getMinY(), mapArea.getMaxX(), mapArea.getMaxY(), oldTransform);
-//
-// graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
-// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
-// graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-// RenderingHints.VALUE_ANTIALIAS_OFF);
-// graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
-// RenderingHints.VALUE_RENDER_SPEED);
-//
-// int xx1 = (int)gg.getMinX();
-// int yy1 = (int)gg.getMinY();
-// int xx2 = (int)gg.getMaxX();
-// int yy2 = (int)gg.getMaxY();
-//
-// graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(), JMapPane.this.getHeight(), xx1,yy1,xx2,yy2,
-// null);
- }
-
// SK, 19.6.2009:
// Ein MapAreaChangedEvent soll nur geworfen werden, wenn auch gezoomt
// wurde! Irgendwie wird das auch aufgerufen, wenn man mit InfoClick
// tool nur click - also garkeit kein draggin gemacht hat.
if ((oldMapArea == null || !oldMapArea.equals(mapArea))
&& (getState() == ZOOM_IN || getState() == ZOOM_OUT))
+ {
+
+ // Draw a quick scaled preview image, so the user is not do bored
+ drawScaledPreviewImage_Zoom(getState());
+
fireMapPaneEvent(new MapAreaChangedEvent(this, oldMapArea, mapArea));
+ }
+
+
}
/**
* Diretly paints scaled preview into the {@link JMapPane}. Used to give the
* user something to look at while we are rendering. Method should be called
* after {@link #setMapArea(Envelope)} has been set to the new mapArea and
- * transform has been reset.
+ * transform has been reset.<br/>
+ * This method does nothing if the {@link #lastRenderingDuration} is smaller
+ * then a trashhold.
*
- * @param oldTransform
- * The old transform has to be passed as parameter.
+ * @param state Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}
*/
- private void drawScaledPreviewImage_ZoomIn(AffineTransform oldTransform) {
+ private void drawScaledPreviewImage_Zoom(int state) {
- Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
- Envelope gg = tranformGeoToWindow(mapArea.getMinX(), mapArea.getMinY(),
- mapArea.getMaxX(), mapArea.getMaxY(), oldTransform);
+ if (state == ZOOM_IN) {
- graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_OFF);
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_SPEED);
-
- int xx1 = (int) gg.getMinX();
- int yy1 = (int) gg.getMinY();
- int xx2 = (int) gg.getMaxX();
- int yy2 = (int) gg.getMaxY();
-
- graphics.setBackground(getMapBackgroundColor());
- graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
- JMapPane.this.getHeight(), xx1, yy1, xx2, yy2, null);
- }
-
- /**
- * Diretly paints scaled preview into the {@link JMapPane}. Used to give the
- * user something to look at while we are rendering. Method should be called
- * after {@link #setMapArea(Envelope)} has been set to the new mapArea and
- * transform has been reset.
- *
- * @param oldMapArea
- * The old mapArea has to be passed as parameter.
- */
- private void drawScaledPreviewImage_ZoomOut(Envelope oldMapArea) {
+ if (lastRenderingDuration < 220)
+ return;
+
+ if (getTransform() != null && getTransform().equals(oldTransform))
+ return;
+
Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
- Envelope gg = tranformGeoToWindow(oldMapArea.getMinX(), oldMapArea.getMinY(),
- oldMapArea.getMaxX(), oldMapArea.getMaxY(), null);
-
+ Envelope gg = tranformGeoToWindow(mapArea.getMinX(), mapArea.getMinY(),
+ mapArea.getMaxX(), mapArea.getMaxY(), oldTransform);
+
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_SPEED);
-
- int xx1 = (int) gg.getMinX();
- int yy1 = (int) gg.getMinY();
- int xx2 = (int) gg.getMaxX();
- int yy2 = (int) gg.getMaxY();
-
+
+ int xx1 = (int) Math.round( gg.getMinX() );
+ int yy1 = (int) Math.round(gg.getMinY());
+ int xx2 = (int) Math.round(gg.getMaxX());
+ int yy2 = (int) Math.round(gg.getMaxY());
+
graphics.setBackground(getMapBackgroundColor());
- graphics.clearRect(0, 0, JMapPane.this.getWidth(),
- JMapPane.this.getHeight());
- graphics.drawImage(baseImage, xx1, yy1, xx2, yy2, 0, 0, JMapPane.this.getWidth(),
- JMapPane.this.getHeight(), null);
+ graphics.drawImage(baseImage, 0, 0, JMapPane.this.getWidth(),
+ JMapPane.this.getHeight(), xx1, yy1, xx2, yy2, null);
+ } else if (state == ZOOM_OUT){
+
+ if (lastRenderingDuration < 400) // This number is higher, because the zoom out preview image is uglier (while borders)
+ return;
+
+ if (mapArea != null && mapArea.equals(oldMapArea))
+ return;
+
+ Graphics2D graphics = (Graphics2D) JMapPane.this.getGraphics();
+ Envelope gg = tranformGeoToWindow(oldMapArea.getMinX(), oldMapArea
+ .getMinY(), oldMapArea.getMaxX(), oldMapArea.getMaxY(), null);
+
+ graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_OFF);
+ graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_SPEED);
+
+ int xx1 = (int) Math.round( gg.getMinX() );
+ int yy1 = (int) Math.round( gg.getMinY() );
+ int xx2 = (int) Math.round( gg.getMaxX() );
+ int yy2 = (int) Math.round( gg.getMaxY() );
+
+ graphics.setBackground(getMapBackgroundColor());
+ graphics.clearRect(0, 0, JMapPane.this.getWidth(), JMapPane.this
+ .getHeight());
+ graphics.drawImage(baseImage, xx1, yy1, xx2, yy2, 0, 0, JMapPane.this
+ .getWidth(), JMapPane.this.getHeight(), null);
+ }
}
private static final Cursor WAIT_CURSOR = Cursor
@@ -426,7 +408,11 @@
private boolean disposed = false;
/** Listener, der auf das Mausrad lauscht und mit Zoom reagiert */
- private MouseWheelListener mouseWheelZoomListener;
+ private final MouseWheelListener mouseWheelZoomListener = new MouseWheelListener() {
+ public void mouseWheelMoved(MouseWheelEvent e) {
+ performMouseWheelEvent(e);
+ }
+ };;
// /** Wenn true, dann werden RasterLayer waehrend des Panning auf
// setVisible(false) gesetzt **/
@@ -467,6 +453,10 @@
*/
final protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();
+ /** We store the old transform for a moment to use it for the
+ "quick scaled preview" in case of ZoomIn **/
+ protected AffineTransform oldTransform = null;
+
/**
* Erzeugt ein neues MapPane.
*
@@ -553,22 +543,8 @@
setWindowSelectionState(ZOOM_IN);
setState(ZOOM_IN);
- // Listener, der auf das Mausrad lauscht und mit Zoom reagiert
- mouseWheelZoomListener = new MouseWheelListener() {
- public void mouseWheelMoved(MouseWheelEvent e) {
- performMouseWheelEvent(e);
- }
- };
this.addMouseWheelListener(mouseWheelZoomListener);
- // Listener, der auf das Mausrad lauscht und mit Zoom reagiert
- mouseWheelZoomListener = new MouseWheelListener() {
- public void mouseWheelMoved(MouseWheelEvent e) {
- performMouseWheelEvent(e);
- }
- };
- this.addMouseWheelListener(mouseWheelZoomListener);
-
/**
* Dieser Listener setzt nach dem Panning (aka Drag) den Maus-Cursor auf
* Wait. Der Rest des Panning wird in der Uberklasse abgewickelt
@@ -1197,14 +1173,14 @@
/**
* Verarbeitet die Mausrad-Aktion, indem gezoomed wird.
*
- * @param e
+ * @param wheelEvt
* Mausrad-Event
*/
- protected void performMouseWheelEvent(MouseWheelEvent e) {
+ protected void performMouseWheelEvent(MouseWheelEvent wheelEvt) {
if (getContext().getLayerCount() == 0)
return;
- int units = e.getUnitsToScroll();
+ int units = wheelEvt.getUnitsToScroll();
// Positiver Wert --> Zoom in --> Faktor < 1
// Negativer Wert --> Zoom out --> Faktir > 1
@@ -1219,7 +1195,7 @@
.warn("No transform can be created! Skipping MouseWheel performAction.");
return;
}
- Point2D mapCoord = transform2.transform(e.getPoint(), null);
+ Point2D mapCoord = transform2.transform(wheelEvt.getPoint(), null);
// Relative Position des Mauszeigers zum Kartenausschnitt
// -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
// erscheinen, wie vor dem Zoom
@@ -1240,6 +1216,12 @@
setWaitCursorDuringNextRepaint(true);
repaint();
+
+ if (units > 0) {
+ drawScaledPreviewImage_Zoom(ZOOM_IN);
+ } else {
+ drawScaledPreviewImage_Zoom(ZOOM_OUT);
+ }
}
/**
@@ -1307,6 +1289,11 @@
protected void resetTransform() {
if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
return;
+
+
+ // We store the last Transform
+ oldTransform = transform;
+
this.transform = new AffineTransform(
// Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten
// nach rechts (Osten) hin groesser
@@ -1417,16 +1404,6 @@
if (getContext().getLayerCount() == 0)
return;
- // double oldScale = getScale();
- // Envelope oldEnv = getMapArea();
-
- /** We store the old transform for a moment to use it for the
- "quick scaled preview" in case of ZoomIn **/
- AffineTransform oldTransform = getTransform();
- /** We store the old mapArea for a moment to use it for the
- "quick scaled preview" in case of ZoomOut **/
- Envelope oldMapArea = getMapArea();
-
switch (e.getButton()) {
// Linksklick --> Eingestellte Funktion
case MouseEvent.BUTTON1: // SimpleFeature-Auswahl nicht ueber die
@@ -1572,7 +1549,7 @@
int oldState = getState();
// MS: ist doch eleganter, wenn IMMER mit Rechtsklick raus-gezoomt
// werden kann!
- // // ZOOM_OUT nur wenn Links-Klick auf ZOOM_IN eingestellt ist)
+ // // ZOOM_OUT nur wenn LinkmapAreas-Klick auf ZOOM_IN eingestellt ist)
// if ( oldState != ZOOM_IN )
// return;
setState(ZOOM_OUT);
@@ -1585,30 +1562,14 @@
return;
}
- // In super.mouseClicked(.) wird (nach Zoom) die MapArea neu gesetzt,
- // aber
- // leider ohne setMapArea(.) aufzurufen, sondern indem einfach die
- // Variable
- // 'mapArea' neu belegt wird
- // --> Transform muss neu berechnet werden
- // --> Aenderung der Aufloesung propagieren
-
setMapArea(mapArea);
- // resetTransform();
- // double newScale = getScale();
- // Envelope newEnv = getMapArea();
- // if ( oldScale != newScale )
- // fireMapPaneEvent( new ScaleChangedEvent(this,oldScale,newScale) );
- // if ( oldEnv == null && newEnv != null || oldEnv != null &&
- // !oldEnv.equals( newEnv ) )
- // fireMapPaneEvent( new MapAreaChangedEvent(this,oldEnv,newEnv) );
if (getState() == ZOOM_IN && e.getButton() == MouseEvent.BUTTON1)
- drawScaledPreviewImage_ZoomIn(oldTransform);
+ drawScaledPreviewImage_Zoom(ZOOM_IN);
else if (getState() == ZOOM_IN && e.getButton() == MouseEvent.BUTTON3)
- drawScaledPreviewImage_ZoomOut(oldMapArea);
+ drawScaledPreviewImage_Zoom(ZOOM_OUT);
else if (getState() == ZOOM_OUT&& e.getButton() == MouseEvent.BUTTON3)
- drawScaledPreviewImage_ZoomOut(oldMapArea);
+ drawScaledPreviewImage_Zoom(ZOOM_OUT);
}
@@ -1643,8 +1604,6 @@
*/
protected void paintComponent(Graphics g) {
- // if (!reset) return; // TEST TEST TETS ONLY REMOVE!!
-
Cursor oldCursor = null;
boolean seriouseChange = false;
@@ -1669,11 +1628,18 @@
}
try {
- // if (!seriouseChange) {
- // LOGGER.info("No seriouse Change => reset = false");
- // reset= false;
- // }
+
+
+ // Measuring the time needed to render the mappane.
+ long startTime = new Date().getTime();
+
super.paintComponent(g);
+
+ // Only are we interested in the time it takes to do a *real* rendering of the image
+ if (seriouseChange)
+ lastRenderingDuration = new Date().getTime() - startTime;
+
+
} catch (Exception e) {
/**
* I only need to catch UnknownHostException.. well...
@@ -1698,16 +1664,25 @@
* MapIcon has long been disabled and should come back
*/
if (mapImage != null && baseImage != null) {
- baseImage
- .getGraphics()
+ final Graphics baseG2 = (Graphics2D)baseImage.getGraphics();
+ baseG2
.drawImage(
mapImage,
baseImage.getWidth() - mapImage.getWidth() - 10,
baseImage.getHeight() - mapImage.getHeight()
- 10, this);
+
+
+// // If in debug mode, write the rending time into the display
+// baseG2.setColor(Color.white);
+// baseG2.drawString(lastRenderingDuration+"ms rendring", 50, 50);
+// baseG2.setColor(Color.black);
+// baseG2.drawString(lastRenderingDuration+"ms rendring", 51, 51);
+
// Repaint with the cached image (fast) which now contains the
// logo
super.paintComponent(g);
+
}
}
@@ -2852,7 +2827,7 @@
* Creates a new filter generator.
*
* @param basePoint
- * defines the point for the "near point" constraint
+ * defNearPointFilterGeneratorines the point for the "near point" constraint
* @param dist
* defines the distance around the base point
* @param crs
@@ -2953,4 +2928,13 @@
Boolean selectable = mapLayerSelectable.get(layer);
return selectable == null ? true : selectable;
}
+
+ /**
+ * Returns in milli seconds the time the last rending of the
+ * {@link JMapPane} took. #Long.MAX_VALUE if the JMapPane has not been
+ * rendered yet.
+ */
+ public long getLastRenderingDuration() {
+ return lastRenderingDuration;
+ }
}
More information about the Schmitzm-commits
mailing list