Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / gui / BaseView.java @ 29596

History | View | Annotate | Download (8.65 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 org.gvsig.app.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.andami.PluginServices;
51
import org.gvsig.andami.messages.NotificationManager;
52
import org.gvsig.andami.ui.mdiManager.IWindowListener;
53
import org.gvsig.andami.ui.mdiManager.IWindowTransform;
54
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
55
import org.gvsig.andami.ui.mdiManager.WindowInfo;
56
import org.gvsig.app.project.documents.gui.IDocumentWindow;
57
import org.gvsig.app.project.documents.gui.WindowData;
58
import org.gvsig.app.project.documents.view.IProjectView;
59
import org.gvsig.app.project.documents.view.MapOverview;
60
import org.gvsig.app.project.documents.view.toc.gui.TOC;
61
import org.gvsig.fmap.mapcontrol.MapControl;
62
import org.gvsig.utils.exceptionHandling.ExceptionListener;
63

    
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
                                lastDivider=lastDividerLocation;
106
                        }
107
                        super.paintChildren(g);
108
                }
109

    
110
        }
111
  /**
112
   * Creates a new View object. Before using it, it must be initialized
113
   * using the <code>initialize()</code> method.
114
   *
115
   * @see initialize()
116
   */
117
  public BaseView() {
118

    
119
  }
120

    
121
  /**
122
   * Create the internal componentes and populate the window with them.
123
   * If the layout properties were set using the
124
   * <code>setWindowData(WindowData)</code>
125
   * method, the window will be populated according to this
126
   * properties.
127
   */
128
  public void initialize() {}
129

    
130
  /**
131
   * This method is used to get <strong>an initial</strong> ViewInfo object
132
   * for this View. It is not intended to retrieve the ViewInfo object in a
133
   * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
134
   * to retrieve the ViewInfo object at any time after the creation of the
135
   * object.
136
   *
137
   * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
138
   */
139
  public WindowInfo getWindowInfo() {
140
          if (m_viewInfo == null)
141
          {
142
                  m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE |
143
                        WindowInfo.MAXIMIZABLE);
144

    
145
                        m_viewInfo.setWidth(500);
146
                        m_viewInfo.setHeight(300);
147
                        m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " +
148
              modelo.getName());
149
          }
150
                 return m_viewInfo;
151
  }
152

    
153
        /**
154
         * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
155
         */
156
        public void windowClosed() {
157
                if (movp!=null)
158
                        PluginServices.getMDIManager().closeWindow(movp);
159
                ///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
160

    
161
                if (modelo != null)
162
                        modelo.storeWindowData(getWindowData());
163
        }
164

    
165
  /**
166
   * DOCUMENT ME!
167
   *
168
   * @return DOCUMENT ME!
169
   */
170
  public IProjectView getModel() {
171
      return modelo;
172
  }
173

    
174
  /**
175
   * DOCUMENT ME!
176
   *
177
   * @return DOCUMENT ME!
178
   */
179
  public MapOverview getMapOverview() {
180
      return m_MapLoc;
181
  }
182

    
183
  /**
184
   * DOCUMENT ME!
185
   *
186
   * @return DOCUMENT ME!
187
   */
188
  public MapControl getMapControl() {
189
      return m_MapControl;
190
  }
191

    
192
  /**
193
   * DOCUMENT ME!
194
   *
195
   * @return DOCUMENT ME!
196
   */
197
  public TOC getTOC() {
198
          return m_TOC;
199
  }
200

    
201
  /* (non-Javadoc)
202
   * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
203
   */
204

    
205
  public Object getWindowModel() {
206
      return modelo;
207
  }
208

    
209
  /**
210
   * This method is used to get <strong>an initial</strong> ViewInfo object
211
   * for this View. It is not intended to retrieve the ViewInfo object in a
212
   * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
213
   * to retrieve the ViewInfo object at any time after the creation of the
214
   * object.
215
   *
216
   * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
217
   */
218

    
219
        public boolean isPalette() {
220
                return isPalette;
221
        }
222

    
223
  /**
224
   * DOCUMENT ME!
225
   */
226
  public void repaintMap() {
227
      m_MapControl.drawMap(false);
228
  }
229

    
230
  public class ViewExceptionListener implements ExceptionListener {
231

    
232
          /**
233
           * @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
234
           */
235
          public void exceptionThrown(Throwable t) {
236
                  NotificationManager.addError(t.getMessage(), t);
237
          }
238

    
239
  }
240

    
241
        /**
242
         * @return
243
         */
244
        public BufferedImage getImage() {
245
                return m_MapControl.getImage();
246
        }
247

    
248
        public void setProjection(IProjection proj)
249
        {
250
                getMapControl().setProjection(proj);
251
        }
252
        public IProjection getProjection()
253
        {
254
                return getMapControl().getProjection();
255
        }
256

    
257
        public WindowData getWindowData() {
258
                updateWindowData();
259
                return windowData;
260
        }
261

    
262
        private void updateWindowData() {
263
                if (windowData == null)
264
                        windowData = new WindowData();
265
                windowData.set("MainWindow.X", Integer.toString(this.getX()));
266
                windowData.set("MainWindow.Y", Integer.toString(this.getY()));
267
                windowData.set("MainWindow.Width", Integer.toString(this.getWidth()));
268
                windowData.set("MainWindow.Height", Integer.toString(this.getHeight()));
269

    
270
                windowData.set("MainDivider.Location", Integer.toString(tempMainSplit.getDividerLocation()));
271
                windowData.set("MainDivider.X", Integer.toString(tempMainSplit.getX()));
272
                windowData.set("MainDivider.Y", Integer.toString(tempMainSplit.getY()));
273
                windowData.set("MainDivider.Width", Integer.toString(tempMainSplit.getWidth()));
274
                windowData.set("MainDivider.Height", Integer.toString(tempMainSplit.getHeight()));
275

    
276
                if (isPalette())
277
                        windowData.set("GraphicLocator.isPalette", "true");
278
                else {
279
                        windowData.set("GraphicLocator.isPalette", "false");
280
                        if (tempSplitToc!=null) {
281
                                windowData.set("TOCDivider.Location", Integer.toString(tempSplitToc.getDividerLocation()));
282
                                windowData.set("TOCDivider.X", Integer.toString(tempSplitToc.getX()));
283
                                windowData.set("TOCDivider.Y", Integer.toString(tempSplitToc.getY()));
284
                                windowData.set("TOCDivider.Width", Integer.toString(tempSplitToc.getWidth()));
285
                                windowData.set("TOCDivider.Height", Integer.toString(tempSplitToc.getHeight()));
286
                        }
287
                }
288
                if (m_TOC!=null) {
289
                        windowData.set("TOC.Width", Integer.toString(m_TOC.getWidth()));
290
                        windowData.set("TOC.Height", Integer.toString(m_TOC.getHeight()));
291
                }
292
                if (m_MapControl!=null) {
293
                        windowData.set("MapControl.Width", Integer.toString(m_MapControl.getWidth()));
294
                        windowData.set("MapControl.Height", Integer.toString(m_MapControl.getHeight()));
295
                }
296
                if (m_MapLoc!=null) {
297
                        windowData.set("GraphicLocator.Width", Integer.toString(m_MapLoc.getWidth()));
298
                        windowData.set("GraphicLocator.Height", Integer.toString(m_MapLoc.getHeight()));
299
                }
300

    
301
        }
302

    
303
        public void setWindowData(WindowData data) {
304
                windowData = data;
305
        }
306
}