Statistics
| Revision:

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

History | View | Annotate | Download (39.9 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();
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(PluginServices.getText(this, "align_left"));
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();
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(PluginServices.getText(this,"align_to_layout_left"));
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();
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(PluginServices.getText(this, "align_center"));
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().getAtributes().m_sizePaper.getAncho() / 2;
171

    
172
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
173
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
174
        efs.startComplex();
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(PluginServices.getText(this,"align_to_layout_center"));
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();
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(PluginServices.getText(this, "align_right"));
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().getAtributes().m_sizePaper.getAncho();
227

    
228
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
229
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
230
        efs.startComplex();
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(PluginServices.getText(this,
243
                "align_to_layout_right"));
244
    }
245

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

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

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

    
262
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
263
        efs.startComplex();
264

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

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

    
275
        efs.endComplex(PluginServices.getText(this, "align_down"));
276
    }
277

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

    
285
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
286
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
287
        efs.startComplex();
288

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

    
298
        efs.endComplex(PluginServices.getText(this,
299
                "align_to_layout_down"));
300
    }
301

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

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

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

    
318
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
319
        efs.startComplex();
320

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

    
330
        efs.endComplex(PluginServices.getText(this, "align_up"));
331
    }
332

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

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

    
351
        efs.endComplex(PluginServices.getText(this, "align_to_layout_up"));
352
    }
353

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

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

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

    
372
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
373
        efs.startComplex();
374

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

    
384
        efs.endComplex(PluginServices.getText(this,
385
                "align_vertical_center"));
386
    }
387

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

    
395
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
396
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
397
        efs.startComplex();
398

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

    
408
        efs.endComplex(PluginServices.getText(this,
409
                "align_to_layout_vertical_center"));
410
    }
411

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

    
423
        for (int i = 0; i < num; i++) {
424
            IFFrame fframe = fframes[i];
425

    
426
            if (xmin > fframe.getBoundBox().getMinX()) {
427
                xmin = fframe.getBoundBox().getMinX();
428
            }
429

    
430
            if (xmax < fframe.getBoundBox().getMaxX()) {
431
                xmax = fframe.getBoundBox().getMaxX();
432
            }
433
        }
434

    
435
        double dif = xmax - xmin;
436
        double dist = dif / num;
437
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
438
        efs.startComplex();
439

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

    
449
        efs.endComplex(PluginServices.getText(this, "distributes_left"));
450
    }
451

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

    
461
        int num = 0;
462
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
463
        num = fframes.length;
464

    
465
        double dif = xmax - xmin;
466
        double dist = dif / num;
467
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
468
        efs.startComplex();
469

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

    
479
        efs.endComplex(PluginServices.getText(this,
480
                "distributes_to_layout_left"));
481
    }
482

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

    
494
        for (int i = 0; i < num; i++) {
495
            IFFrame fframe = fframes[i];
496

    
497
            if (xmin > fframe.getBoundBox().getMinX()) {
498
                xmin = fframe.getBoundBox().getMinX();
499
            }
500

    
501
            if (xmax < fframe.getBoundBox().getMaxX()) {
502
                xmax = fframe.getBoundBox().getMaxX();
503
            }
504
        }
505

    
506
        double dif = xmax - xmin;
507
        double dist = dif / num;
508
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
509
        efs.startComplex();
510

    
511
        for (int i = 0; i < fframes.length; i++) {
512
            IFFrame fframe = fframes[i];
513
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
514
                                                              .clone();
515
            r.x = xmax - (dist * i) - fframe.getBoundBox().width;
516
            fframe.setBoundBox(r);
517
            efs.update(fframes[i], fframe);
518
        }
519

    
520
        efs.endComplex(PluginServices.getText(this, "distributes_right"));
521
    }
522

    
523
    /**
524
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
525
     * y vertical, de derecha a izquierda.
526
     */
527
    private void distRightL() {
528
        double xmin = 0;
529
        double xmax = 0;
530
        xmax = m_layout.getLayoutContext().getAtributes().m_sizePaper.getAncho();
531

    
532
        int num = 0;
533
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
534
        num = fframes.length;
535

    
536
        double dif = xmax - xmin;
537
        double dist = dif / num;
538
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
539
        efs.startComplex();
540

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

    
550
        efs.endComplex(PluginServices.getText(this,
551
                "distributes_to_layout_right"));
552
    }
