001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.project.command.factory;
010:
011: import java.util.List;
012:
013: import net.refractions.udig.project.ILayer;
014: import net.refractions.udig.project.command.CompositeCommand;
015: import net.refractions.udig.project.command.MapCommand;
016: import net.refractions.udig.project.command.UndoableComposite;
017: import net.refractions.udig.project.command.UndoableMapCommand;
018: import net.refractions.udig.project.internal.commands.selection.BBoxSelectionCommand;
019: import net.refractions.udig.project.internal.commands.selection.FIDSelectCommand;
020: import net.refractions.udig.project.internal.commands.selection.NoSelectCommand;
021: import net.refractions.udig.project.internal.commands.selection.SelectCommand;
022:
023: import org.geotools.feature.Feature;
024: import org.geotools.filter.Filter;
025:
026: import com.vividsolutions.jts.geom.Envelope;
027:
028: /**
029: * A factory which can be used to create all the standard selection commands.
030: *
031: * API use
032: *
033: * @author jeichar
034: * @since 0.3
035: */
036: @SuppressWarnings("deprecation")
037: public class SelectionCommandFactory extends
038: net.refractions.udig.project.command.SelectionCommandFactory {
039: /**
040: * Creates a new SelectionCommandFactory object
041: *
042: * @return a new SelectionCommandFactory object
043: */
044: public static SelectionCommandFactory getInstance() {
045: return instance;
046: }
047:
048: private static final SelectionCommandFactory instance = new SelectionCommandFactory();
049:
050: protected SelectionCommandFactory() {
051: // no op;
052: }
053:
054: /**
055: * Creates a new {@linkplain BBoxSelectionCommand}
056: *
057: * @param bbox A bounding used as the filter, all features intersecting the bbox will be
058: * considered selected
059: * @param modifiers Options include: BBoxSelectionCommand.ADD, BBoxSelectionCommand.NONE,
060: * BBoxSelectionCommand.SUBTRACT
061: * @return A new BBoxSelectionCommand. The command should be sent to the
062: * {@linkplain SelectionManager}to be executed.
063: * @see Envelope
064: * @see MapCommand
065: */
066: public UndoableMapCommand createBBoxSelectionCommand(Envelope bbox,
067: int modifiers) {
068: return new BBoxSelectionCommand(bbox, modifiers);
069: }
070:
071: /**
072: * Creates a new {@linkplain BBoxSelectionCommand}.
073: * Same as createBBoxSelectionCommand(bbox, BBoxSelectionCommand.NONE)
074: *
075: * @param bbox A bounding used as the filter, all features intersecting the bbox will be
076: * considered selected
077: * @return A new BBoxSelectionCommand. The command should be sent to the
078: * {@linkplain SelectionManager}to be executed.
079: * @see Envelope
080: * @see MapCommand
081: */
082: public UndoableMapCommand createBBoxSelectionCommand(
083: Envelope boundingBox) {
084: return new BBoxSelectionCommand(boundingBox,
085: BBoxSelectionCommand.NONE);
086: }
087:
088: /**
089: * Creates a {@linkplain NoSelectCommand}
090: *
091: * @return a {@linkplain NoSelectCommand}object. The command should be sent to the
092: * {@linkplain SelectionManager}to be executed.
093: * @see MapCommand
094: */
095: public UndoableMapCommand createNoSelectCommand() {
096: return new NoSelectCommand();
097: }
098:
099: /**
100: * Create a MapCommand that sets the layer selection to be a fidfilter.
101: *
102: * @return a {@linkplain FIDSelectCommand}
103: * @see MapCommand
104: */
105: public UndoableMapCommand createFIDSelectCommand(ILayer layer,
106: String fid) {
107: return new FIDSelectCommand(layer, fid);
108: }
109:
110: /**
111: * Create a MapCommand that sets the layer selection to be a fidfilter.
112: *
113: * @return a {@linkplain FIDSelectCommand}
114: * @see MapCommand
115: */
116: public UndoableMapCommand createFIDSelectCommand(ILayer layer,
117: Feature feature) {
118: return new FIDSelectCommand(layer, feature.getID());
119: }
120:
121: /**
122: * Create a MapCommand that sets the layer selection to be the filter.
123: *
124: * @return a {@linkplain SelectCommand}
125: * @see MapCommand
126: */
127: public UndoableMapCommand createSelectCommand(ILayer layer,
128: Filter filter) {
129: return new SelectCommand(layer, filter);
130: }
131:
132: /**
133: * Create a CompositeCommand
134: *
135: * @param commands the commands to be executed as a single command
136: * @return a {@linkplain CompositeCommand}
137: * @see MapCommand
138: */
139: public MapCommand createCompositeCommand(
140: List<? extends MapCommand> commands) {
141: return new CompositeCommand(commands);
142: }
143:
144: /**
145: * Create a CompositeCommand
146: *
147: * @param commands the commands to be executed as a single command
148: * @return a {@linkplain CompositeCommand}
149: * @see MapCommand
150: */
151: public UndoableMapCommand createUndoableCompositeCommand(
152: List<? extends UndoableMapCommand> commands) {
153: return new UndoableComposite(commands);
154: }
155:
156: }
|