Revision 26141
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/build_javi.xml | ||
---|---|---|
1 |
<project name="Generar extension en Andami" default="generate-without-source" basedir="."> |
|
2 |
<description> |
|
3 |
Instala el plugin de ejemplo en Andami. |
|
4 |
</description> |
|
5 |
<!-- set global properties for this build --> |
|
6 |
<property name="src" location="src"/> |
|
7 |
<property name="build" location="bin"/> |
|
8 |
<property name="dist" location="dist"/> |
|
9 |
<property name="plugin" value="es.prodevelop.gvsig.exportMobile"/> |
|
10 |
<property name="extension-dir" location="C:/Archivos de programa/gvSIG_1.1final/bin/gvSIG/extensiones"/> |
|
11 |
<property name="install-tree-dir" location="C:/Archivos de programa/gvSIG_1.1final/bin/gvSIG/extensiones"/> |
|
12 |
|
|
13 |
<target name="init"> |
|
14 |
<!-- Create the time stamp --> |
|
15 |
<tstamp/> |
|
16 |
<!-- Create the build directory structure used by compile --> |
|
17 |
<mkdir dir="${build}"/> |
|
18 |
<mkdir dir="${dist}"/> |
|
19 |
<!-- Creamos un fichero con el timeStamp para que lo lea el FPanelAbout --> |
|
20 |
<buildnumber/> |
|
21 |
|
|
22 |
</target> |
|
23 |
|
|
24 |
<target name="generate-without-source" description="generate the distribution without the source file" > |
|
25 |
<!-- Create the distribution directory --> |
|
26 |
<mkdir dir="${dist}"/> |
|
27 |
|
|
28 |
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> |
|
29 |
<jar jarfile="${dist}/${plugin}.jar" basedir="${build}"/> |
|
30 |
<copy file="config/config.xml" todir="${dist}"/> |
|
31 |
<copy todir="${dist}"> |
|
32 |
<fileset dir="." includes="text*.properties"/> |
|
33 |
</copy> |
|
34 |
<copy todir="${dist}/images"> |
|
35 |
<fileset dir="images/" includes="*"/> |
|
36 |
</copy> |
|
37 |
<move todir="${extension-dir}/${plugin}/"> |
|
38 |
<fileset dir="${dist}" includes="**/**"/> |
|
39 |
</move> |
|
40 |
</target> |
|
41 |
|
|
42 |
<target name="generate-install-tree-export-only" description="generate the install tree" > |
|
43 |
<!-- Create the distribution directory --> |
|
44 |
<mkdir dir="${dist}"/> |
|
45 |
|
|
46 |
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> |
|
47 |
<jar jarfile="${dist}/${plugin}.jar" basedir="${build}"/> |
|
48 |
<copy file="config/config.xml" todir="${dist}"/> |
|
49 |
<copy todir="${dist}"> |
|
50 |
<fileset dir="." includes="text*.properties"/> |
|
51 |
</copy> |
|
52 |
<copy todir="${dist}/images"> |
|
53 |
<fileset dir="images/" includes="*"/> |
|
54 |
</copy> |
|
55 |
<move todir="./install/bin/gvSIG/extensiones/${plugin}/"> |
|
56 |
<fileset dir="${dist}" includes="**/**"/> |
|
57 |
</move> |
|
58 |
</target> |
|
59 |
|
|
60 |
<!-- |
|
61 |
|
|
62 |
<target name="clean-install-tree-export-synchro"> |
|
63 |
<delete> |
|
64 |
<fileset dir="./install/pub/"> |
|
65 |
<include name="*.zip"/> |
|
66 |
</fileset> |
|
67 |
<fileset dir="./install/export_installer/"> |
|
68 |
<include name="*.jar"/> |
|
69 |
</fileset> |
|
70 |
</delete> |
|
71 |
<delete dir="./install/bin" /> |
|
72 |
<mkdir dir="./install/bin" /> |
|
73 |
<mkdir dir="./install/bin/gvSIG" /> |
|
74 |
<mkdir dir="./install/bin/gvSIG/extensiones" /> |
|
75 |
</target> |
|
76 |
--> |
|
77 |
|
|
78 |
</project> |
|
79 |
|
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/files/NewDir.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile.files; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.FileOutputStream; |
|
6 |
import java.io.IOException; |
|
7 |
|
|
8 |
import org.apache.log4j.Logger; |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* Manages the directory when a gvsig mobile project |
|
13 |
* with his data will be stored |
|
14 |
* |
|
15 |
* @author Anabel Moreno |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class NewDir { |
|
19 |
|
|
20 |
private static Logger logger = Logger.getLogger(NewDir.class.getName()); |
|
21 |
|
|
22 |
private String namePath; |
|
23 |
|
|
24 |
private File newFileProy; |
|
25 |
|
|
26 |
private File[] filesDir; |
|
27 |
|
|
28 |
private int numFiles; |
|
29 |
|
|
30 |
public static final String tempDirectoryPath = System.getProperty("java.io.tmpdir")+"/tmp-andami"; |
|
31 |
|
|
32 |
/** |
|
33 |
* Create new output file |
|
34 |
* |
|
35 |
* @param dirOutPut |
|
36 |
*/ |
|
37 |
public NewDir(String dirOutPut) { |
|
38 |
|
|
39 |
namePath = (dirOutPut + File.separator); |
|
40 |
newFileProy = new File(namePath); |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* @return true if the directory is empty |
|
46 |
*/ |
|
47 |
public boolean isEmpty() { |
|
48 |
|
|
49 |
filesDir = newFileProy.listFiles(); |
|
50 |
numFiles = filesDir.length; |
|
51 |
|
|
52 |
if (contFiles(filesDir) == 0) |
|
53 |
return true; |
|
54 |
else |
|
55 |
return false; |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Count the name of files in a directory |
|
61 |
* |
|
62 |
* @param arrFiles |
|
63 |
* @return the number of files in a directory |
|
64 |
*/ |
|
65 |
private int contFiles(File[] arrFiles) { |
|
66 |
|
|
67 |
int cont = 0; |
|
68 |
for (int i = 0; i < arrFiles.length; i++) { |
|
69 |
|
|
70 |
if (arrFiles[i].exists()) { |
|
71 |
cont++; |
|
72 |
} |
|
73 |
} |
|
74 |
return cont; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Delete files |
|
79 |
*/ |
|
80 |
public void deleteFiles() { |
|
81 |
|
|
82 |
for (int i = 0; i < numFiles; i++) { |
|
83 |
filesDir[i].delete(); |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* if file exists and is directory, while this file is full, the files that |
|
91 |
* are into the file will be deleted |
|
92 |
* |
|
93 |
* @return output directory |
|
94 |
*/ |
|
95 |
public File ifExistDir() { |
|
96 |
|
|
97 |
File outputPath = null; |
|
98 |
|
|
99 |
if (newFileProy.exists()) { |
|
100 |
|
|
101 |
if (newFileProy.isDirectory()) { |
|
102 |
|
|
103 |
// to delete, the directory has to be empty |
|
104 |
|
|
105 |
while (isEmpty() == false) { |
|
106 |
|
|
107 |
deleteFiles(); |
|
108 |
} |
|
109 |
|
|
110 |
File deletedFile = newFileProy; |
|
111 |
boolean delete = deletedFile.delete(); |
|
112 |
// if (delete) System.out.println("delete file"); |
|
113 |
// else System.out.println("not delete"); |
|
114 |
|
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
/** new directory */ |
|
119 |
|
|
120 |
boolean mk = newFileProy.mkdir(); |
|
121 |
|
|
122 |
if (mk == true) { |
|
123 |
|
|
124 |
/* create output File for result layer */ |
|
125 |
outputPath = new File(newFileProy.getAbsolutePath()); |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
return outputPath; |
|
130 |
} |
|
131 |
|
|
132 |
public static void copyFile(File in, File out) { |
|
133 |
|
|
134 |
FileInputStream fis = null; |
|
135 |
FileOutputStream fos = null; |
|
136 |
try { |
|
137 |
fis = new FileInputStream(in); |
|
138 |
fos = new FileOutputStream(out); |
|
139 |
byte[] buf = new byte[1024]; |
|
140 |
int i = 0; |
|
141 |
while ((i = fis.read(buf)) != -1) { |
|
142 |
fos.write(buf, 0, i); |
|
143 |
} |
|
144 |
if (fis != null) fis.close(); |
|
145 |
if (fos != null) fos.close(); |
|
146 |
} catch (Exception e) { |
|
147 |
logger.error("Unable to copy file: " + e.getMessage()); |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
public static void copyShpDbfShxTempToFinal(File source, File dest) { |
|
152 |
|
|
153 |
if (dest == null) { |
|
154 |
logger.error("Unable to copy temp to file: finalFile is NULL !"); |
|
155 |
} |
|
156 |
|
|
157 |
if (source == null) { |
|
158 |
logger.error("Unable to copy temp to file: tempFile is NULL !"); |
|
159 |
} |
|
160 |
|
|
161 |
int temp_last_shp = source.getAbsolutePath().toLowerCase().lastIndexOf(".shp"); |
|
162 |
String temp_base = source.getAbsolutePath().substring(0, temp_last_shp); |
|
163 |
int final_last_shp = dest.getAbsolutePath().toLowerCase().lastIndexOf(".shp"); |
|
164 |
String final_base = dest.getAbsolutePath().substring(0, final_last_shp); |
|
165 |
|
|
166 |
NewDir.copyFile(source, dest); |
|
167 |
|
|
168 |
File f_in = new File(temp_base + ".dbf"); |
|
169 |
File f_out = new File(final_base + ".dbf"); |
|
170 |
NewDir.copyFile(f_in, f_out); |
|
171 |
|
|
172 |
f_in = new File(temp_base + ".shx"); |
|
173 |
f_out = new File(final_base + ".shx"); |
|
174 |
NewDir.copyFile(f_in, f_out); |
|
175 |
} |
|
176 |
|
|
177 |
public static File getTempShpFile() { |
|
178 |
|
|
179 |
File f = null; |
|
180 |
String t = "" + System.currentTimeMillis(); |
|
181 |
try { |
|
182 |
f = File.createTempFile(t, ".shp"); |
|
183 |
f.deleteOnExit(); |
|
184 |
} catch (IOException e) { |
|
185 |
logger.error("Unable to create temp file: " + e.getMessage()); |
|
186 |
} |
|
187 |
return f; |
|
188 |
} |
|
189 |
|
|
190 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/LayerObject.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile; |
|
2 |
|
|
3 |
|
|
4 |
import javax.swing.JButton; |
|
5 |
import javax.swing.JCheckBox; |
|
6 |
import javax.swing.JComboBox; |
|
7 |
import javax.swing.JLabel; |
|
8 |
import javax.swing.JPanel; |
|
9 |
|
|
10 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
11 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
12 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
13 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
14 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
|
15 |
|
|
16 |
/** |
|
17 |
* Create a layer object with its checkbox, button, combo and description change |
|
18 |
* the name to the layer if the name layer is duplicate |
|
19 |
* |
|
20 |
* @author Anabel Moreno |
|
21 |
* |
|
22 |
*/ |
|
23 |
public class LayerObject { |
|
24 |
|
|
25 |
private JCheckBox boxLyr; |
|
26 |
|
|
27 |
private String nameLyr; |
|
28 |
|
|
29 |
private JComboBox comboLyr; |
|
30 |
|
|
31 |
private FieldDescription[] description; |
|
32 |
|
|
33 |
private FLayer lyr; |
|
34 |
|
|
35 |
private JButton buttonLyr; |
|
36 |
|
|
37 |
private JPanel parent; |
|
38 |
|
|
39 |
private JLabel isInto; |
|
40 |
|
|
41 |
// private String nameNew; |
|
42 |
|
|
43 |
/** |
|
44 |
* @param box |
|
45 |
* layer |
|
46 |
* @param name |
|
47 |
* layer order |
|
48 |
* @param combo |
|
49 |
* layer |
|
50 |
* @param layer |
|
51 |
* @param button |
|
52 |
* layer |
|
53 |
*/ |
|
54 |
public LayerObject(JCheckBox box, String name, JComboBox combo, |
|
55 |
FLayer layerwn, JButton button,JPanel pa) { |
|
56 |
|
|
57 |
parent=pa; |
|
58 |
boxLyr = box; |
|
59 |
nameLyr = name; |
|
60 |
comboLyr = combo; |
|
61 |
buttonLyr = button; |
|
62 |
|
|
63 |
|
|
64 |
try { |
|
65 |
// lyr = layer.cloneLayer(); |
|
66 |
// lyr.setName(nameLyr); |
|
67 |
// lyr.setProjection(layer.getProjection()); |
|
68 |
// jldominguez december 2007 |
|
69 |
lyr = layerwn; |
|
70 |
} catch (Exception e) { |
|
71 |
e.printStackTrace(); |
|
72 |
} |
|
73 |
|
|
74 |
if(boxLyr.isSelected()==true){ |
|
75 |
|
|
76 |
if(lyr instanceof FLyrVect){ |
|
77 |
comboLyr.setEnabled(true); |
|
78 |
buttonLyr.setEnabled(true); |
|
79 |
} |
|
80 |
if(lyr instanceof FLyrRaster){ |
|
81 |
comboLyr.setEnabled(true); |
|
82 |
buttonLyr.setEnabled(false); |
|
83 |
} |
|
84 |
} |
|
85 |
else{ |
|
86 |
comboLyr.setEnabled(false); |
|
87 |
buttonLyr.setEnabled(false); |
|
88 |
} |
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
if (lyr instanceof FLyrRaster) { |
|
93 |
buttonLyr.setEnabled(false); |
|
94 |
} |
|
95 |
if (lyr instanceof FLyrWMS) { |
|
96 |
|
|
97 |
comboLyr.setEnabled(false); |
|
98 |
buttonLyr.setEnabled(false); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* @return parent |
|
104 |
*/ |
|
105 |
public JPanel getParent(){ |
|
106 |
return parent; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Set box layer selected |
|
111 |
* |
|
112 |
* @param st |
|
113 |
*/ |
|
114 |
public void setBoxStatus(boolean st) { |
|
115 |
|
|
116 |
boxLyr.setSelected(st); |
|
117 |
|
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* @return layer button |
|
122 |
*/ |
|
123 |
public JButton getButton() { |
|
124 |
|
|
125 |
return buttonLyr; |
|
126 |
} |
|
127 |
|
|
128 |
|
|
129 |
/** |
|
130 |
* @return layer name |
|
131 |
*/ |
|
132 |
public String getName() { |
|
133 |
|
|
134 |
return nameLyr; |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Change layer name |
|
139 |
* @param name |
|
140 |
*/ |
|
141 |
public void setName(String n){ |
|
142 |
|
|
143 |
nameLyr = n; |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* @return layer checkbox |
|
148 |
*/ |
|
149 |
public JCheckBox getBox() { |
|
150 |
|
|
151 |
return boxLyr; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* @return layer combo |
|
156 |
*/ |
|
157 |
public JComboBox getCombo() { |
|
158 |
|
|
159 |
return comboLyr; |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* set combo properties (enabled and selected index) |
|
164 |
* @param combo |
|
165 |
* @param indx |
|
166 |
*/ |
|
167 |
public void setCombo(boolean combo,int indx){ |
|
168 |
|
|
169 |
comboLyr.setEnabled(combo); |
|
170 |
comboLyr.setSelectedIndex(indx); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Set layer field description |
|
175 |
* |
|
176 |
* @param atribSelected |
|
177 |
*/ |
|
178 |
public void setDescription(FieldDescription[] atribSelected) { |
|
179 |
|
|
180 |
description = atribSelected; |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* @return layer description |
|
185 |
*/ |
|
186 |
public FieldDescription[] getDescription() { |
|
187 |
|
|
188 |
return description; |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* set image layer, if this is into the view, and create a label with this image |
|
193 |
* @param imgInto |
|
194 |
*/ |
|
195 |
public void setImage(JLabel imgInto){ |
|
196 |
|
|
197 |
isInto=imgInto; |
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* @return image label |
|
203 |
*/ |
|
204 |
public JLabel getImgLbl(){ |
|
205 |
|
|
206 |
return isInto; |
|
207 |
} |
|
208 |
|
|
209 |
public FLayer getLyr() { |
|
210 |
return lyr; |
|
211 |
} |
|
212 |
|
|
213 |
public void setLyr(FLayer lyr) { |
|
214 |
this.lyr = lyr; |
|
215 |
} |
|
216 |
|
|
217 |
|
|
218 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/ClipExtension.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
|
|
5 |
import com.iver.andami.PluginServices; |
|
6 |
import com.iver.andami.plugins.Extension; |
|
7 |
import com.iver.cit.gvsig.About; |
|
8 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
9 |
import com.iver.cit.gvsig.project.ProjectExtent; |
|
10 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
11 |
|
|
12 |
import es.prodevelop.gvsig.exportMobile.ui.order.FLayerWithNewName; |
|
13 |
import es.prodevelop.gvsig.exportMobile.ui.panels.ExportPanel; |
|
14 |
|
|
15 |
|
|
16 |
/** |
|
17 |
* |
|
18 |
* This extension allows a user to export all the layers in a view |
|
19 |
* |
|
20 |
* @author amoreno |
|
21 |
* |
|
22 |
*/ |
|
23 |
public class ClipExtension extends Extension { |
|
24 |
|
|
25 |
/** |
|
26 |
* Starts the extension |
|
27 |
*/ |
|
28 |
public void initialize() { |
|
29 |
|
|
30 |
// about |
|
31 |
java.net.URL newurl = |
|
32 |
createResourceUrl("about/export-mobile-about.html"); |
|
33 |
About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class); |
|
34 |
claseAbout.getAboutPanel().addAboutUrl("Export to gvSIG Mobile", newurl); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
public boolean isEnabled() { |
|
39 |
|
|
40 |
return true; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* is visible when a view is the active window |
|
45 |
*/ |
|
46 |
public boolean isVisible() { |
|
47 |
com.iver.andami.ui.mdiManager.IWindow f = (com.iver.andami.ui.mdiManager.IWindow) PluginServices |
|
48 |
.getMDIManager().getActiveWindow(); |
|
49 |
|
|
50 |
if (f == null) { |
|
51 |
return false; |
|
52 |
} |
|
53 |
|
|
54 |
return (f instanceof View); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* @param actionCommand not used |
|
59 |
* It's called when the export to gvsig mobile button is pressed |
|
60 |
*/ |
|
61 |
public void execute(String actionCommand) { |
|
62 |
|
|
63 |
View view = (View) PluginServices.getMDIManager().getActiveWindow(); |
|
64 |
view.getModel().getProject().getExtents(); |
|
65 |
// root |
|
66 |
FLayers rt = view.getMapControl().getMapContext().getLayers(); |
|
67 |
ArrayList lyrsNewName = FLayerWithNewName.getAll(rt); |
|
68 |
ProjectExtent[] listExtent = view.getModel().getProject().getExtents(); |
|
69 |
ExportPanel infPanel = new ExportPanel(lyrsNewName, listExtent); |
|
70 |
PluginServices.getMDIManager().addWindow(infPanel); |
|
71 |
} |
|
72 |
|
|
73 |
private java.net.URL createResourceUrl(String path) { |
|
74 |
return getClass().getClassLoader().getResource(path); |
|
75 |
} |
|
76 |
|
|
77 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/rectangle/DrawRectangle.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile.rectangle; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.util.ArrayList; |
|
5 |
|
|
6 |
import org.cresques.cts.IProjection; |
|
7 |
|
|
8 |
import com.hardcode.gdbms.engine.values.Value; |
|
9 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
10 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
11 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
|
12 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
13 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
14 |
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver; |
|
15 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
16 |
import com.iver.cit.gvsig.fmap.layers.FLayerVectorialDB; |
|
17 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
18 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
19 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
20 |
|
|
21 |
/** |
|
22 |
* Utility to create layers with rectangles |
|
23 |
* |
|
24 |
* @author Anabel Moreno |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class DrawRectangle { |
|
28 |
|
|
29 |
private Rectangle2D rect; |
|
30 |
|
|
31 |
private FShape shp; |
|
32 |
|
|
33 |
private View v; |
|
34 |
|
|
35 |
private static String RECTANGLE = "Rectangle"; |
|
36 |
|
|
37 |
public DrawRectangle(View view) { |
|
38 |
|
|
39 |
v = view; |
|
40 |
} |
|
41 |
|
|
42 |
public Rectangle2D getRectangle() { |
|
43 |
|
|
44 |
return rect; |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Set the rectangle of the view |
|
49 |
*/ |
|
50 |
public void setRectView() { |
|
51 |
|
|
52 |
rect = v.getMapControl().getViewPort().getAdjustedExtent(); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Set rectangle of the extent |
|
57 |
* @param recExtent |
|
58 |
*/ |
|
59 |
public void setRectExtent(Rectangle2D recExtent) { |
|
60 |
|
|
61 |
rect = recExtent; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Create and draw a new rectangle poligon |
|
66 |
* |
|
67 |
* @param mapCtrl |
|
68 |
* @return layer |
|
69 |
*/ |
|
70 |
public FLayer draw(MapControl mapCtrl) { |
|
71 |
|
|
72 |
/* DRIVER DEFINITION (SHAPE TYPE AND FIELDS) */ |
|
73 |
ConcreteMemoryDriver driver = new ConcreteMemoryDriver(); |
|
74 |
driver.setShapeType(FShape.POLYGON); |
|
75 |
|
|
76 |
ArrayList arrayFields = new ArrayList(); |
|
77 |
arrayFields.add("ID"); |
|
78 |
Value[] auxRow = new Value[1]; |
|
79 |
|
|
80 |
driver.getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
|
81 |
|
|
82 |
/* GEOMETRY DEFINITION */ |
|
83 |
GeneralPathX rectangulo = new GeneralPathX(); |
|
84 |
|
|
85 |
// rect is the rectangle extent of the view |
|
86 |
/* NEW RECTANGLE */ |
|
87 |
rectangulo.moveTo(rect.getMinX(), rect.getMinY()); |
|
88 |
rectangulo.lineTo(rect.getMinX(), rect.getMaxY()); |
|
89 |
rectangulo.lineTo(rect.getMaxX(), rect.getMaxY()); |
|
90 |
rectangulo.lineTo(rect.getMaxX(), rect.getMinY()); |
|
91 |
rectangulo.closePath(); |
|
92 |
|
|
93 |
shp = new FPolygon2D(rectangulo); |
|
94 |
|
|
95 |
/* ATRIBUTES */ |
|
96 |
auxRow[0] = ValueFactory.createValue(0); |
|
97 |
|
|
98 |
/* ADD RECORD */ |
|
99 |
driver.addShape(shp, auxRow); |
|
100 |
|
|
101 |
/* CREATE AND ADD LAYER */ |
|
102 |
FLayer lyr; |
|
103 |
String layerName = RECTANGLE; |
|
104 |
lyr = LayerFactory.createLayer(layerName, driver, mapCtrl |
|
105 |
.getProjection()); |
|
106 |
|
|
107 |
return lyr; |
|
108 |
|
|
109 |
} |
|
110 |
/** |
|
111 |
* Create and draw a new rectangle poligon |
|
112 |
* |
|
113 |
* @param rect |
|
114 |
* @return layer |
|
115 |
*/ |
|
116 |
public static FLyrVect createRectangleLayer(Rectangle2D rect, IProjection projection) { |
|
117 |
|
|
118 |
/* DRIVER DEFINITION (SHAPE TYPE AND FIELDS) */ |
|
119 |
ConcreteMemoryDriver driver = new ConcreteMemoryDriver(); |
|
120 |
driver.setShapeType(FShape.POLYGON); |
|
121 |
|
|
122 |
ArrayList arrayFields = new ArrayList(); |
|
123 |
arrayFields.add("ID"); |
|
124 |
Value[] auxRow = new Value[1]; |
|
125 |
|
|
126 |
driver.getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
|
127 |
|
|
128 |
/* GEOMETRY DEFINITION */ |
|
129 |
GeneralPathX rectangulo = new GeneralPathX(); |
|
130 |
|
|
131 |
// rect is the rectangle extent of the view |
|
132 |
/* NEW RECTANGLE */ |
|
133 |
rectangulo.moveTo(rect.getMinX(), rect.getMinY()); |
|
134 |
rectangulo.lineTo(rect.getMinX(), rect.getMaxY()); |
|
135 |
rectangulo.lineTo(rect.getMaxX(), rect.getMaxY()); |
|
136 |
rectangulo.lineTo(rect.getMaxX(), rect.getMinY()); |
|
137 |
rectangulo.closePath(); |
|
138 |
|
|
139 |
FPolygon2D shp = new FPolygon2D(rectangulo); |
|
140 |
|
|
141 |
/* ATRIBUTES */ |
|
142 |
auxRow[0] = ValueFactory.createValue(0); |
|
143 |
|
|
144 |
/* ADD RECORD */ |
|
145 |
driver.addShape(shp, auxRow); |
|
146 |
|
|
147 |
/* CREATE AND ADD LAYER */ |
|
148 |
FLyrVect lyr; |
|
149 |
String layerName = RECTANGLE; |
|
150 |
lyr = (FLyrVect)LayerFactory.createLayer(layerName, driver, projection); |
|
151 |
|
|
152 |
return lyr; |
|
153 |
|
|
154 |
} |
|
155 |
|
|
156 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/CreateImage.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile; |
|
2 |
|
|
3 |
import java.net.URL; |
|
4 |
|
|
5 |
import javax.swing.ImageIcon; |
|
6 |
|
|
7 |
import org.apache.log4j.Logger; |
|
8 |
|
|
9 |
/** |
|
10 |
* Class to access the icons used by the extension |
|
11 |
* @author amoreno |
|
12 |
* |
|
13 |
*/ |
|
14 |
public class CreateImage { |
|
15 |
|
|
16 |
private Logger logger = Logger.getLogger(CreateImage.class.getClass()); |
|
17 |
|
|
18 |
public CreateImage() { |
|
19 |
|
|
20 |
} |
|
21 |
|
|
22 |
/** |
|
23 |
* Get path image |
|
24 |
* |
|
25 |
* @param path |
|
26 |
* @return URL |
|
27 |
*/ |
|
28 |
public java.net.URL createResourceUrl(String path) { |
|
29 |
return getClass().getClassLoader().getResource(path); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Create image icon |
|
34 |
* |
|
35 |
* @param path |
|
36 |
* where the image is into. |
|
37 |
* @param description |
|
38 |
* of the image. |
|
39 |
* @return ImageIcon |
|
40 |
*/ |
|
41 |
public ImageIcon createImageIcon(URL path, String description) { |
|
42 |
|
|
43 |
java.net.URL imgURL = path; |
|
44 |
if (imgURL != null) { |
|
45 |
return new ImageIcon(imgURL, description); |
|
46 |
} else { |
|
47 |
logger.error("Couldn't find file: " + path); |
|
48 |
return null; |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/layerexporters/clip/ClipProcess.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile.layerexporters.clip; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import com.iver.andami.PluginServices; |
|
7 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
8 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
|
9 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
10 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
11 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
|
12 |
import com.iver.cit.gvsig.fmap.edition.ISchemaManager; |
|
13 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
|
14 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
15 |
import com.iver.cit.gvsig.fmap.layers.FLayerVectorialDB; |
|
16 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
17 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
|
18 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
|
19 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
|
20 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess; |
|
21 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
|
22 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IOverlayGeoprocess; |
|
23 |
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes; |
|
24 |
import com.iver.cit.gvsig.geoprocess.impl.clip.fmap.ClipVisitor; |
|
25 |
import com.iver.cit.gvsig.geoprocess.impl.convexhull.fmap.ScalableUnionVisitor; |
|
26 |
import com.iver.utiles.swing.threads.CancellableMonitorable; |
|
27 |
import com.iver.utiles.swing.threads.DefaultCancellableMonitorable; |
|
28 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
|
29 |
import com.vividsolutions.jts.geom.Geometry; |
|
30 |
|
|
31 |
//ClipProcess is as ClipGeoprocess but createLayerDefinition method |
|
32 |
//is diferent because we have to add some original layer`s atributes (new description) |
|
33 |
//to export not all layer`s atributes |
|
34 |
|
|
35 |
public class ClipProcess extends AbstractGeoprocess implements |
|
36 |
IOverlayGeoprocess { |
|
37 |
|
|
38 |
private FLyrVect auxLayer; |
|
39 |
|
|
40 |
private boolean onlyFirstLayerSelection = false; |
|
41 |
|
|
42 |
private boolean onlyClipLayerSelection = false; |
|
43 |
|
|
44 |
private ClipVisitor visitor; |
|
45 |
|
|
46 |
private ILayerDefinition resultLayerDefinition; |
|
47 |
|
|
48 |
private FieldDescription[] description; |
|
49 |
|
|
50 |
//private FLayerWithNewName firstWN; |
|
51 |
private FLyrVect firstWN; |
|
52 |
private FBitSet bitset; |
|
53 |
|
|
54 |
public ClipProcess(FLyrVect lyr_wn, FieldDescription[] desc) { |
|
55 |
|
|
56 |
firstWN = lyr_wn; |
|
57 |
setFirstOperand(lyr_wn); |
|
58 |
description = desc; |
|
59 |
} |
|
60 |
|
|
61 |
public ClipProcess(FLyrVect lyr_wn, FieldDescription[] desc, FBitSet bitset) { |
|
62 |
|
|
63 |
firstWN = lyr_wn; |
|
64 |
setFirstOperand(lyr_wn); |
|
65 |
description = desc; |
|
66 |
this.bitset=bitset; |
|
67 |
} |
|
68 |
|
|
69 |
/** set parameters */ |
|
70 |
public void setParameters(Map params) throws GeoprocessException { |
|
71 |
|
|
72 |
Boolean firstLayerSelection = (Boolean) params |
|
73 |
.get("firstlayerselection"); |
|
74 |
if (firstLayerSelection != null) |
|
75 |
this.onlyFirstLayerSelection = firstLayerSelection.booleanValue(); |
|
76 |
|
|
77 |
Boolean secondLayerSelection = (Boolean) params |
|
78 |
.get("secondlayerselection"); |
|
79 |
if (secondLayerSelection != null) |
|
80 |
this.onlyClipLayerSelection = secondLayerSelection.booleanValue(); |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
public void checkPreconditions() throws GeoprocessException { |
|
85 |
// TODO Auto-generated method stub |
|
86 |
if (firstLayer == null) |
|
87 |
throw new GeoprocessException("Clip: capa de entrada a null"); |
|
88 |
if (auxLayer == null) |
|
89 |
throw new GeoprocessException("Clip: capa de clip a null"); |
|
90 |
if (this.writer == null || this.schemaManager == null) { |
|
91 |
throw new GeoprocessException( |
|
92 |
"Operacion de clip sin especificar capa de resultados"); |
|
93 |
} |
|
94 |
|
|
95 |
try { |
|
96 |
if (auxLayer.getShapeType() != XTypes.POLYGON |
|
97 |
&& (auxLayer.getShapeType() != XTypes.MULTI)) { |
|
98 |
throw new GeoprocessException( |
|
99 |
"La capa de recorte no es de pol?gonos"); |
|
100 |
} |
|
101 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
102 |
throw new GeoprocessException( |
|
103 |
"Error al tratar de chequear si la capa de recorte es de pol?gonos"); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
public void process() throws GeoprocessException { |
|
108 |
// TODO Auto-generated method stub |
|
109 |
Geometry clippingGeometry = null; |
|
110 |
try { |
|
111 |
clippingGeometry = computeJtsClippingPoly(); |
|
112 |
} catch (Exception e) { |
|
113 |
throw new GeoprocessException( |
|
114 |
"Error calculando el convex hull de la clipping layer"); |
|
115 |
} |
|
116 |
visitor = new ClipVisitor(clippingGeometry, resultLayerDefinition, |
|
117 |
schemaManager, writer); |
|
118 |
Strategy strategy = StrategyManager.getStrategy(firstLayer); |
|
119 |
try { |
|
120 |
if (onlyFirstLayerSelection) { |
|
121 |
strategy.process(visitor, firstLayer.getRecordset() |
|
122 |
.getSelection()); |
|
123 |
} else { |
|
124 |
strategy.process(visitor); |
|
125 |
} |
|
126 |
} catch (Exception e) { |
|
127 |
throw new GeoprocessException( |
|
128 |
"Problemas al leer los datos de la capa a clipear"); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
public ILayerDefinition createLayerDefinition() { |
|
133 |
|
|
134 |
/*LayerDescription descripLayer = new LayerDescription( |
|
135 |
resultLayerDefinition, firstWN, description); |
|
136 |
resultLayerDefinition = descripLayer.lyrDescrip();*/ |
|
137 |
return resultLayerDefinition; |
|
138 |
|
|
139 |
} |
|
140 |
|
|
141 |
public void setSecondOperand(FLyrVect secondLayer) { |
|
142 |
// TODO Auto-generated method stub |
|
143 |
this.auxLayer = secondLayer; |
|
144 |
} |
|
145 |
|
|
146 |
public void setFirstOperand(FLyrVect lyr) { |
|
147 |
// TODO Auto-generated method stub |
|
148 |
this.firstLayer = lyr; |
|
149 |
} |
|
150 |
|
|
151 |
public IMonitorableTask createTask() { |
|
152 |
final CancellableMonitorable cancelMonitor = createCancelMonitor(); |
|
153 |
|
|
154 |
return new IMonitorableTask() { |
|
155 |
String CLIP_GEOP_MSG = PluginServices.getText(this, "Mensaje_clip"); |
|
156 |
|
|
157 |
String CLIP_MESSAGE = PluginServices.getText(this, |
|
158 |
"Mensaje_procesando_clip_primero"); |
|
159 |
|
|
160 |
String INTERS_MESSAGE = PluginServices.getText(this, |
|
161 |
"Mensaje_procesando_clip_segundo"); |
|
162 |
|
|
163 |
String of = PluginServices.getText(this, "De"); |
|
164 |
|
|
165 |
String currentMsg = CLIP_MESSAGE; |
|
166 |
|
|
167 |
private boolean finished = false; |
|
168 |
|
|
169 |
public int getInitialStep() { |
|
170 |
return cancelMonitor.getInitialStep(); |
|
171 |
} |
|
172 |
|
|
173 |
public int getFinishStep() { |
|
174 |
return cancelMonitor.getFinalStep(); |
|
175 |
} |
|
176 |
|
|
177 |
public int getCurrentStep() { |
|
178 |
return cancelMonitor.getCurrentStep(); |
|
179 |
} |
|
180 |
|
|
181 |
public String getStatusMessage() { |
|
182 |
return CLIP_GEOP_MSG; |
|
183 |
} |
|
184 |
|
|
185 |
public String getNote() { |
|
186 |
return currentMsg + " " + getCurrentStep() + " " + of + " " |
|
187 |
+ getFinishStep(); |
|
188 |
} |
|
189 |
|
|
190 |
public void cancel() { |
|
191 |
((DefaultCancellableMonitorable) cancelMonitor) |
|
192 |
.setCanceled(true); |
|
193 |
ClipProcess.this.cancel(); |
|
194 |
} |
|
195 |
|
|
196 |
public void run() { |
|
197 |
|
|
198 |
Geometry clippingGeometry = null; |
|
199 |
try { |
|
200 |
clippingGeometry = computeJtsClippingPoly(); |
|
201 |
} catch (Exception e) { |
|
202 |
e.printStackTrace(); |
|
203 |
} |
|
204 |
currentMsg = INTERS_MESSAGE; |
|
205 |
visitor = new ClipVisitor(clippingGeometry, |
|
206 |
resultLayerDefinition, schemaManager, writer); |
|
207 |
Strategy strategy = StrategyManager.getStrategy(firstLayer); |
|
208 |
Rectangle2D clippingRect = FConverter |
|
209 |
.convertEnvelopeToRectangle2D(clippingGeometry |
|
210 |
.getEnvelopeInternal()); |
|
211 |
try { |
|
212 |
if (bitset!=null){ |
|
213 |
visitor.setSelection(bitset); |
|
214 |
} |
|
215 |
strategy.process(visitor, clippingRect, cancelMonitor); |
|
216 |
|
|
217 |
} catch (Exception e) { |
|
218 |
e.printStackTrace(); |
|
219 |
} |
|
220 |
finished = true; |
|
221 |
} |
|
222 |
|
|
223 |
public boolean isDefined() { |
|
224 |
return cancelMonitor.isDeterminatedProcess(); |
|
225 |
} |
|
226 |
|
|
227 |
public boolean isCanceled() { |
|
228 |
return cancelMonitor.isCanceled(); |
|
229 |
} |
|
230 |
|
|
231 |
public boolean isFinished() { |
|
232 |
return finished; |
|
233 |
} |
|
234 |
}; |
|
235 |
} |
|
236 |
|
|
237 |
private Geometry computeJtsClippingPoly() |
|
238 |
throws com.iver.cit.gvsig.fmap.DriverException, VisitException { |
|
239 |
|
|
240 |
ScalableUnionVisitor visitor = new ScalableUnionVisitor(); |
|
241 |
|
|
242 |
Strategy strategy = StrategyManager.getStrategy(auxLayer); |
|
243 |
if (onlyClipLayerSelection) { |
|
244 |
strategy.process(visitor, auxLayer.getRecordset().getSelection()); |
|
245 |
} else { |
|
246 |
strategy.process(visitor); |
|
247 |
} |
|
248 |
return visitor.getJtsConvexHull(); |
|
249 |
} |
|
250 |
|
|
251 |
public void setResultLayerProperties(IWriter writer, |
|
252 |
ISchemaManager schemaManager) { |
|
253 |
this.writer = writer; |
|
254 |
this.schemaManager = schemaManager; |
|
255 |
|
|
256 |
} |
|
257 |
|
|
258 |
private DefaultCancellableMonitorable createCancelMonitor() { |
|
259 |
DefaultCancellableMonitorable monitor = new DefaultCancellableMonitorable(); |
|
260 |
monitor.setInitialStep(0); |
|
261 |
monitor.setDeterminatedProcess(true); |
|
262 |
int clipSteps = 0; |
|
263 |
try { |
|
264 |
if (onlyClipLayerSelection) { |
|
265 |
FBitSet selection = auxLayer.getRecordset().getSelection(); |
|
266 |
clipSteps = selection.cardinality(); |
|
267 |
} else { |
|
268 |
clipSteps = auxLayer.getSource().getShapeCount(); |
|
269 |
|
|
270 |
} |
|
271 |
int firstSteps = 0; |
|
272 |
if (onlyFirstLayerSelection) { |
|
273 |
FBitSet selection = firstLayer.getRecordset().getSelection(); |
|
274 |
firstSteps = selection.cardinality(); |
|
275 |
} else { |
|
276 |
firstSteps = firstLayer.getSource().getShapeCount(); |
|
277 |
|
|
278 |
} |
|
279 |
int totalSteps = clipSteps + firstSteps; |
|
280 |
monitor.setFinalStep(totalSteps); |
|
281 |
} catch (DriverException e) { |
|
282 |
// TODO Auto-generated catch block |
|
283 |
e.printStackTrace(); |
|
284 |
} catch (DriverIOException e) { |
|
285 |
// TODO Auto-generated catch block |
|
286 |
e.printStackTrace(); |
|
287 |
} |
|
288 |
return monitor; |
|
289 |
} |
|
290 |
|
|
291 |
public ILayerDefinition getResultLayerDefinition() { |
|
292 |
return resultLayerDefinition; |
|
293 |
} |
|
294 |
|
|
295 |
public void setResultLayerDefinition(ILayerDefinition resultLayerDefinition) { |
|
296 |
this.resultLayerDefinition = resultLayerDefinition; |
|
297 |
} |
|
298 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/layerexporters/clip/PostProcessMonitorableDecoratorMainFirst.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile.layerexporters.clip; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import javax.swing.JOptionPane; |
|
6 |
|
|
7 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
|
8 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
|
9 |
|
|
10 |
import es.prodevelop.gvsig.exportMobile.files.NewDir; |
|
11 |
|
|
12 |
public class PostProcessMonitorableDecoratorMainFirst extends |
|
13 |
MonitorableDecoratorMainFirst { |
|
14 |
|
|
15 |
|
|
16 |
private File tempFile, finalFile; |
|
17 |
|
|
18 |
public PostProcessMonitorableDecoratorMainFirst( |
|
19 |
IMonitorableTask mainTask, |
|
20 |
IMonitorableTask secondaryTask, |
|
21 |
File tmp, File finalf){ |
|
22 |
|
|
23 |
super(mainTask, secondaryTask); |
|
24 |
|
|
25 |
tempFile = tmp; |
|
26 |
finalFile = finalf; |
|
27 |
} |
|
28 |
|
|
29 |
private void postProcess() { |
|
30 |
|
|
31 |
NewDir.copyShpDbfShxTempToFinal(tempFile, finalFile); |
|
32 |
} |
|
33 |
|
|
34 |
public void run() throws Exception { |
|
35 |
super.run(); |
|
36 |
postProcess(); |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/layerexporters/RasterExporter.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile.layerexporters; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.FileOutputStream; |
|
7 |
|
|
8 |
import org.apache.log4j.Logger; |
|
9 |
|
|
10 |
import com.hardcode.driverManager.Driver; |
|
11 |
import com.iver.andami.PluginServices; |
|
12 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
13 |
import com.iver.cit.gvsig.fmap.drivers.raster.CmsRasterDriver; |
|
14 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
15 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
|
16 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
17 |
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
|
18 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
|
19 |
|
|
20 |
import es.prodevelop.gvsig.exportMobile.xml.XmlProjectTags; |
|
21 |
|
|
22 |
/** |
|
23 |
* Exportation subtask |
|
24 |
* Allows a raster layer to be exported |
|
25 |
* |
|
26 |
* @author jcarras |
|
27 |
* |
|
28 |
*/ |
|
29 |
public class RasterExporter extends ExporterSubTask{ |
|
30 |
|
|
31 |
private Logger logger = Logger.getLogger(RasterExporter.class.getClass()); |
|
32 |
private File outputdir; |
|
33 |
private static int INDX_PATH = 10; |
|
34 |
private FLyrRaster inLyrRast; |
|
35 |
|
|
36 |
/** |
|
37 |
* COnstructor with all the needed attributes |
|
38 |
* |
|
39 |
* @param parentProcess |
|
40 |
* @param layer |
|
41 |
* @param rect this parameter is not used currently |
|
42 |
* @param outputdir |
|
43 |
* @param xml |
|
44 |
*/ |
|
45 |
public RasterExporter(AbstractMonitorableTask parentProcess, FLayer layer, |
|
46 |
Rectangle2D rect, File outputdir, XmlBuilder xml) { |
|
47 |
super(parentProcess, layer, rect, xml); |
|
48 |
this.outputdir=outputdir; |
|
49 |
inLyrRast = (FLyrRaster)layer; |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
/** |
|
54 |
* Get old path file, and copy this file to a new file |
|
55 |
*/ |
|
56 |
public void export() { |
|
57 |
setNote(PluginServices.getText(this, "exporting_") + " " + inLayer.getName()); |
|
58 |
try { |
|
59 |
/*String pathLayer = inLayer.getXMLEntity().getXmlTag() |
|
60 |
.getProperty(INDX_PATH).getValue(); |
|
61 |
File oldFile = new File(pathLayer);*/ |
|
62 |
Driver driver = inLyrRast.getSource().getDriver(); |
|
63 |
if (driver instanceof CmsRasterDriver){ |
|
64 |
initXML(); |
|
65 |
CmsRasterDriver drR =(CmsRasterDriver)driver; |
|
66 |
File oldFile = drR.getFile(); |
|
67 |
if (oldFile.exists()) { |
|
68 |
File destFile = new File(outputdir + File.separator + oldFile.getName()); |
|
69 |
destFile = getFreeFile(destFile); |
|
70 |
File wldFile = findWldFile(oldFile); |
|
71 |
if (wldFile == null) { |
|
72 |
logger.warn("Did not find world file for: " + oldFile.getName()); |
|
73 |
} else { |
|
74 |
String newWldPath = destFile.getAbsolutePath(); |
|
75 |
newWldPath = newWldPath.substring(0, newWldPath.lastIndexOf(".")); |
|
76 |
File newWldFile = new File(newWldPath + ".wld"); |
|
77 |
copyFileToFile(wldFile, newWldFile, 5); |
|
78 |
} |
|
79 |
copyFileToFile(oldFile, destFile, 95); |
|
80 |
writeXML(inLayer.getName(), destFile.getName()); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
} catch (Exception e) { |
|
85 |
// TODO Auto-generated catch block |
|
86 |
e.printStackTrace(); |
|
87 |
} finally { |
|
88 |
closeXML(); |
|
89 |
reportToEnd(); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
|
|
94 |
/** |
|
95 |
* Searches the WLD file associated with the layer |
|
96 |
* |
|
97 |
* @param img_file |
|
98 |
* @return |
|
99 |
*/ |
|
100 |
private File findWldFile(File img_file) { |
|
101 |
|
|
102 |
String img_path = img_file.getAbsolutePath(); |
|
103 |
String img_name = img_file.getName(); |
|
104 |
|
|
105 |
int lastp = img_name.lastIndexOf("."); |
|
106 |
String img_name_no_ext = img_name.substring(0, lastp); |
|
107 |
|
|
108 |
String ext = img_path.substring(img_path.length() - 4, img_path.length()); |
|
109 |
File resp = null; |
|
110 |
|
|
111 |
if ((ext.compareToIgnoreCase(".jpg") == 0) || (ext.compareToIgnoreCase("jpeg") == 0)) { |
|
112 |
resp = new File(img_file.getParent() + File.separator + img_name_no_ext + ".jgw"); |
|
113 |
if (resp.exists()) return resp; |
|
114 |
resp = new File(img_file.getParent() + File.separator + img_name_no_ext + ".jpw"); |
|
115 |
if (resp.exists()) return resp; |
|
116 |
resp = new File(img_file.getParent() + File.separator + img_name_no_ext + ".jpgw"); |
|
117 |
if (resp.exists()) return resp; |
|
118 |
} |
|
119 |
|
|
120 |
if ((ext.compareToIgnoreCase(".tif") == 0) || (ext.compareToIgnoreCase("tiff") == 0)) { |
|
121 |
resp = new File(img_file.getParent() + File.separator + img_name_no_ext + ".tfw"); |
|
122 |
if (resp.exists()) return resp; |
|
123 |
} |
|
124 |
|
|
125 |
resp = new File(img_file.getParent() + File.separator + img_name_no_ext + ".wld"); |
|
126 |
if (resp.exists()) return resp; |
|
127 |
return null; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Copies the in file to the outdir directory |
|
132 |
* |
|
133 |
* @param in |
|
134 |
* @param outdir |
|
135 |
* @param numStepsToReport the copy will report this number of steps |
|
136 |
* @throws Exception |
|
137 |
*/ |
|
138 |
public void copyFileToDir(File in, File outdir, int numStepsToReport) throws Exception { |
|
139 |
|
|
140 |
File f = new File(outdir.getAbsolutePath() + File.separator + in.getName()); |
|
141 |
|
|
142 |
copyFileToFile(in, f, numStepsToReport); |
|
143 |
} |
|
144 |
/** |
|
145 |
* Copies the in file data to the outFile file |
|
146 |
* |
|
147 |
* @param in |
|
148 |
* @param outFile |
|
149 |
* @param numStepsToReport the copy will report this number of steps |
|
150 |
* @throws Exception |
|
151 |
*/ |
|
152 |
public void copyFileToFile(File in, File outFile, int numStepsToReport) throws Exception { |
|
153 |
|
|
154 |
File f = outFile; |
|
155 |
|
|
156 |
long flenght = in.length(); |
|
157 |
int currStep = 0; |
|
158 |
long bytesPerStep = flenght / numStepsToReport; |
|
159 |
long bytesCopied = 0; |
|
160 |
|
|
161 |
FileInputStream fis = new FileInputStream(in); |
|
162 |
FileOutputStream fos = new FileOutputStream(f); |
|
163 |
byte[] buf = new byte[1024]; |
|
164 |
int i = 0; |
|
165 |
while ((i = fis.read(buf)) != -1) { |
|
166 |
fos.write(buf, 0, i); |
|
167 |
bytesCopied+=i; |
|
168 |
int newStep = (int)(bytesCopied / bytesPerStep); |
|
169 |
if (newStep>currStep){ |
|
170 |
reportSteps(newStep-currStep); |
|
171 |
currStep=newStep; |
|
172 |
} |
|
173 |
} |
|
174 |
fis.close(); |
|
175 |
fos.close(); |
|
176 |
} |
|
177 |
|
|
178 |
|
|
179 |
/** |
|
180 |
* Number of steps this subtask report |
|
181 |
*/ |
|
182 |
public int getFinalStep() { |
|
183 |
return 100; |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
/** |
|
188 |
* runs the exportation |
|
189 |
*/ |
|
190 |
public void run() { |
|
191 |
export(); |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Writes the layer attributes on the gvsig mobile xml project file |
|
196 |
* |
|
197 |
* @param name |
|
198 |
* @param path |
|
199 |
*/ |
|
200 |
private void writeXML(String name, String path){ |
|
201 |
//<Type> |
|
202 |
xml.writeTag(XmlProjectTags.TYPE, "RASTER"); |
|
203 |
//</Type> |
|
204 |
|
|
205 |
//<Path> |
|
206 |
xml.writeTag(XmlProjectTags.PATH, path); |
|
207 |
//</Path> |
|
208 |
|
|
209 |
//<Name> |
|
210 |
xml.writeTag(XmlProjectTags.NAME, name); |
|
211 |
//</Name> |
|
212 |
} |
|
213 |
|
|
214 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/layerexporters/WMSExporter.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile.layerexporters; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
|
|
5 |
import com.iver.andami.PluginServices; |
|
6 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
7 |
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
|
8 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
|
9 |
|
|
10 |
import es.prodevelop.gvsig.exportMobile.xml.XMLwms; |
|
11 |
|
|
12 |
/** |
|
13 |
* Exports a gvsig wms layer to a gvsig mobile wms layer |
|
14 |
* @author Anabel Moreno |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class WMSExporter extends ExporterSubTask{ |
|
18 |
|
|
19 |
/** |
|
20 |
* Constructor with all the required attributes |
|
21 |
* @param parentProcess |
|
22 |
* @param layer |
|
23 |
* @param rect |
|
24 |
* @param xml |
|
25 |
*/ |
|
26 |
public WMSExporter(AbstractMonitorableTask parentProcess, FLayer layer, |
|
27 |
Rectangle2D rect, XmlBuilder xml) { |
|
28 |
super(parentProcess, layer, rect, xml); |
|
29 |
|
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* Adds to the xml the layer attributes |
|
35 |
*/ |
|
36 |
public void export(){ |
|
37 |
initXML(); |
|
38 |
setNote(PluginServices.getText(this, "exporting_") + " " + inLayer.getName()); |
|
39 |
XMLwms xmlwms = new XMLwms(); |
|
40 |
xmlwms.setxml(inLayer,xml); |
|
41 |
xmlwms.createXML(); |
|
42 |
reportToEnd(); |
|
43 |
closeXML(); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Number of steps the layer will report |
|
48 |
*/ |
|
49 |
public int getFinalStep() { |
|
50 |
return 100; |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Starts the exportation task |
|
55 |
*/ |
|
56 |
public void run() { |
|
57 |
export(); |
|
58 |
} |
|
59 |
} |
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/layerexporters/ExportProcess.java | ||
---|---|---|
1 |
package es.prodevelop.gvsig.exportMobile.layerexporters; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.io.BufferedWriter; |
|
5 |
import java.io.File; |
|
6 |
import java.io.FileOutputStream; |
|
7 |
import java.io.IOException; |
|
8 |
import java.io.OutputStream; |
|
9 |
import java.io.OutputStreamWriter; |
|
10 |
import java.util.ArrayList; |
|
11 |
|
|
12 |
import javax.swing.JOptionPane; |
|
13 |
|
|
14 |
import org.cresques.cts.IProjection; |
|
15 |
|
|
16 |
import com.iver.andami.PluginServices; |
|
17 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
18 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
19 |
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
|
20 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
|
21 |
|
|
22 |
import es.prodevelop.gvsig.exportMobile.xml.Bounds; |
|
23 |
import es.prodevelop.gvsig.exportMobile.xml.XmlProjectTags; |
|
24 |
/** |
|
25 |
* |
|
26 |
* This process executes a series of tasks |
|
27 |
* |
|
28 |
* @author jcarras |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class ExportProcess extends AbstractMonitorableTask{ |
|
32 |
private ArrayList tasks = new ArrayList(); |
|
33 |
private int numSteps=0; |
|
34 |
private XmlBuilder xml = new XmlBuilder(); |
|
35 |
private Rectangle2D rect; |
|
36 |
private String name; |
|
37 |
private IProjection projection; |
|
38 |
private String dirPath; |
|
39 |
public static String PROJECTEXTENSION = ".gvm"; |
|
40 |
|
|
41 |
|
|
42 |
/** |
|
43 |
* Constructor with all needed parameters |
|
44 |
* @param rectangle |
|
45 |
* @param name |
|
46 |
* @param dirPath |
|
47 |
* @param projection |
|
48 |
*/ |
|
49 |
public ExportProcess(Rectangle2D rectangle, String name, String dirPath, IProjection projection){ |
|
50 |
setRect(rectangle); |
|
51 |
setName(name); |
|
52 |
setProjection(projection); |
|
53 |
setDirPath(dirPath); |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Adds a ExporterSubTask task to the list of task to execute |
|
58 |
* The order the tasks are added is the order they will be executed |
|
59 |
* @param task |
|
60 |
*/ |
|
61 |
public void addTask(ExporterSubTask task){ |
|
62 |
tasks.add(task); |
|
63 |
numSteps+=task.getFinalStep(); |
Also available in: Unified diff