root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / gui / AbstractViewPanel.java @ 38514
History | View | Annotate | Download (10.2 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2009 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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2004-2009 IVER TI
|
26 |
*
|
27 |
*/
|
28 |
package org.gvsig.app.project.documents.view.gui; |
29 |
|
30 |
import java.awt.Graphics; |
31 |
import java.awt.image.BufferedImage; |
32 |
import java.beans.PropertyChangeEvent; |
33 |
import java.beans.PropertyChangeListener; |
34 |
|
35 |
import javax.swing.JPanel; |
36 |
import javax.swing.JSplitPane; |
37 |
|
38 |
import org.cresques.cts.IProjection; |
39 |
|
40 |
import org.gvsig.andami.PluginServices; |
41 |
import org.gvsig.andami.messages.NotificationManager; |
42 |
import org.gvsig.andami.ui.mdiManager.IWindowTransform; |
43 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
44 |
import org.gvsig.app.project.ProjectManager; |
45 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
46 |
import org.gvsig.app.project.documents.view.MapOverview; |
47 |
import org.gvsig.app.project.documents.view.ViewDocument; |
48 |
import org.gvsig.app.project.documents.view.toc.gui.TOC; |
49 |
import org.gvsig.fmap.mapcontrol.MapControl; |
50 |
import org.gvsig.utils.exceptionHandling.ExceptionListener; |
51 |
|
52 |
/**
|
53 |
*
|
54 |
* @author 2005- Vicente Caballero
|
55 |
* @author 2009- Joaquin del Cerro
|
56 |
*
|
57 |
*/
|
58 |
|
59 |
public abstract class AbstractViewPanel extends JPanel implements IView, |
60 |
IWindowTransform, PropertyChangeListener {
|
61 |
|
62 |
private static final long serialVersionUID = -259620280790490262L; |
63 |
|
64 |
private static final int DEFAULT_HEIGHT = 450; |
65 |
|
66 |
private static final int DEFAULT_WIDTH = 700; |
67 |
|
68 |
protected MapControl m_MapControl;
|
69 |
protected MapOverview m_MapLoc;
|
70 |
|
71 |
// store the properties of the window
|
72 |
protected WindowInfo m_viewInfo = null; |
73 |
protected WindowLayout windowLayout = null; |
74 |
|
75 |
protected TOC m_TOC;
|
76 |
protected ViewDocument modelo;
|
77 |
protected ViewExceptionListener mapControlExceptionListener =
|
78 |
new ViewExceptionListener();
|
79 |
|
80 |
protected boolean isPalette = false; |
81 |
protected MapOverViewPalette movp;
|
82 |
protected ViewSplitPane tempMainSplit = null; |
83 |
protected JSplitPane tempSplitToc = null; |
84 |
|
85 |
public void windowActivated() { |
86 |
// By default do nothing
|
87 |
} |
88 |
|
89 |
public void toPalette() { |
90 |
// By default do nothing
|
91 |
} |
92 |
|
93 |
public void restore() { |
94 |
// By default do nothing
|
95 |
} |
96 |
|
97 |
protected class ViewSplitPane extends JSplitPane { |
98 |
|
99 |
private static final long serialVersionUID = -7506953938664812652L; |
100 |
private int lastDivider = 0; |
101 |
|
102 |
public ViewSplitPane(int horizontal_split) { |
103 |
super(horizontal_split);
|
104 |
} |
105 |
|
106 |
protected void paintChildren(Graphics g) { |
107 |
if (lastDivider != lastDividerLocation) {
|
108 |
System.out.println("paintChildren = " |
109 |
+ this.lastDividerLocation);
|
110 |
lastDivider = lastDividerLocation; |
111 |
} |
112 |
super.paintChildren(g);
|
113 |
} |
114 |
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Creates a new View object. Before using it, it must be initialized
|
119 |
* using the <code>initialize()</code> method.
|
120 |
*
|
121 |
* @see initialize()
|
122 |
*/
|
123 |
public AbstractViewPanel() {
|
124 |
ProjectManager.getInstance().getCurrentProject().addPropertyChangeListener(this);
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* Create the internal componentes and populate the window with them.
|
129 |
* If the layout properties were set using the
|
130 |
* <code>setWindowData(WindowData)</code> method, the window will be
|
131 |
* populated according to this
|
132 |
* properties.
|
133 |
*/
|
134 |
protected void initialize() { |
135 |
// Do nothing
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
140 |
* for this View. It is not intended to retrieve the ViewInfo object in a
|
141 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
142 |
* to retrieve the ViewInfo object at any time after the creation of the
|
143 |
* object.
|
144 |
*
|
145 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
146 |
*/
|
147 |
public WindowInfo getWindowInfo() {
|
148 |
if (m_viewInfo == null) { |
149 |
m_viewInfo = |
150 |
new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
|
151 |
| WindowInfo.MAXIMIZABLE); |
152 |
|
153 |
m_viewInfo.setWidth(DEFAULT_WIDTH); |
154 |
m_viewInfo.setHeight(DEFAULT_HEIGHT); |
155 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + ": " |
156 |
+ modelo.getName()); |
157 |
} |
158 |
return m_viewInfo;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
|
163 |
*/
|
164 |
public void windowClosed() { |
165 |
if (movp != null) { |
166 |
PluginServices.getMDIManager().closeWindow(movp); |
167 |
} |
168 |
if (modelo != null) { |
169 |
modelo.setWindowLayout(this.getWindowLayout());
|
170 |
} |
171 |
} |
172 |
|
173 |
/**
|
174 |
* @deprecated See {@link #getViewDocument()}
|
175 |
*/
|
176 |
public ViewDocument getModel() {
|
177 |
return modelo;
|
178 |
} |
179 |
|
180 |
public ViewDocument getViewDocument() {
|
181 |
return modelo;
|
182 |
} |
183 |
|
184 |
public MapOverview getMapOverview() {
|
185 |
return m_MapLoc;
|
186 |
} |
187 |
|
188 |
public MapControl getMapControl() {
|
189 |
return m_MapControl;
|
190 |
} |
191 |
|
192 |
public TOC getTOC() {
|
193 |
return m_TOC;
|
194 |
} |
195 |
|
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
*
|
199 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
|
200 |
*/
|
201 |
|
202 |
public Object getWindowModel() { |
203 |
return modelo;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
208 |
* for this View. It is not intended to retrieve the ViewInfo object in a
|
209 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
210 |
* to retrieve the ViewInfo object at any time after the creation of the
|
211 |
* object.
|
212 |
*
|
213 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
214 |
*/
|
215 |
|
216 |
public boolean isPalette() { |
217 |
return isPalette;
|
218 |
} |
219 |
|
220 |
public void repaintMap() { |
221 |
m_MapControl.drawMap(false);
|
222 |
} |
223 |
|
224 |
public class ViewExceptionListener implements ExceptionListener { |
225 |
|
226 |
/**
|
227 |
* @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
|
228 |
*/
|
229 |
public void exceptionThrown(Throwable t) { |
230 |
NotificationManager.addError(t.getMessage(), t); |
231 |
} |
232 |
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* @return
|
237 |
*/
|
238 |
public BufferedImage getImage() { |
239 |
return m_MapControl.getImage();
|
240 |
} |
241 |
|
242 |
public void setProjection(IProjection proj) { |
243 |
getMapControl().setProjection(proj); |
244 |
} |
245 |
|
246 |
public IProjection getProjection() {
|
247 |
return getMapControl().getProjection();
|
248 |
} |
249 |
|
250 |
public WindowLayout getWindowLayout() {
|
251 |
if (windowLayout == null) { |
252 |
windowLayout = new WindowLayout();
|
253 |
} |
254 |
windowLayout.set("MainWindow.X", Integer.toString(this.getX())); |
255 |
windowLayout.set("MainWindow.Y", Integer.toString(this.getY())); |
256 |
windowLayout.set("MainWindow.Width", Integer.toString(this.getWidth())); |
257 |
windowLayout.set("MainWindow.Height",
|
258 |
Integer.toString(this.getHeight())); |
259 |
|
260 |
windowLayout.set("MainDivider.Location",
|
261 |
Integer.toString(tempMainSplit.getDividerLocation()));
|
262 |
windowLayout.set("MainDivider.X",
|
263 |
Integer.toString(tempMainSplit.getX()));
|
264 |
windowLayout.set("MainDivider.Y",
|
265 |
Integer.toString(tempMainSplit.getY()));
|
266 |
windowLayout.set("MainDivider.Width",
|
267 |
Integer.toString(tempMainSplit.getWidth()));
|
268 |
windowLayout.set("MainDivider.Height",
|
269 |
Integer.toString(tempMainSplit.getHeight()));
|
270 |
|
271 |
if (isPalette()) {
|
272 |
windowLayout.set("GraphicLocator.isPalette", "true"); |
273 |
} else {
|
274 |
windowLayout.set("GraphicLocator.isPalette", "false"); |
275 |
if (tempSplitToc != null) { |
276 |
windowLayout.set("TOCDivider.Location",
|
277 |
Integer.toString(tempSplitToc.getDividerLocation()));
|
278 |
windowLayout.set("TOCDivider.X",
|
279 |
Integer.toString(tempSplitToc.getX()));
|
280 |
windowLayout.set("TOCDivider.Y",
|
281 |
Integer.toString(tempSplitToc.getY()));
|
282 |
windowLayout.set("TOCDivider.Width",
|
283 |
Integer.toString(tempSplitToc.getWidth()));
|
284 |
windowLayout.set("TOCDivider.Height",
|
285 |
Integer.toString(tempSplitToc.getHeight()));
|
286 |
} |
287 |
} |
288 |
if (m_TOC != null) { |
289 |
windowLayout.set("TOC.Width", Integer.toString(m_TOC.getWidth())); |
290 |
windowLayout.set("TOC.Height", Integer.toString(m_TOC.getHeight())); |
291 |
} |
292 |
if (m_MapControl != null) { |
293 |
windowLayout.set("MapControl.Width",
|
294 |
Integer.toString(m_MapControl.getWidth()));
|
295 |
windowLayout.set("MapControl.Height",
|
296 |
Integer.toString(m_MapControl.getHeight()));
|
297 |
} |
298 |
if (m_MapLoc != null) { |
299 |
windowLayout.set("GraphicLocator.Width",
|
300 |
Integer.toString(m_MapLoc.getWidth()));
|
301 |
windowLayout.set("GraphicLocator.Height",
|
302 |
Integer.toString(m_MapLoc.getHeight()));
|
303 |
} |
304 |
|
305 |
return windowLayout;
|
306 |
} |
307 |
|
308 |
public void setWindowLayout(WindowLayout data) { |
309 |
windowLayout = data; |
310 |
} |
311 |
|
312 |
public void propertyChange(PropertyChangeEvent evt) { |
313 |
// Detect when the related document has been removed
|
314 |
// and close or dispose whatever is needed
|
315 |
if ("delDocument".equals(evt.getPropertyName())) { |
316 |
if (evt.getOldValue() != null |
317 |
&& evt.getOldValue() instanceof ViewDocument) {
|
318 |
ViewDocument viewDocument = (ViewDocument) evt.getOldValue(); |
319 |
ViewDocument myViewDocument = getViewDocument(); |
320 |
if (myViewDocument != null |
321 |
&& myViewDocument.equals(viewDocument)) { |
322 |
m_MapControl.dispose(); |
323 |
m_MapLoc.dispose(); |
324 |
} |
325 |
} |
326 |
} |
327 |
} |
328 |
} |