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 / histogram / HistogramTocMenuEntry.java @ 2340

History | View | Annotate | Download (3.83 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.raster.tools.app.basic.tool.histogram;
20

    
21
import javax.swing.Icon;
22

    
23
import org.gvsig.andami.PluginServices;
24
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
25
import org.gvsig.app.project.documents.view.toc.ITocItem;
26
import org.gvsig.fmap.mapcontext.layers.FLayer;
27
import org.gvsig.i18n.Messages;
28
import org.gvsig.raster.fmap.layers.FLyrRaster;
29
import org.gvsig.raster.fmap.layers.ILayerState;
30
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
31
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
32
import org.gvsig.raster.swing.RasterSwingLibrary;
33
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
34
import org.gvsig.raster.tools.app.basic.tool.histogram.ui.HistogramDialog;
35

    
36
/**
37
 * Punto de entrada del menu del histograma.
38
 *
39
 * @version 17/04/2007
40
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
41
 */
42
public class HistogramTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem {
43
        static private HistogramTocMenuEntry singleton  = null;
44

    
45
        /**
46
         * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
47
         * getSingleton()
48
         */
49
        private HistogramTocMenuEntry() {}
50

    
51
        /**
52
         * Devuelve un objeto unico a dicha clase
53
         * @return
54
         */
55
        static public HistogramTocMenuEntry getSingleton() {
56
                if (singleton == null)
57
                        singleton = new HistogramTocMenuEntry();
58
                return singleton;
59
        }
60
        
61
        public String getGroup() {
62
                return "RasterLayer";
63
        }
64

    
65
        public int getGroupOrder() {
66
                return 10;
67
        }
68

    
69
        public int getOrder() {
70
                return 30;
71
        }
72

    
73
        public String getText() {
74
                return RasterToolsUtil.getText(this, "histograma");
75
        }
76

    
77
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
78
                if ((selectedItems == null) || (selectedItems.length != 1))
79
                        return false;
80

    
81
                if (selectedItems[0] instanceof ILayerState) {
82
                        if (!((ILayerState) selectedItems[0]).isOpen()) 
83
                                return false;
84
                        return true;
85
                }
86
                return false;
87
        }
88

    
89
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
90
                if ((selectedItems == null) || (selectedItems.length != 1))
91
                        return false;
92

    
93
                if (!(selectedItems[0] instanceof FLyrRaster))
94
                        return false;
95
                
96
                return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.HISTOGRAM);
97
        }
98

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

    
103
                if (!(selectedItems[0] instanceof FLyrRaster))
104
                        return;
105

    
106
                FLyrRaster fLayer = (FLyrRaster) selectedItems[0];
107

    
108
                try {
109
                        HistogramDialog histogramDialog = null;
110
                        histogramDialog = new HistogramDialog(650, 500);
111
                        histogramDialog.setLayer(fLayer);
112
                        histogramDialog.getHistogramPanel().firstRun(); // Mostar por primera vez el histograma
113
                        histogramDialog.setVisible(true);
114
                        PluginServices.getMDIManager().addCentredWindow(histogramDialog);
115
                } catch (Exception e) {
116
                        RasterSwingLibrary.messageBoxError(Messages.getText("histogram_error"), this, e);
117
                        return;
118
                }
119
        }
120
        
121
        public Icon getIcon() {
122
                return RasterToolsUtil.getIcon("layer-histogram");
123
        }
124
        
125
}