Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFramePictureDialog.java @ 717

History | View | Annotate | Download (14.6 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.fframes.gui.dialogs;
23

    
24
import java.awt.Component;
25
import java.awt.Dimension;
26
import java.awt.event.ActionEvent;
27
import java.awt.geom.Rectangle2D;
28
import java.io.File;
29

    
30
import javax.swing.JFileChooser;
31

    
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.messages.NotificationManager;
34
import org.gvsig.andami.ui.mdiManager.WindowInfo;
35
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
36
import org.gvsig.app.project.documents.layout.fframes.FFramePicture;
37
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
38
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation;
39
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
40
import org.gvsig.utils.GenericFileFilter;
41

    
42
/**
43
 * Dialogo para a?adir una imagen al Layout.
44
 * 
45
 * @author Vicente Caballero Navarro
46
 */
47
public class FFramePictureDialog extends AbstractFFrameDialog implements
48
    IFFrameDialog {
49

    
50
    private static final long serialVersionUID = -5270176004672972463L;
51
    private javax.swing.JPanel jContentPane = null;
52
    private javax.swing.JLabel lFichero = null;
53
    private javax.swing.JTextField tFichero = null;
54
    private javax.swing.JButton bExaminar = null;
55
    private javax.swing.JLabel lVisualizacion = null;
56
    private javax.swing.JComboBox cbVisualizacion = null;
57
    private javax.swing.JLabel lCalidad = null;
58
    private javax.swing.JComboBox cbCalidad = null;
59
    private javax.swing.JButton bAceptar = null;
60
    private javax.swing.JButton bCancelar = null;
61
    private Rectangle2D rect = new Rectangle2D.Double();
62
    private FFramePicture fframepicture = null; // = new FFramePicture();
63
    private String namefile = null;
64
    private boolean isAcepted = false;
65
    private JPRotation pRotation = null;
66
    private String path;
67
    private FFramePicture newFFramePicture = null;
68

    
69
    /**
70
     * This is the default constructor
71
     * 
72
     * @param layoutPanel
73
     *            Referencia al Layout.
74
     * @param fframe
75
     *            Referencia al fframe de imagen.
76
     */
77
    public FFramePictureDialog(LayoutPanel layoutPanel, IFFrame frame) {
78
        super(layoutPanel, frame);
79
        fframepicture = (FFramePicture) frame;
80
        initialize();
81
    }
82

    
83
    /**
84
     * Inserta el rect?ngulo que ocupar? el fframe de imagen.
85
     * 
86
     * @param r
87
     *            Rect?ngulo.
88
     */
89
    public void setRectangle(Rectangle2D r) {
90
        rect.setRect(r);
91
    }
92

    
93
    /**
94
     * This method initializes this
95
     */
96
    private void initialize() {
97
        this.setLayout(null);
98
        this.add(getJContentPane(), null);
99
        this.setSize(505, 142);
100
        getPRotation().setRotation(fframepicture.getRotation());
101
    }
102

    
103
    /**
104
     * This method initializes jContentPane
105
     * 
106
     * @return javax.swing.JPanel
107
     */
108
    private javax.swing.JPanel getJContentPane() {
109
        if (jContentPane == null) {
110
            jContentPane = new javax.swing.JPanel();
111
            jContentPane.setLayout(null);
112
            jContentPane.add(getLFichero(), null);
113
            jContentPane.add(getLCalidad(), null);
114
            jContentPane.add(getCbCalidad(), null);
115
            jContentPane.add(getTFichero(), null);
116
            jContentPane.add(getBExaminar(), null);
117
            jContentPane.add(getLVisualizacion(), null);
118
            jContentPane.add(getCbVisualizacion(), null);
119
            jContentPane.add(getBAceptar(), null);
120
            jContentPane.add(getBCancelar(), null);
121
            jContentPane.setSize(499, 139);
122
            jContentPane.setLocation(3, 0);
123
            jContentPane.add(getPRotation(), null);
124
        }
125

    
126
        return jContentPane;
127
    }
128

    
129
    /**
130
     * This method initializes lFichero
131
     * 
132
     * @return javax.swing.JLabel
133
     */
134
    private javax.swing.JLabel getLFichero() {
135
        if (lFichero == null) {
136
            lFichero = new javax.swing.JLabel();
137
            lFichero.setSize(42, 20);
138
            lFichero.setText(PluginServices.getText(this, "Fichero"));
139
            lFichero.setLocation(10, 9);
140
        }
141

    
142
        return lFichero;
143
    }
144

    
145
    /**
146
     * This method initializes tFichero
147
     * 
148
     * @return javax.swing.JTextField
149
     */
150
    private javax.swing.JTextField getTFichero() {
151
        if (tFichero == null) {
152
            tFichero = new javax.swing.JTextField();
153
            tFichero.setBounds(62, 8, 200, 20);
154
            tFichero.setPreferredSize(new java.awt.Dimension(200, 20));
155
        }
156

    
157
        if (fframepicture.getPath() != null) {
158
            tFichero.setText(fframepicture.getPath());
159
        }
160

    
161
        return tFichero;
162
    }
163

    
164
    /**
165
     * This method initializes bExaminar
166
     * 
167
     * @return javax.swing.JButton
168
     */
169
    private javax.swing.JButton getBExaminar() {
170
        if (bExaminar == null) {
171
            bExaminar = new javax.swing.JButton();
172
            bExaminar.setSize(88, 23);
173
            bExaminar.setText(PluginServices.getText(this, "Examinar"));
174
            bExaminar.setLocation(275, 6);
175
            bExaminar.setPreferredSize(new java.awt.Dimension(88, 23));
176
            bExaminar.addActionListener(new java.awt.event.ActionListener() {
177

    
178
                public void actionPerformed(java.awt.event.ActionEvent e) {
179
                    String[] extensions =
180
                        { "jpeg", "jpg", "gif", "png", "bmp", "svg" };
181
                    GenericFileFilter filter =
182
                        new GenericFileFilter(extensions,
183
                            "Image files (jpeg, jpg, gif, png, bmp, svg)");
184

    
185
                    JFileChooser jfc = new JFileChooser();
186
                    jfc.addChoosableFileFilter(filter);
187
                    if (jfc.showOpenDialog((Component) PluginServices
188
                        .getMainFrame()) == JFileChooser.APPROVE_OPTION) {
189
                        File file = jfc.getSelectedFile();
190
                        namefile = file.getName();
191
                        getTFichero().setText(file.getAbsolutePath());
192
                        path = file.getAbsolutePath();
193
                        // fframepicture.setPath(file.getAbsolutePath());
194
                    }
195
                }
196
            });
197
        }
198

    
199
        return bExaminar;
200
    }
201

    
202
    /**
203
     * Inserta el path al TFichero.
204
     * 
205
     * @param val
206
     *            path del fichero.
207
     */
208
    public void setText(String val) {
209
        getTFichero().setText(val);
210
    }
211

    
212
    /**
213
     * This method initializes lVisualizacion
214
     * 
215
     * @return javax.swing.JLabel
216
     */
217
    private javax.swing.JLabel getLVisualizacion() {
218
        if (lVisualizacion == null) {
219
            lVisualizacion = new javax.swing.JLabel();
220
            lVisualizacion.setBounds(9, 62, 105, 20);
221
            lVisualizacion.setText(PluginServices
222
                .getText(this, "visualizacion"));
223
            lVisualizacion.setVisible(false);
224
        }
225

    
226
        return lVisualizacion;
227
    }
228

    
229
    /**
230
     * This method initializes cbVisualizacion
231
     * 
232
     * @return javax.swing.JComboBox
233
     */
234
    private javax.swing.JComboBox getCbVisualizacion() {
235
        if (cbVisualizacion == null) {
236
            cbVisualizacion = new javax.swing.JComboBox();
237
            cbVisualizacion.setSize(245, 20);
238
            cbVisualizacion.addItem(PluginServices.getText(this,
239
                "cuando_activo"));
240
            cbVisualizacion.addItem(PluginServices.getText(this, "siempre"));
241
            cbVisualizacion.setSelectedIndex(fframepicture.getViewing());
242
            cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20));
243
            cbVisualizacion.setLocation(118, 62);
244
            cbVisualizacion.setEnabled(false);
245
            cbVisualizacion.setVisible(false);
246
        }
247

    
248
        return cbVisualizacion;
249
    }
