Revision 1293

View differences:

org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/package.sh
1
#/bin/sh
2

  
3
if [ "$1" = "--help" ] ; then
4
   echo "Usage: First parameter:"
5
   echo "          -update"
6
   echo "          -install"
7
   echo "          -package: crear paquetes"
8
   echo "          -upload: subir al repositorio"
9
   echo "          -tags: crear tags buildNumber_VERSION"
10
   echo "          -commit: subir build number"
11
   echo "          -ticket: crear fichero de texto con las URLS de los índices para el ticket" 
12
   echo "Para hacer nuevo empaquetado"
13
   echo "   1-Comprobar variables VERSION, FIX_VERSION, RELEASE, PACKAGE_DIRECTORY, URL, URL_TAGS, USER y PASS"
14
   echo "   2-Si se ha metido algún paquete nuevo actualizar la variable PROJECT y PLUGINS o ARCH_DEP_PLUGIN si fuera necesario"
15
   echo "   3-Ejecutar ./package.sh -update para actualizar los proyectos"
16
   echo "   4-Ejecutar ./package.sh -install para limpiar e instalar los proyectos"
17
   echo "   5-Ejecutar ./package.sh -package para empaquetar en PACKAGE_DIRECTORY"
18
   echo "   6-Ejecutar ./package.sh -upload para subir a URL"
19
   echo "   7-Ejecutar ./package.sh -commit para subir los buildnumber"
20
   echo "   8-Ejecutar ./package.sh -tags para crear tags en URL_TAGS"
21
   echo "   9-Ejecutar ./package.sh -ticket para generar el fichero con las urls de los índices"
22
   echo "Para revertir cambios del SVN ./package.sh -revert"
23
   exit
24
fi
25

  
26
VERSION=2.0.0
27
FIX_VERSION=SNAPSHOT
28
RELEASE=devel
29
URL=https://devel.gvsig.org/download/projects/Raster/pool/
30
URL_TAGS=https://devel.gvsig.org/svn/gvsig-raster/
31
PACKAGE_DIRECTORY=/home/nacho/Workspaces/gvsig-2.0/build/product/install/pool
32
PATH_TICKET=/tmp/ticket.txt
33
USER=nbrodin
34
PASS=
35

  
36
PLATFORM="linux"
37
COMPILER="gcc4"
38
ARCH="i386"
39
DISTRIBUTION="all"
40
TYPE="dynamic"
41

  
42
PLATFORM_B="win"
43
COMPILER_B="vs8"
44
DISTRIBUTION_B="nt"
45

  
46
#pool packages
47
MAIN_PACKAGE=0 #Posición 1 obligatoria tilecache en ARCH_DEP_PLUGINS
48

  
49
#Plugin list
50
PLUGINS="org.gvsig.raster.gdal/org.gvsig.raster.gdal.app 
51
org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic 
52
org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.multifile 
53
org.gvsig.raster.wmts/org.gvsig.raster.wmts.app/org.gvsig.raster.wmts.app.wmtsclient 
54
org.gvsig.raster.wms/org.gvsig.raster.wms.app/org.gvsig.raster.wms.app.wmsclient 
55
org.gvsig.raster.wcs/org.gvsig.raster.wcs.app/org.gvsig.raster.wcs.app.wcsclient 
56
org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient 
57
org.gvsig.raster.postgis/org.gvsig.raster.postgis.app/org.gvsig.raster.postgis.app.postgisrasterclient"
58

  
59
ARCH_DEP_PLUGINS="org.gvsig.raster.tilecache/org.gvsig.raster.tilecache.app
60
org.gvsig.raster.ermapper/org.gvsig.raster.ermapper.app
61
org.gvsig.raster.lizardtech/org.gvsig.raster.lizardtech.app"
62
 
63
#eclipse projects
64
PROJECTS="org.gvsig.raster.cache 
65
org.gvsig.raster 
66
org.gvsig.raster.gdal 
67
org.gvsig.raster.tilecache 
68
org.gvsig.raster.tools 
69
org.gvsig.raster.wmts 
70
org.gvsig.raster.wms 
71
org.gvsig.raster.wcs 
72
org.gvsig.raster.ermapper 
73
org.gvsig.raster.lizardtech 
74
org.gvsig.raster.netcdf 
75
org.gvsig.raster.postgis"
76

  
77

  
78
CLASSIFIER=$PLATFORM"-"$DISTRIBUTION"-"$COMPILER"-"$ARCH"-"$TYPE
79

  
80
COMMAND_PARAMS="install -P create-installer -Dnative-platform="$PLATFORM" -Dnative-compiler="$COMPILER" -Dnative-arch="$ARCH" -Dnative-distribution="$DISTRIBUTION" -Dlibrary-type="$TYPE" -Dnative-classifier="$CLASSIFIER" -Pinstall-extensions -Dmaven.test.skip"
81

  
82
#-------------------------------------------------
83
#Gets the number of the version
84
#$1: Project name
85
#-------------------------------------------------
86
getVersionProject( ) {
87
  c=-1;
88
  for i in $PLUGINS
89
    do
90
      let "c=c+1";
91
      AUX=`echo $i | grep "$1\/"`; 
92
      if [ "$AUX" != "" ]; then
93
        echo ${VER[c]}
94
        return;
95
      fi
96
    done
97
  c=-1;
98
  for i in $ARCH_DEP_PLUGINS
99
    do
100
      let "c=c+1";
101
      AUX=`echo $i | grep "$1\/"`; 
102
      if [ "$AUX" != "" ]; then
103
        echo ${VER_ARCH_DEP[c]}
104
        return;
105
      fi
106
    done
107
  echo ${VER_ARCH_DEP[MAIN_PACKAGE]}
108
}
109

  
110
#-------------------------------------------------
111
#Loads the array of versions
112
#Be careful. It has to be called after package generation
113
#-------------------------------------------------
114
loadVersion() {
115
  cont=0;
116
  CURRENT_DIR=`pwd`
117
  for i in $PLUGINS
118
   do
119
     if [ -d $i ]; then
120
       cd $i
121
       if [ -f buildNumber.properties ]; then
122
         VER[cont]=`cat buildNumber.properties | grep "buildNumber=" | cut -d'=' -f2`
123
	 #echo "===>>>>$i---->${VER[cont]}"
124
         let "cont=cont+1"; 
125
       fi
126
     fi
127
     cd $CURRENT_DIR
128
   done
129

  
130
  cont=0;
131
  for i in $ARCH_DEP_PLUGINS
132
   do
133
     if [ -d $i ]; then
134
       cd $i
135
       if [ -f buildNumber.properties ]; then
136
         VER_ARCH_DEP[cont]=`cat buildNumber.properties | grep "buildNumber=" | cut -d'=' -f2`
137
	 #echo "===>>>*$i---->${VER_ARCH_DEP[cont]}"
138
         let "cont=cont+1"; 
139
       fi
140
     fi
141
     cd $CURRENT_DIR
142
   done
143
}
144

  
145

  
146
#-------------------------------------------------
147
if [ "$1" = "-update" ] ; then
148
 for i in $PROJECTS
