[Gvsig_english] Setting snap layers by code (in a clean way)

Flavio Pompermaier fla83tn at gmail.com
Tue Mar 23 17:09:29 CET 2010


Hi to all,
I'd like to know if there's a way to preselect (in a "clean way") which of
the FlyrVect layers of my Project's Vista can be set as snapping layer for
another layer?

I tried to use the LayerCollectionListener interface to capture when a layer
is added and, when this occurs, and then add a LayerListener on that layer
to capture editionChange event.
The problem is that the snapping layer must be set when the layer enters
editing mode and AFTER that its VectorialLayerEdited (which embeds snap
settings) is created.
The EditionManager, which creates the  VectorialLayerEdited,  is another
LayerListener at its own time but, unfortunately, it is added only when the
edition starts so I'm not able to get
the layer's VectorialLayerEdited because my LayerListener is always called
before the EditionManager.

I managed to preselect a snapping layer in a "dirty" way (using polling on
the EditionManager) but I don't like it:

public void editionChanged(LayerEvent e) {
        System.out.println("------------------------------ EDIT STARTED");
        // STOP EDITING: do nothing
        if (!e.getSource().isEditing())
            return;
        source = e.getSource();
        EditionManager edManager = CADExtension.getEditionManager();
        VectorialLayerEdited lyrEd = (VectorialLayerEdited)
edManager.getLayerEdited(source);

        // if the VectorialLayerEdited is not yet ready (editionChange of
the EditionManager called)
        if (lyrEd == null) {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    EditionManager edManager =
CADExtension.getEditionManager();
                    VectorialLayerEdited lyrEd = null;
                    // POLLING
                    while ((lyrEd = (VectorialLayerEdited)
edManager.getLayerEdited(source)) == null) {
                        try {
                            Thread.sleep(100);
                            System.out.println("Sleep...");
                        }
                        catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println("Found layer edited");
                    ArrayList<FLyrVect> layersToSnap =
lyrEd.getLayersToSnap();
                    .....
                    .....
               }
        }
}
Isn't it a limitation of gvSIG? Or is there a way to solve the problem in a
better way?

Best regards,
Flavio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.gva.es/pipermail/gvsig_internacional/attachments/20100323/c81b8b86/attachment.htm 


More information about the Gvsig_internacional mailing list