250

    
251
    /**
252
     * This method initializes lCalidad
253
     * 
254
     * @return javax.swing.JLabel
255
     */
256
    private javax.swing.JLabel getLCalidad() {
257
        if (lCalidad == null) {
258
            lCalidad = new javax.swing.JLabel();
259
            lCalidad.setSize(103, 20);
260
            lCalidad.setText(PluginServices.getText(this, "calidad"));
261
            lCalidad.setPreferredSize(new java.awt.Dimension(73, 16));
262
            lCalidad.setLocation(10, 35);
263
        }
264

    
265
        return lCalidad;
266
    }
267

    
268
    /**
269
     * This method initializes cbCalidad
270
     * 
271
     * @return javax.swing.JComboBox
272
     */
273
    private javax.swing.JComboBox getCbCalidad() {
274
        if (cbCalidad == null) {
275
            cbCalidad = new javax.swing.JComboBox();
276
            cbCalidad.setSize(245, 20);
277
            cbCalidad.addItem(PluginServices.getText(this, "presentacion"));
278
            cbCalidad.addItem(PluginServices.getText(this, "borrador"));
279
            cbCalidad.setSelectedIndex(fframepicture.getQuality());
280
            cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20));
281
            cbCalidad.setLocation(118, 35);
282
        }
283

    
284
        return cbCalidad;
285
    }
286

    
287
    /**
288
     * This method initializes bAceptar
289
     * 
290
     * @return javax.swing.JButton
291
     */
292
    private javax.swing.JButton getBAceptar() {
293
        if (bAceptar == null) {
294
            bAceptar = new javax.swing.JButton();
295
            bAceptar.setSize(85, 26);
296
            bAceptar.setText(PluginServices.getText(this, "Aceptar"));
297
            bAceptar.setLocation(70, 89);
298
            bAceptar.addActionListener(new java.awt.event.ActionListener() {
299

    
300
                public void actionPerformed(java.awt.event.ActionEvent e) {
301
                    Dimension dimension = null;
302
                    try {
303
                        // ImageIcon imageIcon = new
304
                        // ImageIcon(getTFichero().getText());
305
                        dimension =
306
                            fframepicture.getBound(getTFichero().getText());
307
                    } catch (Exception ex) {
308
                        NotificationManager.addError("Excepci?n :", ex);
309
                    }
310
                    try {
311
                        newFFramePicture =
312
                            (FFramePicture) fframepicture.clone();
313
                        if (path == null) {
314
                            path = getTFichero().getText();
315
                        }
316
                        newFFramePicture.setPath(path);
317
                        newFFramePicture.setViewing(getCbVisualizacion()
318
                            .getSelectedIndex());
319
                        newFFramePicture.setQuality(getCbCalidad()
320
                            .getSelectedIndex());
321

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

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

    
336
                        newFFramePicture.setBoundBox(FLayoutUtilities
337
                            .toSheetRect(rect, layoutPanel.getLayoutControl()
338
                                .getAT()));
339
                        newFFramePicture.setRotation(getPRotation()
340
                            .getRotation());
341
                    } catch (CloneNotSupportedException e1) {
342
                        LOG.error("It is not possible clonate the object", e);
343
                    }
344
                    isAcepted = true;
345
                    PluginServices.getMDIManager().closeWindow(
346
                        FFramePictureDialog.this);
347
                    notifyDialogClosed();
348
                    layoutPanel.getLayoutControl().setDefaultTool();
349
                    fireActionEvent(new ActionEvent(FFramePictureDialog.this, 1, "accept"));
350
                }
351
            });
352
        }
353

    
354
        return bAceptar;
355
    }
356

    
357
    /**
358
     * This method initializes bCancelar
359
     * 
360
     * @return javax.swing.JButton
361
     */
362
    private javax.swing.JButton getBCancelar() {
363
        if (bCancelar == null) {
364
            bCancelar = new javax.swing.JButton();
365
            bCancelar.setSize(85, 26);
366
            bCancelar.setText(PluginServices.getText(this, "Cancelar"));
367
            bCancelar.setLocation(219, 89);
368
            bCancelar.addActionListener(new java.awt.event.ActionListener() {
369

    
370
                public void actionPerformed(java.awt.event.ActionEvent e) {
371
                    newFFramePicture = null;
372
                    PluginServices.getMDIManager().closeWindow(
373
                        FFramePictureDialog.this);
374
                    notifyDialogClosed();
375
                }
376
            });
377
        }
378

    
379
        return bCancelar;
380
    }
381

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

    
392
        return m_viewinfo;
393
    }
394

    
395
    /**
396
     * @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
397
     */
398
    public boolean getIsAcepted() {
399
        return isAcepted;
400
    }
401

    
402
    /**
403
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
404
     */
405
    public void viewActivated() {
406
    }
407

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

    
421
    public IFFrame getFFrame() {
422
        return newFFramePicture;
423
    }
424

    
425
    public Object getWindowProfile() {
426
        return WindowInfo.DIALOG_PROFILE;
427
    }
428

    
429
} // @jve:decl-index=0:visual-constraint="10,10"