Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / gui / BaseView.java @ 9044

History | View | Annotate | Download (8.17 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.image.BufferedImage;
44

    
45
import javax.swing.JPanel;
46
import javax.swing.JSplitPane;
47

    
48
import org.cresques.cts.IProjection;
49

    
50
import com.iver.andami.PluginServices;
51
import com.iver.andami.messages.NotificationManager;
52
import com.iver.andami.ui.mdiManager.IWindowListener;
53
import com.iver.andami.ui.mdiManager.IWindowTransform;
54
import com.iver.andami.ui.mdiManager.SingletonWindow;
55
import com.iver.andami.ui.mdiManager.WindowInfo;
56
import com.iver.cit.gvsig.fmap.MapControl;
57
import com.iver.cit.gvsig.project.documents.gui.WindowData;
58
import com.iver.cit.gvsig.project.documents.view.IProjectView;
59
import com.iver.cit.gvsig.project.documents.view.MapOverview;
60
import com.iver.cit.gvsig.project.documents.view.toc.gui.TOC;
61
import com.iver.utiles.exceptionHandling.ExceptionListener;
62

    
63
//import javax.swing.JSplitPane;
64
//import com.iver.cit.gvsig.gui.panels.MapOverViewPalette;
65
//import java.util.HashMap;
66

    
67
public abstract class BaseView extends JPanel implements IView,
68
IWindowListener, IWindowTransform, SingletonWindow {
69

    
70
  protected MapControl m_MapControl;
71
  protected MapOverview m_MapLoc;
72

    
73
  // store the properties of the window
74
  protected WindowInfo m_viewInfo = null;
75

    
76
  /** DOCUMENT ME! */
77
  protected TOC m_TOC;
78
  protected IProjectView modelo;
79
  protected ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener();
80

    
81
  protected boolean isPalette=false;
82
  protected MapOverViewPalette movp;
83
  protected JSplitPane tempMainSplit, tempSplitToc=null;
84
  
85
  
86
  protected WindowData windowData = null;
87

    
88
  // OVERRIDE THESE
89
  public void windowActivated() {}
90
  public void toPalette() {}
91
  public void restore() {}
92

    
93

    
94
  /**
95
   * Creates a new View object. Before using it, it must be initialized
96
   * using the <code>initialize()</code> method.
97
   * 
98
   * @see initialize()
99
   */
100
  public BaseView() {
101

    
102
  }
103
  
104
  /**
105
   * Create the internal componentes and populate the window with them.
106
   * If the layout properties were set using the
107
   * <code>setWindowData(WindowData)</code>
108
   * method, the window will be populated according to this
109
   * properties.
110
   */
111
  public void initialize() {}
112

    
113
  /**
114
   * This method is used to get <strong>an initial</strong> ViewInfo object
115
   * for this View. It is not intended to retrieve the ViewInfo object in a
116
   * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
117
   * to retrieve the ViewInfo object at any time after the creation of the
118
   * object.
119
   *
120
   * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
121
   */
122
  public WindowInfo getWindowInfo() {
123
          if (m_viewInfo == null)
124
          {
125
                  m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE |
126
                        WindowInfo.MAXIMIZABLE);
127

    
128
                        m_viewInfo.setWidth(500);
129
                        m_viewInfo.setHeight(300);
130
                        m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " +
131
              modelo.getName());
132
          }
133
                 return m_viewInfo;
134
  }
135

    
136
        /**
137
         * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
138
         */
139
        public void windowClosed() {
140
                if (movp!=null)
141
                        PluginServices.getMDIManager().closeWindow(movp);
142
                ///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
143
                
144
                if (modelo != null)
145
                        modelo.storeWindowData(getWindowData());
146
        }
147

    
148
  /**
149
   * DOCUMENT ME!
150
   *
151
   * @return DOCUMENT ME!
152
   */
153
  public IProjectView getModel() {
154
      return modelo;
155
  }
156

    
157
  /**
158
   * DOCUMENT ME!
159
   *
160
   * @return DOCUMENT ME!
161
   */
162
  public MapOverview getMapOverview() {
163
      return m_MapLoc;
164
  }
165

    
166
  /**
167
   * DOCUMENT ME!
168
   *
169
   * @return DOCUMENT ME!
170
   */
171
  public MapControl getMapControl() {
172
      return m_MapControl;
173
  }
174

    
175
  /**
176
   * DOCUMENT ME!
177
   *
178
   * @return DOCUMENT ME!
179
   */
180
  public TOC getTOC() {
181
          return m_TOC;
182
  }
183

    
184
  /* (non-Javadoc)
185
   * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
186
   */
187

    
188
  public Object getWindowModel() {
189
      return modelo;
190
  }
191

    
192
  /**
193
   * This method is used to get <strong>an initial</strong> ViewInfo object
194
   * for this View. It is not intended to retrieve the ViewInfo object in a
195
   * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
196
   * to retrieve the ViewInfo object at any time after the creation of the
197
   * object.
198
   *
199
   * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
200
   */
201

    
202
        public boolean isPalette() {
203
                return isPalette;
204
        }
205

    
206
  /**
207
   * DOCUMENT ME!
208
   */
209
  public void repaintMap() {
210
      m_MapControl.drawMap(false);
211
  }
212

    
213
  public class ViewExceptionListener implements ExceptionListener {
214

    
215
          /**
216
           * @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
217
           */
218
          public void exceptionThrown(Throwable t) {
219
                  NotificationManager.addError(t.getMessage(), t);
220
          }
221

    
222
  }
223

    
224
        /**
225
         * @return
226
         */
227
        public BufferedImage getImage() {
228
                return m_MapControl.getImage();
229
        }
230

    
231
        public void setProjection(IProjection proj)
232
        {
233
                getMapControl().setProjection(proj);
234
        }
235
        public IProjection getProjection()
236
        {
237
                return getMapControl().getProjection();
238
        }
239

    
240
        public WindowData getWindowData() {
241
                updateWindowData();
242
                return windowData;
243
        }
244
        
245
        private void updateWindowData() {
246
                if (windowData == null)
247
                        windowData = new WindowData();
248
                windowData.set("MainWindow.X", Integer.toString(this.getX()));
249
                windowData.set("MainWindow.Y", Integer.toString(this.getY()));
250
                windowData.set("MainWindow.Width", Integer.toString(this.getWidth()));
251
                windowData.set("MainWindow.Height", Integer.toString(this.getHeight()));
252
                
253
                windowData.set("MainDivider.Location", Integer.toString(tempMainSplit.getDividerLocation()));
254
                windowData.set("MainDivider.X", Integer.toString(tempMainSplit.getX()));
255
                windowData.set("MainDivider.Y", Integer.toString(tempMainSplit.getY()));
256
                windowData.set("MainDivider.Width", Integer.toString(tempMainSplit.getWidth()));
257
                windowData.set("MainDivider.Height", Integer.toString(tempMainSplit.getHeight()));
258
                
259
                if (isPalette())
260
                        windowData.set("GraphicLocator.isPalette", "true");
261
                else {
262
                        windowData.set("GraphicLocator.isPalette", "false");
263
                        if (tempSplitToc!=null) {
264
                                windowData.set("TOCDivider.Location", Integer.toString(tempSplitToc.getDividerLocation()));
265
                                windowData.set("TOCDivider.X", Integer.toString(tempSplitToc.getX()));
266
                                windowData.set("TOCDivider.Y", Integer.toString(tempSplitToc.getY()));
267
                                windowData.set("TOCDivider.Width", Integer.toString(tempSplitToc.getWidth()));
268
                                windowData.set("TOCDivider.Height", Integer.toString(tempSplitToc.getHeight()));
269
                        }
270
                }
271
                if (m_TOC!=null) {
272
                        windowData.set("TOC.Width", Integer.toString(m_TOC.getWidth()));
273
                        windowData.set("TOC.Height", Integer.toString(m_TOC.getHeight()));
274
                }
275
                if (m_MapControl!=null) {
276
                        windowData.set("MapControl.Width", Integer.toString(m_MapControl.getWidth()));
277
                        windowData.set("MapControl.Height", Integer.toString(m_MapControl.getHeight()));
278
                }
279
                if (m_MapLoc!=null) {
280
                        windowData.set("GraphicLocator.Width", Integer.toString(m_MapLoc.getWidth()));
281
                        windowData.set("GraphicLocator.Height", Integer.toString(m_MapLoc.getHeight()));
282
                }
283

    
284
        }
285
        
286
        public void setWindowData(WindowData data) {
287
                windowData = data;
288
        }
289
}