Revision 2602

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/thememanager/legendmanager/FPanelLegendManager.java
72 72
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
73 73
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
74 74
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.AbstractPanel;
75
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.FPanelLegendBreaks;
76 75
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.FPanelLegendDefault;
77 76
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.FPanelLegendLabels;
78 77
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.FPanelLegendValues;
78
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.PanelLegendBreaks;
79 79
/**
80 80
 * 
81 81
 * @author jmorell
......
93 93
    private Legend renderer; // Le asignaremos la leyenda del primer tema activo.
94 94
    private FPanelLegendDefault m_defaultLegendPanel;
95 95
    private FPanelLegendValues m_valuesLegendPanel;
96
    private FPanelLegendBreaks m_breaksLegendPanel;
96
    private PanelLegendBreaks m_breaksLegendPanel;
97 97
    private FPanelLegendLabels m_labelsLegendPanel;
98 98
    private JPanel cards;
99 99
    private ComandosListener m_actionListener = new ComandosListener(this);
......
160 160
    	//Create the cards.
161 161
        m_defaultLegendPanel = new FPanelLegendDefault();
162 162
        m_valuesLegendPanel = new FPanelLegendValues();
163
        m_breaksLegendPanel = new FPanelLegendBreaks();
163
        m_breaksLegendPanel = new PanelLegendBreaks();
164 164
        m_labelsLegendPanel = new FPanelLegendLabels(this);
165 165
        
166 166
        //Create the panel that contains the cards.
......
468 468
	/**
469 469
	 * @return Returns the m_breaksLegendPanel.
470 470
	 */
