Revision 1733

View differences:

branches/CqCMSDvp/libraries/libCq CMS for java.old/javadoc.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project default="javadoc">
3
    <target name="javadoc">
4
        <javadoc destdir="doc" access="package" source="1.4" use="true" notree="false" nonavbar="false" noindex="false" splitindex="true" author="true" version="true" nodeprecatedlist="false" nodeprecated="false" packagenames="org.cresques.cts.gt2,org.cresques.io,org.cresques.geo.cover,org.cresques.ui,org.cresques.geo,org.cresques.cts,org.cresques.ui.cmd,org.cresques.px.gml,org.cresques.px.dxf,org.cresques.px" sourcepath="src" classpath="lib/jmgeoraster.jar;lib/geojava.jar;bin;C:\java\lib\ermapper.jar;lib/gt2cts.jar" overview="C:\eclipse\workspace\Cq CMS for Java\doc-files\overview.html" doctitle="Cresques Mapping Suite for Java v0.1">
5
            <link href="file:/C:/j2sdk1.4.2_03/docs/api/"/>
6
            <link href="jar:file:/C:/java/lib/ermapperdoc.jar!/Javadoc"/>
7
        </javadoc>
8
    </target>
9
</project>
0 10

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/.cvsignore
1
*.dfPackage
2
*.wmf
0 3

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/DataSource.java
1
/*
2
 * Created on 12-may-2004
3
 */
4

  
5
package org.cresques.io;
6

  
7
import java.util.Hashtable;
8

  
9
/**
10
 * Origen de datos. Unidad, volumen de red, etc.
11
 * 
12
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
13
 */
14

  
15
public class DataSource {
16
	private static int counter = 0;
17
	private static Hashtable units = new Hashtable();
18
	String path = null;
19
	String name = null;
20

  
21
	public DataSource(String path, String name) {
22
		this.path = path;
23
		this.name = name;
24
		units.put(name, this);
25
	}
26
	
27
	public String getName() { return name; }
28
	public String getPath() { return path; }
29
	
30
	public static DataSource getDSFromName(String name) {
31
		if (name.indexOf("[") >= 0) name = name.substring(name.indexOf("[")+1);
32
		if (name.indexOf("]") >= 0) name = name.substring(0,name.indexOf("]"));
33
		DataSource ds = (DataSource) units.get(name);
34
		return ds;
35
	}
36
	
37
	/**
38
	 * Sustituye en el path el nombre de la unidad por su path real.
39
	 * 
40
	 * @param path
41
	 * @return
42
	 */
43
	public static String normalize(String path) {
44
		if (path.indexOf("[") >= 0) {
45
			DataSource ds = DataSource.getDSFromName(path);
46
			if (ds == null) return null;
47
			path = path.substring(0,path.indexOf("[")) + 
48
				ds.getPath() + path.substring(path.indexOf("]")+1);
49
			//System.out.println(path);
50
		}
51
		return path;
52
	}
53
	
54
	public String toString() {
55
		return "["+counter+"]";
56
	}
57
}
0 58

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/ShpFile.java
1
/*
2
 * Created on 03-may-2004
3
 *
4
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
5
 */
6
 
7
package org.cresques.io;
8

  
9
import java.io.FileInputStream;
10
import java.io.FileNotFoundException;
11
import java.io.IOException;
12
import java.io.InputStream;
13
import java.nio.MappedByteBuffer;
14
import java.nio.channels.FileChannel;
15

  
16
import org.cresques.cts.ICoordTrans;
17
import org.cresques.cts.IProjection;
18
import org.cresques.px.IObjList;
19
import org.cresques.px.gml.*;
20

  
21
/**
22
 * Clase de soporte para ficheros .shp de ArcView
23
 * 
24
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
25
 * TODO extension .shp sin implementar
26
 */
27

  
28
public class ShpFile extends GeoFile {
29
	private String name;	
30
	int l = 0;
31
	FeatureCollection collection = null;
32

  
33
	/**
34
	 * Constructor de la clase Shp
35
	 *
36
	 */
37
	
38
	public ShpFile(IProjection proj, String name) {
39
		super(proj, name);
40
	}
41

  
42
	/**
43
	 * Carga un .gml
44
	 * @param name nombre del fichero
45
	 */
46
	
47
	public GeoFile load() {
48
		System.out.println("Cargando "+name+" ...");
49
		try {
50
			if (FileFolder.isUrl(name)) {
51
				ZipFileFolder zFolder = new ZipFileFolder(name);
52
				return load(zFolder.getInputStream(name));
53
			} else 
54
				return load(new FileInputStream(name));
55
		} catch (FileNotFoundException e) {
56
			e.printStackTrace();
57
		} catch (IOException ie) {
58
			System.err.println("ERROR."+l+"lineas leidas");
59
			ie.printStackTrace();
60
		}
61
		return this;
62
	}
63
	
64
	public int openLayer() {
65
		String m_Path = null;
66
		try {		
67
			FileInputStream fin = new FileInputStream(m_Path);
68
			// Open the file and then get a channel from the stream
69
			FileChannel fc = fin.getChannel();			
70
			long sz = fc.size();
71
			// Get the file's size and then map it into memory
72
			MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
73
		}
74
		catch(Exception e)
75
		{
76
			System.err.notify();
77
		}
78
		return 0;
79
	}
80
	
81
	public GeoFile load(InputStream is) {
82
		// create a new header.
83
		ShpFileHeader myHeader = new ShpFileHeader();
84
	
85
		// read the header
86
		//myHeader.readHeader(fr);
87
		return this;
88
	}
89
	
90
	/**
91
	 * Obtiene la lista de features.
92
	 */
93
	
94
	public IObjList getObjects() {
95
		return collection;
96
	}
97
	
98
	public void reProject(ICoordTrans rp) {
99
		// TODO metodo reProject pendiente de implementar
100
	}
101

  
102
	/* (non-Javadoc)
103
	 * @see org.cresques.io.GeoFile#close()
104
	 */
105
	public void close() {
106
		// TODO Auto-generated method stub
107
		
108
	}
109
}
0 110

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/GeoRasterFile.java
1
/*
2
 * Created on 26-abr-2004
3
 *
4
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
5
 */
