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