471
	public FPanelLegendBreaks getM_breaksLegendPanel() {
471
	public PanelLegendBreaks getM_breaksLegendPanel() {
472 472
		return m_breaksLegendPanel;
473 473
	}
474 474
	/**
475 475
	 * @param legendPanel The m_breaksLegendPanel to set.
476 476
	 */
477
	public void setM_breaksLegendPanel(FPanelLegendBreaks legendPanel) {
477
	public void setM_breaksLegendPanel(PanelLegendBreaks legendPanel) {
478 478
		m_breaksLegendPanel = legendPanel;
479 479
	}
480 480
	/**
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/thememanager/legendmanager/panels/FPanelLegendBreaks.java
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
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.gui.thememanager.legendmanager.panels;
48

  
49
import java.awt.BorderLayout;
50
import java.awt.Color;
51
import java.awt.GridBagConstraints;
52
import java.awt.GridBagLayout;
53
import java.awt.Insets;
54
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
56
import java.text.NumberFormat;
57
import java.util.ArrayList;
58

  
59
import javax.swing.DefaultComboBoxModel;
60
import javax.swing.JButton;
61
import javax.swing.JCheckBox;
62
import javax.swing.JComboBox;
63
import javax.swing.JLabel;
64
import javax.swing.JOptionPane;
65
import javax.swing.JPanel;
66
import javax.swing.JTextField;
67

  
68
import org.apache.log4j.Logger;
69

  
70
import com.hardcode.gdbms.engine.data.DataSource;
71
import com.hardcode.gdbms.engine.values.DateValue;
72
import com.hardcode.gdbms.engine.values.DoubleValue;
73
import com.hardcode.gdbms.engine.values.FloatValue;
74
import com.hardcode.gdbms.engine.values.IntValue;
75
import com.hardcode.gdbms.engine.values.LongValue;
76
import com.hardcode.gdbms.engine.values.NullValue;
77
import com.hardcode.gdbms.engine.values.Value;
78
import com.iver.andami.PluginServices;
79
import com.iver.cit.gvsig.fmap.DriverException;
80
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
81
import com.iver.cit.gvsig.fmap.layers.FLayer;
82
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
83
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
84
import com.iver.cit.gvsig.fmap.rendering.FInterval;
85
import com.iver.cit.gvsig.fmap.rendering.IInterval;
86
import com.iver.cit.gvsig.fmap.rendering.Legend;
87
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
88
import com.iver.cit.gvsig.fmap.rendering.NullInterval;
89
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
90
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel;
91

  
92

  
93
/**
94
 * DOCUMENT ME!
95
 *
96
 * @author fjp To change the template for this generated type comment go to
97
 * 		   Window>Preferences>Java>Code Generation>Code and
98
 * 		   Comments
99
 */
100
public class FPanelLegendBreaks extends JPanel implements ILegendPanel {
101
	private static Logger logger = Logger.getLogger(FPanelLegendBreaks.class.getName());
102
	private MyListener listener = new MyListener();
103

  
104
	// private TOC m_TOC;
105
	private VectorialIntervalLegend m_Renderer;
106
	private ClassifiableVectorial m_lyr;
107
	private FSymbolTable m_symbolTable = new FSymbolTable("intervals");
108
	private JComboBox m_cboFields;
109
	private JComboBox m_cboIntervalType;
110
	private JTextField m_txtNumIntervals;
111
	private ColorChooserPanel m_colorChooser1;
112
	private ColorChooserPanel m_colorChooser2;
113
	private JButton m_btnDeleteAll;
114
	private JButton m_btnDelete;
115
	//private IInterval[] intervals;
116
	///private int tipoClasificacion = VectorialIntervalLegend.NATURAL_INTERVALS;
117
	private int count = 0;
118
	private JCheckBox chbUseDefault = null;
119
	VectorialIntervalLegend auxLegend=null;
120

  
121
	/**
122
	 *
123
	 */
124
	public FPanelLegendBreaks() {
125
		super();
126
		initComponents();
127
	}
128
	
129
	/**
130
	 * EQUAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
131
	 * quieren crear. Los intervalos se crean con un tama?o igual entre ellos.
132
	 *
133
	 * @param numIntervals n?mero de intervalos
134
	 * @param minValue Valor m?nimo.
135
	 * @param maxValue Valor m?ximo.
136
	 *
137
	 * @return Array con los intervalos.
138
	 */
139
	FInterval[] calculateEqualIntervals(int numIntervals,
140
		double minValue, double maxValue,String fieldName) {
141
		FInterval[] theIntervalArray = new FInterval[numIntervals];
142
		double step = (maxValue - minValue) / numIntervals;
143

  
144
		if (numIntervals>1){
145
			theIntervalArray[0] = new FInterval(minValue,minValue+step);
146
		for (int i = 1; i < numIntervals-1; i++) {
147
			theIntervalArray[i] = new FInterval(minValue + (i * step)+0.01,
148
					minValue + ((i + 1) * step));
149
		}
150
			theIntervalArray[numIntervals-1] = new FInterval(minValue + ((numIntervals-1) * step)+0.01,maxValue);
151
		}else{
152
			theIntervalArray[0] = new FInterval(minValue, maxValue);
153
		}
154
		return theIntervalArray;
155
			
156
	}
157

  
158
	/**
159
	 * NATURAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
160
	 * quieren crear. Los intervalos se distribuyen de forma natural.
161
	 *
162
	 * @param numIntervals n?mero de intervalos
163
	 * @param minValue Valor m?nimo.
164
	 * @param maxValue Valor m?ximo.
165
	 *
166
	 * @return Array con los intervalos.
167
	 */
168
	FInterval[] calculateNaturalIntervals(int numIntervals, double minValue,
169
		double maxValue,String fieldName) {
170
		
171
		NaturalIntervalGenerator intervalGenerator = new NaturalIntervalGenerator(((AlphanumericData) m_lyr),fieldName,numIntervals);
172

  
173
		try {
174
			intervalGenerator.generarIntervalos();
175
		} catch (DriverException e) {
176
			e.printStackTrace();
177
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
178
			e.printStackTrace();
179
		}
180
		int numIntervalsGen=intervalGenerator.getNumIntervals()-1;
181
		if (numIntervalsGen==-1){
182
			//TODO cuando no puede calcular los intervalos.
183
			numIntervalsGen=1;
184
		}
185
		FInterval[] theIntervalArray = new FInterval[numIntervalsGen];
186
		if (numIntervalsGen>1){
187
		
188
		theIntervalArray[0] = new FInterval(minValue, intervalGenerator.getValorRuptura(0));
189
		for (int i = 1; i < numIntervalsGen-1; i++) {
190
			theIntervalArray[i] = new FInterval(intervalGenerator.getValInit(
191
						i-1), intervalGenerator.getValorRuptura(i));
192
		}
193
		
194
		theIntervalArray[numIntervalsGen-1] = new FInterval(intervalGenerator.getValInit(
195
				numIntervalsGen-2), maxValue);
196
		}else{
197
			theIntervalArray[numIntervalsGen-1] = new FInterval(minValue, maxValue);
198
		}
199
		return theIntervalArray;
200
	}
201

  
202
	/**
203
	 * QUANTILE INTERVAL Devuelve un Array con el n?mero de intervalos que se
204
	 * quieren crear. Los intervalos se distribuyen de forma quantile.
205
	 *
206
	 * @param numIntervals n?mero de intervalos
207
	 * @param minValue Valor m?nimo.
208
	 * @param maxValue Valor m?ximo.
209
	 *
210
	 * @return Array con los intervalos.
211
	 */
212
	FInterval[] calculateQuantileIntervals(int numIntervals, double minValue,
213
		double maxValue,String fieldName) {
214
		QuantileIntervalGenerator intervalGenerator = new QuantileIntervalGenerator(((AlphanumericData) m_lyr),fieldName,numIntervals);
215

  
216
		try {
217
			intervalGenerator.generarIntervalos();
218
		} catch (DriverException e) {
219
			e.printStackTrace();
220
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
221
			e.printStackTrace();
222
		}
223
		int numIntervalsGen=intervalGenerator.getNumIntervalGen();
224
		FInterval[] theIntervalArray = new FInterval[numIntervalsGen];
225
		if (intervalGenerator.getNumIntervalGen()>1){
226
		theIntervalArray[0] = new FInterval(minValue, intervalGenerator.getValRuptura(0));
227
		for (int i = 1; i < numIntervalsGen-1; i++) {
228
			theIntervalArray[i] = new FInterval(intervalGenerator.getValInit(
229
						i-1), intervalGenerator.getValRuptura(i));
230
		}
231
		
232
		theIntervalArray[numIntervalsGen-1] = new FInterval(intervalGenerator.getValInit(
233
				numIntervalsGen-2), maxValue);
234
		}else{
235
			theIntervalArray[numIntervalsGen-1] = new FInterval(minValue, maxValue);
236
		}
237
		return theIntervalArray;
238
		
239
		
240
	/*	double numQ = count / numIntervals;
241

  
242
		for (int i = 0; i < count; i++) {
243
		}
244

  
245
		return theIntervalArray;
246
*/
247
	}
248

  
249
	/**
250
	 * DOCUMENT ME!
251
	 */
252
	protected void initComponents() {
253
		/* JLabel label = new JLabel();
254
		   label.setIcon(new javax.swing.ImageIcon(Abrir.class.getClassLoader()
255
		                                                                                                      .getResource("images/ValoresUnicos.png")));
256
		   limagen[1] = new JLabel();
257
		   limagen[1] = label; */
258
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
259
		gridBagConstraints.gridx = 5;
260
		gridBagConstraints.gridy = 0;
261
		JPanel botonestabla = new JPanel();
262

  
263
		JButton btnAddAll = new JButton(PluginServices.getText(this,
264
					"Calcular_intervalos"));
265
		btnAddAll.setActionCommand("ADD_ALL_VALUES");
266
		botonestabla.add(btnAddAll);
267

  
268
		JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir"));
269
		btnAdd.setActionCommand("ADD_VALUE");
270
		btnAdd.addActionListener(listener);
271
		botonestabla.add(btnAdd);
272

  
273
		m_btnDeleteAll = new JButton(PluginServices.getText(this, "Quitar_todos"));
274
		m_btnDeleteAll.setActionCommand("REMOVE_ALL");
275
		m_btnDeleteAll.addActionListener(listener);
276
		botonestabla.add(m_btnDeleteAll);
277

  
278
		m_btnDelete = new JButton(PluginServices.getText(this, "Quitar"));
279
		m_btnDelete.setActionCommand("REMOVE");
280
		m_btnDelete.addActionListener(listener);
281
		botonestabla.add(m_btnDelete);
282

  
283
		m_btnDeleteAll.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
284
				public void propertyChange(java.beans.PropertyChangeEvent e) {
285
					if ((e.getPropertyName().equals("enabled"))) {
286
						System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" 
287
					}
288
				}
289
			});
290
		m_btnDelete.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
291
				public void propertyChange(java.beans.PropertyChangeEvent e) {
292
					if ((e.getPropertyName().equals("enabled"))) {
293
						System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" 
294
					}
295
				}
296
			});
297
		btnAddAll.addActionListener(listener);
298

  
299
		JPanel ptabla = new JPanel();
300
		ptabla.setLayout(new BorderLayout());
301

  
302
		m_cboFields = new JComboBox();
303
		m_cboFields.setActionCommand("FIELD_SELECTED");
304
		m_cboFields.addActionListener(listener);
305
		m_cboFields.setVisible(true);
306

  
307
		JPanel pAux1 = new JPanel();
308

  
309
		/* pAux1.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
310
		   "Campo de clasificaci?n",
311
		   javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
312
		   javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); */
313

  
314
		// pAux1.setPreferredSize(new Dimension(300,50));
315
		GridBagLayout gridBag = new GridBagLayout();
316
		pAux1.setLayout(gridBag);
317

  
318
		GridBagConstraints c = new GridBagConstraints();
319

  
320
		c.anchor = GridBagConstraints.WEST;
321

  
322
		JLabel lblFieldClassification = new JLabel(PluginServices.getText(
323
					this, "Campo_de_clasificacion"));
324
		c.gridx = 0;
325
		c.gridy = 0;
326
		c.insets = new Insets(5, 5, 2, 2);
327
		c.gridwidth = 1;
328
		gridBag.setConstraints(lblFieldClassification, c);
329
		pAux1.add(lblFieldClassification);
330

  
331
		c.gridx = 1;
332
		c.gridy = 0;
333
		gridBag.setConstraints(m_cboFields, c);
334
		pAux1.add(m_cboFields);
335

  
336
		JLabel lblNumIntervals = new JLabel(PluginServices.getText(this,
337
					"No_de_intervalos") + ":");
338
		c.gridx = 3;
339
		c.gridy = 0;
340
		gridBag.setConstraints(lblNumIntervals, c);
341
		pAux1.add(lblNumIntervals);
342

  
343
		m_txtNumIntervals = new JTextField(4);
344
		c.gridx = 4;
345
		c.gridy = 0;
346
		gridBag.setConstraints(m_txtNumIntervals, c);
347
		m_txtNumIntervals.setText("5");
348
		pAux1.add(m_txtNumIntervals);
349

  
350
		JLabel lblIntervalType = new JLabel(PluginServices.getText(this,
351
					"tipo_de_intervalo"));
352
		c.gridx = 0;
353
		c.gridy = 1;
354
		c.insets = new Insets(4, 4, 2, 2);
355
		c.gridwidth = 1;
356
		gridBag.setConstraints(lblIntervalType, c);
357
		pAux1.add(lblIntervalType);
358
		
359
		
360
		m_cboIntervalType = new JComboBox();
361
		m_cboIntervalType.setActionCommand("INTERVAL_TYPE");
362
		m_cboIntervalType.addActionListener(listener);
363
		m_cboIntervalType.addItem(PluginServices.getText(this,"equal_intervals"));
364
		m_cboIntervalType.addItem(PluginServices.getText(this,"natural_intervals"));
365
		m_cboIntervalType.addItem(PluginServices.getText(this,"quantile_intervals"));
366
		m_cboIntervalType.setVisible(true);
367

  
368
		c.gridx = 1;
369
		c.gridy = 1;
370
		gridBag.setConstraints(m_cboIntervalType, c);
371
		pAux1.add(m_cboIntervalType);
372

  
373
		c.gridx = 4;
374
		c.gridy = 1;
375
		gridBag.setConstraints(getChbUseDefault(), c);
376
		pAux1.add(getChbUseDefault());
377
		
378
		c.insets = new Insets(2, 2, 2, 2);
379

  
380
		JLabel lblColor1 = new JLabel(PluginServices.getText(this,
381
					"Color_inicio") + ":");
382
		c.gridx = 0;
383
		c.gridy = 2;
384
		gridBag.setConstraints(lblColor1, c);
385
		pAux1.add(lblColor1);
386

  
387
		m_colorChooser1 = new ColorChooserPanel();
388
		m_colorChooser1.setColor(Color.red);
389
		m_colorChooser1.setAlpha(255);
390
		c.gridx = 1;
391
		c.gridy = 2;
392
		gridBag.setConstraints(m_colorChooser1, c);
393
		pAux1.add(m_colorChooser1);
394

  
395
		JLabel lblColor2 = new JLabel(PluginServices.getText(this, "Color_final") +
396
				":");
397
		c.gridx = 3;
398
		c.gridy = 2;
399
		gridBag.setConstraints(lblColor2, c);
400
		pAux1.add(lblColor2);
401

  
402
		m_colorChooser2 = new ColorChooserPanel();
403
		m_colorChooser2.setColor(Color.blue);
404
		m_colorChooser2.setAlpha(255);
405
		c.gridx = 4;
406
		c.gridy = 2;
407
		gridBag.setConstraints(m_colorChooser2, c);
408
		pAux1.add(m_colorChooser2);
409

  
410
		ptabla.add(m_symbolTable, BorderLayout.CENTER);
411
		this.setLayout(new BorderLayout());
412
		this.add(pAux1, BorderLayout.NORTH);
413
		this.add(ptabla, BorderLayout.CENTER);
414
		this.add(botonestabla, BorderLayout.SOUTH);
415
	}
416

  
417
	/**
418
	 * Damos una primera pasada para saber los l?mites inferior y superior y
419
	 * rellenar un array con los valores. Luego dividimos ese array en
420
	 * intervalos.
421
	 */
