Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / dialogs / FFrameTextDialog.java @ 1551

History | View | Annotate | Download (15.7 KB)

1
/*
2
 * Created on 22-jun-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.fframes.dialogs;
46

    
47
import java.awt.Color;
48
import java.awt.geom.Rectangle2D;
49

    
50
import javax.swing.ImageIcon;
51
import javax.swing.JColorChooser;
52
import javax.swing.JDialog;
53
import javax.swing.JFrame;
54
import javax.swing.JPanel;
55
import javax.swing.JToggleButton;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.andami.ui.mdiManager.ViewInfo;
59
import com.iver.cit.gvsig.Abrir;
60
import com.iver.cit.gvsig.gui.Dialogs.FontChooser;
61
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
62
import com.iver.cit.gvsig.gui.layout.Layout;
63
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
64

    
65

    
66
import javax.swing.JButton;
67
/**
68
 * Dialogo para a?adir texto al Layout.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class FFrameTextDialog extends JPanel implements IFFrameDialog {
73
        public static final ImageIcon ileft = new ImageIcon(Abrir.class.getClassLoader()
74
                                                                                                                                   .getResource("images/left.PNG")); //$NON-NLS-1$
75
        public static final ImageIcon icenterV = new ImageIcon(Abrir.class.getClassLoader()
76
                                                                                                                                          .getResource("images/centerV.PNG")); //$NON-NLS-1$
77
        public static final ImageIcon iright = new ImageIcon(Abrir.class.getClassLoader()
78
                                                                                                                                        .getResource("images/right.PNG")); //$NON-NLS-1$
79
        private javax.swing.JPanel jContentPane = null; //  @jve:visual-info  decl-index=0 visual-constraint="593,10"
80
        private javax.swing.JScrollPane jScrollPane = null;
81
        private javax.swing.JTextArea taTexto = null;
82
        private javax.swing.JLabel lAlinear = null;
83
        private JToggleButton bIzquierda = null;
84
        private JToggleButton bCentro = null;
85
        private JToggleButton bDerecha = null;
86
        private javax.swing.JLabel jLabel1 = null;
87
        private javax.swing.JComboBox jComboBox = null;
88
        private javax.swing.JLabel jLabel2 = null;
89
        private javax.swing.JLabel lRotacion = null;
90
        private javax.swing.JTextField tRotacion = null;
91
        private javax.swing.JLabel lGrados = null;
92
        private javax.swing.JCheckBox chbEscalaVista = null;
93
        private javax.swing.JButton bAceptar = null;
94
        private javax.swing.JButton bCancelar = null;
95
        private Layout m_layout = null;
96
        private Rectangle2D rect = new Rectangle2D.Double();
97
        private FFrameText fframetext = null; //new FFrameText();
98
        private boolean isAcepted = false;
99
        private javax.swing.JButton bFuente = null;
100
        private Color textcolor = null;
101
        private JButton jButton = null;
102
        /**
103
         * This is the default constructor
104
         *
105
         * @param layout Referencia al Layout.
106
         * @param fframe Referencia al fframe de texto.
107
         */
108
        public FFrameTextDialog(Layout layout, FFrameText fframe) {
109
                super();
110
                fframetext = fframe;
111
                m_layout = layout;
112
                textcolor = fframe.getTextColor();
113
                initialize();
114
        }
115

    
116
        /**
117
         * This method initializes this
118
         */
119
        private void initialize() {
120
                this.setLayout(null);
121
                this.add(getJContentPane(), null);
122
                this.setSize(289, 218);
123
        }
124

    
125
        /**
126
         * Inserta el rect?ngulo a ocupar por el fframe de texto.
127
         *
128
         * @param r Rect?ngulo.
129
         */
130
        public void setRectangle(Rectangle2D r) {
131
                rect.setRect(r);
132
        }
133

    
134
        /**
135
         * This method initializes jContentPane
136
         *
137
         * @return javax.swing.JPanel
138
         */
