Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2040 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / gui / AbstractViewPanel.java @ 37235

History | View | Annotate | Download (9.46 KB)

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
 */
22

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

    
30
import java.awt.Graphics;
31
import java.awt.image.BufferedImage;
32

    
33
import javax.swing.JPanel;
34
import javax.swing.JSplitPane;
35

    
36
import org.cresques.cts.IProjection;
37

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

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

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

    
59
    private static final long serialVersionUID = -259620280790490262L;
60

    
61
    private static final int DEFAULT_HEIGHT = 450;
62

    
63
    private static final int DEFAULT_WIDTH = 700;
64

    
65
    protected MapControl m_MapControl;
66
    protected MapOverview m_MapLoc;
67

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

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

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

    
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

    
94
    protected class ViewSplitPane extends JSplitPane {
95

    
96
        private static final long serialVersionUID = -7506953938664812652L;
97
        private int lastDivider = 0;
98

    
99
        public ViewSplitPane(int horizontal_split) {
100
            super(horizontal_split);
101
        }
102

    
103
        protected void paintChildren(Graphics g) {
104
            if (lastDivider != lastDividerLocation) {
105
                System.out.println("paintChildren = "
106
                    + this.lastDividerLocation);
107
                lastDivider = lastDividerLocation;
108
            }
109
            super.paintChildren(g);
110
        }
111

    
112
    }
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
    }
123

    
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> method, the window will be
128
     * populated according to this
129
     * properties.
130
     */
131
    protected void initialize() {
132
        // Do nothing
133
    }
134

    
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
            m_viewInfo =
147
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
148
                    | WindowInfo.MAXIMIZABLE);
149

    
150
            m_viewInfo.setWidth(DEFAULT_WIDTH);
151
            m_viewInfo.setHeight(DEFAULT_HEIGHT);
152
            m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + ": "
153
                + modelo.getName());
154
        }
155
        return m_viewInfo;
156
    }
157

    
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
    }
169

    
170
    /**
171
     * @deprecated See {@link #getViewDocument()}
172
     */
173
    public ViewDocument getModel() {
174
        return modelo;
175
    }
176

    
177
    public ViewDocument getViewDocument() {
178
        return modelo;
179
    }
180

    
181
    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
    /*
194
     * (non-Javadoc)
195
     * 
196
     * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
197
     */
198

    
199
    public Object getWindowModel() {
200
        return modelo;
201
    }
202

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

    
213
    public boolean isPalette() {
214
        return isPalette;
215
    }
216

    
217
    public void repaintMap() {
218
        m_MapControl.drawMap(false);
219
    }
220

    
221
    public class ViewExceptionListener implements ExceptionListener {
222

    
223
        /**
224
         * @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
225
         */
226
        public void exceptionThrown(Throwable t) {
227
            NotificationManager.addError(t.getMessage(), t);
228
        }
229

    
230
    }
231

    
232
    /**
233
     * @return
234
     */
235
    public BufferedImage getImage() {
236
        return m_MapControl.getImage();
237
    }
238

    
239
    public void setProjection(IProjection proj) {
240
        getMapControl().setProjection(proj);
241
    }
242

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

    
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",
255
            Integer.toString(this.getHeight()));
256

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

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

    
302
        return windowLayout;
303
    }
304

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