Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / 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 @ 36648

History | View | Annotate | Download (16.1 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.LayoutControl;
36
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
37
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
38

    
39
/**
40
 * Di?logo que ofrece la posibilidad de posicionar el fframe en un punto en
41
 * concreto del Layout.
42
 * 
43
 * @author Vicente Caballero Navarro
44
 */
45
public class FPositionDialog extends JPanel implements IWindow {
46

    
47
    private static final long serialVersionUID = -1289724614739172740L;
48
    protected static final Logger LOG = LoggerFactory
49
        .getLogger(FPositionDialog.class);
50
    private javax.swing.JLabel lDesdeIzquierda = null;
51
    private javax.swing.JLabel lDesdeArriba = null;
52
    private javax.swing.JLabel lAnchura = null;
53
    private javax.swing.JLabel lAltura = null;
54
    private javax.swing.JButton bAceptar = null;
55
    private javax.swing.JButton bCancelar = null;
56
    private javax.swing.JTextField tDesdeIzquierda = null;
57
    private javax.swing.JTextField tDesdeDerecha = null;
58
    private javax.swing.JTextField tAnchura = null;
59
    private javax.swing.JTextField tAltura = null;
60
    private javax.swing.JLabel lNomUnidades = null;
61
    private javax.swing.JLabel lUnidades = null;
62
    private LayoutPanel layout = null;
63
    private String m_NameUnit = null;
64
    // private ArrayList selecList = new ArrayList();
65
    NumberFormat nf = NumberFormat.getInstance();
66
    private javax.swing.JLabel lAnchoUnidades = null;
67
    private javax.swing.JLabel lAlto = null;
68
    private javax.swing.JLabel lAltoUnidades = null;
69
    private javax.swing.JLabel lAncho = null;
70
    private javax.swing.JPanel pFolio = null;
71
    private javax.swing.JLabel lSeparador = null;
72
    private IFFrame fframe;
73

    
74
    /**
75
     * This is the default constructor
76
     * 
77
     * @param l
78
     *            Referencia al Layout.
79
     */
80
    public FPositionDialog(LayoutPanel l, IFFrame fframe) {
81
        super();
82
        layout = l;
83
        this.fframe = fframe;
84

    
85
        /*
86
         * for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
87
         * IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
88
         * 
89
         * if (fframe.getSelected() != FFrame.NOSELECT) {
90
         * selecList.add(fframe);
91
         * }
92
         * }
93
         */
94
        initialize();
95
    }
96

    
97
    /**
98
     * This method initializes this
99
     */
100
    private void initialize() {
101
        this.setLayout(null);
102

    
103
        if (layout.getLayoutContext().isAdjustingToGrid()) {
104
            nf.setMaximumFractionDigits(1);
105
        } else {
106
            nf.setMaximumFractionDigits(2);
107
        }
108

    
109
        m_NameUnit = layout.getLayoutContext().getAttributes().getNameUnit();
110
        this.add(getLDesdeIzquierda(), null);
111
        this.add(getLDesdeArriba(), null);
112
        this.add(getLAnchura(), null);
113
        this.add(getLAltura(), null);
114
        this.add(getBAceptar(), null);
115
        this.add(getBCancelar(), null);
116
        this.add(getTDesdeIzquierda(), null);
117
        this.add(getTDesdeDerecha(), null);
118
        this.add(getTAnchura(), null);
119
        this.add(getTAltura(), null);
120
        this.add(getLNomUnidades(), null);
121
        this.add(getLUnidades(), null);
122
        this.add(getPFolio(), null);
123
        this.setSize(203, 215);
124
    }
125

    
126
    /**
127
     * This method initializes lDesdeIzquierda
128
     * 
129
     * @return javax.swing.JLabel
130
     */
131
    private javax.swing.JLabel getLDesdeIzquierda() {
132
        if (lDesdeIzquierda == null) {
133
            lDesdeIzquierda = new javax.swing.JLabel();
134
            lDesdeIzquierda.setBounds(9, 85, 116, 20);
135
            lDesdeIzquierda.setText(PluginServices.getText(this,
136
                "desde_izquierda"));
137
        }
138

    
139
        return lDesdeIzquierda;
140
    }
141

    
142
    /**
143
     * This method initializes lDesdeArriba
144
     * 
145
     * @return javax.swing.JLabel
146
     */
147
    private javax.swing.JLabel getLDesdeArriba() {
148
        if (lDesdeArriba == null) {
149
            lDesdeArriba = new javax.swing.JLabel();
150
            lDesdeArriba.setBounds(9, 110, 116, 20);
151
            lDesdeArriba.setText(PluginServices.getText(this, "desde_arriba"));
152
        }
153

    
154
        return lDesdeArriba;
155
    }
156

    
157
    /**
158
     * This method initializes lAnchura
159
     * 
160
     * @return javax.swing.JLabel
161
     */
162
    private javax.swing.JLabel getLAnchura() {
163
        if (lAnchura == null) {
164
            lAnchura = new javax.swing.JLabel();
165
            lAnchura.setBounds(9, 135, 116, 20);
166
            lAnchura.setText(PluginServices.getText(this, "anchura"));
167
        }
168

    
169
        return lAnchura;
170
    }
171

    
172
    /**
173
     * This method initializes lAltura
174
     * 
175
     * @return javax.swing.JLabel
176
     */
177
    private javax.swing.JLabel getLAltura() {
178
        if (lAltura == null) {
179
            lAltura = new javax.swing.JLabel();
180
            lAltura.setBounds(9, 160, 116, 20);
181
            lAltura.setText(PluginServices.getText(this, "altura"));
182
        }
183

    
184
        return lAltura;
185
    }
186

    
187
    /**
188
     * This method initializes bAceptar
189
     * 
190
     * @return javax.swing.JButton
191
     */
192
    private javax.swing.JButton getBAceptar() {
193
        if (bAceptar == null) {
194
            bAceptar = new javax.swing.JButton();
195
            bAceptar.setBounds(12, 185, 85, 23);
196
            bAceptar.setText(PluginServices.getText(this, "Aceptar"));
197
            bAceptar.addActionListener(new java.awt.event.ActionListener() {
198

    
199
                public void actionPerformed(java.awt.event.ActionEvent e) {
200
                    // if (selecList.size() == 1) {
201
                    Rectangle2D.Double r = new Rectangle2D.Double();
202

    
203
                    if (getTDesdeIzquierda().getText().equals("")) {
204
                        getTDesdeIzquierda().setText("0");
205
                    }
206

    
207
                    if (getTDesdeDerecha().getText().equals("")) {
208
                        getTDesdeDerecha().setText("0");
209
                    }
210

    
211
                    if (getTAnchura().getText().equals("")) {
212
                        getTAnchura().setText("0");
213
                    }
214

    
215
                    if (getTAltura().getText().equals("")) {
216
                        getTAltura().setText("0");
217
                    }
218

    
219
                    r.x =
220
                        stringToDouble(getTDesdeIzquierda().getText()
221
                            .toString());
222
                    r.y =
223
                        stringToDouble(getTDesdeDerecha().getText().toString());
224
                    r.width =
225
                        stringToDouble(getTAnchura().getText().toString());
226
                    r.height =
227
                        stringToDouble(getTAltura().getText().toString());
228

    
229
                    // ((IFFrame) selecList.get(0)).setBoundBox(r);
230
                    IFFrame fframeAux;
231
                    try {
232
                        fframeAux = (IFFrame) fframe.clone();
233
                        fframeAux.setBoundBox(r);
234
                        layout.getLayoutContext().getFrameCommandsRecord()
235
                            .update(fframe, fframeAux);
236
                        layout.getLayoutContext().updateFFrames();
237
                    } catch (CloneNotSupportedException e1) {
238
                        LOG.error("It is not possible clonate the object", e);
239
                    }
240

    
241
                    PluginServices.getMDIManager().closeWindow(
242
                        FPositionDialog.this);
243
                    layout.getLayoutControl().setStatus(
244
                        LayoutControl.DESACTUALIZADO);
245
                    layout.repaint();
246
                }
247
            });
248
        }
249

    
250
        return bAceptar;
251
    }
252

    
253
    /**
254
     * Paso de String a double.
255
     * 
256
     * @param s
257
     *            String.
258
     * 
259
     * @return double obtenido.
260
     */
261
    private double stringToDouble(String s) {
262
        String snew = s.replace(',', '.');
263

    
264
        return layout.getLayoutContext().getAttributes()
265
            .fromUnits(Double.parseDouble(snew));
266
    }
267

    
268
    /**
269
     * This method initializes bCancelar
270
     * 
271
     * @return javax.swing.JButton
272
     */
273
    private javax.swing.JButton getBCancelar() {
274
        if (bCancelar == null) {
275
            bCancelar = new javax.swing.JButton();
276
            bCancelar.setBounds(107, 185, 87, 23);
277
            bCancelar.setText(PluginServices.getText(this, "Cancelar"));
278
            bCancelar.addActionListener(new java.awt.event.ActionListener() {
279

    
280
                public void actionPerformed(java.awt.event.ActionEvent e) {
281
                    PluginServices.getMDIManager().closeWindow(
282
                        FPositionDialog.this);
283
                }
284
            });
285
        }
286

    
287
        return bCancelar;
288
    }
289

    
290
    /**
291
     * This method initializes tDesdeIzquierda
292
     * 
293
     * @return javax.swing.JTextField
294
     */
295
    private javax.swing.JTextField getTDesdeIzquierda() {
296
        if (tDesdeIzquierda == null) {
297
            tDesdeIzquierda = new javax.swing.JTextField();
298
            tDesdeIzquierda.setBounds(132, 85, 53, 20);
299
            tDesdeIzquierda.setText(String.valueOf(nf.format(layout
300
                .getLayoutContext().getAttributes()
301
                .toUnits(fframe.getBoundBox().x))));
302
        }
303

    
304
        return tDesdeIzquierda;
305
    }
306

    
307
    /**
308
     * This method initializes tDesdeDerecha
309
     * 
310
     * @return javax.swing.JTextField
311
     */
312
    private javax.swing.JTextField getTDesdeDerecha() {
313
        if (tDesdeDerecha == null) {
314
            tDesdeDerecha = new javax.swing.JTextField();
315
            tDesdeDerecha.setBounds(132, 110, 53, 20);
316
            tDesdeDerecha.setText(String.valueOf(nf.format(layout
317
                .getLayoutContext().getAttributes()
318
                .toUnits(fframe.getBoundBox().y))));
319
        }
320

    
321
        return tDesdeDerecha;
322
    }
323

    
324
    /**
325
     * This method initializes tAnchura
326
     * 
327
     * @return javax.swing.JTextField
328
     */
329
    private javax.swing.JTextField getTAnchura() {
330
        if (tAnchura == null) {
331
            tAnchura = new javax.swing.JTextField();
332
            tAnchura.setBounds(132, 135, 53, 20);
333
            tAnchura.setText(String.valueOf(nf.format(layout.getLayoutContext()
334
                .getAttributes().toUnits(fframe.getBoundBox().width))));
335
        }
336

    
337
        return tAnchura;
338
    }
339

    
340
    /**
341
     * This method initializes tAltura
342
     * 
343
     * @return javax.swing.JTextField
344
     */
345
    private javax.swing.JTextField getTAltura() {
346
        if (tAltura == null) {
347
            tAltura = new javax.swing.JTextField();
348
            tAltura.setBounds(132, 160, 53, 20);
349
            tAltura.setText(String.valueOf(nf.format(layout.getLayoutContext()
350
                .getAttributes().toUnits(fframe.getBoundBox().height))));
351
        }
352

    
353
        return tAltura;
354
    }
355

    
356
    /**
357
     * This method initializes lNomUnidades
358
     * 
359
     * @return javax.swing.JLabel
360
     */
361
    private javax.swing.JLabel getLNomUnidades() {
362
        if (lNomUnidades == null) {
363
            lNomUnidades = new javax.swing.JLabel();
364
            lNomUnidades.setBounds(91, 7, 91, 20);
365
            lNomUnidades.setText(PluginServices.getText(this, m_NameUnit));
366
        }
367

    
368
        return lNomUnidades;
369
    }
370

    
371
    /**
372
     * This method initializes lUnidades
373
     * 
374
     * @return javax.swing.JLabel
375
     */
376
    private javax.swing.JLabel getLUnidades() {
377
        if (lUnidades == null) {
378
            lUnidades = new javax.swing.JLabel();
379
            lUnidades.setBounds(7, 7, 72, 20);
380
            lUnidades.setText(PluginServices.getText(this, "unidades"));
381
        }
382

    
383
        return lUnidades;
384
    }
385

    
386
    /**
387
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
388
     */
389
    public WindowInfo getWindowInfo() {
390
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
391

    
392
        // vi.setResizable(false);
393
        m_viewinfo.setTitle(PluginServices.getText(this, "tamano_posicion"));
394

    
395
        return m_viewinfo;
396
    }
397

    
398
    /**
399
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
400
     */
401
    public void viewActivated() {
402
    }
403

    
404
    /**
405
     * This method initializes lAnchoUnidades
406
     * 
407
     * @return javax.swing.JLabel
408
     */
409
    private javax.swing.JLabel getLAnchoUnidades() {
410
        if (lAnchoUnidades == null) {
411
            lAnchoUnidades = new javax.swing.JLabel();
412

    
413
            if (layout.getLayoutContext().getAttributes().isLandSpace()) {
414
                lAnchoUnidades.setText(String.valueOf(nf.format(layout
415
                    .getLayoutContext().getAttributes().getSizeInUnits()
416
                    .getAlto())));
417
            } else {
418
                lAnchoUnidades.setText(String.valueOf(nf.format(layout
419
                    .getLayoutContext().getAttributes().getSizeInUnits()
420
                    .getAncho())));
421
            }
422
        }
423

    
424
        return lAnchoUnidades;
425
    }
426

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

    
438
        return lAlto;
439
    }
440

    
441
    /**
442
     * This method initializes lAltoUnidades
443
     * 
444
     * @return javax.swing.JLabel
445
     */
446
    private javax.swing.JLabel getLAltoUnidades() {
447
        if (lAltoUnidades == null) {
448
            lAltoUnidades = new javax.swing.JLabel();
449

    
450
            if (layout.getLayoutContext().getAttributes().isLandSpace()) {
451
                lAltoUnidades.setText(String.valueOf(nf.format(layout
452
                    .getLayoutContext().getAttributes().getSizeInUnits()
453
                    .getAncho())));
454
            } else {
455
                lAltoUnidades.setText(String.valueOf(nf.format(layout
456
                    .getLayoutContext().getAttributes().getSizeInUnits()
457
                    .getAlto())));
458
            }
459
        }
460

    
461
        return lAltoUnidades;
462
    }
463

    
464
    /**
465
     * This method initializes lAncho
466
     * 
467
     * @return javax.swing.JLabel
468
     */
469
    private javax.swing.JLabel getLAncho() {
470
        if (lAncho == null) {
471
            lAncho = new javax.swing.JLabel();
472
            lAncho.setText(PluginServices.getText(this, "ancho"));
473
        }
474

    
475
        return lAncho;
476
    }
477

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

    
498
        return pFolio;
499
    }
500

    
501
    /**
502
     * This method initializes lSeparador
503
     * 
504
     * @return javax.swing.JLabel
505
     */
506
    private javax.swing.JLabel getLSeparador() {
507
        if (lSeparador == null) {
508
            lSeparador = new javax.swing.JLabel();
509
            lSeparador.setText("/");
510
        }
511

    
512
        return lSeparador;
513
    }
514

    
515
    public Object getWindowProfile() {
516
        return WindowInfo.DIALOG_PROFILE;
517
    }
518

    
519
}