Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / dialogs / FFramePictureDialog.java @ 1551

History | View | Annotate | Download (10.9 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.Graphics2D;
49
import java.awt.Image;
50
import java.awt.MediaTracker;
51
import java.awt.geom.Rectangle2D;
52
import java.awt.image.BufferedImage;
53
import java.io.File;
54
import java.io.FileInputStream;
55
import java.io.IOException;
56
import java.io.InputStream;
57

    
58
import javax.swing.ImageIcon;
59
import javax.swing.JFileChooser;
60
import javax.swing.JPanel;
61

    
62
import com.iver.andami.PluginServices;
63
import com.iver.andami.messages.NotificationManager;
64
import com.iver.andami.ui.mdiManager.ViewInfo;
65
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
66
import com.iver.cit.gvsig.gui.layout.Layout;
67
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
68
import com.iver.utiles.GenericFileFilter;
69
import com.sun.jimi.core.Jimi;
70

    
71

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

    
94
        /**
95
         * This is the default constructor
96
         *
97
         * @param layout Referencia al Layout.
98
         * @param fframe Referencia al fframe de imagen.
99
         */
100
        public FFramePictureDialog(Layout layout, FFramePicture fframe) {
101
                super();
102
                fframepicture = fframe;
103
                m_layout = layout;
104
                initialize();
105
        }
106

    
107
        /**
108
         * Inserta el rect?ngulo que ocupar? el fframe de imagen.
109
         *
110
         * @param r Rect?ngulo.
111
         */
112
        public void setRectangle(Rectangle2D r) {
113
                rect.setRect(r);
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(381, 127);
123
        }
124

    
125
        /**
126
         * This method initializes jContentPane
127
         *
128
         * @return javax.swing.JPanel
129
         */
130
        private javax.swing.JPanel getJContentPane() {
131
                if (jContentPane == null) {
132
                        jContentPane = new javax.swing.JPanel();
133
                        jContentPane.setLayout(null);
134
                        jContentPane.add(getLFichero(), null);
135
                        jContentPane.add(getLCalidad(), null);
136
                        jContentPane.add(getCbCalidad(), null);
137
                        jContentPane.add(getTFichero(), null);
138
                        jContentPane.add(getBExaminar(), null);
139
                        jContentPane.add(getLVisualizacion(), null);
140
                        jContentPane.add(getCbVisualizacion(), null);
141
                        jContentPane.add(getBAceptar(), null);
142
                        jContentPane.add(getBCancelar(), null);
143
                        jContentPane.setSize(385, 128);
144
                        jContentPane.setLocation(0, 0);
145
                }
146

    
147
                return jContentPane;
148
        }
149

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

    
163
                return lFichero;
164
        }
165

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

    
178
                if (fframepicture.getPath() != null) {
179
                        tFichero.setText(fframepicture.getPath());
180
                }
181

    
182
                return tFichero;
183
        }
184

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

    
205
                                                JFileChooser jfc = new JFileChooser();
206
                                                jfc.addChoosableFileFilter(filter);
207

    
208
                                                //jfc.addChoosableFileFilter(jpgFilter);
209
                                                //jfc.addChoosableFileFilter(gifFilter);
210
                                                //jfc.addChoosableFileFilter(pngFilter);
211
                                                if (jfc.showOpenDialog(
212
                                                                        (Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
213
                                                        File file = jfc.getSelectedFile();
214
                                                        namefile = file.getName();
215
                                                        getTFichero().setText(file.getAbsolutePath());
216
                                                        fframepicture.setPath(file.getAbsolutePath());
217
                                                }
218
                                        }
219
                                });
220
                }
221

    
222
                return bExaminar;
223
        }
224

    
225
        /**
226
         * Inserta el path al TFichero.
227
         *
228
         * @param val path del fichero.
229
         */
230
        public void setText(String val) {
231
                getTFichero().setText(val);
232
        }
233

    
234
        /**
235
         * This method initializes lVisualizacion
236
         *
237
         * @return javax.swing.JLabel
238
         */
239
        private javax.swing.JLabel getLVisualizacion() {
240
                if (lVisualizacion == null) {
241
                        lVisualizacion = new javax.swing.JLabel();
242
                        lVisualizacion.setBounds(9, 62, 75, 20);
243
                        lVisualizacion.setText(PluginServices.getText(this, "visualizacion"));
244
                }
245

    
246
                return lVisualizacion;
247
        }
248

    
249
        /**
250
         * This method initializes cbVisualizacion
251
         *
252
         * @return javax.swing.JComboBox
253
         */
254
        private javax.swing.JComboBox getCbVisualizacion() {
255
                if (cbVisualizacion == null) {
256
                        cbVisualizacion = new javax.swing.JComboBox();
257
                        cbVisualizacion.setSize(245, 20);
258
                        cbVisualizacion.addItem(PluginServices.getText(this, "cuando_activo"));
259
                        cbVisualizacion.addItem(PluginServices.getText(this, "siempre"));
260
                        cbVisualizacion.setSelectedIndex(fframepicture.getViewing());
261
                        cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20));
262
                        cbVisualizacion.setLocation(118, 62);
263
                        cbVisualizacion.setEnabled(false);
264
                }
265

    
266
                return cbVisualizacion;
267
        }
268

    
269
        /**
270
         * This method initializes lCalidad
271
         *
272
         * @return javax.swing.JLabel
273
         */
274
        private javax.swing.JLabel getLCalidad() {
275
                if (lCalidad == null) {
276
                        lCalidad = new javax.swing.JLabel();
277
                        lCalidad.setSize(42, 20);
278
                        lCalidad.setText(PluginServices.getText(this, "calidad"));
279
                        lCalidad.setLocation(10, 35);
280
                }
281

    
282
                return lCalidad;
283
        }
284

    
285
        /**
286
         * This method initializes cbCalidad
287
         *
288
         * @return javax.swing.JComboBox
289
         */
290
        private javax.swing.JComboBox getCbCalidad() {
291
                if (cbCalidad == null) {
292
                        cbCalidad = new javax.swing.JComboBox();
293
                        cbCalidad.setSize(245, 20);
294
                        cbCalidad.addItem(PluginServices.getText(this, "presentacion"));
295
                        cbCalidad.addItem(PluginServices.getText(this, "borrador"));
296
                        cbCalidad.setSelectedIndex(fframepicture.getQuality());
297
                        cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20));
298
                        cbCalidad.setLocation(118, 35);
299
                }
300

    
301
                return cbCalidad;
302
        }
303

    
304
        /**
305
         * This method initializes bAceptar
306
         *
307
         * @return javax.swing.JButton
308
         */
309
        private javax.swing.JButton getBAceptar() {
310
                if (bAceptar == null) {
311
                        bAceptar = new javax.swing.JButton();
312
                        bAceptar.setSize(85, 26);
313
                        bAceptar.setText(PluginServices.getText(this, "Aceptar"));
314
                        bAceptar.setLocation(70, 89);
315
                        bAceptar.addActionListener(new java.awt.event.ActionListener() {
316
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
317
                                            Image image = null;
318
                                                try {
319
                                                    // ImageIcon imageIcon = new ImageIcon(getTFichero().getText());
320
                                                    image = fframepicture.load(getTFichero().getText());
321
                                                } catch (Exception ex) {
322
                                                        NotificationManager.addError("Excepci?n :", ex);
323
                                                }
324

    
325
                                                fframepicture.setViewing(getCbVisualizacion()
326
                                                                                                         .getSelectedIndex());
327
                                                fframepicture.setQuality(getCbCalidad()
328
                                                                                                         .getSelectedIndex());
329

    
330
                                                if (namefile != null) {
331
                                                        fframepicture.setName(namefile);
332
                                                }
333
                                                // Ajustamos la relaci?n de aspecto a la altura.
334
                                                double ratio = (float) (image.getWidth(null)) / (float) (image.getHeight(null));
335
                                                
336
                                                double newWidth = rect.getHeight() * ratio; 
337
                                                Rectangle2D.Double rAdjust = new Rectangle2D.Double(
338
                                                        rect.getMinX(), rect.getMinY(),
339
                                                        newWidth, rect.getHeight());
340
                                        rect = rAdjust;
341

    
342
                                                fframepicture.setBoundBox(FLayoutUtilities.toSheetRect(
343
                                                                rect, m_layout.getAT()));
344
                                                PluginServices.getMDIManager().closeView(FFramePictureDialog.this);
345
                                                m_layout.refresh();
346
                                                isAcepted = true;
347
                                        }
348
                                });
349
                }
350

    
351
                return bAceptar;
352
        }
353

    
354
        /**
355
         * This method initializes bCancelar
356
         *
357
         * @return javax.swing.JButton
358
         */
359
        private javax.swing.JButton getBCancelar() {
360
                if (bCancelar == null) {
361
                        bCancelar = new javax.swing.JButton();
362
                        bCancelar.setSize(85, 26);
363
                        bCancelar.setText(PluginServices.getText(this, "Cancelar"));
364
                        bCancelar.setLocation(219, 89);
365
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
366
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
367
                                                PluginServices.getMDIManager().closeView(FFramePictureDialog.this);
368
                                        }
369
                                });
370
                }
371

    
372
                return bCancelar;
373
        }
374

    
375
        /* (non-Javadoc)
376
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
377
         */
378
        public ViewInfo getViewInfo() {
379
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
380
                m_viewinfo.setTitle(PluginServices.getText(this,
381
                                "propiedades_marco_imagenes"));
382

    
383
                return m_viewinfo;
384
        }
385

    
386
        /**
387
         * @see com.iver.cit.gvsig.gui.layout.fframes.dialogs.IFFrameDialog#getIsAcepted()
388
         */
389
        public boolean getIsAcepted() {
390
                return isAcepted;
391
        }
392

    
393
        /**
394
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
395
         */
396
        public void viewActivated() {
397
        }
398
}