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