1 | /* JRootPane.java --
|
---|
2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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.
|
---|
20 |
|
---|
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.
|
---|
25 |
|
---|
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. */
|
---|
37 |
|
---|
38 | package javax.swing;
|
---|
39 |
|
---|
40 | import java.awt.*;
|
---|
41 | import java.awt.event.*;
|
---|
42 |
|
---|
43 | import javax.accessibility.AccessibleContext;
|
---|
44 | import javax.accessibility.AccessibleRole;
|
---|
45 | import javax.accessibility.AccessibleState;
|
---|
46 | import javax.accessibility.AccessibleStateSet;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * This class is where JComponents are added to.
|
---|
50 | * Unlike awt where you could just say frame.add(),
|
---|
51 | * with swing you need to say frame.getRootPane()
|
---|
52 | * (which delivers an instance of this class)
|
---|
53 | * and add your components to that.
|
---|
54 | *
|
---|
55 | * It is implemented by several 'layers' (pane() should be read as plane())
|
---|
56 | * each on top of the others
|
---|
57 | * where you can add components to.
|
---|
58 | * (getContentPane(), getGlassPane(), getLayeredPane())
|
---|
59 | *
|
---|
60 | * @author Ronald Veldema (rveldema@cs.vu.nl)
|
---|
61 | */
|
---|
62 | public class JRootPane extends JComponent
|
---|
63 | {
|
---|
64 | // The class used to obtain the accessible role for this object.
|
---|
65 | static protected class AccessibleJRootPane
|
---|
66 | {
|
---|
67 | }
|
---|
68 |
|
---|
69 | //A custom layout manager
|
---|
70 | static protected class RootLayout extends BorderLayout
|
---|
71 | {
|
---|
72 | public Dimension preferredLayoutSize ( Container c )
|
---|
73 | {
|
---|
74 | Dimension p = super.preferredLayoutSize(c);
|
---|
75 | System.out.println(" PREF-SIZE from RootLayout = " + p);
|
---|
76 | return p;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | /***********************************************************/
|
---|
81 |
|
---|
82 |
|
---|
83 | //The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such.
|
---|
84 | protected Component glassPane;
|
---|
85 |
|
---|
86 | //The layered pane that manages the menu bar and content pane.
|
---|
87 | protected JLayeredPane layeredPane;
|
---|
88 |
|
---|
89 | // The menu bar.
|
---|
90 | protected JMenuBar menuBar;
|
---|
91 |
|
---|
92 | protected Container contentPane;
|
---|
93 |
|
---|
94 | /********************************************************/
|
---|
95 |
|
---|
96 | public String getUIClassID()
|
---|
97 | { return "JPanel"; }
|
---|
98 |
|
---|
99 |
|
---|
100 | void setJMenuBar(JMenuBar m)
|
---|
101 | { menuBar = m; }
|
---|
102 |
|
---|
103 | JMenuBar getJMenuBar()
|
---|
104 | { return menuBar; }
|
---|
105 |
|
---|
106 |
|
---|
107 | public Container getContentPane()
|
---|
108 | {
|
---|
109 | if (contentPane == null)
|
---|
110 | {
|
---|
111 | setContentPane(createContentPane());
|
---|
112 | }
|
---|
113 | return contentPane;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public void setContentPane(Container p)
|
---|
117 | {
|
---|
118 | contentPane = p;
|
---|
119 | getLayeredPane().add(contentPane, 0);
|
---|
120 | }
|
---|
121 |
|
---|
122 | protected void addImpl(Component comp,
|
---|
123 | Object constraints,
|
---|
124 | int index)
|
---|
125 | {
|
---|
126 | super.addImpl(comp, constraints, index);
|
---|
127 | //System.out.println("don't do that !");
|
---|
128 | }
|
---|
129 |
|
---|
130 | public Component getGlassPane()
|
---|
131 | {
|
---|
132 | if (glassPane == null)
|
---|
133 | setGlassPane(createGlassPane());
|
---|
134 | return glassPane;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public void setGlassPane(Component f)
|
---|
138 | {
|
---|
139 | if (glassPane != null)
|
---|
140 | remove(glassPane);
|
---|
141 |
|
---|
142 | glassPane = f;
|
---|
143 |
|
---|
144 | glassPane.setVisible(false);
|
---|
145 | add(glassPane, 0);
|
---|
146 | }
|
---|
147 |
|
---|
148 | public JLayeredPane getLayeredPane()
|
---|
149 | {
|
---|
150 | if (layeredPane == null)
|
---|
151 | setLayeredPane(createLayeredPane());
|
---|
152 | return layeredPane;
|
---|
153 | }
|
---|
154 | public void setLayeredPane(JLayeredPane f)
|
---|
155 | {
|
---|
156 | if (layeredPane != null)
|
---|
157 | remove(layeredPane);
|
---|
158 |
|
---|
159 | layeredPane = f;
|
---|
160 | add(f, -1);
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | /********************************************************/
|
---|
165 |
|
---|
166 | JRootPane()
|
---|
167 | {
|
---|
168 | setLayout(createRootLayout());
|
---|
169 |
|
---|
170 | getGlassPane();
|
---|
171 | getLayeredPane();
|
---|
172 | getContentPane();
|
---|
173 |
|
---|
174 | setDoubleBuffered(true);
|
---|
175 | updateUI();
|
---|
176 | }
|
---|
177 |
|
---|
178 | protected LayoutManager createRootLayout() {
|
---|
179 | return new RootLayout();
|
---|
180 | }
|
---|
181 |
|
---|
182 | JComponent createContentPane()
|
---|
183 | {
|
---|
184 | JPanel p = new JPanel();
|
---|
185 | p.setName(this.getName()+".contentPane");
|
---|
186 | p.setLayout(new BorderLayout());
|
---|
187 | // p.setVisible(true);
|
---|
188 |
|
---|
189 | System.out.println("Created ContentPane: " + p);
|
---|
190 | return p;
|
---|
191 | }
|
---|
192 |
|
---|
193 | Component createGlassPane()
|
---|
194 | {
|
---|
195 | JPanel p = new JPanel();
|
---|
196 | p.setName(this.getName()+".glassPane");
|
---|
197 | p.setLayout(new BorderLayout());
|
---|
198 | p.setVisible(false);
|
---|
199 |
|
---|
200 | System.out.println("created the glasspane: "+p);
|
---|
201 | return p;
|
---|
202 | }
|
---|
203 |
|
---|
204 | JLayeredPane createLayeredPane()
|
---|
205 | {
|
---|
206 | JLayeredPane l = new JLayeredPane();
|
---|
207 | return l;
|
---|
208 | }
|
---|
209 | }
|
---|