KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > JInternalFrame


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: JInternalFrame.java,v $
11    Revision 1.28 2004/05/05 13:24:32 bobintetley
12    Bugfixes and Laurent's patch for binary compatibility on Container.add()
13
14    Revision 1.27 2004/05/05 12:43:21 bobintetley
15    Patches/new files from Laurent Martell
16
17    Revision 1.26 2004/04/28 08:38:11 bobintetley
18    Hierarchy fixes, code cleanup for base classes, additional javadocs and use of flag to identify JComponent descendants with peers
19
20    Revision 1.25 2004/04/27 06:37:44 bobintetley
21    Corrected hierarchy with JComponent descending Container
22
23    Revision 1.24 2004/03/30 10:42:46 bobintetley
24    Many minor bug fixes, event improvements by Dan Naab. Full swing.Icon support
25
26    Revision 1.23 2004/03/22 15:10:22 bobintetley
27    JRootPane and JLayeredPane implementation
28
29    Revision 1.22 2004/03/12 11:05:24 bobintetley
30    Fixed memory leak in container destruction
31
32    Revision 1.21 2004/03/04 15:32:28 bobintetley
33    JInternalFrame methods now modify their peers after creation
34
35    Revision 1.20 2004/02/24 09:51:35 bobintetley
36    Better contentPane support
37
38    Revision 1.19 2004/01/26 08:11:00 bobintetley
39    Many bugfixes and addition of SwingSet
40
41    Revision 1.18 2004/01/16 15:53:32 bobintetley
42    Many compatibility methods added to Container, Component, JInternalFrame,
43       UIManager, SwingUtilities, JTabbedPane, JPasswordField, JCheckBox
44       and JRadioButton.
45
46    Revision 1.17 2004/01/15 15:20:30 bobintetley
47    Java2D work
48
49    Revision 1.16 2004/01/05 07:58:50 bobintetley
50    Broken in previous commit
51
52    Revision 1.14 2003/12/22 11:10:28 bobintetley
53    Multiple JInternalFrame dispose fixed
54
55    Revision 1.13 2003/12/16 13:59:27 bobintetley
56    Frames now dispose themselves correctly when closed
57
58    Revision 1.12 2003/12/16 11:01:02 bobintetley
59    Additional Swing compatibility
60
61    Revision 1.11 2003/12/15 18:29:57 bobintetley
62    Changed setParent() method to setSwingWTParent() to avoid conflicts with applications
63
64    Revision 1.10 2003/12/15 15:53:32 bobintetley
65    RootPane, size, defaultButton, location and selected
66
67    Revision 1.9 2003/12/14 09:13:38 bobintetley
68    Added CVS log to source headers
69
70 */

71
72
73 package swingwtx.swing;
74
75 import swingwt.awt.*;
76 import swingwtx.swing.event.*;
77
78 import org.eclipse.swt.widgets.*;
79
80 import java.util.*;
81
82 public class JInternalFrame extends JComponent implements WindowConstants, RootPaneContainer {
83     
84     protected org.eclipse.swt.widgets.Composite ppeer = null;
85     protected Vector internalFrameListeners = new Vector();
86     protected JDesktopPane parentpane = null;
87     protected Icon pImage = null;
88     protected String JavaDoc pTitle = "";
89     protected int pCloseOperation = DISPOSE_ON_CLOSE;
90     protected JButton defaultButton = null;
91     protected boolean disposed = true;
92     protected JRootPane rootPane = null;
93     
94     public JInternalFrame() { this("", true, true, true, true); }
95     public JInternalFrame(String JavaDoc title) { this(title, true, true, true, true); }
96     public JInternalFrame(String JavaDoc title, boolean resizable) { this(title, resizable, true, true, true); }
97     public JInternalFrame(String JavaDoc title, boolean resizable, boolean closable) { this(title, resizable, closable, true, true); }
98     public JInternalFrame(String JavaDoc title, boolean resizable, boolean closable, boolean maximizable) { this(title, resizable, closable, maximizable, true); }
99     
100     public JInternalFrame(String JavaDoc title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) {
101         
102         setTitle(title);
103         
104         // Create our rootpane and set it
105
setLayoutImpl(new FillLayout());
106         rootPane = new JRootPane();
107         doAdd(rootPane);
108     }
109     
110     /** Overridden to point to getContentPane() rather than throwing an error */
111     public Component add(swingwt.awt.Component c) { rootPane.getContentPane().add(c); return c; }
112     /** Overridden to point to getContentPane() rather than throwing an error */
113     public void add(swingwt.awt.Component c, Object JavaDoc layoutModifier) { rootPane.getContentPane().add(c, layoutModifier); }
114     /** Overridden to point to getContentPane() rather than throwing an error */
115     public void remove(swingwt.awt.Component c) { rootPane.getContentPane().remove(c); }
116     /** Overridden to point to getContentPane() rather than throwing an error */
117     public LayoutManager getLayout() {
118         return rootPane.getContentPane().getLayout();
119     }
120     /** Overridden to point to getContentPane() rather than throwing an error */
121     public void setLayout(LayoutManager l) {
122         rootPane.getContentPane().setLayout(l);
123     }
124     /** Overridden to point to getContentPane() rather than throwing an error */
125     public void setLayout(LayoutManager2 l) {
126         rootPane.getContentPane().setLayout(l);
127     }
128     
129     public void dispose() {
130         if (!disposed) {
131             // Destroy the container
132
super.dispose();
133             // Destroy the tab
134
parentpane.removeFrame(this);
135             processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
136             disposed = true;
137         }
138     }
139     
140     public void addInternalFrameListener(InternalFrameListener l) { internalFrameListeners.add(l); }
141     public int getDefaultCloseOperation() { return pCloseOperation; }
142     public void setDefaultCloseOperation(int operation) { pCloseOperation = operation; }
143     public JDesktopPane getJDesktopPane() { return parentpane; }
144     public Icon getFrameIcon() { return pImage; }
145     public void setFrameIcon(Icon icon) { pImage = icon; refreshFrame(); }
146     public String JavaDoc getTitle() { return pTitle; }
147     public void setTitle(String JavaDoc title) { pTitle = title; refreshFrame(); }
148     public Control getPeer() { return ppeer; }
149     public void show() { }
150     public void hide() { }
151     public void pack() { if (ppeer != null) ppeer.pack(); }
152     protected void setParentPane(JDesktopPane jdp) { parentpane = jdp; }
153     public boolean isClosable() { return false; }
154     public boolean isResizable() { return false; }
155     public boolean isMaximizable() { return true; }
156     public boolean isIconifiable() { return false; }
157     public boolean isMaximum() { return true; }
158     public void setClosed(boolean b) { if (b) dispose(); }
159     public void setClosable(boolean b) {}
160     public void setResizable(boolean b) {}
161     public void setMaximizable(boolean b) {}
162     public void setIconifiable(boolean b) {}
163     public void setMaximum(boolean b) {}
164     public void setIcon(boolean b) { try { setSelected(false); } catch (java.beans.PropertyVetoException JavaDoc e) {}}
165     public void toFront() { try { setSelected(true); } catch (java.beans.PropertyVetoException JavaDoc e) {} }
166     public void toBack() {try { setSelected(false); } catch (java.beans.PropertyVetoException JavaDoc e) {}}
167     
168     /**
169      * Finds the component representing this JInternalFrame
170      * and updates all it's properties based on what we have stored
171      * here. Just delegates the job to the desktop pane
172      */

173     protected void refreshFrame() {
174         if (parentpane != null) parentpane.refreshFrame(this);
175     }
176     
177     public Dimension getSize() {
178         if (ppeer == null)
179             return new Dimension(0, 0);
180         else
181             return new Dimension(ppeer.getBounds().width, ppeer.getBounds().height);
182     }
183     public void setSize(Dimension d) { }
184     public void setSize(int width, int height) { }
185     public void setLocation(int x, int y) {}
186     public boolean isSelected() { if (parentpane != null) return (parentpane.getSelectedFrame() == this); else return false; }
187     public void setSelected(boolean b) throws java.beans.PropertyVetoException JavaDoc {
188         if (parentpane != null) if (b) parentpane.setSelectedFrame(this);
189     }
190     
191     public void registerEvents() {
192         super.registerEvents();
193     }
194     
195     /**
196      * Called when the user has closed the window -
197      * returns true if the user is allowed to close it
198      */

199     protected boolean processFrameClosing() {
200         processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
201         try {
202             switch (pCloseOperation) {
203                 case DO_NOTHING_ON_CLOSE: return false;
204                 case DISPOSE_ON_CLOSE: if (!disposed) dispose(); return true;
205                 case EXIT_ON_CLOSE: if (!disposed) dispose(); return true;
206                 case HIDE_ON_CLOSE: if (!disposed) dispose(); return true;
207                 default:
208                     return true;
209             }
210         }
211         finally {
212             // Make sure we fire the closed event
213
processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
214         }
215     }
216     
217     public Container getContentPane() {
218         return rootPane.getContentPane();
219     }
220     
221     public Component getGlassPane() {
222         return rootPane.getGlassPane();
223     }
224     
225     public JLayeredPane getLayeredPane() {
226         return rootPane.getLayeredPane();
227     }
228     
229     public JRootPane getRootPane() {
230         return rootPane;
231     }
232     
233     public void setContentPane(Container contentPane) {
234         rootPane.setContentPane(contentPane);
235     }
236     
237     public void setGlassPane(Component glassPane) {
238         rootPane.setGlassPane(glassPane);
239     }
240     
241     public void setLayeredPane(JLayeredPane layeredPane) {
242         rootPane.setLayeredPane(layeredPane);
243     }
244     
245     public void setJMenuBar(JMenuBar menu) {
246         rootPane.setJMenuBar(menu);
247     }
248     
249     public JMenuBar getJMenuBar() {
250         return rootPane.getJMenuBar();
251     }
252     
253     public void setMenuBar(MenuBar menu) {
254         rootPane.setMenuBar(menu);
255     }
256     
257     public MenuBar getMenuBar() {
258         return rootPane.getMenuBar();
259     }
260     
261     public void setDefaultButton(JButton button) {
262         rootPane.setDefaultButton(button);
263     }
264     
265     public JButton getDefaultButton() {
266         return rootPane.getDefaultButton();
267     }
268     
269     /** Allows firing of internal frame events */
270     public void processInternalFrameEvent(int eventID) {
271         InternalFrameEvent e = new InternalFrameEvent(this, eventID);
272         Iterator i = internalFrameListeners.iterator();
273         while (i.hasNext()) {
274             InternalFrameListener l = (InternalFrameListener) i.next();
275             switch (eventID) {
276                 case (InternalFrameEvent.INTERNAL_FRAME_ACTIVATED): l.internalFrameActivated(e); break;
277                 case (InternalFrameEvent.INTERNAL_FRAME_CLOSED): l.internalFrameClosed(e); break;
278                 case (InternalFrameEvent.INTERNAL_FRAME_CLOSING): l.internalFrameClosing(e); break;
279                 case (InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED): l.internalFrameDeactivated(e); break;
280                 case (InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED): l.internalFrameDeiconified(e); break;
281                 case (InternalFrameEvent.INTERNAL_FRAME_ICONIFIED): l.internalFrameDeiconified(e); break;
282                 case (InternalFrameEvent.INTERNAL_FRAME_OPENED): l.internalFrameOpened(e); break;
283             }
284         }
285     }
286     
287     public void setSwingWTParent(Container parent) throws Exception JavaDoc {
288         descendantHasPeer = true;
289         disposed = false;
290         ppeer = new org.eclipse.swt.widgets.Composite(parent.getComposite(), 0);
291         peer = ppeer;
292         composite = ppeer;
293         this.parent = parent;
294         super.setSwingWTParent(parent);
295         processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
296     }
297     
298 }
299
Popular Tags