Statistics
| Revision:

root / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / dialogs / EventsFAlign.java @ 1822

History | View | Annotate | Download (29.2 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.cit.gvsig.fmap.drivers.DriverIOException;
48
import com.iver.cit.gvsig.gui.layout.Layout;
49
import com.iver.cit.gvsig.gui.layout.LayoutEditableFeature;
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.io.IOException;
56

    
57
import java.util.ArrayList;
58
import java.util.Iterator;
59
import java.util.TreeMap;
60

    
61

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

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

    
80
        /**
81
         * Desplaza los fframes seleccionados a la izquierda del fframe m?s
82
         * occidental.
83
         */
84
        private void alignLeft() {
85
                double xmin = Double.MAX_VALUE;
86
                ArrayList frames = m_layout.getAllFFrames();
87

    
88
                for (int i = 0; i < frames.size(); i++) {
89
                        IFFrame fframe = (IFFrame) frames.get(i);
90

    
91
                        if (fframe.getSelected() != 0) {
92
                                if (xmin > fframe.getBoundBox().getMinX()) {
93
                                        xmin = fframe.getBoundBox().getMinX();
94
                                }
95
                        }
96
                }
97

    
98
                for (int i = 0; i < frames.size(); i++) {
99
                        IFFrame fframe = (IFFrame) frames.get(i);
100

    
101
                        if (fframe.getSelected() != 0) {
102
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
103
                                frameclone.getBoundBox().x = xmin;
104
                                modifyFFrame(frameclone, i);
105
                        }
106
                }
107
        }
108

    
109
        /**
110
         * Desplaza los fframes seleccionados a la izquierda del Layout.
111
         */
112
        private void alignLeftL() {
113
                double xmin = 0;
114
                ArrayList frames = m_layout.getAllFFrames();
115

    
116
                for (int i = 0; i < frames.size(); i++) {
117
                        IFFrame fframe = (IFFrame) frames.get(i);
118

    
119
                        if (fframe.getSelected() != 0) {
120
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
121
                                frameclone.getBoundBox().x = xmin;
122
                                modifyFFrame(frameclone, i);
123
                        }
124
                }
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
                ArrayList frames = m_layout.getAllFFrames();
135

    
136
                for (int i = 0; i < frames.size(); i++) {
137
                        IFFrame fframe = (IFFrame) frames.get(i);
138

    
139
                        if (fframe.getSelected() != 0) {
140
                                if (w < fframe.getBoundBox().getWidth()) {
141
                                        w = fframe.getBoundBox().getWidth();
142
                                        xcenter = fframe.getBoundBox().getCenterX();
143
                                }
144
                        }
145
                }
146

    
147
                for (int i = 0; i < frames.size(); i++) {
148
                        IFFrame fframe = (IFFrame) frames.get(i);
149

    
150
                        if (fframe.getSelected() != 0) {
151
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
152
                                frameclone.getBoundBox().x = xcenter -
153
                                        (fframe.getBoundBox().width / 2);
154
                                modifyFFrame(frameclone, i);
155
                        }
156
                }
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

    
166
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
167
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
168

    
169
                        if (fframe.getSelected() != 0) {
170
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
171
                                frameclone.getBoundBox().x = xcenter -
172
                                        (fframe.getBoundBox().width / 2);
173
                                modifyFFrame(frameclone, i);
174
                        }
175
                }
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

    
185
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
186
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
187

    
188
                        if (fframe.getSelected() != 0) {
189
                                if (xmax < fframe.getBoundBox().getMaxX()) {
190
                                        xmax = fframe.getBoundBox().getMaxX();
191
                                }
192
                        }
193
                }
194

    
195
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
196
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
197

    
198
                        if (fframe.getSelected() != 0) {
199
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
200
                                frameclone.getBoundBox().x = xmax -
201
                                        ((IFFrame) m_layout.getAllFFrames().get(i)).getBoundBox().width;
202
                                modifyFFrame(frameclone, i);
203
                        }
204
                }
205
        }
206

    
207
        /**
208
         * Desplaza los fframes seleccionados a la parte derecha del Layout.
209
         */
210
        private void alignRightL() {
211
                double xmax = 0;
212
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
213

    
214
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
215
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
216

    
217
                        if (fframe.getSelected() != 0) {
218
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
219
                                frameclone.getBoundBox().x = xmax -
220
                                        ((IFFrame) m_layout.getAllFFrames().get(i)).getBoundBox().width;
221
                                modifyFFrame(frameclone, i);
222
                        }
223
                }
224
        }
225

    
226
        /**
227
         * Desplaza los fframes seleccionados a la parte inferior del fframe m?s
228
         * hacia abajo.
229
         */
230
        private void alignDown() {
231
                double ymax = Double.MIN_VALUE;
232

    
233
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
234
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
235

    
236
                        if (fframe.getSelected() != 0) {
237
                                if (ymax < fframe.getBoundBox().getMaxY()) {
238
                                        ymax = fframe.getBoundBox().getMaxY();
239
                                }
240
                        }
241
                }
242

    
243
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
244
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
245

    
246
                        if (fframe.getSelected() != 0) {
247
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
248
                                frameclone.getBoundBox().y = ymax -
249
                                        fframe.getBoundBox().height;
250
                                modifyFFrame(frameclone, i);
251
                        }
252
                }
253
        }
254

    
255
        /**
256
         * Desplaza los fframes seleccionados a la parte inferior del Layout.
257
         */
258
        private void alignDownL() {
259
                double ymax = 0;
260
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
261

    
262
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
263
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
264

    
265
                        if (fframe.getSelected() != 0) {
266
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
267
                                frameclone.getBoundBox().y = ymax -
268
                                        fframe.getBoundBox().height;
269
                                modifyFFrame(frameclone, i);
270
                        }
271
                }
272
        }
273

    
274
        /**
275
         * Desplaza los fframes seleccionados a la parte superior del fframe que
276
         * m?s arriba este colocado.
277
         */
278
        private void alignUp() {
279
                double ymin = Double.MAX_VALUE;
280

    
281
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
282
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
283

    
284
                        if (fframe.getSelected() != 0) {
285
                                if (ymin > fframe.getBoundBox().getMinY()) {
286
                                        ymin = fframe.getBoundBox().getMinY();
287
                                }
288
                        }
289
                }
290

    
291
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
292
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
293

    
294
                        if (fframe.getSelected() != 0) {
295
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
296
                                frameclone.getBoundBox().y = ymin;
297
                                modifyFFrame(frameclone, i);
298
                        }
299
                }
300
        }
301

    
302
        /**
303
         * Desplaza los fframes seleccionados a la parte superior del Layout.
304
         */
305
        private void alignUpL() {
306
                double ymin = 0;
307

    
308
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
309
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
310

    
311
                        if (fframe.getSelected() != 0) {
312
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
313
                                frameclone.getBoundBox().y = ymin;
314
                                modifyFFrame(frameclone, i);
315
                        }
316
                }
317
        }
318

    
319
        /**
320
         * Desplaza los fframes seleccionados al centro del fframe m?s alto
321
         * verticalmente.
322
         */
323
        private void alignCenterH() {
324
                double ycenter = 0;
325
                double h = Double.MIN_VALUE;
326

    
327
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
328
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
329

    
330
                        if (fframe.getSelected() != 0) {
331
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
332

    
333
                                if (h < fframe.getBoundBox().getHeight()) {
334
                                        h = fframe.getBoundBox().getHeight();
335
                                        ycenter = fframe.getBoundBox().getCenterY();
336
                                }
337
                        }
338
                }
339

    
340
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
341
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
342

    
343
                        if (fframe.getSelected() != 0) {
344
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
345
                                frameclone.getBoundBox().y = ycenter -
346
                                        (fframe.getBoundBox().height / 2);
347
                                modifyFFrame(frameclone, i);
348
                        }
349
                }
350
        }
351

    
352
        /**
353
         * Desplaza los fframes seleccionados en el Layout al centro verticalmente.
354
         */
355
        private void alignCenterHL() {
356
                double ycenter = 0;
357
                ycenter = m_layout.getAtributes().m_sizePaper.getAlto() / 2;
358

    
359
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
360
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
361

    
362
                        if (fframe.getSelected() != 0) {
363
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
364
                                frameclone.getBoundBox().y = ycenter -
365
                                        (fframe.getBoundBox().height / 2);
366
                                modifyFFrame(frameclone, i);
367
                        }
368
                }
369
        }
370

    
371
        /**
372
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
373
         * de izquierda a derecha.
374
         */
375
        private void distLeft() {
376
                double xmin = Double.MAX_VALUE;
377
                double xmax = Double.MIN_VALUE;
378
                int num = 0;
379

    
380
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
381
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
382

    
383
                        if (fframe.getSelected() != 0) {
384
                                if (xmin > fframe.getBoundBox().getMinX()) {
385
                                        xmin = fframe.getBoundBox().getMinX();
386
                                }
387

    
388
                                if (xmax < fframe.getBoundBox().getMaxX()) {
389
                                        xmax = fframe.getBoundBox().getMaxX();
390
                                }
391

    
392
                                num++;
393
                        }
394
                }
395

    
396
                double dif = xmax - xmin;
397
                double dist = dif / num;
398

    
399
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
400
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
401

    
402
                        if (fframe.getSelected() != 0) {
403
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
404
                                frameclone.getBoundBox().x = xmin + (dist * i);
405
                                modifyFFrame(frameclone, i);
406
                        }
407
                }
408
        }
409

    
410
        /**
411
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
412
         * y vertical, de izquierda a derecha.
413
         */
414
        private void distLeftL() {
415
                double xmin = 0;
416
                double xmax = 0;
417
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
418

    
419
                int num = 0;
420

    
421
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
422
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
423

    
424
                        if (fframe.getSelected() != 0) {
425
                                num++;
426
                        }
427
                }
428

    
429
                double dif = xmax - xmin;
430
                double dist = dif / num;
431

    
432
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
433
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
434

    
435
                        if (fframe.getSelected() != 0) {
436
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
437
                                frameclone.getBoundBox().x = xmin + (dist * i);
438
                                modifyFFrame(frameclone, i);
439
                        }
440
                }
441
        }
442

    
443
        /**
444
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
445
         * de derecha a izquierda.
446
         */
447
        private void distRight() {
448
                double xmin = Double.MAX_VALUE;
449
                double xmax = Double.MIN_VALUE;
450
                int num = 0;
451

    
452
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
453
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
454

    
455
                        if (fframe.getSelected() != 0) {
456
                                if (xmin > fframe.getBoundBox().getMinX()) {
457
                                        xmin = fframe.getBoundBox().getMinX();
458
                                }
459

    
460
                                if (xmax < fframe.getBoundBox().getMaxX()) {
461
                                        xmax = fframe.getBoundBox().getMaxX();
462
                                }
463

    
464
                                num++;
465
                        }
466
                }
467

    
468
                double dif = xmax - xmin;
469
                double dist = dif / num;
470

    
471
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
472
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
473

    
474
                        if (fframe.getSelected() != 0) {
475
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
476
                                frameclone.getBoundBox().x = xmax - (dist * i) -
477
                                        fframe.getBoundBox().width;
478
                                modifyFFrame(frameclone, i);
479
                        }
480
                }
481
        }
482

    
483
        /**
484
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
485
         * y vertical, de derecha a izquierda.
486
         */
487
        private void distRightL() {
488
                double xmin = 0;
489
                double xmax = 0;
490
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
491

    
492
                int num = 0;
493

    
494
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
495
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
496

    
497
                        if (fframe.getSelected() != 0) {
498
                                num++;
499
                        }
500
                }
501

    
502
                double dif = xmax - xmin;
503
                double dist = dif / num;
504

    
505
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
506
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
507

    
508
                        if (fframe.getSelected() != 0) {
509
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
510
                                frameclone.getBoundBox().x = xmax - (dist * i) -
511
                                        fframe.getBoundBox().width;
512
                                modifyFFrame(frameclone, i);
513
                        }
514
                }
515
        }
516

    
517
        /**
518
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
519
         * desde arriba hacia abajo.
520
         */
521
        private void distUp() {
522
                double ymin = Double.MAX_VALUE;
523
                double ymax = Double.MIN_VALUE;
524
                int num = 0;
525

    
526
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
527
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
528

    
529
                        if (fframe.getSelected() != 0) {
530
                                if (ymin > fframe.getBoundBox().getMinY()) {
531
                                        ymin = fframe.getBoundBox().getMinY();
532
                                }
533

    
534
                                if (ymax < fframe.getBoundBox().getMaxY()) {
535
                                        ymax = fframe.getBoundBox().getMaxY();
536
                                }
537

    
538
                                num++;
539
                        }
540
                }
541

    
542
                double dif = ymax - ymin;
543
                double dist = dif / num;
544

    
545
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
546
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
547

    
548
                        if (fframe.getSelected() != 0) {
549
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
550
                                frameclone.getBoundBox().y = ymin + (dist * i);
551
                                modifyFFrame(frameclone, i);
552
                        }
553
                }
554
        }
555

    
556
        /**
557
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
558
         * y vertical, desde arriba hacia abajo.
559
         */
560
        private void distUpL() {
561
                double ymin = 0;
562
                double ymax = 0;
563
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
564

    
565
                int num = 0;
566

    
567
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
568
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
569

    
570
                        if (fframe.getSelected() != 0) {
571
                                num++;
572
                        }
573
                }
574

    
575
                double dif = ymax - ymin;
576
                double dist = dif / num;
577

    
578
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
579
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
580

    
581
                        if (fframe.getSelected() != 0) {
582
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
583
                                frameclone.getBoundBox().y = ymin + (dist * i);
584
                                modifyFFrame(frameclone, i);
585
                        }
586
                }
587
        }
588

    
589
        /**
590
         * Distribuye los fframes seleccionados de forma equidistante y vertical,
591
         * desde bajo hacia arriba.
592
         */
593
        private void distDown() {
594
                double ymin = Double.MAX_VALUE;
595
                double ymax = Double.MIN_VALUE;
596
                int num = 0;
597

    
598
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
599
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
600

    
601
                        if (fframe.getSelected() != 0) {
602
                                if (ymin > fframe.getBoundBox().getMinY()) {
603
                                        ymin = fframe.getBoundBox().getMinY();
604
                                }
605

    
606
                                if (ymax < fframe.getBoundBox().getMaxY()) {
607
                                        ymax = fframe.getBoundBox().getMaxY();
608
                                }
609

    
610
                                num++;
611
                        }
612
                }
613

    
614
                double dif = ymax - ymin;
615
                double dist = dif / num;
616

    
617
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
618
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
619

    
620
                        if (fframe.getSelected() != 0) {
621
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
622
                                frameclone.getBoundBox().y = ymax - (dist * i) -
623
                                        fframe.getBoundBox().height;
624
                                modifyFFrame(frameclone, i);
625
                        }
626
                }
627
        }
628

    
629
        /**
630
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
631
         * y vertical, desde bajo hacia arriba.
632
         */
633
        private void distDownL() {
634
                double ymin = 0;
635
                double ymax = 0;
636
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
637

    
638
                int num = 0;
639

    
640
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
641
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
642

    
643
                        if (fframe.getSelected() != 0) {
644
                                num++;
645
                        }
646
                }
647

    
648
                double dif = ymax - ymin;
649
                double dist = dif / num;
650

    
651
                for (int i = m_layout.getAllFFrames().size() - 1; i >= 0; i--) {
652
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
653

    
654
                        if (fframe.getSelected() != 0) {
655
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
656
                                frameclone.getBoundBox().y = ymax - (dist * i) -
657
                                        fframe.getBoundBox().height;
658
                                modifyFFrame(frameclone, i);
659
                        }
660
                }
661
        }
662

    
663
        /**
664
         * Distribuye los fframes seleccionados de forma equidistante y vertical.
665
         */
666
        private void distCenterH() {
667
                double xmin = Double.MAX_VALUE;
668
                double xmax = Double.MIN_VALUE;
669
                int num = 0;
670

    
671
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
672
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
673

    
674
                        if (fframe.getSelected() != 0) {
675
                                if (xmin > fframe.getBoundBox().getMinX()) {
676
                                        xmin = fframe.getBoundBox().getMinX();
677
                                }
678

    
679
                                if (xmax < fframe.getBoundBox().getMaxX()) {
680
                                        xmax = fframe.getBoundBox().getMaxX();
681
                                }
682

    
683
                                num++;
684
                        }
685
                }
686

    
687
                double dif = xmax - xmin;
688
                double dist = dif / num;
689

    
690
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
691
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
692

    
693
                        if (fframe.getSelected() != 0) {
694
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
695
                                frameclone.getBoundBox().x = (xmin +
696
                                        (((dist) * (i + 1)) - (dist / 2))) -
697
                                        (fframe.getBoundBox().width / 2);
698
                                modifyFFrame(frameclone, i);
699
                        }
700
                }
701
        }
702

    
703
        /**
704
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
705
         * y vertical.
706
         */
707
        private void distCenterHL() {
708
                double xmin = 0;
709
                double xmax = 0;
710
                xmax = m_layout.getAtributes().m_sizePaper.getAncho();
711

    
712
                int num = 0;
713

    
714
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
715
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
716

    
717
                        if (fframe.getSelected() != 0) {
718
                                num++;
719
                        }
720
                }
721

    
722
                double dif = xmax - xmin;
723
                double dist = dif / num;
724

    
725
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
726
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
727

    
728
                        if (fframe.getSelected() != 0) {
729
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
730
                                frameclone.getBoundBox().x = (xmin +
731
                                        (((dist) * (i + 1)) - (dist / 2))) -
732
                                        (fframe.getBoundBox().width / 2);
733
                                modifyFFrame(frameclone, i);
734
                        }
735
                }
736
        }
737

    
738
        /**
739
         * Distribuye los fframes seleccionados de forma equidistante y horizontal.
740
         */
741
        private void distCenterV() {
742
                double ymin = Double.MAX_VALUE;
743
                double ymax = Double.MIN_VALUE;
744
                int num = 0;
745

    
746
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
747
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
748

    
749
                        if (fframe.getSelected() != 0) {
750
                                if (ymin > fframe.getBoundBox().getMinY()) {
751
                                        ymin = fframe.getBoundBox().getMinY();
752
                                }
753

    
754
                                if (ymax < fframe.getBoundBox().getMaxY()) {
755
                                        ymax = fframe.getBoundBox().getMaxY();
756
                                }
757

    
758
                                num++;
759
                        }
760
                }
761

    
762
                double dif = ymax - ymin;
763
                double dist = dif / num;
764

    
765
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
766
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
767

    
768
                        if (fframe.getSelected() != 0) {
769
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
770
                                frameclone.getBoundBox().y = (ymin +
771
                                        (((dist) * (i + 1)) - (dist / 2))) -
772
                                        (fframe.getBoundBox().height / 2);
773
                                modifyFFrame(frameclone, i);
774
                        }
775
                }
776
        }
777

    
778
        /**
779
         * Distribuye los fframes seleccionados en el Layout de forma equidistante
780
         * y horizontal.
781
         */
782
        private void distCenterVL() {
783
                double ymin = 0;
784
                double ymax = 0;
785
                ymax = m_layout.getAtributes().m_sizePaper.getAlto();
786

    
787
                int num = 0;
788

    
789
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
790
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
791

    
792
                        if (fframe.getSelected() != 0) {
793
                                num++;
794
                        }
795
                }
796

    
797
                double dif = ymax - ymin;
798
                double dist = dif / num;
799

    
800
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
801
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
802

    
803
                        if (fframe.getSelected() != 0) {
804
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
805
                                frameclone.getBoundBox().y = (ymin +
806
                                        (((dist) * (i + 1)) - (dist / 2))) -
807
                                        (fframe.getBoundBox().height / 2);
808
                                modifyFFrame(frameclone, i);
809
                        }
810
                }
811
        }
812

    
813
        /**
814
         * Cambia la anchura de los fframes seleccionados por la anchura del m?s
815
         * ancho.
816
         */
817
        private void sizeWidth() {
818
                double wmax = Double.MIN_VALUE;
819

    
820
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
821
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
822

    
823
                        if (fframe.getSelected() != 0) {
824
                                if (wmax < fframe.getBoundBox().getWidth()) {
825
                                        wmax = fframe.getBoundBox().getWidth();
826
                                }
827
                        }
828
                }
829

    
830
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
831
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
832

    
833
                        if (fframe.getSelected() != 0) {
834
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
835
                                frameclone.getBoundBox().width = wmax;
836
                                modifyFFrame(frameclone, i);
837
                        }
838
                }
839
        }
840

    
841
        /**
842
         * Cambia la altura de los fframes seleccionados por la altura del mas
843
         * alto.
844
         */
845
        private void sizeHeight() {
846
                double hmax = Double.MIN_VALUE;
847

    
848
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
849
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
850

    
851
                        if (fframe.getSelected() != 0) {
852
                                if (hmax < fframe.getBoundBox().getHeight()) {
853
                                        hmax = fframe.getBoundBox().getHeight();
854
                                }
855
                        }
856
                }
857

    
858
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
859
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
860

    
861
                        if (fframe.getSelected() != 0) {
862
                                IFFrame frameclone = fframe.cloneFFrame(m_layout);
863
                                frameclone.getBoundBox().height = hmax;
864
                                modifyFFrame(frameclone, i);
865
                        }
866
                }
867
        }
868

    
869
        /**
870
         * Distribuye horizontalmente los fframes dejando como espacio entre ellos
871
         * la media de todos los espacios.
872
         */
873
        private void spaceRight() {
874
                double total = 0;
875
                double num = 0;
876
                double xmin = Double.MAX_VALUE;
877
                double xmax = Double.MIN_VALUE;
878

    
879
                TreeMap treemap = new TreeMap();
880

    
881
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
882
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
883

    
884
                        if (fframe.getSelected() != 0) {
885
                                treemap.put((Object) new Double(fframe.getBoundBox().getMinX()),
886
                                        (Object) fframe);
887
                                num++;
888
                        }
889
                }
890

    
891
                Iterator j = treemap.keySet().iterator();
892

    
893
                if (j.hasNext()) {
894
                        IFFrame fframeA = (IFFrame) treemap.get(j.next());
895
                        IFFrame fframeS = null;
896
                        xmin = fframeA.getBoundBox().x;
897

    
898
                        while (j.hasNext()) {
899
                                fframeS = (IFFrame) treemap.get(j.next());
900
                                total += (fframeS.getBoundBox().getMinX() -
901
                                fframeA.getBoundBox().getMaxX());
902
                                fframeA = fframeS;
903
                        }
904

    
905
                        if (fframeS != null) {
906
                                xmax = fframeS.getBoundBox().getMaxX();
907
                        }
908
                }
909

    
910
                if (inLayout) {
911
                        total += (xmin +
912
                        (m_layout.getAtributes().m_sizePaper.getAncho() - xmax));
913
                        num += 2;
914
                }
915

    
916
                double dist = total / (num - 1);
917
                Iterator k = treemap.keySet().iterator();
918

    
919
                if (k.hasNext()) {
920
                        IFFrame fframeA = (IFFrame) treemap.get(k.next());
921
                        IFFrame frameclone = fframeA.cloneFFrame(m_layout);
922

    
923
                        if (inLayout) {
924
                                frameclone.getBoundBox().x = dist;
925
                                modifyFFrame(frameclone,
926
                                        m_layout.getAllFFrames().indexOf(fframeA));
927
                        }
928

    
929
                        while (k.hasNext()) {
930
                                IFFrame fframeS = (IFFrame) treemap.get(k.next());
931
                                fframeS.getBoundBox().x = fframeA.getBoundBox().getMaxX() +
932
                                        dist;
933
                                frameclone = fframeS;
934
                                modifyFFrame(frameclone,
935
                                        m_layout.getAllFFrames().indexOf(fframeA));
936

    
937
                                //fframeA = fframeS;
938
                        }
939
                }
940
        }
941

    
942
        /**
943
         * Distribuye verticalmente los fframes dejando como espacio entre ellos la
944
         * media de todos los espacios.
945
         */
946
        private void spaceDown() {
947
                double total = 0;
948
                double num = 0;
949
                double ymin = Double.MAX_VALUE;
950
                double ymax = Double.MIN_VALUE;
951

    
952
                TreeMap treemap = new TreeMap();
953

    
954
                for (int i = 0; i < m_layout.getAllFFrames().size(); i++) {
955
                        IFFrame fframe = (IFFrame) m_layout.getAllFFrames().get(i);
956

    
957
                        if (fframe.getSelected() != 0) {
958
                                treemap.put((Object) new Double(fframe.getBoundBox().getMinY()),
959
                                        (Object) fframe);
960
                                num++;
961
                        }
962
                }
963

    
964
                Iterator j = treemap.keySet().iterator();
965

    
966
                if (j.hasNext()) {
967
                        IFFrame fframeA = (IFFrame) treemap.get(j.next());
968
                        ymin = fframeA.getBoundBox().y;
969

    
970
                        IFFrame fframeS = null;
971

    
972
                        while (j.hasNext()) {
973
                                fframeS = (IFFrame) treemap.get(j.next());
974
                                total += (fframeS.getBoundBox().getMinY() -
975
                                fframeA.getBoundBox().getMaxY());
976
                                fframeA = fframeS;
977
                        }
978

    
979
                        if (fframeS != null) {
980
                                ymax = fframeS.getBoundBox().getMaxY();
981
                        }
982
                }
983

    
984
                if (inLayout) {
985
                        total += (ymin +
986
                        (m_layout.getAtributes().m_sizePaper.getAlto() - ymax));
987
                        num += 2;
988
                }
989

    
990
                double dist = total / (num - 1);
991
                Iterator k = treemap.keySet().iterator();
992

    
993
                if (k.hasNext()) {
994
                        IFFrame fframeA = (IFFrame) treemap.get(k.next());
995

    
996
                        if (inLayout) {
997
                                IFFrame frameclone = fframeA.cloneFFrame(m_layout);
998
                                frameclone.getBoundBox().y = dist;
999
                                modifyFFrame(frameclone,
1000
                                        m_layout.getAllFFrames().indexOf(fframeA));
1001
                        }
1002

    
1003
                        while (k.hasNext()) {
1004
                                IFFrame fframeS = (IFFrame) treemap.get(k.next());
1005
                                fframeS.getBoundBox().y = fframeA.getBoundBox().getMaxY() +
1006
                                        dist;
1007
                                fframeA = fframeS;
1008
                        }
1009
                }
1010
        }
1011

    
1012
        //  class Listener implements ActionListener {
1013

    
1014
        /**
1015
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1016
         */
1017
        public void actionPerformed(ActionEvent e) {
1018
                startComplex();
1019

    
1020
                if (!inLayout) {
1021
                        if (e.getActionCommand() == "LEFT") {
1022
                                alignLeft();
1023
                        } else if (e.getActionCommand() == "CENTERV") {
1024
                                alignCenterV();
1025
                        } else if (e.getActionCommand() == "RIGHT") {
1026
                                alignRight();
1027
                        } else if (e.getActionCommand() == "UP") {
1028
                                alignUp();
1029
                        } else if (e.getActionCommand() == "CENTERH") {
1030
                                alignCenterH();
1031
                        } else if (e.getActionCommand() == "DOWN") {
1032
                                alignDown();
1033
                        } else if (e.getActionCommand() == "DISTUP") {
1034
                                distUp();
1035
                        } else if (e.getActionCommand() == "DISTCENTERV") {
1036
                                distCenterV();
1037
                        } else if (e.getActionCommand() == "DISTDOWN") {
1038
                                distDown();
1039
                        } else if (e.getActionCommand() == "DISTLEFT") {
1040
                                distLeft();
1041
                        } else if (e.getActionCommand() == "DISTCENTERH") {
1042
                                distCenterH();
1043
                        } else if (e.getActionCommand() == "DISTRIGHT") {
1044
                                distRight();
1045
                        } else if (e.getActionCommand() == "SIZECENTERV") {
1046
                                sizeWidth();
1047
                        } else if (e.getActionCommand() == "SIZECENTERH") {
1048
                                sizeHeight();
1049
                        } else if (e.getActionCommand() == "SIZEOTHER") {
1050
                                sizeWidth();
1051
                                sizeHeight();
1052
                        } else if (e.getActionCommand() == "SPACERIGHT") {
1053
                                spaceRight();
1054
                        } else if (e.getActionCommand() == "SPACEDOWN") {
1055
                                spaceDown();
1056
                        } else if (e.getActionCommand() == "INLAYOUT") {
1057
                                inLayout = true;
1058
                        }
1059
                } else {
1060
                        if (e.getActionCommand() == "LEFT") {
1061
                                alignLeftL();
1062
                        } else if (e.getActionCommand() == "CENTERV") {
1063
                                alignCenterVL();
1064
                        } else if (e.getActionCommand() == "RIGHT") {
1065
                                alignRightL();
1066
                        } else if (e.getActionCommand() == "UP") {
1067
                                alignUpL();
1068
                        } else if (e.getActionCommand() == "CENTERH") {
1069
                                alignCenterHL();
1070
                        } else if (e.getActionCommand() == "DOWN") {
1071
                                alignDownL();
1072
                        } else if (e.getActionCommand() == "DISTUP") {
1073
                                distUpL();
1074
                        } else if (e.getActionCommand() == "DISTCENTERV") {
1075
                                distCenterVL();
1076
                        } else if (e.getActionCommand() == "DISTDOWN") {
1077
                                distDownL();
1078
                        } else if (e.getActionCommand() == "DISTLEFT") {
1079
                                distLeftL();
1080
                        } else if (e.getActionCommand() == "DISTCENTERH") {
1081
                                distCenterHL();
1082
                        } else if (e.getActionCommand() == "DISTRIGHT") {
1083
                                distRightL();
1084
                        } else if (e.getActionCommand() == "SIZECENTERV") {
1085
                                sizeWidth();
1086
                        } else if (e.getActionCommand() == "SIZECENTERH") {
1087
                                sizeHeight();
1088
                        } else if (e.getActionCommand() == "SIZEOTHER") {
1089
                                sizeWidth();
1090
                                sizeHeight();
1091
                        } else if (e.getActionCommand() == "SPACERIGHT") {
1092
                                spaceRight();
1093
                        } else if (e.getActionCommand() == "SPACEDOWN") {
1094
                                spaceDown();
1095
                        } else if (e.getActionCommand() == "INLAYOUT") {
1096
                                inLayout = false;
1097
                        }
1098
                }
1099

    
1100
                endComplex();
1101
                m_layout.refresh();
1102
        }
1103

    
1104
        /**
1105
         * Comienza la edici?n compleja para que todas las operaciones de edici?n
1106
         * desde esta instrucci?n hasta el endComplex() se pueda deshacer y
1107
         * rehacer todo junto.
1108
         */
1109
        private void startComplex() {
1110
                ((LayoutEditableFeature) m_layout.getCadToolAdapter()
1111
                                                                                 .getEditableFeatureSource()).startComplexGeometry();
1112
        }
1113

    
1114
        /**
1115
         * Finaliza la edici?n compleja para almacenar todos los comandos
1116
         */
1117
        private void endComplex() {
1118
                try {
1119
                        ((LayoutEditableFeature) m_layout.getCadToolAdapter()
1120
                                                                                         .getEditableFeatureSource()).endComplexGeometry();
1121
                } catch (IOException e) {
1122
                        e.printStackTrace();
1123
                } catch (DriverIOException e) {
1124
                        e.printStackTrace();
1125
                }
1126
        }
1127

    
1128
        /**
1129
         * Modifica el FFrame a partir del ?ndice y el fframe que se pasa como
1130
         * par?metro.
1131
         *
1132
         * @param frame FFrame a insertar.
1133
         * @param index ?ndice del fframe a modificar.
1134
         */
1135
        private void modifyFFrame(IFFrame frame, int index) {
1136
                try {
1137
                        ((LayoutEditableFeature) m_layout.getCadToolAdapter()
1138
                                                                                         .getEditableFeatureSource()).modifyFFrame(frame,
1139
                                index);
1140
                } catch (IOException e) {
1141
                        e.printStackTrace();
1142
                } catch (DriverIOException e) {
1143
                        e.printStackTrace();
1144
                }
1145
        }
1146
}