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 / enhanced / EnhancedTocMenuEntry.java @ 2425

History | View | Annotate | Download (4.5 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.andami.PluginServices;
27
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
28
import org.gvsig.app.project.documents.view.toc.ITocItem;
29
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31
import org.gvsig.raster.fmap.layers.FLyrRaster;
32
import org.gvsig.raster.fmap.layers.ILayerState;
33
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
34
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
35
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
36
import org.gvsig.raster.tools.app.basic.raster.process.HistogramProcess;
37
import org.gvsig.raster.tools.app.basic.raster.process.IProcessActions;
38
import org.gvsig.raster.tools.app.basic.raster.process.StatisticsProcess;
39
import org.gvsig.raster.tools.app.basic.tool.enhanced.ui.EnhancedDialog;
40

    
41

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

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

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

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

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

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

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

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

    
90
                if (!((ILayerState) selectedItems[0]).isOpen())
91
                        return false;
92
                
93
                if(((FLyrRaster) selectedItems[0]).getRender().existColorTable())
94
                        return false;
95

    
96
                return true;
97
        }
98

    
99
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
100
                if ((selectedItems == null) || (selectedItems.length != 1))
101
                        return false;
102

    
103
                if (!(selectedItems[0] instanceof IRasterLayerActions))
104
                        return false;
105
                
106
                return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.ENHANCED);
107
        }
108

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

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

    
141
        public void interrupted() {
142
        }
143
        
144
}