Many thanks for posting this Sergey ! Michael
On 8 October 2010 19:19, LSA <[email protected]> wrote: > Hi All, > > I have cooked workaround for this problem, it seems to be working in > geotools 2.6.3. For the impatient ones, complete CorrectedPanTool is below > in message body. > > The problem seems to be the following code in the > JMapPane.paintComponent(Graphics g): > > if (redrawBaseImage) { > if (baseImageMoved) { > afterImageMove(mapAOI, curPaintArea); > baseImageMoved = false; > clearLabelCache = true; > } > > if (renderingExecutor.submit(mapAOI, curPaintArea, > baseImageGraphics)) { > MapPaneEvent ev = new MapPaneEvent(this, > MapPaneEvent.Type.RENDERING_STARTED); > publishEvent(ev); > > } else { > onRenderingRejected(); > } > > } else { > Graphics2D g2 = (Graphics2D) g; > g2.drawImage(baseImage, imageOrigin.x, imageOrigin.y, null); > } > > Specifically, if one releases mouse during the drag, baseImageMoved is > remains set to false, so offscreen buffer is rendered, instead of full map > repaint. > So, my workaround is just sets redrawBaseImage to true in the public void > onMouseReleased(MapMouseEvent ev) of my CorrectedPanTool. > Maybe someone will come with more graceful solution for this problem... > > Here is the code for CorrectedPanTool, that always redraw JMapPane. Please > note, that it differs from the PanTool only in the onMouseReleased method. > > import java.awt.Cursor; > import java.awt.Point; > import java.awt.Toolkit; > import java.lang.reflect.Field; > import java.util.ResourceBundle; > > import javax.swing.ImageIcon; > > import org.geotools.swing.JMapPane; > import org.geotools.swing.event.MapMouseEvent; > import org.geotools.swing.tool.CursorTool; > import org.geotools.swing.tool.PanTool; > > public class CorrectedPanTool extends CursorTool { > > private static final ResourceBundle stringRes = ResourceBundle > .getBundle("org/geotools/swing/Text"); > > /** Tool name */ > public static final String TOOL_NAME = > stringRes.getString("tool_name_pan"); > /** Tool tip text */ > public static final String TOOL_TIP = stringRes.getString("tool_tip_pan"); > /** Cursor */ > public static final String CURSOR_IMAGE = > "/org/geotools/swing/icons/mActionPan.png"; > /** Cursor hotspot coordinates */ > public static final Point CURSOR_HOTSPOT = new Point(15, 15); > /** Icon for the control */ > public static final String ICON_IMAGE = > "/org/geotools/swing/icons/mActionPan.png"; > > private Cursor cursor; > > private Point panePos; > boolean panning; > > public CorrectedPanTool(JMapPane mapPane) { > setMapPane(mapPane); > > Toolkit tk = Toolkit.getDefaultToolkit(); > ImageIcon imgIcon = new > ImageIcon(PanTool.class.getResource(CURSOR_IMAGE)); > cursor = tk.createCustomCursor(imgIcon.getImage(), CURSOR_HOTSPOT, > TOOL_NAME); > > panning = false; > } > > /** > * Respond to a mouse button press event from the map mapPane. This may > signal > * the start of a mouse drag. Records the event's window position. > * > * @param ev > * the mouse event > */ > @Override > public void onMousePressed(MapMouseEvent ev) { > panePos = ev.getPoint(); > panning = true; > } > > /** > * Respond to a mouse dragged event. Calls > * {...@link org.geotools.swing.JMapPane#moveImage()} > * > * @param ev > * the mouse event > */ > @Override > public void onMouseDragged(MapMouseEvent ev) { > if (panning) { > Point pos = ev.getPoint(); > if (!pos.equals(panePos)) { > getMapPane().moveImage(pos.x - panePos.x, pos.y - panePos.y); > panePos = pos; > } > } > } > > /** > * If this button release is the end of a mouse dragged event, requests > the > * map mapPane to repaint the display > * > * @param ev > * the mouse event > */ > @Override > public void onMouseReleased(MapMouseEvent ev) { > panning = false; > Field[] fs = > getMapPane().getClass().getSuperclass().getDeclaredFields(); > for (int i = 0; i < fs.length; i++) { > if (fs[i].getName().equals("redrawBaseImage")) { > try { > fs[i].setAccessible(true); > fs[i].setBoolean(getMapPane(), Boolean.TRUE); > } catch (IllegalArgumentException e) { > e.printStackTrace(); > } catch (IllegalAccessException e) { > e.printStackTrace(); > } > break; > } > } > getMapPane().repaint(); > } > > /** > * Get the mouse cursor for this tool > */ > @Override > public Cursor getCursor() { > return cursor; > } > > /** > * Returns false to indicate that this tool does not draw a box on the map > * display when the mouse is being dragged > */ > @Override > public boolean drawDragBox() { > return false; > } > } > > Sincerely, > Sergey > > On 8/26/2010 8:09 PM, Fred Lehodey wrote: > > Hi Sergey, > Just to complete your question: > this happens when you release the mouse button during the drag..... > If you stop the drag before, there is no problem..... > Is what I noticed... > > Fred. > > > > On Thu, Aug 26, 2010 at 1:34 PM, LSA <[email protected]> wrote: >> >> Hi! >> >> I tried Quickstart demo (with geotools 2.6.5), and it is possible to >> notice, that sometimes map is repainted after dragging with Pan tool, >> while sometimes - it is not. >> I have the following issue in the geotools 2.6.3, maybe some could give >> me an idea how to fix it? >> >> Thanks, >> Sergey >> >> >> ------------------------------------------------------------------------------ >> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program >> Be part of this innovative community and reach millions of netbook users >> worldwide. Take advantage of special opportunities to increase revenue and >> speed time-to-market. Join now, and jumpstart your future. >> http://p.sf.net/sfu/intel-atom-d2d >> _______________________________________________ >> Geotools-gt2-users mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > > ------------------------------------------------------------------------------ > Sell apps to millions through the Intel(R) Atom(Tm) Developer Program > Be part of this innovative community and reach millions of netbook users > worldwide. Take advantage of special opportunities to increase revenue and > speed time-to-market. Join now, and jumpstart your future. > http://p.sf.net/sfu/intel-atom-d2d > > _______________________________________________ > Geotools-gt2-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > > ------------------------------------------------------------------------------ > Beautiful is writing same markup. Internet Explorer 9 supports > standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. > Spend less time writing and rewriting code and more time creating great > experiences on the web. Be a part of the beta today. > http://p.sf.net/sfu/beautyoftheweb > _______________________________________________ > Geotools-gt2-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
