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 / enhanced / ui / EnhancedDialog.java @ 2480

History | View | Annotate | Download (6.84 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.enhanced.ui;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.Component;
26
import java.awt.Dimension;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.util.ArrayList;
30

    
31
import javax.swing.JPanel;
32

    
33
import org.cresques.cts.IProjection;
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.andami.ui.mdiManager.WindowInfo;
37
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
38
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
39
import org.gvsig.raster.fmap.layers.FLyrRaster;
40
import org.gvsig.raster.mainplugin.beans.createlayer.CreateLayerPanel;
41
import org.gvsig.raster.swing.RasterSwingLocator;
42
import org.gvsig.raster.swing.preview.PreviewBasePanelTab;
43
import org.gvsig.raster.swing.preview.PreviewPanel;
44
import org.gvsig.raster.tools.app.basic.raster.bean.previewbase.RasterDataSourcePreview;
45

    
46
/**
47
 * Dialogo para el realce por expansi?n del contraste
48
 * 
49
 * @author Nacho Brodin nachobrodin@gmail.com
50
 */
51
public class EnhancedDialog extends JPanel implements IWindow {
52
        private static final long   serialVersionUID = -5374834293534046986L;
53
        
54
        private PreviewPanel        previewBasePanel = null;
55
        private GraphicsPanel       graphicsPanel    = null;
56
        private FLyrRaster          lyr              = null;
57
        private PreviewFiltering    filteredPreview  = null;
58
        private SelectorsPanel      controlsPanel    = null;
59
        private CreateLayerPanel    layerPanel       = null;
60
        private String              viewName         = null;
61
        private EnhancedListener    listener         = null;
62
        
63
        /**
64
         * Constructor
65
         * @param lyr Capa raster sobre la que se opera
66
         * @param lyrs Lista de capas cargadas en el TOC
67
         * @param width Ancho
68
         * @param height Alto
69
         */
70
        public EnhancedDialog(FLyrRaster lyr, int width, int height) {
71
                this.setPreferredSize(new Dimension(width, height));
72
                this.setSize(width, height);
73
                this.setLayout(new BorderLayout(5, 5));
74
                this.lyr = lyr;
75
                
76
                graphicsPanel = new GraphicsPanel(this.lyr);
77
                filteredPreview = new PreviewFiltering(false);
78
                filteredPreview.setFilterStatus(this.lyr.getRender().getFilterList().getStatusCloned());
79
                controlsPanel = new SelectorsPanel(this.lyr, graphicsPanel.getInputHistogram());
80
                                
81
                this.add((Component)getPreviewBasePanel(), BorderLayout.CENTER);
82
                
83
                listener = new EnhancedListener(controlsPanel, graphicsPanel, this, filteredPreview);
84
                
85
                listener.firstLoad();
86
                
87
                graphicsPanel.setListener(listener);
88
                
89
                graphicsPanel.updateHistogram();
90
                listener.updatePreview();
91
                
92
                IWindow window = PluginServices.getMDIManager().getActiveWindow();
93
                if(window instanceof AbstractViewPanel) {
94
                        AbstractViewPanel view = (AbstractViewPanel)window;
95
                        viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle();
96
                }
97
                
98
                getPreviewBasePanel().getButtonsPanel().addButtonPressedListener(listener);
99
                
100
                previewBasePanel.refreshPreview();
101
        }
102

    
103
        /**
104
         * Obtiene el panel con el histograma
105
         * @return HistogramPanel
106
         */
107
        public PreviewPanel getPreviewBasePanel() {
108
                if (previewBasePanel == null) {
109
                        ArrayList<PreviewBasePanelTab> list = new ArrayList<PreviewBasePanelTab>();
110
                        list.add((PreviewBasePanelTab)graphicsPanel);
111
                        
112
                        JPanel downPreview = new JPanel();
113
                        getNewOrSaveLayerPanel().setLabelFilename("");
114
                        downPreview.setLayout(new GridBagLayout());
115
                        
116
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
117
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
118
                        downPreview.add(getNewOrSaveLayerPanel().getJPanel(), gridBagConstraints);
119
                        
120
                        gridBagConstraints = new GridBagConstraints();
121
                        gridBagConstraints.gridx = 0;
122
                        gridBagConstraints.gridy = 1;
123
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
124
                        gridBagConstraints.anchor = GridBagConstraints.NORTH;
125
                        gridBagConstraints.weightx = 1.0;
126
                        gridBagConstraints.weighty = 1.0;
127
                        downPreview.add(getNewOrSaveLayerPanel().getFileNamePanel(), gridBagConstraints);
128
                        
129
                        IProjection viewProj = null;
130
                        if(lyr.getMapContext() != null)
131
                                viewProj = lyr.getMapContext().getProjection();
132
                        RasterDataSourcePreview dataSourcePreview = new RasterDataSourcePreview(lyr, viewProj);
133
                        previewBasePanel = RasterSwingLocator.getSwingManager().createPreviewPanel(
134
                                        ButtonsPanel.BUTTONS_APPLYCLOSE, 
135
                                        list, 
136
                                        controlsPanel, 
137
                                        downPreview, 
138
                                        filteredPreview, 
139
                                        dataSourcePreview);
140
                        previewBasePanel.getButtonsPanel().addCancel();
141
                }
142
                return previewBasePanel;
143
        }
144
        
145
        /**
146
         * Devuelve un Panel para el guardado de capas en disco o en memoria.
147
         */
148
        public CreateLayerPanel getNewOrSaveLayerPanel() {
149
                 if (layerPanel == null) {
150
                         layerPanel = new CreateLayerPanel(lyr);
151
                         if(lyr.isRemote())
152
                                 layerPanel.disableNewLayer();
153
                 }
154
                 return layerPanel;
155
         }
156
        
157
        /**
158
         * Acciones a ejecutar cuando se cancela
159
         */
160
        public void close() {
161
                try {
162
                        PluginServices.getMDIManager().closeWindow(this);
163
                } catch (ArrayIndexOutOfBoundsException e) {
164
                        //Si la ventana no se puede eliminar no hacemos nada
165
                }
166
        }
167
        
168
        /**
169
         * Obtiene la capa asociada.
170
         * @return FLyrRaster
171
         */
172
        public FLyrRaster getLayer() {
173
                return lyr;
174
        }
175

    
176
        public WindowInfo getWindowInfo() {
177
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
178
                if(getPreviewBasePanel().getDataSourcePreview().getSource() != null) {
179
                        FLyrRaster lyr = (FLyrRaster)getPreviewBasePanel().getDataSourcePreview().getSource();
180
                        m_viewinfo.setAdditionalInfo(lyr.getName());
181
                }
182
                m_viewinfo.setTitle(PluginServices.getText(this, "enhanced"));
183
                m_viewinfo.setHeight(this.getHeight());
184
                m_viewinfo.setWidth(this.getWidth());
185
                return m_viewinfo;
186
        }
187

    
188
        /**
189
         * @return the filteredPreview
190
         */
191
        public PreviewFiltering getFilteredPreview() {
192
                return filteredPreview;
193
        }
194

    
195
        /**
196
         * @return the viewName
197
         */
198
        public String getViewName() {
199
                return viewName;
200
        }
201

    
202
        /**
203
         * @return the graphicsPanel
204
         */
205
        public GraphicsPanel getGraphicsPanel() {
206
                return graphicsPanel;
207
        }
208

    
209
        public Object getWindowProfile() {
210
                return WindowInfo.PROPERTIES_PROFILE;
211
        }
212
}