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 @ 2123

History | View | Annotate | Download (3.75 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.app.project.documents.view.toc.AbstractTocContextMenuAction;
24
import org.gvsig.app.project.documents.view.toc.ITocItem;
25
import org.gvsig.fmap.mapcontext.layers.FLayer;
26
import org.gvsig.raster.fmap.layers.FLyrRaster;
27
import org.gvsig.raster.fmap.layers.ILayerState;
28
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
29
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
30
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
31
import org.gvsig.raster.tools.app.basic.tool.histogram.ui.HistogramDialog;
32

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

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

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

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

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

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

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

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

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

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

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

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

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

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