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