Statistics
| Revision:

root / tags / v1_0_2_Build_910 / libraries / libCorePlugin / src / com / iver / core / mdiManager / FrameWindowSupport.java @ 11275

History | View | Annotate | Download (9.26 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.core.mdiManager;
42

    
43
import java.awt.Component;
44
import java.awt.Image;
45
import java.util.Hashtable;
46
import java.util.Iterator;
47

    
48
import javax.swing.ImageIcon;
49
import javax.swing.JComponent;
50
import javax.swing.JDialog;
51
import javax.swing.JFrame;
52
import javax.swing.JInternalFrame;
53
import javax.swing.JPanel;
54

    
55
import com.iver.andami.ui.mdiFrame.MDIFrame;
56
import com.iver.andami.ui.mdiManager.IWindow;
57
import com.iver.andami.ui.mdiManager.WindowInfo;
58

    
59

    
60
/**
61
 *
62
 */
63
public class FrameWindowSupport {
64
    private Hashtable frameView = new Hashtable();
65
    private Hashtable viewFrame = new Hashtable();
66
    private Image icon;
67
    private WindowInfoSupport vis;
68
        private JFrame mainFrame;
69

    
70
    /**
71
     * Creates a new FrameViewSupport object.
72
     *
73
     * @param i DOCUMENT ME!
74
     */
75
    public FrameWindowSupport(MDIFrame mainFrame) {
76
            this.mainFrame = mainFrame;
77
        icon = mainFrame.getIconImage();
78
    }
79

    
80
    public Iterator getWindowIterator(){
81
            return viewFrame.keySet().iterator();
82
    }
83
    
84
    public boolean contains(IWindow v){
85
            return viewFrame.containsKey(v);
86
    }
87

    
88
        /**
89
         * @param wnd
90
         * @return
91
         */
92
        public boolean contains(JInternalFrame wnd) {
93
                return frameView.contains(wnd);
94
        }
95
    
96
    /**
97
     * DOCUMENT ME!
98
     *
99
     * @param p DOCUMENT ME!
100
     *
101
     * @return DOCUMENT ME!
102
     */
103
    public JDialog getJDialog(IWindow p) {
104
        JDialog dlg = (JDialog) viewFrame.get(p);
105

    
106
        if (dlg == null) {
107
            WindowInfo vi = vis.getWindowInfo(p);
108
            JDialog nuevo = new JDialog(mainFrame);
109

    
110
            nuevo.getContentPane().add((JPanel) p);
111
            nuevo.setSize(getWidth(p, vi), getHeight(p, vi) + 30);
112
            nuevo.setTitle(vi.getTitle());
113
            nuevo.setResizable(vi.isResizable());
114

    
115
            viewFrame.put(p, nuevo);
116
            frameView.put(nuevo, p);
117

    
118
            nuevo.setModal(vi.isModal());
119
            return nuevo;
120
        } else {
121
            return dlg;
122
        }
123
    }
124

    
125
    /**
126
     * DOCUMENT ME!
127
     *
128
     * @param p DOCUMENT ME!
129
     *
130
     * @return DOCUMENT ME!
131
     */
132
    public JInternalFrame getJInternalFrame(IWindow p) {
133
            JInternalFrame frame = (JInternalFrame) viewFrame.get(p);
134

    
135
        if (frame == null) {
136
                //ViewInfo vi = vis.getViewInfo(p);
137
            JInternalFrame nuevo = createJInternalFrame(p);
138
            viewFrame.put(p, nuevo);
139
            frameView.put(nuevo, p);
140

    
141
            return nuevo;
142
        } else {
143
            return frame;
144
        }
145
    }
146

    
147
    public JInternalFrame createJInternalFrame(IWindow p)
148
    {
149
        WindowInfo vi = vis.getWindowInfo(p);
150
        JInternalFrame nuevo = new JInternalFrame();
151
        if (icon != null){
152
            nuevo.setFrameIcon(new ImageIcon(icon));
153
        }
154
        nuevo.getContentPane().add((JPanel) p);
155
        nuevo.setClosable(true);
156
        nuevo.setSize(getWidth(p, vi), getHeight(p, vi));
157
        nuevo.setTitle(vi.getTitle());
158
        nuevo.setVisible(vi.isVisible());
159
        nuevo.setResizable(vi.isResizable());
160
        nuevo.setIconifiable(vi.isIconifiable());
161
        nuevo.setMaximizable(vi.isMaximizable());
162
        nuevo.setLocation(vi.getX(), vi.getY());
163

    
164
        nuevo.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
165
        return nuevo;
166
    }
167
    
168
    public IWindow getWindow(Component dlg){
169
            return (IWindow) frameView.get(dlg);
170
    }
171
    
172
    public Component getFrame(IWindow window) {
173
            return (Component) viewFrame.get(window);
174
    }
175
    
176
    public void closeWindow(IWindow v){
177
            Object c = viewFrame.remove(v);
178
            frameView.remove(c);
179
    }
180
    
181
    /**
182
     * DOCUMENT ME!
183
     *
184
     * @param v DOCUMENT ME!
185
     * @param x DOCUMENT ME!
186
     */
187
    public void setX(IWindow v, int x) {
188
            Object frame = (JInternalFrame) viewFrame.get(v);
189
            if (frame instanceof JInternalFrame) {
190
                    JInternalFrame iframe = (JInternalFrame) frame;
191
                    iframe.setLocation(x, iframe.getY());
192
            }
193
            else if (frame instanceof JDialog) {
194
                    JDialog dialog = (JDialog) frame;
195
                    dialog.setLocation(x, dialog.getY());
196
            }
197
    }
198

    
199
    /**
200
     * DOCUMENT ME!
201
     *
202
     * @param v DOCUMENT ME!
203
     * @param y DOCUMENT ME!
204
     */
205
    public void setY(IWindow v, int y) {
206
            Object frame = (JInternalFrame) viewFrame.get(v);
207
            if (frame instanceof JInternalFrame) {
208
                    JInternalFrame iframe = (JInternalFrame) frame;
209
                    iframe.setLocation(iframe.getX(), y);
210
            }
211
            else if (frame instanceof JDialog) {
212
                    JDialog dialog = (JDialog) frame;
213
                    dialog.setLocation(dialog.getX(), y);
214
            }
215
    }
216

    
217
    /**
218
     * DOCUMENT ME!
219
     *
220
     * @param v DOCUMENT ME!
221
     * @param height DOCUMENT ME!
222
     */
223
    public void setHeight(IWindow v, int height) {
224
            Object frame = (JInternalFrame) viewFrame.get(v);
225
            if (frame instanceof JInternalFrame) {
226
                    JInternalFrame iframe = (JInternalFrame) frame;
227
                    iframe.setSize(iframe.getWidth(), height);
228
            }
229
            else if (frame instanceof JDialog) {
230
                    JDialog dialog = (JDialog) frame;
231
                    dialog.setSize(dialog.getWidth(), height);
232
            }
233
    }
234

    
235
    /**
236
     * DOCUMENT ME!
237
     *
238
     * @param v DOCUMENT ME!
239
     * @param width DOCUMENT ME!
240
     */
241
    public void setWidth(IWindow v, int width) {
242
            Object frame = (JInternalFrame) viewFrame.get(v);
243
            if (frame instanceof JInternalFrame) {
244
                    JInternalFrame iframe = (JInternalFrame) frame;
245
                    iframe.setSize(width, iframe.getHeight());
246
            }
247
            else if (frame instanceof JDialog) {
248
                    JDialog dialog = (JDialog) frame;
249
                    dialog.setSize(width, dialog.getHeight());
250
            }
251
    }
252

    
253
    /**
254
     * DOCUMENT ME!
255
     *
256
     * @param v DOCUMENT ME!
257
     * @param title DOCUMENT ME!
258
     */
259
    public void setTitle(IWindow v, String title) {
260
            Object frame = (JInternalFrame) viewFrame.get(v);
261
            if (frame instanceof JInternalFrame)
262
                    ((JInternalFrame)frame).setTitle(title);
263
            else if (frame instanceof JDialog)
264
                    ((JDialog)frame).setTitle(title);
265
    }
266

    
267
    /**
268
     * DOCUMENT ME!
269
     *
270
     * @param vis The vis to set.
271
     */
272
    public void setVis(WindowInfoSupport vis) {
273
        this.vis = vis;
274
    }
275

    
276
    /**
277
     * DOCUMENT ME!
278
     *
279
     * @param v DOCUMENT ME!
280
     *
281
     * @return DOCUMENT ME!
282
     */
283
    private int getWidth(IWindow v) {
284
        WindowInfo vi = vis.getWindowInfo(v);
285

    
286
        if (vi.getWidth() == -1) {
287
            JPanel p = (JPanel) v;
288

    
289
            return p.getSize().width;
290
        } else {
291
            return vi.getWidth();
292
        }
293
    }
294
    
295
    /**
296
     * DOCUMENT ME!
297
     *
298
     * @param v DOCUMENT ME!
299
     *
300
     * @return DOCUMENT ME!
301
     */
302
    private int getWidth(IWindow v, WindowInfo wi) {
303
        if (wi.getWidth() == -1) {
304
            JPanel p = (JPanel) v;
305

    
306
            return p.getSize().width;
307
        } else {
308
            return wi.getWidth();
309
        }
310
    }
311

    
312
    /**
313
     * DOCUMENT ME!
314
     *
315
     * @param v DOCUMENT ME!
316
     *
317
     * @return DOCUMENT ME!
318
     */
319
    private int getHeight(IWindow v) {
320
        WindowInfo vi = vis.getWindowInfo(v);
321

    
322
        if (vi.getHeight() == -1) {
323
            JPanel p = (JPanel) v;
324

    
325
            return p.getSize().height;
326
        } else {
327
            return vi.getHeight();
328
        }
329
    }
330
    
331
    /**
332
     * DOCUMENT ME!
333
     *
334
     * @param v DOCUMENT ME!
335
     *
336
     * @return DOCUMENT ME!
337
     */
338
    private int getHeight(IWindow v, WindowInfo wi) {
339
        if (wi.getHeight() == -1) {
340
            JPanel p = (JPanel) v;
341

    
342
            return p.getSize().height;
343
        } else {
344
            return wi.getHeight();
345
        }
346
    }
347
    
348
    public void updateWindowInfo(IWindow win, WindowInfo windowInfo) {
349
            Object o = viewFrame.get(win);
350
            if (windowInfo!=null && o!=null) {
351
                    if (o instanceof JComponent) {
352
                        JComponent component = (JComponent) o;
353
                        windowInfo.setWidth(component.getWidth());
354
                                windowInfo.setHeight(component.getHeight());
355
                                windowInfo.setX(component.getX());
356
                                windowInfo.setY(component.getY());
357
                                windowInfo.setClosed(!component.isShowing());
358
                                if (component instanceof JInternalFrame) {
359
                                        JInternalFrame iframe = (JInternalFrame) component;
360
                                        windowInfo.setNormalBounds(iframe.getNormalBounds());
361
                                        windowInfo.setMaximized(iframe.isMaximum());
362
                                }
363
                    }
364
            }
365
    }
366
}