Statistics
| Revision:

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

History | View | Annotate | Download (11.8 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.project.documents.layout.FLayoutUtilities;
59
import com.iver.cit.gvsig.project.documents.layout.fframes.FFramePicture;
60
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
61
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.JPRotation;
62
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
63
import com.iver.utiles.GenericFileFilter;
64

    
65

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

    
91

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

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

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

    
124
        /**
125
         * This method initializes jContentPane
126
         *
127
         * @return javax.swing.JPanel
128
         */
129
        private javax.swing.JPanel getJContentPane() {
130
                if (jContentPane == null) {
131
                        jContentPane = new javax.swing.JPanel();
132
                        jContentPane.setLayout(null);
133
                        jContentPane.add(getLFichero(), null);
134
                        jContentPane.add(getLCalidad(), null);
135
                        jContentPane.add(getCbCalidad(), null);
136
                        jContentPane.add(getTFichero(), null);
137
                        jContentPane.add(getBExaminar(), null);
138
                        jContentPane.add(getLVisualizacion(), null);
139
                        jContentPane.add(getCbVisualizacion(), null);
140
                        jContentPane.add(getBAceptar(), null);
141
                        jContentPane.add(getBCancelar(), null);
142
                        jContentPane.setSize(499, 139);
143
                        jContentPane.setLocation(3, 0);
144
                        jContentPane.add(getPRotation(), null);
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

    
199
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
200
                                                String[] extensions = {
201
                                                                "jpeg", "jpg", "gif", "png", "bmp", "svg"
202
                                                        };
203
                                                GenericFileFilter filter = new GenericFileFilter(extensions,
204
                                                                "Image files (jpeg, jpg, gif, png, bmp, svg)");
205

    
206
                                                JFileChooser jfc = new JFileChooser();
207
                                                jfc.addChoosableFileFilter(filter);
208
                                                if (jfc.showOpenDialog(
209
                                                                        (Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
210
                                                        File file = jfc.getSelectedFile();
211
                                                        namefile = file.getName();
212
                                                        getTFichero().setText(file.getAbsolutePath());
213
                                                        path=file.getAbsolutePath();
214
//                                                        fframepicture.setPath(file.getAbsolutePath());
215
                                                }
216
                                        }
217
                                });
218
                }
219

    
220
                return bExaminar;
221
        }
222

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

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

    
245
                return lVisualizacion;
246
        }
247

    
248
        /**
249
         * This method initializes cbVisualizacion
250
         *
251
         * @return javax.swing.JComboBox
252
         */
253
        private javax.swing.JComboBox getCbVisualizacion() {
254
                if (cbVisualizacion == null) {
255
                        cbVisualizacion = new javax.swing.JComboBox();
256
                        cbVisualizacion.setSize(245, 20);
257
                        cbVisualizacion.addItem(PluginServices.getText(this, "cuando_activo"));
258
                        cbVisualizacion.addItem(PluginServices.getText(this, "siempre"));
259
                        cbVisualizacion.setSelectedIndex(fframepicture.getViewing());
260
                        cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20));
261
                        cbVisualizacion.setLocation(118, 62);
262
                        cbVisualizacion.setEnabled(false);
263
                        cbVisualizacion.setVisible(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(103, 20);
278
                        lCalidad.setText(PluginServices.getText(this, "calidad"));
279
                        lCalidad.setPreferredSize(new java.awt.Dimension(73,16));
280
                        lCalidad.setLocation(10, 35);
281
                }
282

    
283
                return lCalidad;
284
        }
285

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

    
302
                return cbCalidad;
303
        }
304

    
305
        /**
306
         * This method initializes bAceptar
307
         *
308
         * @return javax.swing.JButton
309
         */
310
        private javax.swing.JButton getBAceptar() {
311
                if (bAceptar == null) {
312
                        bAceptar = new javax.swing.JButton();
313
                        bAceptar.setSize(85, 26);
314
                        bAceptar.setText(PluginServices.getText(this, "Aceptar"));
315
                        bAceptar.setLocation(70, 89);
316
                        bAceptar.addActionListener(new java.awt.event.ActionListener() {
317

    
318
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
319
                                            Dimension dimension = null;
320
                                                try {
321
                                                    // ImageIcon imageIcon = new ImageIcon(getTFichero().getText());
322
                                                    dimension = fframepicture.getBound(getTFichero().getText());
323
                                                } catch (Exception ex) {
324
                                                        NotificationManager.addError("Excepci?n :", ex);
325
                                                }
326
                                                newFFramePicture=(FFramePicture)fframepicture.cloneFFrame(m_layout);
327
                                                newFFramePicture.setPath(path);
328
                                                newFFramePicture.setViewing(getCbVisualizacion()
329
                                                                                                         .getSelectedIndex());
330
                                                newFFramePicture.setQuality(getCbCalidad()
331
                                                                                                         .getSelectedIndex());
332

    
333
                                                if (namefile != null) {
334
                                                        newFFramePicture.setName(namefile);
335
                                                }
336
                                                // Ajustamos la relaci?n de aspecto a la altura.
337
                                                double ratio = (float) (dimension.getWidth()) / (float) (dimension.getHeight());
338

    
339
                                                double newWidth = rect.getHeight() * ratio;
340
                                                Rectangle2D.Double rAdjust = new Rectangle2D.Double(
341
                                                        rect.getMinX(), rect.getMinY(),
342
                                                        newWidth, rect.getHeight());
343
                                        rect = rAdjust;
344

    
345
                                                newFFramePicture.setBoundBox(FLayoutUtilities.toSheetRect(
346
                                                                rect, m_layout.getLayoutControl().getAT()));
347
                                                newFFramePicture.setRotation(getPRotation().getRotation());
348
                                                PluginServices.getMDIManager().closeWindow(FFramePictureDialog.this);
349
                                                //m_layout.refresh();
350
                                                isAcepted = true;
351
                                        }
352
                                });
353
                }
354

    
355
                return bAceptar;
356
        }
357

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

    
377
                return bCancelar;
378
        }
379

    
380
        /* (non-Javadoc)
381
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
382
         */
383
        public WindowInfo getWindowInfo() {
384
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
385
                m_viewinfo.setTitle(PluginServices.getText(this,
386
                                "propiedades_marco_imagenes"));
387

    
388
                return m_viewinfo;
389
        }
390

    
391
        /**
392
         * @see com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
393
         */
394
        public boolean getIsAcepted() {
395
                return isAcepted;
396
        }
397

    
398
        /**
399
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
400
         */
401
        public void viewActivated() {
402
        }
403

    
404
        /**
405
         * This method initializes pRotation
406
         *
407
         * @return javax.swing.JPanel
408
         */
409
        private JPRotation getPRotation() {
410
                if (pRotation == null) {
411
                        pRotation = new JPRotation();
412
                        pRotation.setBounds(373, 14, 120, 120);
413
                }
414
                return pRotation;
415
        }
416

    
417
        public IFFrame getFFrame() {
418
                return newFFramePicture;
419
        }
420
}  //  @jve:decl-index=0:visual-constraint="10,10"