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 / gui / dialogs / EventsFAlign.java @ 1700
History | View | Annotate | Download (49.1 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.gui.dialogs; |
23 |
|
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.event.ActionListener; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.util.Arrays; |
28 |
import java.util.Comparator; |
29 |
import java.util.List; |
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.app.ApplicationLocator; |
32 |
import org.gvsig.app.project.documents.layout.LayoutDocument; |
33 |
import org.gvsig.app.project.documents.layout.commands.FrameCommandsRecord; |
34 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
35 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
36 |
import static org.gvsig.app.project.documents.layout.gui.dialogs.FAlignDialog.RELATIVE_TO_GREATER_OBJECT; |
37 |
import static org.gvsig.app.project.documents.layout.gui.dialogs.FAlignDialog.RELATIVE_TO_MINOR_OBJECT; |
38 |
import static org.gvsig.app.project.documents.layout.gui.dialogs.FAlignDialog.RELATIVE_TO_SELECTION; |
39 |
import static org.gvsig.app.project.documents.layout.gui.dialogs.FAlignDialog.RELATIVE_TO_THE_PAGE; |
40 |
import org.gvsig.fmap.geom.Geometry; |
41 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
42 |
import org.gvsig.fmap.geom.GeometryLocator; |
43 |
import org.gvsig.fmap.geom.GeometryManager; |
44 |
import org.gvsig.fmap.geom.primitive.Envelope; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
/**
|
49 |
* Clase que hace de Listener de FAlignDialog.
|
50 |
*
|
51 |
* @author gvSIG Team
|
52 |
*/
|
53 |
public class EventsFAlign implements ActionListener { |
54 |
|
55 |
protected static final Logger LOG = LoggerFactory |
56 |
.getLogger(EventsFAlign.class); |
57 |
private LayoutPanel m_layout;
|
58 |
private boolean inLayout = false; |
59 |
private int alignRelativeTo; |
60 |
|
61 |
/**
|
62 |
* Crea un nuevo FAlign.
|
63 |
*
|
64 |
*/
|
65 |
public EventsFAlign() {
|
66 |
} |
67 |
|
68 |
LayoutPanel getLayout() { |
69 |
LayoutDocument layoutDocument = (LayoutDocument) ApplicationLocator.getManager().getActiveDocument(LayoutDocument.class); |
70 |
if(layoutDocument == null){ |
71 |
return null; |
72 |
} |
73 |
m_layout = (LayoutPanel) layoutDocument.getMainWindow(); |
74 |
return m_layout;
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* Desplaza los fframes seleccionados a la izquierda del fframe m?s
|
79 |
* occidental.
|
80 |
*
|
81 |
* @throws CloneNotSupportedException
|
82 |
*/
|
83 |
private void alignLeft() throws CloneNotSupportedException { |
84 |
LayoutPanel theLayout = getLayout(); |
85 |
if(theLayout == null){ |
86 |
return;
|
87 |
} |
88 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
89 |
if(fframes.length == 0){ |
90 |
return;
|
91 |
} |
92 |
|
93 |
double xmin = Double.POSITIVE_INFINITY; |
94 |
double w;
|
95 |
switch (alignRelativeTo) {
|
96 |
case RELATIVE_TO_THE_PAGE:
|
97 |
xmin = 0;
|
98 |
break;
|
99 |
case RELATIVE_TO_SELECTION:
|
100 |
for (int i = 0; i < fframes.length; i++) { |
101 |
IFFrame fframe = fframes[i]; |
102 |
|
103 |
if (xmin > fframe.getBoundBox().getMinX()) {
|
104 |
xmin = fframe.getBoundBox().getMinX(); |
105 |
} |
106 |
} |
107 |
break;
|
108 |
case RELATIVE_TO_GREATER_OBJECT:
|
109 |
w = Double.NEGATIVE_INFINITY;
|
110 |
for (int i = 0; i < fframes.length; i++) { |
111 |
IFFrame fframe = fframes[i]; |
112 |
if (w < fframe.getBoundBox().getWidth()) {
|
113 |
w = fframe.getBoundBox().getWidth(); |
114 |
xmin = fframe.getBoundBox().getMinX(); |
115 |
} |
116 |
} |
117 |
break;
|
118 |
case RELATIVE_TO_MINOR_OBJECT:
|
119 |
w = Double.POSITIVE_INFINITY;
|
120 |
for (int i = 0; i < fframes.length; i++) { |
121 |
IFFrame fframe = fframes[i]; |
122 |
if (w > fframe.getBoundBox().getWidth()) {
|
123 |
w = fframe.getBoundBox().getWidth(); |
124 |
xmin = fframe.getBoundBox().getMinX(); |
125 |
} |
126 |
} |
127 |
break;
|
128 |
default:
|
129 |
return;
|
130 |
} |
131 |
|
132 |
FrameCommandsRecord efs = |
133 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
134 |
efs.startComplex(PluginServices.getText(this, "align_left")); |
135 |
|
136 |
for (int i = fframes.length - 1; i >= 0; i--) { |
137 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
138 |
|
139 |
Rectangle2D.Double r =
|
140 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
141 |
r.x = xmin; |
142 |
fframe.setBoundBox(r); |
143 |
efs.update(fframes[i], fframe); |
144 |
} |
145 |
|
146 |
efs.endComplex(); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* Desplaza los fframes seleccionados al centro del fframe mas ancho de
|
151 |
* forma horizontal o al centro del layout.
|
152 |
*
|
153 |
* @throws CloneNotSupportedException
|
154 |
*/
|
155 |
private void alignCenterH() throws Exception { |
156 |
LayoutPanel theLayout = getLayout(); |
157 |
if(theLayout == null){ |
158 |
return;
|
159 |
} |
160 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
161 |
if(fframes.length == 0){ |
162 |
return;
|
163 |
} |
164 |
|
165 |
double xcenter = 0; |
166 |
double w;
|
167 |
switch (alignRelativeTo) {
|
168 |
case RELATIVE_TO_THE_PAGE:
|
169 |
xcenter = theLayout.getLayoutContext().getAttributes().getPaperSize().getWidth() / 2;
|
170 |
break;
|
171 |
case RELATIVE_TO_SELECTION:
|
172 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
173 |
Envelope env = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
174 |
for (int i = 0; i < fframes.length; i++) { |
175 |
IFFrame fframe = fframes[i]; |
176 |
Rectangle2D.Double bbox = fframe.getBoundBox();
|
177 |
env.add(geomManager.createEnvelope( |
178 |
bbox.getMinX(), |
179 |
bbox.getMinY(), |
180 |
bbox.getMaxX(), |
181 |
bbox.getMaxY(), |
182 |
SUBTYPES.GEOM2D) |
183 |
); |
184 |
} |
185 |
if (env.isEmpty()) {
|
186 |
return;
|
187 |
} |
188 |
xcenter = env.getCenter(Geometry.DIMENSIONS.X); |
189 |
break;
|
190 |
case RELATIVE_TO_GREATER_OBJECT:
|
191 |
w = Double.NEGATIVE_INFINITY;
|
192 |
for (int i = 0; i < fframes.length; i++) { |
193 |
IFFrame fframe = fframes[i]; |
194 |
if (w < fframe.getBoundBox().getWidth()) {
|
195 |
w = fframe.getBoundBox().getWidth(); |
196 |
xcenter = fframe.getBoundBox().getCenterX(); |
197 |
} |
198 |
} |
199 |
break;
|
200 |
case RELATIVE_TO_MINOR_OBJECT:
|
201 |
w = Double.POSITIVE_INFINITY;
|
202 |
for (int i = 0; i < fframes.length; i++) { |
203 |
IFFrame fframe = fframes[i]; |
204 |
if (w > fframe.getBoundBox().getWidth()) {
|
205 |
w = fframe.getBoundBox().getWidth(); |
206 |
xcenter = fframe.getBoundBox().getCenterX(); |
207 |
} |
208 |
} |
209 |
break;
|
210 |
default:
|
211 |
return;
|
212 |
} |
213 |
|
214 |
FrameCommandsRecord efs = |
215 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
216 |
efs.startComplex(PluginServices.getText(this, "align_center")); |
217 |
|
218 |
for (int i = 0; i < fframes.length; i++) { |
219 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
220 |
|
221 |
Rectangle2D.Double r =
|
222 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
223 |
r.x = xcenter - (fframe.getBoundBox().width / 2);
|
224 |
fframe.setBoundBox(r); |
225 |
efs.update(fframes[i], fframe); |
226 |
} |
227 |
|
228 |
efs.endComplex(); |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Desplaza los fframes seleccionados a la parte derecha del fframe m?s
|
233 |
* oriental.
|
234 |
*
|
235 |
* @throws CloneNotSupportedException
|
236 |
*/
|
237 |
private void alignRight() throws CloneNotSupportedException { |
238 |
LayoutPanel theLayout = getLayout(); |
239 |
if(theLayout == null){ |
240 |
return;
|
241 |
} |
242 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
243 |
if(fframes.length == 0){ |
244 |
return;
|
245 |
} |
246 |
|
247 |
double xmax = Double.NEGATIVE_INFINITY; |
248 |
double w;
|
249 |
switch (alignRelativeTo) {
|
250 |
case RELATIVE_TO_THE_PAGE:
|
251 |
xmax = theLayout.getLayoutContext().getAttributes().getPaperSize().getWidth(); |
252 |
break;
|
253 |
case RELATIVE_TO_SELECTION:
|
254 |
for (int i = 0; i < fframes.length; i++) { |
255 |
IFFrame fframe = fframes[i]; |
256 |
|
257 |
if (xmax < fframe.getBoundBox().getMaxX()) {
|
258 |
xmax = fframe.getBoundBox().getMaxX(); |
259 |
} |
260 |
} |
261 |
break;
|
262 |
case RELATIVE_TO_GREATER_OBJECT:
|
263 |
w = Double.NEGATIVE_INFINITY;
|
264 |
for (int i = 0; i < fframes.length; i++) { |
265 |
IFFrame fframe = fframes[i]; |
266 |
if (w < fframe.getBoundBox().getWidth()) {
|
267 |
w = fframe.getBoundBox().getWidth(); |
268 |
xmax = fframe.getBoundBox().getMaxX(); |
269 |
} |
270 |
} |
271 |
break;
|
272 |
case RELATIVE_TO_MINOR_OBJECT:
|
273 |
w = Double.POSITIVE_INFINITY;
|
274 |
for (int i = 0; i < fframes.length; i++) { |
275 |
IFFrame fframe = fframes[i]; |
276 |
if (w > fframe.getBoundBox().getWidth()) {
|
277 |
w = fframe.getBoundBox().getWidth(); |
278 |
xmax = fframe.getBoundBox().getMaxX(); |
279 |
} |
280 |
} |
281 |
break;
|
282 |
default:
|
283 |
return;
|
284 |
} |
285 |
|
286 |
FrameCommandsRecord efs = |
287 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
288 |
efs.startComplex(PluginServices.getText(this, "align_right")); |
289 |
|
290 |
for (int i = 0; i < fframes.length; i++) { |
291 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
292 |
|
293 |
Rectangle2D.Double r =
|
294 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
295 |
r.x = xmax - fframes[i].getBoundBox().width; |
296 |
fframe.setBoundBox(r); |
297 |
efs.update(fframes[i], fframe); |
298 |
} |
299 |
|
300 |
efs.endComplex(); |
301 |
} |
302 |
|
303 |
/**
|
304 |
* Alinea por debajo los fframes seleccionados.
|
305 |
*
|
306 |
* @throws CloneNotSupportedException
|
307 |
*/
|
308 |
private void alignDown() throws CloneNotSupportedException { |
309 |
LayoutPanel theLayout = getLayout(); |
310 |
if(theLayout == null){ |
311 |
return;
|
312 |
} |
313 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
314 |
if(fframes.length == 0){ |
315 |
return;
|
316 |
} |
317 |
|
318 |
double ymax = Double.NEGATIVE_INFINITY; |
319 |
double h;
|
320 |
switch (alignRelativeTo) {
|
321 |
case RELATIVE_TO_THE_PAGE:
|
322 |
ymax = theLayout.getLayoutContext().getAttributes().getPaperSize().getHeight(); |
323 |
break;
|
324 |
case RELATIVE_TO_SELECTION:
|
325 |
for (int i = 0; i < fframes.length; i++) { |
326 |
IFFrame fframe = fframes[i]; |
327 |
|
328 |
if (ymax < fframe.getBoundBox().getMaxY()) {
|
329 |
ymax = fframe.getBoundBox().getMaxY(); |
330 |
} |
331 |
} |
332 |
break;
|
333 |
case RELATIVE_TO_GREATER_OBJECT:
|
334 |
h = Double.NEGATIVE_INFINITY;
|
335 |
for (int i = 0; i < fframes.length; i++) { |
336 |
IFFrame fframe = fframes[i]; |
337 |
if (h < fframe.getBoundBox().getHeight()) {
|
338 |
h = fframe.getBoundBox().getHeight(); |
339 |
ymax = fframe.getBoundBox().getMaxY(); |
340 |
} |
341 |
} |
342 |
break;
|
343 |
case RELATIVE_TO_MINOR_OBJECT:
|
344 |
h = Double.POSITIVE_INFINITY;
|
345 |
for (int i = 0; i < fframes.length; i++) { |
346 |
IFFrame fframe = fframes[i]; |
347 |
if (h > fframe.getBoundBox().getHeight()) {
|
348 |
h = fframe.getBoundBox().getHeight(); |
349 |
ymax = fframe.getBoundBox().getMaxY(); |
350 |
} |
351 |
} |
352 |
break;
|
353 |
default:
|
354 |
return;
|
355 |
} |
356 |
|
357 |
FrameCommandsRecord efs = |
358 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
359 |
efs.startComplex(PluginServices.getText(this, "align_down")); |
360 |
|
361 |
for (int i = 0; i < fframes.length; i++) { |
362 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
363 |
|
364 |
Rectangle2D.Double r =
|
365 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
366 |
r.y = ymax - fframe.getBoundBox().height; |
367 |
fframe.setBoundBox(r); |
368 |
efs.update(fframes[i], fframe); |
369 |
} |
370 |
|
371 |
efs.endComplex(); |
372 |
} |
373 |
|
374 |
/**
|
375 |
* Desplaza los fframes seleccionados a la parte superior del fframe que
|
376 |
* m?s arriba este colocado.
|
377 |
*
|
378 |
* @throws CloneNotSupportedException
|
379 |
*/
|
380 |
private void alignUp() throws CloneNotSupportedException { |
381 |
LayoutPanel theLayout = getLayout(); |
382 |
if(theLayout == null){ |
383 |
return;
|
384 |
} |
385 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
386 |
if(fframes.length == 0){ |
387 |
return;
|
388 |
} |
389 |
|
390 |
double ymin = Double.MAX_VALUE; |
391 |
double h;
|
392 |
switch (alignRelativeTo) {
|
393 |
case RELATIVE_TO_THE_PAGE:
|
394 |
ymin = 0;
|
395 |
break;
|
396 |
case RELATIVE_TO_SELECTION:
|
397 |
for (int i = 0; i < fframes.length; i++) { |
398 |
IFFrame fframe = fframes[i]; |
399 |
|
400 |
if (ymin > fframe.getBoundBox().getMinY()) {
|
401 |
ymin = fframe.getBoundBox().getMinY(); |
402 |
} |
403 |
} |
404 |
break;
|
405 |
case RELATIVE_TO_GREATER_OBJECT:
|
406 |
h = Double.NEGATIVE_INFINITY;
|
407 |
for (int i = 0; i < fframes.length; i++) { |
408 |
IFFrame fframe = fframes[i]; |
409 |
if (h < fframe.getBoundBox().getHeight()) {
|
410 |
h = fframe.getBoundBox().getHeight(); |
411 |
ymin = fframe.getBoundBox().getMinY(); |
412 |
} |
413 |
} |
414 |
break;
|
415 |
case RELATIVE_TO_MINOR_OBJECT:
|
416 |
h = Double.POSITIVE_INFINITY;
|
417 |
for (int i = 0; i < fframes.length; i++) { |
418 |
IFFrame fframe = fframes[i]; |
419 |
if (h > fframe.getBoundBox().getHeight()) {
|
420 |
h = fframe.getBoundBox().getHeight(); |
421 |
ymin = fframe.getBoundBox().getMinY(); |
422 |
} |
423 |
} |
424 |
break;
|
425 |
default:
|
426 |
return;
|
427 |
} |
428 |
|
429 |
FrameCommandsRecord efs = |
430 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
431 |
efs.startComplex(PluginServices.getText(this, "align_up")); |
432 |
|
433 |
for (int i = 0; i < fframes.length; i++) { |
434 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
435 |
Rectangle2D.Double r =
|
436 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
437 |
r.y = ymin; |
438 |
fframe.setBoundBox(r); |
439 |
efs.update(fframes[i], fframe); |
440 |
} |
441 |
|
442 |
efs.endComplex(); |
443 |
} |
444 |
|
445 |
/**
|
446 |
* Desplaza los fframes seleccionados al centro del fframe m?s alto
|
447 |
* verticalmente o al centro del layout.
|
448 |
*
|
449 |
* @throws CloneNotSupportedException
|
450 |
*/
|
451 |
private void alignCenterV() throws Exception { |
452 |
LayoutPanel theLayout = getLayout(); |
453 |
if(theLayout == null){ |
454 |
return;
|
455 |
} |
456 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
457 |
if(fframes.length == 0){ |
458 |
return;
|
459 |
} |
460 |
|
461 |
double ycenter = 0; |
462 |
double h = Double.NEGATIVE_INFINITY; |
463 |
|
464 |
switch (alignRelativeTo) {
|
465 |
case RELATIVE_TO_THE_PAGE:
|
466 |
ycenter = theLayout.getLayoutContext().getAttributes().getPaperSize().getHeight() / 2;
|
467 |
break;
|
468 |
case RELATIVE_TO_SELECTION:
|
469 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
470 |
Envelope env = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
471 |
for (int i = 0; i < fframes.length; i++) { |
472 |
IFFrame fframe = fframes[i]; |
473 |
Rectangle2D.Double bbox = fframe.getBoundBox();
|
474 |
env.add(geomManager.createEnvelope( |
475 |
bbox.getMinX(), |
476 |
bbox.getMinY(), |
477 |
bbox.getMaxX(), |
478 |
bbox.getMaxY(), |
479 |
SUBTYPES.GEOM2D) |
480 |
); |
481 |
} |
482 |
if(env.isEmpty()){
|
483 |
return;
|
484 |
} |
485 |
ycenter = env.getCenter(Geometry.DIMENSIONS.Y); |
486 |
break;
|
487 |
case RELATIVE_TO_GREATER_OBJECT:
|
488 |
h = Double.NEGATIVE_INFINITY;
|
489 |
for (int i = 0; i < fframes.length; i++) { |
490 |
IFFrame fframe = fframes[i]; |
491 |
if (h < fframe.getBoundBox().getHeight()) {
|
492 |
h = fframe.getBoundBox().getHeight(); |
493 |
ycenter = fframe.getBoundBox().getCenterY(); |
494 |
} |
495 |
} |
496 |
break;
|
497 |
case RELATIVE_TO_MINOR_OBJECT:
|
498 |
h = Double.POSITIVE_INFINITY;
|
499 |
for (int i = 0; i < fframes.length; i++) { |
500 |
IFFrame fframe = fframes[i]; |
501 |
if (h > fframe.getBoundBox().getHeight()) {
|
502 |
h = fframe.getBoundBox().getHeight(); |
503 |
ycenter = fframe.getBoundBox().getCenterY(); |
504 |
} |
505 |
} |
506 |
break;
|
507 |
default:
|
508 |
return;
|
509 |
} |
510 |
|
511 |
FrameCommandsRecord efs = |
512 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
513 |
efs.startComplex(PluginServices.getText(this, "align_vertical_center")); |
514 |
|
515 |
for (int i = 0; i < fframes.length; i++) { |
516 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
517 |
Rectangle2D.Double r =
|
518 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
519 |
r.y = ycenter - (fframe.getBoundBox().height / 2);
|
520 |
fframe.setBoundBox(r); |
521 |
efs.update(fframes[i], fframe); |
522 |
} |
523 |
|
524 |
efs.endComplex(); |
525 |
} |
526 |
|
527 |
/**
|
528 |
* Distribuye los fframes seleccionados horizontalmente con espaciado uniforme
|
529 |
* entre los bordes izquierdos.
|
530 |
*
|
531 |
* @throws CloneNotSupportedException
|
532 |
*/
|
533 |
private void distLeft() throws CloneNotSupportedException { |
534 |
LayoutPanel theLayout = getLayout(); |
535 |
if(theLayout == null){ |
536 |
return;
|
537 |
} |
538 |
int num = 0; |
539 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
540 |
num = fframes.length; |
541 |
if(num <=1){ |
542 |
return;
|
543 |
} |
544 |
|
545 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
546 |
fframesList.sort(new Comparator<IFFrame>() { |
547 |
@Override
|
548 |
public int compare(IFFrame o1, IFFrame o2) { |
549 |
double res = Double.compare(o1.getBoundBox().getMinX(),o2.getBoundBox().getMinX()); |
550 |
|
551 |
if(res == 0){ |
552 |
res = Double.compare(o1.getBoundBox().getMaxX(),o2.getBoundBox().getMaxX());
|
553 |
} |
554 |
return (int) Math.round(res); |
555 |
} |
556 |
} ); |
557 |
|
558 |
double xmin;
|
559 |
double xmax;
|
560 |
switch (alignRelativeTo) {
|
561 |
case RELATIVE_TO_THE_PAGE:
|
562 |
xmin = 0;
|
563 |
double layoutWidth = theLayout.getLayoutContext().getAttributes().getPaperSize().getWidth();
|
564 |
double lastFrameWidth = (fframesList.get(fframesList.size() - 1)).getBoundBox().getWidth(); |
565 |
xmax = layoutWidth - lastFrameWidth; |
566 |
break;
|
567 |
case RELATIVE_TO_SELECTION:
|
568 |
xmin = Double.POSITIVE_INFINITY;
|
569 |
xmax = Double.NEGATIVE_INFINITY;
|
570 |
for (IFFrame fframe : fframesList) {
|
571 |
if (xmin > fframe.getBoundBox().getMinX()) {
|
572 |
xmin = fframe.getBoundBox().getMinX(); |
573 |
} |
574 |
if (xmax < fframe.getBoundBox().getMinX()) {
|
575 |
xmax = fframe.getBoundBox().getMinX(); |
576 |
} |
577 |
} |
578 |
break;
|
579 |
default:
|
580 |
return;
|
581 |
} |
582 |
|
583 |
double dif = xmax - xmin;
|
584 |
double dist = dif / (num-1); |
585 |
FrameCommandsRecord efs = |
586 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
587 |
efs.startComplex(PluginServices.getText(this, "distributes_left")); |
588 |
|
589 |
int i = 0; |
590 |
for (IFFrame fframe : fframesList) {
|
591 |
IFFrame fframeCloned = (IFFrame) fframe.clone(); |
592 |
Rectangle2D.Double r =
|
593 |
(Rectangle2D.Double) fframeCloned.getBoundBox().clone();
|
594 |
r.x = xmin + (dist * i++); |
595 |
fframeCloned.setBoundBox(r); |
596 |
efs.update(fframe, fframeCloned); |
597 |
} |
598 |
|
599 |
efs.endComplex(); |
600 |
} |
601 |
|
602 |
/**
|
603 |
* Distribuye los fframes seleccionados horizontalmente con espaciado uniforme
|
604 |
* entre los bordes izquierdos.
|
605 |
*/
|
606 |
private void distRight() throws CloneNotSupportedException { |
607 |
LayoutPanel theLayout = getLayout(); |
608 |
if(theLayout == null){ |
609 |
return;
|
610 |
} |
611 |
int num = 0; |
612 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
613 |
num = fframes.length; |
614 |
if(num <=1){ |
615 |
return;
|
616 |
} |
617 |
|
618 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
619 |
fframesList.sort(new Comparator<IFFrame>() { |
620 |
@Override
|
621 |
public int compare(IFFrame o1, IFFrame o2) { |
622 |
double res = Double.compare(o2.getBoundBox().getMaxX(),o1.getBoundBox().getMaxX()); |
623 |
|
624 |
if(res == 0){ |
625 |
res = Double.compare(o2.getBoundBox().getMinX(),o1.getBoundBox().getMinX());
|
626 |
} |
627 |
return (int) Math.round(res); |
628 |
} |
629 |
} ); |
630 |
|
631 |
double xmin;
|
632 |
double xmax;
|
633 |
|
634 |
switch (alignRelativeTo) {
|
635 |
case RELATIVE_TO_THE_PAGE:
|
636 |
double layoutWidth = theLayout.getLayoutContext().getAttributes().getPaperSize().getWidth();
|
637 |
double leftFrameWidth = (fframesList.get(fframesList.size() - 1)).getBoundBox().getWidth(); |
638 |
xmax = layoutWidth; |
639 |
xmin = leftFrameWidth; |
640 |
break;
|
641 |
case RELATIVE_TO_SELECTION:
|
642 |
xmin = Double.POSITIVE_INFINITY;
|
643 |
xmax = Double.NEGATIVE_INFINITY;
|
644 |
|
645 |
for (IFFrame fframe : fframesList) {
|
646 |
if (xmin > fframe.getBoundBox().getMaxX()) {
|
647 |
xmin = fframe.getBoundBox().getMaxX(); |
648 |
} |
649 |
if (xmax < fframe.getBoundBox().getMaxX()) {
|
650 |
xmax = fframe.getBoundBox().getMaxX(); |
651 |
} |
652 |
} |
653 |
break;
|
654 |
default:
|
655 |
return;
|
656 |
} |
657 |
|
658 |
|
659 |
double dif = xmax - xmin;
|
660 |
double dist = dif / (num-1); |
661 |
FrameCommandsRecord efs = |
662 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
663 |
efs.startComplex(PluginServices.getText(this, "distributes_right")); |
664 |
|
665 |
int i=0; |
666 |
for (IFFrame fframe : fframesList) {
|
667 |
IFFrame fframecloned = (IFFrame) fframe.clone(); |
668 |
Rectangle2D.Double r =
|
669 |
(Rectangle2D.Double) fframecloned.getBoundBox().clone();
|
670 |
r.x = xmax - (dist * i++) - fframecloned.getBoundBox().width; |
671 |
fframecloned.setBoundBox(r); |
672 |
efs.update(fframe, fframecloned); |
673 |
} |
674 |
|
675 |
efs.endComplex(); |
676 |
} |
677 |
|
678 |
/**
|
679 |
* Distribuye los fframes seleccionados verticalmente con espaciado uniforme
|
680 |
* entre los bordes superiores.
|
681 |
*
|
682 |
* @throws CloneNotSupportedException
|
683 |
*/
|
684 |
private void distUp() throws CloneNotSupportedException { |
685 |
LayoutPanel theLayout = getLayout(); |
686 |
if(theLayout == null){ |
687 |
return;
|
688 |
} |
689 |
int num = 0; |
690 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
691 |
num = fframes.length; |
692 |
if(num <=1){ |
693 |
return;
|
694 |
} |
695 |
|
696 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
697 |
fframesList.sort(new Comparator<IFFrame>() { |
698 |
@Override
|
699 |
public int compare(IFFrame o1, IFFrame o2) { |
700 |
double res = Double.compare(o1.getBoundBox().getMinY(),o2.getBoundBox().getMinY()); |
701 |
|
702 |
if(res == 0){ |
703 |
res = Double.compare(o1.getBoundBox().getMaxY(),o2.getBoundBox().getMaxY());
|
704 |
} |
705 |
return (int) Math.round(res); |
706 |
} |
707 |
} ); |
708 |
|
709 |
double ymin;
|
710 |
double ymax;
|
711 |
|
712 |
switch (alignRelativeTo) {
|
713 |
case RELATIVE_TO_THE_PAGE:
|
714 |
ymin = 0;
|
715 |
double layoutHeight = theLayout.getLayoutContext().getAttributes().getPaperSize().getHeight();
|
716 |
double lastFrameHeight = (fframesList.get(fframesList.size() - 1)).getBoundBox().getHeight(); |
717 |
ymax = layoutHeight - lastFrameHeight; |
718 |
break;
|
719 |
case RELATIVE_TO_SELECTION:
|
720 |
ymin = Double.POSITIVE_INFINITY;
|
721 |
ymax = Double.NEGATIVE_INFINITY;
|
722 |
|
723 |
for (IFFrame fframe : fframesList) {
|
724 |
if (ymin > fframe.getBoundBox().getMinY()) {
|
725 |
ymin = fframe.getBoundBox().getMinY(); |
726 |
} |
727 |
if (ymax < fframe.getBoundBox().getMinY()) {
|
728 |
ymax = fframe.getBoundBox().getMinY(); |
729 |
} |
730 |
} |
731 |
break;
|
732 |
default:
|
733 |
return;
|
734 |
} |
735 |
|
736 |
double dif = ymax - ymin;
|
737 |
double dist = dif / (num - 1); |
738 |
FrameCommandsRecord efs = |
739 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
740 |
efs.startComplex(PluginServices.getText(this, "distributes_up")); |
741 |
|
742 |
int i = 0; |
743 |
for (IFFrame fframe : fframesList) {
|
744 |
IFFrame fframeCloned = (IFFrame) fframe.clone(); |
745 |
Rectangle2D.Double r =
|
746 |
(Rectangle2D.Double) fframeCloned.getBoundBox().clone();
|
747 |
r.y = ymin + (dist * i++); |
748 |
fframeCloned.setBoundBox(r); |
749 |
efs.update(fframe, fframeCloned); |
750 |
} |
751 |
|
752 |
efs.endComplex(); |
753 |
} |
754 |
|
755 |
/**
|
756 |
* Distribuye los fframes seleccionados verticalmente con espaciado uniforme
|
757 |
* entre los bordes inferiores.
|
758 |
*
|
759 |
* @throws CloneNotSupportedException
|
760 |
*/
|
761 |
private void distDown() throws CloneNotSupportedException { |
762 |
LayoutPanel theLayout = getLayout(); |
763 |
if(theLayout == null){ |
764 |
return;
|
765 |
} |
766 |
int num = 0; |
767 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
768 |
num = fframes.length; |
769 |
if(num <=1){ |
770 |
return;
|
771 |
} |
772 |
|
773 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
774 |
fframesList.sort(new Comparator<IFFrame>() { |
775 |
@Override
|
776 |
public int compare(IFFrame o1, IFFrame o2) { |
777 |
double res = Double.compare(o2.getBoundBox().getMaxY(),o1.getBoundBox().getMaxY()); |
778 |
|
779 |
if(res == 0){ |
780 |
res = Double.compare(o2.getBoundBox().getMinY(),o1.getBoundBox().getMinY());
|
781 |
} |
782 |
return (int) Math.round(res); |
783 |
} |
784 |
} ); |
785 |
|
786 |
double ymin;
|
787 |
double ymax;
|
788 |
switch (alignRelativeTo) {
|
789 |
case RELATIVE_TO_THE_PAGE:
|
790 |
double layoutHeight = theLayout.getLayoutContext().getAttributes().getPaperSize().getHeight();
|
791 |
double leftFrameHeight = (fframesList.get(fframesList.size() - 1)).getBoundBox().getHeight(); |
792 |
ymax = layoutHeight; |
793 |
ymin = leftFrameHeight; |
794 |
break;
|
795 |
case RELATIVE_TO_SELECTION:
|
796 |
ymin = Double.POSITIVE_INFINITY;
|
797 |
ymax = Double.NEGATIVE_INFINITY;
|
798 |
|
799 |
for (IFFrame fframe : fframesList) {
|
800 |
|
801 |
if (ymin > fframe.getBoundBox().getMaxY()) {
|
802 |
ymin = fframe.getBoundBox().getMaxY(); |
803 |
} |
804 |
|
805 |
if (ymax < fframe.getBoundBox().getMaxY()) {
|
806 |
ymax = fframe.getBoundBox().getMaxY(); |
807 |
} |
808 |
} |
809 |
break;
|
810 |
default:
|
811 |
return;
|
812 |
} |
813 |
|
814 |
double dif = ymax - ymin;
|
815 |
double dist = dif / (num-1); |
816 |
FrameCommandsRecord efs = |
817 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
818 |
efs.startComplex(PluginServices.getText(this, "distributes_down")); |
819 |
|
820 |
int i=0; |
821 |
for (IFFrame fframe : fframesList) {
|
822 |
IFFrame fframecloned = (IFFrame) fframe.clone(); |
823 |
Rectangle2D.Double r =
|
824 |
(Rectangle2D.Double) fframecloned.getBoundBox().clone();
|
825 |
r.y = ymax - (dist * i++) - fframecloned.getBoundBox().height; |
826 |
fframecloned.setBoundBox(r); |
827 |
efs.update(fframe, fframecloned); |
828 |
} |
829 |
|
830 |
efs.endComplex(); |
831 |
} |
832 |
|
833 |
/**
|
834 |
* Distribuye los fframes seleccionados horizontalmente con espaciado uniforme
|
835 |
* entre los centros.
|
836 |
*
|
837 |
* @throws CloneNotSupportedException
|
838 |
*/
|
839 |
private void distCenterV() throws CloneNotSupportedException { |
840 |
LayoutPanel theLayout = getLayout(); |
841 |
if(theLayout == null){ |
842 |
return;
|
843 |
} |
844 |
int num = 0; |
845 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
846 |
num = fframes.length; |
847 |
if(num <=1){ |
848 |
return;
|
849 |
} |
850 |
|
851 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
852 |
fframesList.sort(new Comparator<IFFrame>() { |
853 |
@Override
|
854 |
public int compare(IFFrame o1, IFFrame o2) { |
855 |
double res = Double.compare(o1.getBoundBox().getCenterX(),o2.getBoundBox().getCenterX()); |
856 |
|
857 |
if(res == 0){ |
858 |
res = Double.compare(o1.getBoundBox().getMinX(),o2.getBoundBox().getMinX());
|
859 |
} |
860 |
return (int) Math.round(res); |
861 |
} |
862 |
} ); |
863 |
|
864 |
double xmin;
|
865 |
double xmax;
|
866 |
|
867 |
switch (alignRelativeTo) {
|
868 |
case RELATIVE_TO_THE_PAGE:
|
869 |
xmin = (fframesList.get(0).getBoundBox().getWidth()) / 2; |
870 |
double layoutWidth = theLayout.getLayoutContext().getAttributes().getPaperSize().getWidth();
|
871 |
double lastFrameWidth = (fframesList.get(fframesList.size() - 1)).getBoundBox().getWidth(); |
872 |
xmax = layoutWidth - lastFrameWidth / 2;
|
873 |
break;
|
874 |
case RELATIVE_TO_SELECTION:
|
875 |
xmin = Double.POSITIVE_INFINITY;
|
876 |
xmax = Double.NEGATIVE_INFINITY;
|
877 |
for (IFFrame fframe : fframesList) {
|
878 |
if (xmin > fframe.getBoundBox().getCenterX()) {
|
879 |
xmin = fframe.getBoundBox().getCenterX(); |
880 |
} |
881 |
|
882 |
if (xmax < fframe.getBoundBox().getCenterX()) {
|
883 |
xmax = fframe.getBoundBox().getCenterX(); |
884 |
} |
885 |
} |
886 |
break;
|
887 |
default:
|
888 |
return;
|
889 |
} |
890 |
|
891 |
double dif = xmax - xmin;
|
892 |
double dist = dif / (num-1); |
893 |
FrameCommandsRecord efs = |
894 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
895 |
efs.startComplex(PluginServices.getText(this, "distributes_vertical")); |
896 |
|
897 |
int i = 0; |
898 |
|
899 |
for (IFFrame fframe : fframesList) {
|
900 |
IFFrame fframeCloned = (IFFrame) fframe.clone(); |
901 |
Rectangle2D.Double r =
|
902 |
(Rectangle2D.Double) fframeCloned.getBoundBox().clone();
|
903 |
r.x = xmin + (dist * i++) - r.width/2;
|
904 |
fframeCloned.setBoundBox(r); |
905 |
efs.update(fframe, fframeCloned); |
906 |
} |
907 |
|
908 |
|
909 |
efs.endComplex(); |
910 |
} |
911 |
|
912 |
/**
|
913 |
* Distribuye los fframes seleccionados horizontalmente
|
914 |
* con espaciado uniforme entre los centros
|
915 |
*
|
916 |
* @throws CloneNotSupportedException
|
917 |
*/
|
918 |
private void distCenterH() throws CloneNotSupportedException { |
919 |
LayoutPanel theLayout = getLayout(); |
920 |
if(theLayout == null){ |
921 |
return;
|
922 |
} |
923 |
int num = 0; |
924 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
925 |
num = fframes.length; |
926 |
if(num <=1){ |
927 |
return;
|
928 |
} |
929 |
|
930 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
931 |
fframesList.sort(new Comparator<IFFrame>() { |
932 |
@Override
|
933 |
public int compare(IFFrame o1, IFFrame o2) { |
934 |
double res = Double.compare(o1.getBoundBox().getCenterY(),o2.getBoundBox().getCenterY()); |
935 |
|
936 |
if(res == 0){ |
937 |
res = Double.compare(o1.getBoundBox().getMinY(),o2.getBoundBox().getMinY());
|
938 |
} |
939 |
return (int) Math.round(res); |
940 |
} |
941 |
}); |
942 |
|
943 |
double ymin;
|
944 |
double ymax;
|
945 |
|
946 |
switch (alignRelativeTo) {
|
947 |
case RELATIVE_TO_THE_PAGE:
|
948 |
ymin = (fframesList.get(0).getBoundBox().getHeight()) / 2; |
949 |
double layoutHeigth = theLayout.getLayoutContext().getAttributes().getPaperSize().getHeight();
|
950 |
double lastFrameHeight = (fframesList.get(fframesList.size() - 1)).getBoundBox().getHeight(); |
951 |
ymax = layoutHeigth - lastFrameHeight / 2;
|
952 |
break;
|
953 |
case RELATIVE_TO_SELECTION:
|
954 |
ymin = Double.POSITIVE_INFINITY;
|
955 |
ymax = Double.NEGATIVE_INFINITY;
|
956 |
for (IFFrame fframe : fframesList) {
|
957 |
if (ymin > fframe.getBoundBox().getCenterY()) {
|
958 |
ymin = fframe.getBoundBox().getCenterY(); |
959 |
} |
960 |
|
961 |
if (ymax < fframe.getBoundBox().getCenterY()) {
|
962 |
ymax = fframe.getBoundBox().getCenterY(); |
963 |
} |
964 |
} |
965 |
break;
|
966 |
default:
|
967 |
return;
|
968 |
} |
969 |
|
970 |
double dif = ymax - ymin;
|
971 |
double dist = dif / (num-1); |
972 |
FrameCommandsRecord efs = |
973 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
974 |
efs.startComplex(PluginServices.getText(this, "distributes_vertical")); |
975 |
|
976 |
int i = 0; |
977 |
|
978 |
for (IFFrame fframe : fframesList) {
|
979 |
IFFrame fframeCloned = (IFFrame) fframe.clone(); |
980 |
Rectangle2D.Double r =
|
981 |
(Rectangle2D.Double) fframeCloned.getBoundBox().clone();
|
982 |
r.y = ymin + (dist * i++) - r.height/2;
|
983 |
fframeCloned.setBoundBox(r); |
984 |
efs.update(fframe, fframeCloned); |
985 |
} |
986 |
|
987 |
|
988 |
efs.endComplex(); |
989 |
} |
990 |
|
991 |
/**
|
992 |
* Cambia la anchura de los fframes seleccionados por la anchura del m?s
|
993 |
* ancho.
|
994 |
*
|
995 |
* @throws CloneNotSupportedException
|
996 |
*/
|
997 |
private void sizeWidth() throws Exception { |
998 |
LayoutPanel theLayout = getLayout(); |
999 |
if(theLayout == null){ |
1000 |
return;
|
1001 |
} |
1002 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
1003 |
if(fframes.length == 0){ |
1004 |
return;
|
1005 |
} |
1006 |
double wmax;
|
1007 |
switch (alignRelativeTo) {
|
1008 |
case RELATIVE_TO_THE_PAGE:
|
1009 |
wmax = theLayout.getLayoutContext().getAttributes().getPaperSize().getWidth(); |
1010 |
break;
|
1011 |
case RELATIVE_TO_SELECTION:
|
1012 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
1013 |
Envelope env = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
1014 |
for (int i = 0; i < fframes.length; i++) { |
1015 |
IFFrame fframe = fframes[i]; |
1016 |
Rectangle2D.Double bbox = fframe.getBoundBox();
|
1017 |
env.add(geomManager.createEnvelope( |
1018 |
bbox.getMinX(), |
1019 |
bbox.getMinY(), |
1020 |
bbox.getMaxX(), |
1021 |
bbox.getMaxY(), |
1022 |
SUBTYPES.GEOM2D) |
1023 |
); |
1024 |
} |
1025 |
if (env.isEmpty()) {
|
1026 |
return;
|
1027 |
} |
1028 |
wmax = env.getLength(Geometry.DIMENSIONS.X); |
1029 |
break;
|
1030 |
case RELATIVE_TO_GREATER_OBJECT:
|
1031 |
wmax = Double.NEGATIVE_INFINITY;
|
1032 |
|
1033 |
for (int i = 0; i < fframes.length; i++) { |
1034 |
IFFrame fframe = fframes[i]; |
1035 |
|
1036 |
if (wmax < fframe.getBoundBox().getWidth()) {
|
1037 |
wmax = fframe.getBoundBox().getWidth(); |
1038 |
} |
1039 |
} |
1040 |
break;
|
1041 |
case RELATIVE_TO_MINOR_OBJECT:
|
1042 |
wmax = Double.POSITIVE_INFINITY;
|
1043 |
|
1044 |
for (int i = 0; i < fframes.length; i++) { |
1045 |
IFFrame fframe = fframes[i]; |
1046 |
|
1047 |
if (wmax > fframe.getBoundBox().getWidth()) {
|
1048 |
wmax = fframe.getBoundBox().getWidth(); |
1049 |
} |
1050 |
} |
1051 |
break;
|
1052 |
default:
|
1053 |
return;
|
1054 |
} |
1055 |
|
1056 |
FrameCommandsRecord efs = |
1057 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
1058 |
efs.startComplex(PluginServices.getText(this, "change_width")); |
1059 |
|
1060 |
for (int i = 0; i < fframes.length; i++) { |
1061 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
1062 |
Rectangle2D.Double r =
|
1063 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
1064 |
r.width = wmax; |
1065 |
fframe.setBoundBox(r); |
1066 |
efs.update(fframes[i], fframe); |
1067 |
} |
1068 |
|
1069 |
efs.endComplex(); |
1070 |
} |
1071 |
|
1072 |
/**
|
1073 |
* Cambia la altura de los fframes seleccionados por la altura del mas
|
1074 |
* alto.
|
1075 |
*
|
1076 |
* @throws CloneNotSupportedException
|
1077 |
*/
|
1078 |
private void sizeHeight() throws Exception { |
1079 |
LayoutPanel theLayout = getLayout(); |
1080 |
if(theLayout == null){ |
1081 |
return;
|
1082 |
} |
1083 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
1084 |
if(fframes.length == 0){ |
1085 |
return;
|
1086 |
} |
1087 |
|
1088 |
double hmax;
|
1089 |
switch (alignRelativeTo) {
|
1090 |
case RELATIVE_TO_THE_PAGE:
|
1091 |
hmax = theLayout.getLayoutContext().getAttributes().getPaperSize().getHeight(); |
1092 |
break;
|
1093 |
case RELATIVE_TO_SELECTION:
|
1094 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
1095 |
Envelope env = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
1096 |
for (int i = 0; i < fframes.length; i++) { |
1097 |
IFFrame fframe = fframes[i]; |
1098 |
Rectangle2D.Double bbox = fframe.getBoundBox();
|
1099 |
env.add(geomManager.createEnvelope( |
1100 |
bbox.getMinX(), |
1101 |
bbox.getMinY(), |
1102 |
bbox.getMaxX(), |
1103 |
bbox.getMaxY(), |
1104 |
SUBTYPES.GEOM2D) |
1105 |
); |
1106 |
} |
1107 |
if (env.isEmpty()) {
|
1108 |
return;
|
1109 |
} |
1110 |
hmax = env.getLength(Geometry.DIMENSIONS.Y); |
1111 |
break;
|
1112 |
case RELATIVE_TO_GREATER_OBJECT:
|
1113 |
hmax = Double.NEGATIVE_INFINITY;
|
1114 |
|
1115 |
for (int i = 0; i < fframes.length; i++) { |
1116 |
IFFrame fframe = fframes[i]; |
1117 |
|
1118 |
if (hmax < fframe.getBoundBox().getHeight()) {
|
1119 |
hmax = fframe.getBoundBox().getHeight(); |
1120 |
} |
1121 |
} |
1122 |
break;
|
1123 |
case RELATIVE_TO_MINOR_OBJECT:
|
1124 |
hmax = Double.POSITIVE_INFINITY;
|
1125 |
|
1126 |
for (int i = 0; i < fframes.length; i++) { |
1127 |
IFFrame fframe = fframes[i]; |
1128 |
|
1129 |
if (hmax > fframe.getBoundBox().getHeight()) {
|
1130 |
hmax = fframe.getBoundBox().getHeight(); |
1131 |
} |
1132 |
} |
1133 |
break;
|
1134 |
default:
|
1135 |
return;
|
1136 |
} |
1137 |
|
1138 |
FrameCommandsRecord efs = |
1139 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
1140 |
efs.startComplex(PluginServices.getText(this, "change_height")); |
1141 |
|
1142 |
for (int i = 0; i < fframes.length; i++) { |
1143 |
IFFrame fframe = (IFFrame) fframes[i].clone(); |
1144 |
Rectangle2D.Double r =
|
1145 |
(Rectangle2D.Double) fframe.getBoundBox().clone();
|
1146 |
r.height = hmax; |
1147 |
fframe.setBoundBox(r); |
1148 |
efs.update(fframes[i], fframe); |
1149 |
} |
1150 |
|
1151 |
efs.endComplex(); |
1152 |
} |
1153 |
|
1154 |
/**
|
1155 |
* Distribuye horizontalmente los fframes dejandolos equiespaciados.
|
1156 |
*
|
1157 |
* @throws CloneNotSupportedException
|
1158 |
*/
|
1159 |
private void spaceRight() throws CloneNotSupportedException { |
1160 |
LayoutPanel theLayout = getLayout(); |
1161 |
if(theLayout == null){ |
1162 |
return;
|
1163 |
} |
1164 |
double xmin = Double.POSITIVE_INFINITY; |
1165 |
double xmax = Double.NEGATIVE_INFINITY; |
1166 |
int num = 0; |
1167 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
1168 |
num = fframes.length; |
1169 |
if(num <=1){ |
1170 |
return;
|
1171 |
} |
1172 |
|
1173 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
1174 |
fframesList.sort(new Comparator<IFFrame>() { |
1175 |
@Override
|
1176 |
public int compare(IFFrame o1, IFFrame o2) { |
1177 |
double res = Double.compare(o1.getBoundBox().getMinX(),o2.getBoundBox().getMinX()); |
1178 |
|
1179 |
if(res == 0){ |
1180 |
res = Double.compare(o1.getBoundBox().getMaxX(),o2.getBoundBox().getMaxX());
|
1181 |
} |
1182 |
return (int) Math.round(res); |
1183 |
} |
1184 |
} ); |
1185 |
|
1186 |
double framesWidth = 0; |
1187 |
|
1188 |
switch (alignRelativeTo) {
|
1189 |
case RELATIVE_TO_THE_PAGE:
|
1190 |
xmin = 0;
|
1191 |
xmax = theLayout.getLayoutContext().getAttributes().getPaperSize().getWidth(); |
1192 |
for (IFFrame fframe : fframesList) {
|
1193 |
framesWidth += fframe.getBoundBox().getWidth(); |
1194 |
} |
1195 |
break;
|
1196 |
case RELATIVE_TO_SELECTION:
|
1197 |
for (IFFrame fframe : fframesList) {
|
1198 |
if (xmin > fframe.getBoundBox().getMinX()) {
|
1199 |
xmin = fframe.getBoundBox().getMinX(); |
1200 |
} |
1201 |
if (xmax < fframe.getBoundBox().getMaxX()) {
|
1202 |
xmax = fframe.getBoundBox().getMaxX(); |
1203 |
} |
1204 |
framesWidth += fframe.getBoundBox().getWidth(); |
1205 |
} |
1206 |
break;
|
1207 |
default:
|
1208 |
return;
|
1209 |
} |
1210 |
|
1211 |
|
1212 |
double dif = xmax - xmin;
|
1213 |
double dist = (dif-framesWidth) / (num-1); |
1214 |
FrameCommandsRecord efs = |
1215 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
1216 |
efs.startComplex(PluginServices.getText(this, "distributes_right")); |
1217 |
|
1218 |
int i = 0; |
1219 |
double currentX = xmin;
|
1220 |
for (IFFrame fframe : fframesList) {
|
1221 |
IFFrame fframeCloned = (IFFrame) fframe.clone(); |
1222 |
Rectangle2D.Double r =
|
1223 |
(Rectangle2D.Double) fframeCloned.getBoundBox().clone();
|
1224 |
r.x = currentX; |
1225 |
currentX += r.width+dist; |
1226 |
fframeCloned.setBoundBox(r); |
1227 |
efs.update(fframe, fframeCloned); |
1228 |
} |
1229 |
|
1230 |
efs.endComplex(); |
1231 |
} |
1232 |
|
1233 |
/**
|
1234 |
* Distribuye verticalmente los fframes dejandolos equiespaciados.
|
1235 |
*
|
1236 |
* @throws CloneNotSupportedException
|
1237 |
*/
|
1238 |
private void spaceDown() throws CloneNotSupportedException { |
1239 |
LayoutPanel theLayout = getLayout(); |
1240 |
if(theLayout == null){ |
1241 |
return;
|
1242 |
} |
1243 |
double ymin = Double.POSITIVE_INFINITY; |
1244 |
double ymax = Double.NEGATIVE_INFINITY; |
1245 |
int num = 0; |
1246 |
IFFrame[] fframes = theLayout.getLayoutContext().getSelectedFFrames();
|
1247 |
num = fframes.length; |
1248 |
if(num <=1){ |
1249 |
return;
|
1250 |
} |
1251 |
|
1252 |
List<IFFrame> fframesList = Arrays.asList(fframes); |
1253 |
fframesList.sort(new Comparator<IFFrame>() { |
1254 |
@Override
|
1255 |
public int compare(IFFrame o1, IFFrame o2) { |
1256 |
double res = Double.compare(o1.getBoundBox().getMinY(),o2.getBoundBox().getMinY()); |
1257 |
|
1258 |
if(res == 0){ |
1259 |
res = Double.compare(o1.getBoundBox().getMaxY(),o2.getBoundBox().getMaxY());
|
1260 |
} |
1261 |
return (int) Math.round(res); |
1262 |
} |
1263 |
} ); |
1264 |
|
1265 |
double framesHeight = 0; |
1266 |
|
1267 |
switch (alignRelativeTo) {
|
1268 |
case RELATIVE_TO_THE_PAGE:
|
1269 |
ymin = 0;
|
1270 |
ymax = theLayout.getLayoutContext().getAttributes().getPaperSize().getHeight(); |
1271 |
for (IFFrame fframe : fframesList) {
|
1272 |
framesHeight += fframe.getBoundBox().getHeight(); |
1273 |
} |
1274 |
break;
|
1275 |
case RELATIVE_TO_SELECTION:
|
1276 |
for (IFFrame fframe : fframesList) {
|
1277 |
if (ymin > fframe.getBoundBox().getMinY()) {
|
1278 |
ymin = fframe.getBoundBox().getMinY(); |
1279 |
} |
1280 |
if (ymax < fframe.getBoundBox().getMaxY()) {
|
1281 |
ymax = fframe.getBoundBox().getMaxY(); |
1282 |
} |
1283 |
framesHeight += fframe.getBoundBox().getHeight(); |
1284 |
} |
1285 |
break;
|
1286 |
default:
|
1287 |
return;
|
1288 |
} |
1289 |
|
1290 |
double dif = ymax - ymin;
|
1291 |
double dist = (dif-framesHeight) / (num-1); |
1292 |
FrameCommandsRecord efs = |
1293 |
theLayout.getLayoutContext().getFrameCommandsRecord(); |
1294 |
efs.startComplex(PluginServices.getText(this, "distributes_up")); |
1295 |
|
1296 |
int i = 0; |
1297 |
double currentY = ymin;
|
1298 |
for (IFFrame fframe : fframesList) {
|
1299 |
IFFrame fframeCloned = (IFFrame) fframe.clone(); |
1300 |
Rectangle2D.Double r =
|
1301 |
(Rectangle2D.Double) fframeCloned.getBoundBox().clone();
|
1302 |
r.y = currentY; |
1303 |
currentY += r.height+dist; |
1304 |
fframeCloned.setBoundBox(r); |
1305 |
efs.update(fframe, fframeCloned); |
1306 |
} |
1307 |
|
1308 |
efs.endComplex(); |
1309 |
} |
1310 |
|
1311 |
/**
|
1312 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
1313 |
*/
|
1314 |
public void actionPerformed(ActionEvent e) { |
1315 |
LayoutPanel theLayout = getLayout(); |
1316 |
if(theLayout == null){ |
1317 |
return;
|
1318 |
} |
1319 |
theLayout.getLayoutContext().updateFFrames(); |
1320 |
|
1321 |
String actionCommand = e.getActionCommand().toUpperCase();
|
1322 |
if (null == actionCommand) { |
1323 |
return;
|
1324 |
} |
1325 |
try {
|
1326 |
switch (actionCommand) {
|
1327 |
case "LEFT": |
1328 |
alignLeft(); |
1329 |
break;
|
1330 |
case "CENTERV": |
1331 |
alignCenterH(); |
1332 |
break;
|
1333 |
case "RIGHT": |
1334 |
alignRight(); |
1335 |
break;
|
1336 |
case "UP": |
1337 |
alignUp(); |
1338 |
break;
|
1339 |
case "CENTERH": |
1340 |
alignCenterV(); |
1341 |
break;
|
1342 |
case "DOWN": |
1343 |
alignDown(); |
1344 |
break;
|
1345 |
case "DISTUP": |
1346 |
distUp(); |
1347 |
break;
|
1348 |
case "DISTCENTERV": |
1349 |
distCenterV(); |
1350 |
break;
|
1351 |
case "DISTDOWN": |
1352 |
distDown(); |
1353 |
break;
|
1354 |
case "DISTLEFT": |
1355 |
distLeft(); |
1356 |
break;
|
1357 |
case "DISTCENTERH": |
1358 |
distCenterH(); |
1359 |
break;
|
1360 |
case "DISTRIGHT": |
1361 |
distRight(); |
1362 |
break;
|
1363 |
case "SIZECENTERV": |
1364 |
sizeWidth(); |
1365 |
break;
|
1366 |
case "SIZECENTERH": |
1367 |
sizeHeight(); |
1368 |
break;
|
1369 |
case "SIZEOTHER": |
1370 |
sizeWidth(); |
1371 |
theLayout |
1372 |
.getLayoutContext() |
1373 |
.updateFFrames(); |
1374 |
sizeHeight(); |
1375 |
break;
|
1376 |
case "SPACERIGHT": |
1377 |
spaceRight(); |
1378 |
break;
|
1379 |
case "SPACEDOWN": |
1380 |
spaceDown(); |
1381 |
break;
|
1382 |
case "INLAYOUT": |
1383 |
inLayout = !inLayout; |
1384 |
break;
|
1385 |
default:
|
1386 |
break;
|
1387 |
} |
1388 |
} catch (Exception ex) { |
1389 |
LOG.error("Can't perform action '"+actionCommand+"'", ex); |
1390 |
} |
1391 |
|
1392 |
theLayout.getLayoutContext().updateFFrames(); |
1393 |
theLayout.getLayoutContext().notifAllObservers(); |
1394 |
} |
1395 |
|
1396 |
public void setAlignRelativeTo(int i) { |
1397 |
this.alignRelativeTo = i;
|
1398 |
} |
1399 |
} |