root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / LayoutContext.java @ 9392
History | View | Annotate | Download (9.08 KB)
1 |
package com.iver.cit.gvsig.project.documents.layout; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Hashtable; |
5 |
|
6 |
import com.iver.andami.PluginServices; |
7 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
8 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
9 |
import com.iver.cit.gvsig.project.documents.layout.commands.DefaultEditableFeatureSource; |
10 |
import com.iver.cit.gvsig.project.documents.layout.commands.EditableFeatureSource; |
11 |
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGroup; |
12 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
13 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
14 |
import com.iver.utiles.XMLEntity; |
15 |
|
16 |
/**
|
17 |
* Modelo del Layout.
|
18 |
*
|
19 |
* @author Vicente Caballero Navarro
|
20 |
*/
|
21 |
public class LayoutContext { |
22 |
private Attributes m_attributes = null; |
23 |
private IFFrame[] fframes; |
24 |
private DefaultEditableFeatureSource efs;
|
25 |
public static Hashtable nums = new Hashtable(); |
26 |
public int numBefore = 0; |
27 |
public int numBehind = 0; |
28 |
private boolean isEditable = true; |
29 |
private Boolean adjustToGrid = null; |
30 |
private Boolean m_showRuler; |
31 |
private Boolean isGridVisible = null; |
32 |
|
33 |
|
34 |
public LayoutContext() {
|
35 |
m_attributes=new Attributes(); |
36 |
efs = new DefaultEditableFeatureSource();
|
37 |
} |
38 |
|
39 |
/**
|
40 |
* Devuelve los atributos del Mapa.
|
41 |
*
|
42 |
* @return Attributes.
|
43 |
*/
|
44 |
public Attributes getAtributes() { |
45 |
return m_attributes;
|
46 |
} |
47 |
|
48 |
public void setAtributes(Attributes attributes) { |
49 |
m_attributes=attributes; |
50 |
} |
51 |
/**
|
52 |
* Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
|
53 |
*
|
54 |
* @return Array con todos los fframes que contiene el Layout.
|
55 |
*/
|
56 |
public IFFrame[] getFFrames() { |
57 |
return fframes;
|
58 |
} |
59 |
|
60 |
public IFFrame getFFrame(int i) { |
61 |
return fframes[i];
|
62 |
} |
63 |
|
64 |
public void updateFFrames() { |
65 |
ArrayList frames = new ArrayList(); |
66 |
IFFrame[] auxfframes = efs.getFFrames();
|
67 |
for (int j = numBehind; j <= numBefore; j++) { |
68 |
for (int i = 0; i < auxfframes.length; i++) { |
69 |
if (auxfframes[i].getLevel() == j) {
|
70 |
frames.add(auxfframes[i]); |
71 |
continue;
|
72 |
} |
73 |
} |
74 |
} |
75 |
fframes = (IFFrame[]) frames.toArray(new IFFrame[0]); |
76 |
} |
77 |
public void delFFrameSelected() { |
78 |
efs.startComplexCommand(); |
79 |
for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) { |
80 |
IFFrame fframe = efs.getFFrame(i); |
81 |
|
82 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
83 |
efs.removeFFrame(i); |
84 |
} |
85 |
} |
86 |
efs.endComplexCommand(PluginServices.getText(this,"remove_elements")); |
87 |
updateFFrames(); |
88 |
} |
89 |
|
90 |
public void clearSelection() { |
91 |
for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) { |
92 |
IFFrame fframe = efs.getFFrame(i); |
93 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
94 |
fframe.setSelected(false);
|
95 |
} |
96 |
} |
97 |
} |
98 |
public void delFFrame(int index) { |
99 |
for (int i = 0; i < getEFS().getAllFFrames().length; i++) { |
100 |
if (getEFS().getFFrame(i).equals(getFFrame(index))) {
|
101 |
getEFS().removeFFrame(i); |
102 |
} |
103 |
} |
104 |
updateFFrames(); |
105 |
} |
106 |
|
107 |
public void delFFrame(IFFrame frame) { |
108 |
for (int i = 0; i < getEFS().getAllFFrames().length; i++) { |
109 |
if (getEFS().getFFrame(i).equals(frame)) {
|
110 |
getEFS().removeFFrame(i); |
111 |
} |
112 |
} |
113 |
updateFFrames(); |
114 |
} |
115 |
public EditableFeatureSource getEFS() {
|
116 |
return efs;
|
117 |
} |
118 |
/**
|
119 |
* A?ade un fframe al Arraylist m_fframes.
|
120 |
*
|
121 |
* @param frame
|
122 |
* fframe a a?adir.
|
123 |
* @param clearSelection
|
124 |
* para que se quede seleccionado ?nicamente el que a?adimos y
|
125 |
* false si lo que se pretende es que no se deseleccionen lo que
|
126 |
* ya est?n seleccionados.
|
127 |
* @param select
|
128 |
* Booleano que indica si se tiene que quedar seleccionado el
|
129 |
* FFrame que se a?ade o no.
|
130 |
*/
|
131 |
public void addFFrame(IFFrame frame, boolean clearSelection, boolean select) { |
132 |
IFFrame[] fframes = getFFrames();
|
133 |
if (clearSelection) {
|
134 |
for (int i = fframes.length - 1; i >= 0; i--) { |
135 |
IFFrame fframe1 = fframes[i]; |
136 |
fframe1.setSelected(false);
|
137 |
} |
138 |
} |
139 |
|
140 |
if (nums.containsKey(frame.getClass())) {
|
141 |
nums.put(frame.getClass(), new Integer(Integer.parseInt(nums.get( |
142 |
frame.getClass()).toString()) + 1));
|
143 |
} else {
|
144 |
nums.put(frame.getClass(), new Integer(0)); |
145 |
} |
146 |
|
147 |
frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
|
148 |
efs.addFFrame(frame); |
149 |
frame.setSelected(select); |
150 |
frame.setLevel(getNumBefore()); |
151 |
updateFFrames(); |
152 |
} |
153 |
|
154 |
public int getNumBehind() { |
155 |
return --numBehind;
|
156 |
} |
157 |
|
158 |
public int getNumBefore() { |
159 |
return ++numBefore;
|
160 |
} |
161 |
public IFFrame[] getAllFFrames() { |
162 |
ArrayList all = new ArrayList(); |
163 |
return (IFFrame[]) allFFrames(getFFrames(), all) |
164 |
.toArray(new IFFrame[0]); |
165 |
} |
166 |
private ArrayList allFFrames(IFFrame[] fframes, ArrayList all) { |
167 |
for (int i = 0; i < fframes.length; i++) { |
168 |
if (fframes[i] instanceof FFrameGroup) { |
169 |
return allFFrames(((FFrameGroup) fframes[i]).getFFrames(), all);
|
170 |
|
171 |
} |
172 |
all.add(fframes[i]); |
173 |
} |
174 |
return all;
|
175 |
} |
176 |
/**
|
177 |
* Devuelve un array con los FFrames seleccionados.
|
178 |
*
|
179 |
* @return Array con los FFrames seleccionados.
|
180 |
*/
|
181 |
public IFFrame[] getFFrameSelected() { |
182 |
ArrayList selecList = new ArrayList(); |
183 |
IFFrame[] fframes=getFFrames();
|
184 |
for (int i = fframes.length - 1; i >= 0; i--) { |
185 |
IFFrame fframe = fframes[i]; |
186 |
|
187 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
188 |
selecList.add(fframe); |
189 |
} |
190 |
} |
191 |
|
192 |
return (IFFrame[]) selecList.toArray(new IFFrame[0]); |
193 |
} |
194 |
public boolean isEditable() { |
195 |
return isEditable;
|
196 |
} |
197 |
|
198 |
public void setEditable(boolean b) { |
199 |
if (!b) {
|
200 |
clearSelection(); |
201 |
//layoutControl.setTool("layoutzoomin");
|
202 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
203 |
} |
204 |
isEditable = b; |
205 |
|
206 |
} |
207 |
/**
|
208 |
* Devuelve si se esta aplicando en los fframes que se a?den al Layout la
|
209 |
* cuadr?cula, o no.
|
210 |
*
|
211 |
* @return true si se esta aplicando la cuadr?cula.
|
212 |
*/
|
213 |
public boolean isAdjustingToGrid() { |
214 |
if (adjustToGrid == null) { |
215 |
adjustToGrid = new Boolean(Layout.getDefaultAdjustToGrid()); |
216 |
} |
217 |
return adjustToGrid.booleanValue();
|
218 |
} |
219 |
/**
|
220 |
* Se actualiza el estado de la cuadr?cula, si se aplica o no.
|
221 |
*
|
222 |
* @param b
|
223 |
* true si se aplica la cuadr?cula.
|
224 |
*/
|
225 |
public void setAdjustToGrid(boolean b) { |
226 |
adjustToGrid = new Boolean(b); |
227 |
} |
228 |
/**
|
229 |
* Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
|
230 |
* para poder despu?s volver a crear el objeto original.
|
231 |
*
|
232 |
* @return XMLEntity.
|
233 |
*
|
234 |
* @throws XMLException
|
235 |
*/
|
236 |
public XMLEntity getXMLEntity() {
|
237 |
XMLEntity xml = new XMLEntity();
|
238 |
xml.putProperty("className", this.getClass().getName()); |
239 |
xml.setName("layout");
|
240 |
xml.putProperty("isCuadricula", isAdjustingToGrid());
|
241 |
// xml.putProperty("m_name", this.getName());
|
242 |
xml.putProperty("isEditable", isEditable());
|
243 |
xml.putProperty("numBehind", numBehind);
|
244 |
xml.putProperty("numBefore", numBefore);
|
245 |
xml.addChild(getAtributes().getXMLEntity()); |
246 |
IFFrame[] fframes=getFFrames();
|
247 |
for (int i = 0; i < fframes.length; i++) { |
248 |
try {
|
249 |
XMLEntity xmlAux = fframes[i].getXMLEntity(); |
250 |
xml.addChild(xmlAux); |
251 |
} catch (SaveException e) {
|
252 |
e.showError(); |
253 |
} |
254 |
} |
255 |
return xml;
|
256 |
} |
257 |
/**
|
258 |
* Inserta si se muestra o no la regla del Layout.
|
259 |
*
|
260 |
* @param b
|
261 |
* True si se muestra la regla.
|
262 |
*/
|
263 |
public void setRuler(boolean b) { |
264 |
m_showRuler = new Boolean(b); |
265 |
} |
266 |
|
267 |
/**
|
268 |
* Devuelve si se muestra la regla del Layout.
|
269 |
*
|
270 |
* @return True si se muestra la regla.
|
271 |
*/
|
272 |
public boolean getRuler() { |
273 |
if (m_showRuler == null) { |
274 |
m_showRuler = new Boolean(Layout.getDefaultShowRulers()); |
275 |
} |
276 |
return m_showRuler.booleanValue();
|
277 |
} |
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
/**
|
284 |
* Devuelve si se esta aplicando en los fframes que se a?den al Layout la
|
285 |
* cuadr?cula, o no.
|
286 |
*
|
287 |
* @return true si se esta aplicando la cuadr?cula.
|
288 |
*/
|
289 |
public boolean isGridVisible() { |
290 |
if (isGridVisible== null) { |
291 |
isGridVisible = new Boolean(Layout.getDefaultShowGrid()); |
292 |
} |
293 |
return isGridVisible.booleanValue();
|
294 |
} |
295 |
/**
|
296 |
* Inserta si se muestra el Grid del Layout.
|
297 |
*
|
298 |
* @param b
|
299 |
* True si se muestra el Grid del Layout.
|
300 |
*/
|
301 |
public void setGridVisible(boolean b) { |
302 |
isGridVisible = new Boolean(b); |
303 |
} |
304 |
} |