Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / dialogs / FFramePictureDialog.java @ 8745

History | View | Annotate | Download (11.2 KB)

1
/*
2
 * Created on 02-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.Component;
48
import java.awt.Dimension;
49
import java.awt.geom.Rectangle2D;
50
import java.io.File;
51

    
52
import javax.swing.JFileChooser;
53
import javax.swing.JPanel;
54

    
55
import com.iver.andami.PluginServices;
56
import com.iver.andami.messages.NotificationManager;
57
import com.iver.andami.ui.mdiManager.WindowInfo;
58
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
59
import com.iver.cit.gvsig.gui.layout.Layout;
60
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
61
import com.iver.utiles.GenericFileFilter;
62

    
63

    
64
/**
65
 * Dialogo para a?adir una imagen al Layout.
66
 *
67
 * @author Vicente Caballero Navarro
68
 */
69
public class FFramePictureDialog extends JPanel implements IFFrameDialog {
70
        private javax.swing.JPanel jContentPane = null;
71
        private javax.swing.JLabel lFichero = null;
72
        private javax.swing.JTextField tFichero = null;
73
        private javax.swing.JButton bExaminar = null;
74
        private javax.swing.JLabel lVisualizacion = null;
75
        private javax.swing.JComboBox cbVisualizacion = null;
76
        private javax.swing.JLabel lCalidad = null;
77
        private javax.swing.JComboBox cbCalidad = null;
78
        private javax.swing.JButton bAceptar = null;
79
        private javax.swing.JButton bCancelar = null;
80
        private Rectangle2D rect = new Rectangle2D.Double();
81
        private FFramePicture fframepicture = null; // = new FFramePicture();
82
        private String namefile = null;
83
        private Layout m_layout = null;
84
        private boolean isAcepted = false;
85
        private JPRotation pRotation = null;
86

    
87
        /**
88
         * This is the default constructor
89
         *
90
         * @param layout Referencia al Layout.
91
         * @param fframe Referencia al fframe de imagen.
92
         */
93
        public FFramePictureDialog(Layout layout, FFramePicture fframe) {
94
                super();
95
                fframepicture = fframe;
96
                m_layout = layout;
97
                initialize();
98
        }
99

    
100
        /**
101
         * Inserta el rect?ngulo que ocupar? el fframe de imagen.
102
         *
103
         * @param r Rect?ngulo.
104
         */
105
        public void setRectangle(Rectangle2D r) {
106
                rect.setRect(r);
107
        }
108

    
109
        /**
110
         * This method initializes this
111
         */
112
        private void initialize() {
113
                this.setLayout(null);
114
                this.add(getJContentPane(), null);
115
                this.setSize(505, 142);
116
                getPRotation().setRotation(fframepicture.getRotation());
117
        }
118

    
119
        /**
120
         * This method initializes jContentPane
121
         *
122
         * @return javax.swing.JPanel
123
         */
124
        private javax.swing.JPanel getJContentPane() {
125
                if (jContentPane == null) {
126
                        jContentPane = new javax.swing.JPanel();
127
                        jContentPane.setLayout(null);
128
                        jContentPane.add(getLFichero(), null);
129
                        jContentPane.add(getLCalidad(), null);
130
                        jContentPane.add(getCbCalidad(), null);
131
                        jContentPane.add(getTFichero(), null);
132
                        jContentPane.add(getBExaminar(), null);
133
                        jContentPane.add(getLVisualizacion(), null);
134
                        jContentPane.add(getCbVisualizacion(), null);
135
                        jContentPane.add(getBAceptar(), null);
136
                        jContentPane.add(getBCancelar(), null);
137
                        jContentPane.setSize(499, 139);
138
                        jContentPane.setLocation(3, 0);
139
                        jContentPane.add(getPRotation(), null);
140
                }
141

    
142
                return jContentPane;
143
        }
144

    
145
        /**
146
         * This method initializes lFichero
147
         *
148
         * @return javax.swing.JLabel
149
         */
150
        private javax.swing.JLabel getLFichero() {
151
                if (lFichero == null) {
152
                        lFichero = new javax.swing.JLabel();
153
                        lFichero.setSize(42, 20);
154
                        lFichero.setText(PluginServices.getText(this, "Fichero"));
155
                        lFichero.setLocation(10, 9);
156
                }
157

    
158
                return lFichero;
159
        }
160

    
161
        /**
162
         * This method initializes tFichero
163
         *
164
         * @return javax.swing.JTextField
165
         */
166
        private javax.swing.JTextField getTFichero() {
167
                if (tFichero == null) {
168
                        tFichero = new javax.swing.JTextField();
169
                        tFichero.setBounds(62, 8, 200, 20);
170
                        tFichero.setPreferredSize(new java.awt.Dimension(200, 20));
171
                }
172

    
173
                if (fframepicture.getPath() != null) {
174
                        tFichero.setText(fframepicture.getPath());
175
                }
176

    
177
                return tFichero;
178
        }
179

    
180
        /**
181
         * This method initializes bExaminar
182
         *
183
         * @return javax.swing.JButton
184
         */
185
        private javax.swing.JButton getBExaminar() {
186
                if (bExaminar == null) {
187
                        bExaminar = new javax.swing.JButton();
188
                        bExaminar.setSize(88, 23);
189
                        bExaminar.setText(PluginServices.getText(this, "Examinar"));
190
                        bExaminar.setLocation(275, 6);
191
                        bExaminar.setPreferredSize(new java.awt.Dimension(88, 23));
192
                        bExaminar.addActionListener(new java.awt.event.ActionListener() {
193
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
194
                                                String[] extensions = {
195
                                                                "jpeg", "jpg", "gif", "png", "bmp", "svg"
196
                                                        };
197
                                                GenericFileFilter filter = new GenericFileFilter(extensions,
198
                                                                "Image files (jpeg, jpg, gif, png, bmp, svg)");
199

    
200
                                                JFileChooser jfc = new JFileChooser();
201
                                                jfc.addChoosableFileFilter(filter);
202
                                                if (jfc.showOpenDialog(
203
                                                                        (Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
204
                                                        File file = jfc.getSelectedFile();
205
                                                        namefile = file.getName();
206
                                                        getTFichero().setText(file.getAbsolutePath());
207
                                                        fframepicture.setPath(file.getAbsolutePath());
208
                                                }
209
                                        }
210
                                });
211
                }
212

    
213
                return bExaminar;
214
        }
215

    
216
        /**
217
         * Inserta el path al TFichero.
218
         *
219
         * @param val path del fichero.
220
         */
221
        public void setText(String val) {
222
                getTFichero().setText(val);
223
        }
224

    
225
        /**
226
         * This method initializes lVisualizacion
227
         *
228
         * @return javax.swing.JLabel
229
         */
230
        private javax.swing.JLabel getLVisualizacion() {
231
                if (lVisualizacion == null) {
232
                        lVisualizacion = new javax.swing.JLabel();
233
                        lVisualizacion.setBounds(9, 62, 105, 20);
234
                        lVisualizacion.setText(PluginServices.getText(this, "visualizacion"));
235
                }
236

    
237
                return lVisualizacion;
238
        }
239

    
240
        /**
241
         * This method initializes cbVisualizacion
242
         *
243
         * @return javax.swing.JComboBox
244
         */
245
        private javax.swing.JComboBox getCbVisualizacion() {
246
                if (cbVisualizacion == null) {
247
                        cbVisualizacion = new javax.swing.JComboBox();
248
                        cbVisualizacion.setSize(245, 20);
249
                        cbVisualizacion.addItem(PluginServices.getText(this, "cuando_activo"));
250
                        cbVisualizacion.addItem(PluginServices.getText(this, "siempre"));
251
                        cbVisualizacion.setSelectedIndex(fframepicture.getViewing());
252
                        cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20));
253
                        cbVisualizacion.setLocation(118, 62);
254
                        cbVisualizacion.setEnabled(false);
255
                }
256

    
257
                return cbVisualizacion;
258
        }
259

    
260
        /**
261
         * This method initializes lCalidad
262
         *
263
         * @return javax.swing.JLabel
264
         */
265
        private javax.swing.JLabel getLCalidad() {
266
                if (lCalidad == null) {
267
                        lCalidad = new javax.swing.JLabel();
268
                        lCalidad.setSize(103, 20);
269
                        lCalidad.setText(PluginServices.getText(this, "calidad"));
270
                        lCalidad.setPreferredSize(new java.awt.Dimension(73,16));
271
                        lCalidad.setLocation(10, 35);
272
                }
273

    
274
                return lCalidad;
275
        }
276

    
277
        /**
278
         * This method initializes cbCalidad
279
         *
280
         * @return javax.swing.JComboBox
281
         */
282
        private javax.swing.JComboBox getCbCalidad() {
283
                if (cbCalidad == null) {
284
                        cbCalidad = new javax.swing.JComboBox();
285
                        cbCalidad.setSize(245, 20);
286
                        cbCalidad.addItem(PluginServices.getText(this, "presentacion"));
287
                        cbCalidad.addItem(PluginServices.getText(this, "borrador"));
288
                        cbCalidad.setSelectedIndex(fframepicture.getQuality());
289
                        cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20));
290
                        cbCalidad.setLocation(118, 35);
291
                }
292

    
293
                return cbCalidad;
294
        }
295

    
296
        /**
297
         * This method initializes bAceptar
298
         *
299
         * @return javax.swing.JButton
300
         */
301
        private javax.swing.JButton getBAceptar() {
302
                if (bAceptar == null) {
303
                        bAceptar = new javax.swing.JButton();
304
                        bAceptar.setSize(85, 26);
305
                        bAceptar.setText(PluginServices.getText(this, "Aceptar"));
306
                        bAceptar.setLocation(70, 89);
307
                        bAceptar.addActionListener(new java.awt.event.ActionListener() {
308
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
309
                                            Dimension dimension = null;
310
                                                try {
311
                                                    // ImageIcon imageIcon = new ImageIcon(getTFichero().getText());
312
                                                    dimension = fframepicture.getBound(getTFichero().getText());
313
                                                } catch (Exception ex) {
314
                                                        NotificationManager.addError("Excepci?n :", ex);
315
                                                }
316

    
317
                                                fframepicture.setViewing(getCbVisualizacion()
318
                                                                                                         .getSelectedIndex());
319
                                                fframepicture.setQuality(getCbCalidad()
320
                                                                                                         .getSelectedIndex());
321

    
322
                                                if (namefile != null) {
323
                                                        fframepicture.setName(namefile);
324
                                                }
325
                                                // Ajustamos la relaci?n de aspecto a la altura.
326
                                                double ratio = (float) (dimension.getWidth()) / (float) (dimension.getHeight());
327

    
328
                                                double newWidth = rect.getHeight() * ratio;
329
                                                Rectangle2D.Double rAdjust = new Rectangle2D.Double(
330
                                                        rect.getMinX(), rect.getMinY(),
331
                                                        newWidth, rect.getHeight());
332
                                        rect = rAdjust;
333

    
334
                                                fframepicture.setBoundBox(FLayoutUtilities.toSheetRect(
335
                                                                rect, m_layout.getAT()));
336
                                                fframepicture.setRotation(getPRotation().getRotation());
337
                                                PluginServices.getMDIManager().closeWindow(FFramePictureDialog.this);
338
                                                m_layout.refresh();
339
                                                isAcepted = true;
340
                                        }
341
                                });
342
                }
343

    
344
                return bAceptar;
345
        }
346

    
347
        /**
348
         * This method initializes bCancelar
349
         *
350
         * @return javax.swing.JButton
351
         */
352
        private javax.swing.JButton getBCancelar() {
353
                if (bCancelar == null) {
354
                        bCancelar = new javax.swing.JButton();
355
                        bCancelar.setSize(85, 26);
356
                        bCancelar.setText(PluginServices.getText(this, "Cancelar"));
357
                        bCancelar.setLocation(219, 89);
358
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
359
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
360
                                                PluginServices.getMDIManager().closeWindow(FFramePictureDialog.this);
361
                                        }
362
                                });
363
                }
364

    
365
                return bCancelar;
366
        }
367

    
368
        /* (non-Javadoc)
369
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
370
         */
371
        public WindowInfo getWindowInfo() {
372
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
373
                m_viewinfo.setTitle(PluginServices.getText(this,
374
                                "propiedades_marco_imagenes"));
375

    
376
                return m_viewinfo;
377
        }
378

    
379
        /**
380
         * @see com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
381
         */
382
        public boolean getIsAcepted() {
383
                return isAcepted;
384
        }
385

    
386
        /**
387
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
388
         */
389
        public void viewActivated() {
390
        }
391

    
392
        /**
393
         * This method initializes pRotation
394
         *
395
         * @return javax.swing.JPanel
396
         */
397
        private JPRotation getPRotation() {
398
                if (pRotation == null) {
399
                        pRotation = new JPRotation();
400
                        pRotation.setBounds(373, 14, 120, 120);
401
                }
402
                return pRotation;
403
        }
404
}  //  @jve:decl-index=0:visual-constraint="10,10"