149
    do
150
      cd $i
151
      echo "-----------------"
152
      echo "Cambiando a"....$i
153
      echo "Ejecutando svn update "
154
      svn update;
155
      cd ..
156
    done
157
fi
158

  
159

  
160
#-------------------------------------------------
161
if [ "$1" = "-commit" ] ; then
162
 for i in $PROJECTS
163
    do
164
      cd $i
165
      echo "-----------------"
166
      echo "Cambiando a"....$i
167
      echo "Ejecutando svn commit "
168
      svn commit * -m "new build number $PVERSION";
169
      cd ..
170
    done
171
fi
172
#-------------------------------------------------
173

  
174
if [ "$1" = "-install" ] ; then
175

  
176
  
177
  echo "***********************************"
178
  echo "Clean and install"
179
  echo "***********************************"
180

  
181

  
182
  INSTALL_PARAMS="install -Dnative-platform="$PLATFORM" -Dnative-compiler="$COMPILER" -Dnative-arch="$ARCH" -Dnative-distribution="$DISTRIBUTION" -Dlibrary-type="$TYPE" -Dnative-classifier="$CLASSIFIER" -Dmaven.test.skip"
183

  
184
  for i in $PROJECTS
185
    do
186
      cd $i
187
      echo "-----------------"
188
      echo "Cambiando a"....$i
189
      echo "Ejecutando mvn "$COMMAND_PARAMS
190
      mvn clean
191
      mvn $INSTALL_PARAMS;
192
      cd ..
193
    done
194

  
195
fi
196

  
197
#-------------------------------------------------
198

  
199
#-------------------------------------------------
200
if [ "$1" = "-package" ] ; then
201

  
202

  
203
  echo "***********************************"
204
  echo "Generating Packages"
205
  echo "************i***********************"
206

  
207
  DIR_BASE=`pwd`
208

  
209
  for i in $PLUGINS
210
    do
211
      cd $i
212
      echo "-----------------"
213
      echo "Cambiando a"....$i
214
      echo "Ejecutando mvn "$COMMAND_PARAMS
215
      mvn $COMMAND_PARAMS;
216
      cd $DIR_BASE
217
    done
218

  
219
  CLASSIFIER_B=$PLATFORM_B"-"$DISTRIBUTION_B"-"$COMPILER_B"-"$ARCH"-"$TYPE
220

  
221
  COMMAND_PARAMS_PLATFORM_B="install -P create-installer -Dnative-platform="$PLATFORM_B" -Dnative-compiler="$COMPILER_B" -Dnative-arch="$ARCH" -Dnative-distribution="$DISTRIBUTION_B" -Dlibrary-type="$TYPE" -Dnative-classifier="$CLASSIFIER_B" -Pinstall-extensions -Dmaven.test.skip"
222

  
223
  for i in $ARCH_DEP_PLUGINS #Plugins architecture dependent
224
    do
225
      pad=`echo $i | cut -d/ -f1` #Projects architecture dependent
226
      cd $pad
227
      echo "-----------------"
228
      echo "Cambiando a"....$pad
229
      echo "Ejecutando mvn "$COMMAND_PARAMS
230
      mvn $COMMAND_PARAMS;
231
      svn revert --recursive .
232
      mvn $COMMAND_PARAMS_PLATFORM_B;
233
      cd $DIR_BASE
234
   done
235

  
236
fi
237

  
238

  
239
loadVersion
240

  
241
#-------------------------------------------------
242
#SOLO TEST
243
#-------------------------------------------------
244
if [ "$1" = "-revert" ] ; then
245
 for i in $PROJECTS
246
    do
247
      cd $i
248
      echo "-----------------"
249
      echo "Cambiando a"....$i
250
      echo "Ejecutando svn update "
251
      svn revert --recursive .
252
      cd ..
253
    done
