Revision 40390

View differences:

branches/v2_0_0_prep/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/impl/AbstractIntervalLegend.java
65 65
	private static final String FIELD_KEYS = "keys";
66 66
	private static final String FIELD_INTERVAL_TYPE = "intervalType";
67 67
	private static final String FIELD_USE_DEFAULT_SYMBOL = "useDefaultSymbol";
68
	private static final String FIELD_NULL_INTERVAL_SYMBOL =
69
			"nullIntervalSymbol";
70 68
	private static final String FIELD_SYMBOLS = "symbols";
71 69
	
72 70
	protected List<Object> keys = new ArrayList<Object>(); // <Object>
......
77 75
	protected int intervalType = NATURAL_INTERVALS;
78 76
	protected boolean useDefaultSymbol = false;
79 77

  
80
	private ISymbol nullIntervalSymbol = null;
78
	// private ISymbol nullIntervalSymbol = null;
81 79

  
82 80
	public static final int EQUAL_INTERVALS = 0;
83 81
	public static final int NATURAL_INTERVALS = 1;
......
87 85
	
88 86
	public void addSymbol(Object key, ISymbol symbol) {
89 87
		if (key == null) {
90
			nullIntervalSymbol = symbol;
91
		}
92
		else {
88
		    // why did we use this?
89
			// nullIntervalSymbol = symbol;
90
		    logger.info(
91
		        "Warning: tried to add symbol with null key.",
92
		        new Exception("Key is NULL"));
93
		} else {
93 94
			symbols.put(key, symbol);
94 95
			keys.add(key);
96
			fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(null, symbol));
95 97
		}
96
		fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(null, symbol));
97 98
	}
