nl.cloudfarming.client.geoviewer.jxmap.layerlist.LayerListController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geoviewer-jxmap Show documentation
Show all versions of geoviewer-jxmap Show documentation
AgroSense geoviewer JXMap implementation. Contains a map/geoviewer TopComponent based on the JXMap classes from swingx.
/**
* 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.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.swing.ActionMap;
import javax.swing.JComponent;
import nl.cloudfarming.client.geoviewer.LayerInfo;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
/**
*
* @author Timon Veenstra
*/
public class LayerListController implements ExplorerManager.Provider, Lookup.Provider{
private final ExplorerManager manager = new ExplorerManager();
private final List layerNodes = Collections.synchronizedList(new ArrayList());
private final LayerListPanel layerListPanel = new LayerListPanel(manager);
private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap());
public LayerListController() {
manager.setRootContext(new LayerListRootNode(new LayerListChildFactory(this)));
}
public void addLayerNode(Node layerNode, LayerInfo layerInfo) {
LayerWrapper layerWrapper = new LayerWrapper(layerNode, layerInfo);
if (!layerNodes.contains(layerWrapper)) {
layerNodes.add(layerWrapper);
((LayerListRootNode) manager.getRootContext()).refresh();
}
}
public void removeLayerNode(Node layerNode) {
// can remove based on layer wrapper with null info since info is not in equals or hashcode
layerNodes.remove(new LayerWrapper(layerNode, null));
((LayerListRootNode) manager.getRootContext()).refresh();
}
LayerWrapper[] getLayerNodes() {
return layerNodes.toArray(new LayerWrapper[layerNodes.size()]);
}
public JComponent getLayerList() {
return layerListPanel;
}
@Override
public ExplorerManager getExplorerManager() {
return manager;
}
@Override
public Lookup getLookup() {
return lookup;
}
static class LayerWrapper{
private final Node layerNode;
private final LayerInfo layerInfo;
public LayerWrapper(Node layerNode, LayerInfo layerInfo) {
this.layerNode = layerNode;
this.layerInfo = layerInfo;
}
public Node getLayerNode() {
return layerNode;
}
public LayerInfo getLayerInfo() {
return layerInfo;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LayerWrapper other = (LayerWrapper) obj;
if (this.layerNode != other.layerNode && (this.layerNode == null || !this.layerNode.equals(other.layerNode))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 17 * hash + (this.layerNode != null ? this.layerNode.hashCode() : 0);
return hash;
}
}
}