Statistics
| Revision:

root / tags / v2_0_0_Build_2050 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / gui / AbstractViewPanel.java @ 38653

History | View | Annotate | Download (10.3 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
import java.beans.PropertyChangeEvent;
33
import java.beans.PropertyChangeListener;
34

    
35
import javax.swing.JPanel;
36
import javax.swing.JSplitPane;
37

    
38
import org.cresques.cts.IProjection;
39

    
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.messages.NotificationManager;
42
import org.gvsig.andami.ui.mdiManager.IWindowTransform;
43
import org.gvsig.andami.ui.mdiManager.WindowInfo;
44
import org.gvsig.app.project.ProjectManager;
45
import org.gvsig.app.project.documents.gui.WindowLayout;
46
import org.gvsig.app.project.documents.view.MapOverview;
47
import org.gvsig.app.project.documents.view.ViewDocument;
48
import org.gvsig.app.project.documents.view.toc.gui.TOC;
49
import org.gvsig.fmap.mapcontrol.MapControl;
50
import org.gvsig.utils.exceptionHandling.ExceptionListener;
51
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
53

    
54
/**
55
 * 
56
 * @author 2005- Vicente Caballero
57
 * @author 2009- Joaquin del Cerro
58
 * 
59
 */
60

    
61
public abstract class AbstractViewPanel extends JPanel implements IView,
62
    IWindowTransform, PropertyChangeListener {
63

    
64
        private static final Logger logger = LoggerFactory.getLogger(AbstractViewPanel.class);
65
        
66
    private static final long serialVersionUID = -259620280790490262L;
67

    
68
    private static final int DEFAULT_HEIGHT = 450;
69

    
70
    private static final int DEFAULT_WIDTH = 700;
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
    protected WindowLayout windowLayout = null;
78

    
79
    protected TOC m_TOC;
80
    protected ViewDocument modelo;
81
    protected ViewExceptionListener mapControlExceptionListener =
82
        new ViewExceptionListener();
83

    
84
    protected boolean isPalette = false;
85
    protected MapOverViewPalette movp;
86
    protected ViewSplitPane tempMainSplit = null;
87
    protected JSplitPane tempSplitToc = null;
88

    
89
    public void windowActivated() {
90
        // By default do nothing
91
    }
92

    
93
    public void toPalette() {
94
        // By default do nothing
95
    }
96

    
97
    public void restore() {
98
        // By default do nothing
99
    }
100

    
101
    protected class ViewSplitPane extends JSplitPane {
102

    
103
        private static final long serialVersionUID = -7506953938664812652L;
104
        private int lastDivider = 0;
105

    
106
        public ViewSplitPane(int horizontal_split) {
107
            super(horizontal_split);
108
        }
109

    
110
        protected void paintChildren(Graphics g) {
111
            if (lastDivider != lastDividerLocation) {
112
                    logger.debug("paintChildren = "+ this.lastDividerLocation);
113
                lastDivider = lastDividerLocation;
114
            }
115
            super.paintChildren(g);
116
        }
117

    
118
    }
119

    
120
    /**
121
     * Creates a new View object. Before using it, it must be initialized
122
     * using the <code>initialize()</code> method.
123
     * 
124
     * @see initialize()
125
     */
126
    public AbstractViewPanel() {
127
            ProjectManager.getInstance().getCurrentProject().addPropertyChangeListener(this);
128
    }
129

    
130
    /**
131
     * Create the internal componentes and populate the window with them.
132
     * If the layout properties were set using the
133
     * <code>setWindowData(WindowData)</code> method, the window will be
134
     * populated according to this
135
     * properties.
136
     */
137
    protected void initialize() {
138
        // Do nothing
139
    }
140

    
141
    /**
142
     * This method is used to get <strong>an initial</strong> ViewInfo object
143
     * for this View. It is not intended to retrieve the ViewInfo object in a
144
     * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
145
     * to retrieve the ViewInfo object at any time after the creation of the
146
     * object.
147
     * 
148
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
149
     */
150
    public WindowInfo getWindowInfo() {
151
        if (m_viewInfo == null) {
152
            m_viewInfo =
153
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
154
                    | WindowInfo.MAXIMIZABLE);
155

    
156
            m_viewInfo.setWidth(DEFAULT_WIDTH);
157
            m_viewInfo.setHeight(DEFAULT_HEIGHT);
158
            m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + ": "
159
                + modelo.getName());
160
        }
161
        return m_viewInfo;
162
    }
163

    
164
    /**
165
     * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
166
     */
167
    public void windowClosed() {
168
        if (movp != null) {
169
            PluginServices.getMDIManager().closeWindow(movp);
170
        }
171
        if (modelo != null) {
172
            modelo.setWindowLayout(this.getWindowLayout());
173
        }
174
    }
175

    
176
    /**
177
     * @deprecated See {@link #getViewDocument()}
178
     */
179
    public ViewDocument getModel() {
180
        return modelo;
181
    }
182

    
183
    public ViewDocument getViewDocument() {
184
        return modelo;
185
    }
186

    
187
    public MapOverview getMapOverview() {
188
        return m_MapLoc;
189
    }
190

    
191
    public MapControl getMapControl() {
192
        return m_MapControl;
193
    }
194

    
195
    public TOC getTOC() {
196
        return m_TOC;
197
    }
198

    
199
    /*
200
     * (non-Javadoc)
201
     * 
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
    public void repaintMap() {
224
        m_MapControl.drawMap(false);
225
    }
226

    
227
    public class ViewExceptionListener implements ExceptionListener {
228

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

    
236
    }
237

    
238
    /**
239
     * @return
240
     */
241
    public BufferedImage getImage() {
242
        return m_MapControl.getImage();
243
    }
244

    
245
    public void setProjection(IProjection proj) {
246
        getMapControl().setProjection(proj);
247
    }
248

    
249
    public IProjection getProjection() {
250
        return getMapControl().getProjection();
251
    }
252

    
253
    public WindowLayout getWindowLayout() {
254
        if (windowLayout == null) {
255
            windowLayout = new WindowLayout();
256
        }
257
        windowLayout.set("MainWindow.X", Integer.toString(this.getX()));
258
        windowLayout.set("MainWindow.Y", Integer.toString(this.getY()));
259
        windowLayout.set("MainWindow.Width", Integer.toString(this.getWidth()));
260
        windowLayout.set("MainWindow.Height",
261
            Integer.toString(this.getHeight()));
262

    
263
        windowLayout.set("MainDivider.Location",
264
            Integer.toString(tempMainSplit.getDividerLocation()));
265
        windowLayout.set("MainDivider.X",
266
            Integer.toString(tempMainSplit.getX()));
267
        windowLayout.set("MainDivider.Y",
268
            Integer.toString(tempMainSplit.getY()));
269
        windowLayout.set("MainDivider.Width",
270
            Integer.toString(tempMainSplit.getWidth()));
271
        windowLayout.set("MainDivider.Height",
272
            Integer.toString(tempMainSplit.getHeight()));
273

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

    
308
        return windowLayout;
309
    }
310

    
311
    public void setWindowLayout(WindowLayout data) {
312
        windowLayout = data;
313
    }
314
    
315
        public void propertyChange(PropertyChangeEvent evt) {
316
                // Detect when the related document has been removed
317
                // and close or dispose whatever is needed
318
                if ("delDocument".equals(evt.getPropertyName())) {
319
                        if (evt.getOldValue() != null
320
                                        && evt.getOldValue() instanceof ViewDocument) {
321
                                ViewDocument viewDocument = (ViewDocument) evt.getOldValue();
322
                                ViewDocument myViewDocument = getViewDocument();
323
                                if (myViewDocument != null
324
                                                && myViewDocument.equals(viewDocument)) {
325
                                        m_MapControl.dispose();
326
                                        m_MapLoc.dispose();
327
                                }
328
                        }
329
                }
330
        }
331
}