root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / LayoutContext.java @ 21299
History | View | Annotate | Download (12.6 KB)
1 |
package com.iver.cit.gvsig.project.documents.layout; |
---|---|
2 |
|
3 |
import java.awt.geom.AffineTransform; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Hashtable; |
6 |
|
7 |
import org.gvsig.fmap.mapcontext.layers.XMLException; |
8 |
|
9 |
import com.iver.andami.PluginServices; |
10 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
11 |
import com.iver.cit.gvsig.project.documents.layout.commands.DefaultEditableFeatureSource; |
12 |
import com.iver.cit.gvsig.project.documents.layout.commands.FrameCommandsRecord; |
13 |
import com.iver.cit.gvsig.project.documents.layout.commands.FrameManager; |
14 |
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGroup; |
15 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
16 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap; |
17 |
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
18 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
19 |
import com.iver.utiles.XMLEntity; |
20 |
|
21 |
/**
|
22 |
* Model of LayoutControl.
|
23 |
*
|
24 |
* @author Vicente Caballero Navarro
|
25 |
*/
|
26 |
public class LayoutContext { |
27 |
private Attributes m_attributes = null; |
28 |
private IFFrame[] fframes; |
29 |
private FrameCommandsRecord fcr;
|
30 |
public static Hashtable nums = new Hashtable(); |
31 |
public int numBefore = 0; |
32 |
public int numBehind = 0; |
33 |
private boolean isEditable = true; |
34 |
private Boolean adjustToGrid = null; |
35 |
private Boolean m_showRuler; |
36 |
private Boolean isGridVisible = null; |
37 |
private ArrayList layoutDrawListeners=new ArrayList(); |
38 |
private AffineTransform m_MatrizTransf; |
39 |
/**
|
40 |
* Create a new object of LayoutContext.
|
41 |
*/
|
42 |
public LayoutContext() {
|
43 |
m_attributes=new Attributes(); |
44 |
m_MatrizTransf = new AffineTransform(); |
45 |
m_MatrizTransf.setToIdentity(); |
46 |
FrameManager fm=new FrameManager();
|
47 |
fcr = new FrameCommandsRecord(fm);
|
48 |
} |
49 |
/**
|
50 |
* Returns the AffineTransform that is applying in the Layout.
|
51 |
*
|
52 |
* @return AffineTransform
|
53 |
*/
|
54 |
public AffineTransform getAT() { |
55 |
return m_MatrizTransf;
|
56 |
} |
57 |
/**
|
58 |
* Add Listener to draw Layout.
|
59 |
* @param ldl LayoutDrawListener.
|
60 |
*/
|
61 |
public void addLayoutDrawListener(LayoutDrawListener ldl) { |
62 |
if (!layoutDrawListeners.contains(ldl))
|
63 |
layoutDrawListeners.add(ldl); |
64 |
} |
65 |
/**
|
66 |
* Call all LayoutDrawListeners.
|
67 |
*
|
68 |
*/
|
69 |
public void callLayoutDrawListeners() { |
70 |
for (int i=0;i<layoutDrawListeners.size();i++) { |
71 |
((LayoutDrawListener)layoutDrawListeners.get(i)).refresh(); |
72 |
} |
73 |
} |
74 |
/**
|
75 |
* It returns the print attributes of the Layout.
|
76 |
*
|
77 |
* @return Attributes.
|
78 |
*/
|
79 |
public Attributes getAtributes() { |
80 |
return m_attributes;
|
81 |
} |
82 |
/**
|
83 |
* Inserts the print attributes of Layout.
|
84 |
* @param attributes Attributes.
|
85 |
*/
|
86 |
public void setAtributes(Attributes attributes) { |
87 |
m_attributes=attributes; |
88 |
} |
89 |
/**
|
90 |
* It obtains the Array with all the FFrames that have been added al Layout.
|
91 |
*
|
92 |
* @return Array with all the FFrames that have been added al Layout.
|
93 |
*/
|
94 |
public IFFrame[] getFFrames() { |
95 |
return fframes;
|
96 |
} |
97 |
/**
|
98 |
* It obtains the FFrame from an index.
|
99 |
**/
|
100 |
public IFFrame getFFrame(int i) { |
101 |
return fframes[i];
|
102 |
} |
103 |
/**
|
104 |
* It orders the FFrames depending on its position specified by level.
|
105 |
*
|
106 |
*/
|
107 |
public void updateFFrames() { |
108 |
ArrayList frames = new ArrayList(); |
109 |
IFFrame[] auxfframes = fcr.getFrameManager().getFFrames();
|
110 |
for (int j = numBehind; j <= numBefore; j++) { |
111 |
for (int i = 0; i < auxfframes.length; i++) { |
112 |
if (auxfframes[i].getLevel() == j) {
|
113 |
frames.add(auxfframes[i]); |
114 |
continue;
|
115 |
} |
116 |
} |
117 |
} |
118 |
fframes = (IFFrame[]) frames.toArray(new IFFrame[0]); |
119 |
} |
120 |
/**
|
121 |
* Remove the fframes selected.
|
122 |
*
|
123 |
*/
|
124 |
public void delFFrameSelected() { |
125 |
fcr.startComplex(); |
126 |
for (int i = fcr.getFrameManager().getAllFFrames().length - 1; i >= 0; i--) { |
127 |
IFFrame fframe = fcr.getFrameManager().getFFrame(i); |
128 |
|
129 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
130 |
fcr.delete(fframe); |
131 |
} |
132 |
} |
133 |
fcr.endComplex(PluginServices.getText(this,"remove_elements")); |
134 |
updateFFrames(); |
135 |
} |
136 |
/**
|
137 |
* Clear the selection of FFrames.
|
138 |
*
|
139 |
*/
|
140 |
public void clearSelection() { |
141 |
for (int i = fcr.getFrameManager().getAllFFrames().length - 1; i >= 0; i--) { |
142 |
IFFrame fframe = fcr.getFrameManager().getFFrame(i); |
143 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
144 |
fframe.setSelected(false);
|
145 |
} |
146 |
} |
147 |
} |
148 |
/**
|
149 |
* Remove the fframe of index.
|
150 |
*
|
151 |
*/
|
152 |
public void delFFrame(int index) { |
153 |
for (int i = 0; i < fcr.getFrameManager().getAllFFrames().length; i++) { |
154 |
IFFrame frame=getFFrame(index); |
155 |
if (fcr.getFrameManager().getFFrame(i).equals(frame)) {
|
156 |
fcr.delete(frame); |
157 |
} |
158 |
} |
159 |
updateFFrames(); |
160 |
} |
161 |
/**
|
162 |
* Remove the fframe of parameter.
|
163 |
* @param frame
|
164 |
* FFrame to remove.
|
165 |
*/
|
166 |
public void delFFrame(IFFrame frame) { |
167 |
for (int i = 0; i < fcr.getFrameManager().getAllFFrames().length; i++) { |
168 |
if (fcr.getFrameManager().getFFrame(i).equals(frame)) {
|
169 |
fcr.delete(frame); |
170 |
} |
171 |
} |
172 |
updateFFrames(); |
173 |
} |
174 |
/**
|
175 |
* Returns the EditableFeatureSource, is the control of all change in the FFrames of Layout.
|
176 |
* @return EditableFatureSource.
|
177 |
*/
|
178 |
public FrameCommandsRecord getEFS() {
|
179 |
return fcr;
|
180 |
} |
181 |
/**
|
182 |
* It adds a fframe to Arraylist of FFrames .
|
183 |
*
|
184 |
* @param frame fframe to add.
|
185 |
* @param clearSelection True
|
186 |
* True if clean the selection of the fframes already added and
|
187 |
* false if intends to maintain the same selection.
|
188 |
* @param select
|
189 |
* Boolean that indicates if has to remain selected the FFrame that is added or not.
|
190 |
*/
|
191 |
public void addFFrame(IFFrame frame, boolean clearSelection, boolean select) { |
192 |
IFFrame[] fframes = getFFrames();
|
193 |
if (clearSelection) {
|
194 |
for (int i = fframes.length - 1; i >= 0; i--) { |
195 |
IFFrame fframe1 = fframes[i]; |
196 |
fframe1.setSelected(false);
|
197 |
} |
198 |
} |
199 |
|
200 |
if (nums.containsKey(frame.getClass())) {
|
201 |
nums.put(frame.getClass(), new Integer(Integer.parseInt(nums.get( |
202 |
frame.getClass()).toString()) + 1));
|
203 |
} else {
|
204 |
nums.put(frame.getClass(), new Integer(0)); |
205 |
} |
206 |
|
207 |
frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
|
208 |
fcr.insert(frame); |
209 |
frame.setSelected(select); |
210 |
frame.setLevel(getNumBefore()); |
211 |
updateFFrames(); |
212 |
} |
213 |
/**
|
214 |
* It adds a fframe to Arraylist of FFrames with the same properties.
|
215 |
*
|
216 |
* @param frame fframe to add.
|
217 |
*/
|
218 |
public void addFFrameSameProperties(IFFrame frame){ |
219 |
fcr.insert(frame); |
220 |
frame.setSelected(true);
|
221 |
frame.setLevel(getNumBefore()); |
222 |
updateFFrames(); |
223 |
} |
224 |
/**
|
225 |
* Returns other number behind the current fframes.
|
226 |
* @return new Position behind.
|
227 |
*/
|
228 |
public int getNumBehind() { |
229 |
return --numBehind;
|
230 |
} |
231 |
/**
|
232 |
* Returns other number before the current fframes.
|
233 |
* @return new Position before.
|
234 |
*/
|
235 |
public int getNumBefore() { |
236 |
return ++numBefore;
|
237 |
} |
238 |
/**
|
239 |
* It returns all the fframes included them erased and modified in all
|
240 |
* its previous forms.
|
241 |
* @return IFFrame[] Array of FFrames.
|
242 |
*/
|
243 |
public IFFrame[] getAllFFrames() { |
244 |
ArrayList all = new ArrayList(); |
245 |
return (IFFrame[]) allFFrames(getFFrames(), all) |
246 |
.toArray(new IFFrame[0]); |
247 |
} |
248 |
private ArrayList allFFrames(IFFrame[] fframes, ArrayList all) { |
249 |
for (int i = 0; i < fframes.length; i++) { |
250 |
if (fframes[i] instanceof FFrameGroup) { |
251 |
ArrayList groupFrames=allFFrames(((FFrameGroup) fframes[i]).getFFrames(), all);
|
252 |
if (!all.containsAll(groupFrames))
|
253 |
all.addAll(groupFrames); |
254 |
|
255 |
}else {
|
256 |
if (!all.contains(fframes[i]))
|
257 |
all.add(fframes[i]); |
258 |
} |
259 |
} |
260 |
return all;
|
261 |
} |
262 |
/**
|
263 |
* It returns an array with the FFrames selected.
|
264 |
*
|
265 |
* @return Array with the FFrames selected.
|
266 |
*/
|
267 |
public IFFrame[] getFFrameSelected() { |
268 |
ArrayList selecList = new ArrayList(); |
269 |
IFFrame[] fframes=getFFrames();
|
270 |
for (int i = fframes.length - 1; i >= 0; i--) { |
271 |
IFFrame fframe = fframes[i]; |
272 |
|
273 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
274 |
selecList.add(fframe); |
275 |
} |
276 |
} |
277 |
|
278 |
return (IFFrame[]) selecList.toArray(new IFFrame[0]); |
279 |
} |
280 |
/**
|
281 |
* It returns if the Layout is in edition.
|
282 |
* @return True if Layout is in edition.
|
283 |
*/
|
284 |
public boolean isEditable() { |
285 |
return isEditable;
|
286 |
} |
287 |
/**
|
288 |
* It inserts if the Layout is in edition.
|
289 |
* @param b
|
290 |
* True if Layout is in edition.
|
291 |
*/
|
292 |
public void setEditable(boolean b) { |
293 |
if (!b) {
|
294 |
clearSelection(); |
295 |
//layoutControl.setTool("layoutzoomin");
|
296 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
297 |
} |
298 |
isEditable = b; |
299 |
|
300 |
} |
301 |
/**
|
302 |
* It returns if has been applying in the fframes that are added to Layout the grid, or not.
|
303 |
*
|
304 |
* @return true if has been applying the grid.
|
305 |
*/
|
306 |
public boolean isAdjustingToGrid() { |
307 |
if (adjustToGrid == null) { |
308 |
adjustToGrid = new Boolean(Layout.getDefaultAdjustToGrid()); |
309 |
} |
310 |
return adjustToGrid.booleanValue();
|
311 |
} |
312 |
/**
|
313 |
* It inserts if has been applying in the fframes that are added to Layout the grid, or not.
|
314 |
*
|
315 |
* @param b
|
316 |
* true if has been applying the grid.
|
317 |
*/
|
318 |
public void setAdjustToGrid(boolean b) { |
319 |
adjustToGrid = new Boolean(b); |
320 |
} |
321 |
/**
|
322 |
* It returns an Object XMLEntity with the information the necessary attributes
|
323 |
* to be able later to create again the original object.
|
324 |
*
|
325 |
* @return XMLEntity.
|
326 |
*
|
327 |
* @throws XMLException
|
328 |
*/
|
329 |
public XMLEntity getXMLEntity() {
|
330 |
XMLEntity xml = new XMLEntity();
|
331 |
xml.putProperty("className", this.getClass().getName()); |
332 |
xml.setName("layout");
|
333 |
xml.putProperty("isCuadricula", isAdjustingToGrid());
|
334 |
// xml.putProperty("m_name", this.getName());
|
335 |
xml.putProperty("isEditable", isEditable());
|
336 |
xml.putProperty("numBehind", numBehind);
|
337 |
xml.putProperty("numBefore", numBefore);
|
338 |
xml.addChild(getAtributes().getXMLEntity()); |
339 |
IFFrame[] fframes=getFFrames();
|
340 |
for (int i = 0; i < fframes.length; i++) { |
341 |
try {
|
342 |
XMLEntity xmlAux = fframes[i].getXMLEntity(); |
343 |
xml.addChild(xmlAux); |
344 |
} catch (SaveException e) {
|
345 |
e.showError(); |
346 |
} |
347 |
} |
348 |
return xml;
|
349 |
} |
350 |
/**
|
351 |
* It inserts if is shown or not the rule of the Layout.
|
352 |
*
|
353 |
* @param b
|
354 |
* True if is shown or not the rule of the Layout.
|
355 |
*/
|
356 |
public void setRuler(boolean b) { |
357 |
m_showRuler = new Boolean(b); |
358 |
} |
359 |
|
360 |
/**
|
361 |
* Returns if is shown or not the rule of the Layout.
|
362 |
*
|
363 |
* @return True si se muestra la regla.
|
364 |
*/
|
365 |
public boolean getRuler() { |
366 |
if (m_showRuler == null) { |
367 |
m_showRuler = new Boolean(Layout.getDefaultShowRulers()); |
368 |
} |
369 |
return m_showRuler.booleanValue();
|
370 |
} |
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
/**
|
377 |
* It returns if has been showing the grid of Layout, or not.
|
378 |
*
|
379 |
* @return true if has been showing the grid of Layout.
|
380 |
*/
|
381 |
public boolean isGridVisible() { |
382 |
if (isGridVisible== null) { |
383 |
isGridVisible = new Boolean(Layout.getDefaultShowGrid()); |
384 |
} |
385 |
return isGridVisible.booleanValue();
|
386 |
} |
387 |
/**
|
388 |
* It inserts if draws the Grid in the Layout or not.
|
389 |
*
|
390 |
* @param b
|
391 |
* True if draws the Grid in the Layout.
|
392 |
*/
|
393 |
public void setGridVisible(boolean b) { |
394 |
isGridVisible = new Boolean(b); |
395 |
} |
396 |
/**
|
397 |
* The dialogs are created here each time that are needed.
|
398 |
*
|
399 |
* @param fframe
|
400 |
* Rectangle that represents the place that occupied the element added.
|
401 |
*
|
402 |
* @return IFFrame Returns the FFrame added or null if the fframe has not been added.
|
403 |
*/
|
404 |
public IFFrame openFFrameDialog(IFFrame frame) {
|
405 |
IFFrameDialog fframedialog = frame.getPropertyDialog(); |
406 |
if (fframedialog != null) { |
407 |
fframedialog.setRectangle(frame.getBoundingBox(getAT())); |
408 |
PluginServices.getMDIManager().addWindow(fframedialog); |
409 |
} |
410 |
return fframedialog.getFFrame();
|
411 |
} |
412 |
/**
|
413 |
* Refresh all FFrames of Layout.
|
414 |
*/
|
415 |
public void fullRefresh() { |
416 |
IFFrame[] fframes = getFFrames();
|
417 |
for (int i = 0; i < fframes.length; i++) { |
418 |
if (fframes[i] instanceof IFFrameUseFMap) { |
419 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
420 |
fframe.refresh(); |
421 |
} |
422 |
} |
423 |
callLayoutDrawListeners(); |
424 |
} |
425 |
|
426 |
} |