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