Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / enhanced / EnhancedTocMenuEntry.java @ 19307

History | View | Annotate | Download (5.75 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.enhanced;
20

    
21
import java.util.ArrayList;
22

    
23
import javax.swing.Icon;
24

    
25
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
26
import org.gvsig.fmap.raster.layers.ILayerState;
27
import org.gvsig.fmap.raster.layers.IRasterLayerActions;
28
import org.gvsig.raster.IProcessActions;
29
import org.gvsig.raster.RasterProcess;
30
import org.gvsig.raster.gui.IGenericToolBarMenuItem;
31
import org.gvsig.rastertools.enhanced.ui.EnhancedDialog;
32
import org.gvsig.rastertools.statistics.StatisticsProcess;
33

    
34
import com.iver.andami.PluginServices;
35
import com.iver.andami.ui.mdiManager.IWindow;
36
import com.iver.cit.gvsig.fmap.layers.FLayer;
37
import com.iver.cit.gvsig.fmap.layers.FLayers;
38
import com.iver.cit.gvsig.project.documents.view.gui.View;
39
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
40
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
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 FLyrRasterSE                  lyr         = null;
50
        private ArrayList                     lyrsRaster  = null;
51

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

    
58
        /**
59
         * Devuelve un objeto unico a dicha clase
60
         * @return
61
         */
62
        static public EnhancedTocMenuEntry getSingleton() {
63
                if (singleton == null)
64
                        singleton = new EnhancedTocMenuEntry();
65
                return singleton;
66
        }
67
        
68
        /*
69
         * (non-Javadoc)
70
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
71
         */
72
        public String getGroup() {
73
                return "RasterProcess";
74
        }
75

    
76
        /*
77
         * (non-Javadoc)
78
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
79
         */
80
        public int getGroupOrder() {
81
                return 55;
82
        }
83

    
84
        /*
85
         * (non-Javadoc)
86
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
87
         */
88
        public int getOrder() {
89
                return 0;
90
        }
91

    
92
        /*
93
         * (non-Javadoc)
94
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
95
         */
96
        public String getText() {
97
                return PluginServices.getText(this, "enhanced_rad");
98
        }
99

    
100
        /*
101
         * (non-Javadoc)
102
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
103
         */
104
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
105
                if ((selectedItems == null) || (selectedItems.length != 1))
106
                        return false;
107

    
108
                if (!(selectedItems[0] instanceof ILayerState))
109
                        return false;
110

    
111
                if (!((ILayerState) selectedItems[0]).isOpen())
112
                        return false;
113

    
114
                return true;
115
        }
116

    
117
        /*
118
         * (non-Javadoc)
119
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
120
         */
121
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
122
                if ((selectedItems == null) || (selectedItems.length != 1))
123
                        return false;
124

    
125
                if (!(selectedItems[0] instanceof FLyrRasterSE))
126
                        return false;
127
                
128
                return ((FLyrRasterSE) selectedItems[0]).isActionEnabled(IRasterLayerActions.ENHANCED);
129
        }
130

    
131
        /*
132
         * (non-Javadoc)
133
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
134
         */
135
        public void execute(ITocItem item, FLayer[] selectedItems) {
136
                if ((selectedItems == null) || (selectedItems.length != 1) || (!(selectedItems[0] instanceof FLyrRasterSE)))
137
                        return;
138
                
139
                IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
140
                lyrsRaster = new ArrayList();
141
                
142
                if(activeWindow instanceof View) {
143
                        FLayers lyrs = ((View)activeWindow).getMapControl().getMapContext().getLayers();
144
                        for (int i = 0; i < lyrs.getLayersCount(); i++) {
145
                                if(lyrs.getLayer(i) instanceof FLyrRasterSE)
146
                                        lyrsRaster.add(lyrs.getLayer(i));
147
                        }
148
                }
149
                
150
                this.lyr = (FLyrRasterSE)selectedItems[0];
151
                if(!lyr.getDataSource().getStatistics().isCalculated()) {
152
                        RasterProcess process = new StatisticsProcess();
153
                        process.addParam("layer", lyr);
154
                        process.addParam("force", new Boolean(false));
155
                        process.setActions(this);
156
                        process.start();        
157
                } else
158
                        end(null);
159
        }
160
        
161
        /*
162
         * (non-Javadoc)
163
         * @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
164
         */
165
        public Icon getIcon() {
166
                return PluginServices.getIconTheme().get("brush-icon");
167
        }
168

    
169
        /**
170
         * Lanzamos la ventana al final del proceso de calculo de estad?sticas.
171
         */
172
        public void end(Object param) {
173
                EnhancedDialog enhancedDialog = new EnhancedDialog(lyr, lyrsRaster, 750, 420);
174
                PluginServices.getMDIManager().addWindow(enhancedDialog);
175
        }
176

    
177
        public void interrupted() {
178
        }
179
}