Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / gui / dialogs / EventsFAlign.java @ 24962

History | View | Annotate | Download (39.7 KB)

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

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

    
53
import com.iver.andami.PluginServices;
54
import com.iver.cit.gvsig.project.documents.layout.commands.FrameCommandsRecord;
55
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
56
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
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.getLayoutContext().getFFrameSelected();
84

    
85
        for (int i = 0; i < fframes.length; i++) {
86
            IFFrame fframe = fframes[i];
87

    
88
            if (xmin > fframe.getBoundBox().getMinX()) {
89
                xmin = fframe.getBoundBox().getMinX();
90
            }
91
        }
92

    
93
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
94
        efs.startComplex(PluginServices.getText(this, "align_left"));
95

    
96
        for (int i = fframes.length - 1; i >= 0; i--) {
97
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
98

    
99
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
100
                                                              .clone();
101
            r.x = xmin;
102
            fframe.setBoundBox(r);
103
            efs.update(fframes[i], fframe);
104
        }
105

    
106
        efs.endComplex();
107
    }
108

    
109
    /**
110
     * Desplaza los fframes seleccionados a la izquierda del Layout.
111
     */
112
    private void alignLeftL() {
113
        double xmin = 0;
114
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
115
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
116
        efs.startComplex(PluginServices.getText(this,"align_to_layout_left"));
117

    
118
        for (int i = 0; i < fframes.length; i++) {
119
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
120

    
121
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
122
                                                              .clone();
123
            r.x = xmin;
124
            fframe.setBoundBox(r);
125
            efs.update(fframes[i], fframe);
126
        }
127

    
128
        efs.endComplex();
129
    }
130

    
131
    /**
132
     * Desplaza los fframes seleccionados al centro del fframe mas ancho de
133
     * forma horizontal.
134
     */
135
    private void alignCenterV() {
136
        double xcenter = 0;
137
        double w = Double.NEGATIVE_INFINITY;
138
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
139

    
140
        for (int i = 0; i < fframes.length; i++) {
141
            IFFrame fframe = fframes[i];
142

    
143
            if (w < fframe.getBoundBox().getWidth()) {
144
                w = fframe.getBoundBox().getWidth();
145
                xcenter = fframe.getBoundBox().getCenterX();
146
            }
147
        }
148

    
149
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
150
        efs.startComplex(PluginServices.getText(this, "align_center"));
151

    
152
        for (int i = 0; i < fframes.length; i++) {
153
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
154

    
155
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
156
                                                              .clone();
157
            r.x = xcenter - (fframe.getBoundBox().width / 2);
158
            fframe.setBoundBox(r);
159
            efs.update(fframes[i], fframe);
160
        }
161

    
162
        efs.endComplex();
163
    }
164

    
165
    /**
166
     * Desplaza los fframes seleccionados al centro del Layout horizontalmente.
167
     */
168
    private void alignCenterVL() {
169
        double xcenter = 0;
170
        xcenter = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAncho() / 2;
171

    
172
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
173
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
174
        efs.startComplex(PluginServices.getText(this,"align_to_layout_center"));
175

    
176
        for (int i = 0; i < fframes.length; i++) {
177
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
178

    
179
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
180
                                                              .clone();
181
            r.x = xcenter - (fframe.getBoundBox().width / 2);
182
            fframe.setBoundBox(r);
183
            efs.update(fframes[i], fframe);
184
        }
185

    
186
        efs.endComplex();
187
    }
188

    
189
    /**
190
     * Desplaza los fframes seleccionados a la parte derecha del fframe m?s
191
     * oriental.
192
     */
193
    private void alignRight() {
194
        double xmax = Double.NEGATIVE_INFINITY;
195
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
196

    
197
        for (int i = 0; i < fframes.length; i++) {
198
            IFFrame fframe = fframes[i];
199

    
200
            if (xmax < fframe.getBoundBox().getMaxX()) {
201
                xmax = fframe.getBoundBox().getMaxX();
202
            }
203
        }
204

    
205
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
206
        efs.startComplex(PluginServices.getText(this, "align_right"));
207

    
208
        for (int i = 0; i < fframes.length; i++) {
209
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
210

    
211
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
212
                                                              .clone();
213
            r.x = xmax - fframes[i].getBoundBox().width;
214
            fframe.setBoundBox(r);
215
            efs.update(fframes[i], fframe);
216
        }
217

    
218
        efs.endComplex();
219
    }
