Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / gui / dialogs / FConfigLayoutDialog.java @ 217

History | View | Annotate | Download (35.4 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.gui.dialogs;
23

    
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.geom.Rectangle2D;
30
import java.text.NumberFormat;
31

    
32
import javax.swing.ButtonGroup;
33
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
35
import javax.swing.JList;
36
import javax.swing.JOptionPane;
37
import javax.swing.JPanel;
38
import javax.swing.JScrollPane;
39

    
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.ui.mdiManager.IWindow;
42
import org.gvsig.andami.ui.mdiManager.IWindowListener;
43
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
44
import org.gvsig.andami.ui.mdiManager.WindowInfo;
45
import org.gvsig.app.ApplicationLocator;
46
import org.gvsig.app.ApplicationManager;
47
import org.gvsig.app.project.ProjectManager;
48
import org.gvsig.app.project.documents.layout.Attributes;
49
import org.gvsig.app.project.documents.layout.LayoutContext;
50
import org.gvsig.app.project.documents.layout.LayoutManager;
51
import org.gvsig.app.project.documents.layout.Size;
52
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
53
import org.gvsig.app.project.documents.layout.fframes.ListViewModel;
54
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
55
import org.gvsig.app.project.documents.view.ViewDocument;
56
import org.gvsig.app.project.documents.view.ViewManager;
57
import org.gvsig.fmap.mapcontext.MapContext;
58
import org.gvsig.i18n.Messages;
59
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
60

    
61
/**
62
 * Clase para configurar el Layout.
63
 * 
64
 * @author Vicente Caballero Navarro
65
 */
66
public class FConfigLayoutDialog extends JPanel implements SingletonWindow {
67

    
68
    private static final long serialVersionUID = -425263925680280142L;
69
    private javax.swing.JLabel lTamPag = null;
70
    private javax.swing.JComboBox cbTipoFolio = null;
71
    private javax.swing.JComboBox cbUnidades = null;
72
    private javax.swing.JLabel lAnchura = null;
73
    private javax.swing.JLabel lAltura = null;
74
    private javax.swing.JTextField tAncho = null;
75
    private javax.swing.JTextField tAlto = null;
76
    private javax.swing.JLabel lOrientacion = null;
77
    private javax.swing.JLabel lMargenes = null;
78
    private javax.swing.JCheckBox chbMargenes = null;
79
    private javax.swing.JLabel lSuperior = null;
80
    private javax.swing.JTextField tSuperior = null;
81
    private javax.swing.JLabel lIzquierdo = null;
82
    private javax.swing.JTextField tIzquierdo = null;
83
    private javax.swing.JLabel lInferior = null;
84
    private javax.swing.JTextField tInferior = null;
85
    private javax.swing.JLabel lDerecho = null;
86
    private javax.swing.JTextField tDerecho = null;
87
    private javax.swing.JLabel lResolucion = null;
88
    private javax.swing.JComboBox cbResolucion = null;
89
    private javax.swing.JButton bAceptar = null;
90
    private javax.swing.JButton bCancelar = null;
91
    private LayoutPanel m_layout = null;
92
    private JPanel pOrientation = null;
93
    private javax.swing.JRadioButton rbHorizontal = null;
94
    private javax.swing.JRadioButton rbVertical = null;
95
    private int unit = 2;
96
    private int type = 0;
97
    private boolean isLand = true;
98
    private boolean margin = false;
99
    private int resolution = 1;
100
    private double der = 2.54;
101
    private double izq = 2.54;
102
    private double sup = 2.54;
103
    private double inf = 2.54;
104
    private NumberFormat nf = NumberFormat.getInstance();
105
        private JList liViews = null;
106
        private boolean showViewList;
107
        private JCheckBox chbViews = null;
108
        private JButton btConfigView = null;
109
        private ViewDocument createdView = null;
110
        private JScrollPane jViewScrollPane = null;
111
        private WindowInfo windowInfo = null;
112

    
113
    /**
114
     * This is the default constructor
115
     * 
116
     * @param layout
117
     *            Referencia al Layout.
118
     */
119
    public FConfigLayoutDialog(LayoutPanel layout) {
120
            this(layout, false);
121
    }
122
    
123
    /**
124
     * This is the default constructor
125
     * 
126
     * @param layout
127
     *            Referencia al Layout.
128
     */
129
    public FConfigLayoutDialog(LayoutPanel layout, boolean showViewList) {
130
        super();
131
        m_layout = layout;
132
        this.showViewList = showViewList;
133
        initialize();
134
    }
135

    
136
    /**
137
     * This method initializes this
138
     */
139
    private void initialize() {
140
            int row = 0;
141
        nf.setMaximumFractionDigits(2);
142
        this.setLayout(new GridBagLayout());
143
        GridBagConstraints c = new GridBagConstraints();
144
        type = m_layout.getLayoutContext().getAttributes().getType();
145
        unit = m_layout.getLayoutContext().getAttributes().getSelTypeUnit();
146
        isLand = m_layout.getLayoutContext().getAttributes().isLandscape();
147
        sup = m_layout.getLayoutContext().getAttributes().getAreaInsets()[0];
148
        inf = m_layout.getLayoutContext().getAttributes().getAreaInsets()[1];
149
        izq = m_layout.getLayoutContext().getAttributes().getAreaInsets()[2];
150
        der = m_layout.getLayoutContext().getAttributes().getAreaInsets()[3];
151
        c.fill = GridBagConstraints.HORIZONTAL;
152
        c.anchor = GridBagConstraints.LINE_START;
153
        c.insets = new Insets(5, 5, 5, 5);
154
        c.gridx = 0;
155
        c.gridy = row++;
156
        c.gridwidth = 1;
157
        this.add(getLTamPag(), c);
158
        c.gridx = GridBagConstraints.RELATIVE;
159
        c.fill = GridBagConstraints.HORIZONTAL;
160
        c.gridwidth = GridBagConstraints.REMAINDER;
161
        this.add(getCbTipoFolio(), c);
162
        c.gridx = 0;
163
        c.gridy = row++;
164
        c.gridwidth = 1;
165
        c.fill = GridBagConstraints.NONE;
166
        this.add(getLAnchura(), c);
167
        c.gridx = 1;
168
        this.add(getTAncho(), c);
169
        c.gridx = 2;
170
        this.add(getLAltura(), c);
171
        c.gridx = 3;
172
        this.add(getTAlto(), c);
173
        c.gridx = 4;
174
        c.gridwidth = GridBagConstraints.REMAINDER;
175
        c.fill = GridBagConstraints.HORIZONTAL;
176
        this.add(getCbUnidades(), c);
177
        c.gridx = 0;
178
        c.gridy = row++;
179
        c.gridwidth = 1;
180
        this.add(getLOrientacion(), c);
181
        c.gridx = GridBagConstraints.RELATIVE;
182
        c.gridwidth = GridBagConstraints.REMAINDER;
183
        this.add(getOrientationPanel(), c);
184
        c.gridy = row++;
185
        c.gridx = 0;
186
        c.gridwidth = 1;
187
        this.add(getLResolucion(), c);
188
        c.gridx = GridBagConstraints.RELATIVE;
189
        c.gridwidth = GridBagConstraints.REMAINDER;
190
        this.add(getCbResolucion(), c);
191
        if (this.showViewList) {
192
                c.gridy = row++;
193
            c.gridx = 0;
194
            c.gridwidth = 1;
195
            c.anchor = GridBagConstraints.PAGE_START;
196
            this.add(getChbViews(), c);
197
            c.gridx = 1;
198
            c.gridwidth = GridBagConstraints.REMAINDER;
199
            this.add(getViewScrollPane(), c);
200
            c.anchor = GridBagConstraints.LINE_START;
201
            c.gridy = row++;
202
            c.gridx = 1;
203
            c.gridwidth = 1;
204
            this.add(getBtConfigView(), c);
205
        }
206
        c.gridy = row++;
207
        c.gridx = 0;
208
        c.gridwidth = GridBagConstraints.REMAINDER;
209
        this.add(getChbMargenes(), c);
210
        c.fill = GridBagConstraints.NONE;
211
        c.gridy = row++;
212
        c.gridx = 0;
213
        c.gridwidth = 1;
214
        this.add(getLSuperior(), c);
215
        c.gridx = GridBagConstraints.RELATIVE;
216
        this.add(getTSuperior(), c);
217
        c.gridx = GridBagConstraints.RELATIVE;
218
        this.add(getLIzquierdo(), c);
219
        this.add(getTIzquierdo(), c);
220
        c.gridy = row++;
221
        c.gridx = 0;
222
        this.add(getLInferior(), c);
223
        c.gridx = GridBagConstraints.RELATIVE;
224
        this.add(getTInferior(), c);
225
        this.add(getLDerecho(), c);
226
        this.add(getTDerecho(), c);
227
        c.gridy = row++;
228
        c.gridx = 3;
229
        c.insets = new Insets(15, 5, 10, 5);
230
        this.add(getBAceptar(), c);
231
        c.gridx = GridBagConstraints.RELATIVE;
232
        this.add(getBCancelar(), c);
233
    }
234

    
235
    /**
236
     * This method initializes lTamPag
237
     * 
238
     * @return javax.swing.JLabel
239
     */
240
    private javax.swing.JLabel getLTamPag() {
241
        if (lTamPag == null) {
242
            lTamPag = new javax.swing.JLabel();
243
            lTamPag
244
                .setText(PluginServices.getText(this, "tamano_pagina"));
245
        }
246

    
247
        return lTamPag;
248
    }
249

    
250
    /**
251
     * This method initializes cbTipoFolio
252
     * 
253
     * @return javax.swing.JComboBox
254
     */
255
    private javax.swing.JComboBox getCbTipoFolio() {
256
        if (cbTipoFolio == null) {
257
            cbTipoFolio = new javax.swing.JComboBox();
258
            cbTipoFolio.addItem(PluginServices.getText(this,
259
                "Igual_que_la_impresora"));
260
            cbTipoFolio.addItem(PluginServices.getText(this, "A4"));
261
            cbTipoFolio.addItem(PluginServices.getText(this, "A3"));
262
            cbTipoFolio.addItem(PluginServices.getText(this, "A2"));
263
            cbTipoFolio.addItem(PluginServices.getText(this, "A1"));
264
            cbTipoFolio.addItem(PluginServices.getText(this, "A0"));
265
            cbTipoFolio.addItem(PluginServices.getText(this, "Personalizado"));
266

    
267
            cbTipoFolio.setSelectedIndex(m_layout.getLayoutContext()
268
                .getAttributes().getType());
269
            cbTipoFolio.addActionListener(new java.awt.event.ActionListener() {
270

    
271
                public void actionPerformed(java.awt.event.ActionEvent e) {
272
                    type = cbTipoFolio.getSelectedIndex();
273

    
274
                    Size size =
275
                        m_layout.getLayoutContext().getAttributes()
276
                            .getSizeinUnits(isLand, type);
277
                    getTAlto().setText(
278
                        String.valueOf(nf.format(size.getAlto())));
279
                    getTAncho().setText(
280
                        String.valueOf(nf.format(size.getAncho())));
281
                    setMargin(margin);
282
                    if (cbTipoFolio.getSelectedItem().equals(
283
                        PluginServices.getText(this, "Personalizado"))) {
284
                        getTAlto().setEnabled(true);
285
                        getTAncho().setEnabled(true);
286
                        getRbVertical().setSelected(true);
287
                        isLand = false;
288
                        getRbVertical().setEnabled(false);
289
                        getRbHorizontal().setEnabled(false);
290
                    } else {
291
                        getTAlto().setEnabled(false);
292
                        getTAncho().setEnabled(false);
293
                        getRbVertical().setEnabled(true);
294
                        getRbHorizontal().setEnabled(true);
295
                    }
296
                }
297
            });
298
        }
299

    
300
        return cbTipoFolio;
301
    }
302

    
303
    /**
304
     * This method initializes cbUnidades
305
     * 
306
     * @return javax.swing.JComboBox
307
     */
308
    private javax.swing.JComboBox getCbUnidades() {
309
        if (cbUnidades == null) {
310
            cbUnidades = new javax.swing.JComboBox();
311
            String[] names = MapContext.getDistanceNames();
312
            for (int i = 0; i < names.length; i++) {
313
                cbUnidades.addItem(PluginServices.getText(this, names[i]));
314
            }
315
            cbUnidades.setSelectedIndex(m_layout.getLayoutContext()
316
                .getAttributes().getSelTypeUnit());
317
            cbUnidades.addActionListener(new java.awt.event.ActionListener() {
318

    
319
                public void actionPerformed(java.awt.event.ActionEvent e) {
320
                    unit = cbUnidades.getSelectedIndex();
321
                    m_layout.getLayoutContext().getAttributes().setUnit(unit);
322

    
323
                    Size size =
324
                        m_layout.getLayoutContext().getAttributes()
325
                            .getSizeinUnits(isLand, type);
326
                    getTAlto().setText(
327
                        String.valueOf(nf.format(size.getAncho())));
328
                    getTAncho().setText(
329
                        String.valueOf(nf.format(size.getAlto())));
330
                    setMargin(margin);
331
                }
332
            });
333
        }
334

    
335
        return cbUnidades;
336
    }
337

    
338
    /**
339
     * This method initializes lAnchura
340
     * 
341
     * @return javax.swing.JLabel
342
     */
343
    private javax.swing.JLabel getLAnchura() {
344
        if (lAnchura == null) {
345
            lAnchura = new javax.swing.JLabel();
346
            lAnchura.setText(PluginServices.getText(this, "anchura"));
347
        }
348
        return lAnchura;
349
    }
350

    
351
    /**
352
     * This method initializes lAltura
353
     * 
354
     * @return javax.swing.JLabel
355
     */
356
    private javax.swing.JLabel getLAltura() {
357
        if (lAltura == null) {
358
            lAltura = new javax.swing.JLabel();
359
            lAltura.setText(PluginServices.getText(this, "altura"));
360
        }
361
        return lAltura;
362
    }
363

    
364
    /**
365
     * This method initializes tAncho
366
     * 
367
     * @return javax.swing.JTextField
368
     */
369
    private javax.swing.JTextField getTAncho() {
370
        if (tAncho == null) {
371
            tAncho = new javax.swing.JTextField(4);
372
            Size size =
373
                m_layout.getLayoutContext().getAttributes()
374
                    .getSizeinUnits(isLand, type);
375
            String s = String.valueOf(nf.format(size.getAncho()));
376
            tAncho.setText(s);
377
            if (getCbTipoFolio().getSelectedItem().equals(
378
                PluginServices.getText(this, "Personalizado"))) {
379
                    tAncho.setEnabled(true);
380
            } else {
381
                    tAncho.setEnabled(false);
382
            }
383
        }
384

    
385
        return tAncho;
386
    }
387

    
388
    /**
389
     * This method initializes tAlto
390
     * 
391
     * @return javax.swing.JTextField
392
     */
393
    private javax.swing.JTextField getTAlto() {
394
        if (tAlto == null) {
395
            tAlto = new javax.swing.JTextField(4);
396
            Size size =
397
                m_layout.getLayoutContext().getAttributes()
398
                    .getSizeinUnits(isLand, type);
399
            String s = String.valueOf(nf.format(size.getAlto()));
400
            tAlto.setText(s);
401
            if (getCbTipoFolio().getSelectedItem().equals(
402
                PluginServices.getText(this, "Personalizado"))) {
403
                    tAlto.setEnabled(true);
404
            } else {
405
                    tAlto.setEnabled(false);
406
            }
407
        }
408

    
409
        return tAlto;
410
    }
411

    
412
    /**
413
     * This method initializes lOrientacion
414
     * 
415
     * @return javax.swing.JLabel
416
     */
417
    private javax.swing.JLabel getLOrientacion() {
418
        if (lOrientacion == null) {
419
            lOrientacion = new javax.swing.JLabel();
420
            lOrientacion.setText(PluginServices.getText(this, "orientacion"));
421
        }
422

    
423
        return lOrientacion;
424
    }
425

    
426
    /**
427
     * This method initializes lMargenes
428
     * 
429
     * @return javax.swing.JLabel
430
     */
431
    private javax.swing.JLabel getLMargenes() {
432
        if (lMargenes == null) {
433
            lMargenes = new javax.swing.JLabel();
434
            lMargenes.setText(PluginServices.getText(this, "margenes"));
435
        }
436

    
437
        return lMargenes;
438
    }
439

    
440
    /**
441
     * Inserta si se dibuja los margenes sobre el Layout o no.
442
     * 
443
     * @param b
444
     *            True si se tiene que dibujar los margenes.
445
     */
446
    private void setMargin(boolean b) {
447
        margin = b;
448

    
449
        if (b) {
450
            getTSuperior().setText(
451
                String.valueOf(nf.format(m_layout.getLayoutContext()
452
                    .getAttributes().toUnits(sup))));
453
            getTIzquierdo().setText(
454
                String.valueOf(nf.format(m_layout.getLayoutContext()
455
                    .getAttributes().toUnits(izq))));
456
            getTInferior().setText(
457
                String.valueOf(nf.format(m_layout.getLayoutContext()
458
                    .getAttributes().toUnits(inf))));
459
            getTDerecho().setText(
460
                String.valueOf(nf.format(m_layout.getLayoutContext()
461
                    .getAttributes().toUnits(der))));
462
            getTSuperior().setEnabled(true);
463
            getTIzquierdo().setEnabled(true);
464
            getTInferior().setEnabled(true);
465
            getTDerecho().setEnabled(true);
466
        } else {
467
            getTSuperior().setText("");
468
            getTIzquierdo().setText("");
469
            getTInferior().setText("");
470
            getTDerecho().setText("");
471
            getTSuperior().setEnabled(false);
472
            getTIzquierdo().setEnabled(false);
473
            getTInferior().setEnabled(false);
474
            getTDerecho().setEnabled(false);
475
        }
476
    }
477

    
478
    /**
479
     * This method initializes chbMargenes
480
     * 
481
     * @return javax.swing.JCheckBox
482
     */
483
    private javax.swing.JCheckBox getChbMargenes() {
484
        if (chbMargenes == null) {
485
            chbMargenes = new javax.swing.JCheckBox();
486
            chbMargenes.setText(PluginServices.getText(this,
487
                "personalizar_margenes"));
488
            chbMargenes.setSelected(m_layout.getLayoutContext().getAttributes()
489
                .isMargin());
490
            setMargin(m_layout.getLayoutContext().getAttributes().isMargin());
491
            chbMargenes.addActionListener(new java.awt.event.ActionListener() {
492

    
493
                public void actionPerformed(java.awt.event.ActionEvent e) {
494
                    if (chbMargenes.isSelected()) {
495
                        margin = true;
496
                    } else {
497
                        margin = false;
498
                    }
499

    
500
                    setMargin(margin);
501
                }
502
            });
503
        }
504

    
505
        return chbMargenes;
506
    }
507

    
508
    /**
509
     * This method initializes lSuperior
510
     * 
511
     * @return javax.swing.JLabel
512
     */
513
    private javax.swing.JLabel getLSuperior() {
514
        if (lSuperior == null) {
515
            lSuperior = new javax.swing.JLabel();
516
            lSuperior.setText(PluginServices.getText(this, "Superior"));
517
        }
518

    
519
        return lSuperior;
520
    }
521

    
522
    /**
523
     * This method initializes tSuperior
524
     * 
525
     * @return javax.swing.JTextField
526
     */
527
    private javax.swing.JTextField getTSuperior() {
528
        if (tSuperior == null) {
529
            tSuperior = new javax.swing.JTextField(4);
530
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
531
                tSuperior.setText(String.valueOf(nf.format(m_layout
532
                    .getLayoutContext().getAttributes().toUnits(sup))));
533
            }
534
        }
535

    
536
        return tSuperior;
537
    }
538

    
539
    /**
540
     * This method initializes lIzquierdo
541
     * 
542
     * @return javax.swing.JLabel
543
     */
544
    private javax.swing.JLabel getLIzquierdo() {
545
        if (lIzquierdo == null) {
546
            lIzquierdo = new javax.swing.JLabel();
547
            lIzquierdo.setText(PluginServices.getText(this, "Izquierdo"));
548
        }
549

    
550
        return lIzquierdo;
551
    }
552

    
553
    /**
554
     * This method initializes tIzquierdo
555
     * 
556
     * @return javax.swing.JTextField
557
     */
558
    private javax.swing.JTextField getTIzquierdo() {
559
        if (tIzquierdo == null) {
560
            tIzquierdo = new javax.swing.JTextField(4);
561
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
562
                tIzquierdo.setText(String.valueOf(nf.format(m_layout
563
                    .getLayoutContext().getAttributes().toUnits(izq))));
564
            }
565
        }
566

    
567
        return tIzquierdo;
568
    }
