Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / gui / dialogs / EventsFAlign.java @ 7906

History | View | Annotate | Download (30.4 KB)

1
/*
2
 * Created on 22-jul-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.project.documents.layout.gui.dialogs;
46

    
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.util.Iterator;
50
import java.util.TreeMap;
51

    
52
import com.iver.andami.PluginServices;
53
import com.iver.cit.gvsig.gui.layout.Layout;
54
import com.iver.cit.gvsig.project.documents.layout.commands.EditableFeatureSource;
55
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
56

    
57

    
58
/**
59
 * Clase que hace de Listener de FAlignDialog.
60
 *
61
 * @author Vicente Caballero Navarro
62
 */
63
public class EventsFAlign implements ActionListener {
64
        private Layout m_layout;
65
        private boolean inLayout = false;
66

    
67
        /**
68
         * Crea un nuevo FAlign.
69
         *
70
         * @param layout Referencia al Layout.
71
         */
72
        public EventsFAlign(Layout layout) {
73
                m_layout = layout;
74
        }
75

    
76
        /**
77
         * Desplaza los fframes seleccionados a la izquierda del fframe m?s
78
         * occidental.
79
         */
80
        private void alignLeft() {
81
                double xmin = Double.MAX_VALUE;
82
                IFFrame[] fframes=m_layout.getFFrames();
83
                for (int i = 0; i < fframes.length; i++) {
84
                        IFFrame fframe = fframes[i];
85

    
86
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
87
                                if (xmin > fframe.getBoundBox().getMinX()) {
88
                                        xmin = fframe.getBoundBox().getMinX();
89
                                }
90
                        }
91
                }
92
                EditableFeatureSource efs=m_layout.getEFS();
93
                efs.startComplexCommand();
94
                for (int i = fframes.length-1; i>=0; i--) {
95
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
96

    
97
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
98
                                fframe.getBoundBox().x = xmin;
99
                                efs.modifyFFrame(fframes[i],fframe);
100
                        }
101
                }
102
                efs.endComplexCommand(PluginServices.getText(this,"align_left"));
103
        }
104

    
105
        /**
106
         * Desplaza los fframes seleccionados a la izquierda del Layout.
107
         */
108
        private void alignLeftL() {
109
                double xmin = 0;
110
                IFFrame[] fframes=m_layout.getFFrames();
111
                EditableFeatureSource efs=m_layout.getEFS();
112
                efs.startComplexCommand();
113
                for (int i = 0; i < fframes.length; i++) {
114
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
115

    
116
                        if (fframe.getSelected() != 0) {
117
                                fframe.getBoundBox().x = xmin;
118
                                efs.modifyFFrame(fframes[i],fframe);
119
                        }
120

    
121
                }
122
                efs.endComplexCommand(PluginServices.getText(this,"align_to_layout_left"));
123
        }
124

    
125
        /**
126
         * Desplaza los fframes seleccionados al centro del fframe mas ancho de
127
         * forma horizontal.
128
         */
129
        private void alignCenterV() {
130
                double xcenter = 0;
131
                double w = Double.MIN_VALUE;
132
                IFFrame[] fframes=m_layout.getFFrames();
133
                for (int i = 0; i < fframes.length; i++) {
134
                        IFFrame fframe = fframes[i];
135

    
136
                        if (fframe.getSelected() != 0) {
137
                                if (w < fframe.getBoundBox().getWidth()) {
138
                                        w = fframe.getBoundBox().getWidth();
139
                                        xcenter = fframe.getBoundBox().getCenterX();
140
                                }
141
                        }
142
                }
143
                EditableFeatureSource efs=m_layout.getEFS();
144
                efs.startComplexCommand();
145
                for (int i = 0; i < fframes.length; i++) {
146
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
147

    
148
                        if (fframe.getSelected() != 0) {
149
                                fframe.getBoundBox().x = xcenter -
150
                                        (fframe.getBoundBox().width / 2);
151
                                efs.modifyFFrame(fframes[i],fframe);
152
                        }
153
                }
154
                efs.endComplexCommand(PluginServices.getText(this,"align_center"));
155
        }
156

    
157
        /**
158
         * Desplaza los fframes seleccionados al centro del Layout horizontalmente.
159
         */
160
        private void alignCenterVL() {
161
                double xcenter = 0;
162
                xcenter = m_layout.getAtributes().m_sizePaper.getAncho() / 2;
163
                IFFrame[] fframes=m_layout.getFFrames();
164
                EditableFeatureSource efs=m_layout.getEFS();
165
                efs.startComplexCommand();
166
                for (int i = 0; i < fframes.length; i++) {
167
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
168

    
169
                        if (fframe.getSelected() != 0) {
170
                                fframe.getBoundBox().x = xcenter -
171
                                        (fframe.getBoundBox().width / 2);
172
                                efs.modifyFFrame(fframes[i],fframe);
173
                        }
174
                }
175
                efs.endComplexCommand(PluginServices.getText(this,"align_to_layout_center"));
176
        }
177

    
178
        /**
179
         * Desplaza los fframes seleccionados a la parte derecha del fframe m?s
180
         * oriental.
181
         */
