2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / javax / swing / JRootPane.java
blobccab07c13b1290400defa94043e2bc3fa7226c23
1 /* JRootPane.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing;
41 import java.awt.BorderLayout;
42 import java.awt.Component;
43 import java.awt.Container;
44 import java.awt.Dimension;
45 import java.awt.LayoutManager;
46 import java.awt.LayoutManager2;
47 import java.io.Serializable;
48 import javax.accessibility.Accessible;
49 import javax.accessibility.AccessibleComponent;
51 /**
52 * This class is where JComponents are added to.
53 * Unlike awt where you could just say frame.add(),
54 * with swing you need to say frame.getRootPane()
55 * (which delivers an instance of this class)
56 * and add your components to that.
58 * It is implemented by several 'layers' (pane() should be read as plane())
59 * each on top of the others
60 * where you can add components to.
61 * (getContentPane(), getGlassPane(), getLayeredPane())
63 * @author Ronald Veldema (rveldema@cs.vu.nl)
65 public class JRootPane extends JComponent
67 // The class used to obtain the accessible role for this object.
68 static protected class AccessibleJRootPane
72 //A custom layout manager
73 static protected class RootLayout extends BorderLayout
75 public Dimension preferredLayoutSize ( Container c )
77 Dimension p = super.preferredLayoutSize(c);
78 System.out.println(" PREF-SIZE from RootLayout = " + p);
79 return p;
83 /***********************************************************/
86 //The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such.
87 protected Component glassPane;
89 //The layered pane that manages the menu bar and content pane.
90 protected JLayeredPane layeredPane;
92 // The menu bar.
93 protected JMenuBar menuBar;
95 protected Container contentPane;
97 /********************************************************/
99 public String getUIClassID()
100 { return "JPanel"; }
103 void setJMenuBar(JMenuBar m)
104 { menuBar = m; }
106 JMenuBar getJMenuBar()
107 { return menuBar; }
110 public Container getContentPane()
112 if (contentPane == null)
114 setContentPane(createContentPane());
116 return contentPane;
119 public void setContentPane(Container p)
121 contentPane = p;
122 getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
125 protected void addImpl(Component comp,
126 Object constraints,
127 int index)
129 super.addImpl(comp, constraints, index);
130 //System.out.println("don't do that !");
133 public Component getGlassPane()
135 if (glassPane == null)
136 setGlassPane(createGlassPane());
137 return glassPane;
140 public void setGlassPane(Component f)
142 if (glassPane != null)
143 remove(glassPane);
145 glassPane = f;
147 glassPane.setVisible(false);
148 add(glassPane, 0);
151 public JLayeredPane getLayeredPane()
153 if (layeredPane == null)
154 setLayeredPane(createLayeredPane());
155 return layeredPane;
157 public void setLayeredPane(JLayeredPane f)
159 if (layeredPane != null)
160 remove(layeredPane);
162 layeredPane = f;
163 add(f, -1);
167 /********************************************************/
169 JRootPane()
171 setLayout(createRootLayout());
173 getGlassPane();
174 getLayeredPane();
175 getContentPane();
177 setDoubleBuffered(true);
178 updateUI();
181 protected LayoutManager createRootLayout() {
182 return new RootLayout();
185 JComponent createContentPane()
187 JPanel p = new JPanel();
188 p.setName(this.getName()+".contentPane");
189 p.setLayout(new BorderLayout());
190 // p.setVisible(true);
192 System.out.println("Created ContentPane: " + p);
193 return p;
196 Component createGlassPane()
198 JPanel p = new JPanel();
199 p.setName(this.getName()+".glassPane");
200 p.setLayout(new BorderLayout());
201 p.setVisible(false);
203 System.out.println("created the glasspane: "+p);
204 return p;
207 JLayeredPane createLayeredPane()
209 JLayeredPane l = new JLayeredPane();
210 return l;