svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / RasterToolsUtil.java @ 12499
History | View | Annotate | Download (6.79 KB)
1 |
/* 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.rastertools; |
20 |
|
21 |
import java.awt.Component; |
22 |
import java.io.File; |
23 |
import java.util.ArrayList; |
24 |
|
25 |
import javax.swing.JOptionPane; |
26 |
|
27 |
import org.gvsig.gui.beans.propertiespanel.PropertiesComponent; |
28 |
import org.gvsig.gui.beans.propertiespanel.PropertyStruct; |
29 |
import org.gvsig.raster.dataset.Params; |
30 |
import org.gvsig.raster.dataset.Params.Param; |
31 |
|
32 |
import com.iver.andami.PluginServices; |
33 |
|
34 |
/**
|
35 |
* Herramientas de uso general y que son dependientes de gvSIG, FMap o de
|
36 |
* libUIComponents.
|
37 |
* En caso de no serlo existe una clase independiente de cualquier proyecto dentro de
|
38 |
* libRaster para este tipo de funciones.
|
39 |
*
|
40 |
* @version 31/05/2007
|
41 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
42 |
*
|
43 |
*/
|
44 |
public class RasterToolsUtil { |
45 |
|
46 |
/**
|
47 |
* Selecciona los controles del panel de propiedades a partir de los par?mtros
|
48 |
* obtenidos del driver. Este m?todo realiza una transformaci?n entre Params
|
49 |
* obtenido del driver de escritura y los par?metros del panel de propiedades.
|
50 |
*
|
51 |
* @param panel Panel de propiedades
|
52 |
* @param params Par?metros del driver
|
53 |
*/
|
54 |
public static void loadPropertiesFromWriterParams(PropertiesComponent pComp, Params params) { |
55 |
for (int i = 0; i < params.getNumParams(); i++) { |
56 |
Param p = params.getParam(i); |
57 |
String name = p.id;
|
58 |
String key = p.id;
|
59 |
Object[] types = null; |
60 |
int selectedValue = 0; |
61 |
|
62 |
switch(p.type) {
|
63 |
case Params.CHECK:
|
64 |
pComp.addValue(name, key, new Boolean((String) p.defaultValue), types);break; |
65 |
case Params.CHOICE:
|
66 |
ArrayList list = new ArrayList(); |
67 |
for (int j = 0; j < p.list.length; j++) { |
68 |
list.add(p.list[j]); |
69 |
if(((String) p.defaultValue).compareTo(p.list[j]) == 0) |
70 |
selectedValue = j; |
71 |
} |
72 |
types = new Object[]{new Integer(PropertiesComponent.TYPE_COMBO), list}; |
73 |
pComp.addValue(name, key, new Integer(selectedValue), types); |
74 |
break;
|
75 |
case Params.SLIDER:
|
76 |
types = new Object[]{new Integer(PropertiesComponent.TYPE_SLIDER), new Integer(p.list[0]), new Integer(p.list[1])}; |
77 |
pComp.addValue(name, key, new Integer((String) p.defaultValue), types); |
78 |
break;
|
79 |
} |
80 |
} |
81 |
} |
82 |
|
83 |
/**
|
84 |
* Carga los par?metros del escritor WriterParams con los valores obtenidos de la
|
85 |
* ventana de propiedades.
|
86 |
*/
|
87 |
public static void loadWriterParamsFromPropertiesPanel(PropertiesComponent pComp, Params params) { |
88 |
ArrayList values = pComp.getValues();
|
89 |
for (int iParam = 0; iParam < params.getNumParams(); iParam++) { |
90 |
Param p = (Param)params.getParam(iParam); |
91 |
for (int iValue = 0; iValue < values.size(); iValue++) { |
92 |
PropertyStruct prop = ((PropertyStruct)values.get(iValue)); |
93 |
if(p.id.compareTo(prop.getKey()) == 0) { |
94 |
switch(p.type) {
|
95 |
case Params.CHECK:
|
96 |
p.defaultValue = String.valueOf(((Boolean)prop.getNewValue()).booleanValue()); |
97 |
break;
|
98 |
case Params.CHOICE:
|
99 |
p.defaultValue = p.list[((Integer)prop.getNewValue()).intValue()];
|
100 |
break;
|
101 |
case Params.SLIDER:
|
102 |
p.defaultValue = String.valueOf(((Integer)prop.getNewValue()).intValue()); |
103 |
} |
104 |
break;
|
105 |
} |
106 |
} |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Funci?n que devuelve true si se tiene permiso de escritura en la ruta indicada en el
|
112 |
* par?metro path y false si no los tiene.
|
113 |
* @param path Ruta a comprobar los permisosv
|
114 |
* @param pluginObject si es distinto de null se obtiene un mensaje de advertencia y sirve como par?metro para
|
115 |
* getText de la traducci?n. Si es null no se mostrar? ventana de advertencia
|
116 |
* @return true si se tiene permiso de escritura en la ruta indicada en el
|
117 |
* par?metro path y false si no los tiene.
|
118 |
*/
|
119 |
public static boolean canWrite(String path, Object pluginObject) { |
120 |
File f = new File(path); |
121 |
if(f.exists() && f.canWrite())
|
122 |
return true; |
123 |
else {
|
124 |
if(pluginObject != null) |
125 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
126 |
PluginServices.getText(pluginObject, "error_escritura"));
|
127 |
return false; |
128 |
} |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Muestra un dialogo con un texto y un bot?n Si o No.
|
133 |
* @param msg Mensaje a mostrar en el dialogo.
|
134 |
* @param parentWindow Ventana desde la que se lanza el dialogo
|
135 |
* @return El bot?n seleccionado por el usuario. true si ha seleccionado "si" y
|
136 |
* false si ha seleccionado "no"
|
137 |
*/
|
138 |
public static boolean messageBoxYesOrNot(String msg, Object parentWindow){ |
139 |
String string1 = PluginServices.getText(parentWindow, "yes"); |
140 |
String string2 = PluginServices.getText(parentWindow, "no"); |
141 |
Object[] options = {string1, string2}; |
142 |
int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
143 |
PluginServices.getText(parentWindow, msg), |
144 |
PluginServices.getText(parentWindow, "confirmacion"),
|
145 |
JOptionPane.YES_NO_OPTION,
|
146 |
JOptionPane.QUESTION_MESSAGE,
|
147 |
null,
|
148 |
options, |
149 |
string1); |
150 |
if (n == JOptionPane.YES_OPTION) |
151 |
return true; |
152 |
else
|
153 |
return false; |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Muestra un dialogo de error con un texto y un bot?n de aceptar.
|
158 |
* @param msg Mensaje a mostrar en el dialogo.
|
159 |
* @param parentWindow Ventana desde la que se lanza el dialogo
|
160 |
*/
|
161 |
public static void messageBoxError(String msg, Object parentWindow){ |
162 |
String string = PluginServices.getText(parentWindow, "accept"); |
163 |
Object[] options = {string}; |
164 |
JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
165 |
PluginServices.getText(parentWindow, msg), |
166 |
PluginServices.getText(parentWindow, "confirmacion"),
|
167 |
JOptionPane.OK_OPTION,
|
168 |
JOptionPane.ERROR_MESSAGE,
|
169 |
null,
|
170 |
options, |
171 |
string); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* Muestra un dialogo de informaci?n con un texto y un bot?n de aceptar.
|
176 |
* @param msg Mensaje a mostrar en el dialogo.
|
177 |
* @param parentWindow Ventana desde la que se lanza el dialogo
|
178 |
*/
|
179 |
public static void messageBoxInfo(String msg, Object parentWindow){ |
180 |
String string = PluginServices.getText(parentWindow, "accept"); |
181 |
Object[] options = {string}; |
182 |
JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
183 |
PluginServices.getText(parentWindow, msg), |
184 |
PluginServices.getText(parentWindow, "confirmacion"),
|
185 |
JOptionPane.OK_OPTION,
|
186 |
JOptionPane.INFORMATION_MESSAGE,
|
187 |
null,
|
188 |
options, |
189 |
string); |
190 |
} |
191 |
} |