553

    
554
    /**
555
     * Distribuye los fframes seleccionados de forma equidistante y vertical,
556
     * desde arriba hacia abajo.
557
     */
558
    private void distUp() {
559
        double ymin = Double.MAX_VALUE;
560
        double ymax = Double.NEGATIVE_INFINITY;
561
        int num = 0;
562
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
563
        num = fframes.length;
564

    
565
        for (int i = 0; i < num; i++) {
566
            IFFrame fframe = fframes[i];
567

    
568
            if (ymin > fframe.getBoundBox().getMinY()) {
569
                ymin = fframe.getBoundBox().getMinY();
570
            }
571

    
572
            if (ymax < fframe.getBoundBox().getMaxY()) {
573
                ymax = fframe.getBoundBox().getMaxY();
574
            }
575
        }
576

    
577
        double dif = ymax - ymin;
578
        double dist = dif / num;
579
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
580
        efs.startComplex();
581

    
582
        for (int i = 0; i < fframes.length; i++) {
583
            IFFrame fframe = fframes[i];
584
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
585
                                                              .clone();
586
            r.y = ymin + (dist * i);
587
            fframe.setBoundBox(r);
588
            efs.update(fframes[i], fframe);
589
        }
590

    
591
        efs.endComplex(PluginServices.getText(this, "distributes_up"));
592
    }
593

    
594
    /**
595
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
596
     * y vertical, desde arriba hacia abajo.
597
     */
598
    private void distUpL() {
599
        double ymin = 0;
600
        double ymax = 0;
601
        ymax = m_layout.getLayoutContext().getAtributes().m_sizePaper.getAlto();
602

    
603
        int num = 0;
604
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
605

    
606
        num = fframes.length;
607

    
608
        double dif = ymax - ymin;
609
        double dist = dif / num;
610
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
611
        efs.startComplex();
612

    
613
        for (int i = 0; i < fframes.length; i++) {
614
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
615
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
616
                                                              .clone();
617
            r.y = ymin + (dist * i);
618
            fframe.setBoundBox(r);
619
            efs.update(fframes[i], fframe);
620
        }
621

    
622
        efs.endComplex(PluginServices.getText(this,
623
                "distributes_to_layout_up"));
624
    }
625

    
626
    /**
627
     * Distribuye los fframes seleccionados de forma equidistante y vertical,
628
     * desde bajo hacia arriba.
629
     */
630
    private void distDown() {
631
        double ymin = Double.MAX_VALUE;
632
        double ymax = Double.NEGATIVE_INFINITY;
633
        int num = 0;
634
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
635
        num = fframes.length;
636

    
637
        for (int i = 0; i < num; i++) {
638
            IFFrame fframe = fframes[i];
639

    
640
            if (ymin > fframe.getBoundBox().getMinY()) {
641
                ymin = fframe.getBoundBox().getMinY();
642
            }
643

    
644
            if (ymax < fframe.getBoundBox().getMaxY()) {
645
                ymax = fframe.getBoundBox().getMaxY();
646
            }
647
        }
648

    
649
        double dif = ymax - ymin;
650
        double dist = dif / num;
651
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
652
        efs.startComplex();
653

    
654
        for (int i = 0; i < fframes.length; i++) {
655
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
656
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
657
                                                              .clone();
658
            r.y = ymax - (dist * i) - fframe.getBoundBox().height;
659
            fframe.setBoundBox(r);
660
            efs.update(fframes[i], fframe);
661
        }
662

    
663
        efs.endComplex(PluginServices.getText(this, "distributes_down"));
664
    }
665

    
666
    /**
667
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
668
     * y vertical, desde bajo hacia arriba.
669
     */
670
    private void distDownL() {
671
        double ymin = 0;
672
        double ymax = 0;
673
        ymax = m_layout.getLayoutContext().getAtributes().m_sizePaper.getAlto();
674

    
675
        int num = 0;
676
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
677

    
678
        num = fframes.length;
679

    
680
        double dif = ymax - ymin;
681
        double dist = dif / num;
682
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
683
        efs.startComplex();
684

    
685
        for (int i = fframes.length - 1; i >= 0; i--) {
686
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
687
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
688
                                                              .clone();
689
            r.y = ymax - (dist * i) - fframe.getBoundBox().height;
690
            fframe.setBoundBox(r);
691
            efs.update(fframes[i], fframe);
692
        }
693

    
694
        efs.endComplex(PluginServices.getText(this,
695
                "distributes_to_layout_down"));
696
    }
697

    
698
    /**
699
     * Distribuye los fframes seleccionados de forma equidistante y vertical.
700
     */
701
    private void distCenterH() {
702
        double xmin = Double.MAX_VALUE;
703
        double xmax = Double.NEGATIVE_INFINITY;
704
        int num = 0;
705
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
706
        num = fframes.length;
707

    
708
        for (int i = 0; i < num; i++) {
709
            IFFrame fframe = fframes[i];
710

    
711
            if (xmin > fframe.getBoundBox().getMinX()) {
712
                xmin = fframe.getBoundBox().getMinX();
713
            }
714

    
715
            if (xmax < fframe.getBoundBox().getMaxX()) {
716
                xmax = fframe.getBoundBox().getMaxX();
717
            }
718
        }
719

    
720
        double dif = xmax - xmin;
721
        double dist = dif / num;
722
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
723
        efs.startComplex();
724

    
725
        for (int i = 0; i < fframes.length; i++) {
726
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
727
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
728
                                                              .clone();
729
            r.x = (xmin + (((dist) * (i + 1)) - (dist / 2))) -
730
                (fframe.getBoundBox().width / 2);
731
            fframe.setBoundBox(r);
732
            efs.update(fframes[i], fframe);
733
        }
734

    
735
        efs.endComplex(PluginServices.getText(this,
736
                "distributes_vertical"));
737
    }
738

    
739
    /**
740
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
741
     * y vertical.
742
     */
743
    private void distCenterHL() {
744
        double xmin = 0;
745
        double xmax = 0;
746
        xmax = m_layout.getLayoutContext().getAtributes().m_sizePaper.getAncho();
747

    
748
        int num = 0;
749
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
750
        num = fframes.length;
751

    
752
        double dif = xmax - xmin;
753
        double dist = dif / num;
754
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
755
        efs.startComplex();
756

    
757
        for (int i = 0; i < fframes.length; i++) {
758
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
759
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
760
                                                              .clone();
761
            r.x = (xmin + (((dist) * (i + 1)) - (dist / 2))) -
762
                (fframe.getBoundBox().width / 2);
763
            fframe.setBoundBox(r);
764
            efs.update(fframes[i], fframe);
765
        }
766

    
767
        efs.endComplex(PluginServices.getText(this,
768
                "distributes_to_layout_vertical"));
769
    }
770

    
771
    /**
772
     * Distribuye los fframes seleccionados de forma equidistante y horizontal.
773
     */
774
    private void distCenterV() {
775
        double ymin = Double.MAX_VALUE;
776
        double ymax = Double.NEGATIVE_INFINITY;
777
        int num = 0;
778
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
779
        num = fframes.length;
780

    
781
        for (int i = 0; i < num; i++) {
782
            IFFrame fframe = fframes[i];
783

    
784
            if (ymin > fframe.getBoundBox().getMinY()) {
785
                ymin = fframe.getBoundBox().getMinY();
786
            }
787

    
788
            if (ymax < fframe.getBoundBox().getMaxY()) {
789
                ymax = fframe.getBoundBox().getMaxY();
790
            }
791
        }
792

    
793
        double dif = ymax - ymin;
794
        double dist = dif / num;
795
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
796
        efs.startComplex();
797

    
798
        for (int i = 0; i < fframes.length; i++) {
799
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
800
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
801
                                                              .clone();
802
            r.y = (ymin + (((dist) * (i + 1)) - (dist / 2))) -
803
                (fframe.getBoundBox().height / 2);
804
            fframe.setBoundBox(r);
805
            efs.update(fframes[i], fframe);
806
        }
807

    
808
        efs.endComplex(PluginServices.getText(this,
809
                "distributes_horizontal"));
810
    }
811

    
812
    /**
813
     * Distribuye los fframes seleccionados en el Layout de forma equidistante
814
     * y horizontal.
815
     */
816
    private void distCenterVL() {
817
        double ymin = 0;
818
        double ymax = 0;
819
        ymax = m_layout.getLayoutContext().getAtributes().m_sizePaper.getAlto();
820

    
821
        int num = 0;
822
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
823
        num = fframes.length;
824

    
825
        double dif = ymax - ymin;
826
        double dist = dif / num;
827
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
828
        efs.startComplex();
829

    
830
        for (int i = 0; i < fframes.length; i++) {
831
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
832
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
833
                                                              .clone();
834
            r.y = (ymin + (((dist) * (i + 1)) - (dist / 2))) -
835
                (fframe.getBoundBox().height / 2);
836
            fframe.setBoundBox(r);
837
            efs.update(fframes[i], fframe);
838
        }
839

    
840
        efs.endComplex(PluginServices.getText(this,
841
                "distributes_to_layout_horizontal"));
842
    }
843

    
844
    /**
845
     * Cambia la anchura de los fframes seleccionados por la anchura del m?s
846
     * ancho.
847
     */
848
    private void sizeWidth() {
849
        double wmax = Double.NEGATIVE_INFINITY;
850
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
851

    
852
        for (int i = 0; i < fframes.length; i++) {
853
            IFFrame fframe = fframes[i];
854

    
855
            if (wmax < fframe.getBoundBox().getWidth()) {
856
                wmax = fframe.getBoundBox().getWidth();
857
            }
858
        }
859

    
860
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
861
        efs.startComplex();
862

    
863
        for (int i = 0; i < fframes.length; i++) {
864
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
865
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
866
                                                              .clone();
867
            r.width = wmax;
868
            fframe.setBoundBox(r);
869
            efs.update(fframes[i], fframe);
870
        }
871

    
872
        efs.endComplex(PluginServices.getText(this, "change_width"));
873
    }
874

    
875
    /**
876
     * Cambia la altura de los fframes seleccionados por la altura del mas
877
     * alto.
878
     */
879
    private void sizeHeight() {
880
        double hmax = Double.NEGATIVE_INFINITY;
881
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
882

    
883
        for (int i = 0; i < fframes.length; i++) {
884
            IFFrame fframe = fframes[i];
885

    
886
            if (hmax < fframe.getBoundBox().getHeight()) {
887
                hmax = fframe.getBoundBox().getHeight();
888
            }
889
        }
890

    
891
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
892
        efs.startComplex();
893

    
894
        for (int i = 0; i < fframes.length; i++) {
895
            IFFrame fframe = fframes[i].cloneFFrame(m_layout);
896
            Rectangle2D.Double r = (Rectangle2D.Double) fframe.getBoundBox()
897
                                                              .clone();
898
            r.height = hmax;
899
            fframe.setBoundBox(r);
900
            efs.update(fframes[i], fframe);
901
        }
902

    
903
        efs.endComplex(PluginServices.getText(this, "change_height"));
904
    }
905

    
906
    /**
907
     * Distribuye horizontalmente los fframes dejando como espacio entre ellos
908
     * la media de todos los espacios.
909
     */
910
    private void spaceRight() {
911
        double total = 0;
912
        double num = 0;
913
        double xmin = Double.MAX_VALUE;
914
        double xmax = Double.NEGATIVE_INFINITY;
915

    
916
        TreeMap treemap = new TreeMap();
917
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
918
        num = fframes.length;
919

    
920
        for (int i = 0; i < num; i++) {
921
            IFFrame fframe = fframes[i];
922
            treemap.put(new Double(fframe.getBoundBox().getMinX()), fframe);
923
        }
924

    
925
        Iterator j = treemap.keySet().iterator();
926

    
927
        if (j.hasNext()) {
928
            IFFrame fframeA = (IFFrame) treemap.get(j.next());
929
            IFFrame fframeS = null;
930
            xmin = fframeA.getBoundBox().x;
931

    
932
            while (j.hasNext()) {
933
                fframeS = (IFFrame) treemap.get(j.next());
934
                total += (fframeS.getBoundBox().getMinX() -
935
                fframeA.getBoundBox().getMaxX());
936
                fframeA = fframeS;
937
            }
938

    
939
            if (fframeS != null) {
940
                xmax = fframeS.getBoundBox().getMaxX();
941
            }
942
        }
943

    
944
        if (inLayout) {
945
            total += (xmin +
946
            (m_layout.getLayoutContext().getAtributes().m_sizePaper.getAncho() - xmax));
947
            num += 2;
948
        }
949

    
950
        double dist = total / (num - 1);
951
        Iterator k = treemap.keySet().iterator();
952
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
953
        efs.startComplex();
954

    
955
        if (k.hasNext()) {
956
            IFFrame fframe = (IFFrame) treemap.get(k.next());
957
            IFFrame fframeA = fframe.cloneFFrame(m_layout);
958

    
959
            if (inLayout) {
960
                Rectangle2D.Double r = (Rectangle2D.Double) fframeA.getBoundBox()
961
                                                                   .clone();
962
                r.x = dist;
963
                fframeA.setBoundBox(r);
964
                efs.update(fframe, fframeA);
965
            }
966

    
967
            while (k.hasNext()) {
968
                IFFrame fframeAux = (IFFrame) treemap.get(k.next());
969
                IFFrame fframeS = fframeAux.cloneFFrame(m_layout);
970
                Rectangle2D.Double r = (Rectangle2D.Double) fframeS.getBoundBox()
971
                                                                   .clone();
972
                r.x = fframeA.getBoundBox().getMaxX() + dist;
973
                fframeS.setBoundBox(r);
974
                efs.update(fframeAux, fframeS);
975
                fframeA = fframeS;
976
            }
977
        }
978

    
979
        efs.endComplex(PluginServices.getText(this, "horizontal_space"));
980
    }