254
fi
255

  
256
#-------------------------------------------------
257
#SOLO TEST
258
#-------------------------------------------------
259
if [ "$1" = "-ticket" ] ; then
260
 rm $PATH_TICKET 2> /dev/null
261
 cont=0;
262
 for i in $PLUGINS
263
    do
264
      package=`echo $i | cut -d/ -f3`
265
      if [ "$package" == "" ] ; then 
266
          package=`echo $i | cut -d/ -f2`
267
      fi
268
      echo "$URL$package/gvSIG-desktop-$VERSION-$package-$VERSION-$FIX_VERSION-${VER[$cont]}-$RELEASE-all-all-j1_5.gvspki" >> $PATH_TICKET
269
      echo "" >> $PATH_TICKET
270
      let "cont=cont+1";
271
    done
272
 cont=0;
273
 for i in $ARCH_DEP_PLUGINS
274
    do
275
      package=`echo $i | cut -d/ -f3`
276
      if [ "$package" == "" ] ; then 
277
          package=`echo $i | cut -d/ -f2`
278
      fi
279
      echo "$URL$package/gvSIG-desktop-$VERSION-$package-$VERSION-$FIX_VERSION-${VER_ARCH_DEP[$cont]}-$RELEASE-lin-x86-j1_5.gvspki" >> $PATH_TICKET
280
      echo "" >> $PATH_TICKET
281
      echo "$URL$package/gvSIG-desktop-$VERSION-$package-$VERSION-$FIX_VERSION-${VER_ARCH_DEP[$cont]}-$RELEASE-win-x86-j1_5.gvspki" >> $PATH_TICKET
282
      echo "" >> $PATH_TICKET
283
      let "cont=cont+1";
284
    done
285
  echo "Creado fichero de URLs en "$PATH_TICKET
286
fi
287

  
288
#-------------------------------------------------
289
if [ "$1" = "-tags" ] ; then
290

  
291
 echo "***********************************"
292
 echo "Creating tags"
293
 echo "***********************************"
294

  
295

  
296
 for i in $PROJECTS
297
   do
298
     PVERSION=`getVersionProject $i`
299
     #echo "svn copy $URL_TAGS$i/trunk $URL_TAGS$i/tags/buildNumber_$PVERSION -m \"Tag build $PVERSION\""
300
     svn copy $URL_TAGS$i/trunk $URL_TAGS$i/tags/buildNumber_$PVERSION -m "Tag build $PVERSION"
301
   done 
302
fi 
303

  
304

  
305

  
306
#-------------------------------------------------
307
if [ "$1" != "-upload" ] ; then
308
  exit
309
fi  
310

  
311
echo "***********************************"
312
echo "Uploading"
313
echo "***********************************"
314

  
315
CURRENT_DIRECTORY=`pwd`;
316
echo "Cambiando a..."$PACKAGE_DIRECTORY
317
cd $PACKAGE_DIRECTORY
318

  
319
cont=0;
320
for i in $PLUGINS
321
do
322
package=`echo $i | cut -d/ -f3`
323
if [ "$package" == "" ] ; then 
324
package=`echo $i | cut -d/ -f2`
325
fi
326
/usr/bin/expect <<EOD
327
spawn cadaver $URL
328
expect (y/n)
329
send y\r
330
expect dav:/download/projects/Raster/pool/>
331
send "cd $package\r"
332
expect $package/>
333
send "lcd $package\r"
334
expect $package/>
335
send "put gvSIG-desktop-$VERSION-$package-$VERSION-$FIX_VERSION-${VER[$cont]}-$RELEASE-all-all-j1_5.gvspkg\r"
336
expect "Nombre de usuario:"
337
send $USER\r
338
expect "Contraseña:"
339
send $PASS\r
340
expect $package/>
341
send "put gvSIG-desktop-$VERSION-$package-$VERSION-$FIX_VERSION-${VER[$cont]}-$RELEASE-all-all-j1_5.gvspki\r"
342
expect $package/>
343
send quit\r
344
expect "cerrada."
345
EOD
346
let "cont=cont+1";
347
done
348

  
349

  
350
cont=0;
351
for i in $ARCH_DEP_PLUGINS
352
do
353
pckgad=`echo $i | cut -d/ -f2` #Packages architecture dependent
354
/usr/bin/expect <<EOD
355
spawn cadaver $URL
356
expect (y/n)
357
send y\r
358
expect dav:/download/projects/Raster/pool/>
359
send "cd $pckgad\r"
360
expect $pckgad/>
361
send "lcd $pckgad\r"
362
expect $pckgad/>
363
send "put gvSIG-desktop-$VERSION-$pckgad-$VERSION-$FIX_VERSION-${VER_ARCH_DEP[$cont]}-$RELEASE-lin-x86-j1_5.gvspkg\r"
364
expect "Nombre de usuario:"
365
send $USER\r
366
expect "Contraseña:"
367
send $PASS\r
368
expect $pckgad/>
369
send "put gvSIG-desktop-$VERSION-$pckgad-$VERSION-$FIX_VERSION-${VER_ARCH_DEP[$cont]}-$RELEASE-lin-x86-j1_5.gvspki\r"
370
expect $pckgad/>
371
send "put gvSIG-desktop-$VERSION-$pckgad-$VERSION-$FIX_VERSION-${VER_ARCH_DEP[$cont]}-$RELEASE-win-x86-j1_5.gvspkg\r"
372
expect $pckgad/>
373
send "put gvSIG-desktop-$VERSION-$pckgad-$VERSION-$FIX_VERSION-${VER_ARCH_DEP[$cont]}-$RELEASE-win-x86-j1_5.gvspki\r"
374
expect $pckgad/>
375
send quit\r
376
expect "cerrada."
377
EOD
378
let "cont=cont+1";
379
done
380

  
381
cd $CURRENT_DIRECTORY
0 382

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.fmap.FmapRasterLibrary
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/util/LayerVisualStatusList.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.util;
23

  
24
import java.util.ArrayList;
25

  
26
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
27
import org.gvsig.fmap.dal.coverage.grid.render.Render;
28
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
29
import org.gvsig.raster.fmap.layers.FLyrRaster;
30
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
31

  
32
/**
33
 * Clase para almacenar estados visuales de una capa raster. Estos estados deben ser locales
34
 * a cada funcionalidad para que no interfieran entre ellos. Luego es posible tener una lista de
35
 * estados globales para restaurar el que nos convenga.
36
 * 07/10/2008
37
 * @author Nacho Brodin nachobrodin@gmail.com
38
 */
39
public class LayerVisualStatusList {
40
	private ArrayList<LayerVisualStatus> list = new ArrayList<LayerVisualStatus>();
41
	
42
	/**
43
	 * Clase que contiene el estado visual de una capa raster.
44
	 * 07/10/2008
45
	 * @author Nacho Brodin nachobrodin@gmail.com
46
	 */
47
	public class LayerVisualStatus {
48
		private ArrayList<RasterFilter>    filterStatus = null;
49
		private Transparency               transparency = null;
50
		
51
		/**
52
		 * Obtiene el estado de la lista de filtros
53
		 * @return Array con el estado de la lista de filtros
54
		 */
55
		public ArrayList<RasterFilter> getFilterStatus() {
56
			return filterStatus;
57
		}
58
		
59
		/**
60
		 * Asigna el estado de la lista de filtros
61
		 * @return Array con el estado de la lista de filtros
62
		 */
63
		public void setFilterStatus(ArrayList<RasterFilter> filterStatus) {
64
			this.filterStatus = filterStatus;
65
		}
66
		
67
		/**
68
		 * Obtiene el estado de la transparencia
69
		 * @return Transparency
70
		 */
71
		public Transparency getTransparency() {
72
			return transparency;
73
		}
74
		
75
		/**
76
		 * Asigna el estado de la transparencia
77
		 * @param Transparency
78
		 */
79
		public void setTransparency(Transparency transparency) {
80
			this.transparency = transparency;
81
		}
82
	}
83
	
84
	/**
85
	 * Limpia la pila de elementos
86
	 */
87
	public void clear() {
88
		list.clear();
89
	}
90
	
91
	/**
92
	 * Salva un estado al final de la lista
93
	 * @param status 
94
	 */
95
	public void add(LayerVisualStatus status) {
96
		list.add(status);
97
	}
98
	
99
	/**
100
	 * Recupera el ?ltimo estado introducido en la lista
101
	 * @return StatusLayer
102
	 */
103
	public LayerVisualStatus getLast() {
104
		return (LayerVisualStatus)list.get(list.size() - 1);
105
	}
106
	
107
	/**
108
	 * Recupera el estado de la posici?n i
109
	 * @return StatusLayer
110
	 */
111
	public LayerVisualStatus get(int i) {
112
		return (LayerVisualStatus)list.get(i);
113
	}
114
		
115
	
116
	/**
117
	 * Saca de la lista el ?ltimo estado y lo asigna a la capa indicada.
118
	 * @param lyr Capa raster
119
	 */
120
	public void restoreVisualStatus(FLyrRaster lyr) {
121
		Render rendering = lyr.getRender();
122
		LayerVisualStatus status = getLast();
123
		if(status != null) {
124
			if(rendering.getFilterList() != null)
125
				rendering.getFilterList().setStatus(status.filterStatus);
126
			lyr.getRender().setLastTransparency(status.transparency);
127
			if(((IRasterLayerActions)lyr).isActionEnabled(IRasterLayerActions.REMOTE_ACTIONS))
128
				lyr.getRender().getFilterList().setStatus(status.filterStatus);
129
		}
130
	}
131
	
132
	/**
133
	 * Obtiene de la capa su estado de visualizaci?n y lo salva en la lista
134
	 * @param lyr Capa raster
135
	 */
136
	public void getVisualStatus(FLyrRaster lyr) {
137
		LayerVisualStatus status = new LayerVisualStatus();
138
		status.transparency = lyr.getRender().getLastTransparency();
139
		status.filterStatus = lyr.getRender().getFilterList().getStatusCloned();
140
		add(status);
141
	}
142
}
0 143

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/util/RasterNotLoadException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.util;
23

  
24

  
25
/**
26
 * Excepci?n producida cuando no es posible cargar un raster en la vista de gvSIG.
27
 * 
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 *
30
 */
31
public class RasterNotLoadException extends Exception {
32
	private static final long serialVersionUID = -3022090543908771484L;
33
	
34
	public RasterNotLoadException(String msg){
35
		super(msg);
36
	}
37
}
0 38

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/util/Queue.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.util;
23

  
24
import java.util.Vector;
25

  
26
/**
27
 * A simple FIFO queue class which causes the calling thread to wait if the
28
 * queue is empty and notifies threads that are waiting when it is not
29
 * empty.
30
 * 
31
 * @author Anil V (akv@eng.sun.com)
32
 */
