Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / ColorTableListener.java @ 13328

History | View | Annotate | Download (4.99 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.colortable;
20

    
21
import java.awt.Dimension;
22
import java.awt.Graphics2D;
23
import java.awt.geom.AffineTransform;
24
import java.awt.geom.Dimension2D;
25

    
26
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
27
import org.gvsig.gui.beans.imagenavigator.IClientImageNavigator;
28
import org.gvsig.raster.datastruct.Extent;
29
import org.gvsig.raster.datastruct.ViewPortData;
30
import org.gvsig.raster.grid.GridPalette;
31
import org.gvsig.raster.grid.GridTransparency;
32
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
/**
42
 *
43
 * @version 27/06/2007
44
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
45
 */
46
public class ColorTableListener implements IClientImageNavigator {
47
        private ColorTablePanel colorTablePanel = null;
48

    
49
        /**
50
         * Construye un ColorTableListener
51
         * @param colorTablePanel
52
         */
53
        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
        public void drawImage(Graphics2D g, double x1, double y1, double x2, double y2, double zoom, int width, int height) {
62
                if (colorTablePanel.getLayer() == null)
63
                        return;
64

    
65
                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()).getBufferFactory().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
                GridTransparency lastTransparency = rendering.getLastTransparency();
89
                applyColorTable(rendering);
90
                rendering.draw(g, vp2);
91
                rendering.setLastTransparency(lastTransparency);
92

    
93
                g.setTransform(trans);
94

    
95
                rendering.getFilterList().popStatus();
96
        }
97

    
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

    
116
        /**
117
         * Que acciones se ejecutaran al haber presionado el bot?n aceptar o aplicar
118
         */
119
        public void accept() {
120

    
121
                /*
122
                IWindow windows[] = PluginServices.getMDIManager().getAllWindows();
123
                for (int i=0;i<windows.length;i++) {
124
                        if(windows[i] instanceof IView)
125
                                ((IView)windows[i]).getTOC().refresh();
126
                }
127
                */
128

    
129
                Rendering rendering = ((FLyrRasterSE) getColorTablePanel().getLayer()).getRender();
130

    
131
                applyColorTable(rendering);
132

    
133
                getColorTablePanel().getLayer().getMapContext().invalidate();
134

    
135
                // TODO: Mirar pq hay que poner invalidate dos veces para que se cargue bien
136
                // el TOC
137

    
138
                getColorTablePanel().getLayer().getMapContext().invalidate();
139

    
140
                getColorTablePanel().getLayer().getMapContext().invalidate();
141
        }
142

    
143
        /**
144
         * Devuelve el panel de ColorTable
145
         * @return
146
         */
147
        public ColorTablePanel getColorTablePanel() {
148
                return colorTablePanel;
149
        }
150
}