981

    
982
    /**
983
     * Distribuye verticalmente los fframes dejando como espacio entre ellos la
984
     * media de todos los espacios.
985
     */
986
    private void spaceDown() {
987
        double total = 0;
988
        double num = 0;
989
        double ymin = Double.MAX_VALUE;
990
        double ymax = Double.NEGATIVE_INFINITY;
991

    
992
        TreeMap treemap = new TreeMap();
993
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
994
        num = fframes.length;
995

    
996
        for (int i = 0; i < num; i++) {
997
            IFFrame fframe = fframes[i];
998
            treemap.put(new Double(fframe.getBoundBox().getMinY()), fframe);
999
        }
1000

    
1001
        Iterator j = treemap.keySet().iterator();
1002

    
1003
        if (j.hasNext()) {
1004
            IFFrame fframeA = (IFFrame) treemap.get(j.next());
1005
            ymin = fframeA.getBoundBox().y;
1006

    
1007
            IFFrame fframeS = null;
1008

    
1009
            while (j.hasNext()) {
1010
                fframeS = (IFFrame) treemap.get(j.next());
1011
                total += (fframeS.getBoundBox().getMinY() -
1012
                fframeA.getBoundBox().getMaxY());
1013
                fframeA = fframeS;
1014
            }
1015

    
1016
            if (fframeS != null) {
1017
                ymax = fframeS.getBoundBox().getMaxY();
1018
            }
1019
        }
1020

    
1021
        if (inLayout) {
1022
            total += (ymin +
1023
            (m_layout.getLayoutContext().getAtributes().m_sizePaper.getAlto() - ymax));
1024
            num += 2;
1025
        }
1026

    
1027
        double dist = total / (num - 1);
1028
        Iterator k = treemap.keySet().iterator();
1029
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
1030
        efs.startComplex();
1031

    
1032
        if (k.hasNext()) {
1033
            IFFrame fframe = (IFFrame) treemap.get(k.next());
1034
            IFFrame fframeA = fframe.cloneFFrame(m_layout);
1035

    
1036
            if (inLayout) {
1037
                Rectangle2D.Double r = (Rectangle2D.Double) fframeA.getBoundBox()
1038
                                                                   .clone();
1039
                r.y = dist;
1040
                fframeA.setBoundBox(r);
1041
                efs.update(fframe, fframeA);
1042
            }
1043

    
1044
            while (k.hasNext()) {
1045
                IFFrame fframeAux = (IFFrame) treemap.get(k.next());
1046
                IFFrame fframeS = fframeAux.cloneFFrame(m_layout);
1047
                Rectangle2D.Double r = (Rectangle2D.Double) fframeS.getBoundBox()
1048
                                                                   .clone();
1049
                r.y = fframeA.getBoundBox().getMaxY() + dist;
1050
                fframeS.setBoundBox(r);
1051
                efs.update(fframeAux, fframeS);
1052
                fframeA = fframeS;
1053
            }
1054
        }
1055

    
1056
        efs.endComplex(PluginServices.getText(this, "vertical_space"));
1057
    }
1058

    
1059
    /**
1060
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1061
     */
1062
    public void actionPerformed(ActionEvent e) {
1063
        m_layout.getLayoutContext().updateFFrames();
1064

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

    
1147
        m_layout.getLayoutContext().updateFFrames();
1148
        m_layout.getLayoutContext().callLayoutDrawListeners();
1149
    }
1150
}