Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / branches / org.gvsig.raster.tools_dataaccess_refactoring / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / filter / grayscale / GrayScaleManager.java @ 2308

History | View | Annotate | Download (4.31 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.tools.app.basic.tool.filter.grayscale;
23

    
24
import java.util.ArrayList;
25
import java.util.List;
26

    
27
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
28
import org.gvsig.fmap.dal.coverage.datastruct.Params;
29
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
30
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
31
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
32
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager;
33
import org.gvsig.raster.tools.app.basic.tool.filter.regionalpha.RegionAlphaByteFilter;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.extensionpoint.ExtensionPoint;
36
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
37
/**
38
 * Gestor del filtro de conversi?n a escala de grises
39
 *
40
 * @author Nacho Brodin nachobrodin@gmail.com
41
 */
42
public class GrayScaleManager implements RasterFilterListManager {
43

    
44
        protected RasterFilterList        filterList = null;
45

    
46
        public static void register() {
47
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
48
                ExtensionPoint point = extensionPoints.get("RasterFilter");
49
                point.append("GrayScale", "", GrayScaleManager.class);
50
        }
51
        
52
        public boolean isDataTypeSupported(int dataType) {
53
                if(dataType != Buffer.TYPE_BYTE)
54
                        return false;
55
                return true;
56
        }
57
        
58
        public Class<?> getFilterClassByID(String id) {
59
                if( id.compareTo("grayscale") == 0)
60
                        return GrayScaleFilter.class;
61
                return null;
62
        }
63

    
64
        /**
65
         * Constructor.
66
         * Asigna la lista de filtros y el managener global.
67
         *
68
         * @param filterListManager
69
         */
70
        public GrayScaleManager(RasterFilterList filterList) {
71
                this.filterList = filterList;
72
        }
73

    
74
        /**
75
         * A?ade un filtro de conversi?n de balance de color RGB.
76
         * @param type. par?metro para el filtro que indica que banda o combinaci?n de
77
         * estas es usada para la conversi?n a escala de gris. El valor de este par?mtro
78
         * est? definido en las constantes de la clase GrayScaleFilter
79
         * @throws FilterTypeException
80
         */
81
        public void addGrayScaleFilter(int type) throws FilterTypeException {
82
                RasterFilter filter = new GrayScaleByteFilter();
83

    
84
                if (filter != null) {
85
                        filter.addParam("typeBand", new Integer(type));
86
                        filterList.add(filter);
87
                }
88
        }
89

    
90
        @SuppressWarnings("unchecked")
91
        public ArrayList getRasterFilterList() {
92
                ArrayList filters = new ArrayList();
93
                filters.add(GrayScaleFilter.class);
94
                return filters;
95
        }
96

    
97
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
98
                if (classFilter.equals(GrayScaleFilter.class)) {
99
                        int type = 0;
100

    
101
                        for (int i = 0; i < params.getNumParams(); i++) {
102
                                if (params.getParam(i).getId().equals("typeBand"))
103
                                        type = ((Integer) params.getParam(i).getDefaultValue()).intValue();
104
                        }
105
                        addGrayScaleFilter(type);
106
                }
107
        }
108
        
109
        public RasterFilter createFilter(Params params) {
110
                Integer type = ((Integer) params.getParamById("typeBand").getDefaultValue());
111
                
112
                RasterFilter filter = new RegionAlphaByteFilter();
113
                filter.addParam("typeBand", type);
114
                return filter;
115
        }
116
        
117
        public void addFilter(Params params) throws FilterTypeException {
118
                addFilter(GrayScaleFilter.class, params);
119
        }
120
        
121
        public RasterFilterList getFilterList() {
122
                return filterList;
123
        }
124
        
125
        public void setFilterList(RasterFilterList filterList) {
126
                this.filterList = filterList;
127
        }
128

    
129
        public int createFilterListFromStrings(List<String> filters, String fil, int filteri) {
130
                return filteri;
131
        }
132

    
133
        public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) {
134
                return filterList;
135
        }
136
}