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 @ 1633

History | View | Annotate | Download (36.8 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.Dimension;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.awt.geom.Rectangle2D;
31
import java.text.NumberFormat;
32

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

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

    
65
/**
66
 * Dialog which can be used to configure the Layout page settings
67
 * 
68
 * @author Vicente Caballero Navarro
69
 * @author Cesar Martinez Izquierdo
70
 */
71
public class FConfigLayoutDialog extends JPanel implements ActionListener {
72

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

    
123
    /**
124
     * This is the default constructor
125
     * 
126
     * @param layout
127
     *            Referencia al Layout.
128
     */
129
    public FConfigLayoutDialog(LayoutPanel layout) {
130
            this(layout, false);
131
    }
132
    
133
    /**
134
     * This is the default constructor
135
     * 
136
     * @param layout
137
     *            Referencia al Layout.
138
     */
139
    public FConfigLayoutDialog(LayoutPanel layout, boolean showViewList) {
140
        super();
141
        m_layout = layout;
142
        temporaryAttributes = (Attributes) layout.getLayoutContext().getAttributes().clone();
143
        this.showViewList = showViewList;
144
        initialize();
145
    }
146

    
147
    /**
148
     * This method initializes this
149
     */
150
    private void initialize() {
151
            int row = 0;
152
        nf.setMaximumFractionDigits(2);
153
        this.setLayout(new GridBagLayout());
154
        GridBagConstraints c = new GridBagConstraints();
155
        type = temporaryAttributes.getType();
156
        unit = temporaryAttributes.getUnit();
157
        isLand = temporaryAttributes.isLandscape();
158
        sup = temporaryAttributes.getAreaInsets()[0];
159
        inf = temporaryAttributes.getAreaInsets()[1];
160
        izq = temporaryAttributes.getAreaInsets()[2];
161
        der = temporaryAttributes.getAreaInsets()[3];
162
        c.fill = GridBagConstraints.HORIZONTAL;
163
        c.anchor = GridBagConstraints.FIRST_LINE_START;
164
        c.insets = new Insets(5, 5, 5, 5);
165
        c.gridx = 0;
166
        c.gridy = row++;
167
        c.gridwidth = 1;
168
        this.add(getLTamPag(), c);
169
        c.gridx = GridBagConstraints.RELATIVE;
170
        c.fill = GridBagConstraints.HORIZONTAL;
171
        c.gridwidth = GridBagConstraints.REMAINDER;
172
        c.weightx = 1;
173
        this.add(getCbTipoFolio(), c);
174
        c.weightx = 0;
175
        c.gridx = 0;
176
        c.gridy = row++;
177
        c.gridwidth = 1;
178
        c.fill = GridBagConstraints.NONE;
179
        this.add(getLAnchura(), c);
180
        c.gridx = 1;
181
        this.add(getTAncho(), c);
182
        c.gridx = 2;
183
        this.add(getLAltura(), c);
184
        c.gridx = 3;
185
        this.add(getTAlto(), c);
186
        c.gridx = 4;
187
        c.gridwidth = GridBagConstraints.REMAINDER;
188
        c.fill = GridBagConstraints.HORIZONTAL;
189
        this.add(getCbUnidades(), c);
190
        c.gridx = 0;
191
        c.gridy = row++;
192
        c.gridwidth = 1;
193
        this.add(getLOrientacion(), c);
194
        c.gridx = GridBagConstraints.RELATIVE;
195
        c.gridwidth = GridBagConstraints.REMAINDER;
196
        this.add(getOrientationPanel(), c);
197
        c.gridy = row++;
198
        c.gridx = 0;
199
        c.gridwidth = 1;
200
        this.add(getLResolucion(), c);
201
        c.gridx = GridBagConstraints.RELATIVE;
202
        c.gridwidth = GridBagConstraints.REMAINDER;
203
        this.add(getCbResolucion(), c);
204
        if (this.showViewList) {
205
            c.gridy = row++;
206
            c.gridx = 0;
207
            c.gridwidth = 1;
208
            this.add(getChbViews(), c);
209
            c.gridx = 1;
210
            c.gridwidth = GridBagConstraints.REMAINDER;
211
            c.weighty = 1;
212
            c.fill = GridBagConstraints.BOTH;
213
            this.add(getViewScrollPane(), c);
214
            c.weighty = 0;
215
            c.fill = GridBagConstraints.HORIZONTAL;
216
            c.gridy = row++;
217
            c.gridx = 1;
218
            c.gridwidth = 1;
219
            this.add(getBtConfigView(), c);
220
        }
221
        c.gridy = row++;
222
        c.gridx = 0;
223
        c.gridwidth = GridBagConstraints.REMAINDER;
224
        this.add(getChbMargenes(), c);
225
        c.gridy = row++;
226
        c.gridx = 1;
227
        c.gridwidth = GridBagConstraints.REMAINDER;
228
        this.add(getPnlMargin(), c);
229
        c.gridy = row++;
230
        c.gridx = 0;
231
        c.gridwidth = GridBagConstraints.REMAINDER;
232
        this.add(getPnlAcceptCancel(), c);
233
        if (!this.showViewList) {
234
            c.gridy = row++;
235
            c.gridx = 0;
236
            c.gridwidth = GridBagConstraints.REMAINDER;
237
            c.weighty = 1;
238
            this.add(new JLabel(""), c);
239
        }
240

    
241
        ToolsSwingUtils.ensureRowsCols(this, 16, 80, 24, 120);
242
    }
243
    
244
    public AcceptCancelPanel getPnlAcceptCancel() {
245
            if (pnlAcceptCancel==null) {
246
                    pnlAcceptCancel = new AcceptCancelPanel(this, this);
247
            }
248
            return pnlAcceptCancel;
249
    }
250
    
251
    private JPanel getPnlMargin() {
252
            if (pnlMargin==null) {
253
                    pnlMargin = new JPanel(new GridBagLayout());
254
                    GridBagConstraints c = new GridBagConstraints();
255
            Insets leftInsets = new Insets(0, 0, 4, 4);
256
            Insets leftInsets2 = new Insets(0, 20, 4, 4);
257
            Insets rightInsets = new Insets(0, 4, 4, 0);
258
            Insets centerInsets = new Insets(0, 4, 4, 4);
259
            c.anchor = GridBagConstraints.LINE_START;
260
            c.fill = GridBagConstraints.NONE;
261
            int row = 0;
262
            c.gridy = row++;
263
            c.gridx = 0;
264
            c.insets = leftInsets;
265
            pnlMargin.add(getLSuperior(), c);
266
            c.gridx = GridBagConstraints.RELATIVE;
267
            c.insets = centerInsets;
268
            pnlMargin.add(getTSuperior(), c);
269
            pnlMargin.add(getLbUnitsTop(), c);
270
            c.insets = leftInsets2;
271
            pnlMargin.add(getLIzquierdo(), c);
272
            c.insets = centerInsets;
273
            pnlMargin.add(getTIzquierdo(), c);
274
            c.insets = rightInsets;
275
            pnlMargin.add(getLbUnitsLeft(), c);
276
            leftInsets = new Insets(4, 0, 0, 4);
277
            leftInsets2 = new Insets(4, 20, 0, 4);
278
            rightInsets = new Insets(4, 4, 0, 0);
279
            centerInsets = new Insets(4, 4, 0, 4);
280
            c.gridy = row++;
281
            c.gridx = 0;
282
            c.insets = leftInsets;
283
            pnlMargin.add(getLInferior(), c);
284
            c.insets = centerInsets;
285
            c.gridx = GridBagConstraints.RELATIVE;
286
            pnlMargin.add(getTInferior(), c);
287
            pnlMargin.add(getLbUnitsBottom(), c);
288
            c.insets = leftInsets2;
289
            pnlMargin.add(getLDerecho(), c);
290
            c.insets = centerInsets;
291
            pnlMargin.add(getTDerecho(), c);
292
            c.insets = rightInsets;
293
            pnlMargin.add(getLbUnitsRight(), c);
294
            }
295
            return pnlMargin;
296
    }
297

    
298
    /**
299
     * This method initializes lTamPag
300
     * 
301
     * @return javax.swing.JLabel
302
     */
303
    private javax.swing.JLabel getLTamPag() {
304
        if (lTamPag == null) {
305
            lTamPag = new javax.swing.JLabel();
306
            lTamPag
307
                .setText(PluginServices.getText(this, "tamano_pagina"));
308
        }
309

    
310
        return lTamPag;
311
    }
312

    
313
    /**
314
     * This method initializes cbTipoFolio
315
     * 
316
     * @return javax.swing.JComboBox
317
     */
318
    private javax.swing.JComboBox getCbTipoFolio() {
319
        if (cbTipoFolio == null) {
320
            cbTipoFolio = new javax.swing.JComboBox();
321
            cbTipoFolio.addItem(PluginServices.getText(this,
322
                "Igual_que_la_impresora"));
323
            cbTipoFolio.addItem(PluginServices.getText(this, "A4"));
324
            cbTipoFolio.addItem(PluginServices.getText(this, "A3"));
325
            cbTipoFolio.addItem(PluginServices.getText(this, "A2"));
326
            cbTipoFolio.addItem(PluginServices.getText(this, "A1"));
327
            cbTipoFolio.addItem(PluginServices.getText(this, "A0"));
328
            cbTipoFolio.addItem(PluginServices.getText(this, "Personalizado"));
329

    
330
            cbTipoFolio.setSelectedIndex(m_layout.getLayoutContext()
331
                .getAttributes().getType());
332
            cbTipoFolio.addActionListener(new java.awt.event.ActionListener() {
333

    
334
                public void actionPerformed(java.awt.event.ActionEvent e) {
335
                    type = cbTipoFolio.getSelectedIndex();
336
                    temporaryAttributes.setType(type);
337
                    Size size = temporaryAttributes.getPaperSizeInUnits();
338
                    getTAlto().setText(
339
                        String.valueOf(nf.format(size.getHeight())));
340
                    getTAncho().setText(
341
                        String.valueOf(nf.format(size.getWidth())));
342
                    setMargin(margin);
343
                    if (cbTipoFolio.getSelectedItem().equals(
344
                        PluginServices.getText(this, "Personalizado"))) {
345
                        getTAlto().setEnabled(true);
346
                        getTAncho().setEnabled(true);
347
                        getRbVertical().setSelected(true);
348
                        isLand = false;
349
                        getRbVertical().setEnabled(false);
350
                        getRbHorizontal().setEnabled(false);
351
                    } else {
352
                        getTAlto().setEnabled(false);
353
                        getTAncho().setEnabled(false);
354
                        getRbVertical().setEnabled(true);
355
                        getRbHorizontal().setEnabled(true);
356
                    }
357
                }
358
            });
359
        }
360

    
361
        return cbTipoFolio;
362
    }
363

    
364
    /**
365
     * This method initializes cbUnidades
366
     * 
367
     * @return javax.swing.JComboBox
368
     */
369
    private javax.swing.JComboBox getCbUnidades() {
370
        if (cbUnidades == null) {
371
            cbUnidades = new javax.swing.JComboBox();
372
            String[] names = MapContext.getDistanceNames();
373
            for (int i = 0; i < names.length; i++) {
374
                cbUnidades.addItem(PluginServices.getText(this, names[i]));
375
            }
376
            cbUnidades.setSelectedIndex(m_layout.getLayoutContext()
377
                .getAttributes().getUnit());
378
            cbUnidades.addActionListener(new java.awt.event.ActionListener() {
379

    
380
                public void actionPerformed(java.awt.event.ActionEvent e) {
381
                        onUnitsChange();
382
                }
383
            });
384
        }
385

    
386
        return cbUnidades;
387
    }
388
    
389
    protected void onUnitsChange() {
390
        unit = cbUnidades.getSelectedIndex();
391
        temporaryAttributes.setUnit(unit);
392
        Size size = temporaryAttributes.getPaperSizeInUnits();
393
        getTAlto().setText(
394
            String.valueOf(nf.format(size.getWidth())));
395
        getTAncho().setText(
396
            String.valueOf(nf.format(size.getHeight())));
397
        String units = Messages.getText(MapContext.getDistanceAbbr()[getCbUnidades().getSelectedIndex()]);
398
        getLbUnitsTop().setText(units);
399
        getLbUnitsBottom().setText(units);
400
        getLbUnitsLeft().setText(units);
401
        getLbUnitsRight().setText(units);
402
        setMargin(margin);
403
    }
404

    
405
    /**
406
     * This method initializes lAnchura
407
     * 
408
     * @return javax.swing.JLabel
409
     */
410
    private javax.swing.JLabel getLAnchura() {
411
        if (lAnchura == null) {
412
            lAnchura = new javax.swing.JLabel();
413
            lAnchura.setText(PluginServices.getText(this, "anchura"));
414
        }
415
        return lAnchura;
416
    }
417

    
418
    /**
419
     * This method initializes lAltura
420
     * 
421
     * @return javax.swing.JLabel
422
     */
423
    private javax.swing.JLabel getLAltura() {
424
        if (lAltura == null) {
425
            lAltura = new javax.swing.JLabel();
426
            lAltura.setText(PluginServices.getText(this, "altura"));
427
        }
428
        return lAltura;
429
    }
430

    
431
    /**
432
     * This method initializes tAncho
433
     * 
434
     * @return javax.swing.JTextField
435
     */
436
    private javax.swing.JTextField getTAncho() {
437
        if (tAncho == null) {
438
            tAncho = new javax.swing.JTextField(4);
439
            Size size = temporaryAttributes.getPaperSizeInUnits();
440
            String s = String.valueOf(nf.format(size.getWidth()));
441
            tAncho.setText(s);
442
            if (getCbTipoFolio().getSelectedItem().equals(
443
                PluginServices.getText(this, "Personalizado"))) {
444
                    tAncho.setEnabled(true);
445
            } else {
446
                    tAncho.setEnabled(false);
447
            }
448
        }
449

    
450
        return tAncho;
451
    }
452

    
453
    /**
454
     * This method initializes tAlto
455
     * 
456
     * @return javax.swing.JTextField
457
     */
458
    private javax.swing.JTextField getTAlto() {
459
        if (tAlto == null) {
460
            tAlto = new javax.swing.JTextField(4);
461
            Size size = temporaryAttributes.getPaperSizeInUnits();
462
            String s = String.valueOf(nf.format(size.getHeight()));
463
            tAlto.setText(s);
464
            if (getCbTipoFolio().getSelectedItem().equals(
465
                PluginServices.getText(this, "Personalizado"))) {
466
                    tAlto.setEnabled(true);
467
            } else {
468
                    tAlto.setEnabled(false);
469
            }
470
        }
471

    
472
        return tAlto;
473
    }
474

    
475
    /**
476
     * This method initializes lOrientacion
477
     * 
478
     * @return javax.swing.JLabel
479
     */
480
    private javax.swing.JLabel getLOrientacion() {
481
        if (lOrientacion == null) {
482
            lOrientacion = new javax.swing.JLabel();
483
            lOrientacion.setText(PluginServices.getText(this, "orientacion"));
484
        }
485

    
486
        return lOrientacion;
487
    }
488

    
489
    /**
490
     * This method initializes lMargenes
491
     * 
492
     * @return javax.swing.JLabel
493
     */
494
    private javax.swing.JLabel getLMargenes() {
495
        if (lMargenes == null) {
496
            lMargenes = new javax.swing.JLabel();
497
            lMargenes.setText(PluginServices.getText(this, "margenes"));
498
        }
499

    
500
        return lMargenes;
501
    }
502

    
503
    /**
504
     * Inserta si se dibuja los margenes sobre el Layout o no.
505
     * 
506
     * @param b
507
     *            True si se tiene que dibujar los margenes.
508
     */
509
    private void setMargin(boolean b) {
510
        margin = b;
511

    
512
        if (b) {
513
            getTSuperior().setText(
514
                String.valueOf(nf.format(
515
                                temporaryAttributes.toUnits(sup))));
516
            getTIzquierdo().setText(
517
                String.valueOf(nf.format(temporaryAttributes.toUnits(izq))));
518
            getTInferior().setText(
519
                String.valueOf(nf.format(temporaryAttributes.toUnits(inf))));
520
            getTDerecho().setText(
521
                String.valueOf(nf.format(temporaryAttributes.toUnits(der))));
522
            getTSuperior().setEnabled(true);
523
            getTIzquierdo().setEnabled(true);
524
            getTInferior().setEnabled(true);
525
            getTDerecho().setEnabled(true);
526
        } else {
527
            getTSuperior().setText("");
528
            getTIzquierdo().setText("");
529
            getTInferior().setText("");
530
            getTDerecho().setText("");
531
            getTSuperior().setEnabled(false);
532
            getTIzquierdo().setEnabled(false);
533
            getTInferior().setEnabled(false);
534
            getTDerecho().setEnabled(false);
535
        }
536
    }
537

    
538
    /**
539
     * This method initializes chbMargenes
540
     * 
541
     * @return javax.swing.JCheckBox
542
     */
543
    private javax.swing.JCheckBox getChbMargenes() {
544
        if (chbMargenes == null) {
545
            chbMargenes = new javax.swing.JCheckBox();
546
            chbMargenes.setText(PluginServices.getText(this,
547
                "personalizar_margenes"));
548
            chbMargenes.setSelected(temporaryAttributes.isMargin());
549
            setMargin(temporaryAttributes.isMargin());
550
            chbMargenes.addActionListener(new java.awt.event.ActionListener() {
551

    
552
                public void actionPerformed(java.awt.event.ActionEvent e) {
553
                    if (chbMargenes.isSelected()) {
554
                        margin = true;
555
                    } else {
556
                        margin = false;
557
                    }
558

    
559
                    setMargin(margin);
560
                }
561
            });
562
        }
563

    
564
        return chbMargenes;
565
    }
566

    
567
    /**
568
     * This method initializes lSuperior
569
     * 
570
     * @return javax.swing.JLabel
571
     */
572
    private javax.swing.JLabel getLSuperior() {
573
        if (lSuperior == null) {
574
            lSuperior = new javax.swing.JLabel();
575
            lSuperior.setText(PluginServices.getText(this, "Superior"));
576
        }
577

    
578
        return lSuperior;
579
    }
580

    
581
    /**
582
     * This method initializes tSuperior
583
     * 
584
     * @return javax.swing.JTextField
585
     */
586
    private javax.swing.JTextField getTSuperior() {
587
        if (tSuperior == null) {
588
            tSuperior = new javax.swing.JTextField(4);
589
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
590
                tSuperior.setText(String.valueOf(nf.format(m_layout
591
                    .getLayoutContext().getAttributes().toUnits(sup))));
592
            }
593
        }
594

    
595
        return tSuperior;
596
    }
597

    
598
    /**
599
     * This method initializes lIzquierdo
600
     * 
601
     * @return javax.swing.JLabel
602
     */
603
    private javax.swing.JLabel getLIzquierdo() {
604
        if (lIzquierdo == null) {
605
            lIzquierdo = new javax.swing.JLabel();
606
            lIzquierdo.setText(PluginServices.getText(this, "Izquierdo"));
607
        }
608

    
609
        return lIzquierdo;
610
    }
611

    
612
    /**
613
     * This method initializes tIzquierdo
614
     * 
615
     * @return javax.swing.JTextField
616
     */
617
    private javax.swing.JTextField getTIzquierdo() {
618
        if (tIzquierdo == null) {
619
            tIzquierdo = new javax.swing.JTextField(4);
620
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
621
                tIzquierdo.setText(String.valueOf(nf.format(m_layout
622
                    .getLayoutContext().getAttributes().toUnits(izq))));
623
            }
624
        }
625

    
626
        return tIzquierdo;
627
    }
628

    
629
    /**
630
     * This method initializes lInferior
631
     * 
632
     * @return javax.swing.JLabel
633
     */
634
    private javax.swing.JLabel getLInferior() {
635
        if (lInferior == null) {
636
            lInferior = new javax.swing.JLabel();
637
            lInferior.setText(PluginServices.getText(this, "Inferior"));
638
        }
639

    
640
        return lInferior;
641
    }
642

    
643
    /**
644
     * This method initializes tInferior
645
     * 
646
     * @return javax.swing.JTextField
647
     */
648
    private javax.swing.JTextField getTInferior() {
649
        if (tInferior == null) {
650
            tInferior = new javax.swing.JTextField(4);
651
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
652
                tInferior.setText(String.valueOf(nf.format(m_layout
653
                    .getLayoutContext().getAttributes().toUnits(inf))));
654
            }
655
        }
656

    
657
        return tInferior;
658
    }
659

    
660
    /**
661
     * This method initializes lDerecho
662
     * 
663
     * @return javax.swing.JLabel
664
     */
665
    private javax.swing.JLabel getLDerecho() {
666
        if (lDerecho == null) {
667
            lDerecho = new javax.swing.JLabel();
668
            lDerecho.setText(PluginServices.getText(this, "Derecho"));
669
        }
670

    
671
        return lDerecho;
672
    }
673

    
674
    /**
675
     * This method initializes tDerecho
676
     * 
677
     * @return javax.swing.JTextField
678
     */
679
    private javax.swing.JTextField getTDerecho() {
680
        if (tDerecho == null) {
681
            tDerecho = new javax.swing.JTextField(4);
682
            if (m_layout.getLayoutContext().getAttributes().isMargin()) {
683
                tDerecho.setText(String.valueOf(nf.format(m_layout
684
                    .getLayoutContext().getAttributes().toUnits(der))));
685
            }
686
        }
687

    
688
        return tDerecho;
689
    }
690

    
691
    private JLabel getLbUnitsTop() {
692
            if (lblUnitsTop==null) {
693
                    String unit = Messages.getText(MapContext.getDistanceAbbr()[getCbUnidades().getSelectedIndex()]);
694
                    lblUnitsTop = new JLabel(unit);
695
            }
696
            return lblUnitsTop;
697
    }
698
    
699
    private JLabel getLbUnitsBottom() {
700
            if (lblUnitsBottom==null) {
701
                    String unit = Messages.getText(MapContext.getDistanceAbbr()[getCbUnidades().getSelectedIndex()]);
702
                    lblUnitsBottom = new JLabel(unit);
703
            }
704
            return lblUnitsBottom;
705
    }
706
    
707
    private JLabel getLbUnitsLeft() {
708
            if (lblUnitsLeft==null) {
709
                    String unit = Messages.getText(MapContext.getDistanceAbbr()[getCbUnidades().getSelectedIndex()]);
710
                    lblUnitsLeft = new JLabel(unit);
711
            }
712
            return lblUnitsLeft;
713
    }
714
    
715
    private JLabel getLbUnitsRight() {
716
            if (lblUnitsRight==null) {
717
                    String unit = Messages.getText(MapContext.getDistanceAbbr()[getCbUnidades().getSelectedIndex()]);
718
                    lblUnitsRight = new JLabel(unit);
719
            }
720
            return lblUnitsRight;
721
    }
722
    
723
    /**
724
     * This method initializes lResolucion
725
     * 
726
     * @return javax.swing.JLabel
727
     */
728
    private javax.swing.JLabel getLResolucion() {
729
        if (lResolucion == null) {
730
            lResolucion = new javax.swing.JLabel();
731
            lResolucion.setText(PluginServices.getText(this,
732
                "resolucion_resultado"));
733
        }
734

    
735
        return lResolucion;
736
    }
737

    
738
    /**
739
     * This method initializes cbResolucion
740
     * 
741
     * @return javax.swing.JComboBox
742
     */
743
    private javax.swing.JComboBox getCbResolucion() {
744
        if (cbResolucion == null) {
745
            cbResolucion = new javax.swing.JComboBox();
746
            cbResolucion.addItem(PluginServices.getText(this, "High_600_dpi"));
747
            cbResolucion.addItem(PluginServices.getText(this, "Normal_300_dpi"));
748
            cbResolucion.addItem(PluginServices.getText(this, "Low_72_dpi"));
749
            cbResolucion.setSelectedIndex(m_layout.getLayoutContext()
750
                .getAttributes().getResolution());
751
            cbResolucion.addActionListener(new java.awt.event.ActionListener() {
752

    
753
                public void actionPerformed(java.awt.event.ActionEvent e) {
754
                    resolution = cbResolucion.getSelectedIndex();
755
                    temporaryAttributes.setResolution(resolution);
756
                }
757
            });
758
        }
759

    
760
        return cbResolucion;
761
    }
762
    
763
    public void addOkButtonActionListener(ActionListener l) {
764
            getPnlAcceptCancel().addOkButtonActionListener(l);
765
    }
766
    
767
    public void addCancelButtonActionListener(ActionListener l) {
768
            getPnlAcceptCancel().addCancelButtonActionListener(l);
769
    }
770

    
771
    private JPanel getOrientationPanel() {
772
            if (pOrientation == null) {
773
                    pOrientation = new JPanel(new GridBagLayout());
774
                    GridBagConstraints c = new GridBagConstraints();
775
                c.anchor = GridBagConstraints.WEST;
776
                c.gridx = 0;
777
                c.gridy = 0;
778
                c.insets = new Insets(0, 0, 0, 10);
779
                pOrientation.add(getRbHorizontal(), c);
780
                c.gridx = 1;
781
                c.insets = new Insets(0, 0, 0, 0);
782
                c.weightx = 1.0;
783
                c.fill = GridBagConstraints.HORIZONTAL;
784
                pOrientation.add(getRbVertical(), c);
785
                // add the radios to the button group
786
                ButtonGroup bgOrientation = new ButtonGroup();
787
                bgOrientation.add(getRbHorizontal());
788
                bgOrientation.add(getRbVertical());
789
                if (isLand) {
790
                        getRbHorizontal().setSelected(true);
791
                }
792
                else {
793
                        getRbVertical().setSelected(true);
794
                }
795
                if (getCbTipoFolio().getSelectedItem().equals(
796
                                PluginServices.getText(this, "Personalizado"))) {
797
                        rbHorizontal.setEnabled(false);
798
                        rbVertical.setEnabled(false);
799
                rbVertical.setSelected(true);
800
                        isLand = false;
801
                }
802
            }
803
            return pOrientation;
804
    }
805
    
806
    /**
807
     * This method initializes chbHorizontal
808
     * 
809
     * @return javax.swing.JCheckBox
810
     */
811
    private javax.swing.JRadioButton getRbHorizontal() {
812
        if (rbHorizontal == null) {
813
            rbHorizontal = new javax.swing.JRadioButton();
814
            rbHorizontal.setText(PluginServices.getText(this, "horizontal"));
815
            rbHorizontal
816
            .addActionListener(new java.awt.event.ActionListener() {
817
                    public void actionPerformed(java.awt.event.ActionEvent e) {
818
                            isLand = true;
819
                            double iz = izq;
820
                            izq = inf;
821
                            inf = der;
822
                            der = sup;
823
                            sup = iz;
824
                            
825
                            Attributes attr = FConfigLayoutDialog.this.temporaryAttributes;
826
                            attr.setIsLandScape(isLand);
827
                            setMargin(margin);
828
                            Size size = attr.getPaperSizeInUnits();
829
                            getTAncho().setText(
830
                                            String.valueOf(nf.format(size.getWidth())));
831
                            getTAlto().setText(
832
                                            String.valueOf(nf.format(size.getHeight())));
833
                    }
834
            });
835
        }
836

    
837
        return rbHorizontal;
838
    }
839

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

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

    
858
                            Attributes attr = FConfigLayoutDialog.this.temporaryAttributes;
859
                            attr.setIsLandScape(isLand);
860
                            setMargin(margin);
861
                            Size size = attr.getPaperSizeInUnits();
862
                            getTAncho().setText(
863
                                                String.valueOf(nf.format(size.getWidth())));
864
                                getTAlto().setText(
865
                                                String.valueOf(nf.format(size.getHeight())));
866
                        }
867
            });
868
        }
869

    
870
        return rbVertical;
871
    }
872

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

    
966
        return chbViews;
967
    }
968
    
969
//    public WindowInfo getWindowInfo() {
970
//            if (windowInfo==null) {
971
//                    windowInfo  = new WindowInfo(WindowInfo.RESIZABLE);
972
//                    if (showViewList) {
973
//                            windowInfo.setWidth(650);
974
//                            windowInfo.setHeight(450);
975
//                    }
976
//                    else {
977
//                            windowInfo.setWidth(550);
978
//                            windowInfo.setHeight(300);                
979
//                    }
980
//                    windowInfo.setTitle(PluginServices.getText(this, "Preparar_pagina"));
981
//            }
982
//        return windowInfo;
983
//    }    
984
//    
985
//    public Dimension getPreferredSize() {
986
//            return new Dimension(getWindowInfo().getWidth(), getWindowInfo().getHeight());
987
//    }
988

    
989

    
990
    /**
991
     * Obtiene el ?rea de los JtextField.
992
     */
993
    private void obtainArea() {
994
        String s = (getTSuperior().getText());
995
        s = s.replace(',', '.');
996

    
997
        if (s.length() == 0) {
998
            s = "0";
999
        }
1000

    
1001
        sup =
1002
            temporaryAttributes
1003
                .fromUnits(Double.valueOf(s).doubleValue());
1004
        s = (getTIzquierdo().getText());
1005
        s = s.replace(',', '.');
1006

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

    
1011
        izq =
1012
            temporaryAttributes
1013
                .fromUnits(Double.valueOf(s).doubleValue());
1014
        s = (getTInferior().getText());
1015
        s = s.replace(',', '.');
1016

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

    
1021
        inf =
1022
            temporaryAttributes
1023
                .fromUnits(Double.valueOf(s).doubleValue());
1024
        s = (getTDerecho().getText());
1025
        s = s.replace(',', '.');
1026

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

    
1031
        der =
1032
            temporaryAttributes
1033
                .fromUnits(Double.valueOf(s).doubleValue());
1034
    }
1035

    
1036
//    public Object getWindowProfile() {
1037
//        return WindowInfo.DIALOG_PROFILE;
1038
//    }
1039
//
1040
//        public Object getWindowModel() {
1041
//                // necessary for considering them as separate SingletonWindows depending showViewList option
1042
//                if (showViewList) {
1043
//                        return m_layout;
1044
//                }
1045
//                else {
1046
//                        return m_layout.getLayoutControl();
1047
//                }
1048
//        }
1049

    
1050
        public void actionPerformed(ActionEvent e) {
1051
                if (e.getActionCommand()=="OK") {
1052
                        onAcceptPressed();
1053
                }
1054
                else {
1055
                        onCancelPressed();
1056
                }
1057
                
1058
        }
1059
        
1060
        private void onCancelPressed() {
1061
        if (createdView!=null) {
1062
                deleteView();
1063
        }
1064
        // we use setVisible(false) to close the window when it has been
1065
        // created using WindowManager.showWindow()
1066
        setVisible(false);
1067
        }
1068
        
1069
        private void onAcceptPressed() {
1070
        obtainArea();
1071

    
1072
        double[] area = { sup, inf, izq, der };
1073

    
1074
        if (type == Attributes.CUSTOM) {
1075
            String width = getTAncho().getText().replace(',', '.');
1076
            String height = getTAlto().getText().replace(',', '.');
1077
            temporaryAttributes.setPaperSize(new Size(
1078
                    Double.valueOf(height).doubleValue(),
1079
                    Double.valueOf(width).doubleValue()));
1080
        }
1081
        else {
1082
                if (isLand) {
1083
                        temporaryAttributes.setIsLandScape(true);
1084
                } else {
1085
                        temporaryAttributes.setIsLandScape(false);
1086
                }
1087
        }
1088
        temporaryAttributes.setType(type);
1089
        m_layout.getLayoutContext().setAtributes(temporaryAttributes);
1090
        temporaryAttributes.setSelectedOptions(type, unit, isLand, margin,
1091
                resolution, area);
1092
        m_layout.obtainRect(false);
1093
        
1094
        if (showViewList && getChbViews().isSelected()) { // a view has been selected
1095
                ViewDocument vd = getSelectedView();
1096
                ProjectManager projectManager = ApplicationLocator.getProjectManager();
1097
            LayoutManager layoutManager = (LayoutManager) projectManager.getDocumentManager(LayoutManager.TYPENAME);
1098
            FFrameView ffv = (FFrameView) layoutManager.createFrame(FFrameView.PERSISTENCE_DEFINITION_NAME);
1099
            ffv.setDocument(m_layout.getDocument());
1100
            LayoutContext lctxt = m_layout.getLayoutContext();
1101
            ffv.setLayoutContext(lctxt);
1102
                ffv.setBoundBox(new Rectangle2D.Double(izq, sup, temporaryAttributes.getPaperSize().getWidth()-(izq+der), temporaryAttributes.getPaperSize().getHeight()-(sup+inf)));
1103
                ffv.setView(vd);
1104
                lctxt.addFFrame(ffv, true, true);
1105
                m_layout.getLayoutControl().setDefaultTool();
1106
        }
1107
        if (createdView!=null && createdView!=getSelectedView()) { // a view was created but later de-selected
1108
                deleteView();
1109
        }
1110
        m_layout.getLayoutControl().fullRect();
1111
        // we use setVisible(false) to close the window when it has been
1112
        // created using WindowManager.showWindow()
1113
        setVisible(false);
1114
        }
1115
}