01: package org.tcat.citd.sim.udig.bookmarks.internal;
02:
03: import java.util.Collection;
04: import java.util.Vector;
05:
06: import net.refractions.udig.project.IMap;
07:
08: /**
09: * This class provides a wrapper for displaying <code>IMap</code> objects as folders in the
10: * <code>BookmarksView</code>.<BR>
11: * <BR>
12: * This gives the advantage of more easily displaying custom menus and icons.
13: * <p>
14: * </p>
15: *
16: * @author cole.markham
17: * @since 1.0.0
18: */
19: public class MapWrapper {
20: private IMap map;
21:
22: /**
23: * Default constructor
24: *
25: * @param map The map that this object will wrap.
26: */
27: public MapWrapper(IMap map) {
28: this .map = map;
29: }
30:
31: /**
32: * @return Returns the map.
33: */
34: public IMap getMap() {
35: return map;
36: }
37:
38: /**
39: * @param map The map to set.
40: */
41: public void setMap(IMap map) {
42: this .map = map;
43: }
44:
45: /**
46: * Get the name for the map
47: *
48: * @return the name
49: */
50: public String getName() {
51: return map.getName();
52: }
53:
54: @Override
55: public String toString() {
56: return this .getName();
57: }
58:
59: /**
60: * Get a wrapper for the project that contains this map
61: *
62: * @return the new ProjectWrapper
63: */
64: public ProjectWrapper getProjectWrapper() {
65: ProjectWrapper wrapper = new ProjectWrapper(map.getProject());
66: return wrapper;
67: }
68:
69: /**
70: * Unwrap all of the maps in the given list
71: *
72: * @param wrappedMaps
73: * @return a Collection of IMap objects
74: */
75: public static Collection unwrap(Collection wrappedMaps) {
76: Vector<IMap> maps = new Vector<IMap>(wrappedMaps.size());
77: for (Object element : wrappedMaps) {
78: if (element instanceof MapWrapper) {
79: MapWrapper wrapper = (MapWrapper) element;
80: maps.add(wrapper.getMap());
81: }
82: }
83: return maps;
84: }
85:
86: /**
87: * Wrap the maps in the given list
88: *
89: * @param maps
90: * @return a Collection of MapWrapper objects
91: */
92: public static Collection<MapWrapper> wrap(Collection<IMap> maps) {
93: Vector<MapWrapper> wrapped = new Vector<MapWrapper>(maps.size());
94: for (IMap map : maps) {
95: wrapped.add(new MapWrapper(map));
96: }
97: return wrapped;
98: }
99: }
|