svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / commands / FrameManager.java @ 167
History | View | Annotate | Download (6.45 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 |
private ArrayList<IFFrame> fframes = new ArrayList<IFFrame>(); |
33 |
private BitSet invalidates = new BitSet(); |
34 |
|
35 |
/**
|
36 |
* Returns from an index the FFrame.
|
37 |
*
|
38 |
* @param index
|
39 |
*
|
40 |
* @return FFrame.
|
41 |
*/
|
42 |
public IFFrame getFFrame(int index) { |
43 |
return fframes.get(index);
|
44 |
} |
45 |
|
46 |
/**
|
47 |
* Returns the number of FFrame.
|
48 |
*
|
49 |
* @return Number of FFrames
|
50 |
*/
|
51 |
public int getFFrameCount() { |
52 |
return fframes.size();
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Undo add FFrame from index.
|
57 |
*
|
58 |
* @param index
|
59 |
*/
|
60 |
public void undoAddFFrame(int index) { |
61 |
doRemoveFFrame(index); |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Add FFrame.
|
66 |
*
|
67 |
* @param frame
|
68 |
*
|
69 |
* @return index of new fframe.
|
70 |
*/
|
71 |
public int doAddFFrame(IFFrame frame) { |
72 |
fframes.add(frame); |
73 |
int index = fframes.size() - 1; |
74 |
notifyAdded(index); |
75 |
return index;
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* Add FFrame from index.
|
80 |
*
|
81 |
* @param frame
|
82 |
* New FFrame.
|
83 |
* @param index
|
84 |
* Index of new FFrame.
|
85 |
*/
|
86 |
public void doAddFFrame(IFFrame frame, int index) { |
87 |
invalidates.set(index, false);
|
88 |
fframes.set(index, frame); |
89 |
notifyAdded(index); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Undo modify an FFrame modified.
|
94 |
*
|
95 |
* @param fant
|
96 |
* Previous fframe.
|
97 |
* @param fnew
|
98 |
* New FFrame.
|
99 |
* @param indexAnt
|
100 |
* Actual index.
|
101 |
* @param indexLast
|
102 |
* Previous index.
|
103 |
*/
|
104 |
public void undoModifyFFrame(int index, int newIndex) { |
105 |
undoRemoveFFrame(index); |
106 |
undoAddFFrame(newIndex); |
107 |
IFFrame fant = fframes.get(newIndex); |
108 |
IFFrame fnew = fframes.get(index); |
109 |
refreshDependences(fant, fnew); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Modify FFrame from index and new FFrame.
|
114 |
*
|
115 |
* @param indexAnt
|
116 |
* Actual index.
|
117 |
* @param frameNext
|
118 |
* New FFrame.
|
119 |
*
|
120 |
* @return New index of FFrame.
|
121 |
*/
|
122 |
public int doModifyFFrame(int indexAnt, IFFrame frameNext) { |
123 |
doRemoveFFrame(indexAnt); |
124 |
|
125 |
return doAddFFrame(frameNext);
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Undo Remove FFrame from index.
|
130 |
*
|
131 |
* @param index
|
132 |
* Actual index of FFrame.
|
133 |
*/
|
134 |
public void undoRemoveFFrame(int index) { |
135 |
invalidates.set(index, false);
|
136 |
notifyAdded(index); |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Remove FFrame from actual index.
|
141 |
*
|
142 |
* @param index
|
143 |
* Actual index.
|
144 |
*/
|
145 |
public void doRemoveFFrame(int index) { |
146 |
invalidates.set(index, true);
|
147 |
notifyRemoved(index); |
148 |
} |
149 |
|
150 |
protected void notifyRemoved(int index) { |
151 |
IFFrame frame = fframes.get(index); |
152 |
frame.frameRemoved(); |
153 |
} |
154 |
|
155 |
protected void notifyAdded(int index) { |
156 |
IFFrame frame = fframes.get(index); |
157 |
frame.frameAdded(); |
158 |
} |
159 |
|
160 |
/**
|
161 |
* Returns all the fframes that are not removed.
|
162 |
*
|
163 |
* @return Vector with fframes.
|
164 |
*/
|
165 |
public IFFrame[] getFFrames() { |
166 |
ArrayList<IFFrame> frames = new ArrayList<IFFrame>(); |
167 |
|
168 |
for (int i = 0; i < getFFrameCount(); i++) { |
169 |
if (!invalidates.get(i)) {
|
170 |
frames.add(fframes.get(i)); |
171 |
} |
172 |
} |
173 |
|
174 |
IFFrame[] fframesV = frames.toArray(new IFFrame[0]); |
175 |
|
176 |
return fframesV;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Returns all the fframes, remove and done not remove.
|
181 |
*
|
182 |
* @return All FFrames.
|
183 |
*/
|
184 |
public IFFrame[] getAllFFrames() { |
185 |
return fframes.toArray(new IFFrame[0]); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Returns all the fframes, remove and done not remove and the ones that are
|
190 |
* in the FFrameGroups
|
191 |
*
|
192 |
* @return All FFrames.
|
193 |
*/
|
194 |
public IFFrame[] getAllFFrameToDepends() { |
195 |
IFFrame[] fs = getAllFFrames();
|
196 |
|
197 |
return getFFrameToDepends(fs);
|
198 |
} |
199 |
|
200 |
private IFFrame[] getFFrameToDepends(IFFrame[] fs) { |
201 |
ArrayList<IFFrame> result = new ArrayList<IFFrame>(); |
202 |
|
203 |
for (int i = 0; i < fs.length; i++) { |
204 |
result.add(fs[i]); |
205 |
|
206 |
if (fs[i] instanceof FFrameGroup) { |
207 |
IFFrame[] ffs =
|
208 |
getFFrameToDepends(((FFrameGroup) fs[i]).getFFrames()); |
209 |
|
210 |
for (int j = 0; j < ffs.length; j++) { |
211 |
result.add(ffs[j]); |
212 |
} |
213 |
} |
214 |
} |
215 |
|
216 |
return result.toArray(new IFFrame[0]); |
217 |
} |
218 |
|
219 |
public void refreshDependences(IFFrame fant, IFFrame fnew) { |
220 |
for (int i = 0; i < fframes.size(); i++) { |
221 |
if (fframes.get(i) instanceof IFFrameViewDependence) { |
222 |
IFFrameViewDependence f = |
223 |
(IFFrameViewDependence) fframes.get(i); |
224 |
f.refreshDependence(fant, fnew); |
225 |
} |
226 |
} |
227 |
} |
228 |
|
229 |
public void redoModifyFFrame(int index, int newIndex, IFFrame frame) { |
230 |
doRemoveFFrame(index); |
231 |
doAddFFrame(frame, newIndex); |
232 |
IFFrame fant = fframes.get(newIndex); |
233 |
refreshDependences(fant, frame); |
234 |
} |
235 |
|
236 |
public BitSet invalidates() { |
237 |
return invalidates;
|
238 |
} |
239 |
|
240 |
public void clear() { |
241 |
|
242 |
} |
243 |
} |