6
package org.cresques.io;
7

  
8
import java.awt.Component;
9
import java.awt.Dimension;
10
import java.awt.Image;
11
import java.awt.geom.Point2D;
12
import java.awt.image.DataBuffer;
13
import java.io.FileWriter;
14
import java.io.IOException;
15
import java.lang.reflect.Constructor;
16
import java.lang.reflect.InvocationTargetException;
17
import java.util.TreeMap;
18

  
19
import org.cresques.cts.ICoordTrans;
20
import org.cresques.cts.IProjection;
21
import org.cresques.io.raster.PixelFilter;
22
import org.cresques.io.raster.SimplePixelFilter;
23
import org.cresques.px.Extent;
24
import org.cresques.px.IObjList;
25
import org.cresques.px.PxContour;
26
import org.cresques.px.PxObjList;
27

  
28
/**
29
 * Manejador de ficheros raster georeferenciados.
30
 * 
31
 * Esta clase abstracta es el ancestro de todas las clases que proporcionan
32
 * soporte para ficheros raster georeferenciados.<br>
33
 * Actua tambien como una 'Fabrica', ocultando al cliente la manera en que
34
 * se ha implementado ese manejo. Una clase nueva que soportara un nuevo
35
 * tipo de raster tendr?a que registrar su extensi?n o extensiones usando
36
 * el m?todo @see registerExtension.<br> 
37
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>*
38
 */
39

  
40
public abstract class GeoRasterFile extends GeoFile {
41
	public static final int RED_BAND	= 0x01;
42
	public static final int GREEN_BAND	= 0x02;
43
	public static final int BLUE_BAND	= 0x04;
44

  
45
	/**
46
	 * Filtro para raster.
47
	 * Permite eliminar la franja inutil alrededor de un raster girado o de
48
	 * un mosaico de borde irregular.
49
	 * 
50
	 * Funciona bien solo con raster en tonos de gris, porque se basa que
51
	 * el valor del pixel no supere un determinado valor 'umbral' que se
52
	 * le pasa al constructor.
53
	 * 
54
	 * Desarrollado para 'limpiar' los bordes de los mosaicos del SIG
55
	 * Oleicola. Para ese caso los par?metros del constructo son:
56
	 * PixelFilter(0x10ffff00, 0xff000000, 0xf0f0f0);
57
	 * 
58
	 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
59
	 */
60

  
61
	
62
	private static TreeMap supportedExtensions = null;
63
	protected Component updatable = null;
64
	protected boolean doTransparency = false;
65
	//protected int alpha = 0;
66
	protected PixelFilter tFilter = null;
67

  
68
	protected int rBandNr = 1, gBandNr = 1, bBandNr = 1;
69
	protected int bandCount = 1;
70
	private int dataType = DataBuffer.TYPE_BYTE;
71

  
72
	static {
73
		supportedExtensions = new TreeMap();
74
		//if (System.getProperty("os.name").toUpperCase().startsWith("WIN")) {
75
			supportedExtensions.put("ecw",  EcwFile.class);
76
		//}
77
		supportedExtensions.put("tif",  TifGeoRefFile.class);
78
		supportedExtensions.put("tiff", TifGeoRefFile.class);
79
		supportedExtensions.put("jpg",  TifGeoRefFile.class);
80
		supportedExtensions.put("png",  TifGeoRefFile.class);
81
		supportedExtensions.put("sid",  MrSidFile.class);
82
	}
83
	
84
	/**
85
	 * Factoria para abrir distintos tipos de raster.
86
	 * 
87
	 * @param proj Proyecci?n en la que est? el raster.
88
	 * @param fName Nombre del fichero.
89
	 * @return GeoRasterFile, o null si hay problemas.
90
	 */
91
	public static GeoRasterFile openFile(IProjection proj, String fName) {
92
		String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1);
93
		GeoRasterFile grf = null;
94
		// TODO NotSupportedExtensionException
95
		if (!supportedExtensions.containsKey(ext)) return grf;
96
		/**/
97
		Class clase = (Class) supportedExtensions.get(ext);
98
		Class [] args = {IProjection.class, String.class};
99
		try {
100
			Constructor hazNuevo = clase.getConstructor(args);
101
			Object [] args2 = {proj, fName};
102
			grf = (GeoRasterFile) hazNuevo.newInstance(args2);
103
		} catch (SecurityException e) {
104
			// TODO Auto-generated catch block
105
			e.printStackTrace();
106
		} catch (NoSuchMethodException e) {
107
			// TODO Auto-generated catch block
108
			e.printStackTrace();
109
		} catch (IllegalArgumentException e) {
110
			// TODO Auto-generated catch block
111
			e.printStackTrace();
112
		} catch (InstantiationException e) {
113
			// TODO Auto-generated catch block
114
			e.printStackTrace();
115
		} catch (IllegalAccessException e) {
116
			// TODO Auto-generated catch block
117
			e.printStackTrace();
118
		} catch (InvocationTargetException e) {
119
			// TODO Auto-generated catch block
120
			e.printStackTrace();
121
		}/**/
122
 		
123
		/* * /
124
		if (ext.compareTo("ecw") == 0) {
125
			grf = new EcwFile(proj, fName);
126
		} else if (ext.compareTo("tif") == 0 || ext.compareTo("tiff") == 0 || ext.compareTo("jpg") == 0  || ext.compareTo("png") == 0 ) {
127
			grf = new TifGeoRefFile(proj, fName);
128
		}/ * */
129

  
130
		return grf;
131
	}
