svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / FPanelLegendValues.java @ 312
History | View | Annotate | Download (9.15 KB)
1 |
/*
|
---|---|
2 |
* Created on 30-abr-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
package com.iver.cit.gvsig.gui.Panels; |
8 |
|
9 |
import java.awt.BorderLayout; |
10 |
import java.awt.Dimension; |
11 |
import java.awt.event.ActionEvent; |
12 |
import java.awt.event.ActionListener; |
13 |
import java.util.ArrayList; |
14 |
import java.util.Comparator; |
15 |
import java.util.TreeMap; |
16 |
|
17 |
import javax.swing.DefaultComboBoxModel; |
18 |
import javax.swing.JButton; |
19 |
import javax.swing.JComboBox; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JOptionPane; |
22 |
import javax.swing.JPanel; |
23 |
|
24 |
import com.iver.cit.gvsig.fmap.FConstant; |
25 |
import com.iver.cit.gvsig.fmap.FLyrVect; |
26 |
import com.iver.cit.gvsig.fmap.FRecordset; |
27 |
import com.iver.cit.gvsig.fmap.FRenderer; |
28 |
import com.iver.cit.gvsig.fmap.FSymbol; |
29 |
import com.iver.cit.gvsig.gui.TOC; |
30 |
import com.iver.mdiApp.Utilities; |
31 |
|
32 |
/**
|
33 |
* @author fjp
|
34 |
*
|
35 |
* To change the template for this generated type comment go to
|
36 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
37 |
*/
|
38 |
public class FPanelLegendValues extends JPanel { |
39 |
|
40 |
private MyListener listener = new MyListener(); |
41 |
// private TOC m_TOC;
|
42 |
private FRenderer m_Renderer;
|
43 |
private FLyrVect m_lyr;
|
44 |
public boolean m_bCacheDirty = true; |
45 |
public String[] m_keysCache; |
46 |
|
47 |
private FSymbolTable m_symbolTable = new FSymbolTable(); |
48 |
|
49 |
private JComboBox m_cboFields; |
50 |
|
51 |
private JButton quitartodo; |
52 |
private JButton quitar; |
53 |
|
54 |
|
55 |
|
56 |
class MyListener implements ActionListener |
57 |
{ |
58 |
//private FLyrShp m_layer;
|
59 |
// private FPanelLegendValues m_Parent;
|
60 |
|
61 |
public MyListener() { // FPanelLegendValues p) { |
62 |
// m_Parent = p;
|
63 |
} |
64 |
|
65 |
public void actionPerformed(ActionEvent e) { |
66 |
|
67 |
// rellenarValue();
|
68 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
69 |
|
70 |
//modificar el combobox de valor
|
71 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
72 |
JComboBox cb = (JComboBox) e.getSource(); |
73 |
String fieldName = (String) cb.getSelectedItem(); |
74 |
System.out.println("Nombre del campo: " + fieldName); |
75 |
m_symbolTable.removeAllItems(); |
76 |
if (fieldName != m_Renderer.getFieldName())
|
77 |
m_bCacheDirty = true;
|
78 |
m_Renderer.setField(fieldName); |
79 |
} |
80 |
|
81 |
|
82 |
//A?adir todos los elementos por valor
|
83 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
84 |
fillTableValues(); |
85 |
} |
86 |
|
87 |
//A?adir un ?nico elemento
|
88 |
if (e.getActionCommand() == "ADD_VALUE") { |
89 |
/* a?adir("Nuevo_Valor");
|
90 |
aceptar.setEnabled(true);
|
91 |
quitartodo.setEnabled(true);
|
92 |
quitar.setEnabled(true); */
|
93 |
} |
94 |
|
95 |
//Vacia la tabla
|
96 |
if (e.getActionCommand() == "REMOVE_ALL") { |
97 |
m_symbolTable.removeAllItems(); |
98 |
// aceptar.setEnabled(false);
|
99 |
} |
100 |
|
101 |
//Quitar solo el elemento seleccionado
|
102 |
if (e.getActionCommand() == "REMOVE") { |
103 |
m_symbolTable.removeSelectedRows(); |
104 |
} |
105 |
|
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
*
|
111 |
*/
|
112 |
public FPanelLegendValues() {
|
113 |
super();
|
114 |
initComponents(); |
115 |
} |
116 |
protected void initComponents() |
117 |
{ |
118 |
/* JLabel label = new JLabel();
|
119 |
label.setIcon(new javax.swing.ImageIcon(Abrir.class.getClassLoader()
|
120 |
.getResource("images/ValoresUnicos.png")));
|
121 |
limagen[1] = new JLabel();
|
122 |
limagen[1] = label; */
|
123 |
|
124 |
JPanel botonestabla = new JPanel(); |
125 |
|
126 |
|
127 |
JButton btnAddAll = new JButton(Utilities.getMessage(this,"Anadir_todos")); |
128 |
btnAddAll.setActionCommand("ADD_ALL_VALUES");
|
129 |
btnAddAll.addActionListener(listener); |
130 |
botonestabla.add(btnAddAll); |
131 |
|
132 |
JButton btnAdd = new JButton(Utilities.getMessage(this,"Anadir")); |
133 |
btnAdd.setActionCommand("ADD_VALUE");
|
134 |
btnAdd.addActionListener(listener); |
135 |
botonestabla.add(btnAdd); |
136 |
|
137 |
quitartodo = new JButton(Utilities.getMessage(this,"Quitar_todos")); |
138 |
quitartodo.setActionCommand("REMOVE_ALL");
|
139 |
quitartodo.addActionListener(listener); |
140 |
botonestabla.add(quitartodo); |
141 |
|
142 |
quitar = new JButton(Utilities.getMessage(this,"Quitar")); |
143 |
quitar.setActionCommand("REMOVE");
|
144 |
quitar.addActionListener(listener); |
145 |
botonestabla.add(quitar); |
146 |
|
147 |
|
148 |
JPanel ptabla = new JPanel(); |
149 |
ptabla.setLayout(new BorderLayout()); |
150 |
|
151 |
m_cboFields = new JComboBox(); |
152 |
m_cboFields.setActionCommand("FIELD_SELECTED");
|
153 |
m_cboFields.addActionListener(listener); |
154 |
m_cboFields.setVisible(true);
|
155 |
JPanel pAux1 = new JPanel(); |
156 |
/* pAux1.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
157 |
"Campo de clasificaci?n",
|
158 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
|
159 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); */
|
160 |
pAux1.setPreferredSize(new Dimension(300,50)); |
161 |
JLabel lblFieldClassification = new JLabel(Utilities.getMessage(this,"Campo_de_clasificacion")); |
162 |
pAux1.add(lblFieldClassification); |
163 |
pAux1.add(m_cboFields); |
164 |
|
165 |
|
166 |
|
167 |
|
168 |
ptabla.add(m_symbolTable, BorderLayout.CENTER);
|
169 |
m_symbolTable.setPreferredSize(new Dimension(400, 200)); |
170 |
this.setLayout(new BorderLayout()); |
171 |
this.add(pAux1, BorderLayout.NORTH); |
172 |
this.add(ptabla, BorderLayout.CENTER); |
173 |
this.add(botonestabla, BorderLayout.SOUTH); |
174 |
} |
175 |
private void fillTableValues() |
176 |
{ |
177 |
FRecordset elRs = m_lyr.getRecordset(); |
178 |
int idField = -1; |
179 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
180 |
System.out.println("Nombre del campo: " + fieldName); |
181 |
m_Renderer.setField(fieldName); |
182 |
|
183 |
m_keysCache = new String[m_lyr.m_NumShapes]; |
184 |
|
185 |
String nomField = m_Renderer.getFieldName();
|
186 |
|
187 |
for (int i=0; i< elRs.getFieldsCount();i++) |
188 |
{ |
189 |
String nomAux = elRs.getFieldName(i).trim();
|
190 |
if (nomField.compareToIgnoreCase(nomAux) == 0) |
191 |
{ |
192 |
idField = i; |
193 |
break;
|
194 |
} |
195 |
} |
196 |
if (idField == -1) |
197 |
{ |
198 |
System.err.println("Campo no reconocido " + nomField); |
199 |
return;
|
200 |
} |
201 |
|
202 |
m_symbolTable.removeAllItems(); |
203 |
int numSymbols = 0; |
204 |
FSymbol theSymbol; |
205 |
// m_Renderer.m_symbolList.clear();
|
206 |
m_Renderer.m_ArrayKeys = new ArrayList(); |
207 |
if (elRs.getFieldType(idField) == FRecordset.STRING)
|
208 |
{ |
209 |
m_Renderer.m_symbolList = new TreeMap(); |
210 |
} |
211 |
else
|
212 |
{ |
213 |
m_Renderer.m_symbolList = new TreeMap( |
214 |
new Comparator() { |
215 |
public int compare(Object o1, Object o2) |
216 |
{ |
217 |
int resul = -1; |
218 |
if ((o1 != null) && (o2 != null)) |
219 |
{ |
220 |
double d2 = Double.parseDouble((String)o2); |
221 |
double d1 = Double.parseDouble((String)o1); |
222 |
resul = (int) (d1-d2);
|
223 |
} |
224 |
return resul;
|
225 |
} |
226 |
} |
227 |
); |
228 |
} |
229 |
|
230 |
String clave;
|
231 |
|
232 |
for (int j = 0; j < m_lyr.m_NumShapes; j++) |
233 |
{ |
234 |
elRs.moveTo(j); |
235 |
|
236 |
clave = elRs.getFieldValueAsString(idField); |
237 |
m_keysCache[j] = clave; |
238 |
|
239 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
240 |
if (!m_Renderer.m_symbolList.containsKey(clave)) {
|
241 |
//si no esta creado el simbolo se crea
|
242 |
theSymbol = new FSymbol(m_lyr.m_shapeType);
|
243 |
theSymbol.m_Descrip = clave; |
244 |
m_Renderer.addSymbol(clave, theSymbol); |
245 |
|
246 |
numSymbols++; |
247 |
|
248 |
if (numSymbols > 100) { |
249 |
JOptionPane.showMessageDialog(this, |
250 |
"M?s 100 de s?mbolos no aportan informaci?n en un plano. Por favor, revise el campo seleccionado.");
|
251 |
break;
|
252 |
} |
253 |
} |
254 |
} // for
|
255 |
|
256 |
System.out.println("Num. Simbolos = " + m_Renderer.m_symbolList.size()); |
257 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.m_symbolList); |
258 |
// ?FILLSYMBOLLISTFROMTABLE ESTAR?A BIEN?????
|
259 |
// m_symbolTable.setFRenderer(m_Renderer);
|
260 |
|
261 |
quitartodo.setEnabled(true);
|
262 |
quitar.setEnabled(true);
|
263 |
|
264 |
m_bCacheDirty = false;
|
265 |
|
266 |
|
267 |
} |
268 |
/**
|
269 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo
|
270 |
* el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
|
271 |
*/
|
272 |
public void fillSymbolListFromTable() |
273 |
{ |
274 |
String clave;
|
275 |
FSymbol theSymbol; |
276 |
|
277 |
// Borramos las anteriores listas:
|
278 |
m_Renderer.m_symbolList.clear(); |
279 |
m_Renderer.m_ArrayKeys.clear(); |
280 |
boolean bRestoValores = false; // PONERLO EN UN CHECKBOX |
281 |
int hasta;
|
282 |
if (bRestoValores)
|
283 |
hasta = m_symbolTable.getRowCount() - 1;
|
284 |
else
|
285 |
hasta = m_symbolTable.getRowCount(); |
286 |
for (int row=0; row < m_symbolTable.getRowCount();row++) |
287 |
{ |
288 |
clave = (String) m_symbolTable.getFieldValue(row,1); |
289 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(row,0);
|
290 |
theSymbol.m_Descrip = (String) m_symbolTable.getFieldValue(row,2); |
291 |
m_Renderer.addSymbol(clave,theSymbol); |
292 |
System.out.println(clave);
|
293 |
} |
294 |
if (bRestoValores)
|
295 |
{ |
296 |
m_Renderer.m_bUseDefaultSymbol = true;
|
297 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta,0);
|
298 |
m_Renderer.setDefaultSymbol(theSymbol); |
299 |
} |
300 |
|
301 |
} |
302 |
|
303 |
public TreeMap getSymList() |
304 |
{ |
305 |
TreeMap resul = new TreeMap(); |
306 |
|
307 |
// m_symbolTable.getModel();
|
308 |
|
309 |
return resul;
|
310 |
} |
311 |
private void fillFieldNames() { |
312 |
|
313 |
FRecordset rs = m_lyr.getRecordset(); |
314 |
String[] nomFields = new String[rs.getFieldsCount()]; |
315 |
for (int i = 0; i < rs.getFieldsCount(); i++) { |
316 |
nomFields[i] = rs.getFieldName(i).trim(); |
317 |
} |
318 |
|
319 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields); |
320 |
m_cboFields.setModel(cM); |
321 |
// fieldsListValor.setSelectedIndex(0);
|
322 |
|
323 |
m_symbolTable.removeAllItems(); |
324 |
|
325 |
} |
326 |
|
327 |
public void setLayer(FLyrVect lyr, FRenderer r) |
328 |
{ |
329 |
// OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL
|
330 |
m_lyr = lyr; |
331 |
m_Renderer = r; |
332 |
|
333 |
fillFieldNames(); |
334 |
// Si es de valor ?nico, rellenamos la tabla
|
335 |
// y seleccionamos el campo que estamos usando
|
336 |
m_symbolTable.removeAllItems(); |
337 |
if (m_Renderer.getLegendType() == FConstant.LEGEND_TYPE_VALUE)
|
338 |
{ |
339 |
m_cboFields.getModel().setSelectedItem(m_Renderer.getFieldName()); |
340 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.m_symbolList); |
341 |
} |
342 |
|
343 |
|
344 |
} |
345 |
|
346 |
} |