569

    
570
    /**
571
     * This method initializes lInferior
572
     * 
573
     * @return javax.swing.JLabel
574
     */
575
    private javax.swing.JLabel getLInferior() {
576
        if (lInferior == null) {
577
            lInferior = new javax.swing.JLabel();
578
            lInferior.setText(PluginServices.getText(this, "Inferior"));
579
        }
580

    
581
        return lInferior;
582
    }
583

    
584
    /**
585
     * This method initializes tInferior
586
     * 
587
     * @return javax.swing.JTextField
588
     */
589
    private javax.swing.JTextField getTInferior() {
590
        if (tInferior == null) {
591
            tInferior = new javax.swing.JTextField(4);
592
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
593
                tInferior.setText(String.valueOf(nf.format(m_layout
594
                    .getLayoutContext().getAttributes().toUnits(inf))));
595
            }
596
        }
597

    
598
        return tInferior;
599
    }
600

    
601
    /**
602
     * This method initializes lDerecho
603
     * 
604
     * @return javax.swing.JLabel
605
     */
606
    private javax.swing.JLabel getLDerecho() {
607
        if (lDerecho == null) {
608
            lDerecho = new javax.swing.JLabel();
609
            lDerecho.setText(PluginServices.getText(this, "Derecho"));
610
        }
611

    
612
        return lDerecho;
613
    }
