Revision 6900 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.legend/org.gvsig.raster.lib.legend.impl/src/main/java/org/gvsig/raster/lib/legend/impl/DefaultColorTable.java

View differences:

DefaultColorTable.java
10 10

  
11 11
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
12 12
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
13
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretationNotification;
13 14
import org.gvsig.raster.lib.legend.api.colortable.ColorTable;
14
import org.gvsig.raster.lib.legend.api.colortable.ColorTableClass;
15
import org.gvsig.raster.lib.legend.api.colortable.ColorTableNotification;
16
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass;
17
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClassNotification;
18
import org.gvsig.raster.lib.legend.impl.colorinterpretation.DefaultColorInterpretationNotification;
19
import org.gvsig.raster.lib.legend.impl.colortable.DefaultColorTableNotification;
15 20
import org.gvsig.tools.ToolsLocator;
16 21
import org.gvsig.tools.dynobject.DynStruct;
22
import org.gvsig.tools.observer.Notification;
23
import org.gvsig.tools.observer.Observable;
24
import org.gvsig.tools.observer.impl.BaseWeakReferencingObservable;
17 25
import org.gvsig.tools.persistence.PersistenceManager;
18 26
import org.gvsig.tools.persistence.PersistentState;
19 27
import org.gvsig.tools.persistence.exception.PersistenceException;
......
22 30
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
23 31
 *
24 32
 */
25
public class DefaultColorTable implements ColorTable {
33
public class DefaultColorTable extends BaseWeakReferencingObservable implements ColorTable {
26 34

  
27 35
    /**
28 36
     * Persistence definition name
......
80 88
        this.name = name;
81 89
        this.classes = classes;
82 90
        this.interpolated = interpolated;
91
        observeClasses();
83 92
        reCalculateColorTable(false);
84 93
    }
85 94

  
95
    private void observeClasses() {
96
        for (ColorTableClass clazz : this.classes) {
97
            clazz.addObserver(this);
98
        }
99
    }
100

  
101
    private void stopObservingClasses() {
102
        for (ColorTableClass clazz : this.classes) {
103
            clazz.deleteObserver(this);
104
        }
105
    }
106

  
86 107
    private void applyPalette(List<ColorTableClass> colorItems) {
87 108
        List<ColorTableClass> arrayColors = new ArrayList<ColorTableClass>();
88 109

  
......
210 231

  
211 232
    @Override
212 233
    public void copyFrom(ColorTable colorTable) {
234
        RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager();
213 235
        this.interpolated = colorTable.isInterpolated();
214 236
        this.name = colorTable.getName();
215
        setClasses(colorTable.getClasses(), false);
237
        List<ColorTableClass> clonedClasses = new ArrayList<ColorTableClass>(colorTable.getClasses().size());
238
        for (ColorTableClass colorTableClass : colorTable.getClasses()) {
239
            ColorTableClass clonedClass = rasterLegendManager.createColorTableClass(
240
                colorTableClass.getName(),
241
                colorTableClass.getValue(),
242
                colorTableClass.getInterpolated(),
243
                colorTableClass.getColor());
244
            clonedClasses.add(clonedClass);
245
        }
246

  
247
        setClasses(clonedClasses, false);
248
        this.notifyObservers(new DefaultColorTableNotification(ColorTableNotification.COPIED_FROM_COLOR_TABLE, new Object[] { colorTable }));
216 249
    }
217 250

  
218 251
    @Override
......
490 523

  
491 524
    @Override
492 525
    public void setClasses(List<ColorTableClass> colorTableClasses, boolean compress) {
526
        if(this.classes!=null){
527
            stopObservingClasses();
528
        }
493 529
        this.classes = colorTableClasses;
530
        observeClasses();
494 531
        reCalculateColorTable(compress);
532
        this.notifyObservers(new DefaultColorTableNotification(ColorTableNotification.SETTED_CLASS_VALUES_COLOR_TABLE, new Object[] { colorTableClasses }));
495 533
    }
496 534

  
497 535
    @Override
......
554 592

  
555 593
    @Override
556 594
    public void setInterpolated(boolean flag) {
595
        boolean oldInterpolated = this.interpolated;
557 596
        this.interpolated = flag;
597
        if(this.classes!=null){
598
            reCalculateColorTable(false);
599
        }
600
        this.notifyObservers(new DefaultColorTableNotification(ColorTableNotification.CHANGED_INTERPOLATED_COLOR_TABLE, new Object[] { new Boolean(oldInterpolated), new Boolean(this.interpolated) }));
558 601
    }
559 602

  
560 603
    @Override
......
565 608
        }
566 609

  
567 610
        this.name = name;
611
        this.notifyObservers(new DefaultColorTableNotification(ColorTableNotification.RENAMED_COLOR_TABLE, new Object[] { name }));
568 612
    }
569 613

  
570 614
    public static void registerPersistence() {
......
622 666
        cloned.copyFrom(this);
623 667
        return cloned;
624 668
    }
669

  
670
    @Override
671
    public void update(Observable observable, Object notification) {
672
        //FIXME:
673

  
674
        if (notification instanceof ColorTableClassNotification && observable instanceof ColorTableClass) {
675
            Notification colorTableClassNotification = (Notification) notification;
676
            if (colorTableClassNotification.getType().equals(ColorTableClassNotification.SETTED_COLOR)
677
                || colorTableClassNotification.getType().equals(ColorTableClassNotification.SETTED_INTERPOLATED)
678
                || colorTableClassNotification.getType().equals(ColorTableClassNotification.SETTED_NAME)
679
                || colorTableClassNotification.getType().equals(ColorTableClassNotification.SETTED_VALUE)) {
680
                this.notifyObservers(new DefaultColorTableNotification(ColorTableNotification.SETTED_CLASS_VALUES_COLOR_TABLE,
681
                    new Object[] { observable }));
682
            }
683
        }
684
    }
625 685
}
626 686

  

Also available in: Unified diff