Statistics
| Revision:

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

History | View | Annotate | Download (17.1 KB)

1
/*
2
 * Created on 28-jul-2004
3
 *
4
 */
5
package com.iver.cit.gvsig.gui.layout.dialogs;
6

    
7
import com.iver.andami.PluginServices;
8
import com.iver.andami.ui.mdiManager.View;
9
import com.iver.andami.ui.mdiManager.ViewInfo;
10

    
11
import com.iver.cit.gvsig.gui.layout.FLayoutGraphics;
12
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
13
import com.iver.cit.gvsig.gui.layout.Layout;
14
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
15
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
16
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup;
17
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
18
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameGraphicsDialog;
19

    
20
import java.awt.Color;
21
import java.awt.geom.Rectangle2D;
22

    
23
import java.util.ArrayList;
24

    
25
import javax.swing.ButtonGroup;
26
import javax.swing.JPanel;
27

    
28

    
29
/**
30
 * Di?logo con todas las opciones para crear un borde a los fframes.
31
 *
32
 * @author Vicente Caballero Navarro
33
 */
34
public class FBorderDialog extends JPanel implements View {
35
        private javax.swing.JRadioButton rbSeleccionados = null;
36
        private javax.swing.JRadioButton rbTodos = null;
37
        private javax.swing.JRadioButton rbMargen = null;
38
        private javax.swing.JCheckBox chbAgrupar = null;
39
        private javax.swing.JPanel pPosicion = null;
40
        private javax.swing.JCheckBox chbIgualLados = null;
41
        private javax.swing.JLabel lunidades = null;
42
        private javax.swing.JTextField tTodosLados = null;
43
        private javax.swing.JLabel lSuperior = null;
44
        private javax.swing.JLabel lInferior = null;
45
        private javax.swing.JTextField tSuperior = null;
46
        private javax.swing.JTextField tInferior = null;
47
        private javax.swing.JLabel lIzquierda = null;
48
        private javax.swing.JLabel lDerecha = null;
49
        private javax.swing.JTextField tIzquierda = null;
50
        private javax.swing.JTextField tDerecha = null;
51
        private javax.swing.JLabel lUnidades = null;
52
        private javax.swing.JButton bAceptar = null;
53
        private javax.swing.JButton bCancelar = null;
54
        private Layout layout = null;
55
        private ArrayList selecList = new ArrayList();
56
        private FFrameGraphics fframegraphics = null;
57
        private FLayoutGraphics flg = null;
58
        private String m_NameUnit = null;
59
        private javax.swing.JButton bConfigurar = null;
60

    
61
        /**
62
         * This is the default constructor
63
         *
64
         * @param l Referencia al Layout.
65
         */
66
        public FBorderDialog(Layout l) {
67
                super();
68
                layout = l;
69
                flg = new FLayoutGraphics(layout);
70
                fframegraphics = new FFrameGraphics();
71
                fframegraphics.setColor(Color.red);
72
                fframegraphics.update(Layout.RECTANGLESIMPLE, layout.getAT());
73

    
74
                initialize();
75
        }
76

    
77
        /**
78
         * This method initializes this
79
         */
80
        private void initialize() {
81
                for (int i = 0; i < layout.getFFrames().size(); i++) {
82
                        if (((IFFrame) layout.getFFrames().get(i)).getSelected() != FFrame.NOSELECT) {
83
                                selecList.add(layout.getFFrames().get(i));
84
                        }
85
                }
86

    
87
                this.setLayout(null);
88
                m_NameUnit = layout.getAtributes().getNameUnit();
89
                this.add(getRbSeleccionados(), null);
90
                this.add(getRbTodos(), null);
91
                this.add(getRbMargen(), null);
92
                this.add(getChbAgrupar(), null);
93
                this.add(getPPosicion(), null);
94
                this.add(getBAceptar(), null);
95
                this.add(getBCancelar(), null);
96
                this.add(getBConfigurar(), null);
97
                this.setSize(371, 223);
98

    
99
                ButtonGroup group = new ButtonGroup();
100
                group.add(getRbSeleccionados());
101
                group.add(getRbTodos());
102
                group.add(getRbMargen());
103
        }
104

    
105
        /**
106
         * This method initializes rbSeleccionados
107
         *
108
         * @return javax.swing.JRadioButton
109
         */
110
        private javax.swing.JRadioButton getRbSeleccionados() {
111
                if (rbSeleccionados == null) {
112
                        rbSeleccionados = new javax.swing.JRadioButton();
113
                        rbSeleccionados.setBounds(10, 8, 416, 20);
114
                        rbSeleccionados.setText(PluginServices.getText(this,
115
                                        "colocar_alrededor_seleccionados"));
116

    
117
                        if (selecList.size() == 0) {
118
                                rbSeleccionados.setEnabled(false);
119
                                getRbTodos().setSelected(true);
120
                        } else {
121
                                rbSeleccionados.setSelected(true);
122
                        }
123
                }
124

    
125
                return rbSeleccionados;
126
        }
127

    
128
        /**
129
         * This method initializes rbTodos
130
         *
131
         * @return javax.swing.JRadioButton
132
         */
133
        private javax.swing.JRadioButton getRbTodos() {
134
                if (rbTodos == null) {
135
                        rbTodos = new javax.swing.JRadioButton();
136
                        rbTodos.setBounds(10, 29, 332, 20);
137
                        rbTodos.setText(PluginServices.getText(this,
138
                                        "colocar_alrededor_todos"));
139
                }
140

    
141
                return rbTodos;
142
        }
143

    
144
        /**
145
         * This method initializes rbMargen
146
         *
147
         * @return javax.swing.JRadioButton
148
         */
149
        private javax.swing.JRadioButton getRbMargen() {
150
                if (rbMargen == null) {
151
                        rbMargen = new javax.swing.JRadioButton();
152
                        rbMargen.setBounds(10, 51, 286, 20);
153
                        rbMargen.setText(PluginServices.getText(this, "colocar_a_margenes"));
154
                }
155

    
156
                return rbMargen;
157
        }
158

    
159
        /**
160
         * This method initializes chbAgrupar
161
         *
162
         * @return javax.swing.JCheckBox
163
         */
164
        private javax.swing.JCheckBox getChbAgrupar() {
165
                if (chbAgrupar == null) {
166
                        chbAgrupar = new javax.swing.JCheckBox();
167
                        chbAgrupar.setBounds(10, 70, 280, 20);
168
                        chbAgrupar.setText(PluginServices.getText(this, "agrupar_linea"));
169
                }
170

    
171
                return chbAgrupar;
172
        }
173

    
174
        /**
175
         * This method initializes pPosicion
176
         *
177
         * @return javax.swing.JPanel
178
         */
179
        private javax.swing.JPanel getPPosicion() {
180
                if (pPosicion == null) {
181
                        pPosicion = new javax.swing.JPanel();
182
                        pPosicion.setLayout(null);
183
                        pPosicion.add(getChbIgualLados(), null);
184
                        pPosicion.add(getLunidades(), null);
185
                        pPosicion.add(getTTodosLados(), null);
186
                        pPosicion.add(getLSuperior(), null);
187
                        pPosicion.add(getLInferior(), null);
188
                        pPosicion.add(getTSuperior(), null);
189
                        pPosicion.add(getTInferior(), null);
190
                        pPosicion.add(getLIzquierda(), null);
191
                        pPosicion.add(getLDerecha(), null);
192
                        pPosicion.add(getTIzquierda(), null);
193
                        pPosicion.add(getTDerecha(), null);
194
                        pPosicion.add(getLUnidades(), null);
195
                        pPosicion.setBounds(12, 92, 350, 97);
196
                        pPosicion.setBorder(javax.swing.BorderFactory.createTitledBorder(
197
                                        null, PluginServices.getText(this, "posicion_linea"),
198
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
199
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
200
                }
201

    
202
                return pPosicion;
203
        }
204

    
205
        /**
206
         * This method initializes chbIgualLados
207
         *
208
         * @return javax.swing.JCheckBox
209
         */
210
        private javax.swing.JCheckBox getChbIgualLados() {
211
                if (chbIgualLados == null) {
212
                        chbIgualLados = new javax.swing.JCheckBox();
213
                        chbIgualLados.setBounds(10, 16, 243, 21);
214
                        chbIgualLados.setText(PluginServices.getText(this,
215
                                        "igual_todos_lados"));
216
                        chbIgualLados.setSelected(true);
217
                        chbIgualLados.addActionListener(new java.awt.event.ActionListener() {
218
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
219
                                                if (!chbIgualLados.isSelected()) {
220
                                                        getTTodosLados().setEnabled(false);
221
                                                        getTSuperior().setEnabled(true);
222
                                                        getTInferior().setEnabled(true);
223
                                                        getTIzquierda().setEnabled(true);
224
                                                        getTDerecha().setEnabled(true);
225
                                                } else {
226
                                                        getTTodosLados().setEnabled(true);
227
                                                        getTSuperior().setEnabled(false);
228
                                                        getTInferior().setEnabled(false);
229
                                                        getTIzquierda().setEnabled(false);
230
                                                        getTDerecha().setEnabled(false);
231
                                                        getTSuperior().setText(tTodosLados.getText());
232
                                                        getTInferior().setText(tTodosLados.getText());
233
                                                        getTIzquierda().setText(tTodosLados.getText());
234
                                                        getTDerecha().setText(tTodosLados.getText());
235
                                                }
236
                                        }
237
                                });
238
                }
239

    
240
                return chbIgualLados;
241
        }
242

    
243
        /**
244
         * This method initializes lunidades
245
         *
246
         * @return javax.swing.JLabel
247
         */
248
        private javax.swing.JLabel getLunidades() {
249
                if (lunidades == null) {
250
                        lunidades = new javax.swing.JLabel();
251
                        lunidades.setBounds(264, 64, 78, 18);
252
                        lunidades.setText(m_NameUnit);
253
                }
254

    
255
                return lunidades;
256
        }
257

    
258
        /**
259
         * This method initializes tTodosLados
260
         *
261
         * @return javax.swing.JTextField
262
         */
263
        private javax.swing.JTextField getTTodosLados() {
264
                if (tTodosLados == null) {
265
                        tTodosLados = new javax.swing.JTextField();
266
                        tTodosLados.setBounds(267, 19, 48, 16);
267
                        tTodosLados.setText("0.5");
268
                        tTodosLados.addCaretListener(new javax.swing.event.CaretListener() {
269
                                        public void caretUpdate(javax.swing.event.CaretEvent e) {
270
                                                if (getChbIgualLados().isSelected()) {
271
                                                        getTSuperior().setText(tTodosLados.getText());
272
                                                        getTInferior().setText(tTodosLados.getText());
273
                                                        getTIzquierda().setText(tTodosLados.getText());
274
                                                        getTDerecha().setText(tTodosLados.getText());
275
                                                }
276
                                        }
277
                                });
278
                }
279

    
280
                return tTodosLados;
281
        }
282

    
283
        /**
284
         * This method initializes lSuperior
285
         *
286
         * @return javax.swing.JLabel
287
         */
288
        private javax.swing.JLabel getLSuperior() {
289
                if (lSuperior == null) {
290
                        lSuperior = new javax.swing.JLabel();
291
                        lSuperior.setBounds(10, 55, 62, 16);
292
                        lSuperior.setText(PluginServices.getText(this, "Superior"));
293
                }
294

    
295
                return lSuperior;
296
        }
297

    
298
        /**
299
         * This method initializes lInferior
300
         *
301
         * @return javax.swing.JLabel
302
         */
303
        private javax.swing.JLabel getLInferior() {
304
                if (lInferior == null) {
305
                        lInferior = new javax.swing.JLabel();
306
                        lInferior.setBounds(10, 72, 62, 16);
307
                        lInferior.setText(PluginServices.getText(this, "Inferior"));
308
                }
309

    
310
                return lInferior;
311
        }
312

    
313
        /**
314
         * This method initializes tSuperior
315
         *
316
         * @return javax.swing.JTextField
317
         */
318
        private javax.swing.JTextField getTSuperior() {
319
                if (tSuperior == null) {
320
                        tSuperior = new javax.swing.JTextField();
321
                        tSuperior.setBounds(78, 55, 48, 16);
322
                        tSuperior.setText("0.5");
323
                        tSuperior.setEnabled(false);
324
                }
325

    
326
                return tSuperior;
327
        }
328

    
329
        /**
330
         * This method initializes tInferior
331
         *
332
         * @return javax.swing.JTextField
333
         */
334
        private javax.swing.JTextField getTInferior() {
335
                if (tInferior == null) {
336
                        tInferior = new javax.swing.JTextField();
337
                        tInferior.setBounds(78, 72, 48, 16);
338
                        tInferior.setText("0.5");
339
                        tInferior.setEnabled(false);
340
                }
341

    
342
                return tInferior;
343
        }
344

    
345
        /**
346
         * This method initializes lIzquierda
347
         *
348
         * @return javax.swing.JLabel
349
         */
350
        private javax.swing.JLabel getLIzquierda() {
351
                if (lIzquierda == null) {
352
                        lIzquierda = new javax.swing.JLabel();
353
                        lIzquierda.setBounds(140, 55, 62, 16);
354
                        lIzquierda.setText(PluginServices.getText(this, "Izquierda"));
355
                }
356

    
357
                return lIzquierda;
358
        }
359

    
360
        /**
361
         * This method initializes lDerecha
362
         *
363
         * @return javax.swing.JLabel
364
         */
365
        private javax.swing.JLabel getLDerecha() {
366
                if (lDerecha == null) {
367
                        lDerecha = new javax.swing.JLabel();
368
                        lDerecha.setBounds(140, 72, 62, 16);
369
                        lDerecha.setText(PluginServices.getText(this, "Derecha"));
370
                }
371

    
372
                return lDerecha;
373
        }
374

    
375
        /**
376
         * This method initializes tIzquierda
377
         *
378
         * @return javax.swing.JTextField
379
         */
380
        private javax.swing.JTextField getTIzquierda() {
381
                if (tIzquierda == null) {
382
                        tIzquierda = new javax.swing.JTextField();
383
                        tIzquierda.setBounds(207, 55, 48, 16);
384
                        tIzquierda.setText("0.5");
385
                        tIzquierda.setEnabled(false);
386
                }
387

    
388
                return tIzquierda;
389
        }
390

    
391
        /**
392
         * This method initializes tDerecha
393
         *
394
         * @return javax.swing.JTextField
395
         */
396
        private javax.swing.JTextField getTDerecha() {
397
                if (tDerecha == null) {
398
                        tDerecha = new javax.swing.JTextField();
399
                        tDerecha.setBounds(207, 72, 48, 16);
400
                        tDerecha.setText("0.5");
401
                        tDerecha.setEnabled(false);
402
                }
403

    
404
                return tDerecha;
405
        }
406

    
407
        /**
408
         * This method initializes lUnidades
409
         *
410
         * @return javax.swing.JLabel
411
         */
412
        private javax.swing.JLabel getLUnidades() {
413
                if (lUnidades == null) {
414
                        lUnidades = new javax.swing.JLabel();
415
                        lUnidades.setBounds(207, 36, 134, 18);
416
                        lUnidades.setText(PluginServices.getText(this, "map_units"));
417
                }
418

    
419
                return lUnidades;
420
        }
421

    
422
        /**
423
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
424
         */
425
        public ViewInfo getViewInfo() {
426
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
427
                m_viewinfo.setTitle(PluginServices.getText(this, "ajustes_linea_grafica"));
428

    
429
                return m_viewinfo;
430
        }
431

    
432
        /**
433
         * This method initializes bAceptar
434
         *
435
         * @return javax.swing.JButton
436
         */
437
        private javax.swing.JButton getBAceptar() {
438
                if (bAceptar == null) {
439
                        bAceptar = new javax.swing.JButton();
440
                        bAceptar.setBounds(134, 193, 100, 20);
441
                        bAceptar.setText(PluginServices.getText(this, "Aceptar"));
442
                        bAceptar.addActionListener(new java.awt.event.ActionListener() {
443
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
444
                                                double x = Double.parseDouble(getTIzquierda().getText()
445
                                                                                                                  .toString());
446
                                                double y = Double.parseDouble(getTSuperior().getText()
447
                                                                                                                  .toString());
448
                                                double w = Double.parseDouble(getTDerecha().getText()
449
                                                                                                                  .toString());
450
                                                double h = Double.parseDouble(getTInferior().getText()
451
                                                                                                                  .toString());
452

    
453
                                                if (!getChbAgrupar().isSelected()) {
454
                                                        Rectangle2D.Double re = new Rectangle2D.Double();
455

    
456
                                                        if (getRbSeleccionados().isSelected()) {
457
                                                                if (selecList.size() > 0) {
458
                                                                        re.setRect(((IFFrame) selecList.get(0)).getBoundBox());
459
                                                                }
460

    
461
                                                                for (int i = 1; i < selecList.size(); i++) {
462
                                                                        Rectangle2D.Double rectaux = ((IFFrame) selecList.get(i)).getBoundBox();
463
                                                                        re.add(rectaux);
464
                                                                }
465

    
466
                                                                //                                                crear un Rect?ngulo alrededor de los fframes seleccionados. 
467
                                                        } else if (getRbTodos().isSelected()) {
468
                                                                if (layout.getFFrames().size() > 0) {
469
                                                                        re.setRect(((IFFrame) layout.getFFrames()
470
                                                                                                                                .get(0)).getBoundBox());
471
                                                                }
472

    
473
                                                                for (int i = 1; i < layout.getFFrames().size();
474
                                                                                i++) {
475
                                                                        Rectangle2D.Double rectaux = ((IFFrame) layout.getFFrames()
476
                                                                                                                                                                  .get(i)).getBoundBox();
477
                                                                        re.add(rectaux);
478
                                                                }
479

    
480
                                                                //                                                creaer un Rect?ngulo que incluya a todos los fframes.
481
                                                        } else if (getRbMargen().isSelected()) {
482
                                                                //                                                creaer un Rect?ngulo en los m?rgenes del Layout.
483
                                                                re.setRect(layout.getAtributes().getArea());
484
                                                        }
485

    
486
                                                        re.setRect(re.x - x, re.y - y, re.width + x + w,
487
                                                                re.height + y + h);
488

    
489
                                                        Rectangle2D.Double rectangle = FLayoutUtilities.fromSheetRect(re,
490
                                                                        layout.getAT());
491

    
492
                                                        /*if (layout.isCuadricula()){
493
                                                           FLayoutUtilities.setRectGrid(rectangle,
494
                                                                              layout.getAtributes().getUnitInPixelsX(),layout.getAtributes().getUnitInPixelsY(), layout.getAT());
495
                                                           }
496
                                                         */
497
                                                        re = FLayoutUtilities.toSheetRect(rectangle,
498
                                                                        layout.getAT());
499
                                                        fframegraphics.setBoundBox(re);
500
                                                        layout.addFFrame(fframegraphics, true);
501
                                                } else { //Agrupar
502

    
503
                                                        Rectangle2D.Double re = new Rectangle2D.Double();
504
                                                        FFrameGroup fframegroup = new FFrameGroup();
505

    
506
                                                        if (getRbSeleccionados().isSelected()) {
507
                                                                if (selecList.size() > 0) {
508
                                                                        re.setRect(((IFFrame) selecList.get(0)).getBoundBox());
509
                                                                }
510

    
511
                                                                for (int i = 1; i < selecList.size(); i++) {
512
                                                                        Rectangle2D.Double rectaux = ((IFFrame) selecList.get(i)).getBoundBox();
513
                                                                        re.add(rectaux);
514
                                                                }
515

    
516
                                                                //                                                crear un Rect?ngulo alrededor de los fframes seleccionados. 
517
                                                        } else if (getRbTodos().isSelected()) {
518
                                                                if (layout.getFFrames().size() > 0) {
519
                                                                        re.setRect(((IFFrame) layout.getFFrames()
520
                                                                                                                                .get(0)).getBoundBox());
521
                                                                }
522

    
523
                                                                for (int i = 1; i < layout.getFFrames().size();
524
                                                                                i++) {
525
                                                                        Rectangle2D.Double rectaux = ((IFFrame) layout.getFFrames()
526
                                                                                                                                                                  .get(i)).getBoundBox();
527
                                                                        ((IFFrame) layout.getFFrames().get(i)).setSelected(true);
528
                                                                        re.add(rectaux);
529
                                                                }
530

    
531
                                                                //                                                creaer un Rect?ngulo que incluya a todos los fframes.
532
                                                        } else if (getRbMargen().isSelected()) {
533
                                                                //                                                creaer un Rect?ngulo en los m?rgenes del Layout.
534
                                                                re.setRect(layout.getAtributes().getArea());
535
                                                        }
536

    
537
                                                        re.setRect(re.x - x, re.y - y, re.width + x + w,
538
                                                                re.height + y + h);
539

    
540
                                                        Rectangle2D.Double rectangle = FLayoutUtilities.fromSheetRect(re,
541
                                                                        layout.getAT());
542

    
543
                                                        /*if (layout.isCuadricula()){
544
                                                           FLayoutUtilities.setRectGrid(rectangle,
545
                                                                           layout.getAtributes().getUnitInPixelsX(),layout.getAtributes().getUnitInPixelsY(), layout.getAT());
546
                                                           }*/
547
                                                        re.setRect(FLayoutUtilities.toSheetRect(rectangle,
548
                                                                        layout.getAT()));
549
                                                        fframegraphics.setBoundBox(re);
550
                                                        layout.addFFrame(fframegraphics, false);
551
                                                        flg.grouping();
552
                                                }
553

    
554
                                                PluginServices.getMDIManager().closeView(FBorderDialog.this);
555
                                                layout.setStatus(Layout.DESACTUALIZADO);
556
                                                layout.repaint();
557
                                        }
558
                                });
559
                }
560

    
561
                return bAceptar;
562
        }
563

    
564
        /**
565
         * This method initializes bCancelar
566
         *
567
         * @return javax.swing.JButton
568
         */
569
        private javax.swing.JButton getBCancelar() {
570
                if (bCancelar == null) {
571
                        bCancelar = new javax.swing.JButton();
572
                        bCancelar.setBounds(251, 193, 100, 20);
573
                        bCancelar.setText(PluginServices.getText(this, "Cancelar"));
574
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
575
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
576
                                                PluginServices.getMDIManager().closeView(FBorderDialog.this);
577
                                        }
578
                                });
579
                }
580

    
581
                return bCancelar;
582
        }
583

    
584
        /**
585
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
586
         */
587
        public void viewActivated() {
588
        }
589

    
590
        /**
591
         * This method initializes bConfigurar
592
         *
593
         * @return javax.swing.JButton
594
         */
595
        private javax.swing.JButton getBConfigurar() {
596
                if (bConfigurar == null) {
597
                        bConfigurar = new javax.swing.JButton();
598
                        bConfigurar.setBounds(17, 193, 100, 20);
599
                        bConfigurar.setText(PluginServices.getText(this, "configurar"));
600
                        bConfigurar.addActionListener(new java.awt.event.ActionListener() {
601
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
602
                                                FFrameGraphicsDialog graphicsdialog = new FFrameGraphicsDialog(layout,
603
                                                                fframegraphics);
604

    
605
                                                PluginServices.getMDIManager().addView(graphicsdialog);
606
                                        }
607
                                });
608
                }
609

    
610
                return bConfigurar;
611
        }
612
}