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 / FLayoutGraphics.java @ 1714
History | View | Annotate | Download (12.9 KB)
1 | 5 | jldominguez | /* 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; |
||
23 | |||
24 | import java.awt.geom.Rectangle2D; |
||
25 | import java.util.ArrayList; |
||
26 | import org.gvsig.andami.PluginServices; |
||
27 | import org.gvsig.app.project.ProjectManager; |
||
28 | import org.gvsig.app.project.documents.layout.fframes.FFrameGroup; |
||
29 | import org.gvsig.app.project.documents.layout.fframes.FFrameLegend; |
||
30 | import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
||
31 | import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
||
32 | 250 | cmartinez | import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameDialogNotification; |
33 | 5 | jldominguez | import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
34 | import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
||
35 | import org.gvsig.app.project.documents.layout.gui.dialogs.FAlignDialog; |
||
36 | import org.gvsig.app.project.documents.layout.gui.dialogs.FBorderDialog; |
||
37 | import org.gvsig.app.project.documents.layout.gui.dialogs.FPositionDialog; |
||
38 | 250 | cmartinez | import org.gvsig.tools.observer.Observable; |
39 | import org.gvsig.tools.observer.Observer; |
||
40 | 1714 | fdiaz | import org.slf4j.Logger; |
41 | import org.slf4j.LoggerFactory; |
||
42 | 5 | jldominguez | |
43 | /**
|
||
44 | * Operaciones realizadas sobre el conjunto de FFrames.
|
||
45 | *
|
||
46 | * @author Vicente Caballero Navarro
|
||
47 | */
|
||
48 | public class FLayoutGraphics { |
||
49 | |||
50 | protected static final Logger LOG = LoggerFactory |
||
51 | .getLogger(FLayoutGraphics.class); |
||
52 | 1714 | fdiaz | private final LayoutPanel layout; |
53 | 5 | jldominguez | private FAlignDialog m_alignLayout = null; |
54 | private FBorderDialog borderdialog = null; |
||
55 | private FPositionDialog positiondialog = null; |
||
56 | private LayoutManager layoutManager = null; |
||
57 | |||
58 | /**
|
||
59 | * Crea un nuevo FLayoutGraphics.
|
||
60 | *
|
||
61 | * @param l
|
||
62 | * Referencia al Layout.
|
||
63 | */
|
||
64 | public FLayoutGraphics(LayoutPanel layoutPanel) {
|
||
65 | layout = layoutPanel; |
||
66 | layoutManager = |
||
67 | (LayoutManager) ProjectManager.getInstance().getDocumentManager(
|
||
68 | DefaultLayoutManager.TYPENAME); |
||
69 | } |
||
70 | |||
71 | /**
|
||
72 | * Transforma un FFrameLegend a FFrames de tipo FFrameSymbol y FFrameText.
|
||
73 | */
|
||
74 | public void simplify() { |
||
75 | layout.getLayoutContext().getFrameCommandsRecord() |
||
76 | .startComplex(PluginServices.getText(this, "simplify")); |
||
77 | IFFrame[] fframes = layout.getLayoutContext().getFFrames();
|
||
78 | for (int i = fframes.length - 1; i >= 0; i--) { |
||
79 | IFFrame fframe = fframes[i]; |
||
80 | |||
81 | if (fframe instanceof FFrameLegend) { |
||
82 | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
||
83 | ((FFrameLegend) fframe) |
||
84 | .toFFrames(layout.getLayoutContext()); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | layout.getLayoutContext().getFrameCommandsRecord().endComplex(); |
||
89 | layout.getLayoutControl().refresh(); |
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * Agrupar en un FFrameGroup todos los FFrames seleccionados.
|
||
94 | */
|
||
95 | public void grouping() { |
||
96 | // Se debe controlar de alguna forma si hay varios seleccionados.
|
||
97 | FFrameGroup fframegroup = |
||
98 | (FFrameGroup) layoutManager |
||
99 | .createFrame(FFrameGroup.PERSISTENCE_DEFINITION_NAME); |
||
100 | |||
101 | // fframegroup.setLayout(layout);
|
||
102 | IFFrame[] fframes = layout.getLayoutContext().getFFrames();
|
||
103 | if (fframes.length > 1) { |
||
104 | ArrayList selecList = new ArrayList(); |
||
105 | |||
106 | for (int i = fframes.length - 1; i >= 0; i--) { |
||
107 | IFFrame fframe = fframes[i]; |
||
108 | |||
109 | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
||
110 | selecList.add(fframe); |
||
111 | layout.getLayoutContext().delFFrame(fframe); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | for (int i = selecList.size() - 1; i >= 0; i--) { |
||
116 | fframegroup.addFFrame((IFFrame) selecList.get(i)); |
||
117 | } |
||
118 | |||
119 | fframegroup.setAt(layout.getLayoutControl().getAT()); |
||
120 | |||
121 | Rectangle2D.Double rd =
|
||
122 | fframegroup.getRectangle(layout.getLayoutControl().getAT()); |
||
123 | |||
124 | Rectangle2D.Double rd1 =
|
||
125 | FLayoutUtilities.toSheetRect(rd, layout.getLayoutControl() |
||
126 | .getAT()); |
||
127 | |||
128 | fframegroup.setBoundBox(rd1); |
||
129 | fframegroup.setSelected(true);
|
||
130 | layout.getLayoutContext().addFFrame(fframegroup, true, true); |
||
131 | layout.getLayoutControl().refresh(); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /**
|
||
136 | * Desagrupar los FFrames que estan contenidos dentro del FFrameGroup en
|
||
137 | * FFrames individuales.
|
||
138 | */
|
||
139 | public void ungrouping() { |
||
140 | layout.getLayoutContext().getFrameCommandsRecord() |
||
141 | .startComplex(PluginServices.getText(this, "ungroup")); |
||
142 | IFFrame[] fframes = layout.getLayoutContext().getFFrames();
|
||
143 | for (int i = fframes.length - 1; i >= 0; i--) { |
||
144 | IFFrame fframe = fframes[i]; |
||
145 | |||
146 | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
||
147 | if (fframe instanceof FFrameGroup) { |
||
148 | FFrameGroup fframegroup = (FFrameGroup) fframe; |
||
149 | ArrayList selecList = new ArrayList(); |
||
150 | |||
151 | for (int j = fframegroup.getFFrames().length - 1; j >= 0; j--) { |
||
152 | selecList.add(fframegroup.getFFrames()[j]); |
||
153 | } |
||
154 | |||
155 | for (int j = selecList.size() - 1; j >= 0; j--) { |
||
156 | IFFrame frame = (IFFrame) selecList.get(j); |
||
157 | frame.setRotation(frame.getRotation() |
||
158 | + fframe.getRotation()); |
||
159 | layout.getLayoutContext() |
||
160 | .addFFrameSameProperties(frame); |
||
161 | } |
||
162 | layout.getLayoutContext().delFFrame(fframegroup); |
||
163 | } |
||
164 | } |
||
165 | } |
||
166 | layout.getLayoutContext().getFrameCommandsRecord().endComplex(); |
||
167 | layout.getLayoutControl().refresh(); |
||
168 | } |
||
169 | |||
170 | /**
|
||
171 | * Abre el di?logo para alinear los FFrames.
|
||
172 | */
|
||
173 | public void aligning() { |
||
174 | m_alignLayout = new FAlignDialog(layout);
|
||
175 | 1714 | fdiaz | // WindowManager winManager = ToolsSwingLocator.getWindowManager();
|
176 | 1700 | fdiaz | // winManager.showWindow(m_alignLayout, "Alinear", WindowManager.MODE.TOOL);
|
177 | 5 | jldominguez | PluginServices.getMDIManager().addWindow(m_alignLayout); |
178 | } |
||
179 | |||
180 | /**
|
||
181 | * Posiciona los FFrames seleccionados delante de los no seleccionados.
|
||
182 | */
|
||
183 | public void before() { |
||
184 | layout.getLayoutContext().getFrameCommandsRecord() |
||
185 | .startComplex(PluginServices.getText(this, "change_before")); |
||
186 | IFFrame[] fframes = layout.getLayoutContext().getFFrames();
|
||
187 | for (int i = fframes.length - 1; i >= 0; i--) { |
||
188 | IFFrame fframe = fframes[i]; |
||
189 | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
||
190 | if (fframe instanceof FFrameGroup) { |
||
191 | ((FFrameGroup) fframe).setAt(layout.getLayoutControl() |
||
192 | .getAT()); |
||
193 | } |
||
194 | |||
195 | IFFrame fframeAux; |
||
196 | try {
|
||
197 | fframeAux = (IFFrame) fframe.clone(); |
||
198 | fframeAux |
||
199 | .setLevel(layout.getLayoutContext().getNumBefore()); |
||
200 | layout.getLayoutContext().getFrameCommandsRecord() |
||
201 | .update(fframe, fframeAux); |
||
202 | fframeAux.getBoundingBox(layout.getLayoutControl().getAT()); |
||
203 | } catch (CloneNotSupportedException e) { |
||
204 | LOG.error("It is not possible clonate the object", e);
|
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | layout.getLayoutContext().getFrameCommandsRecord().endComplex(); |
||
209 | layout.getLayoutContext().updateFFrames(); |
||
210 | layout.getLayoutControl().refresh(); |
||
211 | } |
||
212 | |||
213 | /**
|
||
214 | * Posiciona los FFrames seleccionados detr?s de los FFrames no
|
||
215 | * seleccionados.
|
||
216 | */
|
||
217 | public void behind() { |
||
218 | layout.getLayoutContext().getFrameCommandsRecord() |
||
219 | .startComplex(PluginServices.getText(this, "change_behind")); |
||
220 | IFFrame[] fframes = layout.getLayoutContext().getFFrames();
|
||
221 | for (int i = fframes.length - 1; i >= 0; i--) { |
||
222 | IFFrame fframe = fframes[i]; |
||
223 | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
||
224 | if (fframe instanceof FFrameGroup) { |
||
225 | ((FFrameGroup) fframe).setAt(layout.getLayoutControl() |
||
226 | .getAT()); |
||
227 | } |
||
228 | |||
229 | IFFrame fframeAux; |
||
230 | try {
|
||
231 | fframeAux = (IFFrame) fframe.clone(); |
||
232 | fframeAux |
||
233 | .setLevel(layout.getLayoutContext().getNumBehind()); |
||
234 | layout.getLayoutContext().getFrameCommandsRecord() |
||
235 | .update(fframe, fframeAux); |
||
236 | fframeAux.getBoundingBox(layout.getLayoutControl().getAT()); |
||
237 | } catch (CloneNotSupportedException e) { |
||
238 | LOG.error("It is not possible clonate the object", e);
|
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | layout.getLayoutContext().getFrameCommandsRecord().endComplex(); |
||
243 | layout.getLayoutContext().updateFFrames(); |
||
244 | layout.getLayoutControl().refresh(); |
||
245 | } |
||
246 | |||
247 | /**
|
||
248 | * Abre el di?logo adecuadao a las propiedades del FFrame seleccionado,
|
||
249 | * ahora mismo solo se abre cuando hay un solo FFrame seleccionado.
|
||
250 | */
|
||
251 | 250 | cmartinez | public void openFrameDialog(final Observer observer) { |
252 | 140 | cmartinez | IFFrame[] selecList = layout.getLayoutContext().getSelectedFFrames();
|
253 | 5 | jldominguez | |
254 | if (selecList.length == 1) { |
||
255 | 250 | cmartinez | final IFFrame frame = selecList[0]; |
256 | 1714 | fdiaz | final IFFrameDialog fframeDialog = (IFFrameDialog) layout.createFFrameDialog(frame);
|
257 | 5 | jldominguez | if (fframeDialog != null) { |
258 | 1714 | fdiaz | Observer onPanelClosedObserver = (Observable observable, Object notification) -> { |
259 | if (notification instanceof FFrameDialogNotification && |
||
260 | ((FFrameDialogNotification)notification).getType()==FFrameDialogNotification.DIALOG_CLOSED) { |
||
261 | onDialogClosed(fframeDialog, frame, observer); |
||
262 | } |
||
263 | }; |
||
264 | 250 | cmartinez | fframeDialog.addObserver(onPanelClosedObserver); |
265 | if (observer!=null) { |
||
266 | fframeDialog.addObserver(observer); |
||
267 | } |
||
268 | 5 | jldominguez | PluginServices.getMDIManager().addWindow(fframeDialog); |
269 | } |
||
270 | } |
||
271 | } |
||
272 | 250 | cmartinez | |
273 | public void openFrameDialog() { |
||
274 | openFrameDialog(null);
|
||
275 | } |
||
276 | |||
277 | /**
|
||
278 | * @Deprecated Use {@link #openFrameDialog()}
|
||
279 | * and {@link #openFrameDialog(Observer)}
|
||
280 | * @return
|
||
281 | */
|
||
282 | @Deprecated
|
||
283 | public boolean openFFrameDialog() { |
||
284 | openFrameDialog(null);
|
||
285 | return true; |
||
286 | } |
||
287 | |||
288 | protected void onDialogClosed(IFFrameDialog dialog, IFFrame oldFrame, Observer observer) { |
||
289 | IFFrame fframeAux = dialog.getFFrame(); |
||
290 | if (fframeAux != null) { |
||
291 | // if user has pressed cancel, then fframeAux is null
|
||
292 | if (fframeAux instanceof IFFrameUseFMap) |
||
293 | ((IFFrameUseFMap) fframeAux).refresh(); |
||
294 | layout.getLayoutContext().getFrameCommandsRecord() |
||
295 | .update(oldFrame, fframeAux); |
||
296 | fframeAux.getBoundingBox(layout.getLayoutControl().getAT()); |
||
297 | layout.getLayoutContext().updateFFrames(); |
||
298 | layout.getLayoutControl().setIsReSel(true);
|
||
299 | layout.getLayoutControl().refresh(); |
||
300 | if (observer!=null) { |
||
301 | observer.update(dialog, new FFrameDialogNotification(FFrameDialogNotification.FRAME_CREATED));
|
||
302 | } |
||
303 | } |
||
304 | } |
||
305 | 5 | jldominguez | |
306 | 250 | cmartinez | |
307 | 5 | jldominguez | /**
|
308 | * Selecci?n de todos los FFrames del Layout.
|
||
309 | */
|
||
310 | public void selecAll() { |
||
311 | IFFrame[] fframes = layout.getLayoutContext().getFFrames();
|
||
312 | for (int i = fframes.length - 1; i >= 0; i--) { |
||
313 | IFFrame fframe = fframes[i]; |
||
314 | fframe.setSelected(true);
|
||
315 | } |
||
316 | layout.getLayoutControl().refresh(); |
||
317 | } |
||
318 | |||
319 | /**
|
||
320 | * Abre el di?logo para a?adir un borde a los fframes.
|
||
321 | */
|
||
322 | public boolean border() { |
||
323 | borderdialog = new FBorderDialog(layout);
|
||
324 | PluginServices.getMDIManager().addWindow(borderdialog); |
||
325 | return borderdialog.isAccepted();
|
||
326 | } |
||
327 | |||
328 | /**
|
||
329 | * Abre el di?logo de cambio de posici?n y tama?o del FFrame.
|
||
330 | */
|
||
331 | public void position() { |
||
332 | |||
333 | 140 | cmartinez | IFFrame[] fframes = layout.getLayoutContext().getSelectedFFrames();
|
334 | 5 | jldominguez | if (fframes.length != 0) { |
335 | 1714 | fdiaz | for (IFFrame fframe : fframes) {
|
336 | positiondialog = new FPositionDialog(layout, fframe);
|
||
337 | 5 | jldominguez | PluginServices.getMDIManager().addWindow(positiondialog); |
338 | } |
||
339 | } |
||
340 | } |
||
341 | } |