139
        private javax.swing.JPanel getJContentPane() {
140
                if (jContentPane == null) {
141
                        jContentPane = new javax.swing.JPanel();
142
                        jContentPane.setLayout(null);
143
                        jContentPane.add(getJScrollPane(), null);
144
                        jContentPane.add(getLAlinear(), null);
145
                        jContentPane.add(getBIzquierda(), null);
146
                        jContentPane.add(getBCentro(), null);
147
                        jContentPane.add(getBDerecha(), null);
148

    
149
                        //jContentPane.add(getJLabel1(), null);
150
                        //jContentPane.add(getJComboBox(), null);
151
                        //jContentPane.add(getJLabel2(), null);
152
                        jContentPane.add(getLRotacion(), null);
153
                        jContentPane.add(getTRotacion(), null);
154
                        jContentPane.add(getLGrados(), null);
155
                        jContentPane.add(getChbEscalaVista(), null);
156
                        jContentPane.add(getBAceptar(), null);
157
                        jContentPane.add(getBCancelar(), null);
158
                        jContentPane.add(getBFuente(), null);
159
                        jContentPane.setSize(291, 227);
160
                        jContentPane.setLocation(6, 4);
161
                        jContentPane.add(getJButton(), null);
162
                }
163

    
164
                return jContentPane;
165
        }
166

    
167
        /**
168
         * This method initializes jScrollPane
169
         *
170
         * @return javax.swing.JScrollPane
171
         */
172
        private javax.swing.JScrollPane getJScrollPane() {
173
                if (jScrollPane == null) {
174
                        jScrollPane = new javax.swing.JScrollPane();
175
                        jScrollPane.setViewportView(getTaTexto());
176
                        jScrollPane.setSize(261, 83);
177
                        jScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
178
                        jScrollPane.setLocation(5, 5);
179
                }
180

    
181
                return jScrollPane;
182
        }
183

    
184
        /**
185
         * This method initializes taTexto
186
         *
187
         * @return javax.swing.JTextArea
188
         */
189
        private javax.swing.JTextArea getTaTexto() {
190
                if (taTexto == null) {
191
                        taTexto = new javax.swing.JTextArea();
192

    
193
                        for (int i = 0; i < fframetext.getText().size(); i++) {
194
                                if (!((String) fframetext.getText().get(i)).equals("")) { //$NON-NLS-1$
195
                                        taTexto.append((String) fframetext.getText().get(i));
196
                                }
197

    
198
                                taTexto.setPreferredSize(new java.awt.Dimension(220, 80));
199
                        }
200
                }
201

    
202
                return taTexto;
203
        }
204

    
205
        /**
206
         * This method initializes lAlinear
207
         *
208
         * @return javax.swing.JLabel
209
         */
210
        private javax.swing.JLabel getLAlinear() {
211
                if (lAlinear == null) {
212
                        lAlinear = new javax.swing.JLabel();
213
                        lAlinear.setSize(52, 27);
214
                        lAlinear.setText(PluginServices.getText(this, "alinear")); //$NON-NLS-1$
215
                        lAlinear.setLocation(5, 98);
216
                }
217

    
218
                return lAlinear;
219
        }
220

    
221
        /**
222
         * This method initializes bIzquierda
223
         *
224
         * @return javax.swing.JButton
225
         */
226
        private JToggleButton getBIzquierda() {
227
                if (bIzquierda == null) {
228
                        bIzquierda = new JToggleButton();
229
                        bIzquierda.setSize(30, 27);
230
                        bIzquierda.setPreferredSize(new java.awt.Dimension(28, 20));
231
                        bIzquierda.setLocation(60, 98);
232

    
233
                        if (fframetext.getPos() == FFrameText.LEFT) {
234
                                bIzquierda.setSelected(true);
235
                        }
236

    
237
                        bIzquierda.setIcon(ileft);
238
                        bIzquierda.addActionListener(new java.awt.event.ActionListener() {
239
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
240
                                                fframetext.setPos(FFrameText.LEFT);
241
                                                getBIzquierda().setSelected(true);
242
                                                getBCentro().setSelected(false);
243
                                                getBDerecha().setSelected(false);
244
                                        }
245
                                });
246
                }
247

    
248
                return bIzquierda;
249
        }
250

    
251
        /**
252
         * This method initializes bCentro
253
         *
254
         * @return javax.swing.JButton
255
         */
256
        private JToggleButton getBCentro() {
257
                if (bCentro == null) {
258
                        bCentro = new JToggleButton();
259
                        bCentro.setSize(30, 27);
260
                        bCentro.setPreferredSize(new java.awt.Dimension(28, 20));
261
                        bCentro.setLocation(93, 98);
262

    
263
                        if (fframetext.getPos() == FFrameText.CENTER) {
264
                                bCentro.setSelected(true);
265
                        }
266

    
267
                        bCentro.setIcon(icenterV);
268
                        bCentro.addActionListener(new java.awt.event.ActionListener() {
269
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
270
                                                fframetext.setPos(FFrameText.CENTER);
271
                                                getBIzquierda().setSelected(false);
272
                                                getBCentro().setSelected(true);
273
                                                getBDerecha().setSelected(false);
274
                                        }
275
                                });
276
                }
277

    
278
                return bCentro;
279
        }
280

    
281
        /**
282
         * This method initializes bDerecha
283
         *
284
         * @return javax.swing.JButton
285
         */
286
        private JToggleButton getBDerecha() {
287
                if (bDerecha == null) {
288
                        bDerecha = new JToggleButton();
289
                        bDerecha.setSize(30, 27);
290
                        bDerecha.setPreferredSize(new java.awt.Dimension(28, 20));
291
                        bDerecha.setLocation(126, 98);
292

    
293
                        if (fframetext.getPos() == FFrameText.RIGTH) {
294
                                bDerecha.setSelected(true);
295
                        }
296

    
297
                        bDerecha.setIcon(iright);
298
                        bDerecha.addActionListener(new java.awt.event.ActionListener() {
299
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
300
                                                fframetext.setPos(FFrameText.RIGTH);
301
                                                getBIzquierda().setSelected(false);
302
                                                getBCentro().setSelected(false);
303
                                                getBDerecha().setSelected(true);
304
                                        }
305
                                });
306
                }
307

    
308
                return bDerecha;
309
        }
310

    
311
        /**
312
         * This method initializes jLabel1
313
         *
314
         * @return javax.swing.JLabel
315
         */
316
        private javax.swing.JLabel getJLabel1() {
317
                if (jLabel1 == null) {
318
                        jLabel1 = new javax.swing.JLabel();
319
                        jLabel1.setSize(95, 16);
320
                        jLabel1.setText(PluginServices.getText(this, "__espacio_vertical")); //$NON-NLS-1$
321
                        jLabel1.setLocation(5, 140);
322
                }
323

    
324
                return jLabel1;
325
        }
326

    
327
        /**
328
         * This method initializes jComboBox
329
         *
330
         * @return javax.swing.JComboBox
331
         */
332
        private javax.swing.JComboBox getJComboBox() {
333
                if (jComboBox == null) {
334
                        jComboBox = new javax.swing.JComboBox();
335
                        jComboBox.addItem("0"); //$NON-NLS-1$
336
                        jComboBox.addItem("1"); //$NON-NLS-1$
337
                        jComboBox.addItem("2"); //$NON-NLS-1$
338

    
339
                        //jComboBox.setSelectedIndex(fframetext.getSpace());
340
                        jComboBox.setSize(102, 20);
341
                        jComboBox.setPreferredSize(new java.awt.Dimension(45, 20));
342
                        jComboBox.setLocation(130, 140);
343
                        jComboBox.addActionListener(new java.awt.event.ActionListener() {
344
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
345
                                                //fframetext.setSpace(jComboBox.getSelectedIndex());
346
                                        }
347
                                });
348
                }
349

    
350
                return jComboBox;
351
        }
352

    
353
        /**
354
         * This method initializes jLabel2
355
         *
356
         * @return javax.swing.JLabel
357
         */
358
        private javax.swing.JLabel getJLabel2() {
359
                if (jLabel2 == null) {
360
                        jLabel2 = new javax.swing.JLabel();
361
                        jLabel2.setSize(34, 16);
362
                        jLabel2.setText(PluginServices.getText(this, "__lineas")); //$NON-NLS-1$
363
                        jLabel2.setLocation(238, 141);
364
                }
365

    
366
                return jLabel2;
367
        }
368

    
369
        /**
370
         * This method initializes lRotacion
371
         *
372
         * @return javax.swing.JLabel
373
         */
374
        private javax.swing.JLabel getLRotacion() {
375
                if (lRotacion == null) {
376
                        lRotacion = new javax.swing.JLabel();
377
                        lRotacion.setBounds(6, 131, 109, 16);
378
                        lRotacion.setText(PluginServices.getText(this, "angulo_rotacion")); //$NON-NLS-1$
379
                }
380

    
381
                return lRotacion;
382
        }
383

    
384
        /**
385
         * This method initializes tRotacion
386
         *
387
         * @return javax.swing.JTextField
388
         */
389
        private javax.swing.JTextField getTRotacion() {
390
                if (tRotacion == null) {
391
                        tRotacion = new javax.swing.JTextField();
392
                        tRotacion.setBounds(154, 128, 64, 20);
393
                        tRotacion.setPreferredSize(new java.awt.Dimension(45, 20));
394
                        tRotacion.setText(Double.toString(fframetext.getRotation()));
395
                }
396

    
397
                return tRotacion;
398
        }
399

    
400
        /**
401
         * This method initializes lGrados
402
         *
403
         * @return javax.swing.JLabel
404
         */
405
        private javax.swing.JLabel getLGrados() {
406
                if (lGrados == null) {
407
                        lGrados = new javax.swing.JLabel();
408
                        lGrados.setSize(40, 16);
409
                        lGrados.setText(PluginServices.getText(this, "grados")); //$NON-NLS-1$
410
                        lGrados.setLocation(226, 130);
411
                }
412

    
413
                return lGrados;
414
        }
415

    
416
        /**
417
         * This method initializes chbEscalaVista
418
         *
419
         * @return javax.swing.JCheckBox
420
         */
421
        private javax.swing.JCheckBox getChbEscalaVista() {
422
                if (chbEscalaVista == null) {
423
                        chbEscalaVista = new javax.swing.JCheckBox();
424
                        chbEscalaVista.setSize(280, 24);
425
                        chbEscalaVista.setText(
426
                                PluginServices.getText(this, "__redimensionar_texto_escala")); //$NON-NLS-1$
427
                        chbEscalaVista.setSelected(fframetext.isSizeFixed());
428
                        chbEscalaVista.setLocation(6, 153);
429
                        chbEscalaVista.setEnabled(false);
430
                }
431

    
432
                return chbEscalaVista;
433
        }
434

    
435
        /**
436
         * This method initializes bAceptar
437
         *
438
         * @return javax.swing.JButton
439
         */
440
        private javax.swing.JButton getBAceptar() {
441
                if (bAceptar == null) {
442
                        bAceptar = new javax.swing.JButton();
443
                        bAceptar.setSize(79, 26);
444
                        bAceptar.setText(PluginServices.getText(this, "Aceptar")); //$NON-NLS-1$
445
                        bAceptar.setLocation(46, 183);
446
                        bAceptar.addActionListener(new java.awt.event.ActionListener() {
447
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
448
                                                fframetext.setBoundBox(FLayoutUtilities.toSheetRect(
449
                                                                rect, m_layout.getAT()));
450
                                                fframetext.getText().clear();
451

    
452
                                                for (int i = 0; i < getTaTexto().getLineCount(); i++) {
453
                                                        try {
454
                                                                String s = getTaTexto().getText(getTaTexto()
455
                                                                                                                                        .getLineStartOffset(i),
456
                                                                                getTaTexto().getLineEndOffset(i) -
457
                                                                                getTaTexto().getLineStartOffset(i));
458

    
459
                                                                if (!s.equals("")) { //$NON-NLS-1$
460
                                                                        fframetext.addText(s);
461
                                                                }
462
                                                        } catch (Exception ex) {
463
                                                        }
464
                                                }
465
                                                fframetext.setTextColor(textcolor);
466
                                                fframetext.setSizeFixed(!getChbEscalaVista().isSelected());
467
                                                fframetext.setRotation(Double.parseDouble(
468
                                                                getTRotacion().getText()));
469
                                                PluginServices.getMDIManager().closeView(FFrameTextDialog.this);
470
                                                m_layout.refresh();
471
                                                isAcepted = true;
472
                                        }
473
                                });
474
                }
475

    
476
                return bAceptar;
477
        }
478

    
479
        /**
480
         * This method initializes bCancelar
481
         *
482
         * @return javax.swing.JButton
483
         */
484
        private javax.swing.JButton getBCancelar() {
485
                if (bCancelar == null) {
486
                        bCancelar = new javax.swing.JButton();
487
                        bCancelar.setSize(85, 26);
488
                        bCancelar.setText(PluginServices.getText(this, "Cancelar")); //$NON-NLS-1$
489
                        bCancelar.setLocation(151, 183);
490
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
491
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
492
                                                PluginServices.getMDIManager().closeView(FFrameTextDialog.this);
493
                                        }
494
                                });
495
                }
496

    
497
                return bCancelar;
498
        }
499

    
500
        /* (non-Javadoc)
501
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
502
         */
503
        public ViewInfo getViewInfo() {
504
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
505

    
506
                //vi.setResizable(false);
507
                m_viewinfo.setTitle(PluginServices.getText(this, "Propiedades_texto")); //$NON-NLS-1$
508

    
509
                return m_viewinfo;
510
        }
511

    
512
        /**
513
         * @see com.iver.cit.gvsig.gui.layout.fframes.dialogs.IFFrameDialog#getIsAcepted()
514
         */
515
        public boolean getIsAcepted() {
516
                return isAcepted;
517
        }
518

    
519
        /**
520
         * This method initializes bFuente
521
         *
522
         * @return javax.swing.JButton
523
         */
524
        private javax.swing.JButton getBFuente() {
525
                if (bFuente == null) {
526
                        bFuente = new javax.swing.JButton();
527
                        bFuente.setBounds(157, 98, 73, 27);
528
                        bFuente.setText(PluginServices.getText(this, "fuente")); //$NON-NLS-1$
529
                        bFuente.addActionListener(new java.awt.event.ActionListener() {
530
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
531
                                                fframetext.setFont(FontChooser.showDialog(
532
                                                                PluginServices.getText(this, "__seleccion_de_fuente"), fframetext.getFont())); // fchoser=new FontChooser();         //$NON-NLS-1$
533
                                        }
534
                                });
535
                }
536

    
537
                return bFuente;
538
        }
539

    
540
        /**
541
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
542
         */
543
        public void viewActivated() {
544
        }
545
        /**
546
         * This method initializes jButton        
547
         *         
548
         * @return javax.swing.JButton        
549
         */    
550
        private JButton getJButton() {
551
                if (jButton == null) {
552
                        jButton = new JButton();
553
                        jButton.setForeground(Color.white);
554
                        jButton.setBackground(textcolor);
555
                        jButton.setBounds(235, 98, 32, 27);
556
                        jButton.addActionListener(new java.awt.event.ActionListener() { 
557
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
558
                                        JDialog dlg;
559
                                        JColorChooser colorChooser;
560
                                        colorChooser = new JColorChooser();
561
                                        dlg = JColorChooser.createDialog((JFrame) null,
562
                                                        PluginServices.getText(this, "Elegir_Color"),
563
                                                        true, colorChooser, null, null);
564
                                        dlg.show(true);
565

    
566
                                        textcolor = (Color) colorChooser.getColor();
567

    
568
                                        //getJPanel1().setBackground(textcolor);
569
                                        jButton.setBackground(textcolor);
570

    
571
                                }
572
                        });
573
                }
574
                return jButton;
575
        }
576
 }  //  @jve:decl-index=0:visual-constraint="10,10"