[OpenMap Users] Group Layer Startup

From: Cicero Augusto Wollmann Zandoná <cicero_at_simepar.br>
Date: Thu, 30 Mar 2006 10:49:29 -0300

Hi Openmap users,

My application extends the Viewer. And, in order to offer the possibility to
show/hide a group of layers I created a Layer that does this.

The properties are:
group.class=GroupLayer
group.layers=sublayer1 sublayer2 sublayer3 sublayer4 sublayer5

Everything is working fine, execept that when the GroupLayer is in the Startup
layers group, the sublayers are not shown, although the lightbulb of the
group layer and his children are on. Then, if I turn ANY layer on/off they
appear.

I supect the solution is something simple.

I am sending the .java atached and also pasted it in the e-mail in the case
the file is filtered.

If anyone find the code usefull, feel free to use.

Thanks Already,

Cicero Zandona

This is the GroupLayer source:

import com.bbn.openmap.Layer;
import com.bbn.openmap.event.LayerStatusEvent;
import com.bbn.openmap.event.LayerStatusListener;
import com.bbn.openmap.event.ProjectionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Properties;

/**
 *
 * _at_author cicero
 */
public class GroupLayer extends Layer implements ComponentListener{
    
    public static final String LAYERSPROP = "layers";
    
    private Layer[] layers = null;
    private String[] stLayers = null;
    
    private boolean hiddenInside = false;//prevents a infinite loop
    
    
    public void projectionChanged(ProjectionEvent projectionEvent) {
        //This does not work
        for (Layer lay: layers)
            if (lay!=null && lay.getProjection()==null) {
                lay.setProjection(this.getProjection());
                lay.repaint();
            }
    }
    
    
    public void findAndInit(Object obj) {
        super.findAndInit(obj);
        
        //Find the layers
        if (obj instanceof Layer) {
            Layer layer = (Layer) obj;
            int pos = Arrays.binarySearch(stLayers,
layer.getPropertyPrefix());
            if (pos >= 0) {
                layers[pos] = layer;
                layer.addComponentListener(this);
                //Liga se o layer estiver ligado
                this.doHack = false;
                if (this.isVisible()) {
                    layer.setVisible(true);
                    layer.repaint();
                }
            }
        }
    }
    
    /**
     * Show/hiddes all the layers
     * _at_param vis
     */
    public void setVisible(boolean vis) {
        super.setVisible(vis);
        if (!hiddenInside)
            for (Layer lay: layers)
                if (lay!=null) lay.setVisible(vis);
    }
            
    /**
     * If a layer in the group is hidden, the group layer must be
     * hidden as well
     * _at_param e
     */
    public void componentHidden(ComponentEvent e) {
        this.hiddenInside = true;
        this.setVisible(false);
        this.hiddenInside = false;
    }
    
    public void componentResized(ComponentEvent e) { }
    
    public void componentMoved(ComponentEvent e) { }
    
    public void componentShown(ComponentEvent e) { }
    
    /**
     * Get the properties
     */
    public void setProperties(String prefix, Properties properties) {
        super.setProperties(prefix, properties);
        
        stLayers = properties.getProperty(prefix + "." +
                LAYERSPROP).split(" ");
        Arrays.sort(stLayers);
        
        layers = new Layer[stLayers.length];
    }
}



--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Mar 30 2006 - 09:14:01 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:07 EDT