01: package net.refractions.udig.project.ui.internal.commands.draw;
02:
03: import java.awt.Rectangle;
04: import java.util.ArrayList;
05: import java.util.List;
06:
07: import org.eclipse.core.runtime.IProgressMonitor;
08:
09: import net.refractions.udig.project.IMap;
10: import net.refractions.udig.project.render.displayAdapter.IMapDisplay;
11: import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
12: import net.refractions.udig.project.ui.commands.IDrawCommand;
13: import net.refractions.udig.ui.graphics.ViewportGraphics;
14:
15: /**
16: *
17: *
18: * @author Vitalus
19: *
20: */
21: public class CompositeDrawCommand extends AbstractDrawCommand {
22:
23: private List<IDrawCommand> internalCommands = null;
24:
25: public CompositeDrawCommand(IDrawCommand[] commandsArray) {
26:
27: this .internalCommands = new ArrayList<IDrawCommand>();
28: for (int i = 0; i < commandsArray.length; i++) {
29: internalCommands.add(commandsArray[i]);
30: }
31: }
32:
33: /**
34: *
35: * @param commandsList list of <code>IDrawCommand</code>s.
36: */
37: public CompositeDrawCommand(
38: List<? extends IDrawCommand> commandsList) {
39: this .internalCommands = new ArrayList<IDrawCommand>(
40: commandsList);
41: }
42:
43: public Rectangle getValidArea() {
44: return null;
45: }
46:
47: @Override
48: public void setGraphics(ViewportGraphics graphics,
49: IMapDisplay display) {
50:
51: super .setGraphics(graphics, display);
52: if (internalCommands != null) {
53: for (IDrawCommand command : internalCommands) {
54: command.setGraphics(graphics, display);
55: }
56: }
57: }
58:
59: @Override
60: public void setValid(boolean valid) {
61:
62: super .setValid(valid);
63: if (internalCommands != null) {
64: for (IDrawCommand command : internalCommands) {
65: command.setValid(valid);
66: }
67: }
68: }
69:
70: /**
71: *
72: */
73: @Override
74: public void setMap(IMap map) {
75: super .setMap(map);
76: if (internalCommands != null) {
77: for (IDrawCommand command : internalCommands) {
78: command.setMap(map);
79: }
80: }
81: }
82:
83: /**
84: *
85: */
86: public void run(IProgressMonitor monitor) throws Exception {
87:
88: for (IDrawCommand command : internalCommands) {
89: try {
90: if (command.isValid())
91: command.run(monitor);
92: } catch (Exception e) {
93: e.printStackTrace();
94: }
95: }
96: }
97:
98: }
|