Statistics
| Revision:

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

History | View | Annotate | Download (11.6 KB)

1
/*
2
 * Created on 31-ago-2004
3
 *
4
 */
5
package com.iver.cit.gvsig.gui.layout.dialogs;
6

    
7
import com.iver.andami.PluginServices;
8
import com.iver.andami.ui.mdiManager.View;
9
import com.iver.andami.ui.mdiManager.ViewInfo;
10

    
11
import com.iver.cit.gvsig.gui.layout.Layout;
12
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
13
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
14

    
15
import java.awt.geom.Rectangle2D;
16

    
17
import java.text.NumberFormat;
18

    
19
import java.util.ArrayList;
20

    
21
import javax.swing.JPanel;
22

    
23

    
24
/**
25
 * Di?logo que ofrece la posibilidad de posicionar el fframe en un punto en
26
 * concreto del Layout.
27
 *
28
 * @author Vicente Caballero Navarro
29
 */
30
public class FPositionDialog extends JPanel implements View {
31
        private javax.swing.JLabel lDesdeIzquierda = null;
32
        private javax.swing.JLabel lDesdeArriba = null;
33
        private javax.swing.JLabel lAnchura = null;
34
        private javax.swing.JLabel lAltura = null;
35
        private javax.swing.JButton bAceptar = null;
36
        private javax.swing.JButton bCancelar = null;
37
        private javax.swing.JTextField tDesdeIzquierda = null;
38
        private javax.swing.JTextField tDesdeDerecha = null;
39
        private javax.swing.JTextField tAnchura = null;
40
        private javax.swing.JTextField tAltura = null;
41
        private javax.swing.JLabel lNomUnidades = null;
42
        private javax.swing.JLabel lUnidades = null;
43
        private Layout layout = null;
44
        private String m_NameUnit = null;
45
        private ArrayList selecList = new ArrayList();
46
        NumberFormat nf = NumberFormat.getInstance();
47
        private javax.swing.JLabel lAnchoUnidades = null;
48
        private javax.swing.JLabel lAlto = null;
49
        private javax.swing.JLabel lAltoUnidades = null;
50
        private javax.swing.JLabel lAncho = null;
51
        private javax.swing.JPanel pFolio = null;
52
        private javax.swing.JLabel lSeparador = null;
53

    
54
        /**
55
         * This is the default constructor
56
         *
57
         * @param l Referencia al Layout.
58
         */
59
        public FPositionDialog(Layout l) {
60
                super();
61
                layout = l;
62

    
63
                for (int i = layout.getFFrames().size() - 1; i >= 0; i--) {
64
                        IFFrame fframe = (IFFrame) layout.getFFrames().get(i);
65

    
66
                        if (fframe.getSelected() != FFrame.NOSELECT) {
67
                                selecList.add(fframe);
68
                        }
69
                }
70

    
71
                initialize();
72
        }
73

    
74
        /**
75
         * This method initializes this
76
         */
77
        private void initialize() {
78
                this.setLayout(null);
79

    
80
                if (layout.isCuadricula()) {
81
                        nf.setMaximumFractionDigits(1);
82
                } else {
83
                        nf.setMaximumFractionDigits(2);
84
                }
85

    
86
                m_NameUnit = layout.getAtributes().getNameUnit();
87
                this.add(getLDesdeIzquierda(), null);
88
                this.add(getLDesdeArriba(), null);
89
                this.add(getLAnchura(), null);
90
                this.add(getLAltura(), null);
91
                this.add(getBAceptar(), null);
92
                this.add(getBCancelar(), null);
93
                this.add(getTDesdeIzquierda(), null);
94
                this.add(getTDesdeDerecha(), null);
95
                this.add(getTAnchura(), null);
96
                this.add(getTAltura(), null);
97
                this.add(getLNomUnidades(), null);
98
                this.add(getLUnidades(), null);
99
                this.add(getPFolio(), null);
100
                this.setSize(203, 215);
101
        }
102

    
103
        /**
104
         * This method initializes lDesdeIzquierda
105
         *
106
         * @return javax.swing.JLabel
107
         */
108
        private javax.swing.JLabel getLDesdeIzquierda() {
109
                if (lDesdeIzquierda == null) {
110
                        lDesdeIzquierda = new javax.swing.JLabel();
111
                        lDesdeIzquierda.setBounds(9, 85, 116, 20);
112
                        lDesdeIzquierda.setText(PluginServices.getText(this,
113
                                        "desde_izquierda"));
114
                }
115

    
116
                return lDesdeIzquierda;
117
        }
118

    
119
        /**
120
         * This method initializes lDesdeArriba
121
         *
122
         * @return javax.swing.JLabel
123
         */
124
        private javax.swing.JLabel getLDesdeArriba() {
125
                if (lDesdeArriba == null) {
126
                        lDesdeArriba = new javax.swing.JLabel();
127
                        lDesdeArriba.setBounds(9, 110, 116, 20);
128
                        lDesdeArriba.setText(PluginServices.getText(this, "desde_arriba"));
129
                }
130

    
131
                return lDesdeArriba;
132
        }
133

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

    
146
                return lAnchura;
147
        }
148

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

    
161
                return lAltura;
162
        }
163

    
164
        /**
165
         * This method initializes bAceptar
166
         *
167
         * @return javax.swing.JButton
168
         */
169
        private javax.swing.JButton getBAceptar() {
170
                if (bAceptar == null) {
171
                        bAceptar = new javax.swing.JButton();
172
                        bAceptar.setBounds(12, 185, 85, 23);
173
                        bAceptar.setText(PluginServices.getText(this, "Aceptar"));
174
                        bAceptar.addActionListener(new java.awt.event.ActionListener() {
175
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
176
                                                if (selecList.size() == 1) {
177
                                                        Rectangle2D.Double r = new Rectangle2D.Double();
178

    
179
                                                        if (getTDesdeIzquierda().getText().equals("")) {
180
                                                                getTDesdeIzquierda().setText("0");
181
                                                        }
182

    
183
                                                        if (getTDesdeDerecha().getText().equals("")) {
184
                                                                getTDesdeDerecha().setText("0");
185
                                                        }
186

    
187
                                                        if (getTAnchura().getText().equals("")) {
188
                                                                getTAnchura().setText("0");
189
                                                        }
190

    
191
                                                        if (getTAltura().getText().equals("")) {
192
                                                                getTAltura().setText("0");
193
                                                        }
194

    
195
                                                        r.x = stringToDouble(getTDesdeIzquierda().getText()
196
                                                                                                         .toString());
197
                                                        r.y = stringToDouble(getTDesdeDerecha().getText()
198
                                                                                                         .toString());
199
                                                        r.width = stringToDouble(getTAnchura().getText()
200
                                                                                                                 .toString());
201
                                                        r.height = stringToDouble(getTAltura().getText()
202
                                                                                                                  .toString());
203

    
204
                                                        ((IFFrame) selecList.get(0)).setBoundBox(r);
205
                                                }
206

    
207
                                                PluginServices.getMDIManager().closeView(FPositionDialog.this);
208
                                                layout.setStatus(Layout.DESACTUALIZADO);
209
                                                layout.repaint();
210
                                        }
211
                                });
212
                }
213

    
214
                return bAceptar;
215
        }
216

    
217
        /**
218
         * Paso de String a double.
219
         *
220
         * @param s String.
221
         *
222
         * @return double obtenido.
223
         */
224
        private double stringToDouble(String s) {
225
                String snew = s.replace(',', '.');
226

    
227
                return layout.getAtributes().fromUnits(Double.parseDouble(snew));
228
        }
229

    
230
        /**
231
         * This method initializes bCancelar
232
         *
233
         * @return javax.swing.JButton
234
         */
235
        private javax.swing.JButton getBCancelar() {
236
                if (bCancelar == null) {
237
                        bCancelar = new javax.swing.JButton();
238
                        bCancelar.setBounds(107, 185, 87, 23);
239
                        bCancelar.setText(PluginServices.getText(this, "Cancelar"));
240
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
241
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
242
                                                PluginServices.getMDIManager().closeView(FPositionDialog.this);
243
                                        }
244
                                });
245
                }
246

    
247
                return bCancelar;
248
        }
249

    
250
        /**
251
         * This method initializes tDesdeIzquierda
252
         *
253
         * @return javax.swing.JTextField
254
         */
255
        private javax.swing.JTextField getTDesdeIzquierda() {
256
                if (tDesdeIzquierda == null) {
257
                        tDesdeIzquierda = new javax.swing.JTextField();
258
                        tDesdeIzquierda.setBounds(132, 85, 53, 20);
259
                        tDesdeIzquierda.setText(String.valueOf(nf.format(
260
                                                layout.getAtributes().toUnits(((IFFrame) selecList.get(
261
                                                                0)).getBoundBox().x))));
262
                }
263

    
264
                return tDesdeIzquierda;
265
        }
266

    
267
        /**
268
         * This method initializes tDesdeDerecha
269
         *
270
         * @return javax.swing.JTextField
271
         */
272
        private javax.swing.JTextField getTDesdeDerecha() {
273
                if (tDesdeDerecha == null) {
274
                        tDesdeDerecha = new javax.swing.JTextField();
275
                        tDesdeDerecha.setBounds(132, 110, 53, 20);
276
                        tDesdeDerecha.setText(String.valueOf(nf.format(
277
                                                layout.getAtributes().toUnits(((IFFrame) selecList.get(
278
                                                                0)).getBoundBox().y))));
279
                }
280

    
281
                return tDesdeDerecha;
282
        }
283

    
284
        /**
285
         * This method initializes tAnchura
286
         *
287
         * @return javax.swing.JTextField
288
         */
289
        private javax.swing.JTextField getTAnchura() {
290
                if (tAnchura == null) {
291
                        tAnchura = new javax.swing.JTextField();
292
                        tAnchura.setBounds(132, 135, 53, 20);
293
                        tAnchura.setText(String.valueOf(nf.format(
294
                                                layout.getAtributes().toUnits(((IFFrame) selecList.get(
295
                                                                0)).getBoundBox().width))));
296
                }
297

    
298
                return tAnchura;
299
        }
300

    
301
        /**
302
         * This method initializes tAltura
303
         *
304
         * @return javax.swing.JTextField
305
         */
306
        private javax.swing.JTextField getTAltura() {
307
                if (tAltura == null) {
308
                        tAltura = new javax.swing.JTextField();
309
                        tAltura.setBounds(132, 160, 53, 20);
310
                        tAltura.setText(String.valueOf(nf.format(layout.getAtributes()
311
                                                                                                                   .toUnits(((IFFrame) selecList.get(
312
                                                                0)).getBoundBox().height))));
313
                }
314

    
315
                return tAltura;
316
        }
317

    
318
        /**
319
         * This method initializes lNomUnidades
320
         *
321
         * @return javax.swing.JLabel
322
         */
323
        private javax.swing.JLabel getLNomUnidades() {
324
                if (lNomUnidades == null) {
325
                        lNomUnidades = new javax.swing.JLabel();
326
                        lNomUnidades.setBounds(91, 7, 91, 20);
327
                        lNomUnidades.setText(m_NameUnit);
328
                }
329

    
330
                return lNomUnidades;
331
        }
332

    
333
        /**
334
         * This method initializes lUnidades
335
         *
336
         * @return javax.swing.JLabel
337
         */
338
        private javax.swing.JLabel getLUnidades() {
339
                if (lUnidades == null) {
340
                        lUnidades = new javax.swing.JLabel();
341
                        lUnidades.setBounds(7, 7, 72, 20);
342
                        lUnidades.setText(PluginServices.getText(this, "unidades"));
343
                }
344

    
345
                return lUnidades;
346
        }
347

    
348
        /**
349
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
350
         */
351
        public ViewInfo getViewInfo() {
352
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
353

    
354
                //vi.setResizable(false);
355
                m_viewinfo.setTitle(PluginServices.getText(this, "tama?o_posicion"));
356

    
357
                return m_viewinfo;
358
        }
359

    
360
        /**
361
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
362
         */
363
        public void viewActivated() {
364
        }
365

    
366
        /**
367
         * This method initializes lAnchoUnidades
368
         *
369
         * @return javax.swing.JLabel
370
         */
371
        private javax.swing.JLabel getLAnchoUnidades() {
372
                if (lAnchoUnidades == null) {
373
                        lAnchoUnidades = new javax.swing.JLabel();
374

    
375
                        if (layout.getAtributes().isLandSpace()) {
376
                                lAnchoUnidades.setText(String.valueOf(nf.format(
377
                                                        layout.getAtributes().getSizeInUnits().getAlto())));
378
                        } else {
379
                                lAnchoUnidades.setText(String.valueOf(nf.format(
380
                                                        layout.getAtributes().getSizeInUnits().getAncho())));
381
                        }
382
                }
383

    
384
                return lAnchoUnidades;
385
        }
386

    
387
        /**
388
         * This method initializes lAlto
389
         *
390
         * @return javax.swing.JLabel
391
         */
392
        private javax.swing.JLabel getLAlto() {
393
                if (lAlto == null) {
394
                        lAlto = new javax.swing.JLabel();
395
                        lAlto.setText(PluginServices.getText(this, "alto"));
396
                }
397

    
398
                return lAlto;
399
        }
400

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

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

    
419
                return lAltoUnidades;
420
        }
421

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

    
433
                return lAncho;
434
        }
435

    
436
        /**
437
         * This method initializes pFolio
438
         *
439
         * @return javax.swing.JPanel
440
         */
441
        private javax.swing.JPanel getPFolio() {
442
                if (pFolio == null) {
443
                        pFolio = new javax.swing.JPanel();
444
                        pFolio.add(getLAltoUnidades(), null);
445
                        pFolio.add(getLAlto(), null);
446
                        pFolio.add(getLSeparador(), null);
447
                        pFolio.add(getLAnchoUnidades(), null);
448
                        pFolio.add(getLAncho(), null);
449
                        pFolio.setBounds(9, 31, 180, 43);
450
                        pFolio.setBorder(javax.swing.BorderFactory.createTitledBorder(
451
                                        null, PluginServices.getText(this, "tama?o_pagina"),
452
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
453
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
454
                }
455

    
456
                return pFolio;
457
        }
458

    
459
        /**
460
         * This method initializes lSeparador
461
         *
462
         * @return javax.swing.JLabel
463
         */
464
        private javax.swing.JLabel getLSeparador() {
465
                if (lSeparador == null) {
466
                        lSeparador = new javax.swing.JLabel();
467
                        lSeparador.setText("/");
468
                }
469

    
470
                return lSeparador;
471
        }
472
}