Statistics
| Revision:

root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / FrameWindowSupport.java @ 9209

History | View | Annotate | Download (8.23 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.PluginServices;
56
import com.iver.andami.plugins.PluginClassLoader;
57
import com.iver.andami.ui.mdiFrame.MDIFrame;
58
import com.iver.andami.ui.mdiManager.IWindow;
59
import com.iver.andami.ui.mdiManager.WindowInfo;
60

    
61

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

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

    
82
    public Iterator getWindowIterator(){
83
            return viewFrame.keySet().iterator();
84
    }
85

    
86
    public boolean contains(IWindow v){
87
            return viewFrame.containsKey(v);
88
    }
89

    
90
        /**
91
         * @param wnd
92
         * @return
93
         */
94
        public boolean contains(JInternalFrame wnd) {
95
                return frameView.contains(wnd);
96
        }
97

    
98
    /**
99
     * DOCUMENT ME!
100
     *
101
     * @param p DOCUMENT ME!
102
     *
103
     * @return DOCUMENT ME!
104
     */
105
    public JDialog getJDialog(IWindow p) {
106
        JDialog dlg = (JDialog) viewFrame.get(p);
107

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

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

    
117
            viewFrame.put(p, nuevo);
118
            frameView.put(nuevo, p);
119

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

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

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

    
143
            return nuevo;
144
        } else {
145
            return frame;
146
        }
147
    }
148

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

    
166
        nuevo.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
167
        return nuevo;
168
    }
169

    
170
    public IWindow getWindow(Component dlg){
171
            return (IWindow) frameView.get(dlg);
172
    }
173

    
174
    public Component getFrame(IWindow window) {
175
            return (Component) viewFrame.get(window);
176
    }
177

    
178
    public void closeWindow(IWindow v){
179
            Object c = viewFrame.remove(v);
180
            frameView.remove(c);
181
    }
182

    
183
    /**
184
     * DOCUMENT ME!
185
     *
186
     * @param v DOCUMENT ME!
187
     * @param x DOCUMENT ME!
188
     */
189
    public void setX(IWindow v, int x) {
190
            JInternalFrame o = (JInternalFrame) viewFrame.get(v);
191
        o.setLocation(x, o.getY());
192
    }
193

    
194
    /**
195
     * DOCUMENT ME!
196
     *
197
     * @param v DOCUMENT ME!
198
     * @param y DOCUMENT ME!
199
     */
200
    public void setY(IWindow v, int y) {
201
            JInternalFrame o = (JInternalFrame) viewFrame.get(v);
202

    
203
        o.setLocation(o.getX(), y);
204
    }
205

    
206
    /**
207
     * DOCUMENT ME!
208
     *
209
     * @param v DOCUMENT ME!
210
     * @param height DOCUMENT ME!
211
     */
212
    public void setHeight(IWindow v, int height) {
213
            JInternalFrame o = (JInternalFrame) viewFrame.get(v);
214

    
215
        o.setSize(o.getWidth(), height);
216
    }
217

    
218
    /**
219
     * DOCUMENT ME!
220
     *
221
     * @param v DOCUMENT ME!
222
     * @param width DOCUMENT ME!
223
     */
224
    public void setWidth(IWindow v, int width) {
225
            JInternalFrame o = (JInternalFrame) viewFrame.get(v);
226

    
227
            o.setSize(width, o.getHeight());
228
    }
229

    
230
    /**
231
     * DOCUMENT ME!
232
     *
233
     * @param v DOCUMENT ME!
234
     * @param title DOCUMENT ME!
235
     */
236
    public void setTitle(IWindow v, String title) {
237
            JInternalFrame o = (JInternalFrame) viewFrame.get(v);
238
        o.setTitle(title);
239
    }
240

    
241
    /**
242
     * DOCUMENT ME!
243
     *
244
     * @param vis The vis to set.
245
     */
246
    public void setVis(WindowInfoSupport vis) {
247
        this.vis = vis;
248
    }
249

    
250
    /**
251
     * DOCUMENT ME!
252
     *
253
     * @param v DOCUMENT ME!
254
     *
255
     * @return DOCUMENT ME!
256
     */
257
    private int getWidth(IWindow v) {
258
        WindowInfo vi = vis.getWindowInfo(v);
259

    
260
        if (vi.getWidth() == -1) {
261
            JPanel p = (JPanel) v;
262

    
263
            return p.getSize().width;
264
        } else {
265
            return vi.getWidth();
266
        }
267
    }
268

    
269
    /**
270
     * DOCUMENT ME!
271
     *
272
     * @param v DOCUMENT ME!
273
     *
274
     * @return DOCUMENT ME!
275
     */
276
    private int getWidth(IWindow v, WindowInfo wi) {
277
        if (wi.getWidth() == -1) {
278
            JPanel p = (JPanel) v;
279

    
280
            return p.getSize().width;
281
        } else {
282
            return wi.getWidth();
283
        }
284
    }
285

    
286
    /**
287
     * DOCUMENT ME!
288
     *
289
     * @param v DOCUMENT ME!
290
     *
291
     * @return DOCUMENT ME!
292
     */
293
    private int getHeight(IWindow v) {
294
        WindowInfo vi = vis.getWindowInfo(v);
295

    
296
        if (vi.getHeight() == -1) {
297
            JPanel p = (JPanel) v;
298

    
299
            return p.getSize().height;
300
        } else {
301
            return vi.getHeight();
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, WindowInfo wi) {
313
        if (wi.getHeight() == -1) {
314
            JPanel p = (JPanel) v;
315

    
316
            return p.getSize().height;
317
        } else {
318
            return wi.getHeight();
319
        }
320
    }
321

    
322
    public void updateWindowInfo(IWindow win, WindowInfo windowInfo) {
323
            Object o = viewFrame.get(win);
324
            if (windowInfo!=null && o!=null) {
325
                    if (o instanceof JComponent) {
326
                        JComponent component = (JComponent) o;
327
                        windowInfo.setWidth(component.getWidth());
328
                                windowInfo.setHeight(component.getHeight());
329
                                windowInfo.setX(component.getX());
330
                                windowInfo.setY(component.getY());
331
                                windowInfo.setClosed(!component.isShowing());
332
                                if (component instanceof JInternalFrame) {
333
                                        JInternalFrame iframe = (JInternalFrame) component;
334
                                        windowInfo.setNormalBounds(iframe.getNormalBounds());
335
                                        windowInfo.setMaximized(iframe.isMaximum());
336
                                }
337
                    }
338
            }
339
    }
340
}