root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TransparencyControl.java @ 10940
History | View | Annotate | Download (3.94 KB)
1 |
/* 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.util.TransparencyRange; |
25 |
|
26 |
/**
|
27 |
*
|
28 |
* Clase que hace de interfaz entre los objetos que contienen la informaci?n de
|
29 |
* transparencia y el panel.
|
30 |
*
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
32 |
*/
|
33 |
public class TransparencyControl{ |
34 |
private GridTransparency transparency = null; |
35 |
private TransparencyPanel tPanel = null; |
36 |
|
37 |
/**
|
38 |
* Constructor
|
39 |
* @param tp
|
40 |
*/
|
41 |
public TransparencyControl(TransparencyPanel tp){
|
42 |
this.tPanel = tp;
|
43 |
} |
44 |
|
45 |
public void setTransparencyObject(GridTransparency t){ |
46 |
this.transparency = t;
|
47 |
setValuesFromGridTransparencyToPanel(); |
48 |
} |
49 |
|
50 |
/**
|
51 |
* Carga los valores del panel desde el objeto con la transparencia
|
52 |
*/
|
53 |
private void setValuesFromGridTransparencyToPanel(){ |
54 |
//Asignamos la opacidad al panel
|
55 |
if(transparency.getOpacity() != 255){ |
56 |
tPanel.getOpacityPanel().setControlEnabled(true);
|
57 |
tPanel.getOpacityPanel().setValue((int)(transparency.getOpacity() * 100) / 255); |
58 |
}else{
|
59 |
tPanel.getOpacityPanel().setControlEnabled(false);
|
60 |
tPanel.getOpacityPanel().setValue(100);
|
61 |
} |
62 |
|
63 |
//Asignamos los rangos de transparencia al panel
|
64 |
if(transparency.getTransparencyRange().size() > 0){ |
65 |
tPanel.getPTranspByPixel().clear(); |
66 |
tPanel.getPTranspByPixel().setControlEnabled(true);
|
67 |
for(int i = 0; i < transparency.getTransparencyRange().size(); i ++){ |
68 |
TransparencyRange range = (TransparencyRange)transparency.getTransparencyRange().get(i); |
69 |
tPanel.getPTranspByPixel().addStringElement(range); |
70 |
} |
71 |
}else{
|
72 |
tPanel.getPTranspByPixel().clear(); |
73 |
tPanel.getPTranspByPixel().setControlEnabled(false);
|
74 |
} |
75 |
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* Carga los valores del objeto transparencia desde el panel
|
80 |
*/
|
81 |
private void setValuesFromPanelToGridTransparency(){ |
82 |
|
83 |
//Asignamos la opacidad al objeto
|
84 |
if(tPanel.getOpacityPanel().getCheck().isSelected()){
|
85 |
transparency.setOpacity((int)Math.round((tPanel.getOpacityPanel().getValue() * 255) / 100)); |
86 |
}else
|
87 |
transparency.setOpacity(255);
|
88 |
|
89 |
//Asignamos los rangos de transparencia al objeto
|
90 |
if(tPanel.getPTranspByPixel().getActiveCheck().isSelected()){
|
91 |
transparency.clearListOfTransparencyRange(); |
92 |
ArrayList entries = tPanel.getPTranspByPixel().getEntries();
|
93 |
for(int i = 0; i < entries.size(); i++) |
94 |
transparency.setTransparencyRange((TransparencyRange)entries.get(i)); |
95 |
}else
|
96 |
transparency.clearListOfTransparencyRange(); |
97 |
|
98 |
transparency.activeTransparency(); |
99 |
|
100 |
//Redibujamos
|
101 |
if(tPanel.getLayer() != null) |
102 |
tPanel.getLayer().getMapContext().invalidate(); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* Acciones a ejecutar cuando se acepta
|
107 |
*/
|
108 |
public void accept(){ |
109 |
setValuesFromPanelToGridTransparency(); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Acciones a ejecutar cuando se aplica
|
114 |
*/
|
115 |
public void apply(){ |
116 |
setValuesFromPanelToGridTransparency(); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Acciones a ejecutar cuando se cancela
|
121 |
*/
|
122 |
public void cancel(){ |
123 |
|
124 |
} |
125 |
|
126 |
} |