Revision 25074

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/VectorialInterval.java
63 63
import org.apache.log4j.Logger;
64 64
import org.gvsig.fmap.dal.DataTypes;
65 65
import org.gvsig.fmap.dal.exception.DataException;
66
import org.gvsig.fmap.dal.exception.ReadException;
67 66
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
68 67
import org.gvsig.fmap.dal.feature.FeatureStore;
69 68
import org.gvsig.fmap.dal.feature.FeatureType;
......
85 84
import com.iver.andami.PluginServices;
86 85
import com.iver.andami.messages.NotificationManager;
87 86
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
87
import com.iver.utiles.XMLException;
88 88

  
89 89

  
90 90
/**
......
434 434
            auxLegend = LegendFactory.createVectorialIntervalLegend(layer.getShapeType());
435 435
            auxLegend.useDefaultSymbol(false);
436 436

  
437
            if (chkdefaultvalues.isSelected()) {
438
                auxLegend.getDefaultSymbol().setDescription("Default");
439
                auxLegend.addSymbol(new NullIntervalValue(),
440
                		auxLegend.getDefaultSymbol());
441
            }
442

  
443 437
            int symbolType = layer.getShapeType();
444 438
            int numSymbols = 0;
445 439

  
......
486 480
            symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
487 481
                auxLegend.getValues(), auxLegend.getDescriptions());
488 482

  
489
        } catch (ReadException e) {
483
        } catch (DataException e) {
490 484
        	NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e);
491 485
        } catch (LegendLayerException e) {
492 486
        	NotificationManager.addError(PluginServices.getText(this, "failed_computing_intervals"), e);
......
530 524
    	int shapeType = 0;
531 525
    	try {
532 526
    		shapeType = this.layer.getShapeType();
533
    	} catch (ReadException e) {
527
    	} catch (DataException e) {
534 528
    		NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e);
535 529
    	}
536 530

  
......
565 559
        cmbFieldType.setSelectedIndex(theLegend.getIntervalType());
566 560
*/
567 561
		if (VectorialIntervalLegend.class.equals(legend.getClass())) {
568
			auxLegend = (VectorialIntervalLegend) legend;
562
			try {
563
				auxLegend = (VectorialIntervalLegend) legend.cloneLegend();
564
			} catch (XMLException e) {
565
				NotificationManager.addError(e);
566
			}
569 567
			chkdefaultvalues.setSelected(auxLegend.isUseDefaultSymbol());
570 568
			cmbField.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
571 569
			symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
......
574 572
			colorChooserPanel1.setColor(auxLegend.getEndColor());
575 573
			colorChooserPanel.repaint();
576 574
			colorChooserPanel1.repaint();
577
			txtNumIntervals.setText(String.valueOf(auxLegend.getSymbols().length));
575
			if(auxLegend.isUseDefaultSymbol()) {
576
				txtNumIntervals.setText(String.valueOf(auxLegend.getSymbols().length - 1));
577
			} else {
578
				txtNumIntervals.setText(String.valueOf(auxLegend.getSymbols().length));
579
			}
578 580
		} else {
579 581
			// Si la capa viene con otro tipo de leyenda, creamos
580 582
			// una nueva del tipo que maneja este panel
......
597 599

  
598 600
    protected void fillFieldNames() {
599 601
        FeatureStore rs = null;
600
        ArrayList nomFields = null;
602
        ArrayList<String> nomFields = null;
601 603

  
602 604
        try {
603 605
            rs = ((FLyrVect) layer).getFeatureStore();
604 606
//            logger.debug("rs.start()");
605 607
//            rs.start();
606 608

  
607
            nomFields = new ArrayList();
609
            nomFields = new ArrayList<String>();
608 610

  
609 611
            int type;
610
            Iterator iterator=((FeatureType)rs.getFeatureTypes().get(0)).iterator();
612
            Iterator<FeatureAttributeDescriptor> iterator=rs.getDefaultFeatureType().iterator();
611 613
            while (iterator.hasNext()) {
612
				FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next();
614
				FeatureAttributeDescriptor descriptor = iterator.next();
613 615

  
614 616
//			}
615 617
//            for (int i = 0; i < rs.getFieldCount(); i++) {
......
624 626
                		type == DataTypes.FLOAT ||
625 627
                		type  == DataTypes.LONG)
626 628
                {
627
                	nomFields.add(descriptor.getName().trim());
629
                	nomFields.add(descriptor.getName());
628 630
                }
629 631
            }
630 632

  
......
650 652

  
651 653
		auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
652 654

  
653
		theLegend = auxLegend;
655
		try {
656
			theLegend = (VectorialIntervalLegend) auxLegend.cloneLegend();
657
		} catch (XMLException e) {
658
			// TODO Auto-generated catch block
659
			e.printStackTrace();
660
		}
654 661
		return theLegend;
655 662
	}
656
     /*
657
    public ILegend getLegend() {
658
        fillSymbolListFromTable();
659 663

  
660
        if (auxLegend != null) {
661
        	// your settings that are not the set of symbols must be located here
662
        	auxLegend.setClassifyingFieldNames(
663
        			new String[] {(String) getCmbFields().getSelectedItem()});
664

  
665

  
666

  
667
        	theLegend = auxLegend;
668
        }
669

  
670
        return theLegend;
671
    }*/
672

  
673 664
    /**
674 665
     * A partir de los registros de la tabla, regenera el FRenderer. (No solo
675 666
     * el symbolList, si no tambi�n el arrayKeys y el defaultRenderer
676 667
     */
677
    /*private void fillSymbolListFromTable() {
678
        ISymbol theSymbol;
679
        IInterval theInterval = null;
680 668

  
681
        // Borramos las anteriores listas:
682
        theLegend.clear();
683

  
684
        String fieldName = (String) cmbField.getSelectedItem();
685
        theLegend.setClassifyingFieldNames(new String[] {fieldName});
686

  
687
        for (int row = 0; row < symbolTable.getRowCount(); row++) {
688
            if (!(symbolTable.getFieldValue(row, 1) instanceof FInterval)) {
689
                theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
690
                theSymbol.setDescription((String) symbolTable.getFieldValue(
691
                        row, 2));
692
                theLegend.addSymbol(new NullIntervalValue(), theSymbol);
693
            } else {
694
                theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
695
                theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
696
                theSymbol.setDescription((String) symbolTable.getFieldValue(
697
                        row, 2));
698
                theLegend.addSymbol(theInterval, theSymbol);
699
            }
700

  
701
        }
702
    }*/
703 669
    private void fillSymbolListFromTable() {
704 670
		ISymbol theSymbol;
705 671
		IInterval theInterval = null;
......
719 685
//			rs.start();
720 686
			FeatureType featureType=rs.getDefaultFeatureType();
721 687
			auxLegend
722
					.setClassifyingFieldTypes(new Integer[] { new Integer(
688
					.setClassifyingFieldTypes(new int[] { new Integer(
723 689
							featureType.getAttributeDescriptor(fieldName)
724 690
									.getDataType()) });
725 691
			logger.debug("rs.start()");
726 692
//			rs.stop();
727 693

  
728
		} catch (ReadException e) {
694
		} catch (DataException e) {
729 695
			NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
730 696
		}
731 697

  
......
768 734
    }
769 735

  
770 736
    /**
771
     * A�ade la fila y el s�mbolo para el resto de valores no representados.
772
     */
773
    private void addDefault() {
774

  
775
        auxLegend.getDefaultSymbol().setDescription("Default");
776
        auxLegend.addSymbol(new NullIntervalValue(),
777
            auxLegend.getDefaultSymbol());
778
        symbolTable.addTableRecord(auxLegend.getDefaultSymbol(),
779
            new NullIntervalValue(),
780
            auxLegend.getDefaultSymbol().getDescription());
781
        symbolTable.repaint();
782
    }
783

  
784
    /**
785
     * Elimina la fila de la tabla y el s�mbolo del resto de valores no
786
     * representados por ning�n valor.
787
     */
788
    private void delDefault() {
789
        auxLegend.delSymbol(new NullIntervalValue());
790
        symbolTable.removeRow(new NullIntervalValue());
791
        symbolTable.repaint();
792
    }
793

  
794
    /**
795 737
     * Listener.
796 738
     *
797 739
     * @author Vicente Caballero Navarro
......
835 777
                    		SymbologyFactory.createDefaultSymbolByShapeType(layer.getShapeType()),
836 778
                    		new FInterval(0, 0),
837 779
                    		"0 - 0");
838
                } catch (ReadException e1) {
780
                } catch (DataException e1) {
839 781
                	NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e1);
840 782
                }
841 783

  
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/AttrInTableLabeling.java
57 57

  
58 58
import org.gvsig.fmap.dal.DataTypes;
59 59
import org.gvsig.fmap.dal.exception.DataException;
60
import org.gvsig.fmap.dal.exception.ReadException;
61 60
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
62 61
import org.gvsig.fmap.dal.feature.FeatureType;
63 62
import org.gvsig.fmap.mapcontext.layers.FLayer;
......
67 66
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
68 67
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
69 68
import org.gvsig.gui.beans.swing.JBlank;
70
import org.gvsig.gui.beans.swing.JComboBoxFonts;
71 69

  
72 70
import com.iver.andami.PluginServices;
73 71
import com.iver.andami.messages.NotificationManager;
74 72
import com.iver.cit.gvsig.gui.JComboBoxUnits;
75 73
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
74
import com.iver.cit.gvsig.gui.styling.JComboBoxUnitsReferenceSystem;
76 75
import com.iver.cit.gvsig.gui.utils.FontChooser;
77 76
import com.iver.cit.gvsig.project.Project;
78 77
import com.iver.utiles.swing.JComboBox;
......
93 92
	private JComboBox cmbHeightField;
94 93
	private JComboBox cmbRotationField;
95 94
	private JComboBoxUnits cmbUnits;
95
	private JComboBoxUnitsReferenceSystem cmbReferenceSystem;
96 96
	private JTextField txtHeightField;
97 97
	private FLyrVect layer;
98
	private JComboBoxFonts cmbFonts;
98

  
99 99
	private ColorChooserPanel colorChooser;
100 100
	private JComboBox cmbColorField;
101 101
	private JButton chooseFontBut;
......
115 115
		aux.addComponent(getRdBtnFixedHeight(), getTxtHeightField());
116 116
		aux.addComponent(PluginServices.getText(this, "rotation_height") + ":", getCmbRotationField());
117 117
		aux.addComponent(PluginServices.getText(this, "units") + ":", getCmbUnits());
118
		aux.addComponent(PluginServices.getText(this,""),getCmbReferenceSystem());
118 119
		panel.add(aux);
119 120

  
120 121
		aux = new GridBagLayoutPanel();
......
215 216
		return cmbUnits;
216 217
	}
217 218

  
219
	private JComboBoxUnitsReferenceSystem getCmbReferenceSystem(){
220
		if(cmbReferenceSystem == null){
221
			cmbReferenceSystem = new JComboBoxUnitsReferenceSystem();
222
			cmbReferenceSystem.setName("CMBREFSYST");
223
		}
224
		return cmbReferenceSystem;
225
	}
226

  
218 227
	private JComboBox getCmbColorField() {
219 228
		if (cmbColorField == null) {
220 229
			cmbColorField = new JComboBox();
......
238 247
		//		the text size unit name
239 248
		refreshCmbUnits();
240 249

  
250
		refreshCmbRefSystem();
241 251
		//		the font for the text
242 252
		refreshFont();
243
//
244 253
		//		the color for the font
245 254
		refreshColorFont();
246 255
	}
......
326 335
		if(getCmbUnits().getItemCount() > 0) {
327 336
			strategy.setUnit(getCmbUnits().getSelectedUnitIndex());
328 337
		}
338
		if(getCmbReferenceSystem().getItemCount() > 0) {
339
			strategy.setReferenceSystem(getCmbReferenceSystem().getSelectedIndex());
340
		}
329 341

  
330 342
		strategy.setUsesFixedColor(getRdBtnFixedColor().isSelected());
331 343
		strategy.setFixedColor(colorChooser.getColor());
......
345 357
		if (layer instanceof FLyrVect) {
346 358
			FLyrVect lv = (FLyrVect) layer;
347 359
			try {
348
				FeatureType featureType=(FeatureType)lv.getFeatureStore().getFeatureTypes().get(0);
349
				fieldNames = featureType.getFields();
350

  
351
				Iterator iterator=featureType.iterator();
360
				FeatureType featureType = lv.getFeatureStore()
361
						.getDefaultFeatureType();
362
				fieldNames = new String[featureType.size()];
363
				Iterator<FeatureAttributeDescriptor> iterator = featureType
364
						.iterator();
352 365
				ArrayList<String> l = new ArrayList<String>();
353 366
				ArrayList<String> lColors = new ArrayList<String>();
367
				String name;
368
				FeatureAttributeDescriptor descriptor;
354 369
				while (iterator.hasNext()) {
355
					FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next();
356
					if (descriptor.getDataType() == DataTypes.DOUBLE ||
357
							descriptor.getDataType() == DataTypes.FLOAT ||
358
							descriptor.getDataType() == DataTypes.LONG)/*||
359
							descriptor.getDataType().equals(FeatureAttributeDescriptor.TYPE_INT))*/{
360
						l.add(descriptor.getName());
370
					descriptor = iterator.next();
371

  
372
					name = descriptor.getName();
373
					fieldNames[descriptor.getIndex()] = name;
374
					switch (descriptor.getDataType()) {
375
//					case DataTypes.DECIMAL:
376
//					case DataTypes.NUMERIC:
377
					case DataTypes.FLOAT:
378
//					case DataTypes.REAL:
379
					case DataTypes.DOUBLE:
380
						l.add(name);
381
						break;
382
					case DataTypes.INT:
383
//					case DataTypes.SMALLINT:
384
//					case DataTypes.TINYINT:
385
					case DataTypes.LONG:
386
						lColors.add(name);
387
						l.add(name);
388
						break;
361 389
					}
362
					if (descriptor.getDataType() == DataTypes.INT) {
363
						l.add(descriptor.getName());
364
						lColors.add(descriptor.getName());
365
					}
366

  
367

  
368
				// detect the numeric fields
369

  
370
//				for (int i = 0; i < fieldNames.length; i++) {
371
//					switch (lv.getRecordset().getFieldType(i)) {
372
//					case Types.DECIMAL:
373
//					case Types.NUMERIC:
374
//					case Types.FLOAT:
375
//					case Types.DOUBLE:
376
//					case Types.INTEGER:
377
//					case Types.REAL:
378
//					case Types.SMALLINT:
379
//					case Types.TINYINT:
380
//					case Types.BIGINT:
381
//						l.add(fieldNames[i]);
382
//						break;
383
//					}
384 390
				}
385 391
				numericFieldNames = l.toArray(new String[l.size()]);
386 392
				integerFieldNames = lColors.toArray(new String[lColors.size()]);
387
			} catch (ReadException e) {
393
			} catch (DataException e) {
388 394
				NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e);
389 395
			}
390 396
			refreshControls();
391 397
		}
392 398
	}
393
	private void refreshCmbFont(){
394 399

  
395
		if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
396
			AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
397
			cmbFonts.setFont(aux.getFont());
398
		}
399
	}
400

  
401 400
	private void refreshColorFont(){
402 401

  
403 402
		getCmbColorField().removeAllItems();
......
425 424
				getCmbColorField().setSelectedItem(item);
426 425
				colorChooser.setColor(aux.getFixedColor());
427 426

  
428
			} catch (ReadException e) {
427
			} catch (DataException e) {
429 428
				// should never happen
430 429
				NotificationManager.addWarning(PluginServices.getText(this, "could_not_restore_color_field"), e);
431 430
			}
......
441 440
	}
442 441

  
443 442
	private void refreshCmbUnits() {
444
		getCmbUnits().setSelectedUnitIndex(Project.getDefaultDistanceUnits());
445 443

  
446 444
		if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
447 445
			AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
......
449 447
		}
450 448
	}
451 449

  
450
	private void refreshCmbRefSystem() {
451

  
452
		if (layer.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
453
			AttrInTableLabelingStrategy aux = (AttrInTableLabelingStrategy) layer.getLabelingStrategy();
454
			getCmbReferenceSystem().setSelectedIndex(aux.getReferenceSystem());
455
		}
456
	}
452 457

  
453 458
	private void refreshTextHeight() {
454 459
		getCmbHeightField().removeAllItems();
......
525 530
	}
526 531

  
527 532
	public Class getLabelingStrategyClass() {
528
		return AttrInTableLabeling.class;
533
		return AttrInTableLabelingStrategy.class;

529 534
	}
530 535

  
531 536
}
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/VectorialUniqueValue.java
321 321
        FLyrVect m = (FLyrVect) layer;
322 322

  
323 323
        try {
324
        	String fieldType = m.getFeatureStore().getDefaultFeatureType()
324
        	int fieldType = m.getFeatureStore().getDefaultFeatureType()
325 325
					.getAttributeDescriptor(cmbFields.getSelectedIndex())
326
					.getName();
326
					.getDataType();
327 327
//        	int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
328
        	auxLegend.setClassifyingFieldTypes(new String[] {fieldType});
328
        	auxLegend.setClassifyingFieldTypes(new int[] { fieldType });
329 329
        } catch (DataException e) {
330 330
        	NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e);
331 331
        }

Also available in: Unified diff