614

    
615
    /**
616
     * This method initializes tDerecho
617
     * 
618
     * @return javax.swing.JTextField
619
     */
620
    private javax.swing.JTextField getTDerecho() {
621
        if (tDerecho == null) {
622
            tDerecho = new javax.swing.JTextField(4);
623
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
624
                tDerecho.setText(String.valueOf(nf.format(m_layout
625
                    .getLayoutContext().getAttributes().toUnits(der))));
626
            }
627
        }
628

    
629
        return tDerecho;
630
    }
631

    
632
    /**
633
     * This method initializes lResolucion
634
     * 
635
     * @return javax.swing.JLabel
636
     */
637
    private javax.swing.JLabel getLResolucion() {
638
        if (lResolucion == null) {
639
            lResolucion = new javax.swing.JLabel();
640
            lResolucion.setText(PluginServices.getText(this,
641
                "resolucion_resultado"));
642
        }
643

    
644
        return lResolucion;
645
    }
646

    
647
    /**
648
     * This method initializes cbResolucion
649
     * 
650
     * @return javax.swing.JComboBox
651
     */
652
    private javax.swing.JComboBox getCbResolucion() {
653
        if (cbResolucion == null) {
654
            cbResolucion = new javax.swing.JComboBox();
655
            cbResolucion.addItem(PluginServices.getText(this, "High_600_dpi"));
656
            cbResolucion.addItem(PluginServices.getText(this, "Normal_300_dpi"));
657
            cbResolucion.addItem(PluginServices.getText(this, "Low_72_dpi"));
658
            cbResolucion.setSelectedIndex(m_layout.getLayoutContext()
659
                .getAttributes().getResolution());
660
            cbResolucion.addActionListener(new java.awt.event.ActionListener() {
661

    
662
                public void actionPerformed(java.awt.event.ActionEvent e) {
663
                    resolution = cbResolucion.getSelectedIndex();
664
                }
665
            });
666
        }
667

    
668
        return cbResolucion;
669
    }
