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 / overview / OverviewsTocMenuEntry.java @ 2340

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

    
24
import java.beans.PropertyChangeEvent;
25
import java.beans.PropertyChangeListener;
26

    
27
import javax.swing.Icon;
28

    
29
import org.gvsig.andami.IconThemeHelper;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
32
import org.gvsig.app.project.documents.view.toc.ITocItem;
33
import org.gvsig.fmap.dal.coverage.RasterLocator;
34
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
35
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
36
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
39
import org.gvsig.raster.fmap.layers.FLyrRaster;
40
import org.gvsig.raster.fmap.layers.ILayerState;
41
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
42
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
43
import org.gvsig.raster.swing.RasterSwingLibrary;
44
import org.gvsig.raster.tools.app.basic.raster.process.IProcessActions;
45
import org.gvsig.raster.tools.app.basic.raster.process.OverviewsProcess;
46
import org.gvsig.raster.tools.app.basic.raster.process.RasterProcess;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

    
50
/**
51
 * Herramienta del men? contextual para la generaci?n de overviews.
52
 * 
53
 * 10-dic-2007
54
 * @author Nacho Brodin (nachobrodin@gmail.com)
55
 */
56
public class OverviewsTocMenuEntry extends AbstractTocContextMenuAction implements PropertyChangeListener, IGenericToolBarMenuItem, IProcessActions {
57
        private Logger                       log              = LoggerFactory.getLogger(OverviewsTocMenuEntry.class);
58
        static private OverviewsTocMenuEntry singleton        = null;
59

    
60
        /**
61
         * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
62
         * getSingleton()
63
         */
64
        private OverviewsTocMenuEntry() {}
65

    
66
        /**
67
         * Devuelve un objeto unico a dicha clase
68
         * @return
69
         */
70
        static public OverviewsTocMenuEntry getSingleton() {
71
                if (singleton == null)
72
                        singleton = new OverviewsTocMenuEntry();
73
                return singleton;
74
        }
75

    
76
        public String getGroup() {
77
                return "RasterLayer";
78
        }
79

    
80
        public int getGroupOrder() {
81
                return 10;
82
        }
83

    
84
        public int getOrder() {
85
                return 70;
86
        }
87

    
88
        public String getText() {
89
                return PluginServices.getText(this, "generar_overviews");
90
        }
91
        
92
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
93
                if(!RasterLocator.getManager().isOverviewBuilderSupported())
94
                        return false;
95
                
96
                if ((selectedItems == null) || (selectedItems.length != 1))
97
                        return false;
98

    
99
                if (!(selectedItems[0] instanceof FLyrRaster))
100
                        return false;
101

    
102
                if (!((ILayerState) selectedItems[0]).isOpen())
103
                        return false;
104

    
105
                if (!((FLyrRaster) selectedItems[0]).getDataStore().overviewsSupport())
106
                        return false;
107
                
108
                if (!((FLyrRaster) selectedItems[0]).getDataStore().overviewsSupport())
109
                        return false;
110

    
111
                return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.CREATEOVERVIEWS);                                                        
112
        }
113

    
114
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
115
                if(!RasterLocator.getManager().isOverviewBuilderSupported())
116
                        return false;
117
                
118
                if ((selectedItems == null) || (selectedItems.length != 1))
119
                        return false;
120

    
121
                if (!(selectedItems[0] instanceof FLyrRaster))
122
                        return false;
123

    
124
                return true;
125
        }
126

    
127
        public void execute(ITocItem item, FLayer[] selectedItems) {                
128
                FLayer lyr = selectedItems[0];
129
                if (lyr instanceof FLyrRaster) {
130
                        if (RasterSwingLibrary.messageBoxYesOrNot("sobreescribir_datos_overview", this)) {
131

    
132
                                try {
133
                                        if (((FLyrRaster) lyr).getDataStore().getOverviewCount(0) > 0) {
134
                                                if (!RasterSwingLibrary.messageBoxYesOrNot("sobreescribir_overviews", this))
135
                                                        return;
136
                                        }
137
                                } catch (BandAccessException e) {
138
                                        // Actuamos como si no tubiera overviews pero salvamos un Log
139
                                        log.debug("Error accediendo a la banda en getOverViewCount", this, e);
140

    
141
                                } catch (RasterDriverException e) {
142
                                        // Actuamos como si no tubiera overviews pero salvamos un Log
143
                                        log.debug("Error en getOverViewCount", this, e);
144
                                }
145

    
146
                                RasterProcess process = new OverviewsProcess();
147
                                process.addParam("layer", (FLyrRaster) lyr);
148
                                process.setCancelable(false);
149
                                process.setActions(this);
150
                                process.start();
151
                        }
152
                }
153
        }
154

    
155
        public Icon getIcon() {
156
                return IconThemeHelper.getImageIcon("layer-modify-overviews");
157
        }
158

    
159
        public void end(Object param) {
160
                try {
161
                        ((FLyrDefault) param).reload();
162
                } catch (ReloadLayerException e) {
163
                }
164
        }
165

    
166
        public void propertyChange(PropertyChangeEvent evt) {}
167
        public void interrupted() {}
168
        
169
        public boolean isEnableEvents() {
170
                return true;
171
        }
172
}