Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.app / org.gvsig.raster.app.mainplugin / src / main / java / org / gvsig / raster / app / mainplugin / StatisticsPageFactory.java @ 6786

History | View | Annotate | Download (3.48 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.raster.app.mainplugin;
24

    
25
import javax.swing.event.AncestorEvent;
26
import javax.swing.event.AncestorListener;
27

    
28
import org.gvsig.app.project.documents.view.ViewDocument;
29
import org.gvsig.fmap.mapcontext.layers.FLayer;
30
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
31
import org.gvsig.fmap.mapcontext.layers.LayerListener;
32
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer;
33
import org.gvsig.propertypage.PropertiesPage;
34
import org.gvsig.propertypage.PropertiesPageFactory;
35
import org.gvsig.raster.lib.buffer.api.statistics.Statistics;
36

    
37

    
38
/**
39
 * @author fdiaz
40
 *
41
 */
42
public class StatisticsPageFactory implements PropertiesPageFactory {
43

    
44
    @Override
45
    public String getGroupID() {
46
        return ViewDocument.LAYER_PROPERTIES_PAGE_GROUP;
47
    }
48

    
49
    @Override
50
    public boolean isVisible(Object obj) {
51
        return obj instanceof RasterLayer;
52
    }
53

    
54
    @Override
55
    public PropertiesPage create(Object obj) {
56
        if(obj instanceof RasterLayer){
57
            final RasterLayer layer = (RasterLayer)obj;
58
            final StatisticsPage page = (StatisticsPage) new StatisticsPage(layer.getStatistics(null));
59
            final LayerListener layerListener = new LayerListener() {
60
                @Override
61
                public void visibilityChanged(LayerEvent arg0) {
62
                    //Do nothing
63
                }
64
                @Override
65
                public void nameChanged(LayerEvent arg0) {
66
                    //Do nothing
67
                }
68
                @Override
69
                public void editionChanged(LayerEvent arg0) {
70
                    //Do nothing
71
                }
72
                @Override
73
                public void drawValueChanged(LayerEvent arg0) {
74
                    page.setStatistics(layer.getStatistics(null));
75
                }
76
                @Override
77
                public void activationChanged(LayerEvent arg0) {
78
                    //Do nothing
79
                }
80
            };
81
            layer.addLayerListener(layerListener);
82
            page.addAncestorListener(new AncestorListener() {
83

    
84
                @Override
85
                public void ancestorRemoved(AncestorEvent event) {
86
                    layer.removeLayerListener(layerListener);
87
                }
88

    
89
                @Override
90
                public void ancestorMoved(AncestorEvent event) {
91
                    //Do nothing
92
                }
93

    
94
                @Override
95
                public void ancestorAdded(AncestorEvent event) {
96
                    //Do nothing
97
                }
98
            });
99
            return page;
100
        }
101
        return null;
102
    }
103

    
104
}