Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / dialogs / FPositionDialog.java @ 5503

History | View | Annotate | Download (12.8 KB)

1
/*
2
 * Created on 31-ago-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.gui.layout.dialogs;
46

    
47
import java.awt.geom.Rectangle2D;
48
import java.text.NumberFormat;
49

    
50
import javax.swing.JPanel;
51

    
52
import com.iver.andami.PluginServices;
53
import com.iver.andami.ui.mdiManager.View;
54
import com.iver.andami.ui.mdiManager.ViewInfo;
55
import com.iver.cit.gvsig.gui.layout.Layout;
56
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
57

    
58

    
59
/**
60
 * Di?logo que ofrece la posibilidad de posicionar el fframe en un punto en
61
 * concreto del Layout.
62
 *
63
 * @author Vicente Caballero Navarro
64
 */
65
public class FPositionDialog extends JPanel implements View {
66
        private javax.swing.JLabel lDesdeIzquierda = null;
67
        private javax.swing.JLabel lDesdeArriba = null;
68
        private javax.swing.JLabel lAnchura = null;
69
        private javax.swing.JLabel lAltura = null;
70
        private javax.swing.JButton bAceptar = null;
71
        private javax.swing.JButton bCancelar = null;
72
        private javax.swing.JTextField tDesdeIzquierda = null;
73
        private javax.swing.JTextField tDesdeDerecha = null;
74
        private javax.swing.JTextField tAnchura = null;
75
        private javax.swing.JTextField tAltura = null;
76
        private javax.swing.JLabel lNomUnidades = null;
77
        private javax.swing.JLabel lUnidades = null;
78
        private Layout layout = null;
79
        private String m_NameUnit = null;
80
        //private ArrayList selecList = new ArrayList();
81
        NumberFormat nf = NumberFormat.getInstance();
82
        private javax.swing.JLabel lAnchoUnidades = null;
83
        private javax.swing.JLabel lAlto = null;
84
        private javax.swing.JLabel lAltoUnidades = null;
85
        private javax.swing.JLabel lAncho = null;
86
        private javax.swing.JPanel pFolio = null;
87
        private javax.swing.JLabel lSeparador = null;
88
        private IFFrame fframe;
89
        /**
90
         * This is the default constructor
91
         *
92
         * @param l Referencia al Layout.
93
         */
94
        public FPositionDialog(Layout l,IFFrame fframe) {
95
                super();
96
                layout = l;
97
                this.fframe=fframe;
98

    
99
                /*for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
100
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
101

102
                        if (fframe.getSelected() != FFrame.NOSELECT) {
103
                                selecList.add(fframe);
104
                        }
105
                }
106
                */
107
                initialize();
108
        }
109

    
110
        /**
111
         * This method initializes this
112
         */
113
        private void initialize() {
114
                this.setLayout(null);
115

    
116
                if (layout.isCuadricula()) {
117
                        nf.setMaximumFractionDigits(1);
118
                } else {
119
                        nf.setMaximumFractionDigits(2);
120
                }
121

    
122
                m_NameUnit = layout.getAtributes().getNameUnit();
123
                this.add(getLDesdeIzquierda(), null);
124
                this.add(getLDesdeArriba(), null);
125
                this.add(getLAnchura(), null);
126
                this.add(getLAltura(), null);
127
                this.add(getBAceptar(), null);
128
                this.add(getBCancelar(), null);
129
                this.add(getTDesdeIzquierda(), null);
130
                this.add(getTDesdeDerecha(), null);
131
                this.add(getTAnchura(), null);
132
                this.add(getTAltura(), null);
133
                this.add(getLNomUnidades(), null);
134
                this.add(getLUnidades(), null);
135
                this.add(getPFolio(), null);
136
                this.setSize(203, 215);
137
        }
138

    
139
        /**
140
         * This method initializes lDesdeIzquierda
141
         *
142
         * @return javax.swing.JLabel
143
         */
144
        private javax.swing.JLabel getLDesdeIzquierda() {
145
                if (lDesdeIzquierda == null) {
146
                        lDesdeIzquierda = new javax.swing.JLabel();
147
                        lDesdeIzquierda.setBounds(9, 85, 116, 20);
148
                        lDesdeIzquierda.setText(PluginServices.getText(this,
149
                                        "desde_izquierda"));
150
                }
151

    
152
                return lDesdeIzquierda;
153
        }
154

    
155
        /**
156
         * This method initializes lDesdeArriba
157
         *
158
         * @return javax.swing.JLabel
159
         */
160
        private javax.swing.JLabel getLDesdeArriba() {
161
                if (lDesdeArriba == null) {
162
                        lDesdeArriba = new javax.swing.JLabel();
163
                        lDesdeArriba.setBounds(9, 110, 116, 20);
164
                        lDesdeArriba.setText(PluginServices.getText(this, "desde_arriba"));
165
                }
166

    
167
                return lDesdeArriba;
168
        }
169

    
170
        /**
171
         * This method initializes lAnchura
172
         *
173
         * @return javax.swing.JLabel
174
         */
175
        private javax.swing.JLabel getLAnchura() {
176
                if (lAnchura == null) {
177
                        lAnchura = new javax.swing.JLabel();
178
                        lAnchura.setBounds(9, 135, 116, 20);
179
                        lAnchura.setText(PluginServices.getText(this, "anchura"));
180
                }
181

    
182
                return lAnchura;
183
        }
184

    
185
        /**
186
         * This method initializes lAltura
187
         *
188
         * @return javax.swing.JLabel
189
         */
190
        private javax.swing.JLabel getLAltura() {
191
                if (lAltura == null) {
192
                        lAltura = new javax.swing.JLabel();
193
                        lAltura.setBounds(9, 160, 116, 20);
194
                        lAltura.setText(PluginServices.getText(this, "altura"));
195
                }
196

    
197
                return lAltura;
198
        }
199

    
200
        /**
201
         * This method initializes bAceptar
202
         *
203
         * @return javax.swing.JButton
204
         */
205
        private javax.swing.JButton getBAceptar() {
206
                if (bAceptar == null) {
207
                        bAceptar = new javax.swing.JButton();
208
                        bAceptar.setBounds(12, 185, 85, 23);
209
                        bAceptar.setText(PluginServices.getText(this, "Aceptar"));
210
                        bAceptar.addActionListener(new java.awt.event.ActionListener() {
211
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
212
                                                //if (selecList.size() == 1) {
213
                                                        Rectangle2D.Double r = new Rectangle2D.Double();
214

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

    
219
                                                        if (getTDesdeDerecha().getText().equals("")) {
220
                                                                getTDesdeDerecha().setText("0");
221
                                                        }
222

    
223
                                                        if (getTAnchura().getText().equals("")) {
224
                                                                getTAnchura().setText("0");
225
                                                        }
226

    
227
                                                        if (getTAltura().getText().equals("")) {
228
                                                                getTAltura().setText("0");
229
                                                        }
230

    
231
                                                        r.x = stringToDouble(getTDesdeIzquierda().getText()
232
                                                                                                         .toString());
233
                                                        r.y = stringToDouble(getTDesdeDerecha().getText()
234
                                                                                                         .toString());
235
                                                        r.width = stringToDouble(getTAnchura().getText()
236
                                                                                                                 .toString());
237
                                                        r.height = stringToDouble(getTAltura().getText()
238
                                                                                                                  .toString());
239

    
240
                                                        //((IFFrame) selecList.get(0)).setBoundBox(r);
241
                                                        IFFrame fframeAux=fframe.cloneFFrame(layout);
242
                                                        fframeAux.setBoundBox(r);
243
                                                        layout.getEFS().modifyFFrame(fframe,fframeAux);
244
                                                        layout.updateFFrames();
245
                                                //}
246

    
247
                                                PluginServices.getMDIManager().closeView(FPositionDialog.this);
248
                                                layout.setStatus(Layout.DESACTUALIZADO);
249
                                                layout.repaint();
250
                                        }
251
                                });
252
                }
253

    
254
                return bAceptar;
255
        }
256

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

    
267
                return layout.getAtributes().fromUnits(Double.parseDouble(snew));
268
        }
269

    
270
        /**
271
         * This method initializes bCancelar
272
         *
273
         * @return javax.swing.JButton
274
         */
275
        private javax.swing.JButton getBCancelar() {
276
                if (bCancelar == null) {
277
                        bCancelar = new javax.swing.JButton();
278
                        bCancelar.setBounds(107, 185, 87, 23);
279
                        bCancelar.setText(PluginServices.getText(this, "Cancelar"));
280
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
281
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
282
                                                PluginServices.getMDIManager().closeView(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(
300
                                                layout.getAtributes().toUnits(fframe.getBoundBox().x))));
301
                }
302

    
303
                return tDesdeIzquierda;
304
        }
305

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

    
319
                return tDesdeDerecha;
320
        }
321

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

    
335
                return tAnchura;
336
        }
337

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

    
351
                return tAltura;
352
        }
353

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

    
366
                return lNomUnidades;
367
        }
368

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

    
381
                return lUnidades;
382
        }
383

    
384
        /**
385
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
386
         */
387
        public ViewInfo getViewInfo() {
388
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
389

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

    
393
                return m_viewinfo;
394
        }
395

    
396
        /**
397
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
398
         */
399
        public void viewActivated() {
400
        }
401

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

    
411
                        if (layout.getAtributes().isLandSpace()) {
412
                                lAnchoUnidades.setText(String.valueOf(nf.format(
413
                                                        layout.getAtributes().getSizeInUnits().getAlto())));
414
                        } else {
415
                                lAnchoUnidades.setText(String.valueOf(nf.format(
416
                                                        layout.getAtributes().getSizeInUnits().getAncho())));
417
                        }
418
                }
419

    
420
                return lAnchoUnidades;
421
        }
422

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

    
434
                return lAlto;
435
        }
436

    
437
        /**
438
         * This method initializes lAltoUnidades
439
         *
440
         * @return javax.swing.JLabel
441
         */
442
        private javax.swing.JLabel getLAltoUnidades() {
443
                if (lAltoUnidades == null) {
444
                        lAltoUnidades = new javax.swing.JLabel();
445

    
446
                        if (layout.getAtributes().isLandSpace()) {
447
                                lAltoUnidades.setText(String.valueOf(nf.format(
448
                                                        layout.getAtributes().getSizeInUnits().getAncho())));
449
                        } else {
450
                                lAltoUnidades.setText(String.valueOf(nf.format(
451
                                                        layout.getAtributes().getSizeInUnits().getAlto())));
452
                        }
453
                }
454

    
455
                return lAltoUnidades;
456
        }
457

    
458
        /**
459
         * This method initializes lAncho
460
         *
461
         * @return javax.swing.JLabel
462
         */
463
        private javax.swing.JLabel getLAncho() {
464
                if (lAncho == null) {
465
                        lAncho = new javax.swing.JLabel();
466
                        lAncho.setText(PluginServices.getText(this, "ancho"));
467
                }
468

    
469
                return lAncho;
470
        }
471

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

    
492
                return pFolio;
493
        }
494

    
495
        /**
496
         * This method initializes lSeparador
497
         *
498
         * @return javax.swing.JLabel
499
         */
500
        private javax.swing.JLabel getLSeparador() {
501
                if (lSeparador == null) {
502
                        lSeparador = new javax.swing.JLabel();
503
                        lSeparador.setText("/");
504
                }
505

    
506
                return lSeparador;
507
        }
508
}