670

    
671
    /**
672
     * This method initializes bAceptar
673
     * 
674
     * @return javax.swing.JButton
675
     */
676
    private javax.swing.JButton getBAceptar() {
677
        if (bAceptar == null) {
678
            bAceptar = new javax.swing.JButton();
679
            bAceptar.setText(PluginServices.getText(this, "Aceptar"));
680
            bAceptar.addActionListener(new java.awt.event.ActionListener() {
681

    
682
                public void actionPerformed(java.awt.event.ActionEvent e) {
683
                        Attributes attributes = m_layout.getLayoutContext().getAttributes();
684
                        attributes.setUnit(unit);
685

    
686
                    if (isLand) {
687
                            attributes.setIsLandScape(true);
688
                    } else {
689
                            attributes.setIsLandScape(false);
690
                    }
691

    
692
                    attributes.setType(type);
693
                    attributes.resetSizeinUnits(isLand);
694
                    obtainArea();
695

    
696
                    double[] area = { sup, inf, izq, der };
697

    
698
                    if (type == Attributes.CUSTOM) {
699
                        String width = getTAncho().getText().replace(',', '.');
700
                        String height = getTAlto().getText().replace(',', '.');
701
                        Attributes.CUSTOM_PAPER_SIZE =
702
                            new Size(
703
                                Double.valueOf(height).doubleValue(),
704
                                Double.valueOf(width).doubleValue());
705
                        attributes.m_sizePaper =
706
                            Attributes.CUSTOM_PAPER_SIZE;
707
                    }
708
                    attributes.setType(type);
709
                    m_layout.obtainRect(false);
710
                    m_layout
711
                        .getLayoutContext()
712
                        .getAttributes()
713
                        .setSelectedOptions(type, unit, isLand, margin,
714
                            resolution, area);
715
                    if (showViewList && getChbViews().isSelected()) { // a view has been selected
716
                            ViewDocument vd = getSelectedView();
717
                            ProjectManager projectManager = ApplicationLocator.getProjectManager();
718
                        LayoutManager layoutManager = (LayoutManager) projectManager.getDocumentManager(LayoutManager.TYPENAME);
719
                        FFrameView ffv = (FFrameView) layoutManager.createFrame(FFrameView.PERSISTENCE_DEFINITION_NAME);
720
                        ffv.setDocument(m_layout.getDocument());
721
                        LayoutContext lctxt = m_layout.getLayoutContext();
722
                        ffv.setLayoutContext(lctxt);
723
                            ffv.setBoundBox(new Rectangle2D.Double(izq, sup, attributes.getPaperSize().getAncho()-(izq+der), attributes.getPaperSize().getAlto()-(sup+inf)));
724
                            ffv.setView(vd);
725
                            lctxt.addFFrame(ffv, true, true);
726
                    }
727
                    if (createdView!=null && createdView!=getSelectedView()) { // a view was created but later de-selected
728
                            deleteView();
729
                    }
730
                    PluginServices.getMDIManager().closeWindow(
731
                        FConfigLayoutDialog.this);
732
                    m_layout.getLayoutControl().fullRect();
733
                }
734
            });
735
        }
736

    
737
        return bAceptar;
738
    }