422
	private void fillTableValues() {
423
		FInterval[] arrayIntervalos = null;
424
		DataSource elRs;
425
		m_symbolTable.removeAllItems();
426

  
427
		try {
428
			elRs = ((AlphanumericData) m_lyr).getRecordset();
429
			logger.debug("elRs.start()");
430
			elRs.start();
431

  
432
			int idField = -1;
433
			int numIntervalos=1;
434
			try{
435
			 numIntervalos= Integer.parseInt(m_txtNumIntervals.getText());
436
			}catch (NumberFormatException e) {
437
				System.out.println("Foramto de n?mero erroneo");
438
			}
439
			String fieldName = (String) m_cboFields.getSelectedItem();
440
			System.out.println("Nombre del campo de clasificaci?n: " +
441
				fieldName);
442
			m_Renderer.setFieldName(fieldName);
443

  
444
			String nomField = m_Renderer.getFieldName();
445

  
446
			// Cogemos el tipo de gradaci?n de colores que quiere el usuario y 
447
			// Creamos el primer y ?ltimo color.
448
			Color startColor = m_colorChooser1.getColor();
449
			m_Renderer.setStartColor(startColor);
450

  
451
			Color endColor = m_colorChooser2.getColor();
452
			m_Renderer.setEndColor(endColor);
453

  
454
			
455

  
456
			for (int i = 0; i < elRs.getFieldCount(); i++) {
457
				String nomAux = elRs.getFieldName(i).trim();
458

  
459
				if (nomField.compareToIgnoreCase(nomAux) == 0) {
460
					idField = i;
461

  
462
					break;
463
				}
464
			}
465

  
466
			if (idField == -1) {
467
				System.err.println("Campo no reconocido " + nomField);
468

  
469
				return;
470
			}
471

  
472
			///m_symbolTable.removeAllItems();
473
			///m_valuesCache = new Object[m_lyr.getSource().getShapeCount()];
474
			int numSymbols = 0;
475
			FSymbol theSymbol;
476
			//Date valorDate;
477
			double minValue = Double.MAX_VALUE;
478
			double maxValue = Double.MIN_VALUE;
479
			//Date minValueDate = null;
480
			//Date maxValueDate = null;
481

  
482
			
483
			auxLegend = LegendFactory.createVectorialIntervalLegend(m_lyr.getShapeType());
484

  
485
			Value clave;
486
			//Object resul;
487
			int symbolType = 0;
488
			count = 0;
489
			
490
			for (int j = 0; j < elRs.getRowCount(); j++) {
491
				clave = elRs.getFieldValue(j, idField);
492

  
493
				IInterval interval = auxLegend.getInterval(clave);
494

  
495
				////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
496
				if (auxLegend.getSymbolByInterval(interval) == null) {
497
					//si no esta creado el simbolo se crea
498
					double valor = 0;
499
					symbolType = m_lyr.getShapeType();
500

  
501
					if (clave instanceof IntValue) {
502
						valor = ((IntValue) clave).getValue();
503
					} else if (clave instanceof DoubleValue) {
504
						valor = ((DoubleValue) clave).getValue();
505
					} else if (clave instanceof FloatValue) {
506
						valor = ((FloatValue) clave).getValue();
507
					} else if (clave instanceof LongValue) {
508
						valor = ((LongValue) clave).getValue();
509
					} else if (clave instanceof DateValue) {
510
						//TODO POR IMPLEMENTAR
511
						///valorDate = elRs.getFieldValueAsDate(idField);
512
						///if (valorDate.before(minValueDate)) minValueDate = valorDate;
513
						///if (valorDate.after(maxValueDate)) maxValueDate = valorDate;
514
					} else if (clave instanceof NullValue){
515
						continue;
516
					}
517

  
518
					if (valor < minValue) {
519
						minValue = (double) valor;
520
					}
521

  
522
					if (valor > maxValue) {
523
						maxValue = (double) valor;
524
					}
525
				}
526

  
527
				count++;
528
			}
529

  
530
			switch (m_Renderer.getIntervalType()) {
531
				case VectorialIntervalLegend.EQUAL_INTERVALS:
532
					arrayIntervalos = calculateEqualIntervals(numIntervalos,
533
							minValue, maxValue,fieldName);
534

  
535
					break;
536

  
537
				case VectorialIntervalLegend.NATURAL_INTERVALS:
538
					arrayIntervalos = calculateNaturalIntervals(numIntervalos,
539
							minValue, maxValue,fieldName);
540

  
541
					break;
542

  
543
				case VectorialIntervalLegend.QUANTILE_INTERVALS:
544
					arrayIntervalos = calculateQuantileIntervals(numIntervalos,
545
							minValue, maxValue,fieldName);
546

  
547
					break;
548
			}
549

  
550
			//intervals = arrayIntervalos;
551

  
552
			FInterval elIntervalo;
553
			NumberFormat.getInstance().setMaximumFractionDigits(2);
554
			m_Renderer.clear();
555

  
556
			int r;
557
			int g;
558
			int b;
559
			int stepR;
560
			int stepG;
561
			int stepB;
562
			r = startColor.getRed();
563
			g = startColor.getGreen();
564
			b = startColor.getBlue();
565
			stepR = (endColor.getRed() - r) / arrayIntervalos.length;
566
			stepG = (endColor.getGreen() - g) / arrayIntervalos.length;
567
			stepB = (endColor.getBlue() - b) / arrayIntervalos.length;
568
			if (chbUseDefault.isSelected()){
569
				auxLegend.getDefaultSymbol().setDescription("Default");
570
				auxLegend.addSymbol(new NullInterval(),auxLegend.getDefaultSymbol());
571
			}
572
			for (int k = 0; k < arrayIntervalos.length; k++) {
573
				elIntervalo = arrayIntervalos[k];
574

  
575
				// clave = elIntervalo; // elIntervalo.getMin() + " - " + elIntervalo.getMax();
576
				// System.out.println("k = " + k + " clave = " + clave);
577
				////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
578
				// if (!m_Renderer.m_symbolList.containsKey(elIntervalo)) {
579
				//si no esta creado el simbolo se crea
580
				theSymbol = new FSymbol(symbolType, new Color(r, g, b));
581
				theSymbol.setDescription(NumberFormat.getInstance().format(elIntervalo.getMin()) +
582
					" - " +
583
					NumberFormat.getInstance().format(elIntervalo.getMax()));
584

  
585
				//////////////////////////////////////
586
				// CALCULAMOS UN COLOR APROPIADO
587
				r = r + stepR;
588
				g = g + stepG;
589
				b = b + stepB;
590

  
591
				/////////////////////////////////
592
				auxLegend.addSymbol(elIntervalo, theSymbol);
593
				System.out.println("addSymbol = " + elIntervalo +
594
					" theSymbol = " + theSymbol.getDescription());
595
				numSymbols++;
596

  
597
				if (numSymbols > 100) {
598
					JOptionPane.showMessageDialog(this,
599
						"M?s 100 de s?mbolos no aportan informaci?n en un plano. Por favor, revise el campo seleccionado.");
600

  
601
					break;
602
				}
603

  
604
				// }
605
			} // for
606

  
607
			System.out.println("Num. Simbolos = " +
608
				auxLegend.getValues().length);
609
			m_symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
610
				auxLegend.getValues(), auxLegend.getDescriptions());
611
			elRs.stop();
612
		} catch (DriverException e) {
613
			// TODO Auto-generated catch block
614
			e.printStackTrace();
615
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
616
			e.printStackTrace();
617
		}
618

  
619
		m_btnDeleteAll.setEnabled(true);
620
		m_btnDelete.setEnabled(true);
621
	}
622

  
623
	/**
624
	 * A partir de los registros de la tabla, regenera el FRenderer. (No solo
625
	 * el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
626
	 */
627
	private void fillSymbolListFromTable() {
628
		//String clave;
629
		FSymbol theSymbol;
630
		IInterval theInterval = null;
631

  
632
		// Borramos las anteriores listas:
633
		m_Renderer.clear();
634

  
635
		//boolean bRestoValores = false; // PONERLO EN UN CHECKBOX
636
		//double from = 0;
637
		//double to = 0;
638
		//String[] arraySplit = new String[2];
639
		//int hasta;
640
		String fieldName = (String) m_cboFields.getSelectedItem();
641
		m_Renderer.setFieldName(fieldName);
642

  
643
		/*if (bRestoValores) {
644
			hasta = m_symbolTable.getRowCount() - 1;
645
		} else {
646
			hasta = m_symbolTable.getRowCount();
647
		}
648
*/
649
		for (int row = 0; row < m_symbolTable.getRowCount(); row++) {
650
			// clave = m_symbolTable.getFieldValue(row,1);
651
			if (!(m_symbolTable.getFieldValue(row, 1) instanceof FInterval)){
652
				theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0);
653
				theSymbol.setDescription((String) m_symbolTable.getFieldValue(row, 2));
654
				m_Renderer.addSymbol(new NullInterval(), theSymbol);
655
			}else{
656
			theInterval = (IInterval) m_symbolTable.getFieldValue(row, 1);
657
			theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0);
658
			theSymbol.setDescription((String) m_symbolTable.getFieldValue(row, 2));
659
			m_Renderer.addSymbol(theInterval, theSymbol);
660
			}
661
			///m_Renderer.m_legendIntervals.add(theInterval);
662
		}
663

  
664
	/*	if (bRestoValores) {
665
			//m_Renderer.m_bUseDefaultSymbol = true;
666
			theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta, 0);
667
			m_Renderer.setDefaultSymbol(theSymbol);
668
		}*/
669
	}
670

  
671
	/**
672
	 * DOCUMENT ME!
673
	 */