220

    
221
    /**
222
     * Desplaza los fframes seleccionados a la parte derecha del Layout.
223
     */
224
    private void alignRightL() {
225
        double xmax = 0;
226
        xmax = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAncho();
227

    
228
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
229
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
230
        efs.startComplex(PluginServices.getText(this, "align_to_layout_right"));
231

    
232
        for (int i = 0; i < fframes.length; i++) {
233
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
234

    
235
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
236
                                                              .clone();
237
            r.x = xmax - fframes[i].getBoundBox().width;
238
            fframe.setBoundBox(r);
239
            efs.update(fframes[i], fframe);
240
        }
241

    
242
        efs.endComplex();
243
    }
244

    
245
    /**
246
     * Desplaza los fframes seleccionados a la parte inferior del fframe m?s
247
     * hacia abajo.
248
     */
249
    private void alignDown() {
250
        double ymax = Double.NEGATIVE_INFINITY;
251
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
252

    
253
        for (int i = 0; i < fframes.length; i++) {
254
            IFFrame fframe = fframes[i];
255

    
256
            if (ymax < fframe.getBoundBox().getMaxY()) {
257
                ymax = fframe.getBoundBox().getMaxY();
258
            }
259
        }
260

    
261
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
262
        efs.startComplex(PluginServices.getText(this, "align_down"));
263

    
264
        for (int i = 0; i < fframes.length; i++) {
265
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
266

    
267
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
268
                                                              .clone();
269
            r.y = ymax - fframe.getBoundBox().height;
270
            fframe.setBoundBox(r);
271
            efs.update(fframes[i], fframe);
272
        }
273

    
274
        efs.endComplex();
275
    }
276

    
277
    /**
278
     * Desplaza los fframes seleccionados a la parte inferior del Layout.
279
     */
280
    private void alignDownL() {
281
        double ymax = 0;
282
        ymax = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAlto();
283

    
284
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
285
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
286
        efs.startComplex(PluginServices.getText(this, "align_to_layout_down"));
287

    
288
        for (int i = 0; i < fframes.length; i++) {
289
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
290
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
291
                                                              .clone();
292
            r.y = ymax - fframe.getBoundBox().height;
293
            fframe.setBoundBox(r);
294
            efs.update(fframes[i], fframe);
295
        }
296

    
297
        efs.endComplex();
298
    }
299

    
300
    /**
301
     * Desplaza los fframes seleccionados a la parte superior del fframe que
302
     * m?s arriba este colocado.
303
     */
304
    private void alignUp() {
305
        double ymin = Double.MAX_VALUE;
306
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
307

    
308
        for (int i = 0; i < fframes.length; i++) {
309
            IFFrame fframe = fframes[i];
310

    
311
            if (ymin > fframe.getBoundBox().getMinY()) {
312
                ymin = fframe.getBoundBox().getMinY();
313
            }
314
        }
315

    
316
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
317
        efs.startComplex(PluginServices.getText(this, "align_up"));
318

    
319
        for (int i = 0; i < fframes.length; i++) {
320
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
321
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
322
                                                              .clone();
323
            r.y = ymin;
324
            fframe.setBoundBox(r);
325
            efs.update(fframes[i], fframe);
326
        }
327

    
328
        efs.endComplex();
329
    }
330

    
331
    /**
332
     * Desplaza los fframes seleccionados a la parte superior del Layout.
333
     */
334
    private void alignUpL() {
335
        double ymin = 0;
336
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
337
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
338
        efs.startComplex(PluginServices.getText(this, "align_to_layout_up"));
339

    
340
        for (int i = 0; i < fframes.length; i++) {
341
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
342
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
343
                                                              .clone();
344
            r.y = ymin;
345
            fframe.setBoundBox(r);
346
            efs.update(fframes[i], fframe);
347
        }
348

    
349
        efs.endComplex();
350
    }
351

    
352
    /**
353
     * Desplaza los fframes seleccionados al centro del fframe m?s alto
354
     * verticalmente.
355
     */
356
    private void alignCenterH() {
357
        double ycenter = 0;
358
        double h = Double.NEGATIVE_INFINITY;
359
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
360

    
361
        for (int i = 0; i < fframes.length; i++) {
362
            IFFrame fframe = fframes[i];
363

    
364
            if (h < fframe.getBoundBox().getHeight()) {
365
                h = fframe.getBoundBox().getHeight();
366
                ycenter = fframe.getBoundBox().getCenterY();
367
            }
368
        }
369

    
370
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
371
        efs.startComplex(PluginServices.getText(this, "align_vertical_center"));
372

    
373
        for (int i = 0; i < fframes.length; i++) {
374
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
375
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
376
                                                              .clone();
377
            r.y = ycenter - (fframe.getBoundBox().height / 2);
378
            fframe.setBoundBox(r);
379
            efs.update(fframes[i], fframe);
380
        }
381

    
382
        efs.endComplex();
383
    }
384

    
385
    /**
386
     * Desplaza los fframes seleccionados en el Layout al centro verticalmente.
387
     */
388
    private void alignCenterHL() {
389
        double ycenter = 0;
390
        ycenter = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAlto() / 2;
391

    
392
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
393
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
394
        efs.startComplex(PluginServices.getText(this, "align_to_layout_vertical_center"));
395

    
396
        for (int i = 0; i < fframes.length; i++) {
397
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
398
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
399
                                                              .clone();
400
            r.y = ycenter - (fframe.getBoundBox().height / 2);
401
            fframe.setBoundBox(r);
402
            efs.update(fframes[i], fframe);
403
        }
404

    
405
        efs.endComplex();
406
    }
407

    
408
    /**
409
     * Distribuye los fframes seleccionados de forma equidistante y vertical,
410
     * de izquierda a derecha.
411
     */
412
    private void distLeft() {
413
        double xmin = Double.MAX_VALUE;
414
        double xmax = Double.NEGATIVE_INFINITY;
415
        int num = 0;
416
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
417
        num = fframes.length;
418

    
419
        for (int i = 0; i < num; i++) {
420
            IFFrame fframe = fframes[i];
421

    
422
            if (xmin > fframe.getBoundBox().getMinX()) {
423
                xmin = fframe.getBoundBox().getMinX();
424
            }
425

    
426
            if (xmax < fframe.getBoundBox().getMaxX()) {
427
                xmax = fframe.getBoundBox().getMaxX();
428
            }
429
        }
430

    
431
        double dif = xmax - xmin;
432
        double dist = dif / num;
433
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
434
        efs.startComplex(PluginServices.getText(this, "distributes_left"));
435

    
436
        for (int i = 0; i < fframes.length; i++) {
437
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
438
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
439
                                                              .clone();
440
            r.x = xmin + (dist * i);
441
            fframe.setBoundBox(r);
442
            efs.update(fframes[i], fframe);
443
        }
444

    
445
        efs.endComplex();
446
    }
447

    
448
    /**
449
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
450
     * y vertical, de izquierda a derecha.
451
     */
452
    private void distLeftL() {
453
        double xmin = 0;
454
        double xmax = 0;
455
        xmax = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAncho();
456

    
457
        int num = 0;
458
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
459
        num = fframes.length;
460

    
461
        double dif = xmax - xmin;
462
        double dist = dif / num;
463
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
464
        efs.startComplex(PluginServices.getText(this, "distributes_to_layout_left"));
465

    
466
        for (int i = 0; i < fframes.length; i++) {
467
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
468
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
469
                                                              .clone();
470
            r.x = xmin + (dist * i);
471
            fframe.setBoundBox(r);
472
            efs.update(fframes[i], fframe);
473
        }
474

    
475
        efs.endComplex();
476
    }
477

    
478
    /**
479
     * Distribuye los fframes seleccionados de forma equidistante y vertical,
480
     * de derecha a izquierda.
481
     */
482
    private void distRight() {
483
        double xmin = Double.MAX_VALUE;
484
        double xmax = Double.NEGATIVE_INFINITY;
485
        int num = 0;
486
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
487
        num = fframes.length;
488

    
489
        for (int i = 0; i < num; i++) {
490
            IFFrame fframe = fframes[i];
491

    
492
            if (xmin > fframe.getBoundBox().getMinX()) {
493
                xmin = fframe.getBoundBox().getMinX();
494
            }
495

    
496
            if (xmax < fframe.getBoundBox().getMaxX()) {
497
                xmax = fframe.getBoundBox().getMaxX();
498
            }
499
        }
500

    
501
        double dif = xmax - xmin;
502
        double dist = dif / num;
503
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
504
        efs.startComplex(PluginServices.getText(this, "distributes_right"));
505

    
506
        for (int i = 0; i < fframes.length; i++) {
507
            IFFrame fframe = fframes[i];
508
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
509
                                                              .clone();
510
            r.x = xmax - (dist * i) - fframe.getBoundBox().width;
511
            fframe.setBoundBox(r);
512
            efs.update(fframes[i], fframe);
513
        }
514

    
515
        efs.endComplex();
516
    }
517

    
518
    /**
519
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
520
     * y vertical, de derecha a izquierda.
521
     */
522
    private void distRightL() {
523
        double xmin = 0;
524
        double xmax = 0;
525
        xmax = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAncho();
526

    
527
        int num = 0;
528
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
529
        num = fframes.length;
530

    
531
        double dif = xmax - xmin;
532
        double dist = dif / num;
533
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
534
        efs.startComplex(PluginServices.getText(this, "distributes_to_layout_right"));
535

    
536
        for (int i = 0; i < fframes.length; i++) {
537
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
538
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
539
                                                              .clone();
540
            r.x = xmax - (dist * i) - fframe.getBoundBox().width;
541
            fframe.setBoundBox(r);
542
            efs.update(fframes[i], fframe);
543
        }
544

    
545
        efs.endComplex();
546
    }
547

    
548
    /**
549
     * Distribuye los fframes seleccionados de forma equidistante y vertical,
550
     * desde arriba hacia abajo.
551
     */
552
    private void distUp() {
553
        double ymin = Double.MAX_VALUE;
554
        double ymax = Double.NEGATIVE_INFINITY;
555
        int num = 0;
556
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
557
        num = fframes.length;
558

    
559
        for (int i = 0; i < num; i++) {
560
            IFFrame fframe = fframes[i];
561

    
562
            if (ymin > fframe.getBoundBox().getMinY()) {
563
                ymin = fframe.getBoundBox().getMinY();
564
            }
565

    
566
            if (ymax < fframe.getBoundBox().getMaxY()) {
567
                ymax = fframe.getBoundBox().getMaxY();
568
            }
569
        }
570

    
571
        double dif = ymax - ymin;
572
        double dist = dif / num;
573
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
574
        efs.startComplex(PluginServices.getText(this, "distributes_up"));
575

    
576
        for (int i = 0; i < fframes.length; i++) {
577
            IFFrame fframe = fframes[i];
578
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
579
                                                              .clone();
580
            r.y = ymin + (dist * i);
581
            fframe.setBoundBox(r);
582
            efs.update(fframes[i], fframe);
583
        }
584

    
585
        efs.endComplex();
586
    }
587

    
588
    /**
589
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
590
     * y vertical, desde arriba hacia abajo.
591
     */
592
    private void distUpL() {
593
        double ymin = 0;
594
        double ymax = 0;
595
        ymax = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAlto();
596

    
597
        int num = 0;
598
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
599

    
600
        num = fframes.length;
601

    
602
        double dif = ymax - ymin;
603
        double dist = dif / num;
604
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
605
        efs.startComplex(PluginServices.getText(this, "distributes_to_layout_up"));
606

    
607
        for (int i = 0; i < fframes.length; i++) {
608
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
609
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
610
                                                              .clone();
611
            r.y = ymin + (dist * i);
612
            fframe.setBoundBox(r);
613
            efs.update(fframes[i], fframe);
614
        }
615

    
616
        efs.endComplex();
617
    }
618

    
619
    /**
620
     * Distribuye los fframes seleccionados de forma equidistante y vertical,
621
     * desde bajo hacia arriba.
622
     */
623
    private void distDown() {
624
        double ymin = Double.MAX_VALUE;
625
        double ymax = Double.NEGATIVE_INFINITY;
626
        int num = 0;
627
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
628
        num = fframes.length;
629

    
630
        for (int i = 0; i < num; i++) {
631
            IFFrame fframe = fframes[i];
632

    
633
            if (ymin > fframe.getBoundBox().getMinY()) {
634
                ymin = fframe.getBoundBox().getMinY();
635
            }
636

    
637
            if (ymax < fframe.getBoundBox().getMaxY()) {
638
                ymax = fframe.getBoundBox().getMaxY();
639
            }
640
        }
641

    
642
        double dif = ymax - ymin;
643
        double dist = dif / num;
644
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
645
        efs.startComplex(PluginServices.getText(this, "distributes_down"));
646

    
647
        for (int i = 0; i < fframes.length; i++) {
648
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
649
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
650
                                                              .clone();
651
            r.y = ymax - (dist * i) - fframe.getBoundBox().height;
652
            fframe.setBoundBox(r);
653
            efs.update(fframes[i], fframe);
654
        }
655

    
656
        efs.endComplex();
657
    }
658

    
659
    /**
660
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
661
     * y vertical, desde bajo hacia arriba.
662
     */
663
    private void distDownL() {
664
        double ymin = 0;
665
        double ymax = 0;
666
        ymax = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAlto();
667

    
668
        int num = 0;
669
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
670

    
671
        num = fframes.length;
672

    
673
        double dif = ymax - ymin;
674
        double dist = dif / num;
675
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
676
        efs.startComplex(PluginServices.getText(this, "distributes_to_layout_down"));
677

    
678
        for (int i = fframes.length - 1; i >= 0; i--) {
679
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
680
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
681
                                                              .clone();
682
            r.y = ymax - (dist * i) - fframe.getBoundBox().height;
683
            fframe.setBoundBox(r);
684
            efs.update(fframes[i], fframe);
685
        }
686

    
687
        efs.endComplex();
688
    }
689

    
690
    /**
691
     * Distribuye los fframes seleccionados de forma equidistante y vertical.
692
     */
693
    private void distCenterH() {
694
        double xmin = Double.MAX_VALUE;
695
        double xmax = Double.NEGATIVE_INFINITY;
696
        int num = 0;
697
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
698
        num = fframes.length;
699

    
700
        for (int i = 0; i < num; i++) {
701
            IFFrame fframe = fframes[i];
702

    
703
            if (xmin > fframe.getBoundBox().getMinX()) {
704
                xmin = fframe.getBoundBox().getMinX();
705
            }
706

    
707
            if (xmax < fframe.getBoundBox().getMaxX()) {
708
                xmax = fframe.getBoundBox().getMaxX();
709
            }
710
        }
711

    
712
        double dif = xmax - xmin;
713
        double dist = dif / num;
714
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
715
        efs.startComplex(PluginServices.getText(this, "distributes_vertical"));
716

    
717
        for (int i = 0; i < fframes.length; i++) {
718
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
719
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
720
                                                              .clone();
721
            r.x = (xmin + (((dist) * (i + 1)) - (dist / 2))) -
722
                (fframe.getBoundBox().width / 2);
723
            fframe.setBoundBox(r);
724
            efs.update(fframes[i], fframe);
725
        }
726

    
727
        efs.endComplex();
728
    }
729

    
730
    /**
731
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
732
     * y vertical.
733
     */
734
    private void distCenterHL() {
735
        double xmin = 0;
736
        double xmax = 0;
737
        xmax = m_layout.getLayoutContext().getAttributes().m_sizePaper.getAncho();
738

    
739
        int num = 0;
740
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
741
        num = fframes.length;
742

    
743
        double dif = xmax - xmin;
744
        double dist = dif / num;
745
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
746
        efs.startComplex(PluginServices.getText(this, "distributes_to_layout_vertical"));
747

    
748
        for (int i = 0; i < fframes.length; i++) {
749
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
750
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
751
                                                              .clone();
752
            r.x = (xmin + (((dist) * (i + 1)) - (dist / 2))) -
753
                (fframe.getBoundBox().width / 2);
754
            fframe.setBoundBox(r);
755
            efs.update(fframes[i], fframe);
756
        }
757

    
758
        efs.endComplex();
759
    }
760

    
761
    /**
762
     * Distribuye los fframes seleccionados de forma equidistante y horizontal.
763
     */
764
    private void distCenterV() {
765
        double ymin = Double.MAX_VALUE;
766
        double ymax = Double.NEGATIVE_INFINITY;
767
        int num = 0;
768
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
769
        num = fframes.length;
770

    
771
        for (int i = 0; i < num; i++) {
772
            IFFrame fframe = fframes[i];
773

    
774
            if (ymin > fframe.getBoundBox().getMinY()) {
775
                ymin = fframe.getBoundBox().getMinY();
776
            }
777

    
778
            if (ymax < fframe.getBoundBox().getMaxY()) {
779
                ymax = fframe.getBoundBox().getMaxY();
780
            }
781
        }
782

    
783
        double dif = ymax - ymin;
784
        double dist = dif / num;
785
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
786
        efs.startComplex(PluginServices.getText(this, "distributes_horizontal"));
787

    
788
        for (int i = 0; i < fframes.length; i++) {
789
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
790
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
791
                                                              .clone();
792
            r.y = (ymin + (((dist) * (i + 1)) - (dist / 2))) -
793
                (fframe.getBoundBox().height / 2);
794
            fframe.setBoundBox(r);
795
            efs.update(fframes[i], fframe);
796
        }
797

    
798
        efs.endComplex();
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.getLayoutContext().getAttributes().m_sizePaper.getAlto();
809

    
810
        int num = 0;
811
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
812
        num = fframes.length;
813

    
814
        double dif = ymax - ymin;
815
        double dist = dif / num;
816
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
817
        efs.startComplex(PluginServices.getText(this, "distributes_to_layout_horizontal"));
818

    
819
        for (int i = 0; i < fframes.length; i++) {
820
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
821
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
822
                                                              .clone();
823
            r.y = (ymin + (((dist) * (i + 1)) - (dist / 2))) -
824
                (fframe.getBoundBox().height / 2);
825
            fframe.setBoundBox(r);
826
            efs.update(fframes[i], fframe);
827
        }
828

    
829
        efs.endComplex();
830
    }
831

    
832
    /**
833
     * Cambia la anchura de los fframes seleccionados por la anchura del m?s
834
     * ancho.
835
     */
836
    private void sizeWidth() {
837
        double wmax = Double.NEGATIVE_INFINITY;
838
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
839

    
840
        for (int i = 0; i < fframes.length; i++) {
841
            IFFrame fframe = fframes[i];
842

    
843
            if (wmax < fframe.getBoundBox().getWidth()) {
844
                wmax = fframe.getBoundBox().getWidth();
845
            }
846
        }
847

    
848
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
849
        efs.startComplex(PluginServices.getText(this, "change_width"));
850

    
851
        for (int i = 0; i < fframes.length; i++) {
852
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
853
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
854
                                                              .clone();
855
            r.width = wmax;
856
            fframe.setBoundBox(r);
857
            efs.update(fframes[i], fframe);
858
        }
859

    
860
        efs.endComplex();
861
    }
862

    
863
    /**
864
     * Cambia la altura de los fframes seleccionados por la altura del mas
865
     * alto.
866
     */
867
    private void sizeHeight() {
868
        double hmax = Double.NEGATIVE_INFINITY;
869
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
870

    
871
        for (int i = 0; i < fframes.length; i++) {
872
            IFFrame fframe = fframes[i];
873

    
874
            if (hmax < fframe.getBoundBox().getHeight()) {
875
                hmax = fframe.getBoundBox().getHeight();
876
            }
877
        }
878

    
879
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
880
        efs.startComplex(PluginServices.getText(this, "change_height"));
881

    
882
        for (int i = 0; i < fframes.length; i++) {
883
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
884
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
885
                                                              .clone();
886
            r.height = hmax;
887
            fframe.setBoundBox(r);
888
            efs.update(fframes[i], fframe);
889
        }
890

    
891
        efs.endComplex();
892
    }
893

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

    
904
        TreeMap treemap = new TreeMap();
905
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
906
        num = fframes.length;
907

    
908
        for (int i = 0; i < num; i++) {
909
            IFFrame fframe = fframes[i];
910
            treemap.put(new Double(fframe.getBoundBox().getMinX()), fframe);
911
        }
912

    
913
        Iterator j = treemap.keySet().iterator();
914

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

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

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

    
932
        if (inLayout) {
933
            total += (xmin +
934
            (m_layout.getLayoutContext().getAttributes().m_sizePaper.getAncho() - xmax));
935
            num += 2;
936
        }
937

    
938
        double dist = total / (num - 1);
939
        Iterator k = treemap.keySet().iterator();
940
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
941
        efs.startComplex(PluginServices.getText(this, "horizontal_space"));
942

    
943
        if (k.hasNext()) {
944
            IFFrame fframe = (IFFrame) treemap.get(k.next());
945
            IFFrame fframeA = fframe.cloneFFrame(m_layout);
946

    
947
            if (inLayout) {
948
                Rectangle2D.Double r = (Rectangle2D.Double) fframeA.getBoundBox()
949
                                                                   .clone();
950
                r.x = dist;
951
                fframeA.setBoundBox(r);
952
                efs.update(fframe, fframeA);
953
            }
954

    
955
            while (k.hasNext()) {
956
                IFFrame fframeAux = (IFFrame) treemap.get(k.next());
957
                IFFrame fframeS = fframeAux.cloneFFrame(m_layout);
958
                Rectangle2D.Double r = (Rectangle2D.Double) fframeS.getBoundBox()
959
                                                                   .clone();
960
                r.x = fframeA.getBoundBox().getMaxX() + dist;
961
                fframeS.setBoundBox(r);
962
                efs.update(fframeAux, fframeS);
963
                fframeA = fframeS;
964
            }
965
        }
966

    
967
        efs.endComplex();
968
    }
969

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

    
980
        TreeMap treemap = new TreeMap();
981
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
982
        num = fframes.length;
983

    
984
        for (int i = 0; i < num; i++) {
985
            IFFrame fframe = fframes[i];
986
            treemap.put(new Double(fframe.getBoundBox().getMinY()), fframe);
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.getLayoutContext().getAttributes().m_sizePaper.getAlto() - ymax));
1012
            num += 2;
1013
        }
1014

    
1015
        double dist = total / (num - 1);
1016
        Iterator k = treemap.keySet().iterator();
1017
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
1018
        efs.startComplex(PluginServices.getText(this, "vertical_space"));
1019

    
1020
        if (k.hasNext()) {
1021
            IFFrame fframe = (IFFrame) treemap.get(k.next());
1022
            IFFrame fframeA = fframe.cloneFFrame(m_layout);
1023

    
1024
            if (inLayout) {
1025
                Rectangle2D.Double r = (Rectangle2D.Double) fframeA.getBoundBox()
1026
                                                                   .clone();
1027
                r.y = dist;
1028
                fframeA.setBoundBox(r);
1029
                efs.update(fframe, fframeA);
1030
            }
1031

    
1032
            while (k.hasNext()) {
1033
                IFFrame fframeAux = (IFFrame) treemap.get(k.next());
1034
                IFFrame fframeS = fframeAux.cloneFFrame(m_layout);
1035
                Rectangle2D.Double r = (Rectangle2D.Double) fframeS.getBoundBox()
1036
                                                                   .clone();
1037
                r.y = fframeA.getBoundBox().getMaxY() + dist;
1038
                fframeS.setBoundBox(r);
1039
                efs.update(fframeAux, fframeS);
1040
                fframeA = fframeS;
1041
            }
1042
        }
1043

    
1044
        efs.endComplex();
1045
    }
1046

    
1047
    /**
1048
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1049
     */
1050
    public void actionPerformed(ActionEvent e) {
1051
        m_layout.getLayoutContext().updateFFrames();
1052

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

    
1135
        m_layout.getLayoutContext().updateFFrames();
1136
        m_layout.getLayoutContext().callLayoutDrawListeners();
1137
    }
1138
}