svn-gvsig-desktop / tags / v1_0_2_Build_894 / applications / appgvSIG / src / com / iver / cit / gvsig / DEMO / Export.java @ 10309
History | View | Annotate | Download (5.08 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package com.iver.cit.gvsig.DEMO; |
43 |
|
44 |
import java.awt.FileDialog; |
45 |
import java.awt.Image; |
46 |
import java.io.File; |
47 |
import java.io.FileOutputStream; |
48 |
|
49 |
import javax.swing.JFileChooser; |
50 |
import javax.swing.filechooser.FileFilter; |
51 |
|
52 |
import com.iver.cit.gvsig.fmap.MapControl; |
53 |
import com.sun.jimi.core.Jimi; |
54 |
import com.sun.jimi.core.raster.JimiRasterImage; |
55 |
|
56 |
/**
|
57 |
* @author VCN
|
58 |
*
|
59 |
* To change the template for this generated type comment go to
|
60 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
61 |
*/
|
62 |
|
63 |
public class Export |
64 |
{ |
65 |
private MapControl m_MapControl;
|
66 |
private FileDialog fd; |
67 |
private Image tempImage; |
68 |
Export(MapControl fm) |
69 |
{ |
70 |
m_MapControl=fm; |
71 |
JFileChooser tempChooser = new JFileChooser(); |
72 |
|
73 |
tempChooser.addChoosableFileFilter(new FileFilter() { |
74 |
public boolean accept(File f) { |
75 |
String extension = ""; |
76 |
if (f.isDirectory()) return true; |
77 |
int i = f.getName().lastIndexOf('.'); |
78 |
if (i > 0) extension = f.getName().substring(i + 1).toLowerCase(); |
79 |
if (extension.equals("bmp")) return true; |
80 |
else return false; |
81 |
} |
82 |
public String getDescription() { |
83 |
return "Achivos BMP (*.bmp)"; |
84 |
} |
85 |
}); |
86 |
|
87 |
tempChooser.addChoosableFileFilter(new FileFilter() { |
88 |
public boolean accept(File f) { |
89 |
String extension = ""; |
90 |
if (f.isDirectory()) return true; |
91 |
int i = f.getName().lastIndexOf('.'); |
92 |
if (i > 0) extension = f.getName().substring(i + 1).toLowerCase(); |
93 |
if (extension.equals("jpg") || extension.equals("jpeg")) return true; |
94 |
else return false; |
95 |
} |
96 |
public String getDescription() { |
97 |
return "Archivos JPEG (*.jpg; *.jpeg)"; |
98 |
} |
99 |
}); |
100 |
|
101 |
tempChooser.addChoosableFileFilter(new FileFilter() { |
102 |
public boolean accept(File f) { |
103 |
String extension = ""; |
104 |
if (f.isDirectory()) return true; |
105 |
int i = f.getName().lastIndexOf('.'); |
106 |
if (i > 0) extension = f.getName().substring(i + 1).toLowerCase(); |
107 |
if (extension.equals("png")) return true; |
108 |
else return false; |
109 |
} |
110 |
public String getDescription() { |
111 |
return "Archivos PNG (*.png)"; |
112 |
} |
113 |
}); |
114 |
|
115 |
tempChooser.showSaveDialog(m_MapControl); |
116 |
|
117 |
File tempFile = tempChooser.getSelectedFile();
|
118 |
if (tempFile != null){ |
119 |
try{
|
120 |
|
121 |
tempImage = null;
|
122 |
tempImage = m_MapControl.getImage(); |
123 |
JimiRasterImage jrf = Jimi.createRasterImage(tempImage.getSource()); |
124 |
String tempName = tempFile.getName().toUpperCase().trim();
|
125 |
String extension=""; |
126 |
|
127 |
if ((tempName.endsWith(".JPG")) || (tempName.endsWith(".JPEG")) || (tempChooser.getFileFilter().getDescription().toString()=="Archivos JPEG (*.jpg; *.jpeg)")){ |
128 |
if (!(tempName.endsWith(".JPG")) || (tempName.endsWith(".JPEG"))) extension=".jpg"; |
129 |
|
130 |
File f1=new File(tempFile.getParent(), tempFile.getName() + extension); |
131 |
tempFile.renameTo(f1); |
132 |
System.out.println(tempFile.getName() + ".jpg"); |
133 |
FileOutputStream fout = new FileOutputStream(f1); |
134 |
Jimi.putImage("image/jpg",jrf,fout);
|
135 |
fout.close(); |
136 |
} |
137 |
else if ((tempName.endsWith(".PNG")) || (tempChooser.getFileFilter().getDescription().toString()=="Archivos PNG (*.png)")){ |
138 |
if (!(tempName.endsWith(".PNG"))) extension=".png"; |
139 |
File f2=new File(tempFile.getParent(), tempFile.getName() + extension); |
140 |
tempFile.renameTo(f2); |
141 |
System.out.println(tempFile.getName() + ".png"); |
142 |
FileOutputStream fout = new FileOutputStream(f2); |
143 |
Jimi.putImage("image/png",jrf,fout);
|
144 |
fout.close(); |
145 |
} |
146 |
else if ((tempName.endsWith(".BMP")) || (tempChooser.getFileFilter().getDescription().toString()=="Achivos BMP (*.bmp)")){ |
147 |
if (!(tempName.endsWith(".BMP"))) extension=".bmp"; |
148 |
File f3=new File(tempFile.getParent(), tempFile.getName() + extension); |
149 |
tempFile.renameTo(f3); |
150 |
System.out.println(tempFile.getName() + ".bmp"); |
151 |
FileOutputStream fout = new FileOutputStream(f3); |
152 |
Jimi.putImage("image/bmp",jrf,fout);
|
153 |
fout.close(); |
154 |
} |
155 |
}catch (Exception e){System.out.println("Exception "+e);} |
156 |
} |
157 |
} |
158 |
//>>>>>>> 1.2
|
159 |
} |