Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / DEMO / Export.java @ 931

History | View | Annotate | Download (3.9 KB)

1 312 fernando
2
package com.iver.cit.gvsig.DEMO;
3
4
import java.awt.FileDialog;
5
import java.awt.Image;
6
import java.io.File;
7
import java.io.FileOutputStream;
8
9
import javax.swing.JFileChooser;
10
import javax.swing.filechooser.FileFilter;
11
12 403 fjp
import com.iver.cit.gvsig.fmap.NewMapControl;
13 312 fernando
import com.sun.jimi.core.Jimi;
14
import com.sun.jimi.core.raster.JimiRasterImage;
15
16
/**
17
 * @author VCN
18
 *
19
 * To change the template for this generated type comment go to
20
 * Window>Preferences>Java>Code Generation>Code and Comments
21
 */
22
23
public class Export
24
{
25 403 fjp
        private NewMapControl m_MapControl;
26 312 fernando
        private FileDialog fd;
27
        private Image tempImage;
28 403 fjp
        Export(NewMapControl fm)
29 312 fernando
        {
30
                m_MapControl=fm;
31
                JFileChooser tempChooser = new JFileChooser();
32
33
                tempChooser.addChoosableFileFilter(new FileFilter() {
34
                                public boolean accept(File f) {
35
                                        String extension = "";
36
                                        if (f.isDirectory()) return true;
37
                                        int i = f.getName().lastIndexOf('.');
38
                                        if (i > 0) extension = f.getName().substring(i + 1).toLowerCase();
39
                                        if (extension.equals("bmp")) return true;
40
                                        else return false;
41
                                }
42
                                public String getDescription() {
43
                                        return "Achivos BMP (*.bmp)";
44
                                }
45
                        });
46
47
        tempChooser.addChoosableFileFilter(new FileFilter() {
48
                           public boolean accept(File f) {
49
                                   String extension = "";
50
                                   if (f.isDirectory()) return true;
51
                                   int i = f.getName().lastIndexOf('.');
52
                                   if (i > 0) extension = f.getName().substring(i + 1).toLowerCase();
53
                                   if (extension.equals("jpg") || extension.equals("jpeg")) return true;
54
                                   else return false;
55
                           }
56
                           public String getDescription() {
57
                                   return "Archivos JPEG (*.jpg; *.jpeg)";
58
                           }
59
                   });
60
61
        tempChooser.addChoosableFileFilter(new FileFilter() {
62
                                public boolean accept(File f) {
63
                                        String extension = "";
64
                                        if (f.isDirectory()) return true;
65
                                        int i = f.getName().lastIndexOf('.');
66
                                        if (i > 0) extension = f.getName().substring(i + 1).toLowerCase();
67
                                        if (extension.equals("png")) return true;
68
                                        else return false;
69
                                }
70
                                public String getDescription() {
71
                                        return "Archivos PNG (*.png)";
72
                                }
73
                        });
74
75
        tempChooser.showSaveDialog(m_MapControl);
76
77
        File        tempFile = tempChooser.getSelectedFile();
78
        if (tempFile != null){
79
                try{
80
81
                                tempImage = null;
82
                                 tempImage = m_MapControl.getImage();
83
                                JimiRasterImage jrf = Jimi.createRasterImage(tempImage.getSource());
84
                                String tempName = tempFile.getName().toUpperCase().trim();
85
                                String extension="";
86
87
                                if ((tempName.endsWith(".JPG")) || (tempName.endsWith(".JPEG")) || (tempChooser.getFileFilter().getDescription().toString()=="Archivos JPEG (*.jpg; *.jpeg)")){
88
                                        if (!(tempName.endsWith(".JPG")) || (tempName.endsWith(".JPEG"))) extension=".jpg";
89
90
                                        File f1=new File(tempFile.getParent(), tempFile.getName() + extension);
91
                                        tempFile.renameTo(f1);
92
                                        System.out.println(tempFile.getName() + ".jpg");
93
                                        FileOutputStream fout = new FileOutputStream(f1);
94
                                        Jimi.putImage("image/jpg",jrf,fout);
95
                                        fout.close();
96
                                }
97
                                else if ((tempName.endsWith(".PNG")) || (tempChooser.getFileFilter().getDescription().toString()=="Archivos PNG (*.png)")){
98
                                        if (!(tempName.endsWith(".PNG"))) extension=".png";
99
                                        File f2=new File(tempFile.getParent(), tempFile.getName() + extension);
100
                                        tempFile.renameTo(f2);
101
                                        System.out.println(tempFile.getName() + ".png");
102
                                        FileOutputStream fout = new FileOutputStream(f2);
103
                                        Jimi.putImage("image/png",jrf,fout);
104
                                        fout.close();
105
                                }
106
                                else if ((tempName.endsWith(".BMP")) || (tempChooser.getFileFilter().getDescription().toString()=="Achivos BMP (*.bmp)")){
107
                                        if (!(tempName.endsWith(".BMP"))) extension=".bmp";
108
                                        File f3=new File(tempFile.getParent(), tempFile.getName() + extension);
109
                                        tempFile.renameTo(f3);
110
                                        System.out.println(tempFile.getName() + ".bmp");
111
                                        FileOutputStream fout = new FileOutputStream(f3);
112
                                        Jimi.putImage("image/bmp",jrf,fout);
113
                                        fout.close();
114
                                }
115
                }catch (Exception e){System.out.println("Exception   "+e);}
116
        }
117
  }
118
//>>>>>>> 1.2
119
}