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 @ 1712
History | View | Annotate | Download (8.15 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 |
mainPanel.add(env.getControlBar(), gbc); |
136 |
|
137 |
gbc.gridy = 2;
|
138 |
JPanel p = fixPanelWithReference(env.getTable(), env.getViewZoomBaseCartography(), env.getViewZoomRasterToGeoref());
|
139 |
mainPanel.add(p, gbc); |
140 |
|
141 |
MDIFrame mdi = (MDIFrame)PluginServices.getMainFrame(); |
142 |
GeorefViewWindow window = new GeorefViewWindow(
|
143 |
mainPanel, |
144 |
0, 0, mdi.getWidth() - 50, mdi.getHeight() - 170); |
145 |
|
146 |
try {
|
147 |
PluginServices.getMDIManager().addWindow(window); |
148 |
}catch (Exception e) { |
149 |
//For testing purposes
|
150 |
} |
151 |
|
152 |
windowList.clear(); |
153 |
windowList.add(window); |
154 |
return mainPanel;
|
155 |
} |
156 |
|
157 |
public JPanel createLayoutWithoutReferenceMap(LayoutEnvironment env) { |
158 |
JPanel mainPanel = new JPanel(); |
159 |
mainPanel.setLayout(new GridBagLayout()); |
160 |
|
161 |
GridBagConstraints gbc = new GridBagConstraints(); |
162 |
gbc.fill = GridBagConstraints.BOTH;
|
163 |
gbc.weightx = 1;
|
164 |
gbc.weighty = 1;
|
165 |
|
166 |
gbc.gridx = 0;
|
167 |
gbc.gridy = 0;
|
168 |
mainPanel.add(env.getViewRasterToGeoref(), gbc); |
169 |
|
170 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
171 |
gbc.weighty = 0;
|
172 |
gbc.gridx = 0;
|
173 |
gbc.gridy = 1;
|
174 |
mainPanel.add(env.getControlBar(), gbc); |
175 |
|
176 |
gbc.gridy = 2;
|
177 |
JPanel p = fixPanelWithoutReference(env.getTable(), env.getViewZoomRasterToGeoref());
|
178 |
mainPanel.add(p, gbc); |
179 |
|
180 |
MDIFrame mdi = (MDIFrame)PluginServices.getMainFrame(); |
181 |
GeorefViewWindow window = new GeorefViewWindow(
|
182 |
mainPanel, |
183 |
0, 0, mdi.getWidth() - 50, mdi.getHeight() - 170); |
184 |
|
185 |
try {
|
186 |
PluginServices.getMDIManager().addWindow(window); |
187 |
}catch (Exception e) { |
188 |
//For testing purposes
|
189 |
} |
190 |
|
191 |
windowList.clear(); |
192 |
windowList.add(window); |
193 |
return mainPanel;
|
194 |
} |
195 |
|
196 |
private JPanel fixPanelWithoutReference(JPanel table, JPanel zoom) { |
197 |
JPanel fixPanel = new JPanel(); |
198 |
fixPanel.setPreferredSize(new Dimension(0, smallWindowsHeight)); |
199 |
fixPanel.setLayout(new GridBagLayout()); |
200 |
GridBagConstraints gbc = new GridBagConstraints(); |
201 |
gbc.gridx = 0;
|
202 |
gbc.fill = GridBagConstraints.BOTH;
|
203 |
gbc.weightx = 1;
|
204 |
gbc.weighty = 1;
|
205 |
fixPanel.add(table, gbc); |
206 |
gbc.gridx = 1;
|
207 |
gbc.fill = GridBagConstraints.NONE;
|
208 |
gbc.weightx = 0;
|
209 |
gbc.weighty = 0;
|
210 |
|
211 |
JPanel zoomFixPanel = new JPanel(); |
212 |
zoomFixPanel.setPreferredSize(new Dimension(smallWindowsWidth, smallWindowsHeight)); |
213 |
zoomFixPanel.setLayout(new BorderLayout()); |
214 |
zoomFixPanel.add(zoom, BorderLayout.CENTER);
|
215 |
|
216 |
fixPanel.add(zoomFixPanel, gbc); |
217 |
return fixPanel;
|
218 |
} |
219 |
|
220 |
private JPanel fixPanelWithReference(JPanel table, JPanel zoom1, JPanel zoom2) { |
221 |
JPanel fixPanel = new JPanel(); |
222 |
fixPanel.setPreferredSize(new Dimension(0, smallWindowsHeight)); |
223 |
fixPanel.setLayout(new GridBagLayout()); |
224 |
GridBagConstraints gbc = new GridBagConstraints(); |
225 |
gbc.gridx = 1;
|
226 |
gbc.fill = GridBagConstraints.BOTH;
|
227 |
gbc.weightx = 1;
|
228 |
gbc.weighty = 1;
|
229 |
fixPanel.add(table, gbc); |
230 |
|
231 |
gbc.gridx = 0;
|
232 |
gbc.fill = GridBagConstraints.NONE;
|
233 |
gbc.weightx = 0;
|
234 |
gbc.weighty = 0;
|
235 |
|
236 |
JPanel zoomFixPanel1 = new JPanel(); |
237 |
zoomFixPanel1.setPreferredSize(new Dimension(smallWindowsWidth, smallWindowsHeight)); |
238 |
zoomFixPanel1.setLayout(new BorderLayout()); |
239 |
zoomFixPanel1.add(zoom1, BorderLayout.CENTER);
|
240 |
|
241 |
fixPanel.add(zoomFixPanel1, gbc); |
242 |
|
243 |
JPanel zoomFixPanel2 = new JPanel(); |
244 |
zoomFixPanel2.setPreferredSize(new Dimension(smallWindowsWidth, smallWindowsHeight)); |
245 |
zoomFixPanel2.setLayout(new BorderLayout()); |
246 |
zoomFixPanel2.add(zoom2, BorderLayout.CENTER);
|
247 |
|
248 |
gbc.gridx = 2;
|
249 |
fixPanel.add(zoomFixPanel2, gbc); |
250 |
return fixPanel;
|
251 |
} |
252 |
|
253 |
public LayoutEnvironment createLayoutEnvironment() {
|
254 |
return new LayoutEnvironmentImpl(); |
255 |
} |
256 |
|
257 |
/**
|
258 |
* Cierra todas las ventanas de georreferenciaci?n
|
259 |
*/
|
260 |
public void closeAllWindows() { |
261 |
for (int i = 0; i < windowList.size(); i++) { |
262 |
PluginServices.getMDIManager().closeWindow(windowList.get(i)); |
263 |
} |
264 |
} |
265 |
} |