98 99

  
99 100
	/*
......
374 375
    public ISymbol getSymbolByInterval(IInterval key) {
375 376

  
376 377
		if (key == null){
377
			if (nullIntervalSymbol != null) {
378
				return nullIntervalSymbol;
379
			}
380
			else if (isUseDefaultSymbol()) {
378
			if (isUseDefaultSymbol()) {
381 379
				return defaultSymbol;
382 380
			}
383 381
			return null;
......
418 416

  
419 417
	public ISymbol[] getSymbols() {
420 418
		ISymbol[] symbolList;
421
		if (nullIntervalSymbol == null) {
422
			symbolList = new ISymbol[symbols.size()];
423
			return (ISymbol[]) symbols.values().toArray(symbolList);
424
		}
425
		else {
426
			symbolList = new ISymbol[symbols.size() + 1];
427
			symbolList[0] = nullIntervalSymbol;
428
			int i = 1;
429
			for (Iterator<ISymbol> iterator = symbols.values().iterator(); iterator.hasNext();) {
430
				symbolList[i] = iterator.next();
431
				i++;
432
			}
433
			return symbolList;
434
		}
419
        symbolList = new ISymbol[symbols.size()];
420
        return (ISymbol[]) symbols.values().toArray(symbolList);
435 421
	}
436 422

  
437 423
	public void setDefaultSymbol(ISymbol s) {
......
471 457
	public IInterval getInterval(Object v) {
472 458
		if (v != null ) {
473 459
			for (int i = 0; i < keys.size(); i++) {
474
				if (((IInterval) keys.get(i)).isInInterval(v)) {
475
					return (IInterval) keys.get(i);
476
				}
460
			    
461
			    Object obj_key = keys.get(i);
462
			    if (obj_key instanceof IInterval) {
463
	                if (((IInterval) obj_key).isInInterval(v)) {
464
	                    return (IInterval) obj_key;
465
	                }
466
			    }
477 467
			}
478 468
		}
479 469

  
......
536 526
	public Object clone() throws CloneNotSupportedException {
537 527
		AbstractIntervalLegend clone = (AbstractIntervalLegend) super.clone();
538 528

  
539
		// Clone null interval symbol
540
		if (nullIntervalSymbol != null) {
541
			clone.nullIntervalSymbol = (ISymbol) nullIntervalSymbol.clone();
542
		}
543
		
544 529
		// Clone default symbol
545 530
		if (defaultSymbol != null) {
546 531
			clone.defaultSymbol = (ISymbol) defaultSymbol.clone();
......
554 539
			for (Iterator<Entry<Object, ISymbol>> iterator =
555 540
					symbols.entrySet().iterator(); iterator.hasNext();) {
556 541
				Entry<Object, ISymbol> entry = iterator.next();
557
				IInterval intervalClone =
558
						(IInterval) ((IInterval) entry.getKey()).clone();
542
				
543
				Object key = entry.getKey();
544
				IInterval key_interval = null;
545
				if (key instanceof IInterval) {
546
				    key_interval = (IInterval) key;
547
				    key = key_interval.clone();
548
				}
559 549
				ISymbol symbolClone =
560 550
						(ISymbol) ((ISymbol) entry.getValue()).clone();
561
				clone.addSymbol(intervalClone, symbolClone);
551
				clone.addSymbol(key, symbolClone);
562 552
			}
563 553
		}
564 554
		
......
575 565
		// Set own properties
576 566
		setIntervalType(state.getInt(FIELD_INTERVAL_TYPE));
577 567
		keys = new ArrayList<Object>(state.getList(FIELD_KEYS));
578
		nullIntervalSymbol = (ISymbol) state.get(FIELD_NULL_INTERVAL_SYMBOL);
579 568
		useDefaultSymbol(state.getBoolean(FIELD_USE_DEFAULT_SYMBOL));
580 569
		Map persistedSymbolMap = (Map) state.get(FIELD_SYMBOLS);
581 570
		if (persistedSymbolMap != null) {
......
589 578
		// Save own properties
590 579
		state.set(FIELD_INTERVAL_TYPE, getIntervalType());
591 580
		state.set(FIELD_KEYS, keys);
592
		state.set(FIELD_NULL_INTERVAL_SYMBOL, nullIntervalSymbol);
593 581
		state.set(FIELD_USE_DEFAULT_SYMBOL, isUseDefaultSymbol());
594 582
		state.set(FIELD_SYMBOLS, symbols);
595 583
	}
......
615 603
				// Keys
616 604
				definition.addDynFieldList(FIELD_KEYS)
617 605
					.setClassOfItems(int.class);
618
				// Null interval symbol
619
				definition.addDynFieldObject(FIELD_NULL_INTERVAL_SYMBOL)
620
					.setClassOfValue(ISymbol.class)
621
					.setMandatory(false);
622 606
				// Use default symbol?
623 607
				definition.addDynFieldBoolean(FIELD_USE_DEFAULT_SYMBOL);
624 608
				// Symbols
......
637 621
		(new Comparator<Object>() { 
638 622
					public int compare(Object o1, Object o2) {
639 623
						if ((o1 != null) && (o2 != null)) {
640
							// if (o1 instanceof NullIntervalValue &&
641
							// o2 instanceof NullIntervalValue) {
642
							// return 0;
643
							// }
644
							//
645
							// if (o2 instanceof NullIntervalValue) {
646
							// return 1;
647
							// }
648
							//
649
							// if (o1 instanceof NullIntervalValue) {
650
							// return -1;
651
							// }
624
						    
625
						    boolean o1_inte = (o1 instanceof FInterval);
626
                            boolean o2_inte = (o2 instanceof FInterval);
627
                            
628
                            if (!o1_inte && !o2_inte) {
629
                                return 0;
630
                            } else {
631
                                if (o1_inte && !o2_inte) {
632
                                    return 1;
633
                                } else {
634
                                    if (!o1_inte && o2_inte) {
635
                                        return -1;
636
                                    }
637
                                }
638
                            }
652 639

  
653 640
							FInterval i2 = (FInterval) o2;
654 641
							FInterval i1 = (FInterval) o1;
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/view/legend/gui/VectorialInterval.java
699 699
		String fieldName = (String) cmbField.getSelectedItem();
700 700
		auxLegend.setClassifyingFieldNames(new String[] {fieldName});
701 701

  
702
		auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
702
		ISymbol defsym = null;
703
        if (chkdefaultvalues.isSelected() && defaultSymbolPrev.getSymbol() != null) {
704
            defsym = (ISymbol) defaultSymbolPrev.getSymbol();
705
            String description = PluginServices.getText(this,"default");
706
            defsym.setDescription(description);
707
            auxLegend.setDefaultSymbol(defsym);
708
            auxLegend.useDefaultSymbol(true);
709
        } else {
710
            
711
            auxLegend.useDefaultSymbol(false);
712
        }
703 713

  
704 714
		FeatureStore rs;
705 715
		try {
706 716

  
707 717
			rs = ((FLyrVect) layer).getFeatureStore();
708
//			rs.start();
709 718
			FeatureType featureType=rs.getDefaultFeatureType();
710 719
			auxLegend
711 720
					.setClassifyingFieldTypes(new int[] { new Integer(
712 721
							featureType.getAttributeDescriptor(fieldName)
713 722
									.getType()) });
714
			logger.debug("rs.start()");
715
//			rs.stop();
716 723

  
717 724
		} catch (DataException e) {
718 725
			NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
......
721 728

  
722 729

  
723 730
		for (int row = 0; row < symbolTable.getRowCount(); row++) {
724
			if (!(symbolTable.getFieldValue(row, 1) instanceof FInterval)) {
725
				theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
726
				theSymbol.setDescription((String) symbolTable.getFieldValue(
727
						row, 2));
728
				auxLegend.addSymbol(null, theSymbol);
729
			} else {
731
			if (symbolTable.getFieldValue(row, 1) instanceof FInterval) {
730 732
				theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
731 733
				theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
732 734
				theSymbol.setDescription((String) symbolTable.getFieldValue(
......
734 736
				auxLegend.addSymbol(theInterval, theSymbol);
735 737
			}
736 738
		}
737
		if(chkdefaultvalues.isSelected()){
738
			if(defaultSymbolPrev.getSymbol() != null){
739
				String description = PluginServices.getText(this,"default");
740
				defaultSymbolPrev.getSymbol().setDescription(description);
741
				auxLegend.addSymbol(null, defaultSymbolPrev.getSymbol());
742
			}
739
		
740
		if (auxLegend.isUseDefaultSymbol()) {
741
		    theSymbol = auxLegend.getDefaultSymbol();
742
		    auxLegend.addSymbol(theSymbol.getDescription(), theSymbol);
743 743
		}
744
		
744 745
	}
745 746

  
746 747
    /**

Also available in: Unified diff