Revision 36475 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/view/gui/AbstractViewPanel.java

View differences:

AbstractViewPanel.java
1 1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2009 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 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
*/
2
 *
3
 * Copyright (C) 2007-2009 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 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 22

  
23 23
/*
24
* AUTHORS (In addition to CIT):
25
* 2004-2009 IVER TI
26
*   
27
*/
24
 * AUTHORS (In addition to CIT):
25
 * 2004-2009 IVER TI
26
 *   
27
 */
28 28
package org.gvsig.app.project.documents.view.gui;
29 29

  
30 30
import java.awt.Graphics;
......
34 34
import javax.swing.JSplitPane;
35 35

  
36 36
import org.cresques.cts.IProjection;
37

  
37 38
import org.gvsig.andami.PluginServices;
38 39
import org.gvsig.andami.messages.NotificationManager;
39
import org.gvsig.andami.ui.mdiManager.IWindowListener;
40 40
import org.gvsig.andami.ui.mdiManager.IWindowTransform;
41
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
42 41
import org.gvsig.andami.ui.mdiManager.WindowInfo;
43 42
import org.gvsig.app.project.documents.gui.WindowLayout;
43
import org.gvsig.app.project.documents.view.MapOverview;
44 44
import org.gvsig.app.project.documents.view.ViewDocument;
45
import org.gvsig.app.project.documents.view.MapOverview;
46 45
import org.gvsig.app.project.documents.view.toc.gui.TOC;
47 46
import org.gvsig.fmap.mapcontrol.MapControl;
48 47
import org.gvsig.utils.exceptionHandling.ExceptionListener;
49 48

  
50

  
51 49
/**
52
 *
53
 * @author 2005-         Vicente Caballero
54
 * @author 2009-         Joaquin del Cerro
55 50
 * 
51
 * @author 2005- Vicente Caballero
52
 * @author 2009- Joaquin del Cerro
53
 * 
56 54
 */
57 55

  
58
public abstract class AbstractViewPanel extends JPanel 
59
	implements IView, IWindowTransform {
56
public abstract class AbstractViewPanel extends JPanel implements IView,
57
    IWindowTransform {
60 58

  
61
  /**
59
    /**
62 60
	 * 
63 61
	 */
64
	private static final long serialVersionUID = -259620280790490262L;
62
    private static final long serialVersionUID = -259620280790490262L;
65 63

  
66
  protected MapControl m_MapControl;
67
  protected MapOverview m_MapLoc;
64
    protected MapControl m_MapControl;
65
    protected MapOverview m_MapLoc;
68 66

  
69
  // store the properties of the window
70
  protected WindowInfo m_viewInfo = null;
71
  protected WindowLayout windowLayout = null;
67
    // store the properties of the window
68
    protected WindowInfo m_viewInfo = null;
69
    protected WindowLayout windowLayout = null;
72 70

  
73
  protected TOC m_TOC;
74
  protected ViewDocument modelo;
75
  protected ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener();
71
    protected TOC m_TOC;
72
    protected ViewDocument modelo;
73
    protected ViewExceptionListener mapControlExceptionListener =
74
        new ViewExceptionListener();
76 75

  
77
  protected boolean isPalette=false;
78
  protected MapOverViewPalette movp;
79
  protected ViewSplitPane tempMainSplit=null;
80
  protected JSplitPane tempSplitToc=null;
76
    protected boolean isPalette = false;
77
    protected MapOverViewPalette movp;
78
    protected ViewSplitPane tempMainSplit = null;
79
    protected JSplitPane tempSplitToc = null;
81 80

  
82
  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
  
81
    public void windowActivated() {
82
        // By default do nothing
83
    }
94 84

  
95
  protected class ViewSplitPane extends JSplitPane{
96
	  /**
97
	 * 
98
	 */
99
	private static final long serialVersionUID = -7506953938664812652L;
100
	private int lastDivider=0;
101
		public ViewSplitPane(int horizontal_split) {
102
			super(horizontal_split);
103
		}
85
    public void toPalette() {
86
        // By default do nothing
87
    }
104 88

  
105
		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
		}
89
    public void restore() {
90
        // By default do nothing
91
    }
112 92

  
113
	}
114
  /**
115
   * Creates a new View object. Before using it, it must be initialized
116
   * using the <code>initialize()</code> method.
117
   *
118
   * @see initialize()
119
   */
120
  public AbstractViewPanel() {
121
	  // Do nothing
122
  }
93
    protected class ViewSplitPane extends JSplitPane {
123 94

  
124
  /**
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
  protected void initialize() {
132
	  // Do nothing
133
  }
95
        private static final long serialVersionUID = -7506953938664812652L;
96
        private int lastDivider = 0;
134 97

  
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);
98
        public ViewSplitPane(int horizontal_split) {
99
            super(horizontal_split);
100
        }
149 101

  
150
			m_viewInfo.setWidth(500);
151
			m_viewInfo.setHeight(300);
152
			m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " +
153
              modelo.getName());
154
  	}
155
 		return m_viewInfo;
156
  }
102
        protected void paintChildren(Graphics g) {
103
            if (lastDivider != lastDividerLocation) {
104
                System.out.println("paintChildren = "
105
                    + this.lastDividerLocation);
106
                lastDivider = lastDividerLocation;
107
            }
108
            super.paintChildren(g);
109
        }
157 110

  
158
	/**
159
	 * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
160
	 */
161
	public void windowClosed() {
162
		if (movp!=null) {
163
			PluginServices.getMDIManager().closeWindow(movp);
164
		}
165
		if (modelo != null) {
166
			modelo.setWindowLayout( this.getWindowLayout() );
167
		}
168
	}
111
    }
169 112

  
170
  /**
171
   * @deprecated See {@link #getViewDocument()}
172
   */
173
  public ViewDocument getModel() {
174
      return modelo;
175
  }
113
    /**
114
     * Creates a new View object. Before using it, it must be initialized
115
     * using the <code>initialize()</code> method.
116
     * 
117
     * @see initialize()
118
     */
119
    public AbstractViewPanel() {
120
        // Do nothing
121
    }
176 122

  
177
  public ViewDocument getViewDocument() {
178
      return modelo;
179
  }
123
    /**
124
     * Create the internal componentes and populate the window with them.
125
     * If the layout properties were set using the
126
     * <code>setWindowData(WindowData)</code> method, the window will be
127
     * populated according to this
128
     * properties.
129
     */
130
    protected void initialize() {
131
        // Do nothing
132
    }
180 133

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

  
185
  public MapControl getMapControl() {
186
      return m_MapControl;
187
  }
149
            m_viewInfo.setWidth(500);
150
            m_viewInfo.setHeight(300);
151
            m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : "
152
                + modelo.getName());
153
        }
154
        return m_viewInfo;
155
    }
188 156

  
189
  public TOC getTOC() {
190
  	return m_TOC;
191
  }
157
    /**
158
     * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
159
     */
160
    public void windowClosed() {
161
        if (movp != null) {
162
            PluginServices.getMDIManager().closeWindow(movp);
163
        }
164
        if (modelo != null) {
165
            modelo.setWindowLayout(this.getWindowLayout());
166
        }
167
    }
192 168

  
193
  /* (non-Javadoc)
194
   * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
195
   */
169
    /**
170
     * @deprecated See {@link #getViewDocument()}
171
     */
172
    public ViewDocument getModel() {
173
        return modelo;
174
    }
196 175

  
197
  public Object getWindowModel() {
198
      return modelo;
199
  }
176
    public ViewDocument getViewDocument() {
177
        return modelo;
178
    }
200 179

  
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
   */
180
    public MapOverview getMapOverview() {
181
        return m_MapLoc;
182
    }
210 183

  
211
	public boolean isPalette() {
212
		return isPalette;
213
	}
184
    public MapControl getMapControl() {
185
        return m_MapControl;
186
    }
214 187

  
215
  public void repaintMap() {
216
      m_MapControl.drawMap(false);
217
  }
188
    public TOC getTOC() {
189
        return m_TOC;
190
    }
218 191

  
219
  public class ViewExceptionListener implements ExceptionListener {
192
    /*
193
     * (non-Javadoc)
194
     * 
195
     * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
196
     */
220 197

  
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
  	}
198
    public Object getWindowModel() {
199
        return modelo;
200
    }
227 201

  
228
  }
202
    /**
203
     * This method is used to get <strong>an initial</strong> ViewInfo object
204
     * for this View. It is not intended to retrieve the ViewInfo object in a
205
     * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
206
     * to retrieve the ViewInfo object at any time after the creation of the
207
     * object.
208
     * 
209
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
210
     */
229 211

  
230
	/**
231
	 * @return
232
	 */
233
	public BufferedImage getImage() {
234
		return m_MapControl.getImage();
235
	}
212
    public boolean isPalette() {
213
        return isPalette;
214
    }
236 215

  
237
	public void setProjection(IProjection proj)
238
	{
239
		getMapControl().setProjection(proj);
240
	}
241
	
242
	public IProjection getProjection()
243
	{
244
		return getMapControl().getProjection();
245
	}
216
    public void repaintMap() {
217
        m_MapControl.drawMap(false);
218
    }
246 219

  
247
	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()));
220
    public class ViewExceptionListener implements ExceptionListener {
255 221

  
256
		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()));
222
        /**
223
         * @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
224
         */
225
        public void exceptionThrown(Throwable t) {
226
            NotificationManager.addError(t.getMessage(), t);
227
        }
261 228

  
262
		if (isPalette()) {
263
			windowLayout.set("GraphicLocator.isPalette", "true");
264
	    } else {
265
			windowLayout.set("GraphicLocator.isPalette", "false");
266
			if (tempSplitToc!=null) {
267
				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
			}
273
		}
274
		if (m_TOC!=null) {
275
			windowLayout.set("TOC.Width", Integer.toString(m_TOC.getWidth()));
276
			windowLayout.set("TOC.Height", Integer.toString(m_TOC.getHeight()));
277
		}
278
		if (m_MapControl!=null) {
279
			windowLayout.set("MapControl.Width", Integer.toString(m_MapControl.getWidth()));
280
			windowLayout.set("MapControl.Height", Integer.toString(m_MapControl.getHeight()));
281
		}
282
		if (m_MapLoc!=null) {
283
			windowLayout.set("GraphicLocator.Width", Integer.toString(m_MapLoc.getWidth()));
284
			windowLayout.set("GraphicLocator.Height", Integer.toString(m_MapLoc.getHeight()));
285
		}
229
    }
286 230

  
287
		return windowLayout;
288
	}
231
    /**
232
     * @return
233
     */
234
    public BufferedImage getImage() {
235
        return m_MapControl.getImage();
236
    }
289 237

  
290
	public void setWindowLayout(WindowLayout data) {
291
		windowLayout = data;
292
	}
238
    public void setProjection(IProjection proj) {
239
        getMapControl().setProjection(proj);
240
    }
241

  
242
    public IProjection getProjection() {
243
        return getMapControl().getProjection();
244
    }
245

  
246
    public WindowLayout getWindowLayout() {
247
        if (windowLayout == null) {
248
            windowLayout = new WindowLayout();
249
        }
250
        windowLayout.set("MainWindow.X", Integer.toString(this.getX()));
251
        windowLayout.set("MainWindow.Y", Integer.toString(this.getY()));
252
        windowLayout.set("MainWindow.Width", Integer.toString(this.getWidth()));
253
        windowLayout.set("MainWindow.Height",
254
            Integer.toString(this.getHeight()));
255

  
256
        windowLayout.set("MainDivider.Location",
257
            Integer.toString(tempMainSplit.getDividerLocation()));
258
        windowLayout.set("MainDivider.X",
259
            Integer.toString(tempMainSplit.getX()));
260
        windowLayout.set("MainDivider.Y",
261
            Integer.toString(tempMainSplit.getY()));
262
        windowLayout.set("MainDivider.Width",
263
            Integer.toString(tempMainSplit.getWidth()));
264
        windowLayout.set("MainDivider.Height",
265
            Integer.toString(tempMainSplit.getHeight()));
266

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

  
301
        return windowLayout;
302
    }
303

  
304
    public void setWindowLayout(WindowLayout data) {
305
        windowLayout = data;
306
    }
293 307
}

Also available in: Unified diff