132
	
133
	/**
134
	 * Registra una clase que soporta una extensi?n raster.
135
	 * @param ext extensi?n soportada.
136
	 * @param clase clase que la soporta.
137
	 */
138
	public static void registerExtension(String ext, Class clase) {
139
		ext = ext.toLowerCase();
140
		System.out.println("RASTER: extension '"+ext+"' supported.");
141
		supportedExtensions.put(ext, clase);
142
	}
143
	
144
	/**
145
	 * Tipo de fichero soportado.
146
	 * Devuelve true si el tipo de fichero (extension) est? soportado, si no
147
	 * devuelve false.
148
	 * 
149
	 * @param fName Fichero raster
150
	 * @return  true si est? soportado, si no false.
151
 	 */
152
	public static boolean fileIsSupported(String fName) {
153
		String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1);
154
		return supportedExtensions.containsKey(ext);
155
	}
156
	
157
	public GeoRasterFile(IProjection proj, String name) {
158
		super(proj, name);
159
	}
160
	
161
	abstract public GeoFile load();
162
	
163
	abstract public void close();
164
	
165
	public static PxContour getContour(String fName, String name, IProjection proj) {
166
		PxContour contour = null;
167
		return contour;
168
	}
169
	
170
	abstract public int getWidth();
171
	abstract public int getHeight();
172

  
173
	abstract public void reProject(ICoordTrans rp);
174

  
175
	abstract public void setView(Extent e);
176
	abstract public Extent getView();
177
	
178
	// TRANSPARENCIA. Versi?n de pruebas. Hay que verificar que se puede
179
	// tener filtros y valores alpha, que no es lento, y que no hay una manera
180
	// mejor de hacerlo.
181
	//abstract public void setTransparency(boolean t);
182
	//abstract public void setTransparency(int t);
183
	public void setTransparency(boolean t) {
184
		doTransparency = t;
185
		tFilter = new PixelFilter(255);
186
	}
187
	public void setTransparency(int t ) {
188
		doTransparency = true;
189
		tFilter = new SimplePixelFilter(255 - t);
190
	}
191
	public boolean getTransparency() { return doTransparency; }
192
	public void setAlpha(int alpha) {
193
		if (!doTransparency) setTransparency(255 - alpha);
194
		else tFilter.setAlpha(alpha);
195
	}
196
	public int getAlpha() {
197
		if (tFilter == null)
198
			return 255;
199
		return tFilter.getAlpha();
200
	}
201
	
202
	public void setUpdatable(Component c) { updatable = c; }
203
	
204
	abstract public Image updateImage(int width, int height, ICoordTrans rp);
205

  
206
	/**
207
	 * Obtiene el valor del raster en la coordenada que se le pasa.
208
	 * El valor ser? Double, Int, Byte, etc. dependiendo del tipo de
209
	 * raster.
210
	 * @param x	coordenada X
211
	 * @param y coordenada Y
212
	 * @return
213
	 */
214
	abstract public Object getData(int x, int y, int band);
215

  
216
	/**
217
	 * Actualiza la/s banda/s especificadas en la imagen.
218
	 * @param width		ancho
219
	 * @param height	alto
220
	 * @param rp		reproyecci?n
221
	 * @param img		imagen
222
	 * @param flags		que bandas [ RED_BAND | GREEN_BAND | BLUE_BAND ]
223
	 * @return		img
224
	 */
225
	abstract public Image updateImage(int width, int height, ICoordTrans rp, Image img, int flags);
226

  
227
	public int getBandCount() { return bandCount; }
228
	
229
	/**
230
	 * Asocia un colorBand al rojo, verde o azul.
231
	 * @param flag cual (o cuales) de las bandas.
232
	 * @param nBand	que colorBand
233
	 */
234
	
235
	public void setBand(int flag, int bandNr) {
236
		if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) rBandNr = bandNr;
237
		if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) gBandNr = bandNr;
238
		if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) bBandNr = bandNr;
239
	}
240

  
241
	/**
242
	 * Devuelve el colorBand activo en la banda especificada.
243
	 * @param flag banda.
244
	 */
245
	
246
	public int getBand(int flag) {
247
		if (flag == GeoRasterFile.RED_BAND) return rBandNr;
248
		if (flag == GeoRasterFile.GREEN_BAND) return gBandNr;
249
		if (flag == GeoRasterFile.BLUE_BAND) return bBandNr;
250
		return -1;
251
	}
252
	
253
	/**
254
	 * @return Returns the dataType.
255
	 */
256
	public int getDataType() {
257
		return dataType;
258
	}
259
	/**
260
	 * @param dataType The dataType to set.
261
	 */
262
	public void setDataType(int dataType) {
263
		this.dataType = dataType;
264
	}
265

  
266
	public IObjList getObjects() {
267
		// TODO hay que a?adir el raster a la lista de objetos
268
		IObjList oList = new PxObjList(proj);
269
		return oList;
270
	}
271
	
272
	/**
273
	 * Calcula los par?metros de un worl file a partir de las esquinas del raster.
274
	 *    1. X pixel size A
275
	 *    2. X rotation term D
276
	 *    3. Y rotation term B
277
	 *    4. Y pixel size E
278
	 *    5. X coordinate of upper left corner C
279
	 *    6. Y coordinate of upper left corner F
280
	 * where the real-world coordinates x',y' can be calculated from
281
	 * the image coordinates x,y with the equations
282
	 *  x' = Ax + By + C and y' = Dx + Ey + F.
283
	 *  The signs of the first 4 parameters depend on the orientation
284
	 *  of the image. In the usual case where north is more or less
285
	 *  at the top of the image, the X pixel size will be positive
286
	 *  and the Y pixel size will be negative. For a south-up image,
287
	 *  these signs would be reversed.
288
	 * 
289
	 * You can calculate the World file parameters yourself based
290
	 * on the corner coordinates. The X and Y pixel sizes can be
291
	 *  determined simply by dividing the distance between two
292
	 *  adjacent corners by the number of columns or rows in the image.
293
	 *  The rotation terms are calculated with these equations:
294
	 * 
295
	 *  # B = (A * number_of_columns + C - lower_right_x') / number_of_rows * -1
296
	 *  # D = (E * number_of_rows + F - lower_right_y') / number_of_columns * -1
297
	 * 
298
	 * @param corner (tl, tr, br, bl)
299
	 * @return
300
	 */
301
	
302
	public static double [] cornersToWorldFile(Point2D [] esq, Dimension size) {
303
		double a=0,b=0,c=0,d=0,e=0,f=0;
304
		double x1 = esq[0].getX(), y1 = esq[0].getY();
305
		double x2 = esq[1].getX(), y2 = esq[1].getY();
306
		double x3 = esq[2].getX(), y3 = esq[2].getY();
307
		double x4 = esq[3].getX(), y4 = esq[3].getY();
308
		// A: X-scale
309
		a = Math.abs( Math.sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
310
		      / size.getWidth());
311

  
312
		// E: negative Y-scale
313
		e =  - Math.abs(Math.sqrt((x1-x4)*(x1-x4)+
314
		      (y1-y4)*(y1-y4))/size.getHeight());
315

  
316
		// C, F: upper-left coordinates
317
		c = x1;
318
		f = y1;
319
		
320
		// B & D: rotation parameters
321
		b = (a * size.getWidth() + c - x3 ) / size.getHeight() * -1;
322
		d = (e * size.getHeight() + f - y3 ) / size.getWidth() * -1;
323

  
324
		double [] wf = {a,d,b,e,c,f}; 
325
		return wf;  
326
	}
327
    public static String printWF(String fName, Point2D [] esq, Dimension sz) {
328
    	double [] wf = GeoRasterFile.cornersToWorldFile(esq, sz);
329
    	System.out.println("wf para "+fName);
330
    	System.out.println(esq+"\n"+sz);
331
    	String wfData = "";
332
    	for (int i=0; i<6; i++)
333
    		wfData += wf[i]+"\n";
334
		System.out.println(wfData);
335
		return wfData;
336
    }
337
    
338
    public static void saveWF(String fName, String data) throws IOException {
339
    	FileWriter fw = new FileWriter(fName);
340
    	fw.write(data);
341
    	fw.flush();
342
    	fw.close();
343
    }
344
}
0 345

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/.cvsignore
1
*.swp
2
*.dfPackage
3
*.wmf
0 4

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/ZipFileFolder.java
1
/*
2
 * Created on 03-may-2004
3
 *
4
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
5
 */
6
package org.cresques.io;
7

  
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.util.Enumeration;
11
import java.util.zip.ZipEntry;
12
import java.util.zip.ZipFile;
13

  
14
/**
15
 *
16
 *  
17
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
18
 */
19

  
20
public class ZipFileFolder extends FileFolder {
21
	String zName = null;
22
	public ZipFile file = null;
23
	
24
	public ZipFileFolder() {
25
		super();
26
	}
27
	
28
	/**
29
	 * Constructor.
30
	 * 
31
	 * @param fname
32
	 */
33
	
34
	public ZipFileFolder(String fName) throws IOException {
35
		fName = DataSource.normalize(fName);
36
		if (isUrl(fName))
37
			zName = getZName(fName);
38
		else
39
			zName = fName;
40
		file = new ZipFile(zName);
41
	}
42
	
43
	/**
44
	 * Analiza un nombre de fichero en formato zip://zipname.zip?file.ext
45
	 * @param urlName
46
	 */
47
	
48
	public static boolean isUrl(String name) {
49
		String str = name.substring(0,3);
50
		str.toLowerCase();
51
		if (str.compareTo("zip") == 0)
52
			return true;
53
		return false;
54
	}
55
	
56
	private String getZName(String urlName) {
57
		return urlName.substring(6,urlName.indexOf("?"));
58
	}
59
	private String getFName(String urlName) {
60
		return urlName.substring(urlName.indexOf("?")+1);
61
	}
62
	
63
	public ZipEntry getZipEntry(String fName) throws IOException {
64
		InputStream is = null;
65
		if (isUrl(fName))
66
			fName = getFName(fName);
67
		return file.getEntry(fName);
68
	}
69
	
70
	public InputStream getInputStream(String fName) throws IOException {
71
		return file.getInputStream(getZipEntry(fName));
72
	}
73
	
74
	public InputStream getInputStream(ZipEntry ze) throws IOException {
75
		return file.getInputStream(ze);
76
	}
77
	
78
	public int count() { return file.size(); }
79
	
80
	public Enumeration entries() { return file.entries();}
81
}
0 82

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/DxfGroup.java
1
/*
2
 * Created on 04-may-2004
3
 */
4
package org.cresques.io;
5

  
6
import java.io.BufferedReader;
7
import java.io.IOException;
8
import java.text.DecimalFormat;
9
import java.text.DecimalFormatSymbols;
10
import java.util.Locale;
11

  
12
/**
13
 * Grupo Dxf (code, data). Auxiliar para leer ficheros dxf
14
 * 
15
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
16
 * @author "Michel Michaud" (code from)
17
 */
18

  
19
public class DxfGroup {
20
	int code;
21
	Object data;
22

  
23
	public DxfGroup() {
24
		code = -1;
25
		data = null;
26
	}
27
	
28
	public DxfGroup(int code, String data) {
29
		this.code = code;
30
		this.data = data;
31
	}
32

  
33
	public static DxfGroup read(BufferedReader fi) throws NumberFormatException, IOException {
34
		DxfGroup grp = null;
35
		String txt = fi.readLine();
36
		if (txt != null) {
37
			if (!txt.equals("")) {
38
				grp = new DxfGroup();
39
				grp.code = Integer.parseInt(txt.trim());
40
				grp.readData(fi);				
41
			} else {
42
				// Se trata de una linea en blanco y no se hace nada.
43
			}
44
		}
45
		return grp;
46
	}
47
	
48
	public int getCode() { return code; }
49
	public Object getData() { return data; }
50
	
51
	private void readData(BufferedReader fi) throws IOException {
52
		String txt = fi.readLine().trim();
53
		if (0 <= code && code <= 9) {
54
			data = txt;	//_dfun = string_data
55
		} else if (10 <= code && code <= 59) {
56
			data = new Double(Double.parseDouble(txt)); //_dfun = float_data
57
		} else if (60 <= code && code <= 79) {
58
			try {
59
				data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int
60
			} catch (java.lang.NumberFormatException e) {
61
				data = new Integer((int) Double.parseDouble(txt));
62
			}
63
		} else if (90 <= code && code <= 99) {
64
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 32-bit int
65
		} else if (code == 100) {
66
			data = txt; //_dfun = unicode_data
67
		} else if (code == 102) {
68
			System.err.println("Dxf: codigo "+code+" no implementado."); //_dfun = unicode_data
69
		} else if (code == 105) {
70
			data = txt; ; //_dfun = handle_data
71
		} else if (110 <= code && code <= 139) {
72
			data = new Double(Double.parseDouble(txt)); //_dfun = float_data // not in dxf spec
73
		} else if (140 <= code && code <= 149) { // says 147 in dxf spec
74
			data = new Double(Double.parseDouble(txt)); //_dfun = float_data
75
		} else if (170 <= code && code <= 179) { // says 175 in dxf spec
76
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int
77
		} else if (210 <= code && code <= 239) {
78
			data = new Double(Double.parseDouble(txt)); //_dfun = float_data // del TEXT procendente de exportacion de microstation 
79
		} else if (270 <= code && code <= 279) {
80
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // not in dxf spec
81
		} else if (280 <= code && code <= 289) {
82
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 8-bit int
83
		} else if (290 <= code && code <= 299) {
84
			data = new Boolean(Boolean.getBoolean(txt)); //_dfun = bool_data
85
		} else if (300 <= code && code <= 309) {
86
			data = txt;	//_dfun = string_data
87
		} else if (310 <= code && code <= 319) {
88
			throw new IOException("Dxf: codigo "+code+" no implementado."); //_dfun = bin_data
89
		} else if (320 <= code && code <= 329) {
90
			throw new IOException("Dxf: codigo "+code+" no implementado."); //_dfun = handle_data
91
		} else if (330 <= code && code <= 369) {
92
			System.err.println("Dxf: codigo "+code+" no implementado."); //_dfun = hex_data
93
		} else if (370 <= code && code <= 379) {
94
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 8-bit int
95
		} else if (380 <= code && code <= 389) {
96
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 8-bit int
97
		} else if (390 <= code && code <= 399) {
98
			data = txt; //_dfun = handle_data
99
		} else if (400 <= code && code <= 409) {
100
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int
101
		} else if (410 <= code && code <= 419) {
102
			data = txt;	//_dfun = string_data
103
		} else if (code == 999) {
104
			data = txt;	//_dfun = string_data // comment
105
		} else if (1000 <= code && code <= 1009) {
106
			data = txt;	//_dfun = string_data
107
		} else if (1010 <= code && code <= 1059) {
108
			data = new Double(Double.parseDouble(txt)); //_dfun = float_data
109
		} else if (1060 <= code && code <= 1070) {
110
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data // 16-bit int
111
		} else if (code == 1071) {
112
			data = new Integer(Integer.parseInt(txt)); //_dfun = int_data # 32-bit int
113
		} else {
114
			throw new IOException("DxfReader: c?digo "+code+" desconocido.");
115
			//raise ValueError, "Unexpected code: %d" % code
116
		}
117
		//return _dfun
118
	}
119
	
120
	public boolean equals(int c, String s) {
121
		if (c == code && s.compareTo((String) data) == 0 ) return true;
122
		return false;
123
	}
124
	/*
125
	def get_group(handle):
126
	_code = int(handle.readline())
127
	_dfun = get_data_type(_code)
128
	_data = _dfun(handle.readline())
129
	return (_code, _data)
130
	 */
131
	 
132
	private static final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
133
	private static final DecimalFormat[] decimalFormats = new DecimalFormat[]{
134
						  new DecimalFormat("#0", dfs),
135
						  new DecimalFormat("#0.0", dfs),
136
						  new DecimalFormat("#0.00", dfs),
137
						  new DecimalFormat("#0.000", dfs),
138
						  new DecimalFormat("#0.0000", dfs),
139
						  new DecimalFormat("#0.00000", dfs),
140
						  new DecimalFormat("#0.000000", dfs),
141
						  new DecimalFormat("#0.0000000", dfs),
142
						  new DecimalFormat("#0.00000000", dfs),
143
						  new DecimalFormat("#0.000000000", dfs),
144
						  new DecimalFormat("#0.0000000000", dfs),
145
						  new DecimalFormat("#0.00000000000", dfs),
146
						  new DecimalFormat("#0.000000000000", dfs)};
147
						  
148
	public static String int34car(int code) {
149
		if (code<10) return "  " + Integer.toString(code);
150
		else if (code<100) return " " + Integer.toString(code);
151
		else return Integer.toString(code);
152
	}
153
    
154
	public static String int6car(int value) {
155
		String s = "     " + Integer.toString(value);
156
		return s.substring(s.length()-6, s.length());
157
	}
158
	public static String toString(int code, String value) {
159
	  return int34car(code) + "\r\n" + value + "\r\n";
160
	}
161

  
162
	public static String toString(int code, int value) {
163
	  return int34car(code) + "\r\n" + int6car(value) + "\r\n";
164
	}
165

  
166
	public static String toString(int code, float value, int decimalPartLength) {
167
	  return int34car(code) + "\r\n" +
168
			  decimalFormats[decimalPartLength].format((double)value) + "\r\n";
169
	}
170

  
171
	public static String toString(int code, double value, int decimalPartLength) {
172
	  return int34car(code) + "\r\n" +
173
			  decimalFormats[decimalPartLength].format(value) + "\r\n";
174
	}
175

  
176
	public static String toString(int code, Object value) {
177
		if (value instanceof String) {return toString(code, (String)value);}
178
		else if (value instanceof Integer) {return toString(code, ((Integer)value).intValue());}
179
		else if (value instanceof Double) {return toString(code, ((Double)value).floatValue(), 3);}
180
		else if (value instanceof Double) {return toString(code, ((Double)value).doubleValue(), 6);}
181
		else return toString(code, value.toString());
182
	}
183

  
184
	 
185
	 public String toString() {
186
		return toString(code, data);
187
	 }
188
	/**
189
	 * jmorell: Permite rellenar los datos. ?til en la escirtura de DXFs.
190
	 * @param data The data to set.
191
	 */
192
	public void setData(Object data) {
193
		this.data = data;
194
	}
195
	/**
196
	 * jmorell: Permite rellenar los c?digos. ?til en la escirtura de DXFs.
197
	 * @param code The code to set.
198
	 */
199
	public void setCode(int code) {
200
		this.code = code;
201
	}
202
}
0 203

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/MapServerInputStream.java
1
/*
2
 * Created on 13-dic-2004
3
 */
4
package org.cresques.io;
5

  
6
import java.awt.Image;
7
import java.net.URL;
8

  
9
import javax.imageio.ImageIO;
10

  
11
import org.cresques.cts.ICoordTrans;
12
import org.cresques.cts.IProjection;
13
import org.cresques.px.Extent;
14

  
15
/**
16
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
17
 */
18
public class MapServerInputStream extends GeoRasterFile {
19
	int width, height;
20
	protected MapServerClient mapServer = null;
21
	public MapServerInputStream(IProjection proj, String name) {
22
		super(proj, name);
23
	}
24
	public MapServerInputStream(IProjection proj, MapServerClient server) {
25
		super(proj, server.getName());
26
		mapServer = server;
27
		extent = mapServer.getViewExtent();
28
	}
29
	
30
	public GeoFile load() {
31
		System.out.println("mapServer size = ("+width+","+height+")"/*+
32
				"\n inc=("+file.cellIncrementX+","+file.cellIncrementY+")\n"+
33
				" datum='"+file.datum+"', proyeccion='"+file.projection+"'"*/);
34
		return this;
35
	}
36

  
37
	/* (non-Javadoc)
38
	 * @see org.cresques.io.GeoRasterFile#close()
39
	 */
40
	public void close() {
41
		// TODO Auto-generated method stub
42
		
43
	}
44

  
45
	public void setExtent(Extent e) {
46
		extent = e;
47
	}
48
	
49
	public void setSize(int w, int h) {
50
		width = w; height = h;
51
	}
52

  
53
	public int getWidth() { return width; }
54

  
55
	public int getHeight() { return height; }
56

  
57
	/* (non-Javadoc)
58
	 * @see org.cresques.io.GeoRasterFile#reProject(org.cresques.cts.ICoordTrans)
59
	 */
60
	public void reProject(ICoordTrans rp) {
61
		// TODO Auto-generated method stub
62
	}
63

  
64
	public void setView(Extent e) {
65
/**/	mapServer.setView((long) e.getMin().getX(), (long) e.getMax().getY(),
66
/**/		(long) e.getMax().getX(), (long)e.getMin().getY());
67
	}
68

  
69
	public Extent getView() {
70
		return mapServer.getViewExtent();
71
	}
72

  
73
	/* (non-Javadoc)
74
	 * @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans)
75
	 */
76
	public Image updateImage(int width, int height, ICoordTrans rp) {
77
		Image image = null;
78
		int line, pRGBArray[] = null;
79
		if (mapServer == null) return image;
80
		
81
		try {
82
/**/		mapServer.setViewSize(width, height);
83
	    	System.out.println("Querying mapServer: "+mapServer.getUrl());
84
			image = ImageIO.read(new URL(mapServer.getUrl()));
85
		} catch (Exception e) {
86
			e.printStackTrace();
87
		}
88

  
89
		return image; //.getScaledInstance(width, height, Image.SCALE_FAST);
90
	}
91

  
92
	/* (non-Javadoc)
93
	 * @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int)
94
	 */
95
	public Image updateImage(int width, int height, ICoordTrans rp, Image img, int flags) {
96
		// TODO Auto-generated method stub
97
		return null;
98
	}
99
	/* (non-Javadoc)
100
	 * @see org.cresques.io.GeoRasterFile#getData(int, int, int)
101
	 */
102
	public Object getData(int x, int y, int band) {
103
		// TODO Auto-generated method stub
104
		return null;
105
	}
106
	
107
}
0 108

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/TrkFile.java
1
/*
2
 * Creado el 21-jun-2004
3
 */
4
package org.cresques.io;
5

  
6
import java.io.DataInputStream;
7
import java.io.EOFException;
8
import java.io.FileInputStream;
9
import java.io.FileNotFoundException;
10
import java.io.IOException;
11
import java.io.InputStream;
12

  
13
import org.cresques.cts.ICoordTrans;
14
import org.cresques.cts.IProjection;
15
import org.cresques.px.IObjList;
16
import org.cresques.px.PxObjList;
17
import org.cresques.px.gml.LineString;
18

  
19
/**
20
 * @author luisw
21
 */
22
public class TrkFile  extends GeoFile {
23

  
24
	private DataInputStream is;
25
	long l = 0;
26
	LineString line;
27

  
28
	public TrkFile(IProjection proj, String name) {
29
		super(proj, name);
30
	}
31
	/* (no Javadoc)
32
	 * @see org.cresques.io.GeoFile#load()
33
	 */
34
	public GeoFile load() {
35
		try {
36
			return load(new FileInputStream(name));
37
		} catch (NumberFormatException e) {
38
			// TODO Bloque catch generado autom?ticamente
39
			e.printStackTrace();
40
		} catch (FileNotFoundException e) {
41
			// TODO Bloque catch generado autom?ticamente
42
			e.printStackTrace();
43
		} catch (Exception e) {
44
			// TODO Bloque catch generado autom?ticamente
45
			e.printStackTrace();
46
		}
47
		return this;
48
	}
49
	
50
	public GeoFile load(InputStream is) throws NumberFormatException, Exception {
51
		System.out.println("Trk: Cargando '"+name+"' ...");
52
		this.is = new DataInputStream(is);
53
		line = new LineString();
54
		while (readPoint()) {
55
			l++;
56
		}
57
		extent.add(line.getExtent());
58
		is.close();
59
		System.out.println("Trk: '"+name+"' cargado. ("+l+" puntos).");
60
		return this;
61
	}
62
	
63
	public boolean readPoint() {
64
		int	h, m, s, sgn = 1;
65
		double	D, M, S;
66
		double lat, lng;
67
		try {
68
			h = is.readUnsignedByte();
69
			m = is.readUnsignedByte();
70
			s = is.readUnsignedByte();
71
			is.skipBytes(1);
72
			D = is.readUnsignedByte();
73
			M = is.readByte();
74
			S = is.readUnsignedShort();
75
			S /= 1000.0;
76
			if (M<0) {
77
				sgn = -1;
78
				M *= -1;
79
			} else sgn = 1;
80
			lat = sgn * (D + (M/60D+S/3600D));
81
			D = is.readUnsignedByte();
82
			M = is.readByte();
83
			S = is.readUnsignedShort();
84
			S /= 1000.0;
85
			if (M<0) {
86
				sgn = -1;
87
				M *= -1;
88
			} else sgn = 1;
89
			lng = sgn * (D + (M/60D+S/3600D));
90
			line.add(proj.createPoint(lng, lat));
91
		} catch (EOFException eof) {
92
			return false;
93
		} catch (IOException e) {
94
			// TODO Bloque catch generado autom?ticamente
95
			e.printStackTrace();
96
			return false;
97
		}
98
		return true;
99
	}
100
	/* (no Javadoc)
101
	 * @see org.cresques.io.GeoFile#reProject(org.cresques.geo.ReProjection)
102
	 */
103
	public IObjList getObjects() {
104
		IObjList oList = new PxObjList(proj);
105
		oList.add(line);
106
		return oList;
107
	}
108
	public void reProject(ICoordTrans rp) {
109
		line.reProject(rp);
110
		setProjection(rp.getPDest());
111
	}
112
	/* (non-Javadoc)
113
	 * @see org.cresques.io.GeoFile#close()
114
	 */
115
	public void close() {
116
		// TODO Auto-generated method stub
117
		
118
	}
119

  
120

  
121
}
0 122

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/BookmarkList.java
1
/*
2
 * Creado el 31-ago-2004
3
 */
4
package org.cresques.io;
5

  
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8
import java.util.Iterator;
9
import java.util.Map;
10
import java.util.TreeMap;
11
import java.util.Vector;
12

  
13
import javax.swing.ImageIcon;
14
import javax.swing.JMenu;
15
import javax.swing.JMenuItem;
16

  
17
import org.cresques.cts.IProjection;
18
import org.cresques.ui.CQApp;
19

  
20
/**
21
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
22
 */
23
class Bookmark {
24
	String folder;
25
	String name;
26
	String [] fName;
27
	String projName;
28
	IProjection proj;
29
	
30
	public Bookmark(String fld, String n, String f, IProjection p) {
31
		projName = null;
32
		fName = new String[1];
33
		folder = fld; name = n; fName[0] = f; proj = p;
34
	}
35
	public Bookmark(String fld, String n, String [] f, IProjection p) {
36
		projName = null;
37
		fName = new String[f.length];
38
		folder = fld; name = n; proj = p;
39
		for (int i=0; i<f.length; i++)
40
			fName[i] = f[i];
41
	}
42
}
43

  
44
public class BookmarkList extends TreeMap implements ActionListener {
45
	CQApp app = null;
46
	
47
	public BookmarkList(CQApp mainApp) {
48
		app = mainApp;
49
		loadList();
50
	}
51
	
52
	public void loadList() {
53
	}
54
	
55
	public void addEntry(String fld, String n, String f, IProjection p) {
56
		addEntry(new Bookmark(fld, n, f, p));
57
	}
58
	
59
	public void addEntry(String fld, String n, String [] f, IProjection p) {
60
		addEntry(new Bookmark(fld, n, f, p));
61
	}
62
	
63
	public void addEntry(Bookmark bookmark) {
64
		Vector vector;
65
		if (containsKey(bookmark.folder)) {
66
			vector = (Vector) get(bookmark.folder);
67
		} else {
68
			vector = new Vector();
69
		}
70
		vector.add(bookmark);
71
		put(bookmark.folder, vector);
72
	}
73
	
74
	public JMenu getJMenu() {
75
		JMenuItem it = null;
76
		JMenu menu = null, menu2 = null;
77
		ClassLoader loader = this.getClass().getClassLoader();
78
		//loader.getResource("images/"+"folderXP.gif");
79
		//System.err.println("URL="+loader.getResource("images/"+"folderXP.gif"));
80
		ImageIcon folderIcon = new ImageIcon(loader.getResource("images/"+"folderXP.gif"));
81
		ImageIcon dxfIcon = new ImageIcon(loader.getResource("images/"+"fileXPdxf.gif"));
82
		ImageIcon gmlIcon = new ImageIcon(loader.getResource("images/"+"fileXPgml.gif"));
83
		ImageIcon ecwIcon = new ImageIcon(loader.getResource("images/"+"fileXPecw.gif"));
84
		ImageIcon tifIcon = new ImageIcon(loader.getResource("images/"+"fileXPtif.gif"));
85
		ImageIcon fileIcon = new ImageIcon(loader.getResource("images/"+"fileXP.gif"));
86
		
87
		menu = new JMenu("Favoritos");
88
		menu.setMnemonic('F');
89
		
90
		// Arbol de carpetas
91
		TreeMap menuMap = new TreeMap();
92
		String [] menuNames;
93
		JMenu parentMenu = null;
94
		String mName = null, key = null;;
95

  
96
		Iterator mIter = keySet().iterator();
97
		while (mIter.hasNext()) {
98
			key = (String) mIter.next();
99
			System.out.println("Key:"+key);
100
			menuNames = key.split("\\|");
101
			
102
			parentMenu = menu;
103
			mName = "";
104
			for (int i=0; i<menuNames.length; i++) {
105
				if (i>0) mName += "|";
106
				mName += menuNames[i];
107
				if (menuMap.containsKey(mName)) {
108
					//System.out.println(" mName:"+mName+", parent:"+parentMenu.getText());
109
					parentMenu = (JMenu) menuMap.get(mName);
110
				} else {
111
					//System.out.println("+mName:"+mName+", parent:"+parentMenu.getText());
112
					menu2 = new JMenu(menuNames[i]);
113
					menu2.setIcon(folderIcon);
114
					parentMenu.add(menu2);
115
					menuMap.put(mName, menu2);
116
					parentMenu = menu2;
117
				}
118
			}
119
		}
120
		
121
		// Entradas (Bookmarks)
122
		mIter = entrySet().iterator();
123
		while (mIter.hasNext()) {
124
			Map.Entry entry = (Map.Entry) mIter.next();
125
			String folder = (String) entry.getKey();
126
			
127
			/*menu2 = new JMenu(folder);
128
			menu2.setIcon(folderIcon);
129
			menu.add(menu2);*/
130
			menu2 = (JMenu) menuMap.get(folder);
131

  
132
			Vector vector = ((Vector) entry.getValue());
133
			Bookmark bookmark;
134
			for (int i=0; i<vector.size(); i++) {
135
				bookmark = (Bookmark) vector.get(i);
136
				it = new JMenuItem(bookmark.name);
137
				it.setActionCommand(i+"|"+folder);
138
				it.addActionListener(this);
139
				if (bookmark.fName[0].endsWith("tif"))
140
					it.setIcon(tifIcon);
141
				else if (bookmark.fName[0].endsWith("ecw"))
142
					it.setIcon(ecwIcon);
143
				else if (bookmark.fName[0].endsWith("gml"))
144
					it.setIcon(gmlIcon);
145
				else if (bookmark.fName[0].endsWith("dxf") || bookmark.fName[0].endsWith("DXF"))
146
					it.setIcon(dxfIcon);
147
				else
148
					it.setIcon(fileIcon);
149

  
150
				menu2.add(it);
151
			}
152
		}
153
		//menu.add(menu2);
154
		return menu;
155
	}
156
	
157
	public void actionPerformed(ActionEvent event) {
158
		IProjection proj = null;
159
		String cmd = event.getActionCommand();
160
		int mark = cmd.indexOf('|');
161
		int vectorPos = Integer.parseInt(cmd.substring(0,mark));
162
		cmd = cmd.substring(mark+1);
163
		Bookmark bookmark = (Bookmark) ((Vector) get(cmd)).get(vectorPos);
164
		if (bookmark.fName.length == 1)
165
			app.loadFile(bookmark.fName[0], bookmark.proj);
166
		else
167
			app.loadFile(bookmark.fName, bookmark.proj);
168
	}
169
}
170

  
0 171

  
branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/MapServerClient.java
1
/*
2
 * Created on 12-dic-2004
3
 */
4
package org.cresques.io;
5

  
6
import java.io.BufferedInputStream;
7
import java.io.IOException;
8
import java.io.InputStream;
9
import java.net.MalformedURLException;
10
import java.net.URL;
11

  
12
import org.cresques.px.Extent;
13

  
14
/**
15
 * Consulta para un servidor de mapas.
16
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
17
 */
18
public abstract class MapServerClient implements Extent.Has {
19
	public static final int MAXBUFSIZE = 1024*1024; 
20
    BufferedInputStream bufIn = null;
21
    byte [] buffer;
22
    int bufPos;
23
	String serverName;
24
	protected String urlBase = null;
25
	protected long xMin, xMax, yMin, yMax;
26
	protected int ancho, alto;
27
    public boolean echo = false;
28
    private Extent extent = null;
29
    private int maxViewWidth = 1500;
30
    private int maxViewHeight = 1500;
31
    private float minTimeBetweenQuerys = 0;
32
	
33
	public MapServerClient(String serverName) {
34
		this.serverName = serverName;
35
	}
36
	
37
	public String getName() { return serverName; }
38
	
39
	public byte [] getBuffer() { return buffer; } 
40
	
41
	public void setView(long xMin, long yMin, long xMax, long yMax) {
42
		this.xMin = xMin; this.xMax = xMax;
43
		this.yMax = yMax; this.yMin = yMin;
44
	}
45
	
46
	public void setViewSize( int w, int h) {
47
		ancho = w; alto = h;
48
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff