Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / gui / dialogs / EventsFAlign.java @ 31496

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 org.gvsig.app.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 org.gvsig.andami.PluginServices;
54
import org.gvsig.app.project.documents.layout.commands.FrameCommandsRecord;
55
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
56
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
57

    
58

    
59

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

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

    
78
    /**
79
     * Desplaza los fframes seleccionados a la izquierda del fframe m?s
80
     * occidental.
81
     */
82
    private void alignLeft() {
83
        double xmin = Double.MAX_VALUE;
84
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
85

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

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

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

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

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

    
107
        efs.endComplex();
108
    }
109

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

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

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

    
129
        efs.endComplex();
130
    }
131

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

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

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

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

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

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

    
163
        efs.endComplex();
164
    }
165

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

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

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

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

    
187
        efs.endComplex();
188
    }
189

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

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

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

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

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

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

    
219
        efs.endComplex();
220
    }
221

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

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

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

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

    
243
        efs.endComplex();
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(PluginServices.getText(this, "align_down"));
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();
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().getAttributes().m_sizePaper.getAlto();
284

    
285
        IFFrame[] fframes = m_layout.getLayoutContext().getFFrameSelected();
286
        FrameCommandsRecord efs = m_layout.getLayoutContext().getFrameCommandsRecord();
287
        efs.startComplex(PluginServices.getText(this, "align_to_layout_down"));
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();
299
    }
300

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

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

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

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

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

    
329
        efs.endComplex();
330
    }
331

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

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

    
350
        efs.endComplex();
351
    }
352

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

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

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

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

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

    
383
        efs.endComplex();
384
    }
385

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

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

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

    
406
        efs.endComplex();
407
    }
408

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

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

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

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

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

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

    
446
        efs.endComplex();
447
    }
448

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

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

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

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

    
476
        efs.endComplex();
477
    }
478

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

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

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

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

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

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

    
516
        efs.endComplex();
517
    }
518

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

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

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

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

    
546
        efs.endComplex();
547
    }
548

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

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

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

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

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

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

    
586
        efs.endComplex();
587
    }
588

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

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

    
601
        num = fframes.length;
602

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

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

    
617
        efs.endComplex();
618
    }
619

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

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

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

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

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

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

    
657
        efs.endComplex();
658
    }
659

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

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

    
672
        num = fframes.length;
673

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

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

    
688
        efs.endComplex();
689
    }
690

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

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

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

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

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

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

    
728
        efs.endComplex();
729
    }
730

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

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

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

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

    
759
        efs.endComplex();
760
    }
761

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

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

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

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

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

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

    
799
        efs.endComplex();
800
    }
801

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

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

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

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

    
830
        efs.endComplex();
831
    }
832

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

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

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

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

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

    
861
        efs.endComplex();
862
    }
863

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

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

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

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

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

    
892
        efs.endComplex();
893
    }
894

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

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

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

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

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

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

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

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

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

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

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

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

    
968
        efs.endComplex();
969
    }
970

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

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

    
985
        for (int i = 0; i < num; i++) {
986
            IFFrame fframe = fframes[i];
987
            treemap.put(new Double(fframe.getBoundBox().getMinY()), fframe);
988
        }
989

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

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

    
996
            IFFrame fframeS = null;
997

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

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

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

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

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

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

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

    
1045
        efs.endComplex();
1046
    }
1047

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

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

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