Statistics
| Revision:

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

History | View | Annotate | Download (6.77 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.JDialog;
50
import javax.swing.JFrame;
51
import javax.swing.JInternalFrame;
52
import javax.swing.JPanel;
53

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

    
58

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
200
        o.setLocation(o.getX(), y);
201
    }
202

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

    
212
        o.setSize(o.getWidth(), height);
213
    }
214

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

    
224
            o.setSize(width, o.getHeight());
225
    }
226

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

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

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

    
257
        if (vi.getWidth() == -1) {
258
            JPanel p = (JPanel) v;
259

    
260
            return p.getSize().width;
261
        } else {
262
            return vi.getWidth();
263
        }
264
    }
265

    
266
    /**
267
     * DOCUMENT ME!
268
     *
269
     * @param v DOCUMENT ME!
270
     *
271
     * @return DOCUMENT ME!
272
     */
273
    private int getHeight(IWindow v) {
274
        WindowInfo vi = vis.getWindowInfo(v);
275

    
276
        if (vi.getHeight() == -1) {
277
            JPanel p = (JPanel) v;
278

    
279
            return p.getSize().height;
280
        } else {
281
            return vi.getHeight();
282
        }
283
    }
284
}