182
        private void alignRight() {
183
                double xmax = Double.MIN_VALUE;
184
                IFFrame[] fframes=m_layout.getFFrames();
185
                for (int i = 0; i < fframes.length; i++) {
186
                        IFFrame fframe = fframes[i];
187

    
188
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
189
                                if (xmax < fframe.getBoundBox().getMaxX()) {
190
                                        xmax = fframe.getBoundBox().getMaxX();
191
                                }
192
                        }
193
                }
194
                EditableFeatureSource efs=m_layout.getEFS();
195
                efs.startComplexCommand();
196
                for (int i = 0; i < fframes.length; i++) {
197
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
198

    
199
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
200
                                fframe.getBoundBox().x = xmax -
201
                                        fframes[i].getBoundBox().width;
202
                                efs.modifyFFrame(fframes[i],fframe);
203
                        }
204
                }
205
                efs.endComplexCommand(PluginServices.getText(this,"align_right"));
206
        }
207

    
208
        /**
209
         * Desplaza los fframes seleccionados a la parte derecha del Layout.
210
         */
211
        private void alignRightL() {
212
                double xmax = 0;
213
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
214
                IFFrame[] fframes=m_layout.getFFrames();
215
                EditableFeatureSource efs=m_layout.getEFS();
216
                efs.startComplexCommand();
217
                for (int i = 0; i < fframes.length; i++) {
218
                        IFFrame fframe =fframes[i].cloneFFrame(m_layout);
219

    
220
                        if (fframe.getSelected() != 0) {
221
                                fframe.getBoundBox().x = xmax -
222
                                        fframes[i].getBoundBox().width;
223
                                efs.modifyFFrame(fframes[i], fframe);
224
                        }
225
                }
226
                efs.endComplexCommand(PluginServices.getText(this,"align_to_layout_right"));
227
        }
228

    
229
        /**
230
         * Desplaza los fframes seleccionados a la parte inferior del fframe m?s
231
         * hacia abajo.
232
         */
233
        private void alignDown() {
234
                double ymax = Double.MIN_VALUE;
235
                IFFrame[] fframes=m_layout.getFFrames();
236

    
237
                for (int i = 0; i < fframes.length; i++) {
238
                        IFFrame fframe = fframes[i];
239

    
240
                        if (fframe.getSelected() != 0) {
241
                                if (ymax < fframe.getBoundBox().getMaxY()) {
242
                                        ymax = fframe.getBoundBox().getMaxY();
243
                                }
244
                        }
245
                }
246
                EditableFeatureSource efs=m_layout.getEFS();
247
                efs.startComplexCommand();
248
                for (int i = 0; i < fframes.length; i++) {
249
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
250

    
251
                        if (fframe.getSelected() != 0) {
252
                                fframe.getBoundBox().y = ymax - fframe.getBoundBox().height;
253
                                efs.modifyFFrame(fframes[i],fframe);
254
                        }
255
                }
256
                efs.endComplexCommand(PluginServices.getText(this,"align_down"));
257
        }
258

    
259
        /**
260
         * Desplaza los fframes seleccionados a la parte inferior del Layout.
261
         */
262
        private void alignDownL() {
263
                double ymax = 0;
264
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
265
                IFFrame[] fframes=m_layout.getFFrames();
266
                EditableFeatureSource efs=m_layout.getEFS();
267
                efs.startComplexCommand();
268
                for (int i = 0; i < fframes.length; i++) {
269
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
270

    
271
                        if (fframe.getSelected() != 0) {
272
                                fframe.getBoundBox().y = ymax - fframe.getBoundBox().height;
273
                                efs.modifyFFrame(fframes[i],fframe);
274
                        }
275
                }
276
                efs.endComplexCommand(PluginServices.getText(this,"align_to_layout_down"));
277
        }
278

    
279
        /**
280
         * Desplaza los fframes seleccionados a la parte superior del fframe que
281
         * m?s arriba este colocado.
282
         */
283
        private void alignUp() {
284
                double ymin = Double.MAX_VALUE;
285
                IFFrame[] fframes=m_layout.getFFrames();
286
                for (int i = 0; i < fframes.length; i++) {
287
                        IFFrame fframe = fframes[i];
288

    
289
                        if (fframe.getSelected() != 0) {
290
                                if (ymin > fframe.getBoundBox().getMinY()) {
291
                                        ymin = fframe.getBoundBox().getMinY();
292
                                }
293
                        }
294
                }
295
                EditableFeatureSource efs=m_layout.getEFS();
296
                efs.startComplexCommand();
297
                for (int i = 0; i < fframes.length; i++) {
298
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
299

    
300
                        if (fframe.getSelected() != 0) {
301
                                fframe.getBoundBox().y = ymin;
302
                                efs.modifyFFrame(fframes[i],fframe);
303
                        }
304
                }
305
                efs.endComplexCommand(PluginServices.getText(this,"align_up"));
306
        }
307

    
308
        /**
309
         * Desplaza los fframes seleccionados a la parte superior del Layout.
310
         */
311
        private void alignUpL() {
312
                double ymin = 0;
313
                IFFrame[] fframes=m_layout.getFFrames();
314
                EditableFeatureSource efs=m_layout.getEFS();
315
                efs.startComplexCommand();
316
                for (int i = 0; i < fframes.length; i++) {
317
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
318

    
319
                        if (fframe.getSelected() != 0) {
320
                                fframe.getBoundBox().y = ymin;
321
                                efs.modifyFFrame(fframes[i],fframe);
322
                        }
323
                }
324
                efs.endComplexCommand(PluginServices.getText(this,"align_to_layout_up"));
325
        }
326

    
327
        /**
328
         * Desplaza los fframes seleccionados al centro del fframe m?s alto
329
         * verticalmente.
330
         */
331
        private void alignCenterH() {
332
                double ycenter = 0;
333
                double h = Double.MIN_VALUE;
334
                IFFrame[] fframes=m_layout.getFFrames();
335
                for (int i = 0; i < fframes.length; i++) {
336
                        IFFrame fframe = fframes[i];
337

    
338
                        if (fframe.getSelected() != 0) {
339
                                if (h < fframe.getBoundBox().getHeight()) {
340
                                        h = fframe.getBoundBox().getHeight();
341
                                        ycenter = fframe.getBoundBox().getCenterY();
342
                                }
343
                        }
344
                }
345
                EditableFeatureSource efs=m_layout.getEFS();
346
                efs.startComplexCommand();
347
                for (int i = 0; i < fframes.length; i++) {
348
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
349

    
350
                        if (fframe.getSelected() != 0) {
351
                                fframe.getBoundBox().y = ycenter -
352
                                        (fframe.getBoundBox().height / 2);
353
                                efs.modifyFFrame(fframes[i],fframe);
354
                        }
355
                }
356
                efs.endComplexCommand(PluginServices.getText(this,"align_vertical_center"));
357
        }
358

    
359
        /**
360
         * Desplaza los fframes seleccionados en el Layout al centro verticalmente.
361
         */
362
        private void alignCenterHL() {
363
                double ycenter = 0;
364
                ycenter = m_layout.getAtributes().m_sizePaper.getAlto() / 2;
365
                IFFrame[] fframes=m_layout.getFFrames();
366
                EditableFeatureSource efs=m_layout.getEFS();
367
                efs.startComplexCommand();
368
                for (int i = 0; i < fframes.length; i++) {
369
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
370

    
371
                        if (fframe.getSelected() != 0) {
372
                                fframe.getBoundBox().y = ycenter -
373
                                        (fframe.getBoundBox().height / 2);
374
                                efs.modifyFFrame(fframes[i],fframe);
375
                        }
376
                }
377
                efs.endComplexCommand(PluginServices.getText(this,"align_to_layout_vertical_center"));
378
        }
379

    
380
        /**
381
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
382
         * de izquierda a derecha.
383
         */
384
        private void distLeft() {
385
                double xmin = Double.MAX_VALUE;
386
                double xmax = Double.MIN_VALUE;
387
                int num = 0;
388
                IFFrame[] fframes=m_layout.getFFrames();
389
                for (int i = 0; i < fframes.length; i++) {
390
                        IFFrame fframe = fframes[i];
391

    
392
                        if (fframe.getSelected() != 0) {
393
                                if (xmin > fframe.getBoundBox().getMinX()) {
394
                                        xmin = fframe.getBoundBox().getMinX();
395
                                }
396

    
397
                                if (xmax < fframe.getBoundBox().getMaxX()) {
398
                                        xmax = fframe.getBoundBox().getMaxX();
399
                                }
400

    
401
                                num++;
402
                        }
403
                }
404

    
405
                double dif = xmax - xmin;
406
                double dist = dif / num;
407
                EditableFeatureSource efs=m_layout.getEFS();
408
                efs.startComplexCommand();
409
                for (int i = 0; i < fframes.length; i++) {
410
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
411

    
412
                        if (fframe.getSelected() != 0) {
413
                                fframe.getBoundBox().x = xmin + (dist * i);
414
                                efs.modifyFFrame(fframes[i],fframe);
415
                        }
416
                }
417
                efs.endComplexCommand(PluginServices.getText(this,"distributes_left"));
418
        }
419

    
420
        /**
421
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
422
         * y vertical, de izquierda a derecha.
423
         */
424
        private void distLeftL() {
425
                double xmin = 0;
426
                double xmax = 0;
427
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
428

    
429
                int num = 0;
430
                IFFrame[] fframes=m_layout.getFFrames();
431
                for (int i = 0; i < fframes.length; i++) {
432
                        IFFrame fframe = fframes[i];
433

    
434
                        if (fframe.getSelected() != 0) {
435
                                num++;
436
                        }
437
                }
438

    
439
                double dif = xmax - xmin;
440
                double dist = dif / num;
441
                EditableFeatureSource efs=m_layout.getEFS();
442
                efs.startComplexCommand();
443
                for (int i = 0; i < fframes.length; i++) {
444
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
445

    
446
                        if (fframe.getSelected() != 0) {
447
                                fframe.getBoundBox().x = xmin + (dist * i);
448
                                efs.modifyFFrame(fframes[i],fframe);
449
                        }
450
                }
451
                efs.endComplexCommand(PluginServices.getText(this,"distributes_to_layout_left"));
452
        }
453

    
454
        /**
455
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
456
         * de derecha a izquierda.
457
         */
458
        private void distRight() {
459
                double xmin = Double.MAX_VALUE;
460
                double xmax = Double.MIN_VALUE;
461
                int num = 0;
462
                IFFrame[] fframes=m_layout.getFFrames();
463
                for (int i = 0; i < fframes.length; i++) {
464
                        IFFrame fframe = fframes[i];
465

    
466
                        if (fframe.getSelected() != 0) {
467
                                if (xmin > fframe.getBoundBox().getMinX()) {
468
                                        xmin = fframe.getBoundBox().getMinX();
469
                                }
470

    
471
                                if (xmax < fframe.getBoundBox().getMaxX()) {
472
                                        xmax = fframe.getBoundBox().getMaxX();
473
                                }
474

    
475
                                num++;
476
                        }
477
                }
478

    
479
                double dif = xmax - xmin;
480
                double dist = dif / num;
481
                EditableFeatureSource efs=m_layout.getEFS();
482
                efs.startComplexCommand();
483
                for (int i = 0; i < fframes.length; i++) {
484
                        IFFrame fframe = fframes[i];
485

    
486
                        if (fframe.getSelected() != 0) {
487
                                fframe.getBoundBox().x = xmax - (dist * i) -
488
                                        fframe.getBoundBox().width;
489
                                efs.modifyFFrame(fframes[i],fframe);
490
                        }
491
                }
492
                efs.endComplexCommand(PluginServices.getText(this,"distributes_right"));
493
        }
494

    
495
        /**
496
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
497
         * y vertical, de derecha a izquierda.
498
         */
499
        private void distRightL() {
500
                double xmin = 0;
501
                double xmax = 0;
502
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
503

    
504
                int num = 0;
505
                IFFrame[] fframes=m_layout.getFFrames();
506
                for (int i = 0; i < fframes.length; i++) {
507
                        IFFrame fframe = fframes[i];
508

    
509
                        if (fframe.getSelected() != 0) {
510
                                num++;
511
                        }
512
                }
513

    
514
                double dif = xmax - xmin;
515
                double dist = dif / num;
516
                EditableFeatureSource efs=m_layout.getEFS();
517
                efs.startComplexCommand();
518
                for (int i = 0; i < fframes.length; i++) {
519
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
520

    
521
                        if (fframe.getSelected() != 0) {
522
                                fframe.getBoundBox().x = xmax - (dist * i) -
523
                                        fframe.getBoundBox().width;
524
                                efs.modifyFFrame(fframes[i],fframe);
525
                        }
526
                }
527
                efs.endComplexCommand(PluginServices.getText(this,"distributes_to_layout_right"));
528
        }
529

    
530
        /**
531
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
532
         * desde arriba hacia abajo.
533
         */
534
        private void distUp() {
535
                double ymin = Double.MAX_VALUE;
536
                double ymax = Double.MIN_VALUE;
537
                int num = 0;
538
                IFFrame[] fframes=m_layout.getFFrames();
539

    
540
                for (int i = 0; i < fframes.length; i++) {
541
                        IFFrame fframe = fframes[i];
542

    
543
                        if (fframe.getSelected() != 0) {
544
                                if (ymin > fframe.getBoundBox().getMinY()) {
545
                                        ymin = fframe.getBoundBox().getMinY();
546
                                }
547

    
548
                                if (ymax < fframe.getBoundBox().getMaxY()) {
549
                                        ymax = fframe.getBoundBox().getMaxY();
550
                                }
551

    
552
                                num++;
553
                        }
554
                }
555

    
556
                double dif = ymax - ymin;
557
                double dist = dif / num;
558
                EditableFeatureSource efs=m_layout.getEFS();
559
                efs.startComplexCommand();
560
                for (int i = 0; i <fframes.length; i++) {
561
                        IFFrame fframe = fframes[i];
562

    
563
                        if (fframe.getSelected() != 0) {
564
                                fframe.getBoundBox().y = ymin + (dist * i);
565
                                efs.modifyFFrame(fframes[i],fframe);
566
                        }
567
                }
568
                efs.endComplexCommand(PluginServices.getText(this,"distributes_up"));
569
        }
570

    
571
        /**
572
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
573
         * y vertical, desde arriba hacia abajo.
574
         */
575
        private void distUpL() {
576
                double ymin = 0;
577
                double ymax = 0;
578
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
579

    
580
                int num = 0;
581
                IFFrame[] fframes=m_layout.getFFrames();
582
                for (int i = 0; i < fframes.length; i++) {
583
                        IFFrame fframe = fframes[i];
584

    
585
                        if (fframe.getSelected() != 0) {
586
                                num++;
587
                        }
588
                }
589

    
590
                double dif = ymax - ymin;
591
                double dist = dif / num;
592
                EditableFeatureSource efs=m_layout.getEFS();
593
                efs.startComplexCommand();
594
                for (int i = 0; i < fframes.length; i++) {
595
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
596

    
597
                        if (fframe.getSelected() != 0) {
598
                                fframe.getBoundBox().y = ymin + (dist * i);
599
                                efs.modifyFFrame(fframes[i],fframe);
600
                        }
601
                }
602
                efs.endComplexCommand(PluginServices.getText(this,"distributes_to_layout_up"));
603
        }
604

    
605
        /**
606
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
607
         * desde bajo hacia arriba.
608
         */
609
        private void distDown() {
610
                double ymin = Double.MAX_VALUE;
611
                double ymax = Double.MIN_VALUE;
612
                int num = 0;
613
                IFFrame[] fframes=m_layout.getFFrames();
614
                for (int i = 0; i < fframes.length; i++) {
615
                        IFFrame fframe = fframes[i];
616

    
617
                        if (fframe.getSelected() != 0) {
618
                                if (ymin > fframe.getBoundBox().getMinY()) {
619
                                        ymin = fframe.getBoundBox().getMinY();
620
                                }
621

    
622
                                if (ymax < fframe.getBoundBox().getMaxY()) {
623
                                        ymax = fframe.getBoundBox().getMaxY();
624
                                }
625

    
626
                                num++;
627
                        }
628
                }
629

    
630
                double dif = ymax - ymin;
631
                double dist = dif / num;
632
                EditableFeatureSource efs=m_layout.getEFS();
633
                efs.startComplexCommand();
634
                for (int i = 0; i < fframes.length; i++) {
635
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
636

    
637
                        if (fframe.getSelected() != 0) {
638
                                fframe.getBoundBox().y = ymax - (dist * i) -
639
                                        fframe.getBoundBox().height;
640
                                efs.modifyFFrame(fframes[i],fframe);
641
                        }
642
                }
643
                efs.endComplexCommand(PluginServices.getText(this,"distributes_down"));
644
        }
645

    
646
        /**
647
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
648
         * y vertical, desde bajo hacia arriba.
649
         */
650
        private void distDownL() {
651
                double ymin = 0;
652
                double ymax = 0;
653
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
654

    
655
                int num = 0;
656
                IFFrame[] fframes=m_layout.getFFrames();
657
                for (int i = 0; i < fframes.length; i++) {
658
                        IFFrame fframe = fframes[i];
659

    
660
                        if (fframe.getSelected() != 0) {
661
                                num++;
662
                        }
663
                }
664

    
665
                double dif = ymax - ymin;
666
                double dist = dif / num;
667
                EditableFeatureSource efs=m_layout.getEFS();
668
                efs.startComplexCommand();
669
                for (int i = fframes.length - 1; i >= 0; i--) {
670
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
671

    
672
                        if (fframe.getSelected() != 0) {
673
                                fframe.getBoundBox().y = ymax - (dist * i) -
674
                                        fframe.getBoundBox().height;
675
                                efs.modifyFFrame(fframes[i],fframe);
676
                        }
677
                }
678
                efs.endComplexCommand(PluginServices.getText(this,"distributes_to_layout_down"));
679
        }
680

    
681
        /**
682
         * Distribuye los fframes seleccionados de forma equidistante y vertical.
683
         */
684
        private void distCenterH() {
685
                double xmin = Double.MAX_VALUE;
686
                double xmax = Double.MIN_VALUE;
687
                int num = 0;
688
                IFFrame[] fframes=m_layout.getFFrames();
689
                for (int i = 0; i < fframes.length; i++) {
690
                        IFFrame fframe = fframes[i];
691

    
692
                        if (fframe.getSelected() != 0) {
693
                                if (xmin > fframe.getBoundBox().getMinX()) {
694
                                        xmin = fframe.getBoundBox().getMinX();
695
                                }
696

    
697
                                if (xmax < fframe.getBoundBox().getMaxX()) {
698
                                        xmax = fframe.getBoundBox().getMaxX();
699
                                }
700

    
701
                                num++;
702
                        }
703
                }
704

    
705
                double dif = xmax - xmin;
706
                double dist = dif / num;
707
                EditableFeatureSource efs=m_layout.getEFS();
708
                efs.startComplexCommand();
709
                for (int i = 0; i < fframes.length; i++) {
710
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
711

    
712
                        if (fframe.getSelected() != 0) {
713
                                fframe.getBoundBox().x = (xmin +
714
                                        (((dist) * (i + 1)) - (dist / 2))) -
715
                                        (fframe.getBoundBox().width / 2);
716
                                efs.modifyFFrame(fframes[i],fframe);
717
                        }
718
                }
719
                efs.endComplexCommand(PluginServices.getText(this,"distributes_vertical"));
720
        }
721

    
722
        /**
723
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
724
         * y vertical.
725
         */
726
        private void distCenterHL() {
727
                double xmin = 0;
728
                double xmax = 0;
729
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
730

    
731
                int num = 0;
732
                IFFrame[] fframes=m_layout.getFFrames();
733
                for (int i = 0; i < fframes.length; i++) {
734
                        IFFrame fframe = fframes[i];
735

    
736
                        if (fframe.getSelected() != 0) {
737
                                num++;
738
                        }
739
                }
740

    
741
                double dif = xmax - xmin;
742
                double dist = dif / num;
743
                EditableFeatureSource efs=m_layout.getEFS();
744
                efs.startComplexCommand();
745
                for (int i = 0; i < fframes.length; i++) {
746
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
747

    
748
                        if (fframe.getSelected() != 0) {
749
                                fframe.getBoundBox().x = (xmin +
750
                                        (((dist) * (i + 1)) - (dist / 2))) -
751
                                        (fframe.getBoundBox().width / 2);
752
                                efs.modifyFFrame(fframes[i],fframe);
753
                        }
754
                }
755
                efs.endComplexCommand(PluginServices.getText(this,"distributes_to_layout_vertical"));
756
        }
757

    
758
        /**
759
         * Distribuye los fframes seleccionados de forma equidistante y horizontal.
760
         */
761
        private void distCenterV() {
762
                double ymin = Double.MAX_VALUE;
763
                double ymax = Double.MIN_VALUE;
764
                int num = 0;
765
                IFFrame[] fframes=m_layout.getFFrames();
766
                for (int i = 0; i < fframes.length; i++) {
767
                        IFFrame fframe = fframes[i];
768

    
769
                        if (fframe.getSelected() != 0) {
770
                                if (ymin > fframe.getBoundBox().getMinY()) {
771
                                        ymin = fframe.getBoundBox().getMinY();
772
                                }
773

    
774
                                if (ymax < fframe.getBoundBox().getMaxY()) {
775
                                        ymax = fframe.getBoundBox().getMaxY();
776
                                }
777

    
778
                                num++;
779
                        }
780
                }
781

    
782
                double dif = ymax - ymin;
783
                double dist = dif / num;
784
                EditableFeatureSource efs=m_layout.getEFS();
785
                efs.startComplexCommand();
786
                for (int i = 0; i < fframes.length; i++) {
787
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
788

    
789
                        if (fframe.getSelected() != 0) {
790
                                fframe.getBoundBox().y = (ymin +
791
                                        (((dist) * (i + 1)) - (dist / 2))) -
792
                                        (fframe.getBoundBox().height / 2);
793
                                efs.modifyFFrame(fframes[i],fframe);
794
                        }
795
                }
796
                efs.endComplexCommand(PluginServices.getText(this,"distributes_horizontal"));
797
        }
798

    
799
        /**
800
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
801
         * y horizontal.
802
         */
803
        private void distCenterVL() {
804
                double ymin = 0;
805
                double ymax = 0;
806
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
807

    
808
                int num = 0;
809
                IFFrame[] fframes=m_layout.getFFrames();
810
                for (int i = 0; i < fframes.length; i++) {
811
                        IFFrame fframe = fframes[i];
812

    
813
                        if (fframe.getSelected() != 0) {
814
                                num++;
815
                        }
816
                }
817

    
818
                double dif = ymax - ymin;
819
                double dist = dif / num;
820
                EditableFeatureSource efs=m_layout.getEFS();
821
                efs.startComplexCommand();
822
                for (int i = 0; i < fframes.length; i++) {
823
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
824

    
825
                        if (fframe.getSelected() != 0) {
826
                                fframe.getBoundBox().y = (ymin +
827
                                        (((dist) * (i + 1)) - (dist / 2))) -
828
                                        (fframe.getBoundBox().height / 2);
829
                                efs.modifyFFrame(fframes[i],fframe);
830
                        }
831
                }
832
                efs.endComplexCommand(PluginServices.getText(this,"distributes_to_layout_horizontal"));
833
        }
834

    
835
        /**
836
         * Cambia la anchura de los fframes seleccionados por la anchura del m?s
837
         * ancho.
838
         */
839
        private void sizeWidth() {
840
                double wmax = Double.MIN_VALUE;
841
                IFFrame[] fframes=m_layout.getFFrames();
842
                for (int i = 0; i < fframes.length; i++) {
843
                        IFFrame fframe = fframes[i];
844

    
845
                        if (fframe.getSelected() != 0) {
846
                                if (wmax < fframe.getBoundBox().getWidth()) {
847
                                        wmax = fframe.getBoundBox().getWidth();
848
                                }
849
                        }
850
                }
851
                EditableFeatureSource efs=m_layout.getEFS();
852
                efs.startComplexCommand();
853
                for (int i = 0; i < fframes.length; i++) {
854
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
855

    
856
                        if (fframe.getSelected() != 0) {
857
                                fframe.getBoundBox().width = wmax;
858
                        efs.modifyFFrame(fframes[i],fframe);
859
                        }
860
                }
861
                efs.endComplexCommand(PluginServices.getText(this,"change_width"));
862
        }
863

    
864
        /**
865
         * Cambia la altura de los fframes seleccionados por la altura del mas
866
         * alto.
867
         */
868
        private void sizeHeight() {
869
                double hmax = Double.MIN_VALUE;
870
                IFFrame[] fframes=m_layout.getFFrames();
871
                for (int i = 0; i < fframes.length; i++) {
872
                        IFFrame fframe = fframes[i];
873

    
874
                        if (fframe.getSelected() != 0) {
875
                                if (hmax < fframe.getBoundBox().getHeight()) {
876
                                        hmax = fframe.getBoundBox().getHeight();
877
                                }
878
                        }
879
                }
880
                EditableFeatureSource efs=m_layout.getEFS();
881
                efs.startComplexCommand();
882
                for (int i = 0; i < fframes.length; i++) {
883
                        IFFrame fframe = fframes[i].cloneFFrame(m_layout);
884

    
885
                        if (fframe.getSelected() != 0) {
886
                                fframe.getBoundBox().height = hmax;
887
                                efs.modifyFFrame(fframes[i],fframe);
888
                        }
889
                }
890
                efs.endComplexCommand(PluginServices.getText(this,"change_height"));
891
        }
892

    
893
        /**
894
         * Distribuye horizontalmente los fframes dejando como espacio entre ellos
895
         * la media de todos los espacios.
896
         */
897
        private void spaceRight() {
898
                double total = 0;
899
                double num = 0;
900
                double xmin = Double.MAX_VALUE;
901
                double xmax = Double.MIN_VALUE;
902

    
903
                TreeMap treemap = new TreeMap();
904
                IFFrame[] fframes=m_layout.getFFrames();
905
                for (int i = 0; i < fframes.length; i++) {
906
                        IFFrame fframe = fframes[i];
907

    
908
                        if (fframe.getSelected() != 0) {
909
                                treemap.put(new Double(fframe.getBoundBox().getMinX()),
910
                                        fframe);
911
                                num++;
912
                        }
913
                }
914

    
915
                Iterator j = treemap.keySet().iterator();
916

    
917
                if (j.hasNext()) {
918
                        IFFrame fframeA = (IFFrame) treemap.get(j.next());
919
                        IFFrame fframeS = null;
920
                        xmin = fframeA.getBoundBox().x;
921

    
922
                        while (j.hasNext()) {
923
                                fframeS = (IFFrame) treemap.get(j.next());
924
                                total += (fframeS.getBoundBox().getMinX() -
925
                                fframeA.getBoundBox().getMaxX());
926
                                fframeA = fframeS;
927
                        }
928

    
929
                        if (fframeS != null) {
930
                                xmax = fframeS.getBoundBox().getMaxX();
931
                        }
932
                }
933

    
934
                if (inLayout) {
935
                        total += (xmin +
936
                        (m_layout.getAtributes().m_sizePaper.getAncho() - xmax));
937
                        num += 2;
938
                }
939

    
940
                double dist = total / (num - 1);
941
                Iterator k = treemap.keySet().iterator();
942
                EditableFeatureSource efs=m_layout.getEFS();
943
                efs.startComplexCommand();
944
                if (k.hasNext()) {
945
                        IFFrame fframe=(IFFrame) treemap.get(k.next());
946
                        IFFrame fframeA = fframe.cloneFFrame(m_layout);
947

    
948
                        if (inLayout) {
949
                                fframeA.getBoundBox().x = dist;
950
                                efs.modifyFFrame(fframe,fframeA);
951
                        }
952

    
953
                        while (k.hasNext()) {
954
                                IFFrame fframeAux=(IFFrame) treemap.get(k.next());
955
                                IFFrame fframeS = fframeAux.cloneFFrame(m_layout);
956
                                fframeS.getBoundBox().x = fframeA.getBoundBox().getMaxX() +
957
                                        dist;
958
                                efs.modifyFFrame(fframeAux,fframeS);
959
                                fframeA = fframeS;
960
                        }
961
                }
962
                efs.endComplexCommand(PluginServices.getText(this,"horizontal_space"));
963
        }
964

    
965
        /**
966
         * Distribuye verticalmente los fframes dejando como espacio entre ellos la
967
         * media de todos los espacios.
968
         */
969
        private void spaceDown() {
970
                double total = 0;
971
                double num = 0;
972
                double ymin = Double.MAX_VALUE;
973
                double ymax = Double.MIN_VALUE;
974

    
975
                TreeMap treemap = new TreeMap();
976
                IFFrame[] fframes=m_layout.getFFrames();
977
                for (int i = 0; i < fframes.length; i++) {
978
                        IFFrame fframe = fframes[i];
979

    
980
                        if (fframe.getSelected() != 0) {
981
                                treemap.put(new Double(fframe.getBoundBox().getMinY()),
982
                                        fframe);
983
                                num++;
984
                        }
985
                }
986

    
987
                Iterator j = treemap.keySet().iterator();
988

    
989
                if (j.hasNext()) {
990
                        IFFrame fframeA = (IFFrame) treemap.get(j.next());
991
                        ymin = fframeA.getBoundBox().y;
992

    
993
                        IFFrame fframeS = null;
994

    
995
                        while (j.hasNext()) {
996
                                fframeS = (IFFrame) treemap.get(j.next());
997
                                total += (fframeS.getBoundBox().getMinY() -
998
                                fframeA.getBoundBox().getMaxY());
999
                                fframeA = fframeS;
1000
                        }
1001

    
1002
                        if (fframeS != null) {
1003
                                ymax = fframeS.getBoundBox().getMaxY();
1004
                        }
1005
                }
1006

    
1007
                if (inLayout) {
1008
                        total += (ymin +
1009
                        (m_layout.getAtributes().m_sizePaper.getAlto() - ymax));
1010
                        num += 2;
1011
                }
1012

    
1013
                double dist = total / (num - 1);
1014
                Iterator k = treemap.keySet().iterator();
1015
                EditableFeatureSource efs=m_layout.getEFS();
1016
                efs.startComplexCommand();
1017
                if (k.hasNext()) {
1018
                        IFFrame fframe=(IFFrame) treemap.get(k.next());
1019
                        IFFrame fframeA = fframe.cloneFFrame(m_layout) ;
1020

    
1021
                        if (inLayout) {
1022
                                fframeA.getBoundBox().y = dist;
1023
                                efs.modifyFFrame(fframe,fframeA);
1024
                        }
1025

    
1026
                        while (k.hasNext()) {
1027
                                IFFrame fframeAux= (IFFrame) treemap.get(k.next());
1028
                                IFFrame fframeS = fframeAux.cloneFFrame(m_layout);
1029
                                fframeS.getBoundBox().y = fframeA.getBoundBox().getMaxY() +
1030
                                        dist;
1031
                                efs.modifyFFrame(fframeAux,fframeS);
1032
                                fframeA = fframeS;
1033
                        }
1034
                }
1035
                efs.endComplexCommand(PluginServices.getText(this,"vertical_space"));
1036
        }
1037

    
1038
        //  class Listener implements ActionListener {
1039

    
1040
        /**
1041
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1042
         */
1043
        public void actionPerformed(ActionEvent e) {
1044
                m_layout.updateFFrames();
1045
                if (!inLayout) {
1046
                        if (e.getActionCommand() == "LEFT") {
1047
                                alignLeft();
1048
                        } else if (e.getActionCommand() == "CENTERV") {
1049
                                alignCenterV();
1050
                        } else if (e.getActionCommand() == "RIGHT") {
1051
                                alignRight();
1052
                        } else if (e.getActionCommand() == "UP") {
1053
                                alignUp();
1054
                        } else if (e.getActionCommand() == "CENTERH") {
1055
                                alignCenterH();
1056
                        } else if (e.getActionCommand() == "DOWN") {
1057
                                alignDown();
1058
                        } else if (e.getActionCommand() == "DISTUP") {
1059
                                distUp();
1060
                        } else if (e.getActionCommand() == "DISTCENTERV") {
1061
                                distCenterV();
1062
                        } else if (e.getActionCommand() == "DISTDOWN") {
1063
                                distDown();
1064
                        } else if (e.getActionCommand() == "DISTLEFT") {
1065
                                distLeft();
1066
                        } else if (e.getActionCommand() == "DISTCENTERH") {
1067
                                distCenterH();
1068
                        } else if (e.getActionCommand() == "DISTRIGHT") {
1069
                                distRight();
1070
                        } else if (e.getActionCommand() == "SIZECENTERV") {
1071
                                sizeWidth();
1072
                        } else if (e.getActionCommand() == "SIZECENTERH") {
1073
                                sizeHeight();
1074
                        } else if (e.getActionCommand() == "SIZEOTHER") {
1075
                                sizeWidth();
1076
                                m_layout.updateFFrames();
1077
                                sizeHeight();
1078
                        } else if (e.getActionCommand() == "SPACERIGHT") {
1079
                                spaceRight();
1080
                        } else if (e.getActionCommand() == "SPACEDOWN") {
1081
                                spaceDown();
1082
                        } else if (e.getActionCommand() == "INLAYOUT") {
1083
                                inLayout = true;
1084
                        }
1085
                } else {
1086
                        if (e.getActionCommand() == "LEFT") {
1087
                                alignLeftL();
1088
                        } else if (e.getActionCommand() == "CENTERV") {
1089
                                alignCenterVL();
1090
                        } else if (e.getActionCommand() == "RIGHT") {
1091
                                alignRightL();
1092
                        } else if (e.getActionCommand() == "UP") {
1093
                                alignUpL();
1094
                        } else if (e.getActionCommand() == "CENTERH") {
1095
                                alignCenterHL();
1096
                        } else if (e.getActionCommand() == "DOWN") {
1097
                                alignDownL();
1098
                        } else if (e.getActionCommand() == "DISTUP") {
1099
                                distUpL();
1100
                        } else if (e.getActionCommand() == "DISTCENTERV") {
1101
                                distCenterVL();
1102
                        } else if (e.getActionCommand() == "DISTDOWN") {
1103
                                distDownL();
1104
                        } else if (e.getActionCommand() == "DISTLEFT") {
1105
                                distLeftL();
1106
                        } else if (e.getActionCommand() == "DISTCENTERH") {
1107
                                distCenterHL();
1108
                        } else if (e.getActionCommand() == "DISTRIGHT") {
1109
                                distRightL();
1110
                        } else if (e.getActionCommand() == "SIZECENTERV") {
1111
                                sizeWidth();
1112
                        } else if (e.getActionCommand() == "SIZECENTERH") {
1113
                                sizeHeight();
1114
                        } else if (e.getActionCommand() == "SIZEOTHER") {
1115
                                sizeWidth();
1116
                                m_layout.updateFFrames();
1117
                                sizeHeight();
1118
                        } else if (e.getActionCommand() == "SPACERIGHT") {
1119
                                spaceRight();
1120
                        } else if (e.getActionCommand() == "SPACEDOWN") {
1121
                                spaceDown();
1122
                        } else if (e.getActionCommand() == "INLAYOUT") {
1123
                                inLayout = false;
1124
                        }
1125
                }
1126
                m_layout.updateFFrames();
1127
                m_layout.refresh();
1128
        }
1129
}