Statistics
| Revision:

gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.framework / org.gvsig.raster.georeferencing.framework.andami / src / main / java / org / gvsig / raster / georeferencing / framework / andami / GeoreferencingAndamiFrameworkManagerImpl.java @ 1682

History | View | Annotate | Download (7.9 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2013 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.georeferencing.framework.andami;
23

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

    
32
import javax.swing.JPanel;
33

    
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiFrame.MDIFrame;
36
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkManager;
37
import org.gvsig.raster.georeferencing.framework.LayoutEnvironment;
38

    
39
public class GeoreferencingAndamiFrameworkManagerImpl implements GeoreferencingFrameworkManager {
40
        //private static final Logger           logger                         = LoggerFactory.getLogger(GeoreferencingAndamiFrameworkManagerImpl.class);
41
        private static final int              smallWindowsHeight             = 140;
42
        private static final int              smallWindowsWidth              = 220;
43
        private static final double           smallWindowsWidthPercent       = 0.5;
44
        private List<GeorefViewWindow>        windowList                     = new ArrayList<GeorefViewWindow>();
45
        private HashMap<JPanel, AndamiWindow> windows                        = new HashMap<JPanel, AndamiWindow>();
46
    private int                           preferredWidth                 = 0;
47
    private int                           preferredHeight                = 0;
48
        
49
    public GeoreferencingAndamiFrameworkManagerImpl() {
50
            try {
51
                    MDIFrame p = (MDIFrame)PluginServices.getMainFrame();
52
                    preferredWidth = p.getWidth();
53
                preferredHeight = p.getHeight() - 100;
54
            } catch (Exception e) {
55
                    preferredWidth = 800;//p.getWidth();
56
                preferredHeight = 700;//p.getHeight() - 100;
57
                }
58
    }
59
           
60
        public void showWindow(JPanel panel, int w, int h, String message) {
61
                AndamiWindow window = new AndamiWindow(panel, -1, -1, w, h, message);
62
                windows.put(panel, window);
63
                PluginServices.getMDIManager().addWindow(window);
64
        }
65
        
66
        public void closeWindow(JPanel panel) {
67
                AndamiWindow window = windows.get(panel);
68
                PluginServices.getMDIManager().closeWindow(window);
69
                windows.remove(panel);
70
        }
71
        
72
        public int getPreferredViewHeight() {
73
                return preferredHeight - smallWindowsHeight;
74
        }
75
        
76
        public int getPreferredTableHeight() {
77
                return smallWindowsHeight;
78
        }
79
        
80
        public int getPreferredZoomHeight() {
81
                return smallWindowsHeight;
82
        }
83
        
84
        public int getPreferredViewWidth(boolean withMap) {
85
                if(withMap) {
86
                        return preferredWidth >> 1;
87
                } else {
88
                        return preferredWidth;
89
                }
90
        }
91
        
92
        public int getPreferredZoomWidth(boolean withMap) {
93
                if(withMap) {
94
                        return (int)(preferredWidth * (smallWindowsWidthPercent * 0.5));
95
                } else {
96
                        return (int)(preferredWidth * 0.25);
97
                }
98
        }
99
        
100
        public int getPreferredTableWidth(boolean withMap) {
101
                if(withMap) {
102
                        return (int)(preferredWidth * (1 - smallWindowsWidthPercent));
103
                } else {
104
                        return (int)(preferredWidth * 0.75);
105
                }
106
        }
107
        
108
        public void createLayout(LayoutEnvironment env) {
109
                if(env.getViewBaseCartography() == null || env.getViewZoomBaseCartography() == null)
110
                        createLayoutWithoutReferenceMap(env);
111
                else
112
                        createLayoutWithReferenceMap(env);
113
        }
114
        
115
        public JPanel createLayoutWithReferenceMap(LayoutEnvironment env) {
116
                JPanel mainPanel = new JPanel();
117
                mainPanel.setLayout(new GridBagLayout());
118
                
119
                GridBagConstraints gbc = new GridBagConstraints();
120
                gbc.fill = GridBagConstraints.BOTH;
121
                gbc.weightx = 1;
122
                gbc.weighty = 1;
123
                gbc.gridwidth = 1;
124

    
125
                gbc.gridx = 0;
126
                mainPanel.add(env.getViewBaseCartography(), gbc);
127
                gbc.gridx = 1;
128
                mainPanel.add(env.getViewRasterToGeoref(), gbc);
129
                
130
                gbc.fill = GridBagConstraints.HORIZONTAL;
131
                gbc.weighty = 0;
132
                gbc.gridx = 0;
133
                gbc.gridy = 1;
134
                gbc.gridwidth = 2;
135
                JPanel p = fixPanelWithReference(env.getTable(), env.getViewZoomRasterToGeoref(), env.getViewZoomBaseCartography());
136
                mainPanel.add(p, gbc);
137
                
138
                GeorefViewWindow window = new GeorefViewWindow(
139
                                mainPanel,
140
                                0, 0, preferredWidth, preferredHeight);
141
                
142
                try {
143
                        PluginServices.getMDIManager().addWindow(window);
144
                }catch (Exception e) {
145
                        //For testing purposes
146
                }
147
                
148
                windowList.clear();
149
                windowList.add(window);
150
                return mainPanel;
151
        }
152
        
153
        public JPanel createLayoutWithoutReferenceMap(LayoutEnvironment env) {
154
                JPanel mainPanel = new JPanel();
155
                mainPanel.setLayout(new GridBagLayout());
156
                
157
                GridBagConstraints gbc = new GridBagConstraints();
158
                gbc.fill = GridBagConstraints.BOTH;
159
                gbc.weightx = 1;
160
                gbc.weighty = 1;
161

    
162
                gbc.gridx = 0;
163
                gbc.gridy = 0;
164
                mainPanel.add(env.getViewRasterToGeoref(), gbc);
165
                
166
                gbc.fill = GridBagConstraints.HORIZONTAL;
167
                gbc.weighty = 0;
168
                gbc.gridx = 0;
169
                gbc.gridy = 1;
170
                JPanel p = fixPanelWithoutReference(env.getTable(), env.getViewZoomRasterToGeoref());
171
                mainPanel.add(p, gbc);
172
                
173
                GeorefViewWindow window = new GeorefViewWindow(
174
                                mainPanel,
175
                                0, 0, preferredWidth, preferredHeight);
176
                
177
                try {
178
                        PluginServices.getMDIManager().addWindow(window);
179
                }catch (Exception e) {
180
                        //For testing purposes
181
                }
182
                
183
                windowList.clear();
184
                windowList.add(window);
185
                return mainPanel;
186
        }
187
        
188
        private JPanel fixPanelWithoutReference(JPanel table, JPanel zoom) {
189
                JPanel fixPanel = new JPanel();
190
                fixPanel.setPreferredSize(new Dimension(0, smallWindowsHeight));
191
                fixPanel.setLayout(new GridBagLayout());
192
                GridBagConstraints gbc = new GridBagConstraints();
193
                gbc.gridx = 0;
194
                gbc.fill = GridBagConstraints.BOTH;
195
                gbc.weightx = 1;
196
                gbc.weighty = 1;
197
                fixPanel.add(table, gbc);
198
                gbc.gridx = 1;
199
                gbc.fill = GridBagConstraints.NONE;
200
                gbc.weightx = 0;
201
                gbc.weighty = 0;
202
                
203
                JPanel zoomFixPanel = new JPanel();
204
                zoomFixPanel.setPreferredSize(new Dimension(smallWindowsWidth, smallWindowsHeight));
205
                zoomFixPanel.setLayout(new BorderLayout());
206
                zoomFixPanel.add(zoom, BorderLayout.CENTER);
207
                
208
                fixPanel.add(zoomFixPanel, gbc);
209
                return fixPanel;
210
        }
211
        
212
        private JPanel fixPanelWithReference(JPanel table, JPanel zoom1, JPanel zoom2) {
213
                JPanel fixPanel = new JPanel();
214
                fixPanel.setPreferredSize(new Dimension(0, smallWindowsHeight));
215
                fixPanel.setLayout(new GridBagLayout());
216
                GridBagConstraints gbc = new GridBagConstraints();
217
                gbc.gridx = 1;
218
                gbc.fill = GridBagConstraints.BOTH;
219
                gbc.weightx = 1;
220
                gbc.weighty = 1;
221
                fixPanel.add(table, gbc);
222
                
223
                gbc.gridx = 0;
224
                gbc.fill = GridBagConstraints.NONE;
225
                gbc.weightx = 0;
226
                gbc.weighty = 0;
227
                
228
                JPanel zoomFixPanel1 = new JPanel();
229
                zoomFixPanel1.setPreferredSize(new Dimension(smallWindowsWidth, smallWindowsHeight));
230
                zoomFixPanel1.setLayout(new BorderLayout());
231
                zoomFixPanel1.add(zoom1, BorderLayout.CENTER);
232
                
233
                fixPanel.add(zoomFixPanel1, gbc);
234
                
235
                JPanel zoomFixPanel2 = new JPanel();
236
                zoomFixPanel2.setPreferredSize(new Dimension(smallWindowsWidth, smallWindowsHeight));
237
                zoomFixPanel2.setLayout(new BorderLayout());
238
                zoomFixPanel2.add(zoom2, BorderLayout.CENTER);
239
                
240
                gbc.gridx = 2;
241
                fixPanel.add(zoomFixPanel2, gbc);
242
                return fixPanel;
243
        }
244

    
245
        public LayoutEnvironment createLayoutEnvironment() {
246
                return new LayoutEnvironmentImpl();
247
        }
248
        
249
        /**
250
         * Cierra todas las ventanas de georreferenciaci?n
251
         */
252
        public void closeAllWindows() {
253
                for (int i = 0; i < windowList.size(); i++) {
254
                        PluginServices.getMDIManager().closeWindow(windowList.get(i));
255
                }
256
        }
257
}