33
public class Queue {
34
	private Vector<Object> vector = new Vector<Object>();
35

  
36
	/**
37
	 * Put the object into the queue.
38
	 * 
39
	 * @param object
40
	 *            the object to be appended to the queue.
41
	 */
42
	public synchronized void put(Object object) {
43
		vector.addElement(object);
44
		notify();
45
	}
46

  
47
	/**
48
	 * Pull the first object out of the queue. Wait if the queue is empty.
49
	 */
50
	public synchronized Object pull() {
51
		while (isEmpty())
52
			try {
53
				wait();
54
			} catch (InterruptedException ex) {
55
			}
56
			return get();
57
	}
58

  
59
	/**
60
	 * Get the first object out of the queue. Return null if the queue is
61
	 * empty.
62
	 */
63
	public synchronized Object get() {
64
		Object object = peek();
65
		if (object != null)
66
			vector.removeElementAt(0);
67
		return object;
68
	}
69

  
70
	/**
71
	 * Peek to see if something is available.
72
	 */
73
	public Object peek() {
74
		if (isEmpty())
75
			return null;
76
		return vector.elementAt(0);
77
	}
78

  
79
	/**
80
	 * Is the queue empty?
81
	 */
82
	public boolean isEmpty() {
83
		return vector.isEmpty();
84
	}
85

  
86
	/**
87
	 * How many elements are there in this queue?
88
	 */
89
	public int size() {
90
		return vector.size();
91
	}
92
}
0 93

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/util/ExtendedFileFilter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.util;
23

  
24
import java.io.File;
25
import java.util.ArrayList;
26

  
27
import javax.swing.filechooser.FileFilter;
28

  
29

  
30
/**
31
 * ExtendedFileFilter es una clase para usarla junto a los JFileChooser.
32
 * Ofrece una funcionalidad simple para poder agregar extensiones de manera
33
 * comoda y rapida. Las descripciones ya las pone con un formato, asi que esto
34
 * es opcional poner una descripci?n especifica.
35
 * 
36
 * Un ejemplo t?pico de como se usaria:
37
 * <pre>
38
 * // Usamos el JFileChooser de libUIComponents
39
 * JFileChooser chooser = new JFileChooser(this.getClass().toString(), (File) null);
40
 * // Desactivamos el modo de ver todos los ficheros
41
 * chooser.setAcceptAllFileFilterUsed(false);
42
 * // Activamos la multiseleccion
43
 * chooser.setMultiSelectionEnabled(true);
44
 * // Nos guardamos cada tipo de fichero en uno que contenga todos
45
 * ExtendedFileFilter allFilters = new ExtendedFileFilter();
46
 * for (int i = 0; i < formats.length; i++) {
47
 *   ExtendedFileFilter fileFilter = new ExtendedFileFilter();
48
 *   fileFilter.addExtension(formats[i]);
49
 *   // Agregamos el filefilter al JFileChooser
50
 *   chooser.addChoosableFileFilter(fileFilter);
51
 *   // Agregamos el mismo filtro a un ExtendedFileFilter global 
52
 *   allFilters.addExtension(formats[i]);
53
 * }
54
 * // Poner una descripcion (OPCIONAL) para todos los ficheros.
55
 * allFilters.setDescription(PluginServices.getText(this, "todos_soportados"));
56
 * // Lo a?adimos
57
 * chooser.addChoosableFileFilter(allFilters);
58
 * // Y lo dejamos seleccionado por defecto
59
 * chooser.setFileFilter(allFilters);
60
 * </pre>
61
 * 
62
 * @version 21/11/2007
63
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
64
 */
65
public class ExtendedFileFilter extends FileFilter {
66
	String description = null;
67

  
68
	ArrayList extensions = new ArrayList();
69

  
70
	/**
71
	 * Constructor de un ExtendedFileFilter
72
	 */
73
	public ExtendedFileFilter() {
74
	}
75

  
76
	/**
77
	 * Construye un ExtendedFileFilter con una extensi?n ya agregada
78
	 * @param extension
79
	 */
80
	public ExtendedFileFilter(String extension) {
81
		addExtension(extension);
82
	}
83

  
84
	/**
85
	 * A?ade una extensi?n a la lista de extensiones soportadas
86
	 * @param extension
87
	 */
88
	public void addExtension(String extension) {
89
		if (extension == null)
90
			return;
91

  
92
		extensions.add(extension);
93
	}
94

  
95
	/*
96
	 * (non-Javadoc)
97
	 * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
98
	 */
99
	public boolean accept(File f) {
100
		if (f.isDirectory())
101
			return true;
102

  
103
		String s = f.getName();
104
		int i = s.lastIndexOf('.');
105

  
106
		if (i > 0 && i < s.length() - 1) {
107
			String extension = s.substring(i + 1).toLowerCase();
108
			for (int j = 0; j < extensions.size(); j++) {
109
				if (extensions.get(j).toString().toLowerCase().equals(extension))
110
					return true;
111
			}
112
		}
113

  
114
		return false;
115
	}
116

  
117
	/**
118
	 * Normaliza el nombre de un fichero, a?adiendo la extension si fuera
119
	 * necesario
120
	 * @param file
121
	 * @return
122
	 */
123
	public String getNormalizedFilename(File file) {
124
		String s = file.getName();
125
		int i = s.lastIndexOf('.');
126

  
127
		if (i > 0 && i < s.length() - 1) {
128
			String extension = s.substring(i + 1).toLowerCase();
129
			for (int j = 0; j < extensions.size(); j++) {
130
				if (extensions.get(j).toString().toLowerCase().equals(extension))
131
					return file.toString();
132
			}
133
		}
134

  
135
		return file.toString() + "." + extensions.get(0).toString().toLowerCase();
136
	}
137

  
138
	/*
139
	 * (non-Javadoc)
140
	 * @see javax.swing.filechooser.FileFilter#getDescription()
141
	 */
142
	public String getDescription() {
143
		String format1 = "";
144
		String format2 = "";
145
		for (int j = 0; j < extensions.size(); j++) {
146
			if (format1.length() != 0) {
147
				format1 = format1 + ", ";
148
				format2 = format2 + "; ";
149
			}
150
			// Files JPG, GIF, ... (*.jpg; *.gif ...)
151
			if (j >= 4) {
152
				format1 = "...";
153
				format2 = "...";
154
				break;
155
			}
156
			format1 = format1 + extensions.get(j).toString().toUpperCase();
157
			format2 = format2 + "*." + extensions.get(j).toString().toLowerCase();
158
		}
159
		if (description == null)
160
			return "files" + " " + format1 + " (" + format2 + ")";
161

  
162
		return description + " (" + format2 + ")";
163
	}
164

  
165
	/**
166
	 * Especifica la descripcion del item
167
	 * @param description the description to set
168
	 */
169
	public void setDescription(String description) {
170
		this.description = description;
171
	}
172

  
173
	/**
174
	 * Borra una extension de la lista de extensiones
175
	 * @param extension
176
	 */
177
	public void removeExtension(String extension){
178
		extensions.remove(extension);
179
 }
180

  
181
	/**
182
	 * Borra todas las extensiones existentes
183
	 */
184
	public void clearExtensions(){
185
		extensions.clear();
186
	}
187

  
188
	/**
189
	 * Devuelve una lista con las extensiones disponibles
190
	 * @return
191
	 */
192
	public ArrayList getExtensions(){
193
		return extensions;
194
	}
195
}
0 196

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/util/GenericBasePanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.util;
23

  
24
/**
25
 * Clase no abstracta para instanciar un BasePanel generico
26
 * 18/08/2008
27
 * @author Nacho Brodin nachobrodin@gmail.com
28
 */
29
public class GenericBasePanel extends BasePanel {
30
	private static final long serialVersionUID = 1L;
31

  
32
	/*
33
	 * (non-Javadoc)
34
	 * @see org.gvsig.raster.util.BasePanel#init()
35
	 */
36
	protected void init() {
37
	}
38

  
39
	/*
40
	 * (non-Javadoc)
41
	 * @see org.gvsig.raster.util.BasePanel#translate()
42
	 */
43
	protected void translate() {
44
	}	
45
}
0 46

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/util/BasePanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.util;
23

  
24
import java.awt.Component;
25
import java.awt.event.ActionListener;
26
import java.awt.event.KeyListener;
27
import java.awt.event.MouseListener;
28
import java.util.ArrayList;
29

  
30
import javax.swing.AbstractButton;
31
import javax.swing.JPanel;
32

  
33
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

  
37
/**
38
 * Clase base para los paneles gr?ficos. 
39
 * 
40
 * 17/07/2008
41
 * @author Nacho Brodin nachobrodin@gmail.com
42
 */