674
	private void fillFieldNames() {
675
		DataSource rs = null;
676
		ArrayList nomFields = null;
677

  
678
		try {
679
			rs = ((AlphanumericData) m_lyr).getRecordset();
680
			logger.debug("rs.start()");
681
			rs.start();
682

  
683
			nomFields = new ArrayList();
684

  
685
			Value val;
686

  
687
			for (int i = 0; i < rs.getFieldCount(); i++) {
688
				//TODO deber?a de existir un getFieldType
689
				val = rs.getFieldValue(0, i);
690

  
691
				if (val.getClass() == NullValue.class) {
692
					continue;
693
				}
694

  
695
				if ((val.getClass() == IntValue.class) ||
696
						(val.getClass() == DoubleValue.class) ||
697
						(val.getClass() == FloatValue.class) ||
698
						(val.getClass() == LongValue.class)) {
699
					nomFields.add(rs.getFieldName(i).trim());
700
				}
701
			}
702

  
703
			rs.stop();
704
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
705
			e1.printStackTrace();
706
		} catch (DriverException e) {
707
			e.printStackTrace();
708
		}
709

  
710
		/*        ArrayList nomFields = new ArrayList();
711
		   for (int i = 0; i < rs.getFieldsCount(); i++) {
712
		           if ((rs.getFieldType(i) == FRecordset.INTEGER) ||
713
		                   (rs.getFieldType(i) == FRecordset.DECIMAL) ||
714
		                   (rs.getFieldType(i) == FRecordset.DATE))
715
		           {
716
		                   nomFields.add(rs.getFieldName(i).trim());
717
		           }
718
		
719
		   }
720
		 */
721
		DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray());
722
		m_cboFields.setModel(cM);
723

  
724
		// fieldsListValor.setSelectedIndex(0);
725
		m_symbolTable.removeAllItems();
726
	}
727

  
728
	/**
729
	 * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer,
730
	 * 		com.iver.cit.gvsig.fmap.rendering.Legend)
731
	 */
732
	public void setLayer(FLayer lyr, Legend r) {
733
		//		 m_TOC = t;
734
		// OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL
735
		// m_lyr = (FLyrVect) t.getFirstLyrVectSelected();
736
		m_lyr = (ClassifiableVectorial) lyr;
737
		fillFieldNames();
738

  
739
		if (r instanceof VectorialIntervalLegend) {
740
			m_Renderer = (VectorialIntervalLegend) r;
741
			m_cboFields.getModel().setSelectedItem(m_Renderer.getFieldName());
742
			m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(),
743
				m_Renderer.getValues(), m_Renderer.getDescriptions());
744
			m_colorChooser1.setColor(m_Renderer.getStartColor());
745
			m_colorChooser2.setColor(m_Renderer.getEndColor());
746
			m_colorChooser1.repaint();
747
			m_colorChooser2.repaint();
748
		} else {
749
			try {
750
				// Si la capa viene con otro tipo de leyenda, creamos
751
				// una nueva del tipo que maneja este panel
752
				m_Renderer = new VectorialIntervalLegend(m_lyr.getShapeType());
753
			} catch (DriverException e) {
754
				// TODO Auto-generated catch block
755
				e.printStackTrace();
756
			}
757
		}
758
		m_cboIntervalType.setSelectedIndex(m_Renderer.getIntervalType());
759
	}
760

  
761
	/**
762
	 * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
763
	 */
764
	public Legend getLegend() {
765
		fillSymbolListFromTable();
766
		if (auxLegend != null){
767
			m_Renderer.setDefaultSymbol(auxLegend.getDefaultSymbol());
768
			m_Renderer.useDefaultSymbol(chbUseDefault.isSelected());
769
		}
770
		return m_Renderer;
771
	}
772

  
773
	/**
774
	 * DOCUMENT ME!
775
	 *
776
	 * @author Vicente Caballero Navarro
777
	 */
778
	class MyListener implements ActionListener {
779
		//private FLyrShp m_layer;
780
		// private FPanelLegendValues m_Parent;
781
		public MyListener() { // FPanelLegendValues p) {
782

  
783
			// m_Parent = p;
784
		}
785

  
786
		/**
787
		 * DOCUMENT ME!
788
		 *
789
		 * @param e DOCUMENT ME!
790
		 */
791
		public void actionPerformed(ActionEvent e) {
792
			// rellenarValue();
793
			System.out.println("ActionEvent con " + e.getActionCommand());
794

  
795
			//modificar el combobox de valor
796
			if (e.getActionCommand() == "FIELD_SELECTED") {
797
				JComboBox cb = (JComboBox) e.getSource();
798
				String fieldName = (String) cb.getSelectedItem();
799
				System.out.println("Nombre del campo: " + fieldName);
800
				m_symbolTable.removeAllItems();
801

  
802
				m_Renderer.setFieldName(fieldName);
803
			} else if (e.getActionCommand() == "INTERVAL_TYPE") {
804
				JComboBox cb = (JComboBox) e.getSource();
805
				
806
				if (m_Renderer!=null && cb.getSelectedIndex() != m_Renderer.getIntervalType()) {
807
					m_Renderer.setIntervalType(cb.getSelectedIndex());
808
					m_symbolTable.removeAllItems();
809
				}
810
				
811
			}
812

  
813
			//A?adir todos los elementos por valor
814
			if (e.getActionCommand() == "ADD_ALL_VALUES") {
815
				fillTableValues();
816
			}
817

  
818
			//A?adir un ?nico elemento
819
			if (e.getActionCommand() == "ADD_VALUE") {
820
				try {
821
					m_symbolTable.addTableRecord(new FSymbol(m_lyr.getShapeType()),new FInterval(0,0),"0 - 0");
822
				} catch (DriverException e1) {
823
					e1.printStackTrace();
824
				}
825
			
826
				/*        a?adir("Nuevo_Valor");
827
				   aceptar.setEnabled(true);
828
				   quitartodo.setEnabled(true);
829
				   quitar.setEnabled(true); */
830
			}
831

  
832
			//Vacia la tabla
833
			if (e.getActionCommand() == "REMOVE_ALL") {
834
				m_symbolTable.removeAllItems();
835

  
836
				// aceptar.setEnabled(false);
837
			}
838

  
839
			//Quitar solo el elemento seleccionado
840
			if (e.getActionCommand() == "REMOVE") {
841
				m_symbolTable.removeSelectedRows();
842
			}
843
		}
844
	}
845

  
846
	/**
847
	 * This method initializes chbUseDefault	
848
	 * 	
849
	 * @return javax.swing.JCheckBox	
850
	 */    
851
	private JCheckBox getChbUseDefault() {
852
		if (chbUseDefault == null) {
853
			chbUseDefault = new JCheckBox();
854
			chbUseDefault.setSelected(true);
855
			chbUseDefault.addActionListener(new java.awt.event.ActionListener() { 
856
				public void actionPerformed(java.awt.event.ActionEvent e) {    
857
					fillTableValues();
858
				}
859
			});
860
			chbUseDefault.setText(PluginServices.getText(this,"resto_valores"));
861
		}
862
		return chbUseDefault;
863
	}
864
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/thememanager/legendmanager/panels/FSymbolTable.java
90 90
		this.type = type;
91 91
		table = new JTable();
92 92
		table.setModel(new MyTableModel());
93
		table.setPreferredScrollableViewportSize(new Dimension(500, 70));
93
		table.setPreferredScrollableViewportSize(new Dimension(480, 110));
94 94

  
95 95
		//Create the scroll pane and add the table to it.
96 96
		JScrollPane scrollPane = new JScrollPane(table);
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/thememanager/legendmanager/panels/PanelLegendBreaks.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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
 * 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
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.gui.thememanager.legendmanager.panels;
42

  
43
import javax.swing.DefaultComboBoxModel;
44
import javax.swing.JOptionPane;
45
import javax.swing.JPanel;
46
import javax.swing.JLabel;
47

  
48
import com.hardcode.gdbms.engine.data.DataSource;
49
import com.hardcode.gdbms.engine.values.DateValue;
50
import com.hardcode.gdbms.engine.values.DoubleValue;
51
import com.hardcode.gdbms.engine.values.FloatValue;
52
import com.hardcode.gdbms.engine.values.IntValue;
53
import com.hardcode.gdbms.engine.values.LongValue;
54
import com.hardcode.gdbms.engine.values.NullValue;
55
import com.hardcode.gdbms.engine.values.Value;
56
import com.iver.andami.PluginServices;
57
import javax.swing.JComboBox;
58
import javax.swing.JTextField;
59

  
60
import com.iver.cit.gvsig.fmap.DriverException;
61
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
62
import com.iver.cit.gvsig.fmap.layers.FLayer;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
64
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
65
import com.iver.cit.gvsig.fmap.rendering.FInterval;
66
import com.iver.cit.gvsig.fmap.rendering.IInterval;
67
import com.iver.cit.gvsig.fmap.rendering.Legend;
68
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
69
import com.iver.cit.gvsig.fmap.rendering.NullInterval;
70
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
71
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel;
72

  
73
import java.awt.Color;
74
import javax.swing.JCheckBox;
75
import java.awt.BorderLayout;
76
import java.awt.event.ActionEvent;
77
import java.awt.event.ActionListener;
78
import java.text.NumberFormat;
79
import java.util.ArrayList;
80

  
81
import javax.swing.JButton;
82

  
83
import org.apache.log4j.Logger;
84

  
85
public class PanelLegendBreaks extends JPanel {
86
	private static Logger logger = Logger.getLogger(PanelLegendBreaks.class.getName());
87
	private JPanel panelN = null;
88
	private JLabel lblField = null;
89
	private JComboBox cmbField = null;
90
	private JLabel lblNumIntervals = null;
91
	private JTextField txtNumIntervals = null;
92
	private JLabel lblInitColor = null;
93
	private JLabel lblEndColor = null;
94
	private ColorChooserPanel colorChooserPanel = null;
95
	private ColorChooserPanel colorChooserPanel1 = null;
96
	private JCheckBox chkdefaultvalues = null;
97
	private JLabel lblType = null;
98
	private JComboBox cmbFieldType = null;
99
	private JPanel panelS = null;
100
	private JButton bintervals = null;
101
	private JButton bInsert = null;
102
	private JButton bDelAll = null;
103
	private JButton bDel = null;
104
	private int count = 0;
105
	private ClassifiableVectorial m_lyr;
106
	private VectorialIntervalLegend m_Renderer;
107
	private VectorialIntervalLegend auxLegend=null;
108
	private FSymbolTable m_symbolTable = new FSymbolTable("intervals");
109
	private MyListener listener = new MyListener();
110
	private JPanel panelC = null;
111
	/**
112
	 * This is the default constructor
113
	 */
114
	public PanelLegendBreaks() {
115
		super();
116
		initialize();
117
	}
118

  
119
	/**
120
	 * This method initializes this
121
	 * 
122
	 * @return void
123
	 */
124
	private void initialize() {
125
		this.setLayout(new BorderLayout());
126
		this.setSize(447, 300);
127
		this.add(getPanelN(), java.awt.BorderLayout.NORTH);
128
		this.add(getPanelS(), java.awt.BorderLayout.SOUTH);
129
		this.add(getPanelC(), java.awt.BorderLayout.CENTER);
130
	}
131

  
132
	/**
133
	 * This method initializes panelN	
134
	 * 	
135
	 * @return javax.swing.JPanel	
136
	 */
137
	private JPanel getPanelN() {
138
		if (panelN == null) {
139
			lblType = new JLabel();
140
			lblType.setBounds(new java.awt.Rectangle(3,27,112,20));
141
			lblType.setText(PluginServices.getText(this,"tipo_de_intervalo"));
142
			lblEndColor = new JLabel();
143
			lblEndColor.setBounds(new java.awt.Rectangle(143,51,77,20));
144
			lblEndColor.setText(PluginServices.getText(this, "Color_final"));
145
			lblInitColor = new JLabel();
146
			lblInitColor.setBounds(new java.awt.Rectangle(4,51,77,20));
147
			lblInitColor.setText(PluginServices.getText(this, "Color_inicio"));
148
			lblNumIntervals = new JLabel();
149
			lblNumIntervals.setBounds(new java.awt.Rectangle(282,51,127,20));
150
			lblNumIntervals.setText(PluginServices.getText(this,"No_de_intervalos"));
151
			lblField = new JLabel();
152
			lblField.setBounds(new java.awt.Rectangle(4,1,160,20));
153
			lblField.setText(PluginServices.getText(this,"Campo_de_clasificacion"));
154
			panelN = new JPanel();
155
			panelN.setLayout(null);
156
			panelN.setPreferredSize(new java.awt.Dimension(450,75));
157
			panelN.add(lblField, null);
158
			panelN.add(getJComboBox(), null);
159
			panelN.add(lblNumIntervals, null);
160
			panelN.add(getTxtNumIntervals(), null);
161
			panelN.add(lblInitColor, null);
162
			panelN.add(lblEndColor, null);
163
			panelN.add(getColorChooserPanel(), null);
164
			panelN.add(getColorChooserPanel1(), null);
165
			panelN.add(getChkdefaultvalues(), null);
166
			panelN.add(lblType, null);
167
			panelN.add(getJComboBox1(), null);
168
		}
169
		return panelN;
170
	}
171

  
172
	/**
173
	 * This method initializes jComboBox	
174
	 * 	
175
	 * @return javax.swing.JComboBox	
176
	 */
177
	private JComboBox getJComboBox() {
178
		if (cmbField == null) {
179
			cmbField = new JComboBox();
180
			cmbField.setBounds(new java.awt.Rectangle(168,1,282,20));
181
			cmbField.setActionCommand("FIELD_SELECTED");
182
			cmbField.addActionListener(listener);
183
			cmbField.setVisible(true);
184
		}
185
		return cmbField;
186
	}
187

  
188
	/**
189
	 * This method initializes txtNumIntervals	
190
	 * 	
191
	 * @return javax.swing.JTextField	
192
	 */
193
	private JTextField getTxtNumIntervals() {
194
		if (txtNumIntervals == null) {
195
			txtNumIntervals = new JTextField();
196
			txtNumIntervals.setText("5");
197
			txtNumIntervals.setBounds(new java.awt.Rectangle(408,51,37,20));
198
		}
199
		return txtNumIntervals;
200
	}
201

  
202
	/**
203
	 * This method initializes colorChooserPanel	
204
	 * 	
205
	 * @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel	
206
	 */
207
	private ColorChooserPanel getColorChooserPanel() {
208
		if (colorChooserPanel == null) {
209
			colorChooserPanel = new ColorChooserPanel();
210
			colorChooserPanel.setBounds(new java.awt.Rectangle(85,51,54,20));
211
			colorChooserPanel.setAlpha(255);
212
			colorChooserPanel.setColor(Color.red);
213
		}
214
		return colorChooserPanel;
215
	}
216

  
217
	/**
218
	 * This method initializes colorChooserPanel1	
219
	 * 	
220
	 * @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel	
221
	 */
222
	private ColorChooserPanel getColorChooserPanel1() {
223
		if (colorChooserPanel1 == null) {
224
			colorChooserPanel1 = new ColorChooserPanel();
225
			colorChooserPanel1.setBounds(new java.awt.Rectangle(224,51,54,20));
226
			colorChooserPanel1.setAlpha(255);
227
			colorChooserPanel1.setColor(Color.blue);
228
		}
229
		return colorChooserPanel1;
230
	}
231

  
232
	/**
233
	 * This method initializes chkdefaultvalues	
234
	 * 	
235
	 * @return javax.swing.JCheckBox	
236
	 */
237
	private JCheckBox getChkdefaultvalues() {
238
		if (chkdefaultvalues == null) {
239
			chkdefaultvalues = new JCheckBox();
240
			chkdefaultvalues.setText(PluginServices.getText(this,"resto_valores"));
241
			chkdefaultvalues.setBounds(new java.awt.Rectangle(341,27,109,20));
242
		}
243
		return chkdefaultvalues;
244
	}
245

  
246
	/**
247
	 * This method initializes jComboBox1	
248
	 * 	
249
	 * @return javax.swing.JComboBox	
250
	 */
251
	private JComboBox getJComboBox1() {
252
		if (cmbFieldType == null) {
253
			cmbFieldType = new JComboBox();
254
			cmbFieldType.setBounds(new java.awt.Rectangle(116,27,212,20));
255
			cmbFieldType.setActionCommand("INTERVAL_TYPE");
256
			cmbFieldType.addActionListener(listener);
257
			cmbFieldType.addItem(PluginServices.getText(this,"equal_intervals"));
258
			cmbFieldType.addItem(PluginServices.getText(this,"natural_intervals"));
259
			cmbFieldType.addItem(PluginServices.getText(this,"quantile_intervals"));
260
			cmbFieldType.setVisible(true);
261
		}
262
		return cmbFieldType;
263
	}
264

  
265
	/**
266
	 * This method initializes panelS	
267
	 * 	
268
	 * @return javax.swing.JPanel	
269
	 */
270
	private JPanel getPanelS() {
271
		if (panelS == null) {
272
			panelS = new JPanel();
273
			panelS.setPreferredSize(new java.awt.Dimension(417,32));
274
			panelS.add(getBintervals(), null);
275
			panelS.add(getBInsert(), null);
276
			panelS.add(getBDelAll(), null);
277
			panelS.add(getBDel(), null);
278
		}
279
		return panelS;
280
	}
281

  
282
	/**
283
	 * This method initializes bintervals	
284
	 * 	
285
	 * @return javax.swing.JButton	
286
	 */
287
	private JButton getBintervals() {
288
		if (bintervals == null) {
289
			bintervals = new JButton();
290
			bintervals.setActionCommand("ADD_ALL_VALUES");
291
			bintervals.addActionListener(listener);
292
			bintervals.setText(PluginServices.getText(this,"Calcular_intervalos"));
293
		}
294
		return bintervals;
295
	}
296

  
297
	/**
298
	 * This method initializes bInsert	
299
	 * 	
300
	 * @return javax.swing.JButton	
301
	 */
302
	private JButton getBInsert() {
303
		if (bInsert == null) {
304
			bInsert = new JButton();
305
			bInsert.setActionCommand("ADD_VALUE");
306
			bInsert.addActionListener(listener);
307
			bInsert.setText(PluginServices.getText(this, "Anadir"));
308
		}
309
		return bInsert;
310
	}
311

  
312
	/**
313
	 * This method initializes bDelAll	
314
	 * 	
315
	 * @return javax.swing.JButton	
316
	 */
317
	private JButton getBDelAll() {
318
		if (bDelAll == null) {
319
			bDelAll = new JButton();
320
			bDelAll.setActionCommand("REMOVE_ALL");
321
			bDelAll.addActionListener(listener);
322
			bDelAll.setText(PluginServices.getText(this, "Quitar_todos"));
323
		}
324
		return bDelAll;
325
	}
326

  
327
	/**
328
	 * This method initializes bDel	
329
	 * 	
330
	 * @return javax.swing.JButton	
331
	 */
332
	private JButton getBDel() {
333
		if (bDel == null) {
334
			bDel = new JButton();
335
			bDel.setText(PluginServices.getText(this, "Quitar"));
336
			bDel.setActionCommand("REMOVE");
337
			bDel.addActionListener(listener);
338
		}
339
		return bDel;
340
	}
341
	class MyListener implements ActionListener {
342
		//private FLyrShp m_layer;
343
		// private FPanelLegendValues m_Parent;
344
		public MyListener() { // FPanelLegendValues p) {
345

  
346
			// m_Parent = p;
347
		}
348

  
349
		/**
350
		 * DOCUMENT ME!
351
		 *
352
		 * @param e DOCUMENT ME!
353
		 */
354
		public void actionPerformed(ActionEvent e) {
355
			// rellenarValue();
356
			System.out.println("ActionEvent con " + e.getActionCommand());
357

  
358
			//modificar el combobox de valor
359
			if (e.getActionCommand() == "FIELD_SELECTED") {
360
				JComboBox cb = (JComboBox) e.getSource();
361
				String fieldName = (String) cb.getSelectedItem();
362
				System.out.println("Nombre del campo: " + fieldName);
363
				m_symbolTable.removeAllItems();
364

  
365
				m_Renderer.setFieldName(fieldName);
366
			} else if (e.getActionCommand() == "INTERVAL_TYPE") {
367
				JComboBox cb = (JComboBox) e.getSource();
368
				
369
				if (m_Renderer!=null && cb.getSelectedIndex() != m_Renderer.getIntervalType()) {
370
					m_Renderer.setIntervalType(cb.getSelectedIndex());
371
					m_symbolTable.removeAllItems();
372
				}
373
				
374
			}
375

  
376
			//A?adir todos los elementos por valor
377
			if (e.getActionCommand() == "ADD_ALL_VALUES") {
378
				fillTableValues();
379
			}
380

  
381
			//A?adir un ?nico elemento
382
			if (e.getActionCommand() == "ADD_VALUE") {
383
				try {
384
					m_symbolTable.addTableRecord(new FSymbol(m_lyr.getShapeType()),new FInterval(0,0),"0 - 0");
385
				} catch (DriverException e1) {
386
					e1.printStackTrace();
387
				}
388
			
389
				/*        a?adir("Nuevo_Valor");
390
				   aceptar.setEnabled(true);
391
				   quitartodo.setEnabled(true);
392
				   quitar.setEnabled(true); */
393
			}
394

  
395
			//Vacia la tabla
396
			if (e.getActionCommand() == "REMOVE_ALL") {
397
				m_symbolTable.removeAllItems();
398

  
399
				// aceptar.setEnabled(false);
400
			}
401

  
402
			//Quitar solo el elemento seleccionado
403
			if (e.getActionCommand() == "REMOVE") {
404
				m_symbolTable.removeSelectedRows();
405
			}
406
		}
407
	}
408
	/**
409
	 * Damos una primera pasada para saber los l?mites inferior y superior y
410
	 * rellenar un array con los valores. Luego dividimos ese array en
411
	 * intervalos.
412
	 */
413
	private void fillTableValues() {
414
		FInterval[] arrayIntervalos = null;
415
		DataSource elRs;
416
		m_symbolTable.removeAllItems();
417

  
418
		try {
419
			elRs = ((AlphanumericData) m_lyr).getRecordset();
420
			logger.debug("elRs.start()");
421
			elRs.start();
422

  
423
			int idField = -1;
424
			int numIntervalos=1;
425
			try{
426
			 numIntervalos= Integer.parseInt(txtNumIntervals.getText());
427
			}catch (NumberFormatException e) {
428
				System.out.println("Foramto de n?mero erroneo");
429
			}
430
			String fieldName = (String) cmbField.getSelectedItem();
431
			System.out.println("Nombre del campo de clasificaci?n: " +
432
				fieldName);
433
			m_Renderer.setFieldName(fieldName);
434

  
435
			String nomField = m_Renderer.getFieldName();
436

  
437
			// Cogemos el tipo de gradaci?n de colores que quiere el usuario y 
438
			// Creamos el primer y ?ltimo color.
439
			Color startColor = colorChooserPanel.getColor();
440
			m_Renderer.setStartColor(startColor);
441

  
442
			Color endColor = colorChooserPanel1.getColor();
443
			m_Renderer.setEndColor(endColor);
444

  
445
			
446

  
447
			for (int i = 0; i < elRs.getFieldCount(); i++) {
448
				String nomAux = elRs.getFieldName(i).trim();
449

  
450
				if (nomField.compareToIgnoreCase(nomAux) == 0) {
451
					idField = i;
452

  
453
					break;
454
				}
455
			}
456

  
457
			if (idField == -1) {
458
				System.err.println("Campo no reconocido " + nomField);
459

  
460
				return;
461
			}
462

  
463
			///m_symbolTable.removeAllItems();
464
			///m_valuesCache = new Object[m_lyr.getSource().getShapeCount()];
465
			int numSymbols = 0;
466
			FSymbol theSymbol;
467
			//Date valorDate;
468
			double minValue = Double.MAX_VALUE;
469
			double maxValue = Double.MIN_VALUE;
470
			//Date minValueDate = null;
471
			//Date maxValueDate = null;
472

  
473
			
474
			auxLegend = LegendFactory.createVectorialIntervalLegend(m_lyr.getShapeType());
475

  
476
			Value clave;
477
			//Object resul;
478
			int symbolType = 0;
479
			count = 0;
480
			
481
			for (int j = 0; j < elRs.getRowCount(); j++) {
482
				clave = elRs.getFieldValue(j, idField);
483

  
484
				IInterval interval = auxLegend.getInterval(clave);
485

  
486
				////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
487
				if (auxLegend.getSymbolByInterval(interval) == null) {
488
					//si no esta creado el simbolo se crea
489
					double valor = 0;
490
					symbolType = m_lyr.getShapeType();
491

  
492
					if (clave instanceof IntValue) {
493
						valor = ((IntValue) clave).getValue();
494
					} else if (clave instanceof DoubleValue) {
495
						valor = ((DoubleValue) clave).getValue();
496
					} else if (clave instanceof FloatValue) {
497
						valor = ((FloatValue) clave).getValue();
498
					} else if (clave instanceof LongValue) {
499
						valor = ((LongValue) clave).getValue();
500
					} else if (clave instanceof DateValue) {
501
						//TODO POR IMPLEMENTAR
502
						///valorDate = elRs.getFieldValueAsDate(idField);
503
						///if (valorDate.before(minValueDate)) minValueDate = valorDate;
504
						///if (valorDate.after(maxValueDate)) maxValueDate = valorDate;
505
					} else if (clave instanceof NullValue){
506
						continue;
507
					}
508

  
509
					if (valor < minValue) {
510
						minValue = (double) valor;
511
					}
512

  
513
					if (valor > maxValue) {
514
						maxValue = (double) valor;
515
					}
516
				}
517

  
518
				count++;
519
			}
520

  
521
			switch (m_Renderer.getIntervalType()) {
522
				case VectorialIntervalLegend.EQUAL_INTERVALS:
523
					arrayIntervalos = calculateEqualIntervals(numIntervalos,
524
							minValue, maxValue,fieldName);
525

  
526
					break;
527

  
528
				case VectorialIntervalLegend.NATURAL_INTERVALS:
529
					arrayIntervalos = calculateNaturalIntervals(numIntervalos,
530
							minValue, maxValue,fieldName);
531

  
532
					break;
533

  
534
				case VectorialIntervalLegend.QUANTILE_INTERVALS:
535
					arrayIntervalos = calculateQuantileIntervals(numIntervalos,
536
							minValue, maxValue,fieldName);
537

  
538
					break;
539
			}
540

  
541
			//intervals = arrayIntervalos;
542

  
543
			FInterval elIntervalo;
544
			NumberFormat.getInstance().setMaximumFractionDigits(2);
545
			m_Renderer.clear();
546

  
547
			int r;
548
			int g;
549
			int b;
550
			int stepR;
551
			int stepG;
552
			int stepB;
553
			r = startColor.getRed();
554
			g = startColor.getGreen();
555
			b = startColor.getBlue();
556
			stepR = (endColor.getRed() - r) / arrayIntervalos.length;
557
			stepG = (endColor.getGreen() - g) / arrayIntervalos.length;
558
			stepB = (endColor.getBlue() - b) / arrayIntervalos.length;
559
			if (chkdefaultvalues.isSelected()){
560
				auxLegend.getDefaultSymbol().setDescription("Default");
561
				auxLegend.addSymbol(new NullInterval(),auxLegend.getDefaultSymbol());
562
			}
563
			for (int k = 0; k < arrayIntervalos.length; k++) {
564
				elIntervalo = arrayIntervalos[k];
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff