gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.lib / org.gvsig.geoprocess.lib.sextante / src / main / java / org / gvsig / geoprocess / lib / sextante / SimpleTaskStatusDelegated.java @ 1552
History | View | Annotate | Download (5.51 KB)
1 | 223 | cordinyana | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | 245 | cordinyana | * Copyright (C) 2007-2012 gvSIG Association.
|
5 | 223 | cordinyana | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program 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
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | 245 | cordinyana | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 223 | cordinyana | */
|
24 | package org.gvsig.geoprocess.lib.sextante; |
||
25 | |||
26 | import java.util.Date; |
||
27 | |||
28 | import es.unex.sextante.core.ITaskMonitor; |
||
29 | |||
30 | import org.gvsig.tools.ToolsLocator; |
||
31 | import org.gvsig.tools.observer.Observer; |
||
32 | import org.gvsig.tools.task.SimpleTaskStatus; |
||
33 | import org.gvsig.tools.task.TaskStatusManager; |
||
34 | |||
35 | /**
|
||
36 | * {@link SimpleTaskStatus} implementation which delegates in a
|
||
37 | * {@link ITaskMonitor} and a default {@link SimpleTaskStatus}.
|
||
38 | *
|
||
39 | * @author gvSIG Team
|
||
40 | * @version $Id$
|
||
41 | */
|
||
42 | public class SimpleTaskStatusDelegated implements SimpleTaskStatus { |
||
43 | |||
44 | private final ITaskMonitor monitor; |
||
45 | private final SimpleTaskStatus status; |
||
46 | private long min; |
||
47 | private long max; |
||
48 | |||
49 | /**
|
||
50 | * Creates a new {@link SimpleTaskStatusDelegated} with a
|
||
51 | * {@link ITaskMonitor} and the name of the task to perform.
|
||
52 | *
|
||
53 | * @param monitor
|
||
54 | * to delegate to
|
||
55 | * @param taskName
|
||
56 | * name of the task to perform
|
||
57 | */
|
||
58 | public SimpleTaskStatusDelegated(ITaskMonitor monitor, String taskName) { |
||
59 | this.monitor = monitor;
|
||
60 | if (this.monitor != null) { |
||
61 | this.monitor.setDeterminate(false); |
||
62 | } |
||
63 | this.status =
|
||
64 | ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus( |
||
65 | taskName); |
||
66 | this.status.setAutoremove(true); |
||
67 | } |
||
68 | |||
69 | public void addObserver(Observer o) { |
||
70 | status.addObserver(o); |
||
71 | } |
||
72 | |||
73 | public void deleteObserver(Observer o) { |
||
74 | status.deleteObserver(o); |
||
75 | } |
||
76 | |||
77 | public void deleteObservers() { |
||
78 | status.deleteObservers(); |
||
79 | } |
||
80 | |||
81 | public void setTittle(String tittle) { |
||
82 | status.setTitle(tittle); |
||
83 | } |
||
84 | |||
85 | public void setTitle(String title) { |
||
86 | status.setTitle(title); |
||
87 | } |
||
88 | |||
89 | public void message(String message) { |
||
90 | status.message(message); |
||
91 | if (this.monitor != null) { |
||
92 | monitor.setProgressText(message); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | public void setRangeOfValues(long min, long max) { |
||
97 | this.min = min;
|
||
98 | this.max = max;
|
||
99 | status.setRangeOfValues(min, max); |
||
100 | if (this.monitor != null) { |
||
101 | monitor.setDeterminate(true);
|
||
102 | } |
||
103 | } |
||
104 | |||
105 | public void setCurValue(long value) { |
||
106 | status.setCurValue(value); |
||
107 | if (this.monitor != null) { |
||
108 | monitor.setProgress((int) (value - min), (int) (max - min)); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | public boolean isCancellationRequested() { |
||
113 | return status.isCancellationRequested();
|
||
114 | } |
||
115 | |||
116 | public void cancelRequest() { |
||
117 | status.cancelRequest(); |
||
118 | } |
||
119 | |||
120 | public void terminate() { |
||
121 | status.terminate(); |
||
122 | if (this.monitor != null) { |
||
123 | monitor.close(); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | public String getTitle() { |
||
128 | return status.getTitle();
|
||
129 | } |
||
130 | |||
131 | public void cancel() { |
||
132 | status.cancel(); |
||
133 | } |
||
134 | |||
135 | public String getCode() { |
||
136 | return status.getCode();
|
||
137 | } |
||
138 | |||
139 | public void abort() { |
||
140 | status.abort(); |
||
141 | if (this.monitor != null) { |
||
142 | monitor.close(); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | public int getCompleted() { |
||
147 | return status.getCompleted();
|
||
148 | } |
||
149 | |||
150 | public void remove() { |
||
151 | status.remove(); |
||
152 | } |
||
153 | |||
154 | public void add() { |
||
155 | status.add(); |
||
156 | } |
||
157 | |||
158 | public String getLabel() { |
||
159 | return status.getLabel();
|
||
160 | } |
||
161 | |||
162 | public void setCancellable(boolean cancellable) { |
||
163 | status.setCancellable(cancellable); |
||
164 | } |
||
165 | |||
166 | public boolean isCancelled() { |
||
167 | return status.isCancelled()
|
||
168 | || (monitor != null && monitor.isCanceled());
|
||
169 | } |
||
170 | |||
171 | public void setAutoremove(boolean autoremove) { |
||
172 | status.setAutoremove(autoremove); |
||
173 | } |
||
174 | |||
175 | public boolean isAborted() { |
||
176 | return status.isAborted();
|
||
177 | } |
||
178 | |||
179 | public boolean isRunning() { |
||
180 | return status.isRunning();
|
||
181 | } |
||
182 | |||
183 | public boolean getAutoRemove() { |
||
184 | return status.getAutoRemove();
|
||
185 | } |
||
186 | |||
187 | public Date getLastModification() { |
||
188 | return status.getLastModification();
|
||
189 | } |
||
190 | |||
191 | public TaskStatusManager getManager() {
|
||
192 | return status.getManager();
|
||
193 | } |
||
194 | |||
195 | public boolean isIndeterminate() { |
||
196 | return status.isIndeterminate();
|
||
197 | } |
||
198 | |||
199 | public boolean isCancellable() { |
||
200 | return status.isCancellable();
|
||
201 | } |
||
202 | |||
203 | 303 | nbrodin | public void pop() { |
204 | status.pop(); |
||
205 | } |
||
206 | |||
207 | public void push() { |
||
208 | status.push(); |
||
209 | } |
||
210 | |||
211 | public void setIndeterminate() { |
||
212 | status.setIndeterminate(); |
||
213 | } |
||
214 | 1046 | jjdelcerro | |
215 | public void restart() { |
||
216 | status.restart(); |
||
217 | } |
||
218 | 303 | nbrodin | |
219 | 1109 | jjdelcerro | public void incrementCurrentValue() { |
220 | this.status.incrementCurrentValue();
|
||
221 | } |
||
222 | |||
223 | public String getMessage() { |
||
224 | return this.status.getMessage(); |
||
225 | } |
||
226 | |||
227 | 1552 | jjdelcerro | @Override
|
228 | public String getProgressLabel() { |
||
229 | return status.getProgressLabel();
|
||
230 | } |
||
231 | |||
232 | 223 | cordinyana | } |