Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 Agrosense <info@cloudfarming.nl> Licensed under the Eclipse Public License - v 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.eclipse.org/legal/epl-v10.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package nl.cloudfarming.client.geoviewer;
 
 import java.util.*;
 import  org.openide.explorer.ExplorerManager;
 import  org.openide.nodes.Node;

Layer

A layer is a a grouped set of one or more items that posses the capability to be displayed on a map.

Data hierarchy

Layers and layer data are usually organized as nodes in a tree. The layer can be considered the parent node, and the Geographicals the children. Because of this, the layer and its data will often be displayed in an explorer like component like a BeanTreeView.

Selection synchronization

To synchronize selection between the map and views based on the ExplorerManager managing the layer and its data, the issueing ExplorerManager needs to add propertyChangeListeners to the layer. Any change in selection on the map will be published as propertyChange event with as key: ExplorerManager.PROP_SELECTED_NODES

Author(s):
Timon Veenstra
 
 public interface Layer {
 
     public static final String PROP_PALETTE = "palette";
     public static final String PROP_CATEGORY = "category";
     public static final String PROP_NAME = "name";
     public static String LAYER_NODE_ICON_BASE = "nl/cloudfarming/client/icon/layers-map-icon.png";
 
     public static enum SelectionChangeDirection {
 
         BASE_TO_MAP, MAP_TO_BASE;
     }

    
The category of the layer. For example an AREA-layer (for Fields etc.) or SENSOR-layer for sensor data.

Returns:
the category of this layer
 
     public Category getCategory();

    
The name of this layer.

Returns:
String name
 
     public String getName();

    
A palette contains information about how the layer should be displayed.

Returns:
Palette
 
     public Palette getPalette();

    
A palette contains information about how the layer should be displayed.

Param:
The palette to set
 
     void setPalette(Palette palette);

    
Get an array with actions for this layer.

Returns:
 
     public LayerAction[] getActions();

    
Add property change listener to this class.

Parameters:
listener The listener object
    public void addPropertyChangeListener(PropertyChangeListener listener);

    
Add property change listener to this class.

Parameters:
propertyName Property to listen to for changes
listener The Listener object
    void addPropertyChangeListener(String propertyNamePropertyChangeListener listener);

    
Remove the property change listener from this class.

Parameters:
propertyNamen The property the listener is currently listening to
listener The Listener object
    void removePropertyChangeListener(String propertyNamePropertyChangeListener listener);

    
Remove the property change listener from this class.

Parameters:
listener The Listener object
//    ExplorerManager getExplorerManager();
    static class Sync {
        private static final Set<PropertyChangeListenerlisteners = Collections.synchronizedSet(new HashSet<PropertyChangeListener>());
        public static void SyncBaseExplorer(final Layer layerfinal ExplorerManager baseExplorer) {
            //FIXME remove system outs
            ..println("baseExplorer@" + System.identityHashCode(baseExplorer));
            PropertyChangeListener baseExplorerListener = new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
                        layer.fireNodeSelectionChange(evt.);
                    }
                }
            };
            .add(baseExplorerListener);
            baseExplorer.addPropertyChangeListener(baseExplorerListener);
            PropertyChangeListener baseLayerListener = new PropertyChangeListener() {
                @Override
                public void propertyChange(final PropertyChangeEvent evt) {
                    if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
                        if (layer.getActiveChangeDirection() != .) {
                            try {
                                baseExplorer.setSelectedNodes(new Node[0]);
                            } catch (PropertyVetoException ex) {
                                Exceptions.printStackTrace(ex);
                            }
                            for (Node node : (Node[]) evt.getNewValue()) {
                                Geographical object = node.getLookup().lookup(Geographical.class);
                                ExplorerManagerUtil.addObjectToSelection(objectbaseExplorer);
                            }
                            for (Node node : (Node[]) evt.getNewValue()) {
                                ..println("MAP_TO_BASE:Selected node " + node.getDisplayName());
                            }
                        }
                    }
                }
            };
            .add(baseLayerListener);
            layer.addPropertyChangeListener(baseLayerListener);
        }
        public static void SyncMapExplorer(final Layer layerfinal ExplorerManager mapExplorer) {
            PropertyChangeListener mapListener = new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
                        layer.fireNodeSelectionChange(evt.);
                    }
                }
            };
            .add(mapListener);
            mapExplorer.addPropertyChangeListener(mapListener);
            PropertyChangeListener layerListener = new PropertyChangeListener() {
                @Override
                public void propertyChange(final PropertyChangeEvent evt) {
                    if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
                        if (layer.getActiveChangeDirection() != .) {
                            try {
                                mapExplorer.setSelectedNodes(new Node[0]);
                            } catch (PropertyVetoException ex) {
                                Exceptions.printStackTrace(ex);
                            }
                            for (Node node : (Node[]) evt.getNewValue()) {
                                Geographical object = node.getLookup().lookup(Geographical.class);
                                ExplorerManagerUtil.addObjectToSelection(objectmapExplorer);
                            }
                            for (Node node : (Node[]) evt.getNewValue()) {
                                ..println("BASE_TO_MAP:Selected node " + node.getDisplayName());
                            }
                        }
                    }
                }
            };
            .add(layerListener);
            layer.addPropertyChangeListener(layerListener);
        }
    }
New to GrepCode? Check out our FAQ X