Revision 2796 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/thememanager/legendmanager/panels/FPanelLegendValues.java
FPanelLegendValues.java | ||
---|---|---|
46 | 46 |
*/ |
47 | 47 |
package com.iver.cit.gvsig.gui.thememanager.legendmanager.panels; |
48 | 48 |
|
49 |
import java.awt.BorderLayout; |
|
50 |
import java.awt.Dimension; |
|
51 |
import java.awt.event.ActionEvent; |
|
52 |
import java.awt.event.ActionListener; |
|
53 |
|
|
54 |
import javax.swing.DefaultComboBoxModel; |
|
55 |
import javax.swing.JButton; |
|
56 |
import javax.swing.JComboBox; |
|
57 |
import javax.swing.JLabel; |
|
58 |
import javax.swing.JOptionPane; |
|
59 |
import javax.swing.JPanel; |
|
60 |
|
|
61 |
import org.apache.log4j.Logger; |
|
62 |
|
|
63 | 49 |
import com.hardcode.gdbms.engine.data.DataSource; |
64 | 50 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
65 | 51 |
import com.hardcode.gdbms.engine.values.NullValue; |
66 | 52 |
import com.hardcode.gdbms.engine.values.Value; |
67 | 53 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
54 |
|
|
68 | 55 |
import com.iver.andami.PluginServices; |
56 |
|
|
69 | 57 |
import com.iver.cit.gvsig.ProjectExtension; |
70 | 58 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
71 | 59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
... | ... | |
75 | 63 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
76 | 64 |
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue; |
77 | 65 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
66 |
|
|
67 |
import org.apache.log4j.Logger; |
|
68 |
|
|
69 |
import java.awt.BorderLayout; |
|
70 |
import java.awt.Dimension; |
|
71 |
import java.awt.event.ActionEvent; |
|
72 |
import java.awt.event.ActionListener; |
|
73 |
|
|
74 |
import javax.swing.DefaultComboBoxModel; |
|
75 |
import javax.swing.JButton; |
|
78 | 76 |
import javax.swing.JCheckBox; |
77 |
import javax.swing.JComboBox; |
|
78 |
import javax.swing.JLabel; |
|
79 |
import javax.swing.JOptionPane; |
|
80 |
import javax.swing.JPanel; |
|
79 | 81 |
|
82 |
|
|
80 | 83 |
/** |
81 |
* @author fjp
|
|
84 |
* DOCUMENT ME!
|
|
82 | 85 |
* |
83 |
* To change the template for this generated type comment go to |
|
84 |
* Window>Preferences>Java>Code Generation>Code and Comments |
|
86 |
* @author fjp To change the template for this generated type comment go to |
|
87 |
* Window>Preferences>Java>Code Generation>Code and |
|
88 |
* Comments |
|
85 | 89 |
*/ |
86 | 90 |
public class FPanelLegendValues extends JPanel implements ILegendPanel { |
87 |
private static Logger logger = Logger.getLogger(FPanelLegendValues.class.getName()); |
|
88 |
private MyListener listener = new MyListener(); |
|
89 |
// private TOC m_TOC; |
|
90 |
private VectorialUniqueValueLegend m_Renderer; |
|
91 |
private ClassifiableVectorial m_lyr; |
|
92 |
//private boolean m_bCacheDirty = true; |
|
93 |
|
|
94 |
private FSymbolTable m_symbolTable = new FSymbolTable("values"); |
|
91 |
private static Logger logger = Logger.getLogger(FPanelLegendValues.class.getName()); |
|
92 |
private MyListener listener = new MyListener(); |
|
95 | 93 |
|
96 |
private JComboBox m_cboFields; |
|
97 |
|
|
98 |
private JButton quitartodo; |
|
99 |
private JButton quitar; |
|
100 |
private JCheckBox chbUseDefault = null; |
|
101 |
private VectorialUniqueValueLegend auxLegend; |
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
class MyListener implements ActionListener |
|
106 |
{ |
|
107 |
//private FLyrShp m_layer; |
|
108 |
// private FPanelLegendValues m_Parent; |
|
94 |
// private TOC m_TOC; |
|
95 |
private VectorialUniqueValueLegend m_Renderer; |
|
96 |
private ClassifiableVectorial m_lyr; |
|
109 | 97 |
|
110 |
public MyListener() { // FPanelLegendValues p) { |
|
111 |
// m_Parent = p; |
|
112 |
} |
|
98 |
//private boolean m_bCacheDirty = true; |
|
99 |
private FSymbolTable m_symbolTable = new FSymbolTable("values"); |
|
100 |
private JComboBox m_cboFields; |
|
101 |
private JButton quitartodo; |
|
102 |
private JButton quitar; |
|
103 |
private JCheckBox chbUseDefault = null; |
|
104 |
private VectorialUniqueValueLegend auxLegend; |
|
113 | 105 |
|
114 |
public void actionPerformed(ActionEvent e) { |
|
106 |
/** |
|
107 |
* |
|
108 |
*/ |
|
109 |
public FPanelLegendValues() { |
|
110 |
super(); |
|
111 |
initComponents(); |
|
112 |
} |
|
115 | 113 |
|
116 |
// rellenarValue(); |
|
117 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
|
114 |
/** |
|
115 |
* DOCUMENT ME! |
|
116 |
*/ |
|
117 |
protected void initComponents() { |
|
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 |
JPanel botonestabla = new JPanel(); |
|
118 | 124 |
|
119 |
//modificar el combobox de valor |
|
120 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
|
121 |
JComboBox cb = (JComboBox) e.getSource(); |
|
122 |
String fieldName = (String) cb.getSelectedItem(); |
|
123 |
System.out.println("Nombre del campo: " + fieldName); |
|
124 |
m_symbolTable.removeAllItems(); |
|
125 |
if (fieldName != m_Renderer.getFieldName()) |
|
126 |
//m_bCacheDirty = true; |
|
127 |
m_Renderer.setFieldName(fieldName); |
|
128 |
} |
|
125 |
JButton btnAddAll = new JButton(PluginServices.getText(this, |
|
126 |
"Anadir_todos")); |
|
127 |
btnAddAll.setActionCommand("ADD_ALL_VALUES"); |
|
128 |
btnAddAll.addActionListener(listener); |
|
129 |
botonestabla.add(btnAddAll); |
|
129 | 130 |
|
131 |
JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir")); |
|
132 |
btnAdd.setActionCommand("ADD_VALUE"); |
|
133 |
btnAdd.addActionListener(listener); |
|
134 |
botonestabla.add(btnAdd); |
|
130 | 135 |
|
131 |
//A?adir todos los elementos por valor
|
|
132 |
if (e.getActionCommand() == "ADD_ALL_VALUES") {
|
|
133 |
fillTableValues();
|
|
134 |
}
|
|
136 |
quitartodo = new JButton(PluginServices.getText(this, "Quitar_todos"));
|
|
137 |
quitartodo.setActionCommand("REMOVE_ALL");
|
|
138 |
quitartodo.addActionListener(listener);
|
|
139 |
botonestabla.add(quitartodo);
|
|
135 | 140 |
|
136 |
//A?adir un ?nico elemento |
|
137 |
if (e.getActionCommand() == "ADD_VALUE") { |
|
138 |
try { |
|
139 |
m_symbolTable.addTableRecord(new FSymbol(m_lyr.getShapeType()),ValueFactory.createValue(0.0),"0 - 0"); |
|
140 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) { |
|
141 |
e1.printStackTrace(); |
|
142 |
} |
|
143 |
/* a?adir("Nuevo_Valor"); |
|
144 |
aceptar.setEnabled(true); |
|
145 |
quitartodo.setEnabled(true); |
|
146 |
quitar.setEnabled(true); */ |
|
147 |
} |
|
141 |
quitar = new JButton(PluginServices.getText(this, "Quitar")); |
|
142 |
quitar.setActionCommand("REMOVE"); |
|
143 |
quitar.addActionListener(listener); |
|
144 |
botonestabla.add(quitar); |
|
148 | 145 |
|
149 |
//Vacia la tabla |
|
150 |
if (e.getActionCommand() == "REMOVE_ALL") { |
|
151 |
m_symbolTable.removeAllItems(); |
|
152 |
// aceptar.setEnabled(false); |
|
153 |
} |
|
146 |
JPanel ptabla = new JPanel(); |
|
147 |
ptabla.setLayout(new BorderLayout()); |
|
154 | 148 |
|
155 |
//Quitar solo el elemento seleccionado
|
|
156 |
if (e.getActionCommand() == "REMOVE") {
|
|
157 |
m_symbolTable.removeSelectedRows();
|
|
158 |
}
|
|
149 |
m_cboFields = new JComboBox();
|
|
150 |
m_cboFields.setActionCommand("FIELD_SELECTED");
|
|
151 |
m_cboFields.addActionListener(listener);
|
|
152 |
m_cboFields.setVisible(true);
|
|
159 | 153 |
|
160 |
} |
|
161 |
} |
|
154 |
JPanel pAux1 = new JPanel(); |
|
162 | 155 |
|
163 |
/** |
|
164 |
* |
|
165 |
*/ |
|
166 |
public FPanelLegendValues() { |
|
167 |
super(); |
|
168 |
initComponents(); |
|
169 |
} |
|
170 |
protected void initComponents() |
|
171 |
{ |
|
172 |
/* JLabel label = new JLabel(); |
|
173 |
label.setIcon(new javax.swing.ImageIcon(Abrir.class.getClassLoader() |
|
174 |
.getResource("images/ValoresUnicos.png"))); |
|
175 |
limagen[1] = new JLabel(); |
|
176 |
limagen[1] = label; */ |
|
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)); |
|
177 | 161 |
|
178 |
JPanel botonestabla = new JPanel(); |
|
179 |
|
|
162 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText( |
|
163 |
this, "Campo_de_clasificacion")); |
|
164 |
pAux1.add(lblFieldClassification); |
|
165 |
pAux1.add(m_cboFields); |
|
180 | 166 |
|
181 |
JButton btnAddAll = new JButton(PluginServices.getText(this,"Anadir_todos")); |
|
182 |
btnAddAll.setActionCommand("ADD_ALL_VALUES"); |
|
183 |
btnAddAll.addActionListener(listener); |
|
184 |
botonestabla.add(btnAddAll); |
|
167 |
ptabla.add(m_symbolTable, BorderLayout.CENTER); |
|
168 |
m_symbolTable.setPreferredSize(new Dimension(400, 200)); |
|
169 |
this.setLayout(new BorderLayout()); |
|
170 |
this.add(pAux1, BorderLayout.NORTH); |
|
171 |
this.add(ptabla, BorderLayout.CENTER); |
|
172 |
this.add(botonestabla, BorderLayout.SOUTH); |
|
173 |
pAux1.add(getChbUseDefault(), null); |
|
174 |
} |
|
185 | 175 |
|
186 |
JButton btnAdd = new JButton(PluginServices.getText(this,"Anadir")); |
|
187 |
btnAdd.setActionCommand("ADD_VALUE"); |
|
188 |
btnAdd.addActionListener(listener); |
|
189 |
botonestabla.add(btnAdd); |
|
176 |
/** |
|
177 |
* DOCUMENT ME! |
|
178 |
*/ |
|
179 |
private void fillTableValues() { |
|
180 |
DataSource elRs; |
|
190 | 181 |
|
191 |
quitartodo = new JButton(PluginServices.getText(this,"Quitar_todos")); |
|
192 |
quitartodo.setActionCommand("REMOVE_ALL"); |
|
193 |
quitartodo.addActionListener(listener); |
|
194 |
botonestabla.add(quitartodo); |
|
182 |
try { |
|
183 |
elRs = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject() |
|
184 |
.getDataSourceByLayer((FLayer) m_lyr); |
|
185 |
logger.debug("elRs.start()"); |
|
186 |
elRs.start(); |
|
195 | 187 |
|
196 |
quitar = new JButton(PluginServices.getText(this,"Quitar")); |
|
197 |
quitar.setActionCommand("REMOVE"); |
|
198 |
quitar.addActionListener(listener); |
|
199 |
botonestabla.add(quitar); |
|
188 |
int idField = -1; |
|
189 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
|
190 |
System.out.println("Nombre del campo: " + fieldName); |
|
191 |
idField = elRs.getFieldIndexByName(fieldName); |
|
192 |
m_Renderer.setFieldName(fieldName); |
|
200 | 193 |
|
201 |
|
|
202 |
JPanel ptabla = new JPanel(); |
|
203 |
ptabla.setLayout(new BorderLayout()); |
|
204 |
|
|
205 |
m_cboFields = new JComboBox(); |
|
206 |
m_cboFields.setActionCommand("FIELD_SELECTED"); |
|
207 |
m_cboFields.addActionListener(listener); |
|
208 |
m_cboFields.setVisible(true); |
|
209 |
JPanel pAux1 = new JPanel(); |
|
210 |
/* pAux1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, |
|
211 |
"Campo de clasificaci?n", |
|
212 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
213 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); */ |
|
214 |
pAux1.setPreferredSize(new Dimension(300,50)); |
|
215 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText(this,"Campo_de_clasificacion")); |
|
216 |
pAux1.add(lblFieldClassification); |
|
217 |
pAux1.add(m_cboFields); |
|
218 |
|
|
219 |
|
|
194 |
//long numReg = elRs.getRowCount(); |
|
195 |
if (idField == -1) { |
|
196 |
System.err.println("Campo no reconocido " + fieldName); |
|
220 | 197 |
|
221 |
|
|
222 |
ptabla.add(m_symbolTable, BorderLayout.CENTER); |
|
223 |
m_symbolTable.setPreferredSize(new Dimension(400, 200)); |
|
224 |
this.setLayout(new BorderLayout()); |
|
225 |
this.add(pAux1, BorderLayout.NORTH); |
|
226 |
this.add(ptabla, BorderLayout.CENTER); |
|
227 |
this.add(botonestabla, BorderLayout.SOUTH); |
|
228 |
pAux1.add(getChbUseDefault(), null); |
|
229 |
} |
|
230 |
private void fillTableValues() |
|
231 |
{ |
|
232 |
DataSource elRs; |
|
233 |
try { |
|
234 |
elRs = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject().getDataSourceByLayer((FLayer) m_lyr); |
|
235 |
logger.debug("elRs.start()"); |
|
236 |
elRs.start(); |
|
237 |
int idField = -1; |
|
238 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
|
239 |
System.out.println("Nombre del campo: " + fieldName); |
|
240 |
idField = elRs.getFieldIndexByName(fieldName); |
|
241 |
m_Renderer.setFieldName(fieldName); |
|
242 |
//long numReg = elRs.getRowCount(); |
|
243 |
|
|
244 |
if (idField == -1) |
|
245 |
{ |
|
246 |
System.err.println("Campo no reconocido " + fieldName); |
|
247 |
return; |
|
248 |
} |
|
249 |
|
|
250 |
m_symbolTable.removeAllItems(); |
|
251 |
int numSymbols = 0; |
|
252 |
FSymbol theSymbol = null; |
|
253 |
|
|
254 |
|
|
255 |
//auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend(); |
|
256 |
auxLegend = LegendFactory.createVectorialUniqueValueLegend(m_lyr.getShapeType()); |
|
257 |
Value clave; |
|
258 |
//Object resul; |
|
259 |
if (chbUseDefault.isSelected()){ |
|
260 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
261 |
auxLegend.addSymbol(new NullUniqueValue(),auxLegend.getDefaultSymbol()); |
|
262 |
|
|
263 |
} |
|
264 |
for (int j = 0; j < elRs.getRowCount(); j++) |
|
265 |
{ |
|
266 |
clave = elRs.getFieldValue(j,idField); |
|
267 |
if (clave instanceof NullValue) |
|
268 |
continue; |
|
269 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo. |
|
270 |
if (auxLegend.getSymbolByValue(clave) == null) { |
|
271 |
//si no esta creado el simbolo se crea |
|
272 |
theSymbol = new FSymbol(m_lyr.getShapeType()); |
|
273 |
|
|
274 |
theSymbol.setDescription(clave.toString()); |
|
275 |
auxLegend.addSymbol(clave,theSymbol); |
|
276 |
|
|
277 |
numSymbols++; |
|
278 |
|
|
198 |
return; |
|
199 |
} |
|
200 |
|
|
201 |
m_symbolTable.removeAllItems(); |
|
202 |
|
|
203 |
int numSymbols = 0; |
|
204 |
FSymbol theSymbol = null; |
|
205 |
|
|
206 |
//auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend(); |
|
207 |
auxLegend = LegendFactory.createVectorialUniqueValueLegend(m_lyr.getShapeType()); |
|
208 |
|
|
209 |
Value clave; |
|
210 |
|
|
211 |
//Object resul; |
|
212 |
if (chbUseDefault.isSelected()) { |
|
213 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
214 |
auxLegend.addSymbol(new NullUniqueValue(), |
|
215 |
auxLegend.getDefaultSymbol()); |
|
216 |
} |
|
217 |
|
|
218 |
for (int j = 0; j < elRs.getRowCount(); j++) { |
|
219 |
clave = elRs.getFieldValue(j, idField); |
|
220 |
|
|
221 |
if (clave instanceof NullValue) { |
|
222 |
continue; |
|
223 |
} |
|
224 |
|
|
225 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo. |
|
226 |
if (auxLegend.getSymbolByValue(clave) == null) { |
|
227 |
//si no esta creado el simbolo se crea |
|
228 |
theSymbol = new FSymbol(m_lyr.getShapeType()); |
|
229 |
|
|
230 |
theSymbol.setDescription(clave.toString()); |
|
231 |
auxLegend.addSymbol(clave, theSymbol); |
|
232 |
|
|
233 |
numSymbols++; |
|
234 |
|
|
279 | 235 |
if (numSymbols == 100) { |
280 | 236 |
int resp = JOptionPane.showConfirmDialog(this, |
281 |
PluginServices.getText(this, "mas_de_100_simbolos"), |
|
282 |
PluginServices.getText(this, "quiere_continuar"), |
|
283 |
JOptionPane.YES_NO_OPTION, |
|
284 |
JOptionPane.WARNING_MESSAGE |
|
285 |
); |
|
286 |
if (resp == JOptionPane.NO_OPTION || resp==JOptionPane.DEFAULT_OPTION) |
|
237 |
PluginServices.getText(this, |
|
238 |
"mas_de_100_simbolos"), |
|
239 |
PluginServices.getText(this, "quiere_continuar"), |
|
240 |
JOptionPane.YES_NO_OPTION, |
|
241 |
JOptionPane.WARNING_MESSAGE); |
|
242 |
|
|
243 |
if ((resp == JOptionPane.NO_OPTION) || |
|
244 |
(resp == JOptionPane.DEFAULT_OPTION)) { |
|
287 | 245 |
return; |
246 |
} |
|
288 | 247 |
} |
289 |
} |
|
290 |
} // for |
|
291 |
|
|
292 |
m_symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
|
293 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
|
294 |
elRs.stop(); |
|
295 |
} catch (DriverException e) { |
|
296 |
// TODO Auto-generated catch block |
|
297 |
e.printStackTrace(); |
|
298 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
299 |
e.printStackTrace(); |
|
300 |
} |
|
248 |
} |
|
249 |
} // for |
|
301 | 250 |
|
302 |
quitartodo.setEnabled(true); |
|
303 |
quitar.setEnabled(true); |
|
304 |
|
|
305 |
//m_bCacheDirty = false; |
|
306 |
|
|
307 |
|
|
308 |
} |
|
309 |
/** |
|
310 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo |
|
311 |
* el symbolList, si no tambi?n el arrayKeys y el defaultRenderer |
|
312 |
*/ |
|
313 |
private void fillSymbolListFromTable() |
|
314 |
{ |
|
315 |
Value clave; |
|
316 |
FSymbol theSymbol; |
|
317 |
|
|
318 |
// Borramos las anteriores listas: |
|
319 |
m_Renderer.clear(); |
|
320 |
boolean bRestoValores = false; // PONERLO EN UN CHECKBOX |
|
321 |
int hasta; |
|
322 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
|
323 |
m_Renderer.setFieldName(fieldName); |
|
324 |
|
|
325 |
if (bRestoValores) |
|
326 |
hasta = m_symbolTable.getRowCount() - 1; |
|
327 |
else |
|
328 |
hasta = m_symbolTable.getRowCount(); |
|
329 |
for (int row=0; row < m_symbolTable.getRowCount();row++) |
|
330 |
{ |
|
331 |
clave = (Value) m_symbolTable.getFieldValue(row,1); |
|
332 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(row,0); |
|
333 |
theSymbol.setDescription((String) m_symbolTable.getFieldValue(row,2)); |
|
334 |
m_Renderer.addSymbol(clave,theSymbol); |
|
335 |
System.out.println(clave); |
|
336 |
} |
|
337 |
if (bRestoValores) |
|
338 |
{ |
|
339 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta,0); |
|
340 |
m_Renderer.setDefaultSymbol(theSymbol); |
|
341 |
} |
|
342 |
|
|
343 |
} |
|
344 |
|
|
345 |
private void fillFieldNames() { |
|
251 |
m_symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
|
252 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
|
253 |
elRs.stop(); |
|
254 |
} catch (DriverException e) { |
|
255 |
// TODO Auto-generated catch block |
|
256 |
e.printStackTrace(); |
|
257 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
258 |
e.printStackTrace(); |
|
259 |
} |
|
346 | 260 |
|
347 |
DataSource rs; |
|
348 |
try { |
|
349 |
rs = ((AlphanumericData)m_lyr).getRecordset(); |
|
350 |
logger.debug("rs.start()"); |
|
351 |
rs.start(); |
|
352 |
String[] nomFields = new String[rs.getFieldCount()]; |
|
353 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
|
354 |
nomFields[i] = rs.getFieldName(i).trim(); |
|
355 |
} |
|
356 |
rs.stop(); |
|
357 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields); |
|
358 |
m_cboFields.setModel(cM); |
|
359 |
// fieldsListValor.setSelectedIndex(0); |
|
360 |
} catch (DriverException e) { |
|
361 |
e.printStackTrace(); |
|
362 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
363 |
e.printStackTrace(); |
|
364 |
} |
|
365 |
|
|
366 |
m_symbolTable.removeAllItems(); |
|
261 |
quitartodo.setEnabled(true); |
|
262 |
quitar.setEnabled(true); |
|
367 | 263 |
|
368 |
} |
|
369 |
|
|
370 |
public void setLayer(FLayer lyr, Legend r) |
|
371 |
{ |
|
372 |
// OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL |
|
373 |
m_lyr = (ClassifiableVectorial) lyr; |
|
374 |
fillFieldNames(); |
|
375 |
|
|
376 |
// Si es de valor ?nico, rellenamos la tabla |
|
377 |
// y seleccionamos el campo que estamos usando |
|
378 |
m_symbolTable.removeAllItems(); |
|
379 |
if (r instanceof VectorialUniqueValueLegend) |
|
380 |
{ |
|
381 |
m_Renderer = (VectorialUniqueValueLegend) r; |
|
382 |
m_cboFields.getModel().setSelectedItem(m_Renderer.getFieldName()); |
|
383 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(), |
|
384 |
m_Renderer.getValues(), m_Renderer.getDescriptions()); |
|
385 |
} |
|
386 |
else |
|
387 |
{ |
|
388 |
try { |
|
389 |
// Si la capa viene con otro tipo de leyenda, creamos |
|
390 |
// una nueva del tipo que maneja este panel |
|
391 |
m_Renderer = new VectorialUniqueValueLegend(m_lyr.getShapeType()); |
|
392 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
393 |
// TODO Auto-generated catch block |
|
394 |
e.printStackTrace(); |
|
395 |
} |
|
396 |
} |
|
264 |
//m_bCacheDirty = false; |
|
265 |
} |
|
397 | 266 |
|
398 |
|
|
399 |
} |
|
400 |
/* (non-Javadoc) |
|
401 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend() |
|
402 |
*/ |
|
403 |
public Legend getLegend() { |
|
404 |
fillSymbolListFromTable(); |
|
405 |
if (auxLegend != null){ |
|
406 |
m_Renderer.setDefaultSymbol(auxLegend.getDefaultSymbol()); |
|
407 |
m_Renderer.useDefaultSymbol(chbUseDefault.isSelected()); |
|
408 |
} |
|
409 |
return m_Renderer; |
|
410 |
} |
|
411 |
/** |
|
412 |
* This method initializes chbUseDefault |
|
413 |
* |
|
414 |
* @return javax.swing.JCheckBox |
|
415 |
*/ |
|
416 |
private JCheckBox getChbUseDefault() { |
|
417 |
if (chbUseDefault == null) { |
|
418 |
chbUseDefault = new JCheckBox(); |
|
419 |
chbUseDefault.setSelected(true); |
|
420 |
chbUseDefault.addActionListener(new java.awt.event.ActionListener() { |
|
421 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
422 |
fillTableValues(); |
|
423 |
} |
|
424 |
}); |
|
425 |
chbUseDefault.setText(PluginServices.getText(this,"resto_valores")); |
|
426 |
} |
|
427 |
return chbUseDefault; |
|
428 |
} |
|
267 |
/** |
|
268 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo |
|
269 |
* el symbolList, si no tambi?n el arrayKeys y el defaultRenderer |
|
270 |
*/ |
|
271 |
private void fillSymbolListFromTable() { |
|
272 |
Value clave; |
|
273 |
FSymbol theSymbol; |
|
429 | 274 |
|
275 |
// Borramos las anteriores listas: |
|
276 |
m_Renderer.clear(); |
|
277 |
|
|
278 |
boolean bRestoValores = false; // PONERLO EN UN CHECKBOX |
|
279 |
int hasta; |
|
280 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
|
281 |
m_Renderer.setFieldName(fieldName); |
|
282 |
|
|
283 |
if (bRestoValores) { |
|
284 |
hasta = m_symbolTable.getRowCount() - 1; |
|
285 |
} else { |
|
286 |
hasta = m_symbolTable.getRowCount(); |
|
287 |
} |
|
288 |
|
|
289 |
for (int row = 0; row < m_symbolTable.getRowCount(); row++) { |
|
290 |
clave = (Value) m_symbolTable.getFieldValue(row, 1); |
|
291 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0); |
|
292 |
theSymbol.setDescription((String) m_symbolTable.getFieldValue(row, 2)); |
|
293 |
m_Renderer.addSymbol(clave, theSymbol); |
|
294 |
System.out.println(clave); |
|
295 |
} |
|
296 |
|
|
297 |
if (bRestoValores) { |
|
298 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta, 0); |
|
299 |
m_Renderer.setDefaultSymbol(theSymbol); |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* DOCUMENT ME! |
|
305 |
*/ |
|
306 |
private void fillFieldNames() { |
|
307 |
DataSource rs; |
|
308 |
|
|
309 |
try { |
|
310 |
rs = ((AlphanumericData) m_lyr).getRecordset(); |
|
311 |
logger.debug("rs.start()"); |
|
312 |
rs.start(); |
|
313 |
|
|
314 |
String[] nomFields = new String[rs.getFieldCount()]; |
|
315 |
|
|
316 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
|
317 |
nomFields[i] = rs.getFieldName(i).trim(); |
|
318 |
} |
|
319 |
|
|
320 |
rs.stop(); |
|
321 |
|
|
322 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields); |
|
323 |
m_cboFields.setModel(cM); |
|
324 |
|
|
325 |
// fieldsListValor.setSelectedIndex(0); |
|
326 |
} catch (DriverException e) { |
|
327 |
e.printStackTrace(); |
|
328 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
329 |
e.printStackTrace(); |
|
330 |
} |
|
331 |
|
|
332 |
m_symbolTable.removeAllItems(); |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* DOCUMENT ME! |
|
337 |
* |
|
338 |
* @param lyr DOCUMENT ME! |
|
339 |
* @param r DOCUMENT ME! |
|
340 |
*/ |
|
341 |
public void setLayer(FLayer lyr, Legend r) { |
|
342 |
// OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL |
|
343 |
m_lyr = (ClassifiableVectorial) lyr; |
|
344 |
fillFieldNames(); |
|
345 |
|
|
346 |
// Si es de valor ?nico, rellenamos la tabla |
|
347 |
// y seleccionamos el campo que estamos usando |
|
348 |
m_symbolTable.removeAllItems(); |
|
349 |
|
|
350 |
if (r instanceof VectorialUniqueValueLegend) { |
|
351 |
m_Renderer = (VectorialUniqueValueLegend) r; |
|
352 |
getChbUseDefault().setSelected(m_Renderer.isUseDefaultSymbol()); |
|
353 |
m_cboFields.getModel().setSelectedItem(m_Renderer.getFieldName()); |
|
354 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(), |
|
355 |
m_Renderer.getValues(), m_Renderer.getDescriptions()); |
|
356 |
} else { |
|
357 |
try { |
|
358 |
// Si la capa viene con otro tipo de leyenda, creamos |
|
359 |
// una nueva del tipo que maneja este panel |
|
360 |
m_Renderer = new VectorialUniqueValueLegend(m_lyr.getShapeType()); |
|
361 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) { |
|
362 |
// TODO Auto-generated catch block |
|
363 |
e.printStackTrace(); |
|
364 |
} |
|
365 |
} |
|
366 |
} |
|
367 |
|
|
368 |
/* (non-Javadoc) |
|
369 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend() |
|
370 |
*/ |
|
371 |
public Legend getLegend() { |
|
372 |
fillSymbolListFromTable(); |
|
373 |
|
|
374 |
if (auxLegend != null) { |
|
375 |
m_Renderer.setDefaultSymbol(auxLegend.getDefaultSymbol()); |
|
376 |
m_Renderer.useDefaultSymbol(chbUseDefault.isSelected()); |
|
377 |
} |
|
378 |
|
|
379 |
return m_Renderer; |
|
380 |
} |
|
381 |
|
|
382 |
/** |
|
383 |
* This method initializes chbUseDefault |
|
384 |
* |
|
385 |
* @return javax.swing.JCheckBox |
|
386 |
*/ |
|
387 |
private JCheckBox getChbUseDefault() { |
|
388 |
if (chbUseDefault == null) { |
|
389 |
chbUseDefault = new JCheckBox(); |
|
390 |
chbUseDefault.setSelected(true); |
|
391 |
chbUseDefault.addActionListener(new java.awt.event.ActionListener() { |
|
392 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
393 |
if (auxLegend==null)auxLegend=m_Renderer; |
|
394 |
if (chbUseDefault.isSelected()) { |
|
395 |
addDefault(); |
|
396 |
} else { |
|
397 |
delDefault(); |
|
398 |
} |
|
399 |
} |
|
400 |
}); |
|
401 |
chbUseDefault.setText(PluginServices.getText(this, "resto_valores")); |
|
402 |
} |
|
403 |
|
|
404 |
return chbUseDefault; |
|
405 |
} |
|
406 |
|
|
407 |
/** |
|
408 |
* A?ade el resto de valores. |
|
409 |
*/ |
|
410 |
private void addDefault() { |
|
411 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
412 |
auxLegend.addSymbol(new NullUniqueValue(), auxLegend.getDefaultSymbol()); |
|
413 |
m_symbolTable.addTableRecord(auxLegend.getDefaultSymbol(), |
|
414 |
new NullUniqueValue(), auxLegend.getDefaultSymbol().getDescription()); |
|
415 |
m_symbolTable.repaint(); |
|
416 |
} |
|
417 |
|
|
418 |
/** |
|
419 |
* Elimina el resto de valores que no estan representados por ning?n otro s?mbolo.. |
|
420 |
*/ |
|
421 |
private void delDefault() { |
|
422 |
auxLegend.delSymbol(new NullUniqueValue()); |
|
423 |
m_symbolTable.removeRow(new NullUniqueValue()); |
|
424 |
m_symbolTable.repaint(); |
|
425 |
} |
|
426 |
|
|
427 |
/** |
|
428 |
* Listener. |
|
429 |
* |
|
430 |
* @author Vicente Caballero Navarro |
|
431 |
*/ |
|
432 |
class MyListener implements ActionListener { |
|
433 |
//private FLyrShp m_layer; |
|
434 |
// private FPanelLegendValues m_Parent; |
|
435 |
public MyListener() { // FPanelLegendValues p) { |
|
436 |
|
|
437 |
// m_Parent = p; |
|
438 |
} |
|
439 |
|
|
440 |
/** |
|
441 |
* DOCUMENT ME! |
|
442 |
* |
|
443 |
* @param e DOCUMENT ME! |
|
444 |
*/ |
|
445 |
public void actionPerformed(ActionEvent e) { |
|
446 |
// rellenarValue(); |
|
447 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
|
448 |
|
|
449 |
//modificar el combobox de valor |
|
450 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
|
451 |
JComboBox cb = (JComboBox) e.getSource(); |
|
452 |
String fieldName = (String) cb.getSelectedItem(); |
|
453 |
System.out.println("Nombre del campo: " + fieldName); |
|
454 |
m_symbolTable.removeAllItems(); |
|
455 |
|
|
456 |
if (fieldName != m_Renderer.getFieldName()) { |
|
457 |
//m_bCacheDirty = true; |
|
458 |
m_Renderer.setFieldName(fieldName); |
|
459 |
} |
|
460 |
} |
|
461 |
|
|
462 |
//A?adir todos los elementos por valor |
|
463 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
|
464 |
fillTableValues(); |
|
465 |
} |
|
466 |
|
|
467 |
//A?adir un ?nico elemento |
|
468 |
if (e.getActionCommand() == "ADD_VALUE") { |
|
469 |
try { |
|
470 |
m_symbolTable.addTableRecord(new FSymbol( |
|
471 |
m_lyr.getShapeType()), |
|
472 |
ValueFactory.createValue(0.0), "0 - 0"); |
|
473 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) { |
|
474 |
e1.printStackTrace(); |
|
475 |
} |
|
476 |
|
|
477 |
/* a?adir("Nuevo_Valor"); |
|
478 |
aceptar.setEnabled(true); |
|
479 |
quitartodo.setEnabled(true); |
|
480 |
quitar.setEnabled(true); */ |
|
481 |
} |
|
482 |
|
|
483 |
//Vacia la tabla |
|
484 |
if (e.getActionCommand() == "REMOVE_ALL") { |
|
485 |
m_symbolTable.removeAllItems(); |
|
486 |
|
|
487 |
// aceptar.setEnabled(false); |
|
488 |
} |
|
489 |
|
|
490 |
//Quitar solo el elemento seleccionado |
|
491 |
if (e.getActionCommand() == "REMOVE") { |
|
492 |
m_symbolTable.removeSelectedRows(); |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
430 | 496 |
} |
Also available in: Unified diff