[Gvsig_english] Refresh functionnality

Pablo Piqueras Bartolomé pablo.piqueras at iver.es
Wed Jul 30 08:03:19 CEST 2008


Charlotte Declercq escribió:
> Hi,
>
> I have tried this but it doesn't draw the layers at all.
> I don't know what to do.
> Could someone from Iver help ?
>
> Charlotte
>
> Fran a écrit :
>> Hi Charlotte.
>>
>> Maybe you can try this method:
>>
>> public void setCachingDrawnLayers(boolean bCacheDrawnLayers)
>>
>> You can use like this YourTopLayer.setCachingDrawnLayers(true);
>>
>> Then, your layer will have a copy of the image generated before your 
>> layer is drawn, and dependent on the event that generated the 
>> repaint, it will be used or not.
>> I didn't test, but it may work.
>>
>> Cheers.
>>
>> Fran.
>>
>>
>> Charlotte Declercq escribió:
>>> Hello,
>>>
>>> I am looking in the code to add a refresh functionnality to gvsig 
>>> desktop.
>>> I have modified the paint method of MapControl (lib_FMap) here to add :
>>>
>>>
>>>                    while(true){
>>>                       Thread.sleep(2000);
>>>                       this.paint();
>>>                                             //commandRefresh();
>>>                        //System.out.println("refresh");
>>>                   }
>>>                 to refresh the map all 2 seconds.
>>>
>>> I would like to refresh only one layer and not all the layers, is it 
>>> possible to do that? If yes could someone guide me?
>>> If I could have a developper contact it would be great, thanks.
>>>
>>> Charlotte.
>>>
>>>
>>> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
>>>
>>> Here is the whole function :
>>>
>>> public void paint()
>>>        {
>>>            try
>>>            {
>>>                canceldraw.setCanceled(false);
>>>                /* if (image == null)
>>>                {
>>>                    image = new BufferedImage(vp.getImageWidth(), 
>>> vp.getImageHeight(),
>>>                            BufferedImage.TYPE_INT_ARGB);
>>>                    Graphics gTemp = image.createGraphics();
>>>                    Color theBackColor = vp.getBackColor();
>>>                    if (theBackColor == null)
>>>                        gTemp.setColor(Color.WHITE);
>>>                    else
>>>                        gTemp.setColor(theBackColor);
>>>
>>>                    gTemp.fillRect(0,0,getWidth(), getHeight());
>>>                    gTemp.dispose();
>>>                    // g.drawImage(image,0,0,null);
>>>                    System.out.println("Imagen con null en 
>>> DESACTUALIZADO. Width = " + this.getWidth());
>>>                } */
>>>                Graphics2D g = image.createGraphics();
>>>
>>>                ViewPort viewPort = mapContext.getViewPort();
>>>
>>>                if (status == DESACTUALIZADO)
>>>                {
>>>                    Graphics2D gTemp = image.createGraphics();
>>>                    Color theBackColor = viewPort.getBackColor();
>>>                    if (theBackColor == null)
>>>                        gTemp.setColor(Color.WHITE);
>>>                    else
>>>                        gTemp.setColor(theBackColor);
>>>                    gTemp.fillRect(0, 0, viewPort.getImageWidth(), 
>>> viewPort.getImageHeight());
>>>                                                      // status = 
>>> ACTUALIZADO;/****charlotte: décommenter pour ne pas boucler***/
>>>                                                        // ESTILO MAC
>>> //                    BufferedImage imgMac = new 
>>> BufferedImage(vp.getImageWidth(), vp.getImageHeight(),
>>> //                            BufferedImage.TYPE_INT_ARGB);
>>> //
>>> //                    mapContext.draw(imgMac, g, canceldraw, 
>>> mapContext.getScaleView());
>>> //                    g.drawImage(imgMac, 0, 0, null);
>>>                    // FIN ESTILO MAC
>>>                    // SIN MAC:
>>>                                      mapContext.draw(image, g, 
>>> canceldraw, mapContext.getScaleView());
>>>                                      
>>> /************************************added 
>>> here*******************************************************/
>>>                    while(true){
>>>                       Thread.sleep(2000);
>>>                       this.paint();
>>>                                             //commandRefresh();
>>>                        //System.out.println("refresh");
>>>                   }
>>>                    
>>> /**************************************************************************************************/ 
>>>
>>>                                  }
>>>                else if (status == ONLY_GRAPHICS)
>>>                {
>>>                    status = ACTUALIZADO;
>>>                    mapContext.drawGraphics(image, g, 
>>> canceldraw,mapContext.getScaleView());
>>>                    System.out.println("charlotte:paint2");
>>>                }
>>>
>>>
>>>                // status = FAST_PAINT;
>>>              //  drawerAlive = false;
>>>                timer.stop();
>>>                repaint();
>>>
>>>
>>>            } catch (Throwable e) {
>>>                timer.stop();
>>>              //  isCancelled = true;
>>>                e.printStackTrace();
>>>                throwException(e);
>>>            } finally {
>>>            }
>>>
>>>        }
>>>
>>>    }
>>>
>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> Gvsig_internacional mailing list
>> Gvsig_internacional at runas.cap.gva.es
>> http://runas.cap.gva.es/mailman/listinfo/gvsig_internacional
>>
>
>
Hello Charlotte,

I'll try to answer your queries:

An instance of "PaintingRequest" is created to refresh "MapControl" 
according its status.

During this process, user will see partial results each 360 ms. (this 
improves the interactivity sensation), combined with the possibility of 
being cancelled.

You can change that default value: "360" by "2000" (2 seconds), as you 
wanted, then user will see the parcial results of a heavy refresh/paint 
process each 2 seconds (before this process would finished).

About the second question "refresh only one layer": MapControl invokes 
MapContext to repaint the layers according its status:

status = ACTUALIZADO -> won't repaint/paint any.
status = ONLY_GRAPHICS -> will repaint the MapControl's MapContext's 
GraphicLayer layer.
status = DESACTUALIZADO -> will try to repaint all layers.

In all cases, MapContext delegates to the layer, to draw its data. Then, 
according its status (dirty, visible, ...) and its nature, the layer 
will paint all its graphical items, some of them, or any.

Then, with the current version, you can't use the current draw-mechanism 
defined in MapControl-MapContext-FLayer to refresh only the layer you 
want from MapControl. (Probably changing the status of the other layers, 
but sometimes this mustn't be done).

If you want to paint/refresh the layer from MapControl, you'll need to 
modify the current whole MapControl concept, it treats all layers as a 
group to be painted, that are updated (ACTUALIZADO), or not 
(DESACTUALIZADO), and probably add some method in MapContext, ... then 
this is a dangerous way. :-)

Test if hiding the other layers, it works like you want.


-------------

Source code: gvSIG 1.1.2

More about MapControl: 
https://gvsig.org/web/docdev/reference/fmap/mapcontrol/mapcontrol

More about MapContext: https://gvsig.org/docdev/reference/fmap/mapcontext

More about the layers: https://gvsig.org/docdev/reference/fmap/layers

-------------

Probably another workmate could help more.

-------------


Regards.

-- 
Pablo Piqueras Bartolomé

Equipo de gvSIG
IVER T.I. S.A.
C/. Lérida, 20
46005 - Valencia (Spain)
www.iver.es
www.gvsig.com


Este mensaje y sus archivos son confidenciales. No está permitida su reproducción o distribución sin la autorización expresa de "IVER Tecnologías de la Información". Si usted no es el destinatario previsto, queda desautorizado cualquier uso, acceso o copia de este mensaje. Si ha recibido este mensaje por error, por favor bórrelo e infórmenos por esta misma vía.




More information about the Gvsig_internacional mailing list