Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / enhanced / EnhancedTocMenuEntry.java @ 2125

History | View | Annotate | Download (4.36 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.enhanced;
23

    
24
import javax.swing.Icon;
25

    
26
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
27
import org.gvsig.app.project.documents.view.toc.ITocItem;
28
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
29
import org.gvsig.fmap.mapcontext.layers.FLayer;
30
import org.gvsig.raster.fmap.layers.FLyrRaster;
31
import org.gvsig.raster.fmap.layers.ILayerState;
32
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
33
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
34
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
35
import org.gvsig.raster.tools.app.basic.raster.process.HistogramProcess;
36
import org.gvsig.raster.tools.app.basic.raster.process.IProcessActions;
37
import org.gvsig.raster.tools.app.basic.raster.process.StatisticsProcess;
38
import org.gvsig.raster.tools.app.basic.tool.enhanced.ui.EnhancedDialog;
39

    
40

    
41
/**
42
 * Punto de entrada para la funcionalidad de realce por expansi?n del contraste
43
 * 19/02/2008
44
 * @author Nacho Brodin nachobrodin@gmail.com
45
 */
46
public class EnhancedTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem, IProcessActions {
47
        static private EnhancedTocMenuEntry   singleton   = null;
48
        private FLyrRaster                    lyr         = null;
49

    
50
        /**
51
         * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
52
         * getSingleton()
53
         */
54
        private EnhancedTocMenuEntry() {}
55

    
56
        /**
57
         * Devuelve un objeto unico a dicha clase
58
         * @return
59
         */
60
        static public EnhancedTocMenuEntry getSingleton() {
61
                if (singleton == null)
62
                        singleton = new EnhancedTocMenuEntry();
63
                return singleton;
64
        }
65
        
66
        public String getGroup() {
67
                return "RasterProcess";
68
        }
69

    
70
        public int getGroupOrder() {
71
                return 55;
72
        }
73

    
74
        public int getOrder() {
75
                return 0;
76
        }
77

    
78
        public String getText() {
79
                return RasterToolsUtil.getText(this, "enhanced_rad");
80
        }
81

    
82
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
83
                if ((selectedItems == null) || (selectedItems.length != 1))
84
                        return false;
85

    
86
                if (!(selectedItems[0] instanceof ILayerState))
87
                        return false;
88

    
89
                if (!((ILayerState) selectedItems[0]).isOpen())
90
                        return false;
91

    
92
                return true;
93
        }
94

    
95
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
96
                if ((selectedItems == null) || (selectedItems.length != 1))
97
                        return false;
98

    
99
                if (!(selectedItems[0] instanceof IRasterLayerActions))
100
                        return false;
101
                
102
                return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.ENHANCED);
103
        }
104

    
105
        public void execute(ITocItem item, FLayer[] selectedItems) {
106
                if ((selectedItems == null) || (selectedItems.length != 1) || (!(selectedItems[0] instanceof FLyrRaster)))
107
                        return;
108
                                
109
                this.lyr = (FLyrRaster)selectedItems[0];
110
                
111
                if(!lyr.getDataStore().getStatistics().isCalculated()) 
112
                        StatisticsProcess.launcher(lyr, this);
113
                else
114
                        end(null);
115
        }
116
        
117
        public Icon getIcon() {
118
                return RasterToolsUtil.getIcon("layer-enhanced");
119
        }
120

    
121
        /**
122
         * Lanzamos la ventana al final del proceso de calculo de estad?sticas.
123
         */
124
        public synchronized void end(Object param) {
125
                if(param == null || param instanceof FLyrRaster) {
126
                        HistogramProcess histogramProcess = new HistogramProcess();
127
                        histogramProcess.setActions(this);
128
                        histogramProcess.addParam("histogramable", this.lyr.getDataStore().getHistogramComputer());
129
                        histogramProcess.start();
130
                } 
131
                if(param instanceof BufferHistogram) {
132
                        EnhancedDialog enhancedDialog = new EnhancedDialog(lyr, 760, 421);
133
                        RasterToolsUtil.addWindow(enhancedDialog);
134
                }
135
        }
136

    
137
        public void interrupted() {
138
        }
139
        
140
}