01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.gui.swing;
17:
18: /**
19: * a simple selection manager
20: * @author Ian Turton
21: */
22: import javax.swing.event.EventListenerList;
23:
24: import org.geotools.gui.swing.event.SelectionChangeListener;
25: import org.geotools.gui.swing.event.SelectionChangedEvent;
26: import org.geotools.map.MapLayer;
27: import org.opengis.filter.Filter;
28:
29: public class SelectionManager {
30: EventListenerList listeners = new EventListenerList();
31:
32: /**
33: * the layer to select
34: */
35: MapLayer selectionLayer;
36:
37: public SelectionManager(MapLayer layer) {
38: setSelectionLayer(layer);
39: }
40:
41: /**
42: * add a SelectionChangedListener to this manager, note this need not
43: * be a map which is why we pass a filter back not a map point.
44: * @param l - the listener
45: */
46: public void addSelectionChangeListener(SelectionChangeListener l) {
47: listeners.add(SelectionChangeListener.class, l);
48: }
49:
50: /**
51: * Remove a selectionlistener
52: * @param l - the listener
53: */
54: public void removeSelectionChangeListener(SelectionChangeListener l) {
55: listeners.remove(SelectionChangeListener.class, l);
56: }
57:
58: /**
59: * notify listeners that the selection has changed
60: * @param source - where the mousemovement came from
61: * @param filter - the filter which selects the
62: * selected feature(s)
63: */
64: public void selectionChanged(Object source, Filter filter) {
65: SelectionChangeListener[] l = (SelectionChangeListener[]) listeners
66: .getListeners(SelectionChangeListener.class);
67: SelectionChangedEvent ev = new SelectionChangedEvent(source,
68: filter);
69:
70: for (int i = 0; i < l.length; i++) {
71: l[i].selectionChanged(ev);
72: }
73: }
74:
75: /**
76: * get the selected layer
77: * @return - the layer
78: */
79: public MapLayer getSelectionLayer() {
80: return selectionLayer;
81: }
82:
83: /**
84: * sets the selection layer
85: * @param selectionLayer - the layer
86: */
87: public void setSelectionLayer(MapLayer selectionLayer) {
88: this.selectionLayer = selectionLayer;
89:
90: }
91: }
|