Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.impl / src / main / java / org / gvsig / fmap / raster / lib / legend / impl / DefaultColorInterpretation.java @ 44831

History | View | Annotate | Download (23.9 KB)

1
package org.gvsig.raster.lib.legend.impl;
2

    
3
import java.util.List;
4

    
5
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
6
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretationNotification;
7
import org.gvsig.raster.lib.legend.api.colortable.ColorTable;
8
import org.gvsig.raster.lib.legend.api.colortable.ColorTableNotification;
9
import org.gvsig.raster.lib.legend.impl.colorinterpretation.DefaultColorInterpretationNotification;
10
import org.gvsig.tools.ToolsLocator;
11
import org.gvsig.tools.dynobject.DynStruct;
12
import org.gvsig.tools.observer.Notification;
13
import org.gvsig.tools.observer.Observable;
14
import org.gvsig.tools.observer.impl.BaseWeakReferencingObservable;
15
import org.gvsig.tools.persistence.PersistenceManager;
16
import org.gvsig.tools.persistence.PersistentState;
17
import org.gvsig.tools.persistence.exception.PersistenceException;
18

    
19
/**
20
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
21
 *
22
 */
23
public class DefaultColorInterpretation extends BaseWeakReferencingObservable implements ColorInterpretation {
24

    
25
    /**
26
     * Persistence definition name
27
     */
28
    public static final String PERSISTENCE_DEFINITION = "ColorInterpretationPersistence";
29

    
30
    /**
31
     * Persistence definition description
32
     */
33
    public static final String PERSISTENCE_DESCRIPTION =
34
        "Persistence color interpretation definition description";
35

    
36
    private static final String COLOR_INTERPRETATION_PERSISTENCE_FIELD = "colorInterpretation";
37
    private static final String COLOR_TABLE_PERSISTENCE_FIELD = "colorTable";
38
    private static final String PALETTE_BAND_PERSISTENCE_FIELD = "paletteBand";
39

    
40

    
41
    private String[] colorInterpretation = null;
42

    
43
    private ColorTable colorTable;
44

    
45
    private int paletteBand;
46

    
47
    /**
48
     * Empty constructor
49
     */
50
    public DefaultColorInterpretation() {
51
        this.colorInterpretation = new String[0];
52
        this.paletteBand = -1;
53
        this.colorTable = null;
54

    
55
    }
56

    
57
    /**
58
     *
59
     * @param bandColorInterpretations
60
     */
61
    public DefaultColorInterpretation(String[] bandColorInterpretations) {
62

    
63
        for (int i = 0; i < bandColorInterpretations.length; i++) {
64
            if (!isColorInterpretationValid(bandColorInterpretations[i])) {
65
                throw new IllegalArgumentException(String.format(
66
                    "%1s color interpretation is not valid", bandColorInterpretations[i]));
67
            }
68
        }
69

    
70
        this.colorInterpretation = new String[bandColorInterpretations.length];
71
        System.arraycopy(bandColorInterpretations, 0, this.colorInterpretation, 0,
72
            this.colorInterpretation.length);
73
        this.paletteBand = -1;
74
        this.colorTable = null;
75
    }
76

    
77
    /**
78
     * Constructor to initialize color interpretation with the number of bands.
79
     * It is necessary to indicate color interpretation of each band using
80
     * {@link ColorInterpretation#setColorInterpValue(int, String)}
81
     *
82
     * @param nBands
83
     *            Number of bands of this color interpretation
84
     */
85
    public DefaultColorInterpretation(int nBands) {
86
        this.colorInterpretation = new String[nBands];
87
        this.paletteBand = -1;
88
        this.colorTable = null;
89
    }
90

    
91
    /**
92
     * @param bandColorInterpretation
93
     */
94
    public DefaultColorInterpretation(String bandColorInterpretation) {
95

    
96
        this.paletteBand = -1;
97
        this.colorTable = null;
98
        if (bandColorInterpretation.equals(RGB)) {
99
            this.colorInterpretation = new String[] { RED_BAND, GREEN_BAND, BLUE_BAND };
100
        } else if (bandColorInterpretation.equals(BGR)) {
101
            this.colorInterpretation = new String[] { BLUE_BAND, GREEN_BAND, RED_BAND };
102
        } else if (bandColorInterpretation.equals(ARGB)) {
103
            this.colorInterpretation = new String[] { RED_BAND, GREEN_BAND, BLUE_BAND, ALPHA_BAND };
104
        } else if (bandColorInterpretation.equals(GRAYSCALE)) {
105
            this.colorInterpretation = new String[] { GRAY_BAND };
106
        }else if (bandColorInterpretation.equals(PALETTE)) {
107
            this.colorInterpretation = new String[] { PALETTE_BAND };
108
            this.paletteBand = 0;
109
        }else if (bandColorInterpretation.equals(HSL)) {
110
            this.colorInterpretation = new String[] { HUE_BAND, SATURATION_BAND, LIGHTNESS_BAND };
111
        }else if (bandColorInterpretation.equals(CMYK)) {
112
            this.colorInterpretation = new String[] { CYAN_BAND, MAGENTA_BAND, YELLOW_BAND, BLACK_BAND };
113
        }else if (bandColorInterpretation.equals(YCBCR)) {
114
            this.colorInterpretation = new String[] { YCBCR_Y_BAND, YCBCR_CB_BAND, YCBCR_CR_BAND };
115
        }
116

    
117
        if(this.colorInterpretation == null){
118
            throw new IllegalArgumentException(
119
                "Can not create color interpretation. Type is not recognised");
120
        }
121
    }
122

    
123
    @Override
124
    public void setColorInterpValue(int band, String value) {
125

    
126
        String[] oldColorInterpretation = new String[this.colorInterpretation.length];
127
        System.arraycopy(this.colorInterpretation, 0, oldColorInterpretation, 0, this.colorInterpretation.length);
128
        if (band < 0 || band >= this.colorInterpretation.length) {
129
            throw new IllegalArgumentException("Band is out of color interpretation bands");
130
        }
131

    
132
        if (!isColorInterpretationValid(value)) {
133
            throw new IllegalArgumentException(String.format("%1s is not valid", value));
134
        }
135

    
136
        this.colorInterpretation[band] = value;
137
        this.notifyObservers(new DefaultColorInterpretationNotification(ColorInterpretationNotification.CHANGED_COLOR_INTERPRETATION_VALUE,
138
            new Object[] { oldColorInterpretation, this.colorInterpretation }));
139
    }
140

    
141
    @Override
142
    public int length() {
143
        return this.colorInterpretation.length;
144
    }
145

    
146
    private boolean isColorInterpretationValid(String bandColorInterpretation) {
147
        if (bandColorInterpretation.equals(RED_BAND)
148
            || bandColorInterpretation.equals(GREEN_BAND)
149
            || bandColorInterpretation.equals(BLUE_BAND)
150
            || bandColorInterpretation.equals(GRAY_BAND)
151
            || bandColorInterpretation.equals(PALETTE_BAND)
152
            || bandColorInterpretation.equals(HUE_BAND)
153
            || bandColorInterpretation.equals(SATURATION_BAND)
154
            || bandColorInterpretation.equals(LIGHTNESS_BAND)
155
            || bandColorInterpretation.equals(CYAN_BAND)
156
            || bandColorInterpretation.equals(MAGENTA_BAND)
157
            || bandColorInterpretation.equals(YELLOW_BAND)
158
            || bandColorInterpretation.equals(BLACK_BAND)
159
            || bandColorInterpretation.equals(YCBCR_Y_BAND)
160
            || bandColorInterpretation.equals(YCBCR_CB_BAND)
161
            || bandColorInterpretation.equals(YCBCR_CR_BAND)
162
            || bandColorInterpretation.equals(UNDEFINED_BAND)
163
//            || colorInterpretation.equals(RED_BLUE_BAND)
164
//            || colorInterpretation.equals(RED_GREEN_BAND)
165
//            || colorInterpretation.equals(GREEN_BLUE_BAND)
166
            || bandColorInterpretation.equals(ALPHA_BAND)) {
167
            return true;
168
        }
169
        return false;
170
    }
171

    
172
    @Override
173
    public boolean hasInterpretation() {
174
        if (colorInterpretation == null) {
175
            return false;
176
        }
177
        for (int i = 0; i < colorInterpretation.length; i++) {
178
            if (colorInterpretation[i].equals(RED_BAND)
179
                || colorInterpretation[i].equals(GREEN_BAND)
180
                || colorInterpretation[i].equals(BLUE_BAND)
181
//                || colorInterpretation[i].equals(RED_GREEN_BAND)
182
//                || colorInterpretation[i].equals(RED_BLUE_BAND)
183
//                || colorInterpretation[i].equals(GREEN_BLUE_BAND)
184
                || colorInterpretation[i].equals(PALETTE_BAND)
185
                || colorInterpretation[i].equals(HUE_BAND)
186
                || colorInterpretation[i].equals(SATURATION_BAND)
187
                || colorInterpretation[i].equals(LIGHTNESS_BAND)
188
                || colorInterpretation[i].equals(CYAN_BAND)
189
                || colorInterpretation[i].equals(MAGENTA_BAND)
190
                || colorInterpretation[i].equals(YELLOW_BAND)
191
                || colorInterpretation[i].equals(BLACK_BAND)
192
                || colorInterpretation[i].equals(YCBCR_Y_BAND)
193
                || colorInterpretation[i].equals(YCBCR_CB_BAND)
194
                || colorInterpretation[i].equals(YCBCR_CR_BAND)
195
                || colorInterpretation[i].equals(GRAY_BAND)) {
196

    
197
                return true;
198
            }
199
        }
200
        return false;
201
    }
202

    
203
    @Override
204
    public boolean isBGR() {
205
        if (colorInterpretation != null) {
206
            if (colorInterpretation.length == 3 && colorInterpretation[0] == BLUE_BAND
207
                && colorInterpretation[1] == GREEN_BAND && colorInterpretation[2] == RED_BAND) {
208
                return true;
209
            }
210
        }
211
        return false;
212
    }
213

    
214
    @Override
215
    public boolean isRGB() {
216
        if (colorInterpretation != null) {
217
            if (colorInterpretation.length >= 3 && hasAnyBandWithThisColorInterpretation(RED_BAND)
218
                && hasAnyBandWithThisColorInterpretation(GREEN_BAND)
219
                && hasAnyBandWithThisColorInterpretation(BLUE_BAND)) {
220
                return true;
221
            }
222
        }
223
        return false;
224
    }
225

    
226
    @Override
227
    public boolean hasAnyRGBBand() {
228
        if (colorInterpretation != null) {
229
                boolean redFound = false;
230
                boolean greenFound = false;
231
                boolean bluefound = false;
232
                for (int i = 0; i < colorInterpretation.length; i++) {
233
                    if(colorInterpretation[i]==RED_BAND){
234
                        redFound = true;
235
                    }
236
                    if(colorInterpretation[i]==GREEN_BAND){
237
                        greenFound = true;
238
                    }
239
                    if(colorInterpretation[i]==BLUE_BAND){
240
                        bluefound = true;
241
                    }
242
                }
243
                if(redFound || greenFound || bluefound){
244
                    return true;
245
                }
246
        }
247
        return false;
248
    }
249

    
250
    @Override
251
    public boolean isHSL() {
252
        if (colorInterpretation != null) {
253
            if (colorInterpretation.length >= 3 && hasAnyBandWithThisColorInterpretation( HUE_BAND)
254
                && hasAnyBandWithThisColorInterpretation(LIGHTNESS_BAND) && hasAnyBandWithThisColorInterpretation(SATURATION_BAND) ) {
255
                return true;
256
            }
257
        }
258
        return false;
259
    }
260

    
261
    private boolean hasAnyBandWithThisColorInterpretation(String interpretation){
262
        if (colorInterpretation != null) {
263
            for (int i = 0; i < colorInterpretation.length; i++) {
264
                if(colorInterpretation[i] == interpretation){
265
                    return true;
266
                }
267
            }
268
        }
269
        return false;
270
    }
271

    
272
    @Override
273
    public boolean isCMYK() {
274
        if (colorInterpretation != null) {
275
            if (colorInterpretation.length >= 4 && hasAnyBandWithThisColorInterpretation(CYAN_BAND)
276
                && hasAnyBandWithThisColorInterpretation(MAGENTA_BAND)
277
                && hasAnyBandWithThisColorInterpretation(YELLOW_BAND)
278
                && hasAnyBandWithThisColorInterpretation(BLACK_BAND) ) {
279
                return true;
280
            }
281
        }
282
        return false;
283
    }
284

    
285
    @Override
286
    public boolean isYCBCR() {
287
        if (colorInterpretation != null) {
288
            if (colorInterpretation.length >= 3 && hasAnyBandWithThisColorInterpretation(YCBCR_Y_BAND)
289
                && hasAnyBandWithThisColorInterpretation(YCBCR_CB_BAND)
290
                && hasAnyBandWithThisColorInterpretation(YCBCR_CR_BAND) ) {
291
                return true;
292
            }
293
        }
294
        return false;
295
    }
296

    
297
    @Override
298
    public boolean isRGBA() {
299
        if (colorInterpretation != null) {
300
            if (colorInterpretation.length >= 4 && hasAnyBandWithThisColorInterpretation(RED_BAND)
301
                && hasAnyBandWithThisColorInterpretation(GREEN_BAND)
302
                && hasAnyBandWithThisColorInterpretation(BLUE_BAND)
303
                && hasAnyBandWithThisColorInterpretation(ALPHA_BAND)) {
304
                return true;
305
            }
306
        }
307
        return false;
308
    }
309
    @Override
310
    public boolean isGray() {
311
        if (colorInterpretation != null && this.length() >= 1
312
            && hasAnyBandWithThisColorInterpretation(GRAY_BAND)) {
313
            return true;
314
        }
315
        return false;
316
    }
317

    
318
    @Override
319
    public boolean hasAnyGrayBand() {
320
        if (colorInterpretation != null) {
321
            for (int i = 0; i < colorInterpretation.length; i++) {
322
                if (colorInterpretation[i] == GRAY_BAND) {
323
                    return true;
324
                }
325
            }
326
        }
327
        return false;
328
    }
329

    
330
    @Override
331
    public boolean hasAnyPaletteBand() {
332
        if (colorInterpretation != null) {
333
            for (int i = 0; i < colorInterpretation.length; i++) {
334
                if (colorInterpretation[i] == PALETTE_BAND) {
335
                    return true;
336
                }
337
            }
338
        }
339
        return false;
340
    }
341

    
342
    @Override
343
    public boolean isColorInterpretation(int band) {
344
        return colorInterpretation[band].equals(RED_BAND)
345
            || colorInterpretation[band].equals(GREEN_BAND)
346
            || colorInterpretation[band].equals(BLUE_BAND)
347
            || colorInterpretation[band].equals(HUE_BAND)
348
            || colorInterpretation[band].equals(SATURATION_BAND)
349
            || colorInterpretation[band].equals(LIGHTNESS_BAND)
350
            || colorInterpretation[band].equals(CYAN_BAND)
351
            || colorInterpretation[band].equals(MAGENTA_BAND)
352
            || colorInterpretation[band].equals(YELLOW_BAND)
353
            || colorInterpretation[band].equals(BLACK_BAND)
354
            || colorInterpretation[band].equals(YCBCR_Y_BAND)
355
            || colorInterpretation[band].equals(YCBCR_CB_BAND)
356
            || colorInterpretation[band].equals(YCBCR_CR_BAND);
357
    }
358

    
359
    @Override
360
    public boolean hasAnyColorInterpretationBand() {
361
        if (colorInterpretation != null) {
362
            for (int i = 0; i < colorInterpretation.length; i++) {
363
                if (isColorInterpretation(i)) {
364
                    return true;
365
                }
366
            }
367
        }
368
        return false;
369
    }
370

    
371
    @Override
372
    public boolean isGrayInterpretation(int band) {
373
        return colorInterpretation[band].equals(GRAY_BAND);
374
    }
375

    
376
    @Override
377
    public boolean isPaletteInterpretation(int band) {
378
        return colorInterpretation[band].equals(PALETTE_BAND);
379
    }
380

    
381
    @Override
382
    public boolean isAlphaInterpretation(int band) {
383
        return colorInterpretation[band].equals(ALPHA_BAND);
384
    }
385

    
386
    @Override
387
    public String get(int i) {
388
        if (i < 0 || i >= colorInterpretation.length) {
389
            throw new IllegalArgumentException("Index out of defined color interpretation");
390
        }
391
        return colorInterpretation[i];
392
    }
393

    
394
    @Override
395
    public int getBand(String id) {
396
        if (colorInterpretation != null && !id.equalsIgnoreCase(ColorInterpretation.UNDEFINED_BAND)) {
397
            for (int i = 0; i < colorInterpretation.length; i++)
398
                if (colorInterpretation[i] != null && colorInterpretation[i].equals(id))
399
                    return i;
400
        }
401
        return -1;
402
    }
403

    
404
    @Override
405
    public boolean isUndefined() {
406
        for (int i = 0; i < colorInterpretation.length; i++) {
407
            if (colorInterpretation[i] != null) {
408
                if (!colorInterpretation[i].equals(ALPHA_BAND))
409
                    return false;
410
            }
411
        }
412
        return true;
413
    }
414

    
415
    @Override
416
    public String[] getValues() {
417
        return colorInterpretation;
418
    }
419

    
420
    @Override
421
    public boolean hasAlphaBand() {
422
        return getAlphaBand() >= 0;
423
    }
424

    
425
    @Override
426
    public int getAlphaBand() {
427
        String[] values = getValues();
428
        for (int i = 0; i < values.length; i++) {
429
            if (values[i] != null && values[i].equals(ALPHA_BAND))
430
                return i;
431
        }
432
        return -1;
433
    }
434

    
435
    @Override
436
    public void addColorInterpretation(ColorInterpretation ci) {
437
        String[] oldColorInterpretation = this.colorInterpretation;
438
        String[] newCI = new String[colorInterpretation.length + ci.length()];
439
        for (int i = 0; i < colorInterpretation.length; i++)
440
            newCI[i] = colorInterpretation[i];
441
        for (int i = 0; i < ci.length(); i++) {
442
            newCI[colorInterpretation.length + i] = ci.get(i);
443
        }
444
        this.colorInterpretation = newCI;
445
        this.notifyObservers(new DefaultColorInterpretationNotification(ColorInterpretationNotification.ADDED_COLOR_INTERPRETATION,
446
            new Object[] { oldColorInterpretation, this.colorInterpretation }));
447

    
448
    }
449

    
450
    public static void registerPersistence() {
451
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
452
        DynStruct definition = manager.getDefinition(PERSISTENCE_DEFINITION);
453
        if (definition == null) {
454
            definition =
455
                manager.addDefinition(DefaultColorInterpretation.class, PERSISTENCE_DEFINITION,
456
                    PERSISTENCE_DESCRIPTION, null, null);
457
            definition.addDynFieldList(COLOR_INTERPRETATION_PERSISTENCE_FIELD)
458
                .setClassOfItems(String.class).setMandatory(false);
459
            definition.addDynFieldInt(PALETTE_BAND_PERSISTENCE_FIELD).setMandatory(false);
460
            definition.addDynFieldObject(COLOR_TABLE_PERSISTENCE_FIELD).setClassOfValue(ColorTable.class);
461
        }
462
    }
463

    
464
    public void saveToState(PersistentState state) throws PersistenceException {
465
        state.set(COLOR_INTERPRETATION_PERSISTENCE_FIELD, colorInterpretation);
466
    }
467

    
468
    @SuppressWarnings("unchecked")
469
    public void loadFromState(PersistentState state) throws PersistenceException {
470
        List<String> descriptions =
471
            (List<String>) state.get(COLOR_INTERPRETATION_PERSISTENCE_FIELD);
472
        this.colorInterpretation = descriptions.toArray(new String[descriptions.size()]);
473
        this.setPaletteBand(state.getInt(PALETTE_BAND_PERSISTENCE_FIELD, -1));
474
        this.setPalette((ColorTable)state.get(COLOR_TABLE_PERSISTENCE_FIELD));
475
    }
476

    
477
    @Override
478
    public void copyFrom(ColorInterpretation colorInterpretation) {
479
        String[] oldColorInterpretation = new String[this.length()];
480
        System.arraycopy(this.colorInterpretation, 0, oldColorInterpretation, 0, length());
481

    
482
        this.colorInterpretation = new String[colorInterpretation.length()];
483
        System.arraycopy(colorInterpretation.getValues(), 0, this.colorInterpretation, 0, colorInterpretation.length());
484
        this.paletteBand = colorInterpretation.getPaletteBand();
485

    
486
        this.notifyObservers(new DefaultColorInterpretationNotification(ColorInterpretationNotification.COPIED_FROM_COLOR_INTERPRETATION,
487
            new Object[] { oldColorInterpretation, this.colorInterpretation }));
488
    }
489

    
490
    @Override
491
    public Object clone() throws CloneNotSupportedException {
492
        ColorInterpretation cloned = new DefaultColorInterpretation(this.length());
493
        cloned.copyFrom(this);
494
        if(this.colorTable!=null){
495
            cloned.setPalette((ColorTable)this.colorTable.clone());
496
        }
497
        return cloned;
498
    }
499

    
500
    @Override
501
    public boolean hasAnyHSLBand() {
502
        if (colorInterpretation != null) {
503
            boolean hueFound = false;
504
            boolean saturationFound = false;
505
            boolean lightnessFound = false;
506
            for (int i = 0; i < colorInterpretation.length; i++) {
507
                if (colorInterpretation[i] == HUE_BAND) {
508
                    hueFound = true;
509
                }
510
                if (colorInterpretation[i] == SATURATION_BAND) {
511
                    saturationFound = true;
512
                }
513
                if (colorInterpretation[i] == LIGHTNESS_BAND) {
514
                    lightnessFound = true;
515
                }
516
            }
517
            if (hueFound || saturationFound || lightnessFound) {
518
                return true;
519
            }
520
        }
521
        return false;
522
    }
523

    
524
    @Override
525
    public boolean hasAnyCMYKBand() {
526
        if (colorInterpretation != null) {
527
            boolean cyanFound = false;
528
            boolean magentaFound = false;
529
            boolean yellowFound = false;
530
            boolean blackFound = false;
531
            for (int i = 0; i < colorInterpretation.length; i++) {
532
                if (colorInterpretation[i] == CYAN_BAND) {
533
                    cyanFound = true;
534
                }
535
                if (colorInterpretation[i] == MAGENTA_BAND) {
536
                    magentaFound = true;
537
                }
538
                if (colorInterpretation[i] == YELLOW_BAND) {
539
                    yellowFound = true;
540
                }
541
                if (colorInterpretation[i] == BLACK_BAND) {
542
                    blackFound = true;
543
                }
544
            }
545
            if (cyanFound || magentaFound || yellowFound || blackFound) {
546
                return true;
547
            }
548
        }
549
        return false;
550
    }
551

    
552
    @Override
553
    public boolean hasAnyYCBCRBand() {
554
        if (colorInterpretation != null) {
555
            boolean cBFound = false;
556
            boolean cRFound = false;
557
            boolean yFound = false;
558
            for (int i = 0; i < colorInterpretation.length; i++) {
559
                if (colorInterpretation[i] == YCBCR_CB_BAND) {
560
                    cBFound = true;
561
                }
562
                if (colorInterpretation[i] == YCBCR_CR_BAND) {
563
                    cRFound = true;
564
                }
565
                if (colorInterpretation[i] == YCBCR_Y_BAND) {
566
                    yFound = true;
567
                }
568
            }
569
            if (cBFound || cRFound || yFound ) {
570
                return true;
571
            }
572
        }
573
        return false;
574
    }
575

    
576
    @Override
577
    public boolean isPalette() {
578
        if(this.paletteBand>=0 && this.paletteBand<this.length() && this.colorTable!=null){
579
            return true;
580
        }
581
        return false;
582
    }
583

    
584
    @Override
585
    public void setPalette(ColorTable colorTable) {
586
        ColorTable oldColorTable = this.colorTable;
587
        if (colorTable != null && !colorTable.equals(oldColorTable)) {
588
            if(oldColorTable!=null){
589
                oldColorTable.deleteObserver(this);
590
            }
591
            this.colorTable = colorTable;
592
            this.colorTable.addObserver(this);
593
            this.notifyObservers(new DefaultColorInterpretationNotification(
594
                ColorInterpretationNotification.SETTED_PALETTE, new Object[] { oldColorTable, colorTable }));
595
        }
596
    }
597

    
598
    @Override
599
    public void setPaletteBand(int band) {
600
        if (band != this.paletteBand) {
601
            int oldPaletteBand = this.paletteBand;
602
            if (band >= 0 && band < this.length()) {
603
                this.paletteBand = band;
604
            } else {
605
                this.paletteBand = -1;
606
            }
607
            this.notifyObservers(new DefaultColorInterpretationNotification(
608
                ColorInterpretationNotification.SETTED_PALETTE_BAND, new Object[] { new Integer(oldPaletteBand),
609
                    new Integer(this.paletteBand) }));
610
        }
611
    }
612

    
613
    @Override
614
    public int getPaletteBand() {
615
        return this.paletteBand;
616
    }
617

    
618
    @Override
619
    public ColorTable getPalette() {
620
        return this.colorTable;
621
    }
622

    
623
    @Override
624
    public void update(Observable observable, Object notification) {
625
        if (notification instanceof ColorTableNotification && observable instanceof ColorTable) {
626
            Notification colorTableNotification = (Notification) notification;
627
            if (colorTableNotification.getType().equals(ColorTableNotification.CHANGED_INTERPOLATED_COLOR_TABLE)
628
                || colorTableNotification.getType().equals(ColorTableNotification.COMPRESSED_COLOR_TABLE)
629
                || colorTableNotification.getType().equals(ColorTableNotification.COPIED_FROM_COLOR_TABLE)
630
                || colorTableNotification.getType().equals(ColorTableNotification.REMOVED_DUPLICATED_VALUES_COLOR_TABLE)
631
                || colorTableNotification.getType().equals(ColorTableNotification.SETTED_CLASS_VALUES_COLOR_TABLE)) {
632
                this.notifyObservers(new DefaultColorInterpretationNotification(ColorInterpretationNotification.CHANGED_PALETTE,
633
                    new Object[] { observable }));
634
            }
635
        }
636
    }
637

    
638
}