Revision 47724

View differences:

branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.mapcontext.layers.order.impl.BasicLayerOrderLibrary
2
org.gvsig.fmap.mapcontext.raster.impl.MapContextRasterLibrary
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/fmap/mapcontext/impl/i18n/text.properties
1
_Raster_at_bottom_then_polygons_lines_points=Capas de im?genes en el fondo, despu?s pol?gonos, l?neas y puntos
2
_Raster_Polygon_Line_Point_order_manager=Orden Im?genes-Pol?gonos-L?neas-Puntos
3
_Default_order=Orden por defecto
4
_Layers_are_placed_always_on_top=Las capas se colocan siempre sobre las existentes
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/fmap/mapcontext/impl/i18n/text_en.properties
1
_Raster_at_bottom_then_polygons_lines_points=Raster layers at bottom, then polygon, linear and point layers
2
_Raster_Polygon_Line_Point_order_manager=Raster-Polygon-Line-Point order
3
_Default_order=Default order
4
_Layers_are_placed_always_on_top=Layers are placed always on top
5

  
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/cmyktorgb/CMYKToRGBOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="CMYKToRGBOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>CMYKToRGBOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
19
          defaultValue="true" group="Basic">
20
          <description>Marked if it must copy the unprocessed bands</description>
21
        </field>
22
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
23
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
24
          hidden="true">
25
          <description></description>
26
        </field>      </fields>
27
    </class>
28

  
29
  </classes>
30
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/rgbtocmyk/RGBToCMYKOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="RGBToCMYKOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>RGBToCMYKOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
19
          defaultValue="true" group="Basic">
20
          <description>Marked if it must copy the unprocessed bands</description>
21
        </field>
22
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
23
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
24
          hidden="true">
25
          <description></description>
26
        </field>      </fields>
27
    </class>
28

  
29
  </classes>
30
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/hsltorgb/HSLToRGBOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="HSLToRGBOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>HSLToRGBOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
19
          defaultValue="true" group="Basic">
20
          <description>Marked if it must copy the unprocessed bands</description>
21
        </field>
22
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
23
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
24
          hidden="true">
25
          <description></description>
26
        </field>
27
      </fields>
28
    </class>
29

  
30
  </classes>
31
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/rgbtohsl/RGBToHSLOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="RGBToHSLOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>RGBToHSLOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
19
          defaultValue="true" group="Basic">
20
          <description>Marked if it must copy the unprocessed bands</description>
21
        </field>
22
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
23
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
24
          hidden="true">
25
          <description></description>
26
        </field>
27
      </fields>
28
    </class>
29

  
30
  </classes>
31
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/equalization/EqualizationOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="EqualizationOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>EqualizationOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true"
12
          group="Basic"
13
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
14
          hidden="true">
15
          <description></description>
16
          <tags>
17
            <valueItem name="lookupParameter" value="output_color_interpretation" />
18
          </tags>
19
          <description></description>
20
        </field>
21
        <field name="statistics" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.buffer.api.statistics.Statistics" hidden="true">
22
          <description></description>
23
        </field>
24
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
25
          defaultValue="true" group="Basic">
26
          <description>Marked if it must copy the unprocessed bands</description>
27
        </field>
28
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
29
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
30
          hidden="true">
31
          <description></description>
32
        </field>
33
      </fields>
34
    </class>
35

  
36
  </classes>
37
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/colortable/ColorTableOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="ColorTableOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>ColorTableOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
19
          defaultValue="true" group="Basic">
20
          <description>Marked if it must copy the unprocessed bands</description>
21
        </field>
22
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
23
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
24
          hidden="true">
25
          <description></description>
26
        </field>      </fields>
27
    </class>
28

  
29
  </classes>
30
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/brightness/BrightnessOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="BrightnessOperationParameters">
7
      <extends>
8
      </extends>
9
      <description>BrightnessOperationParameters</description>
10
      <fields>
11
        <field name="brightness" type="integer" mandatory="true" group="Basic"
12
          minValue="-255" maxValue="255" defaultValue="0">
13
          <description>Integer value [-255,255]</description>
14
        </field>
15
        <field name="color_interpretation" type="object" mandatory="true"
16
          group="Basic"
17
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
18
          hidden="true">
19
          <tags>
20
            <valueItem name="lookupParameter" value="output_color_interpretation" />
21
          </tags>
22
          <description></description>
23
        </field>
24
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
25
          defaultValue="true" group="Basic">
26
          <description>Marked if it must copy the unprocessed bands</description>
27
        </field>
28
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
29
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
30
          hidden="true">
31
          <description></description>
32
        </field>
33
      </fields>
34
    </class>
35

  
36
  </classes>
37
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/grayscale/GrayScaleOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="GrayScaleOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>GrayScaleOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
19
          defaultValue="true" group="Basic">
20
          <description>Marked if it must copy the unprocessed bands</description>
21
        </field>
22
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
23
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
24
          hidden="true">
25
          <description></description>
26
        </field>
27
      </fields>
28
    </class>
29

  
30
  </classes>
31
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/colorbalancehsl/ColorBalanceHSLOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="ColorBalanceHSLOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>ColorBalanceHSLOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="hue" type="double" mandatory="true" group="Basic" minValue="-180" maxValue="180" defaultValue="0">
19
          <description>Double value [-180,180]</description>
20
        </field>
21
        <field name="lightness" type="double" mandatory="true" group="Basic" minValue="-100" maxValue="100" defaultValue="0">
22
          <description>Double value [-100,100]</description>
23
        </field>
24
        <field name="saturation" type="double" mandatory="true" group="Basic" minValue="-100" maxValue="100" defaultValue="0">
25
          <description>Double value [-100,100]</description>
26
        </field>
27
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
28
          defaultValue="true" group="Basic">
29
          <description>Marked if it must copy the unprocessed bands</description>
30
        </field>
31
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
32
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
33
          hidden="true">
34
          <description></description>
35
        </field>
36

  
37
      </fields>
38
    </class>
39

  
40
  </classes>
41
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/colorbalancecmy/ColorBalanceCMYOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="ColorBalanceCMYOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>ColorBalanceCMYOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="cyan" type="integer" mandatory="true" group="Basic" minValue="0" maxValue="100" defaultValue="0">
19
          <description>Integer value [0,100]</description>
20
        </field>
21
        <field name="magenta" type="integer" mandatory="true" group="Basic" minValue="0" maxValue="100" defaultValue="0">
22
          <description>Integer value [0,100]</description>
23
        </field>
24
        <field name="yellow" type="integer" mandatory="true" group="Basic" minValue="0" maxValue="100" defaultValue="0">
25
          <description>Integer value [0,100]</description>
26
        </field>
27
        <field name="luminosity" type="boolean" mandatory="false" group="Basic" defaultValue="false">
28
          <description>Marked if it must respect the luminosity</description>
29
        </field>
30
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
31
          defaultValue="true" group="Basic">
32
          <description>Marked if it must copy the unprocessed bands</description>
33
        </field>
34
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
35
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
36
          hidden="true">
37
          <description></description>
38
        </field>
39

  
40
      </fields>
41
    </class>
42

  
43
  </classes>
44
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/contrast/ContrastOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="ContrastOperationParameters">
7
      <extends>
8
      </extends>
9
      <description>ContrastOperationParameters</description>
10
      <fields>
11
        <field name="contrast" type="integer" mandatory="true" group="Basic"
12
          minValue="-255" maxValue="255" defaultValue="0">
13
          <description>Integer value [-255,255]</description>
14
        </field>
15
        <field name="color_interpretation" type="object" mandatory="true"
16
          group="Basic"
17
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
18
          hidden="true">
19
          <description></description>
20
          <tags>
21
            <valueItem name="lookupParameter" value="output_color_interpretation" />
22
          </tags>
23
          <description></description>
24
        </field>
25
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
26
          defaultValue="true" group="Basic">