43
public abstract class BasePanel extends JPanel {
44
	private static final long    serialVersionUID         = -8877600252349334979L;
45
	private boolean	             enableValueChangedEvent  = true;
46
	
47
	public static final int      KEYLISTENER              = 0;
48
	public static final int      ACTIONLISTENER           = 1;
49
	public static final int      MOUSELISTENER            = 2;
50
	private static final Logger  logger                   = LoggerFactory.getLogger(DefaultFLyrRaster.class);
51
	
52
	/**
53
	 * Obtiene una instancia de una clase generica que hereda de BasePanel
54
	 * @return BasePanel
55
	 */
56
	public static BasePanel getInstance() {
57
		return new GenericBasePanel();
58
	}
59
	
60
	/**
61
	 * Obtiene la traducci?n de la cadena de texto
62
	 * @param parent Ventana padre
63
	 * @param text Cadena a traducir
64
	 * @return Cadena de texto traducida
65
	 */
66
	public String getText(Object parent, String key) {
67
		 if (key == null)
68
	            return null;
69
	        String translation = org.gvsig.i18n.Messages.getText(key, false);
70
	        if (translation != null)
71
	            return translation;
72
	        else {
73
	            logger.debug("Can't find translation for ''{1}''.", key);
74
	            return key;
75
	        }
76
	}
77
	
78
	/**
79
	 * Obtiene la traducci?n de la cadena de texto
80
	 * @param text Cadena a traducir
81
	 * @return Cadena de texto traducida
82
	 */
83
	public String getText(String text) {
84
		return getText(this, text);
85
	}
86
	
87
	/**
88
	 * Asigna el valor para la activaci?n y desactivaci?n del evento de cambio de valor en
89
	 * las cajas de texto.
90
	 * @param enableValueChangedEvent
91
	 */
92
	public void setEnableValueChangedEvent(boolean enableValueChangedEvent) {
93
		this.enableValueChangedEvent = enableValueChangedEvent;
94
	}
95
	
96
	/**
97
	 * Obtiene el valor para la activaci?n y desactivaci?n del evento de cambio de valor en
98
	 * las cajas de texto.
99
	 * @param enableValueChangedEvent
100
	 */
101
	public boolean isEnableValueChangedEvent() {
102
		return this.enableValueChangedEvent;
103
	}
104
	
105
	/**
106
	 * Obtiene la lista de componentes del panel. Si dentro tiene alg?n BasePanel
107
	 * consulta la lista de componentes de este y la devuelve.
108
	 * @return
109
	 */
110
	public ArrayList getComponentList() {
111
		ArrayList listComp = new ArrayList();
112
		for (int i = 0; i < this.getComponentCount(); i++) {
113
			if(getComponent(i) instanceof BasePanel) {
114
				ArrayList list = ((BasePanel)getComponent(i)).getComponentList();
115
				for (int j = 0; j < list.size(); j++) 
116
					listComp.add(list.get(j));
117
			} else
118
				listComp.add(getComponent(i));
119
		}
120
		return listComp;
121
	}
122
	
123
	/**
124
	 * Registra un listener en todos los componentes contenidos en este panel.
125
	 * @param type Tipo de listener definido por las variables est?ticas en esta clase
126
	 * @param listener Objeto listener del tipo correcto
127
	 */
128
	public void registerListener(int type, Object listener) {
129
		ArrayList listComp = getComponentList();
130
		if(type == KEYLISTENER) {
131
			if(listener instanceof KeyListener) {
132
				for (int i = 0; i < listComp.size(); i++)
133
					if(listComp.get(i) instanceof Component)
134
						((Component)listComp.get(i)).addKeyListener((KeyListener)listener);
135
			}
136
		}
137
		if(type == ACTIONLISTENER) {
138
			if(listener instanceof ActionListener) {
139
				for (int i = 0; i < listComp.size(); i++)
140
					if(listComp.get(i) instanceof AbstractButton)
141
						((AbstractButton)listComp.get(i)).addActionListener((ActionListener)listener);
142
			}
143
		}
144
		if(type == MOUSELISTENER) {
145
			if(listener instanceof MouseListener) {
146
				for (int i = 0; i < listComp.size(); i++)
147
					if(listComp.get(i) instanceof Component)
148
						((Component)listComp.get(i)).addMouseListener((MouseListener)listener);
149
			}
150
		}
151
	}
152
	
153
	/**
154
	 * Traducci?n centralizada de los componentes de una panel
155
	 */
156
	protected abstract void translate();
157
	
158
	/**
159
	 * Acciones de inicializaci?n
160
	 */
161
	protected abstract void init();
162
}
0 163

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/util/CancelTaskImpl.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.util;
23

  
24
import org.gvsig.compat.net.ICancellable;
25
import org.gvsig.tools.task.Cancellable;
26

  
27
/**
28
 * All tasks which use libRemoteServices need an object that implements ICancellable
29
 * to cancel processes.
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public class CancelTaskImpl implements ICancellable {
33
	private boolean       cancel = false;
34
	private Cancellable   c      = null;
35
	
36
	public CancelTaskImpl() {
37
	}
38
	
39
	public CancelTaskImpl(Cancellable c) {
40
		this.c = c;
41
	}
42
	
43
	/*
44
	 * (non-Javadoc)
45
	 * @see org.gvsig.compat.net.ICancellable#getID()
46
	 */
47
	public Object getID() {
48
		return this;
49
	}
50

  
51
	/*
52
	 * (non-Javadoc)
53
	 * @see org.gvsig.compat.net.ICancellable#isCanceled()
54
	 */
55
	public boolean isCanceled() {
56
		if(c != null)
57
			return c.isCanceled();
58
		return cancel;
59
	}
60
	
61
	/**
62
	 * Cancel the task
63
	 * @param cancel
64
	 */
65
	public void setCanceled(boolean cancel) {
66
		if(c != null)
67
			c.setCanceled(cancel);
68
		this.cancel = cancel;
69
	}
70
}
0 71

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/legend/ImageLegend.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.legend;
23

  
24
import java.awt.Image;
25

  
26
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
27
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
28
import org.gvsig.fmap.mapcontext.rendering.legend.IRasterLegend;
29
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
30
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
31
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34

  
35
/**
36
 * This object is for rasters which returns its legend as a image
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 *
39
 */
40
public class ImageLegend implements IRasterLegend, IHasImageLegend {
41
	private Image    image = null;
42
	
43
	public ImageLegend(Image image) {
44
		this.image = image;
45
	}
46
	
47
	public Image getImageLegend() {
48
		return image;
49
	}
50
	
51
	public Object clone() throws CloneNotSupportedException {
52
		return new ImageLegend(image);
53
	}
54
	
55
	public void addLegendListener(LegendContentsChangedListener listener) {
56
		
57
	}
58

  
59
	public ILegend cloneLegend() {
60
		try {
61
			return (ILegend)clone();
62
		} catch (CloneNotSupportedException e) {
63
		}
64
		return null;
65
	}
66

  
67
	public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) {
68
		
69
	}
70

  
71
	public ISymbol getDefaultSymbol() {
72
		return null;
73
	}
74

  
75
	public LegendContentsChangedListener[] getListeners() {
76
		return null;
77
	}
78

  
79
	public void removeLegendListener(LegendContentsChangedListener listener) {
80
		
81
	}
82

  
83
	public void loadFromState(PersistentState state)
84
			throws PersistenceException {
85
		
86
	}
87

  
88
	public void saveToState(PersistentState state) throws PersistenceException {
89
		
90
	}
91

  
92
	public String getPathImage() {
93
		return null;
94
	}
95

  
96
}
0 97

  
org.gvsig.raster/tags/buildNumber_28/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/legend/ColorTableLegend.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.legend;
23

  
24
import java.awt.Color;
25
import java.util.Arrays;
26
import java.util.List;
27

  
28
import org.gvsig.fmap.dal.coverage.RasterLocator;
29
import org.gvsig.fmap.dal.coverage.datastruct.ColorItem;
30
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
31
import org.gvsig.fmap.dal.coverage.util.MathUtils;
32
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend;
33
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
34
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
35
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
36
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
37
import org.gvsig.symbology.SymbologyLocator;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43
import org.gvsig.tools.persistence.PersistentState;
44
import org.gvsig.tools.persistence.exception.PersistenceException;
45

  
46
/**
47
 * Leyenda para tablas de color aplicadas a un raster.
48
 *
49
 * @version 27/06/2007
50
 * @author Nacho Brodin (nachobrodin@gmail.com)
51
 */
52
public class ColorTableLegend implements IClassifiedLegend, ILegend {
53
	public static final String  COLOR_TABLE_LEGEND_DYNCLASS_NAME = "ColorTableLegend";
54
	private static final String FIELD_SYMBOLS                    = "symbols";
55
	private static final String FIELD_DESCRIPTIONS               = "descriptions";
56

  
57
	private ISymbol[]           symbols                          = null;
58
	private String[]            desc                             = null;
59

  
60
	/**
61
	 * Crea una leyenda de tipo ColorTableLegend a partir de un objeto ColorTable
62
	 * @param colorTable
63
	 * @return ColorTableLegend
64
	 */
65
	public static ColorTableLegend createLegend(ColorTable colorTable) {
66
		if ((colorTable == null) || (colorTable.getColorItems() == null))
67
			return null;
68
		MathUtils math = RasterLocator.getManager().getMathUtils();
69
		
70
		ILineSymbol line = SymbologyLocator.getSymbologyManager().createSimpleLineSymbol();
71
		line.setLineColor(Color.BLACK);
72
		ISymbol[] symbol = new ISymbol[colorTable.getColorItems().size()];
73
		String[] desc = new String[colorTable.getColorItems().size()];
74

  
75
		String nameClass = null;
76
		for (int i = 0; i < colorTable.getColorItems().size(); i++) {
77
			IFillSymbol s = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol();
78
			s.setOutline(line);
79
			s.setFillColor(((ColorItem) colorTable.getColorItems().get(i)).getColor());
80
			nameClass = ((ColorItem) colorTable.getColorItems().get(i)).getNameClass();
81
			if ((nameClass == null) || (nameClass.equals(""))){
82
				if (i < (colorTable.getColorItems().size() - 1)){
83
					desc[i] = "[" + math.format(((ColorItem) colorTable.getColorItems().get(i)).getValue(), 2) + " , " + math.format(((ColorItem) colorTable.getColorItems().get(i + 1)).getValue(), 2) + "[ ";
84
				}else{
85
					desc[i] = "[" + math.format(((ColorItem) colorTable.getColorItems().get(i)).getValue(), 2) + "] ";
86
				}
87
			}else{
88
				desc[i] = ((ColorItem) colorTable.getColorItems().get(i)).getNameClass();
89
			}	
90
			symbol[i] = s;
91
		}
92

  
93
		return new ColorTableLegend(symbol, desc);
94
	}
95

  
96
	/**
97
	 * Leyenda para tablas de color raster.
98
	 * @param s Lista de simbolos
99
	 * @param d Lista de descripciones de simbolos
100
	 */
101
	public ColorTableLegend(ISymbol[] s, String[] d) {
102
		symbols = s;
103
		desc = d;
104
	}
105

  
106
	/**
107
	 * Empty constructor used only for persistence purposes.
108
	 */
109
	public ColorTableLegend() {
110
	}
111

  
112
	/*
113
	 * (non-Javadoc)
114
	 * @see com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend#getDescriptions()
115
	 */
116
	public String[] getDescriptions() {
117
		return desc;
118
	}
119

  
120
	/*
121
	 * (non-Javadoc)
122
	 * @see com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend#getSymbols()
123
	 */
124
	public ISymbol[] getSymbols() {
125
		return symbols;
126
	}
127

  
128
	/*
129
	 * (non-Javadoc)
130
	 * @see com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend#getValues()
131
	 */
132
	public Object[] getValues() {
133
		return desc;
134
	}
135

  
136
	/*
137
	 * (non-Javadoc)
138
	 * @see com.iver.cit.gvsig.fmap.rendering.ILegend#cloneLegend()
139
	 */
140
	public ILegend cloneLegend() {
141
		return null;
142
	}
143

  
144
	/*
145
	 * (non-Javadoc)
146
	 * @see com.iver.cit.gvsig.fmap.rendering.ILegend#getDefaultSymbol()
147
	 */
148
	public ISymbol getDefaultSymbol() {
149
		return null;
150
	}
151

  
152
	/*
153
	 * (non-Javadoc)
154
	 * @see com.iver.cit.gvsig.fmap.rendering.ILegend#getSLDString(java.lang.String)
155
	 */
156
	public String getSLDString(String layerName) {
157
		return null;
158
	}
159

  
160
	/*
161
	 * (non-Javadoc)
162
	 * @see com.iver.utiles.IPersistance#getClassName()
163
	 */
164
	public String getClassName() {
165
		return null;
166
	}
167

  
168
	public void addLegendListener(LegendContentsChangedListener listener) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff