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