Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / gui / dialogs / FPositionDialog.java @ 5

History | View | Annotate | Download (16.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.geom.Rectangle2D;
25
import java.text.NumberFormat;
26

    
27
import javax.swing.JPanel;
28

    
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

    
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.ui.mdiManager.IWindow;
34
import org.gvsig.andami.ui.mdiManager.WindowInfo;
35
import org.gvsig.app.project.documents.layout.DefaultLayoutNotification;
36
import org.gvsig.app.project.documents.layout.LayoutNotification;
37
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
38
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
39
import org.gvsig.tools.observer.Observable;
40
import org.gvsig.tools.observer.ObservableHelper;
41
import org.gvsig.tools.observer.Observer;
42

    
43
/**
44
 * Di?logo que ofrece la posibilidad de posicionar el fframe en un punto en
45
 * concreto del Layout.
46
 * 
47
 * @author Vicente Caballero Navarro
48
 */
49
public class FPositionDialog extends JPanel implements IWindow, Observable {
50

    
51
    private static final long serialVersionUID = -1289724614739172740L;
52
    protected static final Logger LOG = LoggerFactory
53
        .getLogger(FPositionDialog.class);
54
    private javax.swing.JLabel lDesdeIzquierda = null;
55
    private javax.swing.JLabel lDesdeArriba = null;
56
    private javax.swing.JLabel lAnchura = null;
57
    private javax.swing.JLabel lAltura = null;
58
    private javax.swing.JButton bAceptar = null;
59
    private javax.swing.JButton bCancelar = null;
60
    private javax.swing.JTextField tDesdeIzquierda = null;
61
    private javax.swing.JTextField tDesdeDerecha = null;
62
    private javax.swing.JTextField tAnchura = null;
63
    private javax.swing.JTextField tAltura = null;
64
    private javax.swing.JLabel lNomUnidades = null;
65
    private javax.swing.JLabel lUnidades = null;
66
    private LayoutPanel layout = null;
67
    private String m_NameUnit = null;
68
    // private ArrayList selecList = new ArrayList();
69
    NumberFormat nf = NumberFormat.getInstance();
70
    private javax.swing.JLabel lAnchoUnidades = null;
71
    private javax.swing.JLabel lAlto = null;
72
    private javax.swing.JLabel lAltoUnidades = null;
73
    private javax.swing.JLabel lAncho = null;
74
    private javax.swing.JPanel pFolio = null;
75
    private javax.swing.JLabel lSeparador = null;
76
    private IFFrame fframe;
77
    private ObservableHelper observers;
78
    
79
    /**
80
     * This is the default constructor
81
     * 
82
     * @param l
83
     *            Referencia al Layout.
84
     */
85
    public FPositionDialog(LayoutPanel layoutPanel, IFFrame fframe) {
86
        super();
87
        layout = layoutPanel;
88
        this.fframe = fframe;
89
        observers = new ObservableHelper();
90
        observers.addObserver(layoutPanel.getLayoutControl());
91

    
92
        /*
93
         * for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
94
         * IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
95
         * 
96
         * if (fframe.getSelected() != FFrame.NOSELECT) {
97
         * selecList.add(fframe);
98
         * }
99
         * }
100
         */
101
        initialize();
102
    }
103

    
104
    /**
105
     * This method initializes this
106
     */
107
    private void initialize() {
108
        this.setLayout(null);
109

    
110
        if (layout.getLayoutContext().isAdjustingToGrid()) {
111
            nf.setMaximumFractionDigits(1);
112
        } else {
113
            nf.setMaximumFractionDigits(2);
114
        }
115

    
116
        m_NameUnit = layout.getLayoutContext().getAttributes().getNameUnit();
117
        this.add(getLDesdeIzquierda(), null);
118
        this.add(getLDesdeArriba(), null);
119
        this.add(getLAnchura(), null);
120
        this.add(getLAltura(), null);
121
        this.add(getBAceptar(), null);
122
        this.add(getBCancelar(), null);
123
        this.add(getTDesdeIzquierda(), null);
124
        this.add(getTDesdeDerecha(), null);
125
        this.add(getTAnchura(), null);
126
        this.add(getTAltura(), null);
127
        this.add(getLNomUnidades(), null);
128
        this.add(getLUnidades(), null);
129
        this.add(getPFolio(), null);
130
        this.setSize(203, 215);
131
    }
132

    
133
    /**
134
     * This method initializes lDesdeIzquierda
135
     * 
136
     * @return javax.swing.JLabel
137
     */
138
    private javax.swing.JLabel getLDesdeIzquierda() {
139
        if (lDesdeIzquierda == null) {
140
            lDesdeIzquierda = new javax.swing.JLabel();
141
            lDesdeIzquierda.setBounds(9, 85, 116, 20);
142
            lDesdeIzquierda.setText(PluginServices.getText(this,
143
                "desde_izquierda"));
144
        }
145

    
146
        return lDesdeIzquierda;
147
    }
148

    
149
    /**
150
     * This method initializes lDesdeArriba
151
     * 
152
     * @return javax.swing.JLabel
153
     */
154
    private javax.swing.JLabel getLDesdeArriba() {
155
        if (lDesdeArriba == null) {
156
            lDesdeArriba = new javax.swing.JLabel();
157
            lDesdeArriba.setBounds(9, 110, 116, 20);
158
            lDesdeArriba.setText(PluginServices.getText(this, "desde_arriba"));
159
        }
160

    
161
        return lDesdeArriba;
162
    }
163

    
164
    /**
165
     * This method initializes lAnchura
166
     * 
167
     * @return javax.swing.JLabel
168
     */
169
    private javax.swing.JLabel getLAnchura() {
170
        if (lAnchura == null) {
171
            lAnchura = new javax.swing.JLabel();
172
            lAnchura.setBounds(9, 135, 116, 20);
173
            lAnchura.setText(PluginServices.getText(this, "anchura"));
174
        }
175

    
176
        return lAnchura;
177
    }
178

    
179
    /**
180
     * This method initializes lAltura
181
     * 
182
     * @return javax.swing.JLabel
183
     */
184
    private javax.swing.JLabel getLAltura() {
185
        if (lAltura == null) {
186
            lAltura = new javax.swing.JLabel();
187
            lAltura.setBounds(9, 160, 116, 20);
188
            lAltura.setText(PluginServices.getText(this, "altura"));
189
        }
190

    
191
        return lAltura;
192
    }
193

    
194
    /**
195
     * This method initializes bAceptar
196
     * 
197
     * @return javax.swing.JButton
198
     */
199
    private javax.swing.JButton getBAceptar() {
200
        if (bAceptar == null) {
201
            bAceptar = new javax.swing.JButton();
202
            bAceptar.setBounds(12, 185, 85, 23);
203
            bAceptar.setText(PluginServices.getText(this, "Aceptar"));
204
            bAceptar.addActionListener(new java.awt.event.ActionListener() {
205

    
206
                public void actionPerformed(java.awt.event.ActionEvent e) {
207
                    // if (selecList.size() == 1) {
208
                    Rectangle2D.Double r = new Rectangle2D.Double();
209

    
210
                    if (getTDesdeIzquierda().getText().equals("")) {
211
                        getTDesdeIzquierda().setText("0");
212
                    }
213

    
214
                    if (getTDesdeDerecha().getText().equals("")) {
215
                        getTDesdeDerecha().setText("0");
216
                    }
217

    
218
                    if (getTAnchura().getText().equals("")) {
219
                        getTAnchura().setText("0");
220
                    }
221

    
222
                    if (getTAltura().getText().equals("")) {
223
                        getTAltura().setText("0");
224
                    }
225

    
226
                    r.x =
227
                        stringToDouble(getTDesdeIzquierda().getText()
228
                            .toString());
229
                    r.y =
230
                        stringToDouble(getTDesdeDerecha().getText().toString());
231
                    r.width =
232
                        stringToDouble(getTAnchura().getText().toString());
233
                    r.height =
234
                        stringToDouble(getTAltura().getText().toString());
235

    
236
                    // ((IFFrame) selecList.get(0)).setBoundBox(r);
237
                    IFFrame fframeAux;
238
                    try {
239
                        fframeAux = (IFFrame) fframe.clone();
240
                        fframeAux.setBoundBox(r);
241
                        layout.getLayoutContext().getFrameCommandsRecord()
242
                            .update(fframe, fframeAux);
243
                        layout.getLayoutContext().updateFFrames();
244
                    } catch (CloneNotSupportedException e1) {
245
                        LOG.error("It is not possible clonate the object", e);
246
                    }
247

    
248
                    PluginServices.getMDIManager().closeWindow(
249
                        FPositionDialog.this);
250
                    observers.notifyObservers(FPositionDialog.this, 
251
                        new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));      
252
                    layout.repaint();
253
                }
254
            });
255
        }
256

    
257
        return bAceptar;
258
    }
259

    
260
    /**
261
     * Paso de String a double.
262
     * 
263
     * @param s
264
     *            String.
265
     * 
266
     * @return double obtenido.
267
     */
268
    private double stringToDouble(String s) {
269
        String snew = s.replace(',', '.');
270

    
271
        return layout.getLayoutContext().getAttributes()
272
            .fromUnits(Double.parseDouble(snew));
273
    }
274

    
275
    /**
276
     * This method initializes bCancelar
277
     * 
278
     * @return javax.swing.JButton
279
     */
280
    private javax.swing.JButton getBCancelar() {
281
        if (bCancelar == null) {
282
            bCancelar = new javax.swing.JButton();
283
            bCancelar.setBounds(107, 185, 87, 23);
284
            bCancelar.setText(PluginServices.getText(this, "Cancelar"));
285
            bCancelar.addActionListener(new java.awt.event.ActionListener() {
286

    
287
                public void actionPerformed(java.awt.event.ActionEvent e) {
288
                    PluginServices.getMDIManager().closeWindow(
289
                        FPositionDialog.this);
290
                }
291
            });
292
        }
293

    
294
        return bCancelar;
295
    }
296

    
297
    /**
298
     * This method initializes tDesdeIzquierda
299
     * 
300
     * @return javax.swing.JTextField
301
     */
302
    private javax.swing.JTextField getTDesdeIzquierda() {
303
        if (tDesdeIzquierda == null) {
304
            tDesdeIzquierda = new javax.swing.JTextField();
305
            tDesdeIzquierda.setBounds(132, 85, 53, 20);
306
            tDesdeIzquierda.setText(String.valueOf(nf.format(layout
307
                .getLayoutContext().getAttributes()
308
                .toUnits(fframe.getBoundBox().x))));
309
        }
310

    
311
        return tDesdeIzquierda;
312
    }
313

    
314
    /**
315
     * This method initializes tDesdeDerecha
316
     * 
317
     * @return javax.swing.JTextField
318
     */
319
    private javax.swing.JTextField getTDesdeDerecha() {
320
        if (tDesdeDerecha == null) {
321
            tDesdeDerecha = new javax.swing.JTextField();
322
            tDesdeDerecha.setBounds(132, 110, 53, 20);
323
            tDesdeDerecha.setText(String.valueOf(nf.format(layout
324
                .getLayoutContext().getAttributes()
325
                .toUnits(fframe.getBoundBox().y))));
326
        }
327

    
328
        return tDesdeDerecha;
329
    }
330

    
331
    /**
332
     * This method initializes tAnchura
333
     * 
334
     * @return javax.swing.JTextField
335
     */
336
    private javax.swing.JTextField getTAnchura() {
337
        if (tAnchura == null) {
338
            tAnchura = new javax.swing.JTextField();
339
            tAnchura.setBounds(132, 135, 53, 20);
340
            tAnchura.setText(String.valueOf(nf.format(layout.getLayoutContext()
341
                .getAttributes().toUnits(fframe.getBoundBox().width))));
342
        }
343

    
344
        return tAnchura;
345
    }
346

    
347
    /**
348
     * This method initializes tAltura
349
     * 
350
     * @return javax.swing.JTextField
351
     */
352
    private javax.swing.JTextField getTAltura() {
353
        if (tAltura == null) {
354
            tAltura = new javax.swing.JTextField();
355
            tAltura.setBounds(132, 160, 53, 20);
356
            tAltura.setText(String.valueOf(nf.format(layout.getLayoutContext()
357
                .getAttributes().toUnits(fframe.getBoundBox().height))));
358
        }
359

    
360
        return tAltura;
361
    }
362

    
363
    /**
364
     * This method initializes lNomUnidades
365
     * 
366
     * @return javax.swing.JLabel
367
     */
368
    private javax.swing.JLabel getLNomUnidades() {
369
        if (lNomUnidades == null) {
370
            lNomUnidades = new javax.swing.JLabel();
371
            lNomUnidades.setBounds(91, 7, 91, 20);
372
            lNomUnidades.setText(PluginServices.getText(this, m_NameUnit));
373
        }
374

    
375
        return lNomUnidades;
376
    }
377

    
378
    /**
379
     * This method initializes lUnidades
380
     * 
381
     * @return javax.swing.JLabel
382
     */
383
    private javax.swing.JLabel getLUnidades() {
384
        if (lUnidades == null) {
385
            lUnidades = new javax.swing.JLabel();
386
            lUnidades.setBounds(7, 7, 72, 20);
387
            lUnidades.setText(PluginServices.getText(this, "unidades"));
388
        }
389

    
390
        return lUnidades;
391
    }
392

    
393
    /**
394
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
395
     */
396
    public WindowInfo getWindowInfo() {
397
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
398

    
399
        // vi.setResizable(false);
400
        m_viewinfo.setTitle(PluginServices.getText(this, "tamano_posicion"));
401

    
402
        return m_viewinfo;
403
    }
404

    
405
    /**
406
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
407
     */
408
    public void viewActivated() {
409
    }
410

    
411
    /**
412
     * This method initializes lAnchoUnidades
413
     * 
414
     * @return javax.swing.JLabel
415
     */
416
    private javax.swing.JLabel getLAnchoUnidades() {
417
        if (lAnchoUnidades == null) {
418
            lAnchoUnidades = new javax.swing.JLabel();
419

    
420
            if (layout.getLayoutContext().getAttributes().isLandSpace()) {
421
                lAnchoUnidades.setText(String.valueOf(nf.format(layout
422
                    .getLayoutContext().getAttributes().getSizeInUnits()
423
                    .getAlto())));
424
            } else {
425
                lAnchoUnidades.setText(String.valueOf(nf.format(layout
426
                    .getLayoutContext().getAttributes().getSizeInUnits()
427
                    .getAncho())));
428
            }
429
        }
430

    
431
        return lAnchoUnidades;
432
    }
433

    
434
    /**
435
     * This method initializes lAlto
436
     * 
437
     * @return javax.swing.JLabel
438
     */
439
    private javax.swing.JLabel getLAlto() {
440
        if (lAlto == null) {
441
            lAlto = new javax.swing.JLabel();
442
            lAlto.setText(PluginServices.getText(this, "alto"));
443
        }
444

    
445
        return lAlto;
446
    }
447

    
448
    /**
449
     * This method initializes lAltoUnidades
450
     * 
451
     * @return javax.swing.JLabel
452
     */
453
    private javax.swing.JLabel getLAltoUnidades() {
454
        if (lAltoUnidades == null) {
455
            lAltoUnidades = new javax.swing.JLabel();
456

    
457
            if (layout.getLayoutContext().getAttributes().isLandSpace()) {
458
                lAltoUnidades.setText(String.valueOf(nf.format(layout
459
                    .getLayoutContext().getAttributes().getSizeInUnits()
460
                    .getAncho())));
461
            } else {
462
                lAltoUnidades.setText(String.valueOf(nf.format(layout
463
                    .getLayoutContext().getAttributes().getSizeInUnits()
464
                    .getAlto())));
465
            }
466
        }
467

    
468
        return lAltoUnidades;
469
    }
470

    
471
    /**
472
     * This method initializes lAncho
473
     * 
474
     * @return javax.swing.JLabel
475
     */
476
    private javax.swing.JLabel getLAncho() {
477
        if (lAncho == null) {
478
            lAncho = new javax.swing.JLabel();
479
            lAncho.setText(PluginServices.getText(this, "ancho"));
480
        }
481

    
482
        return lAncho;
483
    }
484

    
485
    /**
486
     * This method initializes pFolio
487
     * 
488
     * @return javax.swing.JPanel
489
     */
490
    private javax.swing.JPanel getPFolio() {
491
        if (pFolio == null) {
492
            pFolio = new javax.swing.JPanel();
493
            pFolio.add(getLAltoUnidades(), null);
494
            pFolio.add(getLAlto(), null);
495
            pFolio.add(getLSeparador(), null);
496
            pFolio.add(getLAnchoUnidades(), null);
497
            pFolio.add(getLAncho(), null);
498
            pFolio.setBounds(9, 31, 180, 43);
499
            pFolio.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
500
                PluginServices.getText(this, "tamanyo_pagina"),
501
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
502
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
503
        }
504

    
505
        return pFolio;
506
    }
507

    
508
    /**
509
     * This method initializes lSeparador
510
     * 
511
     * @return javax.swing.JLabel
512
     */
513
    private javax.swing.JLabel getLSeparador() {
514
        if (lSeparador == null) {
515
            lSeparador = new javax.swing.JLabel();
516
            lSeparador.setText("/");
517
        }
518

    
519
        return lSeparador;
520
    }
521

    
522
    public Object getWindowProfile() {
523
        return WindowInfo.DIALOG_PROFILE;
524
    }
525

    
526

    
527
    public void addObserver(Observer o) {
528
        observers.addObserver(o);        
529
    }
530

    
531
    public void deleteObserver(Observer o) {
532
      observers.deleteObserver(o);        
533
    }
534

    
535
    public void deleteObservers() {
536
       observers.deleteObservers();        
537
    }
538
}