27
          <description>Marked if it must copy the unprocessed bands</description>
28
        </field>
29
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
30
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
31
          hidden="true">
32
          <description></description>
33
        </field>
34

  
35
      </fields>
36
    </class>
37

  
38
  </classes>
39
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/pansharpening/PansharpeningOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="PansharpeningOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>PansharpeningOperationParameters</description>
10
      <fields>
11
        <field name="statistics" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.buffer.api.statistics.Statistics">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
19
          <description></description>
20
        </field>
21
        <!-- <field name="bands_to_process" type="List" typeOfItems="integer" mandatory="false" group="Basic">
22
          <description></description>
23
        </field> -->
24
      </fields>
25
    </class>
26

  
27
  </classes>
28
</definitions>
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/raster/lib/legend/impl/operations/colorbalancergb/ColorBalanceRGBOperationParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="ColorBalanceRGBOperationParameters">
7
       <extends>
8
      </extends>
9
      <description>ColorBalanceRGBOperationParameters</description>
10
      <fields>
11
        <field name="color_interpretation" type="object" mandatory="true" group="Basic" classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation" hidden="true">
12
          <description></description>
13
          <tags>
14
            <valueItem name="lookupParameter" value="output_color_interpretation" />
15
          </tags>
16
          <description></description>
17
        </field>
18
        <field name="red" type="integer" mandatory="true" group="Basic" minValue="0" maxValue="100" defaultValue="50">
19
          <description>Integer value [-100,100]</description>
20
        </field>
21
        <field name="green" type="integer" mandatory="true" group="Basic" minValue="0" maxValue="100" defaultValue="50">
22
          <description>Integer value [-100,100]</description>
23
        </field>
24
        <field name="blue" type="integer" mandatory="true" group="Basic" minValue="0" maxValue="100" defaultValue="50">
25
          <description>Integer value [-100,100]</description>
26
        </field>
27
        <field name="luminosity" type="boolean" mandatory="false" group="Basic" defaultValue="false">
28
          <description>Marked if it must copy the unprocessed bands</description>
29
        </field>
30
        <field name="copy_unprocessed_bands" type="boolean" mandatory="false"
31
          defaultValue="true" group="Basic">
32
          <description>Marked if it must copy the unprocessed bands</description>
33
        </field>
34
        <field name="output_color_interpretation" type="object" mandatory="false" group="Basic"
35
          classOfValue="org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation"
36
          hidden="true">
37
          <description></description>
38
        </field>
39

  
40

  
41
      </fields>
42
    </class>
43

  
44
  </classes>
45
</definitions>
0 46

  
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/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
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
}
branches/org.gvsig.desktop-2.0.411-vcsgis1_0_96/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/DefaultColorTable.java
1
package org.gvsig.raster.lib.legend.impl;
2

  
3
import java.awt.Color;
4
import java.io.File;
5
import java.util.ArrayList;
6
import java.util.Collections;
7
import java.util.List;
8

  
9
import org.apache.commons.lang3.StringUtils;
10

  
11
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
12
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
13
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretationNotification;
14
import org.gvsig.raster.lib.legend.api.colortable.ColorTable;
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;
20
import org.gvsig.tools.ToolsLocator;
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;
25
import org.gvsig.tools.persistence.PersistenceManager;
26
import org.gvsig.tools.persistence.PersistentState;
27
import org.gvsig.tools.persistence.exception.PersistenceException;
28

  
29
/**
30
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
31
 *
32
 */
33
public class DefaultColorTable extends BaseWeakReferencingObservable implements ColorTable {
34

  
35
    /**
36
     * Persistence definition name
37
     */
38
    public static final String PERSISTENT_NAME = "ColorTablePersistent";
39
    /**
40
     * Description of persistence definition
41
     */
42
    public static final String PERSISTENT_DESCRIPTION = "Persistent definition of color table";
43

  
44
    private static final String NAME_PERSISTENCE_FIELD = "name";
45
    private static final String RANGE_PERSISTENCE_FIELD = "range";
46
    private static final String NAME_CLASS_PERSISTENCE_FIELD = "nameClass";
47
    private static final String CLASSES_PERSISTENCE_FIELD = "classes";
48
    private static final String PALETTE_BY_BAND_PERSISTENCE_FIELD = "paletteByBand";
49
    private static final String INTERPOLATED_PERSISTENCE_FIELD = "interpolated";
50
    private static final String ERROR_COLOR_PERSISTENCE_FIELD = "errorColor";
51

  
52
    /**
53
     * Default number of classes when {@link ColorTable} is created
54
     */
55
    private static final int defaultNumberOfClasses = 256;
56

  
57
    private List<ColorTableClass> classes;
58
    private String name;
59
    private boolean interpolated;
60
    private int errorColor = 8;
61
    private double[] classValues = null;
62
    private byte[][] paletteByBand = null;
63
    private String[] classNames = null;
64

  
65
    /**
66
     * Empty constructor
67
     */
68
    public DefaultColorTable() {
69

  
70
    }
71

  
72
    /**
73
     * Default constructor
74
     *
75
     * @param name
76
     *            Name of {@link ColorTable}
77
     * @param classes
78
     *            Classes of {@link ColorTable}
79
     * @param interpolated
80
     *            True if this {@link ColorTable} is interpolated
81
     */
82
    public DefaultColorTable(String name, List<ColorTableClass> classes, boolean interpolated) {
83

  
84
        if (isNamePath(name)) {
85
            throw new IllegalArgumentException("Name of Color table can not be a path");
86
        }
87

  
88
        this.name = name;
89
        this.classes = classes;
90
        this.interpolated = interpolated;
91
        observeClasses();
92
        reCalculateColorTable(false);
93
    }
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

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

  
110
        classValues = new double[0];
111
        classNames = new String[0];
112

  
113
        if (colorItems.size() == 0) {
114
            return;
115
        }
116

  
117
        double min = colorItems.get(0).getValue();
118
        double max = colorItems.get(colorItems.size() - 1).getValue();
119

  
120
        if (min > max) {
121
            double aux = max;
122
            max = min;
123
            min = aux;
124
        }
125

  
126
        Color color = Color.white;
127
        Color colorOld = null;
128

  
129
        // Make parts, keeping each class in an array
130
        for (int i = 0; i < defaultNumberOfClasses; i++) {
131
            double value = min + ((i * (max - min)) / (defaultNumberOfClasses - 1));
132
            int pos = 0;
133
            for (int j = 1; j <= colorItems.size(); j++) {
134
                if (j < colorItems.size()) {
135
                    if (value < colorItems.get(j).getValue()) {
136
                        pos = j - 1;
137
                        break;
138
                    }
139
                } else {
140
                    pos = j - 1;
141
                    break;
142
                }
143
            }
144

  
145
            // Calculate palette color
146
            if (interpolated) {
147
                color = interpolatedColor(value, pos);
148
            } else {
149
                if ((pos + 1) < colorItems.size()) {
150
                    double min2 = colorItems.get(pos).getValue();
151
                    double max2 = colorItems.get(pos + 1).getValue();
152
                    if ((min2 + ((max2 - min2) * colorItems.get(pos + 1).getInterpolated() / 100)) < value) {
153
                        pos++;
154
                    }
155
                }
156
                color = colorItems.get(pos).getColor();
157
            }
158

  
159
            if (!isEqualColor(color, colorOld, 0)) {
160
                ColorTableClass colorItem = new DefaultColorTableClass();
161
                colorItem.setValue(value);
162
                colorItem.setColor(color);
163
                arrayColors.add(colorItem);
164
            }
165

  
166
            colorOld = color;
167
        }
168

  
169
        // Una vez tenemos una paleta de 256 colores o inferior, rellenamos
170
        // los siguientes valores para hacer busquedas rapidas.
171
        paletteByBand = new byte[arrayColors.size()][4];
172
        classValues = new double[arrayColors.size()];
173
        classNames = new String[arrayColors.size()];
174

  
175
        for (int i = 0; i < arrayColors.size(); i++) {
176
            paletteByBand[i][0] = (byte) arrayColors.get(i).getColor().getRed();
177
            paletteByBand[i][1] = (byte) arrayColors.get(i).getColor().getGreen();
178
            paletteByBand[i][2] = (byte) arrayColors.get(i).getColor().getBlue();
179
            paletteByBand[i][3] = (byte) arrayColors.get(i).getColor().getAlpha();
180
            classValues[i] = arrayColors.get(i).getValue();
181
            classNames[i] = arrayColors.get(i).getName();
182
        }
183
    }
184

  
185
    private boolean canDelete(int first, int last) {
186
        if (first >= getClasses().size()) {
187
            return false;
188
        }
189
        if (last >= getClasses().size()) {
190
            return false;
191
        }
192
        ColorTableClass c1 = getClasses().get(first);
193
        ColorTableClass c2 = getClasses().get(last);
194
        for (int i = (first + 1); i < last; i++) {
195
            if (!isCorrectColor(c1, c2, getClasses().get(i))) {
196
                return false;
197
            }
198
        }
199
        return true;
200
    }
201

  
202
    @Override
203
    public void compressPalette() {
204
        removeDuplicatedValues();
205
        int size = -1;
206

  
207
        while (size != classes.size()) {
208
            int init = 0;
209
            int posMax = 2;
210

  
211
            size = classes.size();
212
            while (init < classes.size()) {
213
                if ((posMax < classes.size()) && canDelete(init, posMax)) {
214
                    posMax++;
215
                    continue;
216
                }
217
                if ((init + 2) < posMax) {
218
                    if (canDelete(init, posMax - 1)) {
219
                        for (int i = (posMax - 2); i > init; i--) {
220
                            if (i < classes.size()) {
221
                                classes.remove(i);
222
                            }
223
                        }
224
                    }
225
                }
226
                init++;
227
                posMax = init + 2;
228
            }
229
        }
230
    }
231

  
232
    @Override
233
    public void copyFrom(ColorTable colorTable) {
234
        RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager();
235
        this.interpolated = colorTable.isInterpolated();
236
        this.name = colorTable.getName();
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 }));
249
    }
250

  
251
    @Override
252
    public List<ColorTableClass> getClasses() {
253
        return this.classes;
254
    }
255

  
256
    @Override
257
    public String getName() {
258
        return this.name;
259
    }
260

  
261
    @Override
262
    public boolean hasAlpha() {
263
        for (int i = 0; i < classes.size(); i++) {
264
            ColorTableClass colorTableClass = classes.get(i);
265
            if (colorTableClass.getColor().getAlpha() != 255) {
266
                return true;
267
            }
268
        }
269
        return false;
270
    }
271

  
272
    private Color interpolatedColor(double value, int pos) {
273
        if (classes.size() <= 0) {
274
            return Color.black;
275
        }
276

  
277
        if ((pos + 1) == classes.size()) {
278
            return classes.get(pos).getColor();
279
        }
280

  
281
        if (value <= classes.get(0).getValue()) {
282
            return classes.get(0).getColor();
283
        }
284

  
285
        ColorTableClass item1 = classes.get(pos);
286
        ColorTableClass item2 = classes.get(pos + 1);
287

  
288
        double percValue =
289
            ((value - item1.getValue()) * 100) / (item2.getValue() - item1.getValue());
290

  
291
        Color halfColor =
292
            new Color((item2.getColor().getRed() + item1.getColor().getRed()) >> 1, (item2
293
                .getColor().getGreen() + item1.getColor().getGreen()) >> 1, (item2.getColor()
294
                .getBlue() + item1.getColor().getBlue()) >> 1, (item2.getColor().getAlpha() + item1
295
                .getColor().getAlpha()) >> 1);
296

  
297
        Color color1, color2;
298
        double perc1, perc2;
299

  
300
        if (percValue > item2.getInterpolated()) {
301
            color1 = halfColor;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff