KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > client > util > MdiWindowManager


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.client.util;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import javax.swing.*;
28 import javax.swing.event.InternalFrameAdapter JavaDoc;
29 import javax.swing.event.InternalFrameEvent JavaDoc;
30
31 import org.lucane.client.Plugin;
32 import org.lucane.client.widgets.ManagedWindow;
33
34 public class MdiWindowManager implements WindowManager
35 {
36     private HashMap JavaDoc windows = new HashMap JavaDoc();
37     private JDesktopPane desktop = new JDesktopPane();
38     private JFrame container = new JFrame();
39     
40     public MdiWindowManager()
41     {
42         container.getContentPane().add(desktop, BorderLayout.CENTER);
43         container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
44         container.setSize(800, 600);
45     }
46
47     public void show(ManagedWindow window)
48     {
49         final JInternalFrame f = new JInternalFrame(window.getTitle(), true, true, true, true);
50         f.setName(window.getName());
51         f.setContentPane(window.getContentPane());
52         //f.setIconImage(window.getIconImage());
53
f.setJMenuBar(window.getJMenuBar());
54         f.setSize(window.getPreferredSize());
55         //f.setTitle(window.getTitle());
56
f.setResizable(window.isResizeable());
57         if(window.getPreferredSize() == null)
58             f.pack();
59         
60         if(window.mustExitPluginOnClose())
61         {
62             final Plugin plugin = window.getOwner();
63             f.addInternalFrameListener(new InternalFrameAdapter JavaDoc() {
64                 public void internalFrameClosing(InternalFrameEvent JavaDoc e) {
65                     plugin.exit();
66                 }
67             });
68         }
69         
70         //WidgetState.restore(window.getOwner().getLocalConfig(), f);
71
windows.put(window, f);
72         
73         Iterator JavaDoc listeners = window.getWindowListeners();
74         //while(listeners.hasNext())
75
// f.addWindowListener((WindowListener)listeners.next());
76

77         SwingUtilities.invokeLater(new Runnable JavaDoc() {
78             public void run() {
79                 f.show();
80             }
81         });
82         
83         desktop.add(f);
84         container.show();
85     }
86     
87     public void hide(ManagedWindow window)
88     {
89         final JInternalFrame f = (JInternalFrame)windows.get(window);
90         SwingUtilities.invokeLater(new Runnable JavaDoc() {
91             public void run() {
92                 f.setVisible(false);
93             }
94         });
95     }
96     
97     public boolean isVisible(ManagedWindow window)
98     {
99         JInternalFrame f = (JInternalFrame)windows.get(window);
100         return f.isVisible();
101     }
102     
103     public void dispose(ManagedWindow window)
104     {
105         JInternalFrame f = (JInternalFrame)windows.get(window);
106         //WidgetState.save(window.getOwner().getLocalConfig(), f);
107
f.dispose();
108         
109         if(window.mustExitPluginOnClose())
110             window.getOwner().exit();
111     }
112     
113     public Iterator JavaDoc getAllWindows()
114     {
115         return windows.keySet().iterator();
116     }
117     
118     public Iterator JavaDoc getWindowsFor(Plugin plugin)
119     {
120         //TODO code this
121
return getAllWindows();
122     }
123
124     public void propertyChange(PropertyChangeEvent JavaDoc pce)
125     {
126         //TODO handle these events
127
}
128 }
Popular Tags