svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / commands / FrameManager.java @ 36648
History | View | Annotate | Download (8.06 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
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 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.commands; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.BitSet; |
26 |
|
27 |
import org.gvsig.app.project.documents.layout.fframes.FFrameGroup; |
28 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
29 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameViewDependence; |
30 |
|
31 |
public class FrameManager { |
32 |
|
33 |
private ArrayList<IFFrame> fframes = new ArrayList<IFFrame>(); |
34 |
private BitSet invalidates = new BitSet(); |
35 |
|
36 |
/**
|
37 |
* Returns from an index the FFrame.
|
38 |
*
|
39 |
* @param index
|
40 |
*
|
41 |
* @return FFrame.
|
42 |
*/
|
43 |
public IFFrame getFFrame(int index) { |
44 |
return fframes.get(index);
|
45 |
} |
46 |
|
47 |
/**
|
48 |
* Returns the number of FFrame.
|
49 |
*
|
50 |
* @return Number of FFrames
|
51 |
*/
|
52 |
public int getFFrameCount() { |
53 |
return fframes.size();
|
54 |
} |
55 |
|
56 |
/**
|
57 |
* Add a FFrame in the mechanism of control creating a command.
|
58 |
*
|
59 |
* @param f
|
60 |
* FFrame to add
|
61 |
*/
|
62 |
// public void addFFrame(IFFrame f) {
|
63 |
// int virtualIndex = doAddFFrame(f);
|
64 |
// AbstractCommand command=new InsertFrameCommand(this, f, virtualIndex);
|
65 |
// command.setDescription(f.getNameFFrame());
|
66 |
// if (complex) {
|
67 |
// commands.add(command);
|
68 |
// } else {
|
69 |
// cr.add(command);
|
70 |
// PluginServices.getMainFrame().enableControls();
|
71 |
// }
|
72 |
// }
|
73 |
/**
|
74 |
* Remove the FFrame by the index.
|
75 |
*
|
76 |
* @param index
|
77 |
*/
|
78 |
// public void removeFFrame(int index) {
|
79 |
// if (invalidates.get(index)) {
|
80 |
// return;
|
81 |
// }
|
82 |
// IFFrame frame=getFFrame(index);
|
83 |
// doRemoveFFrame(index);
|
84 |
// AbstractCommand command=new DeleteFrameCommand(this, index);
|
85 |
// command.setDescription(frame.getNameFFrame());
|
86 |
// if (complex) {
|
87 |
// commands.add(command);
|
88 |
// } else {
|
89 |
// cr.add(command);
|
90 |
// PluginServices.getMainFrame().enableControls();
|
91 |
// }
|
92 |
// }
|
93 |
|
94 |
/**
|
95 |
* Modify a fframe to another fframe new.
|
96 |
*
|
97 |
* @param fant
|
98 |
* Previous Fframe.
|
99 |
* @param fnew
|
100 |
* New FFrame.
|
101 |
*/
|
102 |
// public boolean modifyFFrame(IFFrame fant, IFFrame fnew) {
|
103 |
// int posAnt = -1;
|
104 |
//
|
105 |
// for (int i = 0; i < fframes.size(); i++) {
|
106 |
// if (fframes.get(i).equals(fant) && !invalidates.get(i)) {
|
107 |
// posAnt = i;
|
108 |
// }
|
109 |
// }
|
110 |
// if (posAnt==-1)
|
111 |
// return false;
|
112 |
// int pos = doModifyFFrame(posAnt, fnew);
|
113 |
// AbstractCommand command=new UpdateFrameCommand(this, fnew, posAnt, pos);
|
114 |
// command.setDescription(fant.getNameFFrame());
|
115 |
// if (complex) {
|
116 |
// commands.add(command);
|
117 |
// } else {
|
118 |
// cr.add(command);
|
119 |
// PluginServices.getMainFrame().enableControls();
|
120 |
// }
|
121 |
//
|
122 |
// refreshDependences(fant, fnew);
|
123 |
// return true;
|
124 |
// }
|
125 |
/**
|
126 |
* Undo add FFrame from index.
|
127 |
*
|
128 |
* @param index
|
129 |
*/
|
130 |
public void undoAddFFrame(int index) { |
131 |
doRemoveFFrame(index); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* Add FFrame.
|
136 |
*
|
137 |
* @param frame
|
138 |
*
|
139 |
* @return index of new fframe.
|
140 |
*/
|
141 |
public int doAddFFrame(IFFrame frame) { |
142 |
fframes.add(frame); |
143 |
|
144 |
return fframes.size() - 1; |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Add FFrame from index.
|
149 |
*
|
150 |
* @param frame
|
151 |
* New FFrame.
|
152 |
* @param index
|
153 |
* Index of new FFrame.
|
154 |
*/
|
155 |
public void doAddFFrame(IFFrame frame, int index) { |
156 |
invalidates.set(index, false);
|
157 |
fframes.set(index, frame); |
158 |
} |
159 |
|
160 |
/**
|
161 |
* Undo modify an FFrame modified.
|
162 |
*
|
163 |
* @param fant
|
164 |
* Previous fframe.
|
165 |
* @param fnew
|
166 |
* New FFrame.
|
167 |
* @param indexAnt
|
168 |
* Actual index.
|
169 |
* @param indexLast
|
170 |
* Previous index.
|
171 |
*/
|
172 |
public void undoModifyFFrame(int index, int newIndex) { |
173 |
undoRemoveFFrame(index); |
174 |
undoAddFFrame(newIndex); |
175 |
IFFrame fant = fframes.get(newIndex); |
176 |
IFFrame fnew = fframes.get(index); |
177 |
refreshDependences(fant, fnew); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* Modify FFrame from index and new FFrame.
|
182 |
*
|
183 |
* @param indexAnt
|
184 |
* Actual index.
|
185 |
* @param frameNext
|
186 |
* New FFrame.
|
187 |
*
|
188 |
* @return New index of FFrame.
|
189 |
*/
|
190 |
public int doModifyFFrame(int indexAnt, IFFrame frameNext) { |
191 |
doRemoveFFrame(indexAnt); |
192 |
|
193 |
return doAddFFrame(frameNext);
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Undo Remove FFrame from index.
|
198 |
*
|
199 |
* @param index
|
200 |
* Actual index of FFrame.
|
201 |
*/
|
202 |
public void undoRemoveFFrame(int index) { |
203 |
invalidates.set(index, false);
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Remove FFrame from actual index.
|
208 |
*
|
209 |
* @param index
|
210 |
* Actual index.
|
211 |
*/
|
212 |
public void doRemoveFFrame(int index) { |
213 |
invalidates.set(index, true);
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Returns all the fframes that are not removed.
|
218 |
*
|
219 |
* @return Vector with fframes.
|
220 |
*/
|
221 |
public IFFrame[] getFFrames() { |
222 |
ArrayList<IFFrame> frames = new ArrayList<IFFrame>(); |
223 |
|
224 |
for (int i = 0; i < getFFrameCount(); i++) { |
225 |
if (!invalidates.get(i)) {
|
226 |
frames.add(fframes.get(i)); |
227 |
} |
228 |
} |
229 |
|
230 |
IFFrame[] fframesV = frames.toArray(new IFFrame[0]); |
231 |
|
232 |
return fframesV;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Returns all the fframes, remove and done not remove.
|
237 |
*
|
238 |
* @return All FFrames.
|
239 |
*/
|
240 |
public IFFrame[] getAllFFrames() { |
241 |
return fframes.toArray(new IFFrame[0]); |
242 |
} |
243 |
|
244 |
/**
|
245 |
* Returns all the fframes, remove and done not remove and the ones that are
|
246 |
* in the FFrameGroups
|
247 |
*
|
248 |
* @return All FFrames.
|
249 |
*/
|
250 |
public IFFrame[] getAllFFrameToDepends() { |
251 |
IFFrame[] fs = getAllFFrames();
|
252 |
|
253 |
return getFFrameToDepends(fs);
|
254 |
} |
255 |
|
256 |
private IFFrame[] getFFrameToDepends(IFFrame[] fs) { |
257 |
ArrayList<IFFrame> result = new ArrayList<IFFrame>(); |
258 |
|
259 |
for (int i = 0; i < fs.length; i++) { |
260 |
result.add(fs[i]); |
261 |
|
262 |
if (fs[i] instanceof FFrameGroup) { |
263 |
IFFrame[] ffs =
|
264 |
getFFrameToDepends(((FFrameGroup) fs[i]).getFFrames()); |
265 |
|
266 |
for (int j = 0; j < ffs.length; j++) { |
267 |
result.add(ffs[j]); |
268 |
} |
269 |
} |
270 |
} |
271 |
|
272 |
return result.toArray(new IFFrame[0]); |
273 |
} |
274 |
|
275 |
public void refreshDependences(IFFrame fant, IFFrame fnew) { |
276 |
for (int i = 0; i < fframes.size(); i++) { |
277 |
if (fframes.get(i) instanceof IFFrameViewDependence) { |
278 |
IFFrameViewDependence f = |
279 |
(IFFrameViewDependence) fframes.get(i); |
280 |
f.refreshDependence(fant, fnew); |
281 |
} |
282 |
} |
283 |
} |
284 |
|
285 |
public void redoModifyFFrame(int index, int newIndex, IFFrame frame) { |
286 |
doRemoveFFrame(index); |
287 |
doAddFFrame(frame, newIndex); |
288 |
IFFrame fant = fframes.get(newIndex); |
289 |
refreshDependences(fant, frame); |
290 |
} |
291 |
|
292 |
public BitSet invalidates() { |
293 |
return invalidates;
|
294 |
} |
295 |
|
296 |
public void clear() { |
297 |
// TODO Auto-generated method stub
|
298 |
|
299 |
} |
300 |
} |