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

History | View | Annotate | Download (3.76 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.raster.fmap.layers.FLyrRaster;
28
import org.gvsig.raster.fmap.layers.ILayerState;
29
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
30
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
31
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
32
import org.gvsig.raster.tools.app.basic.tool.histogram.ui.HistogramDialog;
33

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

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

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

    
63
        public int getGroupOrder() {
64
                return 10;
65
        }
66

    
67
        public int getOrder() {
68
                return 30;
69
        }
70

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

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

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

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

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

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

    
101
                if (!(selectedItems[0] instanceof FLyrRaster))
102
                        return;
103

    
104
                FLyrRaster fLayer = (FLyrRaster) selectedItems[0];
105

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