svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / Params.java @ 15969
History | View | Annotate | Download (4.57 KB)
1 | 11652 | bsanchez | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | */
|
||
19 | package org.gvsig.raster.dataset; |
||
20 | |||
21 | import java.util.ArrayList; |
||
22 | import java.util.Iterator; |
||
23 | |||
24 | |||
25 | /**
|
||
26 | * Par?metros para los drivers de escritura. Las variables estaticas contenidas representan
|
||
27 | * los tipos de par?metro posibles.
|
||
28 | 12333 | bsanchez | *
|
29 | 11652 | bsanchez | * @version 17/04/2007
|
30 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
31 | */
|
||
32 | 11899 | bsanchez | public class Params implements Cloneable { |
33 | 11652 | bsanchez | public static final int CHECK = 1; |
34 | public static final int CHOICE = 2; |
||
35 | public static final int SLIDER = 3; |
||
36 | public static final int MULTI_CHECK = 4; |
||
37 | 12333 | bsanchez | |
38 | 11652 | bsanchez | /**
|
39 | * Clase que representa un par?metro. Los atributos principales son:
|
||
40 | * <UL>
|
||
41 | * <LI>type: tipo de par?metro que tendr? un valor correspondiente a las variables estaticas de
|
||
42 | 12333 | bsanchez | * Params.</LI>
|
43 | 11652 | bsanchez | * <LI>id: que contiene el identificador del par?metro en cadena de texto</LI>
|
44 | * <LI>defaultValue: que ser? el valor por defecto asignado al par?metro</LI>
|
||
45 | * <LI>list: que contiene una lista de valores con datos asociados al par?metro en concreto</LI>
|
||
46 | * </UL>
|
||
47 | 12333 | bsanchez | * . Por ejemplo, para una selecci?n por lista de valores tendr? la lista de valores a
|
48 | 11652 | bsanchez | * seleccionar. Para un slider tendr? el valor m?ximo, el m?nimo, el intervalo menor
|
49 | * y el mayor. Para una selecci?n por check esta lista puede ser vacia.
|
||
50 | 12333 | bsanchez | *
|
51 | 11652 | bsanchez | * @version 17/04/2007
|
52 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
53 | *
|
||
54 | */
|
||
55 | public class Param { |
||
56 | public int type = -1; |
||
57 | public String id = null; |
||
58 | 12333 | bsanchez | public Object defaultValue = null; |
59 | 11652 | bsanchez | public String[] list = null; |
60 | } |
||
61 | 12333 | bsanchez | |
62 | 11652 | bsanchez | private ArrayList params = new ArrayList(); |
63 | 12333 | bsanchez | |
64 | 11652 | bsanchez | /**
|
65 | * Obtiene el par?metro de la posici?n definida por param
|
||
66 | * @param param Posici?n del par?metro
|
||
67 | * @return Objeto Param
|
||
68 | */
|
||
69 | public Param getParam(int param) { |
||
70 | return (Param)params.get(param);
|
||
71 | } |
||
72 | 12333 | bsanchez | |
73 | 11652 | bsanchez | /**
|
74 | * Asigna el par?metro pasado a la lista de par?metros necesitados por el driver
|
||
75 | * @param param
|
||
76 | */
|
||
77 | public void setParam(Param param) { |
||
78 | params.add(param); |
||
79 | } |
||
80 | 11811 | bsanchez | |
81 | 11652 | bsanchez | /**
|
82 | * Inicializa la lista de par?metros
|
||
83 | */
|
||
84 | public void clear() { |
||
85 | params.clear(); |
||
86 | } |
||
87 | 12333 | bsanchez | |
88 | 11652 | bsanchez | /**
|
89 | * Obtiene un par?metro de la lista a partir de su identificador
|
||
90 | * @param id Identificador del par?metro
|
||
91 | * @return Par?metro o null si no existe
|
||
92 | */
|
||
93 | public Param getParamById(String id) { |
||
94 | for (Iterator iter = params.iterator(); iter.hasNext();) { |
||
95 | Param p = (Param) iter.next(); |
||
96 | 11750 | bsanchez | if (p.id.equals(id))
|
97 | 11652 | bsanchez | return p;
|
98 | } |
||
99 | return null; |
||
100 | } |
||
101 | 12333 | bsanchez | |
102 | 11652 | bsanchez | /**
|
103 | 11750 | bsanchez | * Asigna un par?metro. Si existe este lo reemplaza.
|
104 | 11652 | bsanchez | * @param id Identificador
|
105 | * @param value Valor
|
||
106 | * @param type Tipo
|
||
107 | * @param list Lista de valores
|
||
108 | */
|
||
109 | 12333 | bsanchez | public void setParam(String id, Object value, int type, String[] list) { |
110 | 11652 | bsanchez | Param p = getParamById(id); |
111 | 11750 | bsanchez | if (p == null) |
112 | 11652 | bsanchez | p = new Param();
|
113 | 11750 | bsanchez | |
114 | p.id = id; |
||
115 | p.defaultValue = value; |
||
116 | p.type = type; |
||
117 | p.list = list; |
||
118 | params.add(p); |
||
119 | 11652 | bsanchez | } |
120 | 11811 | bsanchez | |
121 | /**
|
||
122 | * Borra los parametros asociados a ese id
|
||
123 | * @param id
|
||
124 | */
|
||
125 | public void removeParam(String id) { |
||
126 | for (int i = 0; i < params.size(); i++) { |
||
127 | Param p = (Param) params.get(i); |
||
128 | if (p.id.equals(id)) {
|
||
129 | params.remove(i); |
||
130 | i--; |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | 12333 | bsanchez | |
135 | 11652 | bsanchez | /**
|
136 | * Asigna un valor para un par?metro existens. Si no existe no hace nada.
|
||
137 | 12333 | bsanchez | *
|
138 | 11652 | bsanchez | * @param id Identificador del par?metro
|
139 | * @param value Valor a asignar
|
||
140 | */
|
||
141 | 12333 | bsanchez | public void changeParamValue(String id, Object value) { |
142 | 11652 | bsanchez | for (Iterator iter = params.iterator(); iter.hasNext();) { |
143 | Param p = (Param) iter.next(); |
||
144 | if(p.id.equals(id))
|
||
145 | p.defaultValue = value; |
||
146 | } |
||
147 | } |
||
148 | 12333 | bsanchez | |
149 | 11652 | bsanchez | /**
|
150 | * Obtiene el n?mero de par?metros.
|
||
151 | * @return N?mero de par?metros.
|
||
152 | */
|
||
153 | public int getNumParams() { |
||
154 | return params.size();
|
||
155 | } |
||
156 | 12333 | bsanchez | |
157 | 11830 | bsanchez | /**
|
158 | * Devuelve el array de los Params
|
||
159 | * @return
|
||
160 | */
|
||
161 | public ArrayList getParams() { |
||
162 | return params;
|
||
163 | } |
||
164 | 12333 | bsanchez | |
165 | 11899 | bsanchez | /* (non-Javadoc)
|
166 | * @see java.lang.Object#clone()
|
||
167 | */
|
||
168 | public Object clone() throws CloneNotSupportedException { |
||
169 | Object aux = super.clone(); |
||
170 | ((Params) aux).params = (ArrayList) this.params.clone(); |
||
171 | return aux;
|
||
172 | } |
||
173 | 11652 | bsanchez | } |