Statistics
| Revision:

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

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.project.documents.layout.fframes.gui.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.Layout;
59
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
60
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
61
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.JPRotation;
62
import com.iver.utiles.GenericFileFilter;
63

    
64

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

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

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

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

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

    
143
                return jContentPane;
144
        }
145

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

    
159
                return lFichero;
160
        }
161

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

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

    
178
                return tFichero;
179
        }
180

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

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

    
214
                return bExaminar;
215
        }
216

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

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

    
238
                return lVisualizacion;
239
        }
240

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

    
258
                return cbVisualizacion;
259
        }
260

    
261
        /**
262
         * This method initializes lCalidad
263
         *
264
         * @return javax.swing.JLabel
265
         */
266
        private javax.swing.JLabel getLCalidad() {
267
                if (lCalidad == null) {
268
                        lCalidad = new javax.swing.JLabel();
269
                        lCalidad.setSize(42, 20);
270
                        lCalidad.setText(PluginServices.getText(this, "calidad"));
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"