739

    
740
    /**
741
     * This method initializes bCancelar
742
     * 
743
     * @return javax.swing.JButton
744
     */
745
    private javax.swing.JButton getBCancelar() {
746
        if (bCancelar == null) {
747
            bCancelar = new javax.swing.JButton();
748
            bCancelar.setText(PluginServices.getText(this, "Cancelar"));
749
            bCancelar.addActionListener(new java.awt.event.ActionListener() {
750

    
751
                public void actionPerformed(java.awt.event.ActionEvent e) {
752
                    if (createdView!=null) {
753
                            deleteView();
754
                    }
755
                    PluginServices.getMDIManager().closeWindow(
756
                        FConfigLayoutDialog.this);
757
                }
758
            });
759
        }
760

    
761
        return bCancelar;
762
    }
763

    
764
    private JPanel getOrientationPanel() {
765
            if (pOrientation == null) {
766
                    pOrientation = new JPanel(new GridBagLayout());
767
                    GridBagConstraints c = new GridBagConstraints();
768
                c.anchor = GridBagConstraints.WEST;
769
                c.gridx = 0;
770
                c.gridy = 0;
771
                c.insets = new Insets(0, 0, 0, 10);
772
                pOrientation.add(getRbHorizontal(), c);
773
                c.gridx = 1;
774
                c.insets = new Insets(0, 0, 0, 0);
775
                c.weightx = 1.0;
776
                c.fill = GridBagConstraints.HORIZONTAL;
777
                pOrientation.add(getRbVertical(), c);
778
                // add the radios to the button group
779
                ButtonGroup bgOrientation = new ButtonGroup();
780
                bgOrientation.add(getRbHorizontal());
781
                bgOrientation.add(getRbVertical());
782
                if (isLand) {
783
                        getRbHorizontal().setSelected(true);
784
                }
785
                else {
786
                        getRbVertical().setSelected(true);
787
                }
788
                if (getCbTipoFolio().getSelectedItem().equals(
789
                                PluginServices.getText(this, "Personalizado"))) {
790
                        rbHorizontal.setEnabled(false);
791
                        rbVertical.setEnabled(false);
792
                rbVertical.setSelected(true);
793
                        isLand = false;
794
                }
795
            }
796
            return pOrientation;
797
    }
