All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.cloudfarming.client.geoviewer.jxmap.layerlist.LayerListNode Maven / Gradle / Ivy

Go to download

AgroSense geoviewer JXMap implementation. Contains a map/geoviewer TopComponent based on the JXMap classes from swingx.

There is a newer version: 13.03-beta
Show newest version
/**
 * Copyright (C) 2010-2012 Agrosense [email protected]
 *
 * 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.jxmap.layerlist;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.beans.BeanInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.Action;
import nl.cloudfarming.client.geoviewer.Layer;
import nl.cloudfarming.client.geoviewer.LayerInfo;
import nl.cloudfarming.client.geoviewer.event.GeoEvent;
import org.openide.nodes.FilterNode;
import org.openide.util.ImageUtilities;

/**
 *
 * @author Timon Veenstra
 */
class LayerListNode extends FilterNode{
    
    private final LayerInfo info;
    private final SettingsForLayerAction settingsAction;
    private boolean visible = true;
    private final Image ICON_32_ON = ImageUtilities.loadImage("nl/cloudfarming/client/geoviewer/Actions-layer-visible-on-icon32.png");
    private final Image ICON_32_OFF = ImageUtilities.loadImage("nl/cloudfarming/client/geoviewer/Actions-layer-visible-off-icon32.png");
    private final Image ICON_16_ON = ImageUtilities.loadImage("nl/cloudfarming/client/geoviewer/Actions-layer-visible-on-icon.png");
    private final Image ICON_16_OFF = ImageUtilities.loadImage("nl/cloudfarming/client/geoviewer/Actions-layer-visible-off-icon.png");

    @Override
    public Image getIcon(int type) {
        switch (type) {
            case BeanInfo.ICON_COLOR_32x32:
                return visible ? ICON_32_ON : ICON_32_OFF;
            default:
                return visible ? ICON_16_ON : ICON_16_OFF;
        }

    }    

    LayerListNode(LayerListController.LayerWrapper layerWrapper) {
        super(layerWrapper.getLayerNode(), new FilterLayerListChildren(layerWrapper.getLayerNode()));
        this.info = layerWrapper.getLayerInfo();
        Layer layer = getLookup().lookup(Layer.class);
        settingsAction = new SettingsForLayerAction(info, layer);
    }
 
    @Override
    public Action[] getActions(boolean context) {

        final Layer layer = getLookup().lookup(Layer.class);

        List superActions = new ArrayList();

        if (super.getActions(context) != null && super.getActions(context).length > 0) {
            superActions.addAll(Arrays.asList(super.getActions(context)));
        }
        superActions.add(new RemoveLayerAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                GeoEvent.getProducer().triggerEvent(GeoEvent.DISCARD_LAYER, layer);
            }
        });
        superActions.add(settingsAction);
        superActions.add(new VisibilityLayerAction(info) {

            @Override
            public void actionPerformed(ActionEvent ae) {
                super.actionPerformed(ae);
                fireIconChange();
            }
        });
        return superActions.toArray(new Action[superActions.size()]);
    }

    @Override
    public Action getPreferredAction() {
        
        return settingsAction;
    }

    
    
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy