Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / dialogs / FPositionDialog.java @ 1763

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 com.iver.andami.PluginServices;
48
import com.iver.andami.ui.mdiManager.View;
49
import com.iver.andami.ui.mdiManager.ViewInfo;
50

    
51
import com.iver.cit.gvsig.gui.layout.Layout;
52
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
53
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
54

    
55
import java.awt.geom.Rectangle2D;
56

    
57
import java.text.NumberFormat;
58

    
59
import java.util.ArrayList;
60

    
61
import javax.swing.JPanel;
62

    
63

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

    
104
                /*for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
105
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
106

107
                        if (fframe.getSelected() != FFrame.NOSELECT) {
108
                                selecList.add(fframe);
109
                        }
110
                }
111
                */
112
                initialize();
113
        }
114

    
115
        /**
116
         * This method initializes this
117
         */
118
        private void initialize() {
119
                this.setLayout(null);
120

    
121
                if (layout.isCuadricula()) {
122
                        nf.setMaximumFractionDigits(1);
123
                } else {
124
                        nf.setMaximumFractionDigits(2);
125
                }
126

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

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

    
157
                return lDesdeIzquierda;
158
        }
159

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

    
172
                return lDesdeArriba;
173
        }
174

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

    
187
                return lAnchura;
188
        }
189

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

    
202
                return lAltura;
203
        }
204

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

    
220
                                                        if (getTDesdeIzquierda().getText().equals("")) {
221
                                                                getTDesdeIzquierda().setText("0");
222
                                                        }
223

    
224
                                                        if (getTDesdeDerecha().getText().equals("")) {
225
                                                                getTDesdeDerecha().setText("0");
226
                                                        }
227

    
228
                                                        if (getTAnchura().getText().equals("")) {
229
                                                                getTAnchura().setText("0");
230
                                                        }
231

    
232
                                                        if (getTAltura().getText().equals("")) {
233
                                                                getTAltura().setText("0");
234
                                                        }
235

    
236
                                                        r.x = stringToDouble(getTDesdeIzquierda().getText()
237
                                                                                                         .toString());
238
                                                        r.y = stringToDouble(getTDesdeDerecha().getText()
239
                                                                                                         .toString());
240
                                                        r.width = stringToDouble(getTAnchura().getText()
241
                                                                                                                 .toString());
242
                                                        r.height = stringToDouble(getTAltura().getText()
243
                                                                                                                  .toString());
244

    
245
                                                        //((IFFrame) selecList.get(0)).setBoundBox(r);
246
                                                        fframe.setBoundBox(r);
247
                                                //}
248

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

    
256
                return bAceptar;
257
        }
258

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

    
269
                return layout.getAtributes().fromUnits(Double.parseDouble(snew));
270
        }
271

    
272
        /**
273
         * This method initializes bCancelar
274
         *
275
         * @return javax.swing.JButton
276
         */
277
        private javax.swing.JButton getBCancelar() {
278
                if (bCancelar == null) {
279
                        bCancelar = new javax.swing.JButton();
280
                        bCancelar.setBounds(107, 185, 87, 23);
281
                        bCancelar.setText(PluginServices.getText(this, "Cancelar"));
282
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
283
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
284
                                                PluginServices.getMDIManager().closeView(FPositionDialog.this);
285
                                        }
286
                                });
287
                }
288

    
289
                return bCancelar;
290
        }
291

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

    
305
                return tDesdeIzquierda;
306
        }
307

    
308
        /**
309
         * This method initializes tDesdeDerecha
310
         *
311
         * @return javax.swing.JTextField
312
         */
313
        private javax.swing.JTextField getTDesdeDerecha() {
314
                if (tDesdeDerecha == null) {
315
                        tDesdeDerecha = new javax.swing.JTextField();
316
                        tDesdeDerecha.setBounds(132, 110, 53, 20);
317
                        tDesdeDerecha.setText(String.valueOf(nf.format(
318
                                                layout.getAtributes().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(
334
                                                layout.getAtributes().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.getAtributes()
350
                                                                                                                   .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(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.View#getViewInfo()
388
         */
389
        public ViewInfo getViewInfo() {
390
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
391

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

    
395
                return m_viewinfo;
396
        }
397

    
398
        /**
399
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
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.getAtributes().isLandSpace()) {
414
                                lAnchoUnidades.setText(String.valueOf(nf.format(
415
                                                        layout.getAtributes().getSizeInUnits().getAlto())));
416
                        } else {
417
                                lAnchoUnidades.setText(String.valueOf(nf.format(
418
                                                        layout.getAtributes().getSizeInUnits().getAncho())));
419
                        }
420
                }
421

    
422
                return lAnchoUnidades;
423
        }
424

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

    
436
                return lAlto;
437
        }
438

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

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

    
457
                return lAltoUnidades;
458
        }
459

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

    
471
                return lAncho;
472
        }
473

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

    
494
                return pFolio;
495
        }
496

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

    
508
                return lSeparador;
509
        }
510
}