svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / calculator / gui / CalculatorPanel.java @ 19178
History | View | Annotate | Download (24.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.calculator.gui; |
42 |
|
43 |
import info.clearthought.layout.TableLayout; |
44 |
|
45 |
import java.awt.BorderLayout; |
46 |
import java.awt.GridBagConstraints; |
47 |
import java.awt.GridBagLayout; |
48 |
import java.awt.Insets; |
49 |
import java.awt.event.FocusEvent; |
50 |
import java.awt.event.FocusListener; |
51 |
import java.awt.event.MouseAdapter; |
52 |
import java.awt.event.MouseEvent; |
53 |
import java.awt.event.MouseListener; |
54 |
import java.util.HashMap; |
55 |
import java.util.Iterator; |
56 |
import java.util.Set; |
57 |
|
58 |
import javax.swing.BorderFactory; |
59 |
import javax.swing.JButton; |
60 |
import javax.swing.JCheckBox; |
61 |
import javax.swing.JPanel; |
62 |
import javax.swing.JScrollPane; |
63 |
import javax.swing.JTextArea; |
64 |
import javax.swing.JTree; |
65 |
import javax.swing.border.BevelBorder; |
66 |
import javax.swing.border.CompoundBorder; |
67 |
import javax.swing.border.EmptyBorder; |
68 |
import javax.swing.border.TitledBorder; |
69 |
import javax.swing.tree.DefaultMutableTreeNode; |
70 |
import javax.swing.tree.DefaultTreeModel; |
71 |
import javax.swing.tree.TreePath; |
72 |
|
73 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
74 |
import org.gvsig.remotesensing.calculator.gui.listener.CalculatorPanelListener; |
75 |
import org.nfunk.jep.JEP; |
76 |
|
77 |
import com.iver.andami.PluginServices; |
78 |
import com.iver.cit.gvsig.fmap.MapContext; |
79 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
80 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
81 |
|
82 |
/**
|
83 |
* Panel que implementa el comportamiento b?sico de una calculadora
|
84 |
* cuyas variables pueden ser asociadas a las bandas de las capas raster
|
85 |
* cargadas en una vista.
|
86 |
*
|
87 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
88 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
89 |
* @version 19/10/2007
|
90 |
*/
|
91 |
|
92 |
public class CalculatorPanel extends JPanel implements FocusListener{ |
93 |
|
94 |
private static final long serialVersionUID = 1L; |
95 |
|
96 |
//-------JBUTTON---------//
|
97 |
private JButton salvar; |
98 |
private JButton recuperar; |
99 |
|
100 |
//-------PANEL---------//
|
101 |
|
102 |
private JPanel centerPanel; |
103 |
private JPanel expresionPanel; |
104 |
|
105 |
//-------JTEXTAREA---------//
|
106 |
private JTextArea jTextExpresion; |
107 |
|
108 |
//-------JSCROLLPANE---------//
|
109 |
private JScrollPane scrollExpresion; |
110 |
private JScrollPane scrollTree; |
111 |
private JScrollPane scrollVariables; |
112 |
|
113 |
//--------JTREE--------------//
|
114 |
private JTree jtree; |
115 |
|
116 |
// ------ JCheckBox----------//
|
117 |
private JCheckBox jCheckExtent; |
118 |
|
119 |
|
120 |
//----------------------------------------//
|
121 |
private KeysPanel kp;
|
122 |
private TableFormat jTableVariables;
|
123 |
private MapContext m_MapContext = null; |
124 |
private View view = null; |
125 |
private HashMap m_Constants; |
126 |
private HashMap qWindowsHash = null; |
127 |
|
128 |
/**
|
129 |
* Elementos de la tabla de variablas que debe permanecer fijo
|
130 |
* independientemente la expresi?n.
|
131 |
*/
|
132 |
private HashMap persistentVarTable = null; |
133 |
|
134 |
private final String nombreBandas="Band"; |
135 |
private JEP parser = null; |
136 |
private CalculatorPanelListener listener = null; |
137 |
|
138 |
private boolean checkVisible = true; |
139 |
|
140 |
/**
|
141 |
* @param calculatorDialog
|
142 |
* @param view vista de la aplicacion
|
143 |
*/
|
144 |
public CalculatorPanel(View view) { |
145 |
super();
|
146 |
this.view = view;
|
147 |
if (view != null) |
148 |
m_MapContext = view.getModel().getMapContext(); |
149 |
|
150 |
listener = new CalculatorPanelListener(this); |
151 |
Inicializar(); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* @param calculatorDialog
|
156 |
* @param view vista de la aplicacion
|
157 |
*/
|
158 |
public CalculatorPanel(View view, boolean checkVisible) { |
159 |
super();
|
160 |
this.checkVisible = checkVisible;
|
161 |
this.view = view;
|
162 |
if (view != null) |
163 |
m_MapContext = view.getModel().getMapContext(); |
164 |
|
165 |
listener = new CalculatorPanelListener(this); |
166 |
Inicializar(); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* Inicializar los elementos del Panel CalculatorPanel
|
171 |
*/
|
172 |
private void Inicializar(){ |
173 |
|
174 |
JPanel principalPanel = new JPanel(); |
175 |
BorderLayout bd=new BorderLayout(); |
176 |
principalPanel.setLayout(bd); |
177 |
kp=new KeysPanel(getJTextExpression());
|
178 |
//agregar el panel central
|
179 |
principalPanel.add(getCenterPanel(), BorderLayout.CENTER);
|
180 |
//this.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
|
181 |
principalPanel.setBorder( new EmptyBorder(3, 3, 3, 3)); |
182 |
|
183 |
MouseListener m = new MouseAdapter() { |
184 |
public void mousePressed(MouseEvent e) { |
185 |
jTableVariables.setEnEspera(false);
|
186 |
} |
187 |
}; |
188 |
|
189 |
kp.getJButton0().addMouseListener(m); |
190 |
kp.getJButton1().addMouseListener(m); |
191 |
kp.getJButton2().addMouseListener(m); |
192 |
kp.getJButton3().addMouseListener(m); |
193 |
kp.getJButton4().addMouseListener(m); |
194 |
kp.getJButton5().addMouseListener(m); |
195 |
kp.getJButton6().addMouseListener(m); |
196 |
kp.getJButton7().addMouseListener(m); |
197 |
kp.getJButton8().addMouseListener(m); |
198 |
kp.getJButton9().addMouseListener(m); |
199 |
kp.getJButtonMinus().addMouseListener(m); |
200 |
kp.getJButtonPlus().addMouseListener(m); |
201 |
kp.getJButtonBrackets().addMouseListener(m); |
202 |
kp.getJButtonDivide().addMouseListener(m); |
203 |
kp.getJButtonMultiply().addMouseListener(m); |
204 |
kp.getJButtonDot().addMouseListener(m); |
205 |
|
206 |
this.setLayout(new BorderLayout()); |
207 |
this.add(principalPanel, BorderLayout.CENTER); |
208 |
} |
209 |
|
210 |
|
211 |
/**
|
212 |
* Define los elementos del panel central: JTree, Tabla de Variables y calculadora
|
213 |
* @return panel central
|
214 |
*/
|
215 |
public JPanel getCenterPanel() { |
216 |
|
217 |
if (centerPanel==null){ |
218 |
centerPanel=new JPanel(); |
219 |
centerPanel.setLayout(new GridBagLayout()); |
220 |
GridBagConstraints c = new GridBagConstraints(); |
221 |
c.fill = GridBagConstraints.BOTH;
|
222 |
|
223 |
c.insets=new Insets(2,2,0,2); |
224 |
c.weightx = 0.75;
|
225 |
c.gridx = 0;
|
226 |
c.gridy = 0;
|
227 |
// Agregar jtree
|
228 |
getScrollTree().setSize(50,70); |
229 |
centerPanel.add(getScrollTree(), c); |
230 |
|
231 |
c.insets=new Insets(2,2,0,2); |
232 |
c.weightx = 1.0;
|
233 |
c.gridx = 1;
|
234 |
c.gridy = 0;
|
235 |
getScrollVariables().setSize(50,70); |
236 |
getJTableVariables().getTableFormat().getColumn(PluginServices.getText(this, "valor")).setPreferredWidth(180); |
237 |
// Agregar la tabla de variables
|
238 |
centerPanel.add(getScrollVariables(), c); |
239 |
|
240 |
c.weightx = 0.0;
|
241 |
c.gridx = 2;
|
242 |
c.gridy = 0;
|
243 |
//Agregar el KeyPanel
|
244 |
centerPanel.add(kp, c); |
245 |
|
246 |
c.insets=new Insets(2,2,0,2); |
247 |
c.weightx = 1.0;
|
248 |
c.gridwidth=2;
|
249 |
c.gridx = 0;
|
250 |
c.gridy = 1;
|
251 |
//Agregar check habilitar distinta extension
|
252 |
if (checkVisible)
|
253 |
centerPanel.add(getJCheckExtent(), c); |
254 |
|
255 |
c.fill = GridBagConstraints.BOTH;
|
256 |
c.insets=new Insets(2,2,0,2); |
257 |
c.weightx = 1.0;
|
258 |
c.gridwidth=3;
|
259 |
c.gridx = 0;
|
260 |
c.gridy = 2;
|
261 |
//Agergar el panel que contiene la expresion
|
262 |
centerPanel.add(getExpresionPanel(), c); |
263 |
} |
264 |
|
265 |
return centerPanel;
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* Crea un panel en el que se agrega el area de texto donde se define la expresi?n.
|
270 |
* @return panel con el area de texto donde se define la expresi?n
|
271 |
*/
|
272 |
public JPanel getExpresionPanel() { |
273 |
|
274 |
if (expresionPanel==null){ |
275 |
expresionPanel=new JPanel(); |
276 |
} |
277 |
expresionPanel.setLayout(new BorderLayout()); |
278 |
expresionPanel.add(getScrollExpresion(),BorderLayout.CENTER);
|
279 |
//Este panel contine los botones de salvar y recuperar
|
280 |
JPanel p=new JPanel(); |
281 |
TableLayout thisLayout = new TableLayout(new double[][] { |
282 |
{5.0,TableLayout.PREFERRED},
|
283 |
{TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}}); |
284 |
|
285 |
//Establece la separaci?n entre los elementos
|
286 |
thisLayout.setHGap(3);
|
287 |
thisLayout.setVGap(3);
|
288 |
|
289 |
p.setLayout(thisLayout); |
290 |
TitledBorder topBorder = BorderFactory.createTitledBorder("Expresi?n"); |
291 |
topBorder.setTitlePosition(TitledBorder.TOP);
|
292 |
//creamos un borde compuesto
|
293 |
expresionPanel.setBorder(new CompoundBorder(topBorder,new EmptyBorder(0,0,0,0))); |
294 |
p.add(getSalvar(),"1,0");
|
295 |
p.add(getRecuperar(),"1,1");
|
296 |
|
297 |
expresionPanel.add(p,BorderLayout.EAST);
|
298 |
return expresionPanel;
|
299 |
} |
300 |
|
301 |
|
302 |
/**
|
303 |
* @return checkbox permitir distinto extend
|
304 |
*/
|
305 |
public JCheckBox getJCheckExtent() { |
306 |
|
307 |
if (jCheckExtent==null){ |
308 |
jCheckExtent=new JCheckBox( PluginServices.getText(this, "distinto_extent"),false); |
309 |
jCheckExtent.addActionListener(listener); |
310 |
} |
311 |
|
312 |
return jCheckExtent;
|
313 |
} |
314 |
|
315 |
|
316 |
/**
|
317 |
* @return arbol con capas, funciones, operadores y constantes
|
318 |
*/
|
319 |
public JTree getJtree() { |
320 |
|
321 |
if (jtree==null){ |
322 |
jtree=new JTree(); |
323 |
jtree.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
324 |
// Rellenar el arbol con los items correspondientes
|
325 |
if (m_MapContext!=null) |
326 |
this.InicizlizaJTree(jtree);
|
327 |
} |
328 |
return jtree;
|
329 |
} |
330 |
|
331 |
|
332 |
/**
|
333 |
* @return area de texto donde se intoduce la expresi?n
|
334 |
*/
|
335 |
public JTextArea getJTextExpression() { |
336 |
|
337 |
if (jTextExpresion==null){ |
338 |
jTextExpresion=new JTextArea(); |
339 |
jTextExpresion.setLineWrap(true);
|
340 |
jTextExpresion.setWrapStyleWord(true);
|
341 |
jTextExpresion.addFocusListener(this);
|
342 |
jTextExpresion.addKeyListener(new CalculatorPanelListener(this)); |
343 |
} |
344 |
|
345 |
return jTextExpresion;
|
346 |
} |
347 |
|
348 |
|
349 |
/**
|
350 |
* @return formato de la tabla
|
351 |
*/
|
352 |
public TableFormat getJTableVariables() {
|
353 |
if (jTableVariables==null){ |
354 |
jTableVariables=new TableFormat(jTextExpresion);
|
355 |
} |
356 |
return jTableVariables;
|
357 |
} |
358 |
|
359 |
|
360 |
/**
|
361 |
* @return scroll con el arbol
|
362 |
*/
|
363 |
public JScrollPane getScrollTree() { |
364 |
if (scrollTree==null){ |
365 |
scrollTree=new JScrollPane(); |
366 |
scrollTree.setViewportView(getJtree()); |
367 |
scrollTree.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
368 |
} |
369 |
return scrollTree;
|
370 |
} |
371 |
|
372 |
|
373 |
/**
|
374 |
* @return scroll con el area de expresi?n
|
375 |
*/
|
376 |
public JScrollPane getScrollExpresion() { |
377 |
if (scrollExpresion==null){ |
378 |
scrollExpresion=new JScrollPane(); |
379 |
scrollExpresion.setViewportView(getJTextExpression()); |
380 |
scrollExpresion.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
381 |
} |
382 |
return scrollExpresion;
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* @return scroll con la tabla de variables
|
387 |
*/
|
388 |
public JScrollPane getScrollVariables() { |
389 |
if (scrollVariables==null){ |
390 |
scrollVariables=new JScrollPane(); |
391 |
} |
392 |
scrollVariables.setViewportView(getJTableVariables().getTableFormat()); |
393 |
scrollVariables.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
394 |
return scrollVariables;
|
395 |
} |
396 |
|
397 |
/**
|
398 |
* @return button cargar expresi?n
|
399 |
*/
|
400 |
public JButton getRecuperar() { |
401 |
if(recuperar==null){ |
402 |
recuperar=new JButton(); |
403 |
recuperar.setText(PluginServices.getText(this,"cargar")); |
404 |
recuperar.addActionListener(listener); |
405 |
} |
406 |
return recuperar;
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* @return button salvar expresi?n
|
411 |
*/
|
412 |
public JButton getSalvar() { |
413 |
if(salvar==null){ |
414 |
salvar=new JButton(); |
415 |
salvar.setText(PluginServices.getText(this,"salvar")); |
416 |
salvar.addActionListener(listener); |
417 |
} |
418 |
return salvar;
|
419 |
} |
420 |
|
421 |
|
422 |
/**
|
423 |
* Metodo que rellena el Jtree con las las capas cargadas en la vista y sus
|
424 |
* bandas correspondientes. Ademas con las funciones, operadores y constantes
|
425 |
* estandar.
|
426 |
*/
|
427 |
void InicizlizaJTree(JTree jTree){ |
428 |
int i;
|
429 |
double dCellsize;
|
430 |
String sName;
|
431 |
//Eliminar el contenido del ?rbol con el que se inicializa por defecto
|
432 |
jTree.setModel(null);
|
433 |
FLayers layers = m_MapContext.getLayers(); |
434 |
//Nodo principal
|
435 |
DefaultMutableTreeNode main = new DefaultMutableTreeNode(PluginServices.getText(this,"elementos_jtree")); |
436 |
DefaultMutableTreeNode node = new DefaultMutableTreeNode(PluginServices.getText(this,"capas_jtree")); |
437 |
DefaultMutableTreeNode child;
|
438 |
DefaultMutableTreeNode bandas;
|
439 |
for (i = 0; i < layers.getLayersCount(); i++){ |
440 |
//obtiene las capas raster de la vista actual
|
441 |
if (layers.getLayer(i) instanceof FLyrRasterSE){ |
442 |
//Nombre por defecto de las bandas
|
443 |
child = new DefaultMutableTreeNode(layers.getLayer(i).getName()); |
444 |
//Obtener las todas las bandas de cada capa raster de la vista
|
445 |
// tomamos el nombre de cada una de las bandas
|
446 |
for (int j=0; j<((FLyrRasterSE) layers.getLayer(i)).getBandCount(); j++){ |
447 |
String s=nombreBandas+(j+1); |
448 |
bandas= new DefaultMutableTreeNode(s); |
449 |
child.add(bandas); |
450 |
} |
451 |
node.add(child); |
452 |
} |
453 |
} |
454 |
main.add(node); |
455 |
|
456 |
//Funciones
|
457 |
String sFunctions[] ={ "sin","cos","tan","asin", "acos","atan","atan2","sinh", |
458 |
"cosh","tanh","asinh", "acosh","atanh","ln","log","exp", |
459 |
"abs","rand","mod","sqrt","if" }; |
460 |
node = new DefaultMutableTreeNode(PluginServices.getText(this,"funciones_jtree")); |
461 |
for (i = 0; i < sFunctions.length; i++){ |
462 |
//agregar los elementos al subarbol
|
463 |
child = new DefaultMutableTreeNode(" " + sFunctions[i] + "() "); |
464 |
node.add(child); |
465 |
} |
466 |
main.add(node); |
467 |
//Operadores
|
468 |
String sOperators[] = {"+","-","*","/","%","!","^","&&","||","<",">","<=",">=", "==","!="}; |
469 |
node = new DefaultMutableTreeNode(PluginServices.getText(this,"operadores_jtree")); |
470 |
for (i = 0; i < sOperators.length; i++){ |
471 |
child = new DefaultMutableTreeNode(" " + sOperators[i] + " "); |
472 |
node.add(child); |
473 |
} |
474 |
main.add(node); |
475 |
//Constantes
|
476 |
node = new DefaultMutableTreeNode(PluginServices.getText(this,"constantes_jtree")); |
477 |
m_Constants = new HashMap(); |
478 |
m_Constants.put("e", " " + Double.toString(Math.E) + " "); |
479 |
m_Constants.put("Pi", " " + Double.toString(Math.PI)+ " "); |
480 |
for (i = 0; i < layers.getLayersCount(); i++){ |
481 |
if (layers.getLayer(i) instanceof FLyrRasterSE){ |
482 |
sName = "Tama?o celda [" + layers.getLayer(i).getName() + "]"; |
483 |
dCellsize =((FLyrRasterSE)layers.getLayer(i)).getCellSize(); |
484 |
m_Constants.put(sName, " " + Double.toString(dCellsize) + " "); |
485 |
} |
486 |
} |
487 |
Set set= m_Constants.keySet();
|
488 |
Iterator iter = set.iterator();
|
489 |
while(iter.hasNext()){
|
490 |
child = new DefaultMutableTreeNode((String)iter.next()); |
491 |
node.add(child); |
492 |
} |
493 |
main.add(node); |
494 |
//asociar el conenido del arbol al jTree
|
495 |
jTree.setModel(new DefaultTreeModel(main)); |
496 |
//GENERAR LOS EVENTOS DEL RAT?N CORRESPONDIENTES
|
497 |
MouseListener ml = new MouseAdapter() { |
498 |
public void mousePressed(MouseEvent e) { |
499 |
int iRow=jtree.getRowForLocation(e.getX(),e.getY());
|
500 |
TreePath path = jtree.getPathForLocation(e.getX(), e.getY());
|
501 |
if( iRow != -1 && e.getClickCount() == 2) { |
502 |
//al hacer doble click sobre un elemento del arbol
|
503 |
insertTextFromTree(path); |
504 |
} |
505 |
} |
506 |
}; |
507 |
jTree.addMouseListener(ml); |
508 |
|
509 |
} |
510 |
|
511 |
/**
|
512 |
* Agrega el texto del ?rbol sobre el que se ha hecho doble click en el cuadro de la expresion
|
513 |
*/
|
514 |
private void insertTextFromTree(TreePath path){ |
515 |
String var;
|
516 |
boolean yaAsignada=false; |
517 |
//Devuelve la ruta de acceso primaria de la ruta de acceso proporcionada.
|
518 |
TreePath parent = path.getParentPath();
|
519 |
if (parent != null && !parent.toString().equals("["+ PluginServices.getText(this,"elementos_jtree")+"]") && !parent.toString().equals("["+PluginServices.getText(this,"elementos_jtree")+", "+ PluginServices.getText(this,"capas_jtree")+"]")){ |
520 |
String sParentName = parent.toString();
|
521 |
//String s = path.getLastPathComponent().toString();;
|
522 |
String s = null; |
523 |
if (parent.getParentPath().toString().equals("["+PluginServices.getText(this,"elementos_jtree")+", "+ PluginServices.getText(this,"capas_jtree")+"]")){ |
524 |
s =path.getParentPath().getLastPathComponent().toString()+"["+ path.getLastPathComponent().toString()+"]"; |
525 |
if(jTableVariables.isEnEspera()){
|
526 |
// Asigna la variable al nuevo valor
|
527 |
int row= jTableVariables.getFilaSeleccionada();
|
528 |
|
529 |
// Tratamiento de la asignacion incluyendo posibilidad de distinto extent
|
530 |
|
531 |
// Tomo la primera que haya asignada
|
532 |
if(checkVisible && !getJCheckExtent().isSelected()){
|
533 |
|
534 |
String layerBand,layerName;
|
535 |
FLyrRasterSE rasterLayer1, rasterLayer2; |
536 |
int filaAsignada=0; |
537 |
|
538 |
for (int i=0; i< getJTableVariables().getTableFormat().getRowCount(); i++) |
539 |
{ |
540 |
|
541 |
layerBand= getJTableVariables().getTableFormat().getValueAt(i,1).toString();
|
542 |
|
543 |
if (!layerBand.equals("")){ |
544 |
// primera variable asignada
|
545 |
filaAsignada=i; |
546 |
break;
|
547 |
} |
548 |
|
549 |
// si no hay ninguna asignada
|
550 |
if (i==getJTableVariables().getTableFormat().getRowCount()-1){ |
551 |
|
552 |
//insertar normalmente
|
553 |
jTableVariables.actualizarVariable(row,s); |
554 |
jTableVariables.setEnEspera(false);
|
555 |
yaAsignada=true;
|
556 |
s="";
|
557 |
} |
558 |
|
559 |
} |
560 |
|
561 |
if (!yaAsignada){
|
562 |
|
563 |
// Se comparan
|
564 |
layerBand= getJTableVariables().getTableFormat().getValueAt(filaAsignada,1).toString();
|
565 |
layerName = layerBand.substring(0,layerBand.indexOf("[")); |
566 |
rasterLayer1 = (FLyrRasterSE)m_MapContext.getLayers().getLayer(layerName); |
567 |
|
568 |
// Variable pasan como argumento
|
569 |
layerName = s.substring(0,s.indexOf("[")); |
570 |
rasterLayer2 = (FLyrRasterSE)m_MapContext.getLayers().getLayer(layerName); |
571 |
|
572 |
if ((rasterLayer1.getFullRasterExtent().height() == rasterLayer2.getFullRasterExtent().height()) && (rasterLayer1.getFullRasterExtent().width() == rasterLayer2.getFullRasterExtent().width())){// iguales){ |
573 |
|
574 |
jTableVariables.actualizarVariable(row,s); |
575 |
jTableVariables.setEnEspera(false);
|
576 |
s="";
|
577 |
|
578 |
} else s=""; |
579 |
} |
580 |
} |
581 |
// Permitiendo tama?os diferentes
|
582 |
else{
|
583 |
jTableVariables.actualizarVariable(row,s); |
584 |
jTableVariables.setEnEspera(false);
|
585 |
s="";
|
586 |
} |
587 |
}else{
|
588 |
// var: almacena el nombre de la variable asociada al valor
|
589 |
var=consultarVariable(s); |
590 |
jTextExpresion.insert(var,jTextExpresion.getCaretPosition()); |
591 |
s="";
|
592 |
} |
593 |
} |
594 |
else
|
595 |
s = path.getLastPathComponent().toString(); |
596 |
if (sParentName.equals("["+PluginServices.getText(this,"elementos_jtree")+", "+ PluginServices.getText(this,"constantes_jtree")+"]")){ |
597 |
if (m_Constants.containsKey(s)){
|
598 |
s = (String) m_Constants.get(s);
|
599 |
}else{
|
600 |
s = "";
|
601 |
} |
602 |
} |
603 |
jTextExpresion.insert(s,jTextExpresion.getCaretPosition()); |
604 |
if (sParentName.equals("["+PluginServices.getText(this,"elementos_jtree")+", "+ PluginServices.getText(this,"funciones_jtree")+"]")){ |
605 |
jTextExpresion.setCaretPosition(jTextExpresion.getCaretPosition() - 2);
|
606 |
} |
607 |
} |
608 |
} |
609 |
|
610 |
/**
|
611 |
* Agregar la variable y el valor a la tabla, haciendo la comprobacion del extent
|
612 |
* @param valor
|
613 |
* @return la variable asociada al valor-->capa[banda]
|
614 |
*/
|
615 |
private String insertVariableToJTable(String valor){ |
616 |
|
617 |
|
618 |
String layerBand,layerName;
|
619 |
FLyrRasterSE rasterLayer1, rasterLayer2; |
620 |
String s;
|
621 |
int filaAsignada = 0; |
622 |
boolean yaAsignada=false; |
623 |
|
624 |
/* Antes de insertar la variable hay que comprobar si no esta marcada la casilla que no hay diferente extent
|
625 |
caso no permitir distinto extent*/
|
626 |
|
627 |
if (checkVisible && !getJCheckExtent().isSelected()){
|
628 |
if (getJTableVariables().getTableFormat().getRowCount()>0){ |
629 |
for (int i=0; i< getJTableVariables().getTableFormat().getRowCount(); i++) |
630 |
{ |
631 |
layerBand= getJTableVariables().getTableFormat().getValueAt(i,1).toString();
|
632 |
if (!layerBand.equals("")){ |
633 |
// primera variable asignada
|
634 |
filaAsignada=i; |
635 |
break;
|
636 |
} |
637 |
// si no hay ninguna asignada
|
638 |
if (i==getJTableVariables().getTableFormat().getRowCount()-1){ |
639 |
s=jTableVariables.InsertRow(null,valor);
|
640 |
getQWindowsHash().put(s,null);
|
641 |
return s;
|
642 |
} |
643 |
} // fin for
|
644 |
|
645 |
// Si la tabla no estaba vacia y habia algun elemento asignado
|
646 |
if (yaAsignada==false){ |
647 |
// Primera variable de la tabla
|
648 |
layerBand= getJTableVariables().getTableFormat().getValueAt(filaAsignada,1).toString();
|
649 |
layerName = layerBand.substring(0,layerBand.indexOf("[")); |
650 |
rasterLayer1 = (FLyrRasterSE)m_MapContext.getLayers().getLayer(layerName); |
651 |
|
652 |
// Variable que me pasan como argumento
|
653 |
layerName = valor.substring(0,valor.indexOf("[")); |
654 |
rasterLayer2 = (FLyrRasterSE)m_MapContext.getLayers().getLayer(layerName); |
655 |
// Se compara si tienen las mismas dimensiones
|
656 |
if ((rasterLayer1.getFullRasterExtent().height() == rasterLayer2.getFullRasterExtent().height()) && (rasterLayer1.getFullRasterExtent().width() == rasterLayer2.getFullRasterExtent().width()) )// && (qWindow.getNY()== qWindow1.getNY()) |
657 |
{ |
658 |
s=jTableVariables.InsertRow(null,valor);
|
659 |
getQWindowsHash().put(s,null);
|
660 |
return s;
|
661 |
} |
662 |
// no tienen las mismas dimensiones
|
663 |
else return ""; |
664 |
} |
665 |
} |
666 |
else {
|
667 |
// Inserto primera variable
|
668 |
s=jTableVariables.InsertRow(null,valor);
|
669 |
getQWindowsHash().put(s,null);
|
670 |
return s;
|
671 |
} |
672 |
} // Si la casilla esta seleccionada.
|
673 |
else {
|
674 |
|
675 |
// Inserto la variable, no hay reestricciones de extent.
|
676 |
s=jTableVariables.InsertRow(null,valor);
|
677 |
getQWindowsHash().put(s,null);
|
678 |
return s;
|
679 |
} |
680 |
return ""; |
681 |
} |
682 |
|
683 |
|
684 |
/**
|
685 |
* Se utiliza para conocer si un determinado valor-->(capa[banda])
|
686 |
* tiene una variable asociada, si no es as? se introduce y
|
687 |
* se le asigna una nueva variable
|
688 |
*
|
689 |
* @param valor
|
690 |
* @return el nombre de la variable asignada a ese valor
|
691 |
*/
|
692 |
private String consultarVariable(String valor){ |
693 |
//obtiene la variable asociada a un valor
|
694 |
String s=jTableVariables.getVariableOf(valor);
|
695 |
//si es s=="" indica que ese valor no est? introducido en la tabla
|
696 |
if (s.equals("")){ |
697 |
String aux;
|
698 |
//aux contiene el nombre de la variable asignada a valor
|
699 |
aux=insertVariableToJTable(valor); |
700 |
return aux;
|
701 |
} |
702 |
return s;
|
703 |
} |
704 |
|
705 |
|
706 |
public void focusLost(FocusEvent e) { |
707 |
|
708 |
if(e.getSource()==jTextExpresion){
|
709 |
jTableVariables.setEnEspera(false);
|
710 |
System.out.println("Evento del textarea: "+jTableVariables.isEnEspera()); |
711 |
} |
712 |
} |
713 |
|
714 |
|
715 |
|
716 |
public void focusGained(FocusEvent e) { |
717 |
|
718 |
} |
719 |
|
720 |
|
721 |
/**
|
722 |
* inicializa el parser y lo devuelve
|
723 |
* @return parser
|
724 |
*/
|
725 |
public JEP initializeParser(){
|
726 |
parser=null;
|
727 |
parser=getParser(); |
728 |
return parser;
|
729 |
|
730 |
} |
731 |
|
732 |
|
733 |
/**
|
734 |
* @return parser
|
735 |
*/
|
736 |
public JEP getParser() {
|
737 |
if (parser==null){ |
738 |
parser = new JEP();
|
739 |
parser.setAllowUndeclared(true);
|
740 |
parser.addStandardFunctions(); |
741 |
} |
742 |
return parser;
|
743 |
} |
744 |
|
745 |
/**
|
746 |
* @return tabla hash con las variables definidas
|
747 |
*/
|
748 |
public HashMap getQWindowsHash() { |
749 |
if (qWindowsHash==null) |
750 |
qWindowsHash = new HashMap(); |
751 |
return qWindowsHash;
|
752 |
} |
753 |
|
754 |
/**
|
755 |
* @return vista actual de la aplicacion
|
756 |
*/
|
757 |
public View getView() { |
758 |
return view;
|
759 |
} |
760 |
|
761 |
public void setPersistentVarTable(HashMap persistentVarTable) { |
762 |
this.persistentVarTable = persistentVarTable;
|
763 |
loadVarTable(); |
764 |
} |
765 |
|
766 |
/**
|
767 |
* Carga la tabla de variables a partir del HasMap de persistencia.
|
768 |
*
|
769 |
*/
|
770 |
private void loadVarTable(){ |
771 |
TableFormat varTable = getJTableVariables(); |
772 |
if (varTable.getCont()>0) |
773 |
varTable.getTableFormat().removeRowSelectionInterval(0,varTable.getCont()-1); |
774 |
for (Iterator iter = persistentVarTable.keySet().iterator(); iter.hasNext();) { |
775 |
String key = (String) iter.next(); |
776 |
varTable.InsertRow(key,(String)persistentVarTable.get(key));
|
777 |
getQWindowsHash().put(key, persistentVarTable.get(key)); |
778 |
} |
779 |
} |
780 |
|
781 |
/**
|
782 |
* Actualiza el HasMap de persistencia con los elementos que tiene la tabla de
|
783 |
* variables.
|
784 |
*
|
785 |
*/
|
786 |
public void updatePersistentVarTable(){ |
787 |
for(int i=0;i<getJTableVariables().getTableFormat().getRowCount();i++){ |
788 |
String var = getJTableVariables().getTableFormat().getValueAt(i,0).toString(); |
789 |
String value = getJTableVariables().getTableFormat().getValueAt(i,1).toString(); |
790 |
persistentVarTable().put(var, value); |
791 |
} |
792 |
} |
793 |
|
794 |
public HashMap persistentVarTable() { |
795 |
return persistentVarTable;
|
796 |
} |
797 |
} |
798 |
|
799 |
|