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

nl.cloudfarming.client.geoviewer.jxmap.map.RootMapPanelController 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.map;

import com.vividsolutions.jts.geom.Point;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.cloudfarming.client.geoviewer.Geographical;
import nl.cloudfarming.client.geoviewer.Layer;
import nl.cloudfarming.client.geoviewer.LayerInfo;
import nl.cloudfarming.client.geoviewer.event.GeoEvent;
import nl.cloudfarming.client.geoviewer.jxmap.LayerDropTarget;
import nl.cloudfarming.client.geoviewer.jxmap.Module;
import nl.cloudfarming.client.geoviewer.jxmap.layerlist.LayerListController;
import nl.cloudfarming.eventbus.GuiEvent;
import nl.cloudfarming.eventbus.GuiEventBus;
import nl.cloudfarming.eventbus.GuiEventKey;
import nl.cloudfarming.eventbus.GuiEventListener;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.openide.nodes.Node;

/**
 * Controller of the rootmap panel.
 *
 * The RootMapPanelController is the
 * MapController implementation for the JXMap geoviewer
 * implementation. It exposes methods to control this map implementation.
 * 
* 

Swing hierarchy

The top swing component for the * RootMapController is the * {@link MapViewerTopComponent}. This TopComponent only contains the hook to * the netbeans window management system, like {@link #setActive(boolean)} on * componentActivated and componentDeactivated. The controller delivers the root * panel to TopComponent which is a {@link RootMapPanel}. The Controller * controls the state and content of this root panel.

The {@link RootMapPanel} * is a * JXPanel which contains a JLayerPane. The layered pane contains * several layers starting with the JXMap layer as background.

Layer * containing object ({@link ObjectLayer)} implementations) are represented as * an {@link ObjectLayerPanel} and added to the layered panel on the {@link RootMapPanel.LayerGroup#LAYER_ACTIVE} * position. * ObjectLayerPanels are ObjectScenes and contain * LayerObjectWidgets representing geographical components on the * map.

* * MapViewerTopComponent->RootMapPanel->ObjectLayerPanel->LayerObjectWidget * * @author Timon Veenstra */ public class RootMapPanelController { private final RootMapPanel mapPanel; private final Map layerPanelMap = new HashMap(); private static int lastId = 0; private final LayerDropTargetListener dropTargetListener = new LayerDropTargetListener(); private final RequestFocusEventListener requestFocusEventListener = new RequestFocusEventListener(); private static final Logger LOGGER = Logger.getLogger(RootMapPanelController.class.getName()); public RootMapPanelController(LayerListController layerListController) { mapPanel = new RootMapPanel(layerListController.getLayerList()); // // register a drop target listener for the layerlist component // DropTarget dt = new DropTarget(layerListController.getLayerList(), dropTargetListener); dt.setDefaultActions(DnDConstants.ACTION_COPY); dt.setActive(true); layerListController.getLayerList().setDropTarget(dt); // // register a drop target listener for the top panel of the map component // DropTarget dt2 = new DropTarget(mapPanel.getTopPanel(), dropTargetListener); dt.setDefaultActions(DnDConstants.ACTION_COPY); dt.setActive(true); mapPanel.getTopPanel().setDropTarget(dt2); // // add the request focus listener // GuiEventBus.addListener(requestFocusEventListener); } public void addLayerDropTarget(LayerDropTarget dropTarget) { dropTargetListener.addDropTarget(dropTarget); } public RootMapPanel getPanel() { return mapPanel; } public void addLayerNode(Node layerNode, LayerInfo layerInfo) { Layer layer = Layer.Finder.findLayer(layerNode); //FIXME set propert ID, should depend on layer order since its used for event dispatching LayerPanel layerPanel = new LayerPanel(layerNode, mapPanel.getMapViewer(), lastId++, layerInfo); // // let layerpanel listen to selection changes in layelist em. // layer.addPropertyChangeListener(layerPanel); // // save reference to the layerpanel and add it to the map panel // layerPanelMap.put(layer, layerPanel); mapPanel.addLayerPanel(layerPanel); } public void removeLayerNode(Node layerNode) { final Layer layer = Layer.Finder.findLayer(layerNode); if (layer == null){ LOGGER.warning("removeLayerNode called with a node without a layer in its hierarchy"); return; } LayerPanel layerPanel = layerPanelMap.get(layer); // // remove reference to the layerpanel and remove it from the map panel // mapPanel.removeLayerPanel(layerPanel); layerPanelMap.remove(layer); } public void refreshLayerNode(Node layerNode) { final Layer layer = Layer.Finder.findLayer(layerNode); if (layer == null){ LOGGER.warning("refreshLayerNode called with a node without a layer in its hierarchy"); return; } LayerPanel layerPanel = layerPanelMap.get(layer); if (layerPanel != null) { layerPanel.repaint(); } else { LOGGER.log(Level.WARNING, "refresh requested for unmanaged layer {0} in node {1}",new Object[]{layer,layerNode}); } } private class RequestFocusEventListener implements GuiEventListener { @Override public void onEvent(GuiEvent event) { Geographical geographical = event.getContent(); Point centroid = geographical.getCentroid(); if (centroid != null) { GeoPosition geoPosition = new GeoPosition(centroid.getY(), centroid.getX()); mapPanel.getMapViewer().setCenterPosition(geoPosition); mapPanel.getMapViewer().setZoom(3); } } @Override public boolean listensTo(GuiEventKey guiEventKey) { return GeoEvent.REQUEST_FOCUS.equals(guiEventKey); } @Override public String getModuleName() { return Module.MODULE_NAME; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy