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 31496 jjdelcerro
/* gvSIG. Geographic Information System of the Valencian Government
2 36475 cordinyana
 *
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 31496 jjdelcerro
23
/*
24 36475 cordinyana
 * AUTHORS (In addition to CIT):
25
 * 2004-2009 IVER TI
26
 *
27
 */
28 29596 jpiera
package org.gvsig.app.project.documents.view.gui;
29 7392 sbayarri
30 10839 caballero
import java.awt.Graphics;
31 7392 sbayarri
import java.awt.image.BufferedImage;
32 38514 cordinyana
import java.beans.PropertyChangeEvent;
33
import java.beans.PropertyChangeListener;
34 7392 sbayarri
35
import javax.swing.JPanel;
36
import javax.swing.JSplitPane;
37
38
import org.cresques.cts.IProjection;
39 36475 cordinyana
40 29596 jpiera
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 38514 cordinyana
import org.gvsig.app.project.ProjectManager;
45 31496 jjdelcerro
import org.gvsig.app.project.documents.gui.WindowLayout;
46 36475 cordinyana
import org.gvsig.app.project.documents.view.MapOverview;
47 31496 jjdelcerro
import org.gvsig.app.project.documents.view.ViewDocument;
48 29596 jpiera
import org.gvsig.app.project.documents.view.toc.gui.TOC;
49 20994 jmvivo
import org.gvsig.fmap.mapcontrol.MapControl;
50 29596 jpiera
import org.gvsig.utils.exceptionHandling.ExceptionListener;
51 38608 jjdelcerro
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
53 7392 sbayarri
54 31496 jjdelcerro
/**
55
 *
56 36475 cordinyana
 * @author 2005- Vicente Caballero
57
 * @author 2009- Joaquin del Cerro
58
 *
59 31496 jjdelcerro
 */
60 7392 sbayarri
61 36475 cordinyana
public abstract class AbstractViewPanel extends JPanel implements IView,
62 38514 cordinyana
    IWindowTransform, PropertyChangeListener {
63 7392 sbayarri
64 38608 jjdelcerro
        private static final Logger logger = LoggerFactory.getLogger(AbstractViewPanel.class);
65
66 36475 cordinyana
    private static final long serialVersionUID = -259620280790490262L;
67 31496 jjdelcerro
68 36482 cordinyana
    private static final int DEFAULT_HEIGHT = 450;
69
70
    private static final int DEFAULT_WIDTH = 700;
71
72 36475 cordinyana
    protected MapControl m_MapControl;
73
    protected MapOverview m_MapLoc;
74 7392 sbayarri
75 36475 cordinyana
    // store the properties of the window
76
    protected WindowInfo m_viewInfo = null;
77
    protected WindowLayout windowLayout = null;
78 7392 sbayarri
79 36475 cordinyana
    protected TOC m_TOC;
80
    protected ViewDocument modelo;
81
    protected ViewExceptionListener mapControlExceptionListener =
82
        new ViewExceptionListener();
83 7392 sbayarri
84 36475 cordinyana
    protected boolean isPalette = false;
85
    protected MapOverViewPalette movp;
86
    protected ViewSplitPane tempMainSplit = null;
87
    protected JSplitPane tempSplitToc = null;
88 10839 caballero
89 36475 cordinyana
    public void windowActivated() {
90
        // By default do nothing
91
    }
92 10839 caballero
93 36475 cordinyana
    public void toPalette() {
94
        // By default do nothing
95
    }
96 7392 sbayarri
97 36475 cordinyana
    public void restore() {
98
        // By default do nothing
99
    }
100 10839 caballero
101 36475 cordinyana
    protected class ViewSplitPane extends JSplitPane {
102 10839 caballero
103 36475 cordinyana
        private static final long serialVersionUID = -7506953938664812652L;
104
        private int lastDivider = 0;
105 7392 sbayarri
106 36475 cordinyana
        public ViewSplitPane(int horizontal_split) {
107
            super(horizontal_split);
108
        }
109 7392 sbayarri
110 36475 cordinyana
        protected void paintChildren(Graphics g) {
111
            if (lastDivider != lastDividerLocation) {
112 38608 jjdelcerro
                    logger.debug("paintChildren = "+ this.lastDividerLocation);
113 36475 cordinyana
                lastDivider = lastDividerLocation;
114
            }
115
            super.paintChildren(g);
116
        }
117 7392 sbayarri
118 36475 cordinyana
    }
119 7392 sbayarri
120 36475 cordinyana
    /**
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 38514 cordinyana
            ProjectManager.getInstance().getCurrentProject().addPropertyChangeListener(this);
128 36475 cordinyana
    }
129 7392 sbayarri
130 36475 cordinyana
    /**
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 33408 fdiaz
141 36475 cordinyana
    /**
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 7392 sbayarri
156 36482 cordinyana
            m_viewInfo.setWidth(DEFAULT_WIDTH);
157
            m_viewInfo.setHeight(DEFAULT_HEIGHT);
158 36765 cordinyana
            m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + ": "
159 36475 cordinyana
                + modelo.getName());
160
        }
161
        return m_viewInfo;
162
    }
163 7392 sbayarri
164 36475 cordinyana
    /**
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 7392 sbayarri
176 36475 cordinyana
    /**
177
     * @deprecated See {@link #getViewDocument()}
178
     */
179
    public ViewDocument getModel() {
180
        return modelo;
181
    }
182 7392 sbayarri
183 36475 cordinyana
    public ViewDocument getViewDocument() {
184
        return modelo;
185
    }
186 7392 sbayarri
187 36475 cordinyana
    public MapOverview getMapOverview() {
188
        return m_MapLoc;
189
    }
190 7392 sbayarri
191 36475 cordinyana
    public MapControl getMapControl() {
192
        return m_MapControl;
193
    }
194 7392 sbayarri
195 36475 cordinyana
    public TOC getTOC() {
196
        return m_TOC;
197
    }
198 7392 sbayarri
199 36475 cordinyana
    /*
200
     * (non-Javadoc)
201
     *
202
     * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
203
     */
204 7392 sbayarri
205 36475 cordinyana
    public Object getWindowModel() {
206
        return modelo;
207
    }
208 7392 sbayarri
209 36475 cordinyana
    /**
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 7392 sbayarri
219 36475 cordinyana
    public boolean isPalette() {
220
        return isPalette;
221
    }
222 7392 sbayarri
223 36475 cordinyana
    public void repaintMap() {
224
        m_MapControl.drawMap(false);
225
    }
226 7392 sbayarri
227 36475 cordinyana
    public class ViewExceptionListener implements ExceptionListener {
228 10839 caballero
229 36475 cordinyana
        /**
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 10839 caballero
236 36475 cordinyana
    }
237 9044 cesar
238 36475 cordinyana
    /**
239
     * @return
240
     */
241
    public BufferedImage getImage() {
242
        return m_MapControl.getImage();
243
    }
244 10839 caballero
245 36475 cordinyana
    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 38514 cordinyana
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 7392 sbayarri
}