root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / gui / BaseView.java @ 37338
History | View | Annotate | Download (8.75 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project.documents.view.gui; |
42 |
|
43 |
import java.awt.Graphics; |
44 |
import java.awt.image.BufferedImage; |
45 |
|
46 |
import javax.swing.JPanel; |
47 |
import javax.swing.JSplitPane; |
48 |
|
49 |
import org.cresques.cts.IProjection; |
50 |
import org.gvsig.fmap.swing.toc.TOC; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.messages.NotificationManager; |
54 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
55 |
import com.iver.andami.ui.mdiManager.IWindowTransform; |
56 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
57 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
58 |
import com.iver.cit.gvsig.fmap.MapControl; |
59 |
import com.iver.cit.gvsig.project.documents.gui.IDocumentWindow; |
60 |
import com.iver.cit.gvsig.project.documents.gui.WindowData; |
61 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
62 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
63 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
64 |
|
65 |
//import javax.swing.JSplitPane;
|
66 |
//import com.iver.cit.gvsig.gui.panels.MapOverViewPalette;
|
67 |
//import java.util.HashMap;
|
68 |
|
69 |
public abstract class BaseView extends JPanel implements IView, |
70 |
IWindowListener, IWindowTransform, SingletonWindow, IDocumentWindow { |
71 |
|
72 |
protected MapControl m_MapControl;
|
73 |
protected MapOverview m_MapLoc;
|
74 |
|
75 |
// store the properties of the window
|
76 |
protected WindowInfo m_viewInfo = null; |
77 |
|
78 |
/** DOCUMENT ME! */
|
79 |
protected TOC m_TOC;
|
80 |
protected IProjectView modelo;
|
81 |
protected ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener(); |
82 |
|
83 |
protected boolean isPalette=false; |
84 |
protected MapOverViewPalette movp;
|
85 |
protected ViewSplitPane tempMainSplit=null; |
86 |
protected JSplitPane tempSplitToc=null; |
87 |
|
88 |
|
89 |
protected WindowData windowData = null; |
90 |
|
91 |
// OVERRIDE THESE
|
92 |
public void windowActivated() {} |
93 |
public void toPalette() {} |
94 |
public void restore() {} |
95 |
|
96 |
protected class ViewSplitPane extends JSplitPane{ |
97 |
private int lastDivider=0; |
98 |
public ViewSplitPane(int horizontal_split) { |
99 |
super(horizontal_split);
|
100 |
} |
101 |
|
102 |
protected void paintChildren(Graphics g) { |
103 |
if (lastDivider!=lastDividerLocation){
|
104 |
System.out.println("paintChildren = "+this.lastDividerLocation); |
105 |
// getMapControl().getMapContext().clearAllCachingImageDrawnLayers();
|
106 |
lastDivider=lastDividerLocation; |
107 |
} |
108 |
super.paintChildren(g);
|
109 |
} |
110 |
|
111 |
} |
112 |
/**
|
113 |
* Creates a new View object. Before using it, it must be initialized
|
114 |
* using the <code>initialize()</code> method.
|
115 |
*
|
116 |
* @see initialize()
|
117 |
*/
|
118 |
public BaseView() {
|
119 |
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* Create the internal componentes and populate the window with them.
|
124 |
* If the layout properties were set using the
|
125 |
* <code>setWindowData(WindowData)</code>
|
126 |
* method, the window will be populated according to this
|
127 |
* properties.
|
128 |
*/
|
129 |
public void initialize() {} |
130 |
|
131 |
/**
|
132 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
133 |
* for this View. It is not intended to retrieve the ViewInfo object in a
|
134 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
135 |
* to retrieve the ViewInfo object at any time after the creation of the
|
136 |
* object.
|
137 |
*
|
138 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
139 |
*/
|
140 |
public WindowInfo getWindowInfo() {
|
141 |
if (m_viewInfo == null) |
142 |
{ |
143 |
m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE |
|
144 |
WindowInfo.MAXIMIZABLE); |
145 |
|
146 |
m_viewInfo.setWidth(500);
|
147 |
m_viewInfo.setHeight(300);
|
148 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " + |
149 |
modelo.getName()); |
150 |
} |
151 |
return m_viewInfo;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
|
156 |
*/
|
157 |
public void windowClosed() { |
158 |
if (movp!=null) |
159 |
PluginServices.getMDIManager().closeWindow(movp); |
160 |
///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
161 |
|
162 |
if (modelo != null) |
163 |
modelo.storeWindowData(getWindowData()); |
164 |
} |
165 |
|
166 |
/**
|
167 |
* DOCUMENT ME!
|
168 |
*
|
169 |
* @return DOCUMENT ME!
|
170 |
*/
|
171 |
public IProjectView getModel() {
|
172 |
return modelo;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* DOCUMENT ME!
|
177 |
*
|
178 |
* @return DOCUMENT ME!
|
179 |
*/
|
180 |
public MapOverview getMapOverview() {
|
181 |
return m_MapLoc;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* DOCUMENT ME!
|
186 |
*
|
187 |
* @return DOCUMENT ME!
|
188 |
*/
|
189 |
public MapControl getMapControl() {
|
190 |
return m_MapControl;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* DOCUMENT ME!
|
195 |
*
|
196 |
* @return DOCUMENT ME!
|
197 |
*/
|
198 |
public TOC getTOC() {
|
199 |
return m_TOC;
|
200 |
} |
201 |
|
202 |
/* (non-Javadoc)
|
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 |
/**
|
225 |
* DOCUMENT ME!
|
226 |
*/
|
227 |
public void repaintMap() { |
228 |
m_MapControl.drawMap(false);
|
229 |
} |
230 |
|
231 |
public class ViewExceptionListener implements ExceptionListener { |
232 |
|
233 |
/**
|
234 |
* @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
|
235 |
*/
|
236 |
public void exceptionThrown(Throwable t) { |
237 |
NotificationManager.addError(t.getMessage(), t); |
238 |
} |
239 |
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @return
|
244 |
*/
|
245 |
public BufferedImage getImage() { |
246 |
return m_MapControl.getImage();
|
247 |
} |
248 |
|
249 |
public void setProjection(IProjection proj) |
250 |
{ |
251 |
getMapControl().setProjection(proj); |
252 |
} |
253 |
public IProjection getProjection()
|
254 |
{ |
255 |
return getMapControl().getProjection();
|
256 |
} |
257 |
|
258 |
public WindowData getWindowData() {
|
259 |
updateWindowData(); |
260 |
return windowData;
|
261 |
} |
262 |
|
263 |
private void updateWindowData() { |
264 |
if (windowData == null) |
265 |
windowData = new WindowData();
|
266 |
windowData.set("MainWindow.X", Integer.toString(this.getX())); |
267 |
windowData.set("MainWindow.Y", Integer.toString(this.getY())); |
268 |
windowData.set("MainWindow.Width", Integer.toString(this.getWidth())); |
269 |
windowData.set("MainWindow.Height", Integer.toString(this.getHeight())); |
270 |
|
271 |
windowData.set("MainDivider.Location", Integer.toString(tempMainSplit.getDividerLocation())); |
272 |
windowData.set("MainDivider.X", Integer.toString(tempMainSplit.getX())); |
273 |
windowData.set("MainDivider.Y", Integer.toString(tempMainSplit.getY())); |
274 |
windowData.set("MainDivider.Width", Integer.toString(tempMainSplit.getWidth())); |
275 |
windowData.set("MainDivider.Height", Integer.toString(tempMainSplit.getHeight())); |
276 |
|
277 |
if (isPalette())
|
278 |
windowData.set("GraphicLocator.isPalette", "true"); |
279 |
else {
|
280 |
windowData.set("GraphicLocator.isPalette", "false"); |
281 |
if (tempSplitToc!=null) { |
282 |
windowData.set("TOCDivider.Location", Integer.toString(tempSplitToc.getDividerLocation())); |
283 |
windowData.set("TOCDivider.X", Integer.toString(tempSplitToc.getX())); |
284 |
windowData.set("TOCDivider.Y", Integer.toString(tempSplitToc.getY())); |
285 |
windowData.set("TOCDivider.Width", Integer.toString(tempSplitToc.getWidth())); |
286 |
windowData.set("TOCDivider.Height", Integer.toString(tempSplitToc.getHeight())); |
287 |
} |
288 |
} |
289 |
if (m_TOC!=null) { |
290 |
windowData.set("TOC.Width", Integer.toString(m_TOC.getComponent().getWidth())); |
291 |
windowData.set("TOC.Height", Integer.toString(m_TOC.getComponent().getHeight())); |
292 |
} |
293 |
if (m_MapControl!=null) { |
294 |
windowData.set("MapControl.Width", Integer.toString(m_MapControl.getWidth())); |
295 |
windowData.set("MapControl.Height", Integer.toString(m_MapControl.getHeight())); |
296 |
} |
297 |
if (m_MapLoc!=null) { |
298 |
windowData.set("GraphicLocator.Width", Integer.toString(m_MapLoc.getWidth())); |
299 |
windowData.set("GraphicLocator.Height", Integer.toString(m_MapLoc.getHeight())); |
300 |
} |
301 |
|
302 |
} |
303 |
|
304 |
public void setWindowData(WindowData data) { |
305 |
windowData = data; |
306 |
} |
307 |
} |