Revision 29887

View differences:

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/xml/XmlProjectTags.java
1
package es.prodevelop.gvsig.exportMobile.xml;
2

  
3

  
4
public class XmlProjectTags {
5

  
6
	private XmlProjectTags(){};
7
	
8
	public static final String PROJECT = "Project";
9
	public static final String B_BOX = "BoundingBox";
10
	public static final String X_MIN = "xMin";
11
	public static final String X_MAX = "xMax";
12
	public static final String Y_MIN = "yMin";
13
	public static final String Y_MAX = "yMax";
14
	public static final String NAME = "Name";
15
	public static final String VISIBLE = "Visible";
16
	public static final String SCALE_MAX = "ScaleMax";
17
	public static final String SCALE_MIN = "ScaleMin";
18
	public static final String LAYERS = "Layers";
19
	public static final String LAYER = "Layer";
20
	public static final String TYPE = "Type";
21
	public static final String PATH = "Path";
22
	public static final String STYLE = "Style";
23
	public static final String POINT_SYMBOL = "PointSymbol";
24
	public static final String LINE_SYMBOL = "LineSymbol";
25
	public static final String POLYGON_SYMBOL = "PolygonSymbol";
26
	public static final String COLOR = "Color";
27
	public static final String SIZE = "Size";
28
	public static final String FILL_COLOR = "FillColor";
29
	public static final String FILL = "Fill";
30
	public static final String WMSCONFIG = "WMSConfig";
31
	public static final String LAYER_NAME = "LayerName";
32
	public static final String URL = "URL";
33
	public static final String LAYERQUERY = "LayerQuery";
34
	// public static final String SRS = "SRS";
35
	public static final String IMAGE_FORMAT = "ImageFormat";
36
	public static final String TRANSPARENCY = "Transparency";
37
	public static final String WMSLAYERS = "WmsLayers";
38
	public static final String WSMSTYLES = "WmsStyles";
39
	public static final String CRS = "CRS";
40
	
41
	
42
}
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/xml/XMLlyr.java
1
package es.prodevelop.gvsig.exportMobile.xml;
2

  
3
import java.awt.BasicStroke;
4
import java.awt.Color;
5

  
6
import com.iver.cit.gvsig.fmap.DriverException;
7
import com.iver.cit.gvsig.fmap.core.FShape;
8
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
9
import com.iver.cit.gvsig.fmap.layers.FLayer;
10
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
11
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
12
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
13
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
14
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
15
import com.iver.utiles.StringUtilities;
16

  
17
/**
18
 * 
19
 * @author amoreno
20
 *
21
 */
22
public class XMLlyr {
23

  
24
	private FLayer layer;
25
	private String color;
26
	private String colorFill;
27
	private int size;
28
	private int fill;
29

  
30
	public  XMLlyr(){
31
		
32
	}
33
	
34
	public String getColor(){
35
		return this.color;
36
	}
37
	public int getSize(){
38
		return this.size;
39
	}
40
	public int getFill(){
41
		return this.fill;
42
	}
43
	public String getColorFill(){
44
		return this.colorFill;
45
	}
46
	
47
		
48
	public void createTextToXML(FLayer lyr, int shpType){
49
		
50
		layer = lyr;
51
		if(layer instanceof FLyrVect){
52
			
53
			FLyrVect layerV = (FLyrVect) layer;
54
			try {
55
				
56
				FSymbol symbol = null;
57
				if (shpType == FShape.LINE) {
58
					
59
					VectorialLegend vleg = (VectorialLegend)layerV.getLegend();
60
					if (vleg instanceof SingleSymbolLegend){
61
						symbol = (FSymbol)((SingleSymbolLegend)vleg).getDefaultSymbol();
62
					}
63
					//tomar de vectorialintervallegend y vectorialuniquevaluelegend el primer valor
64
					//como symbol, y luego de symbol obtener lo que necesitemos
65
					if(vleg instanceof VectorialIntervalLegend){
66
						
67
						symbol = (FSymbol)((VectorialIntervalLegend)vleg).getSymbol(0);
68
					}
69
					if(vleg instanceof VectorialUniqueValueLegend){
70
						
71
						symbol = (FSymbol)((VectorialUniqueValueLegend)vleg).getSymbol(0);
72
					}
73
					Color col=symbol.getColor();
74
					this.color = StringUtilities.color2String(col);
75
					
76
					// instead of symbol.getSize(), we have to use this:
77
					// jldominguez
78
					int stroke_width = Math.round(((BasicStroke) symbol.getStroke()).getLineWidth());
79
					this.size = stroke_width;
80
				}
81
				
82
				if(shpType == FShape.POINT){
83
					
84
					VectorialLegend vleg = (VectorialLegend)layerV.getLegend();
85
					if (vleg instanceof SingleSymbolLegend){
86
						symbol = (FSymbol)((SingleSymbolLegend)vleg).getDefaultSymbol();
87
					}
88
					//tomar de vectorialintervallegend y vectorialuniquevaluelegend el primer valor
89
					//como symbol, y luego de symbol obtener lo que necesitemos
90
					if(vleg instanceof VectorialIntervalLegend){
91
						
92
						symbol = (FSymbol)((VectorialIntervalLegend)vleg).getSymbol(0);
93
					}
94
					if(vleg instanceof VectorialUniqueValueLegend){
95
						
96
						symbol = (FSymbol)((VectorialUniqueValueLegend)vleg).getSymbol(0);
97
					}
98
					Color col=symbol.getColor();
99
					this.color = StringUtilities.color2String(col);
100
					
101
					// instead of symbol.getSize(), we have to use this:
102
					// jldominguez
103
					if (symbol.isSizeInPixels()) {
104
						size = symbol.getSize();
105
					} else {
106
						// TODO calcular el tamanyo en pixeles
107
						size = 3;
108
					}
109
				}
110
				
111
				
112
				if(shpType == FShape.POLYGON){
113
					
114
					VectorialLegend vleg = (VectorialLegend)layerV.getLegend();
115
					if (vleg instanceof SingleSymbolLegend){
116
						symbol = (FSymbol)((SingleSymbolLegend)vleg).getDefaultSymbol();
117
					}
118
					//tomar de vectorialintervallegend y vectorialuniquevaluelegend el primer valor
119
					//como symbol, y luego de symbol obtener lo que necesitemos
120
					if(vleg instanceof VectorialIntervalLegend){
121
						
122
						symbol = (FSymbol)((VectorialIntervalLegend)vleg).getSymbol(0);
123
					}
124
					if(vleg instanceof VectorialUniqueValueLegend){
125
						
126
						symbol = (FSymbol)((VectorialUniqueValueLegend)vleg).getSymbol(0);
127
					}
128
					Color colFill=symbol.getColor();
129
					
130
					
131
					// there was a np exception when polygons were not filled
132
					// jldominguez
133
					if (colFill == null) {
134
						this.colorFill = StringUtilities.color2String(Color.WHITE);
135
						fill = 0;
136
					} else {
137
						this.colorFill = StringUtilities.color2String(colFill);
138
						fill = 1;
139
					}
140

  
141
					// instead of symbol.getSize(), we have to use this:
142
					// jldominguez
143
					int stroke_width = Math.round(((BasicStroke) symbol.getStroke()).getLineWidth());
144
					this.size = stroke_width;
145

  
146
					Color col = symbol.getOutlineColor();
147
					
148
					// there was a np exception when polygons were not filled
149
					// jldominguez
150
					if (col == null) {
151
						this.color = StringUtilities.color2String(Color.BLACK);
152
					} else {
153
						this.color = StringUtilities.color2String(col);
154
					}
155

  
156
					/*
157
					int symboltype = symbol.getSymbolType();
158
					FConstant f = null;
159
					if(symboltype == f.SYMBOL_TYPE_FILL)
160
						this.fill=1;
161
					else
162
						this.fill=0;
163
						*/	
164
				}
165
			} catch (IndexOutOfBoundsException e) {
166
				e.printStackTrace();
167
			} catch (DriverException e) {
168
				e.printStackTrace();
169
			}
170
		}		
171
	}	
172
}
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/xml/XMLwms.java
1
package es.prodevelop.gvsig.exportMobile.xml;
2

  
3

  
4
import com.iver.cit.gvsig.fmap.layers.FLayer;
5
import com.iver.cit.gvsig.fmap.layers.XMLException;
6
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
7
import com.iver.utiles.xmlEntity.generate.Property;
8

  
9
/**
10
 * get wms layer properties and create its xml project
11
 * @author Anabel Moreno
12
 *
13
 */
14
public class XMLwms implements XMLgetter{
15

  
16
	private static int NAME = 2;
17
	
18
	private static int URL = 10;
19
	
20
	private static int LAYERQUERY = 12;
21
	
22
	private static int CAPLAYERSTYLES = 21;
23
	
24
	private static int CRS = 14;
25
	
26
	private static int IMAGEFORMAT = 13;
27
	
28
	private static int TRANSPARENCY = 6;
29
	
30
	XmlBuilder xml;
31
	
32
	private FLayer layerWMS;
33
	
34
	public void setxml(FLayer layerwn,XmlBuilder xml_builder){
35
		
36
		this.layerWMS = layerwn;
37
		this.xml = xml_builder;
38
	}
39
				
40
	public void createXML(){
41
		
42
		Property[] pr;
43
		try {
44
			pr = layerWMS.getXMLEntity().getXmlTag().getProperty();
45
			//<WMSCONFIG>
46
			//xml.openTag(XmlProjectTags.WMSCONFIG);
47
				xml.writeTag(XmlProjectTags.TYPE, "WMS");
48
				//<LAYERNAME>
49
				xml.writeTag(XmlProjectTags.NAME, layerWMS.getName());
50
				//</LAYERNAME>
51
				
52
				//<URL>
53
				xml.writeTag(XmlProjectTags.URL,pr[URL].getValue());
54
				//</URL>
55
				
56
				//<LAYERQUERY>
57
				//xml.openTag(XmlProjectTags.LAYERQUERY);
58
					
59
					//<NAME>
60
					xml.writeTag(XmlProjectTags.WMSLAYERS, pr[LAYERQUERY].getValue());
61
					//</NAME>
62
						
63
					//<STYLE>
64
					xml.writeTag(XmlProjectTags.WSMSTYLES,pr[CAPLAYERSTYLES].getValue());
65
					//</STYLE>
66
						
67
				//xml.closeTag();
68
				//</LAYERQUERY>
69
				
70
				
71
				//<SRS>
72
				xml.writeTag(XmlProjectTags.CRS, pr[CRS].getValue());
73
				//</SRS>
74
				
75
				//<IMAGEFORMAT>
76
				xml.writeTag(XmlProjectTags.IMAGE_FORMAT, pr[IMAGEFORMAT].getValue());
77
				//</IMAGEFORMAT>
78
				
79
				//<TRANSPARENCY>
80
				xml.writeTag(XmlProjectTags.TRANSPARENCY,pr[TRANSPARENCY].getValue());
81
				//</TRANSPARENCY>
82
				
83
			//xml.closeTag();
84
			//</WMSCONFIG>
85
			
86
		} catch (XMLException e) {
87
			// TODO Auto-generated catch block
88
			e.printStackTrace();
89
		}
90
	}
91
}
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/xml/Bounds.java
1
package es.prodevelop.gvsig.exportMobile.xml;
2

  
3
import java.awt.geom.Rectangle2D;
4
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
5

  
6
/**
7
 * Get bounds of view and create new tags to the xml project
8
 * @author Anabel Moreno
9
 *
10
 */
11
public class Bounds extends Rectangle2D.Double implements XMLgetter {
12
	public static final String tag = "bounds";
13
	
14
	public XmlBuilder xml;
15
	
16
	public static Bounds createBounds(Rectangle2D rect){
17
		Bounds bounds = new Bounds();
18
		bounds.setRect(rect);
19
		return bounds;
20
	}
21
	
22
	public void setXML(XmlBuilder xml_builder){
23
		
24
		this.xml = xml_builder;
25
	}
26
	
27
	public void createXML(){
28
		
29
		//<Bounds>
30
		xml.openTag(XmlProjectTags.B_BOX);
31
		
32
			//<xMin>
33
			xml.writeTag(XmlProjectTags.X_MIN,java.lang.Double.toString(this.getMinX()));
34
			//</xMin>
35
			
36
			//<xMax>
37
			xml.writeTag(XmlProjectTags.X_MAX,java.lang.Double.toString(this.getMaxX()));
38
			//</xMax>
39
			
40
			//<yMin>
41
			xml.writeTag(XmlProjectTags.Y_MIN,java.lang.Double.toString(this.getMinY()));
42
			//</yMin>
43
			
44
			//<yMax>
45
			xml.writeTag(XmlProjectTags.Y_MAX,java.lang.Double.toString(this.getMaxY()));
46
			//</yMax>
47
			
48
		xml.closeTag();
49
		//</Bounds>
50
	}
51
	
52
}
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/xml/XMLgetter.java
1
package es.prodevelop.gvsig.exportMobile.xml;
2

  
3
public interface XMLgetter {
4
	void createXML();
5
}
tags/tmp_build/prototypes/mobile/desktop/extensions/extExportMobile/src/es/prodevelop/gvsig/exportMobile/xml/Style.java
1

  
2
package es.prodevelop.gvsig.exportMobile.xml;
3

  
4
import com.iver.cit.gvsig.fmap.core.FShape;
5
import com.iver.cit.gvsig.fmap.layers.FLayer;
6
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
7
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
8

  
9
/**
10
 * Get style of a layer, and create a new tag
11
 * @author Anabel Moreno
12
 *
13
 */
14

  
15
public class Style implements XMLgetter{
16

  
17
	FLayer lyr;
18
	String color;
19
	String colorFill;
20
	int size;
21
	int fill;
22
	XmlBuilder xml;
23
	int shpType;
24
	
25
	public void setXML(XmlBuilder xml_builder){
26
		
27
		this.xml = xml_builder;
28
	}
29
	
30
	public void setLayer(FLayer layer, int shpType){
31
		this.lyr = layer;
32
		this.shpType=shpType;
33
	}
34
	
35
	
36
	public void createXML(){
37
		
38
		XMLlyr xmlyr = new XMLlyr();
39
		xmlyr.createTextToXML(lyr, shpType);
40
		FLyrVect lyrV = (FLyrVect) lyr;
41
		
42
		//<Style>
43
		xml.openTag(XmlProjectTags.STYLE);
44
		
45
		//try {
46
			
47
			if(shpType == FShape.POINT){
48
				
49
				//<PointSymbol>
50
				xml.openTag(XmlProjectTags.POINT_SYMBOL);
51
				
52
					//<Color>
53
					xml.writeTag(XmlProjectTags.COLOR, xmlyr.getColor());
54
					//</Color>
55
					
56
					//<Size>
57
					xml.writeTag(XmlProjectTags.SIZE, java.lang.Integer.toString(xmlyr.getSize()));
58
					//</Size>
59
					
60
				xml.closeTag();
61
				//</PointSymbol>
62
				
63
			}
64
			if(shpType == FShape.LINE){
65
				
66
				//<LineSymbol>
67
				xml.openTag(XmlProjectTags.LINE_SYMBOL);
68
				
69
					//<Color>
70
					xml.writeTag(XmlProjectTags.COLOR, xmlyr.getColor());
71
					//</Color>
72
					
73
					//<Size>
74
					xml.writeTag(XmlProjectTags.SIZE, java.lang.Integer.toString(xmlyr.getSize()));
75
					//</Size>
76
					
77
				xml.closeTag();
78
				//</LineSymbol>
79
				
80
			}
81
			
82
			
83
			if(shpType == FShape.POLYGON){
84
				
85
				//<PoligonSymbol>
86
				xml.openTag(XmlProjectTags.POLYGON_SYMBOL);
87
				
88
					//<LineSymbol>
89
					xml.openTag(XmlProjectTags.LINE_SYMBOL);
90
					
91
						//<Color>
92
						xml.writeTag(XmlProjectTags.COLOR, xmlyr.getColor());
93
						//</Color>
94
						
95
						//<Size>
96
						xml.writeTag(XmlProjectTags.SIZE, java.lang.Integer.toString(xmlyr.getSize()));
97
						//</Size>
98
						
99
					xml.closeTag();
100
					//</LineSymbol>
101
				
102
					//<FillColor>
103
					xml.writeTag(XmlProjectTags.FILL_COLOR, xmlyr.getColorFill());
104
					//</FillColor>
105
					
106
					//<Fill>
107
					xml.writeTag(XmlProjectTags.FILL, java.lang.Integer.toString(xmlyr.getFill()));
108
					//</FillColor>
109
				xml.closeTag();
110
				//</PoligonSymbol>
111
							
112
			}
113
		/*} catch (DriverException e) {
114
			// TODO Auto-generated catch block
115
			e.printStackTrace();
116
		}*/
117
			
118
		
119
		xml.closeTag();
120
		//</Style>
121

  
122
		
123
	}
124
}
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/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();
64
	}
65
	
66
	/**
67
	 * Creates a VectorialExporterTask and adds it to the list of tasks to execute
68
	 * @param lyr
69
	 * @param outputFields
70
	 * @param processType
71
	 */
72
	public void addVectorialTask(FLayer lyr, FieldDescription[] outputFields, int processType){
73
		VectorialExporterTask task = new VectorialExporterTask(this,
74
				lyr,
75
				getRect(),
76
				dirPath,
77
				processType,
78
				outputFields,
79
				xml);
80
		addTask(task);
81
	}
82
	
83
	/**
84
	 * Creates a RasterExporter task and adds it to the list of tasks to execute
85
	 * @param lyr
86
	 */
87
	public void addRasterTask(FLayer lyr){
88
		RasterExporter task = new RasterExporter(this,lyr,rect, new File(dirPath),xml);
89
		addTask(task);
90
	}
91
	
92
	/**
93
	 * Creates a WMSExporter task and adds it to the list of tasks to execute
94
	 * @param lyr
95
	 */
96
	public void addWMSTask(FLayer lyr){
97
		WMSExporter task = new WMSExporter(this,lyr,getRect(),xml);
98
		addTask(task);
99
	}
100
	
101
	/**
102
	 * Closes the oppened xml tags and stores the project file
103
	 */
104
	private void writeProjectFile(){
105
		// done
106
		
107
		xml.closeTag();
108
		//</Layers>
109
				
110
		xml.closeTag();
111
		//</Project>
112
		
113
		//new file
114
		File fileout = new File(dirPath+ File.separator + name + PROJECTEXTENSION);
115
		createFile(fileout,xml.getXML());
116
	}
117
	
118
	/**
119
	 * Starts the xml to be ready for pushing the layers into
120
	 */
121
	private void initProjectFile(){
122
		xml.writeHeader();
123
		//<Project>
124
		xml.openTag(XmlProjectTags.PROJECT);
125
		Bounds bounds = Bounds.createBounds(rect);
126
			
127
			//<BoundingBox>
128
			bounds.setXML(xml);
129
			bounds.createXML();
130
			//</BoundingBox>
131
			
132
			//<Name>
133
			xml.writeTag(XmlProjectTags.NAME, name);
134
			//<Name>
135
			
136
			//<CRS>
137
			String crsProyect = getProjection().getAbrev();
138
			xml.writeTag(XmlProjectTags.CRS, crsProyect);
139
			//</CRS>
140
			
141
			//<Layers>
142
			xml.openTag(XmlProjectTags.LAYERS);
143
	}
144

  
145
	/**
146
	 * To be executed before running this
147
	 */
148
	public void preProcess(){
149
		setInitialStep(0);
150
		this.setFinalStep(numSteps);
151
		setDeterminatedProcess(true);
152
	}
153
	
154
	/**
155
	 * Executes all the tasks in the list, creates the project file and 
156
	 * reports the steps not reported yet
157
	 */
158
	public void run() throws Exception {
159
		
160
		initProjectFile();
161
		for (int i=0; i<tasks.size(); i++){
162
			ExporterSubTask task = (ExporterSubTask)tasks.get(i);
163
			if (!isCanceled()){
164
				task.run();
165
			}else{
166
				task.setCancelled(true);
167
			}
168
		}
169
		setNote("Generating project file");
170
		writeProjectFile();
171
		JOptionPane.showMessageDialog(null,
172
				PluginServices.getText(this, "export_done") + "\n" + dirPath,
173
				PluginServices.getText(this, "exporMob"),
174
				JOptionPane.INFORMATION_MESSAGE);
175
		
176
		reportToEnd();
177
	}
178

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff