Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TransparencyControl.java @ 10740

History | View | Annotate | Download (4 KB)

1 10740 nacho
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.properties.panels;
20
21
import java.util.ArrayList;
22
23
import org.gvsig.raster.grid.GridTransparency;
24
import org.gvsig.raster.shared.TransparencyRange;
25
import org.gvsig.raster.shared.TransparencyRangeException;
26
27
/**
28
 *
29
 * Clase que hace de interfaz entre los objetos que contienen la informaci?n de
30
 * transparencia y el panel.
31
 *
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public class TransparencyControl{
35
    private GridTransparency transparency = null;
36
    private TransparencyPanel tPanel = null;
37
38
    /**
39
     * Constructor
40
     * @param tp
41
     */
42
    public TransparencyControl(TransparencyPanel tp){
43
            this.tPanel = tp;
44
    }
45
46
    public void setTransparencyObject(GridTransparency t){
47
            this.transparency = t;
48
            setValuesFromGridTransparencyToPanel();
49
    }
50
51
    /**
52
     * Carga los valores del panel desde el objeto con la transparencia
53
     */
54
    private void setValuesFromGridTransparencyToPanel(){
55
            //Asignamos la opacidad al panel
56
            if(transparency.getOpacity() != 255){
57
                    tPanel.getOpacityPanel().setControlEnabled(true);
58
                    tPanel.getOpacityPanel().setValue((int)(transparency.getOpacity() * 100) / 255);
59
            }else{
60
                    tPanel.getOpacityPanel().setControlEnabled(false);
61
                    tPanel.getOpacityPanel().setValue(100);
62
            }
63
64
            //Asignamos los rangos de transparencia al panel
65
            if(transparency.getTransparencyRange().size() > 0){
66
                    tPanel.getPTranspByPixel().clear();
67
                        tPanel.getPTranspByPixel().setControlEnabled(true);
68
                    for(int i = 0; i < transparency.getTransparencyRange().size(); i ++){
69
                            TransparencyRange range = (TransparencyRange)transparency.getTransparencyRange().get(i);
70
                            tPanel.getPTranspByPixel().addStringElement(range);
71
                    }
72
            }else{
73
                    tPanel.getPTranspByPixel().clear();
74
                    tPanel.getPTranspByPixel().setControlEnabled(false);
75
            }
76
77
    }
78
79
    /**
80
     * Carga los valores del objeto transparencia desde el panel
81
     */
82
    private void setValuesFromPanelToGridTransparency(){
83
84
            //Asignamos la opacidad al objeto
85
            if(tPanel.getOpacityPanel().getCheck().isSelected()){
86
                    transparency.setOpacity((int)Math.round((tPanel.getOpacityPanel().getValue() * 255) / 100));
87
            }else
88
                    transparency.setOpacity(255);
89
90
            //Asignamos los rangos de transparencia al objeto
91
            if(tPanel.getPTranspByPixel().getActiveCheck().isSelected()){
92
                    transparency.clearListOfTransparencyRange();
93
                    ArrayList entries = tPanel.getPTranspByPixel().getEntries();
94
                    for(int i = 0; i < entries.size(); i++)
95
                                transparency.setTransparencyRange((TransparencyRange)entries.get(i));
96
            }else
97
                    transparency.clearListOfTransparencyRange();
98
99
            transparency.activeTransparency();
100
101
            //Redibujamos
102
            if(tPanel.getLayer() != null)
103
                    tPanel.getLayer().getMapContext().invalidate();
104
    }
105
106
    /**
107
         * Acciones a ejecutar cuando se acepta
108
         */
109
        public void accept(){
110
                setValuesFromPanelToGridTransparency();
111
        }
112
113
        /**
114
         * Acciones a ejecutar cuando se aplica
115
         */
116
        public void apply(){
117
                setValuesFromPanelToGridTransparency();
118
        }
119
120
        /**
121
         * Acciones a ejecutar cuando se cancela
122
         */
123
        public void cancel(){
124
125
        }
126
127
}