Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / ColorTableListener.java @ 12942

History | View | Annotate | Download (5.22 KB)

1 12369 bsanchez
/* 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 12344 bsanchez
package org.gvsig.rastertools.colortable;
20
21 12553 bsanchez
import java.awt.Dimension;
22 12344 bsanchez
import java.awt.Graphics2D;
23 12553 bsanchez
import java.awt.geom.AffineTransform;
24
import java.awt.geom.Dimension2D;
25 12344 bsanchez
26 12553 bsanchez
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
27 12344 bsanchez
import org.gvsig.gui.beans.imagenavigator.IClientImageNavigator;
28 12553 bsanchez
import org.gvsig.raster.datastruct.Extent;
29
import org.gvsig.raster.datastruct.ViewPortData;
30 12568 bsanchez
import org.gvsig.raster.grid.GridPalette;
31
import org.gvsig.raster.grid.GridTransparency;
32 12553 bsanchez
import org.gvsig.raster.grid.filter.RasterFilterList;
33
import org.gvsig.raster.grid.filter.RasterFilterListManager;
34
import org.gvsig.raster.grid.filter.bands.ColorTableListManager;
35
import org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter;
36
import org.gvsig.raster.grid.filter.statistics.TailTrimFilter;
37
import org.gvsig.raster.grid.render.Rendering;
38
import org.gvsig.rastertools.colortable.ui.ColorTablePanel;
39
40
import com.iver.cit.gvsig.fmap.ViewPort;
41 12369 bsanchez
/**
42
 *
43
 * @version 27/06/2007
44
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
45
 */
46 12344 bsanchez
public class ColorTableListener implements IClientImageNavigator {
47 12553 bsanchez
        private ColorTablePanel colorTablePanel = null;
48 12344 bsanchez
49 12568 bsanchez
        /**
50
         * Construye un ColorTableListener
51
         * @param colorTablePanel
52
         */
53 12553 bsanchez
        public ColorTableListener(ColorTablePanel colorTablePanel) {
54
                this.colorTablePanel = colorTablePanel;
55
        }
56
57
        /*
58
         * (non-Javadoc)
59
         * @see org.gvsig.gui.beans.imagenavigator.IClientImageNavigator#drawImage(java.awt.Graphics2D, double, double, double, double, double, int, int)
60
         */
61 12344 bsanchez
        public void drawImage(Graphics2D g, double x1, double y1, double x2, double y2, double zoom, int width, int height) {
62 12553 bsanchez
                if (colorTablePanel.getLayer() == null)
63
                        return;
64 12344 bsanchez
65 12553 bsanchez
                Rendering rendering = ((FLyrRasterSE) colorTablePanel.getLayer()).getRender();
66
67
                if ((rendering == null) || ((x2 - x1) == 0.0) || ((y2 - y1) == 0.0))
68
                        return;
69
70
                rendering.getFilterList().pushStatus();
71
72
                ViewPort vp = new ViewPort(null);
73
74
                Dimension2D dimension = new Dimension(width, height);
75
                Extent extent = new Extent(x1, y1, x2, y2);
76
77
                ViewPortData vp2 = new ViewPortData(vp.getProjection(), extent, dimension);
78
                vp2.setMat(new AffineTransform(zoom, 0.0, 0.0, zoom, -x1*zoom, -y1*zoom));
79
80
                Extent extent2 = ((FLyrRasterSE) colorTablePanel.getLayer()).getDatasource().getExtent();
81
82
                AffineTransform trans = g.getTransform();
83
                // Calcular cuanto sobresale la imagen y rectificar ese desplazamiento
84
                if (y1 > extent2.maxY()) {
85
                        g.translate(0.0, (-(extent2.maxY() - y1) * zoom)*2.0);
86
                }
87
88 12568 bsanchez
                GridTransparency lastTransparency = rendering.getLastTransparency();
89
                applyColorTable(rendering);
90 12553 bsanchez
                rendering.draw(g, vp2);
91 12568 bsanchez
                rendering.setLastTransparency(lastTransparency);
92
93 12553 bsanchez
                g.setTransform(trans);
94
95
                rendering.getFilterList().popStatus();
96 12344 bsanchez
        }
97 12568 bsanchez
98
        /**
99
         * Aqui se aplica el estado de las tablas de color al rendering pasado
100
         * por parametro
101
         * @param rendering
102
         * @return
103
         */
104
        public void applyColorTable(Rendering rendering) {
105
                RasterFilterList filterList = rendering.getFilterList();
106
                RasterFilterListManager stackManager = new RasterFilterListManager(filterList);
107
                ColorTableListManager cManager = (ColorTableListManager) stackManager.getManagerByClass(ColorTableListManager.class);
108
109
                filterList.remove(LinearEnhancementFilter.class);
110
                filterList.remove(TailTrimFilter.class);
111
112
                GridPalette gridPalette = colorTablePanel.getGridPalette();
113
                cManager.addColorTableFilter(gridPalette);
114
115
                GridTransparency gridTransparency = new GridTransparency();
116
                gridTransparency.setTransparencyRangeList(gridPalette.getTransparencyRange());
117
                gridTransparency.activeTransparency();
118
119
                rendering.setLastTransparency(gridTransparency);
120
        }
121
122
        /**
123
         * Que acciones se ejecutaran al haber presionado el bot?n aceptar o aplicar
124
         */
125
        public void accept() {
126 12914 bsanchez
127
                /*
128
                IWindow windows[] = PluginServices.getMDIManager().getAllWindows();
129
                for (int i=0;i<windows.length;i++) {
130
                        if(windows[i] instanceof IView)
131
                                ((IView)windows[i]).getTOC().refresh();
132
                }
133
                */
134
135 12568 bsanchez
                Rendering rendering = ((FLyrRasterSE) getColorTablePanel().getLayer()).getRender();
136
137
                applyColorTable(rendering);
138
139
                getColorTablePanel().getLayer().getMapContext().invalidate();
140 12914 bsanchez
141
                // TODO: Mirar pq hay que poner invalidate dos veces para que se cargue bien
142
                // el TOC
143
144
                getColorTablePanel().getLayer().getMapContext().invalidate();
145
146
                getColorTablePanel().getLayer().getMapContext().invalidate();
147 12568 bsanchez
        }
148
149
        /**
150
         * Devuelve el panel de ColorTable
151
         * @return
152
         */
153
        public ColorTablePanel getColorTablePanel() {
154
                return colorTablePanel;
155
        }
156 12344 bsanchez
}