001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project.ui.commands;
018:
019: import java.awt.Color;
020: import java.awt.Point;
021: import java.awt.Shape;
022: import java.io.IOException;
023: import java.util.List;
024:
025: import net.refractions.udig.project.ILayer;
026: import net.refractions.udig.project.command.UndoableMapCommand;
027: import net.refractions.udig.project.render.IViewportModel;
028: import net.refractions.udig.project.render.displayAdapter.IMapDisplay;
029: import net.refractions.udig.project.ui.IAnimation;
030: import net.refractions.udig.project.ui.internal.commands.draw.CompositeDrawCommand;
031: import net.refractions.udig.project.ui.internal.commands.draw.DrawEditFeatureCommand;
032: import net.refractions.udig.project.ui.internal.commands.draw.DrawFeatureCommand;
033: import net.refractions.udig.project.ui.internal.commands.draw.DrawShapeCommand;
034: import net.refractions.udig.project.ui.internal.commands.draw.StartAnimationCommand;
035: import net.refractions.udig.project.ui.internal.commands.draw.StopAnimationCommand;
036: import net.refractions.udig.project.ui.internal.commands.draw.TranslateCommand;
037: import net.refractions.udig.project.ui.internal.commands.draw.ZoomDrawCommand;
038: import net.refractions.udig.ui.graphics.ViewportGraphics;
039:
040: import org.geotools.feature.Feature;
041: import org.opengis.referencing.crs.CoordinateReferenceSystem;
042:
043: /**
044: * Creates draw commands.
045: *
046: * @author jeichar
047: * @since 0.3
048: */
049: public class DrawCommandFactory {
050:
051: private DrawCommandFactory() {
052: // no op
053: }
054:
055: private static final DrawCommandFactory instance = new DrawCommandFactory();
056:
057: /**
058: * Creates a new DrawCommandFactory object
059: *
060: * @return a new DrawCommandFactory object
061: */
062: public static DrawCommandFactory getInstance() {
063: return instance;
064: }
065:
066: /**
067: * Creates a new {@linkplain DrawShapeCommand}
068: *
069: * @param shape The shape to draw
070: * @param paint the shape outline color
071: * @param lineStyle see {@linkplain ViewportGraphics} for line styles
072: * @param lineWidth The width of the shape outline
073: * @return a new DrawShapeCommand object
074: * @see DrawShapeCommand
075: */
076: public DrawShapeCommand createDrawShapeCommand(Shape shape,
077: Color paint, int lineStyle, int lineWidth) {
078: return new DrawShapeCommand(shape, paint, lineStyle, lineWidth);
079: }
080:
081: /**
082: * Creates a new {@linkplain DrawShapeCommand}
083: *
084: * @param shape
085: * @param paint
086: * @return a new DrawShapeCommand object
087: * @see DrawShapeCommand
088: */
089: public DrawShapeCommand createDrawShapeCommand(Shape shape,
090: Color paint) {
091: return createDrawShapeCommand(shape, paint, -1, 1);
092: }
093:
094: /**
095: * Creates a new {@linkplain DrawShapeCommand}
096: *
097: * @param shape
098: * @return a new DrawShapeCommand object
099: */
100: public DrawShapeCommand createDrawShapeCommand(Shape shape) {
101: return createDrawShapeCommand(shape, null, -1, 1);
102: }
103:
104: /**
105: * Creates a new {@linkplain DrawEditFeatureCommand}
106: *
107: * @param model The viewport model associated with the viewport that will be rendered to.
108: * @return a new DrawFeatureCommand object
109: * @see DrawEditFeatureCommand
110: */
111: public IDrawCommand createEditFeaturesCommand(IViewportModel model) {
112: return new DrawEditFeatureCommand(model);
113: }
114:
115: /**
116: * Creates a new {@linkplain TranslateCommand}
117: *
118: * @param offset The amount of translation
119: * @return a new TranslateCommand object
120: * @see TranslateCommand
121: */
122: public TranslateCommand createTranslateCommand(Point offset) {
123: return new TranslateCommand(offset);
124: }
125:
126: /**
127: * Creates a new {@linkplain TranslateCommand}
128: *
129: * @param x the amount of y translation
130: * @param y the amount of y translation
131: * @return a new {@linkplain TranslateCommand}
132: * @see TranslateCommand
133: */
134: public TranslateCommand createTranslateCommand(int x, int y) {
135: return new TranslateCommand(x, y);
136: }
137:
138: /**
139: * Creates a new {@linkplain TranslateCommand}
140: *
141: * @param x the amount of y translation
142: * @param y the amount of y translation
143: * @return a new {@linkplain ZoomDrawCommand}
144: * @see ZoomDrawCommand
145: */
146: public ZoomDrawCommand createZoomDrawCommand(int centerx,
147: int centery, double amount) {
148: return new ZoomDrawCommand(centerx, centery, amount);
149: }
150:
151: /**
152: * Creates a new {@linkplain DrawFeatureCommand}
153: *
154: * @param feature the feature to draw
155: * @param layer the layer that the feature is part of.
156: * @param model the ViewportModel that is used to calculate size and position.
157: * @return a new {@linkplain DrawFeatureCommand}
158: * @see DrawFeatureCommand
159: */
160: public DrawFeatureCommand createDrawFeatureCommand(Feature feature,
161: ILayer layer) {
162: try {
163: return new DrawFeatureCommand(feature, layer);
164: } catch (IOException e) {
165: return new DrawFeatureCommand(feature);
166: }
167: }
168:
169: /**
170: * Creates a new {@linkplain DrawFeatureCommand}
171: *
172: * @param feature the feature to draw
173: * @param evaluationObject the layer that the feature is part of.
174: * @param model the ViewportModel that is used to calculate size and position.
175: * @return a new {@linkplain DrawFeatureCommand}
176: * @see DrawFeatureCommand
177: */
178: public DrawFeatureCommand createDrawFeatureCommand(Feature feature) {
179: return new DrawFeatureCommand(feature);
180: }
181:
182: /**
183: * Creates a new {@linkplain DrawFeatureCommand}
184: *
185: * @param feature the feature to draw
186: * @param evaluationObject the layer that the feature is part of.
187: * @return a new {@linkplain DrawFeatureCommand}
188: * @see DrawFeatureCommand
189: */
190: public DrawFeatureCommand createDrawFeatureCommand(Feature feature,
191: CoordinateReferenceSystem crs) {
192: return new DrawFeatureCommand(feature, crs);
193: }
194:
195: /**
196: * Creates a new {@linkplain StartAnimationCommand}
197: *
198: * @return a new {@linkplain StartAnimationCommand}
199: * @see StartAnimationCommand
200: */
201: public UndoableMapCommand createStartAnimationCommand(
202: IMapDisplay display, List<IAnimation> animations) {
203: return new StartAnimationCommand(display, animations);
204: }
205:
206: /**
207: * Creates a new {@linkplain StartAnimationCommand}
208: *
209: * @return a new {@linkplain StartAnimationCommand}
210: * @see StartAnimationCommand
211: */
212: public UndoableMapCommand createStopAnimationCommand(
213: IMapDisplay display, List<IAnimation> animations) {
214: return new StopAnimationCommand(display, animations);
215: }
216:
217: /**
218: * Creates a new {@linkplain CompositeDrawCommand}
219: *
220: * @param commandsArray
221: * @return
222: */
223: public IDrawCommand createCompositeDrawCommand(
224: IDrawCommand[] commandsArray) {
225: return new CompositeDrawCommand(commandsArray);
226: }
227:
228: /**
229: * Creates a new {@linkplain CompositeDrawCommand}
230: *
231: * @param commandsList
232: * @return
233: */
234: public IDrawCommand createCompositeDrawCommand(
235: List<? extends IDrawCommand> commandsList) {
236: return new CompositeDrawCommand(commandsList);
237: }
238:
239: }
|