798
    
799
    /**
800
     * This method initializes chbHorizontal
801
     * 
802
     * @return javax.swing.JCheckBox
803
     */
804
    private javax.swing.JRadioButton getRbHorizontal() {
805
        if (rbHorizontal == null) {
806
            rbHorizontal = new javax.swing.JRadioButton();
807
            rbHorizontal.setText(PluginServices.getText(this, "horizontal"));
808
            rbHorizontal
809
            .addActionListener(new java.awt.event.ActionListener() {
810
                    public void actionPerformed(java.awt.event.ActionEvent e) {
811
                            isLand = true;
812
                            double iz = izq;
813
                            izq = inf;
814
                            inf = der;
815
                            der = sup;
816
                            sup = iz;
817

    
818
                            setMargin(margin);
819

    
820
                            if (type == Attributes.CUSTOM) {
821
                                    Attributes.CUSTOM_PAPER_SIZE =
822
                                                    new Size(Double.valueOf(
823
                                                                    getTAlto().getText()).doubleValue(),
824
                                                                    Double.valueOf(getTAncho().getText())
825
                                                                    .doubleValue());
826
                            }
827

    
828
                            Size size =
829
                                            m_layout.getLayoutContext().getAttributes()
830
                                            .getSizeinUnits(isLand, type);
831
                            getTAncho().setText(
832
                                            String.valueOf(nf.format(size.getAncho())));
833
                            getTAlto().setText(
834
                                            String.valueOf(nf.format(size.getAlto())));
835
                    }
836
            });
837
        }
838

    
839
        return rbHorizontal;
840
    }
841

    
842
    /**
843
     * This method initializes chbVertical
844
     * 
845
     * @return javax.swing.JCheckBox
846
     */
847
    private javax.swing.JRadioButton getRbVertical() {        if (rbVertical == null) {
848
                rbVertical = new javax.swing.JRadioButton();
849
                rbVertical.setText(PluginServices.getText(this, "vertical"));
850
                rbVertical.addActionListener(new java.awt.event.ActionListener() {
851

    
852
                        public void actionPerformed(java.awt.event.ActionEvent e) {
853
                                isLand = false;
854
                                double in = inf;
855
                                inf = izq;
856
                                izq = sup;
857
                                sup = der;
858
                                der = in;
859

    
860
                                setMargin(margin);
861

    
862
                                if (type == Attributes.CUSTOM) {
863
                                        Attributes.CUSTOM_PAPER_SIZE =
864
                                                        new Size(Double.valueOf(getTAlto().getText())
865
                                                                        .doubleValue(), Double.valueOf(
866
                                                                                        getTAncho().getText()).doubleValue());
867
                                }
868

    
869
                                Size size =
870
                                                m_layout.getLayoutContext().getAttributes()
871
                                                .getSizeinUnits(isLand, type);
872
                                getTAncho().setText(
873
                                                String.valueOf(nf.format(size.getAncho())));
874
                                getTAlto().setText(
875
                                                String.valueOf(nf.format(size.getAlto())));
876
                        }
877
            });
878
        }
879

    
880
        return rbVertical;
881
    }
882

    
883
    /**
884
     * This method initializes liVistas
885
     * 
886
     * @return javax.swing.JList
887
     */
888
    private javax.swing.JList getViewList() {
889
                if (liViews  == null) {
890
            ListViewModel listModel = new ListViewModel();
891
            listModel.addCreateNewViewObj();
892
            if (listModel.addViews()) {
893
               JOptionPane.showMessageDialog(
894
                   ApplicationLocator.getManager().getRootComponent(),
895
                   Messages.getText("_Some_views_excluded_from_list_because_have_editing_layers"),
896
                   Messages.getText("Preparar_pagina"),
897
                   JOptionPane.WARNING_MESSAGE); 
898
            }
899
            
900
            liViews = new javax.swing.JList(listModel);
901
            liViews.setSelectedIndex(0);
902
                }
903
        return liViews;
904
    }
905
    
906
    private JScrollPane getViewScrollPane(){
907
            if (jViewScrollPane==null) {
908
                    jViewScrollPane = new javax.swing.JScrollPane();
909
                    jViewScrollPane.setViewportView(getViewList());
910
                    jViewScrollPane.setPreferredSize(new java.awt.Dimension(300, 100));            
911
            }
912
            return jViewScrollPane;
913
    }
914
    
