Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / mdiManager / FrameWindowSupport.java @ 40558

History | View | Annotate | Download (9.1 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.coreplugin.mdiManager;
25

    
26
import java.awt.Component;
27
import java.awt.Dimension;
28
import java.awt.Image;
29
import java.util.Hashtable;
30
import java.util.Iterator;
31

    
32
import javax.swing.ImageIcon;
33
import javax.swing.JComponent;
34
import javax.swing.JDialog;
35
import javax.swing.JFrame;
36
import javax.swing.JInternalFrame;
37
import javax.swing.JPanel;
38

    
39
import org.gvsig.andami.ui.mdiFrame.MDIFrame;
40
import org.gvsig.andami.ui.mdiManager.IWindow;
41
import org.gvsig.andami.ui.mdiManager.WindowInfo;
42
import org.gvsig.coreplugin.mdiManager.frames.ExternalFrame;
43
import org.gvsig.coreplugin.mdiManager.frames.IFrame;
44
import org.gvsig.coreplugin.mdiManager.frames.InternalFrame;
45
import org.gvsig.i18n.Messages;
46

    
47

    
48

    
49
/**
50
 *
51
 */
52
public class FrameWindowSupport {
53
    private Hashtable frameView = new Hashtable();
54
    private Hashtable viewFrame = new Hashtable();
55
    private Image icon;
56
    private WindowInfoSupport vis;
57
        private JFrame mainFrame;
58

    
59
    /**
60
     * Creates a new FrameViewSupport object.
61
     *
62
     * @param i DOCUMENT ME!
63
     */
64
    public FrameWindowSupport(MDIFrame mainFrame) {
65
            this.mainFrame = mainFrame;
66
        icon = mainFrame.getIconImage();
67
    }
68

    
69
    public Iterator getWindowIterator(){
70
            return viewFrame.keySet().iterator();
71
    }
72

    
73
    public boolean contains(IWindow v){
74
            return viewFrame.containsKey(v);
75
    }
76

    
77
        /**
78
         * @param wnd
79
         * @return
80
         */
81
        public boolean contains(JInternalFrame wnd) {
82
                return frameView.contains(wnd);
83
        }
84

    
85
    /**
86
     * DOCUMENT ME!
87
     *
88
     * @param p DOCUMENT ME!
89
     *
90
     * @return DOCUMENT ME!
91
     */
92
    public JDialog getJDialog(IWindow p) {
93
        JDialog dlg = (JDialog) viewFrame.get(p);
94

    
95
        if (dlg == null) {
96
            WindowInfo vi = vis.getWindowInfo(p);
97
            ExternalFrame nuevo = new ExternalFrame(mainFrame);
98

    
99
            nuevo.getContentPane().add((JPanel) p);
100
            nuevo.setSize(getWidth(p, vi), getHeight(p, vi) + 30);
101
            nuevo.setTitle(vi.getTitle());
102
            nuevo.setResizable(vi.isResizable());
103
            nuevo.setMinimumSize(vi.getMinimumSize());
104

    
105
            viewFrame.put(p, nuevo);
106
            frameView.put(nuevo, p);
107

    
108
            nuevo.setModal(vi.isModal());
109
            return nuevo;
110
        } else {
111
            return dlg;
112
        }
113
    }
114

    
115
    /**
116
     * DOCUMENT ME!
117
     *
118
     * @param p DOCUMENT ME!
119
     *
120
     * @return DOCUMENT ME!
121
     */
122
    public JInternalFrame getJInternalFrame(IWindow p) {
123
            JInternalFrame frame = (JInternalFrame) viewFrame.get(p);
124

    
125
        if (frame == null) {
126
                //ViewInfo vi = vis.getViewInfo(p);
127
            JInternalFrame nuevo = createJInternalFrame(p);
128
            viewFrame.put(p, nuevo);
129
            frameView.put(nuevo, p);
130

    
131
            return nuevo;
132
        } else {
133
            return frame;
134
        }
135
    }
136
    
137
    /**
138
     * Gets the frame associated to the provided IWindow panel.
139
     * The frame will usually be a JInternalFrame or a JDialog.
140
     *
141
     * @param panel The IWindow panel whose frame wants to be retrieved.
142
     *
143
     * @return The associated frame, it will usually be a JInternalFrame or
144
     * a JDialog.
145
     */
146
    public Component getFrame(IWindow panel) {
147
            Object object = viewFrame.get(panel);
148
            if (object!=null && object instanceof Component) {
149
                    return (Component) object;
150
            }
151
            else {
152
            throw new RuntimeException(Messages.getText("window_not_found")
153
                + ": " + panel.getWindowInfo().getTitle());
154
            }
155
    }
156

    
157
    public JInternalFrame createJInternalFrame(IWindow p)
158
    {
159
        WindowInfo wi = vis.getWindowInfo(p);
160
        JInternalFrame nuevo = new InternalFrame();
161
        if (icon != null){
162
            nuevo.setFrameIcon(new ImageIcon(icon));
163
        }
164
        
165
        nuevo.getContentPane().add((JPanel) p);
166
        nuevo.setClosable(!wi.isNotClosable());
167
        nuevo.setSize(getWidth(p, wi), getHeight(p, wi));
168
        nuevo.setTitle(wi.getTitle());
169
        nuevo.setVisible(wi.isVisible());
170
        nuevo.setResizable(wi.isResizable());
171
        nuevo.setIconifiable(wi.isIconifiable());
172
        nuevo.setMaximizable(wi.isMaximizable());
173
        nuevo.setLocation(wi.getX(), wi.getY());
174
        nuevo.setMinimumSize(wi.getMinimumSize());
175

    
176
        nuevo.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
177
        return nuevo;
178
    }
179

    
180
    public IWindow getWindow(Component dlg){
181
            return (IWindow) frameView.get(dlg);
182
    }
183

    
184
    public void closeWindow(IWindow v){
185
            Object c = viewFrame.remove(v);
186
            frameView.remove(c);
187
    }
188

    
189
    /**
190
     * DOCUMENT ME!
191
     *
192
     * @param v DOCUMENT ME!
193
     * @param x DOCUMENT ME!
194
     */
195
    public void setX(IWindow win, int x) {
196
            IFrame frame = (IFrame) viewFrame.get(win);
197
            if (frame != null) {
198
                frame.setX(x);
199
            }
200
            
201
    }
202

    
203
    /**
204
     * DOCUMENT ME!
205
     *
206
     * @param v DOCUMENT ME!
207
     * @param y DOCUMENT ME!
208
     */
209
    public void setY(IWindow win, int y) {
210
            IFrame frame = (IFrame) viewFrame.get(win);
211
        if (frame != null) {
212
            frame.setY(y);
213
        }
214
    }
215

    
216
    /**
217
     * DOCUMENT ME!
218
     *
219
     * @param v DOCUMENT ME!
220
     * @param height DOCUMENT ME!
221
     */
222
    public void setHeight(IWindow win, int height) {
223
            IFrame frame = (IFrame) viewFrame.get(win);
224
            frame.setHeight(height);
225
    }
226

    
227
    /**
228
     * DOCUMENT ME!
229
     *
230
     * @param v DOCUMENT ME!
231
     * @param width DOCUMENT ME!
232
     */
233
    public void setWidth(IWindow win, int width) {
234
            IFrame frame = (IFrame) viewFrame.get(win);
235
            frame.setWidth(width);
236
    }
237

    
238
    /**
239
     * DOCUMENT ME!
240
     *
241
     * @param v DOCUMENT ME!
242
     * @param title DOCUMENT ME!
243
     */
244
    public void setTitle(IWindow win, String title) {
245
            IFrame frame = (IFrame) viewFrame.get(win);
246
            frame.setTitle(title);
247
    }
248
    
249
        /**
250
         * Sets the minimum allowed size for the provided window.
251
         * 
252
         * @param sw
253
         * @param minSize
254
         */
255
        public void setMinimumSize(IWindow win, Dimension minSize) {
256
            IFrame frame = (IFrame) viewFrame.get(win);
257
            frame.setMinimumSize(minSize);
258
        }
259

    
260
    /**
261
     * DOCUMENT ME!
262
     *
263
     * @param vis The vis to set.
264
     */
265
    public void setVis(WindowInfoSupport vis) {
266
        this.vis = vis;
267
    }
268

    
269
    /**
270
     * DOCUMENT ME!
271
     *
272
     * @param v DOCUMENT ME!
273
     *
274
     * @return DOCUMENT ME!
275
     */
276
    private int getWidth(IWindow v) {
277
        WindowInfo vi = vis.getWindowInfo(v);
278

    
279
        if (vi.getWidth() == -1) {
280
            JPanel p = (JPanel) v;
281

    
282
            return p.getSize().width;
283
        } else {
284
            return vi.getWidth();
285
        }
286
    }
287

    
288
    /**
289
     * DOCUMENT ME!
290
     *
291
     * @param v DOCUMENT ME!
292
     *
293
     * @return DOCUMENT ME!
294
     */
295
    private int getWidth(IWindow v, WindowInfo wi) {
296
        if (wi.getWidth() == -1) {
297
            JPanel p = (JPanel) v;
298

    
299
            return p.getSize().width;
300
        } else {
301
            return wi.getWidth();
302
        }
303
    }
304

    
305
    /**
306
     * DOCUMENT ME!
307
     *
308
     * @param v DOCUMENT ME!
309
     *
310
     * @return DOCUMENT ME!
311
     */
312
    private int getHeight(IWindow v) {
313
        WindowInfo vi = vis.getWindowInfo(v);
314

    
315
        if (vi.getHeight() == -1) {
316
            JPanel p = (JPanel) v;
317

    
318
            return p.getSize().height;
319
        } else {
320
            return vi.getHeight();
321
        }
322
    }
323

    
324
    /**
325
     * DOCUMENT ME!
326
     *
327
     * @param v DOCUMENT ME!
328
     *
329
     * @return DOCUMENT ME!
330
     */
331
    private int getHeight(IWindow v, WindowInfo wi) {
332
        if (wi.getHeight() == -1) {
333
            JPanel p = (JPanel) v;
334

    
335
            return p.getSize().height;
336
        } else {
337
            return wi.getHeight();
338
        }
339
    }
340

    
341
    public void updateWindowInfo(IWindow win, WindowInfo windowInfo) {
342
            Object o = viewFrame.get(win);
343
            if (windowInfo!=null && o!=null) {
344
                    if (o instanceof JComponent) {
345
                        JComponent component = (JComponent) o;
346
                        windowInfo.updateWidth(component.getWidth());
347
                                windowInfo.updateHeight(component.getHeight());
348
                                windowInfo.updateX(component.getX());
349
                                windowInfo.updateY(component.getY());
350
                                windowInfo.updateClosed(!component.isShowing());
351
                                if (component instanceof JInternalFrame) {
352
                                        JInternalFrame iframe = (JInternalFrame) component;
353
                                        windowInfo.updateNormalBounds(iframe.getNormalBounds());
354
                                        windowInfo.updateMaximized(iframe.isMaximum());
355
                                }
356
                    }
357
            }
358
    }
359

    
360
}