Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / dialogs / EventsFAlign.java @ 6071

History | View | Annotate | Download (30.3 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.gui.layout.dialogs;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.cit.gvsig.gui.layout.Layout;
49
import com.iver.cit.gvsig.gui.layout.commands.EditableFeatureSource;
50
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
51

    
52
import java.awt.event.ActionEvent;
53
import java.awt.event.ActionListener;
54

    
55
import java.util.Iterator;
56
import java.util.TreeMap;
57

    
58

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

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

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

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

    
98
                        if (fframe.getSelected() != 0) {
99
                                fframe.getBoundBox().x = xmin;
100
                                efs.modifyFFrame(fframes[i],fframe);
101
                        }
102

    
103
                }
104
                efs.endComplexCommand(PluginServices.getText(this,"align_left"));
105
        }
106

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

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

    
123
                }
124
                efs.endComplexCommand(PluginServices.getText(this,"align_to_layout_left"));
125
        }
126

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
399
                                if (xmax < fframe.getBoundBox().getMaxX()) {
400
                                        xmax = fframe.getBoundBox().getMaxX();
401
                                }
402

    
403
                                num++;
404
                        }
405
                }
406

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

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

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

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

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

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

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

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

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

    
473
                                if (xmax < fframe.getBoundBox().getMaxX()) {
474
                                        xmax = fframe.getBoundBox().getMaxX();
475
                                }
476

    
477
                                num++;
478
                        }
479
                }
480

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

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

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

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

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

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

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

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

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

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

    
550
                                if (ymax < fframe.getBoundBox().getMaxY()) {
551
                                        ymax = fframe.getBoundBox().getMaxY();
552
                                }
553

    
554
                                num++;
555
                        }
556
                }
557

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

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

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

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

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

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

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

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

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

    
624
                                if (ymax < fframe.getBoundBox().getMaxY()) {
625
                                        ymax = fframe.getBoundBox().getMaxY();
626
                                }
627

    
628
                                num++;
629
                        }
630
                }
631

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

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

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

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

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

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

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

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

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

    
699
                                if (xmax < fframe.getBoundBox().getMaxX()) {
700
                                        xmax = fframe.getBoundBox().getMaxX();
701
                                }
702

    
703
                                num++;
704
                        }
705
                }
706

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

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

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

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

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

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

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

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

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

    
776
                                if (ymax < fframe.getBoundBox().getMaxY()) {
777
                                        ymax = fframe.getBoundBox().getMaxY();
778
                                }
779

    
780
                                num++;
781
                        }
782
                }
783

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
917
                Iterator j = treemap.keySet().iterator();
918

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

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

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

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

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

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

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

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

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

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

    
989
                Iterator j = treemap.keySet().iterator();
990

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

    
995
                        IFFrame fframeS = null;
996

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

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

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

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

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

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

    
1040
        //  class Listener implements ActionListener {
1041

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