915
    private JButton getBtConfigView() {
916
            if (btConfigView==null) {
917
                    UsabilitySwingManager manager = org.gvsig.tools.swing.api.ToolsSwingLocator.getUsabilitySwingManager();
918
                    btConfigView = manager.createJButton(Messages.getText("Configure_view"));
919
                    btConfigView.addActionListener(new ActionListener() {
920
                                public void actionPerformed(ActionEvent e) {
921
                                        ViewDocument view = FConfigLayoutDialog.this.getSelectedView();
922
                                        if (view!=null) {
923
                                                IWindow propWin = view.getPropertiesWindow();
924
                                                ApplicationManager manager = ApplicationLocator.getManager();
925
                                                manager.getUIManager().addWindow(propWin);
926
                                        }
927
                                }
928
                    });
929
            }
930
            return btConfigView;
931
    }
932
    
933
    protected ViewDocument getSelectedView() {
934
            Object selected = FConfigLayoutDialog.this.getViewList().getSelectedValue();
935
            ViewDocument view = null;
936
            if (selected instanceof ViewDocument) {
937
                    view = (ViewDocument) selected;
938
            }
939
            else if (selected==ListViewModel.CREATE_NEW_VIEW_OBJECT) {
940
                    if (FConfigLayoutDialog.this.createdView==null) {
941
                            view = createView();
942
                    }
943
                    else {
944
                            view = FConfigLayoutDialog.this.createdView;
945
                    }
946
            }
947
            return view;
948
    }
949
    
950
    private ViewDocument createView() {
951
        ProjectManager projectManager = ApplicationLocator.getProjectManager();
952
        ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME);
953
        createdView = (ViewDocument) viewManager.createDocument();
954
            ProjectManager.getInstance().getCurrentProject().addDocument(createdView);
955
            return createdView;
956
    }
957
    
958
    private void deleteView() {
959
            ProjectManager projectManager = ApplicationLocator.getProjectManager();
960
        ProjectManager.getInstance().getCurrentProject().removeDocument(createdView);
961
        createdView = null;
962
    }
963
    
964
    /**
965
     * This method initializes lResolucion
966
     * 
967
     * @return javax.swing.JLabel
968
     */
969
    private javax.swing.JCheckBox getChbViews() {
970
        if (chbViews == null) {
971
                chbViews = new JCheckBox(PluginServices.getText(this,
972
                    "Insert_view"));
973
                chbViews.setSelected(true);
974
        }
975

    
976
        return chbViews;
977
    }
978
    
979
    /*
980
     * (non-Javadoc)
981
     * 
982
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
983
     */
984
    public WindowInfo getWindowInfo() {
985
            if (windowInfo==null) {
986
                    windowInfo  = new WindowInfo(WindowInfo.RESIZABLE);
987
                    if (showViewList) {
988
                            windowInfo.setWidth(600);
989
                            windowInfo.setHeight(450);
990
                    }
991
                    else {
992
                            windowInfo.setWidth(550);
993
                            windowInfo.setHeight(300);                
994
                    }
995
                    windowInfo.setTitle(PluginServices.getText(this, "Preparar_pagina"));
996
            }
997
        return windowInfo;
998
    }
999

    
1000
    /**
1001
     * Obtiene el ?rea de los JtextField.
1002
     */
1003
    private void obtainArea() {
1004
        String s = (getTSuperior().getText());
1005
        s = s.replace(',', '.');
1006

    
1007
        if (s.length() == 0) {
1008
            s = "0";
1009
        }
1010

    
1011
        sup =
1012
            m_layout.getLayoutContext().getAttributes()
1013
                .fromUnits(Double.valueOf(s).doubleValue());
1014
        s = (getTIzquierdo().getText());
1015
        s = s.replace(',', '.');
1016

    
1017
        if (s.length() == 0) {
1018
            s = "0";
1019
        }
1020

    
1021
        izq =
1022
            m_layout.getLayoutContext().getAttributes()
1023
                .fromUnits(Double.valueOf(s).doubleValue());
1024
        s = (getTInferior().getText());
1025
        s = s.replace(',', '.');
1026

    
1027
        if (s.length() == 0) {
1028
            s = "0";
1029
        }
1030

    
1031
        inf =
1032
            m_layout.getLayoutContext().getAttributes()
1033
                .fromUnits(Double.valueOf(s).doubleValue());
1034
        s = (getTDerecho().getText());
1035
        s = s.replace(',', '.');
1036

    
1037
        if (s.length() == 0) {
1038
            s = "0";
1039
        }
1040

    
1041
        der =
1042
            m_layout.getLayoutContext().getAttributes()
1043
                .fromUnits(Double.valueOf(s).doubleValue());
1044
    }
1045

    
1046
    public Object getWindowProfile() {
1047
        return WindowInfo.DIALOG_PROFILE;
1048
    }
1049

    
1050
        public Object getWindowModel() {
1051
                // necessary for considering them as separate SingletonWindows depending showViewList option
1052
                if (showViewList) {
1053
                        return m_layout;
1054
                }
1055
                else {
1056
                        return m_layout.getLayoutControl();
1057
                }
1058
        }
1059
}