Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / correction / ModeManager.java @ 2328

History | View | Annotate | Download (4.71 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.impl.grid.filter.correction;
23

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

    
27
import org.gvsig.fmap.dal.coverage.datastruct.Params;
28
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
29
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager;
30
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
31
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
32
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
33
import org.gvsig.raster.impl.store.ParamImpl;
34

    
35
/**
36
 * Gestor de la pila de filtros para el filtro de moda.
37
 *
38
 * @author Nacho Brodin nachobrodin@gmail.com
39
 */
40
public class ModeManager extends AbstractRasterFilterManager {
41
        private static String   ID = "Moda";
42
        
43
        /**
44
         * Default constructor. Sets the filter list.
45
         * @param filterList
46
         */
47
        public ModeManager(RasterFilterList filterList) {
48
                super(filterList);
49
        }
50
        
51
        public String getManagerID() {
52
                return ID;
53
        }
54

    
55
        public static void register() {
56
                AbstractRasterFilterManager.register(ID, ModeManager.class);
57
        }
58

    
59
        /**
60
         * Constructor. Asigna la lista de filtros y el manager.
61
         * @param filterListManager
62
         */
63
        public ModeManager(RasterFilterListManagerImpl filterListManager) {
64
                super(filterListManager.getFilterList());
65
        }
66

    
67
        public boolean isDataTypeSupported(int dataType) {
68
                return true;
69
        }
70
        
71
        public Class<?> getFilterClassByID(String id) {
72
                if(id.compareTo("moda") == 0)
73
                        return ModeFilter.class;
74
                return null;
75
        }
76

    
77
        /**
78
         * A?ade un filtro de moda a la pila de filtros.
79
         * @param sideLong
80
         * @throws FilterTypeException
81
         */
82
        public void addModeFilter(int sideLong) throws FilterTypeException {
83
                RasterFilter filter = new ModeByteFilter();
84

    
85
                //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
86

    
87
                if (filter != null) {
88
                        filter.addParam("sideLong", new Integer(sideLong));
89
                        getFilterList().add(filter);
90
                }
91
        }
92

    
93
        public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) {
94
                if (rf instanceof ModeFilter) {
95
                        filterList.add("filter.moda.active=true");
96
                        ModeFilter modaFilter = (ModeFilter) rf;
97
                        filterList.add("filter.moda.sideLong=" + modaFilter.getSideWindow());
98
                }
99

    
100
                return filterList;
101
        }
102

    
103
        public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException {
104
                if ((fil.startsWith("filter.moda.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) {
105

    
106
                        int sideLong = 0;
107
                        filters.remove(0);
108

    
109
                        for (int prop = 0; prop < filters.size(); prop++) {
110
                                String elem = (String) filters.get(prop);
111
                                if (elem.startsWith("filter.moda.sideLong")) {
112
                                        sideLong = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
113
                                        filters.remove(prop);
114
                                        prop--;
115
                                }
116
                        }
117
                        addModeFilter(sideLong);
118
                }
119
                return filteri;
120
        }
121

    
122
        public List<Class<?>> getRasterFilterList() {
123
                List<Class<?>> filters = new ArrayList<Class<?>>();
124
                filters.add(ModeFilter.class);
125
                return filters;
126
        }
127

    
128
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
129
                if (ModeFilter.class.isAssignableFrom(classFilter)) {
130
                        int sideLong = 0;
131
                        for (int i = 0; i < params.getNumParams(); i++) {
132
                                if (((ParamImpl)params.getParam(i)).getId().equals("sideLong") &&
133
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
134
                                        sideLong = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
135
                        }
136
                        addModeFilter(sideLong);
137
                }
138
        }
139
        
140
        public void addFilter(Params params) throws FilterTypeException {
141
                addFilter(ModeFilter.class, params);
142
        }
143
        
144
        public RasterFilter createFilter(Params params) {
145
                if(        params.getParamById("sideLong") != null) {
146
                        int sideLong = ((Integer) params.getParamById("sideLong").getDefaultValue()).intValue();
147
                        RasterFilter filter = new ModeByteFilter();
148
                        filter.addParam("sideLong", new Integer(sideLong));
149
                        return filter;
150
                }
151
                return null;
152
        }
153
        
154
}