Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / JRootPane.java
blobdea4ee4b195afb6ea63465c1f07db1bb17ee2c1c
1 /* JRootPane.java --
2 Copyright (C) 2002, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 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.IllegalComponentStateException;
46 import java.awt.Insets;
47 import java.awt.LayoutManager;
48 import java.awt.LayoutManager2;
49 import java.awt.Rectangle;
50 import java.io.Serializable;
52 import javax.accessibility.Accessible;
53 import javax.accessibility.AccessibleRole;
54 import javax.swing.plaf.RootPaneUI;
56 /**
57 * This class is where JComponents are added to. Unlike awt where you could
58 * just say frame.add(), with swing you need to say frame.getRootPane()
59 * (which delivers an instance of this class) and add your components to
60 * that. It is implemented by several 'layers' (pane() should be read as
61 * plane()) each on top of the others where you can add components to.
62 * (getContentPane(), getGlassPane(), getLayeredPane())
64 * @author Ronald Veldema (rveldema@cs.vu.nl)
66 public class JRootPane extends JComponent implements Accessible
68 // The class used to obtain the accessible role for this object.
69 protected class AccessibleJRootPane extends AccessibleJComponent
71 /**
72 * For compatability with Sun's JDK
74 private static final long serialVersionUID = 1082432482784468088L;
76 /**
77 * Creates a new <code>AccessibleJRootPane</code> object.
79 protected AccessibleJRootPane()
81 // Nothing to do here.
84 /**
85 * DOCUMENT ME!
87 * @return DOCUMENT ME!
89 public AccessibleRole getAccessibleRole()
91 return AccessibleRole.ROOT_PANE;
95 // Custom Layout Manager for JRootPane. It positions contentPane and
96 // menuBar withing its layeredPane.
97 protected class RootLayout implements LayoutManager2, Serializable
99 /** DOCUMENT ME! */
100 private static final long serialVersionUID = -4100116998559815027L;
103 * The cached layout info for the glass pane.
105 private Rectangle glassPaneBounds;
108 * The cached layout info for the layered pane.
110 private Rectangle layeredPaneBounds;
113 * The cached layout info for the content pane.
115 private Rectangle contentPaneBounds;
118 * The cached layout info for the menu bar.
120 private Rectangle menuBarBounds;
123 * The cached preferred size.
125 private Dimension prefSize;
128 * Creates a new <code>RootLayout</code> object.
130 protected RootLayout()
132 // Nothing to do here.
136 * DOCUMENT ME!
138 * @param comp DOCUMENT ME!
139 * @param constraints DOCUMENT ME!
141 public void addLayoutComponent(Component comp, Object constraints)
143 // Nothing to do here.
147 * DOCUMENT ME!
149 * @param name DOCUMENT ME!
150 * @param comp DOCUMENT ME!
152 public void addLayoutComponent(String name, Component comp)
154 // Nothing to do here.
158 * DOCUMENT ME!
160 * @param target DOCUMENT ME!
162 * @return DOCUMENT ME!
164 public float getLayoutAlignmentX(Container target)
166 return 0.0F;
170 * DOCUMENT ME!
172 * @param target DOCUMENT ME!
174 * @return DOCUMENT ME!
176 public float getLayoutAlignmentY(Container target)
178 return 0.0F;
182 * DOCUMENT ME!
184 * @param target DOCUMENT ME!
186 public void invalidateLayout(Container target)
188 synchronized (this)
190 glassPaneBounds = null;
191 layeredPaneBounds = null;
192 contentPaneBounds = null;
193 menuBarBounds = null;
194 prefSize = null;
199 * DOCUMENT ME!
201 * @param c DOCUMENT ME!
203 public void layoutContainer(Container c)
205 if (glassPaneBounds == null || layeredPaneBounds == null
206 || contentPaneBounds == null || menuBarBounds == null)
208 Insets i = getInsets();
209 int containerWidth = c.getBounds().width - i.left - i.right;
210 int containerHeight = c.getBounds().height - i.top - i.bottom;
212 // 1. the glassPane fills entire viewable region (bounds - insets).
213 // 2. the layeredPane filles entire viewable region.
214 // 3. the menuBar is positioned at the upper edge of layeredPane.
215 // 4. the contentPane fills viewable region minus menuBar, if present.
218 // +-------------------------------+
219 // | JLayeredPane |
220 // | +--------------------------+ |
221 // | | menuBar | |
222 // | +--------------------------+ |
223 // | +--------------------------+ |
224 // | |contentPane | |
225 // | | | |
226 // | | | |
227 // | | | |
228 // | +--------------------------+ |
229 // +-------------------------------+
231 if (menuBar != null)
233 Dimension menuBarSize = menuBar.getPreferredSize();
234 if (menuBarSize.height > containerHeight)
235 menuBarSize.height = containerHeight;
236 menuBarBounds = new Rectangle(0, 0, containerWidth,
237 menuBarSize.height);
238 contentPaneBounds = new Rectangle(0, menuBarSize.height,
239 containerWidth,
240 containerHeight - menuBarSize.height);
242 else
243 contentPaneBounds = new Rectangle(0, 0, containerWidth,
244 containerHeight);
246 glassPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
247 layeredPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
250 glassPane.setBounds(glassPaneBounds);
251 layeredPane.setBounds(layeredPaneBounds);
252 if (menuBar != null)
253 menuBar.setBounds(menuBarBounds);
254 contentPane.setBounds(contentPaneBounds);
258 * DOCUMENT ME!
260 * @param target DOCUMENT ME!
262 * @return DOCUMENT ME!
264 public Dimension maximumLayoutSize(Container target)
266 return preferredLayoutSize(target);
270 * DOCUMENT ME!
272 * @param target DOCUMENT ME!
274 * @return DOCUMENT ME!
276 public Dimension minimumLayoutSize(Container target)
278 return preferredLayoutSize(target);
282 * DOCUMENT ME!
284 * @param c DOCUMENT ME!
286 * @return DOCUMENT ME!
288 public Dimension preferredLayoutSize(Container c)
290 // We must synchronize here, otherwise we cannot guarantee that the
291 // prefSize is still non-null when returning.
292 synchronized (this)
294 if (prefSize == null)
296 Insets i = getInsets();
297 prefSize = new Dimension(i.left + i.right, i.top + i.bottom);
298 Dimension contentPrefSize = contentPane.getPreferredSize();
299 prefSize.width += contentPrefSize.width;
300 prefSize.height += contentPrefSize.height;
301 if (menuBar != null)
303 Dimension menuBarSize = menuBar.getPreferredSize();
304 if (menuBarSize.width > contentPrefSize.width)
305 prefSize.width += menuBarSize.width - contentPrefSize.width;
306 prefSize.height += menuBarSize.height;
309 // Return a copy here so the cached value won't get trashed by some
310 // other component.
311 return new Dimension(prefSize);
316 * DOCUMENT ME!
318 * @param comp DOCUMENT ME!
320 public void removeLayoutComponent(Component comp)
322 // Nothing to do here.
326 /** DOCUMENT ME! */
327 private static final long serialVersionUID = 8690748000348575668L;
329 public static final int NONE = 0;
330 public static final int FRAME = 1;
331 public static final int PLAIN_DIALOG = 2;
332 public static final int INFORMATION_DIALOG = 3;
333 public static final int ERROR_DIALOG = 4;
334 public static final int COLOR_CHOOSER_DIALOG = 5;
335 public static final int FILE_CHOOSER_DIALOG = 6;
336 public static final int QUESTION_DIALOG = 7;
337 public static final int WARNING_DIALOG = 8;
339 /** DOCUMENT ME! */
340 protected Component glassPane;
342 /** DOCUMENT ME! */
343 protected JLayeredPane layeredPane;
345 /** DOCUMENT ME! */
346 protected JMenuBar menuBar;
348 /** DOCUMENT ME! */
349 protected Container contentPane;
351 protected JButton defaultButton;
354 * This field is unused since JDK1.3. To override the default action you
355 * should modify the JRootPane's ActionMap.
357 * @deprecated since JDK1.3
359 * @specnote the specs indicate that the type of this field is
360 * a package private inner class
361 * javax.swing.JRootPane.DefaultAction. I assume that the closest
362 * public superclass is javax.swing.Action.
364 protected Action defaultPressAction;
367 * This field is unused since JDK1.3. To override the default action you
368 * should modify the JRootPane's ActionMap.
370 * @deprecated since JDK1.3
372 * @specnote the specs indicate that the type of this field is
373 * a package private inner class
374 * javax.swing.JRootPane.DefaultAction. I assume that the closest
375 * public superclass is javax.swing.Action.
377 protected Action defaultReleaseAction;
380 * @since 1.4
382 private int windowDecorationStyle = NONE;
385 * DOCUMENT ME!
387 * @param m DOCUMENT ME!
389 public void setJMenuBar(JMenuBar m)
391 JLayeredPane jlPane = getLayeredPane();
392 if (menuBar != null)
393 jlPane.remove(menuBar);
394 menuBar = m;
395 if (menuBar != null)
396 jlPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
400 * @deprecated Replaced by <code>setJMenuBar()</code>
402 public void setMenuBar(JMenuBar m)
404 setJMenuBar(m);
408 * DOCUMENT ME!
410 * @return DOCUMENT ME!
412 public JMenuBar getJMenuBar()
414 return menuBar;
418 * @deprecated Replaced by <code>getJMenuBar()</code>
420 public JMenuBar getMenuBar()
422 return getJMenuBar();
426 * DOCUMENT ME!
428 * @return DOCUMENT ME!
430 public boolean isValidateRoot()
432 return true;
436 * DOCUMENT ME!
438 * @return DOCUMENT ME!
440 public Container getContentPane()
442 if (contentPane == null)
443 setContentPane(createContentPane());
444 return contentPane;
448 * Sets the JRootPane's content pane. The content pane should typically be
449 * opaque for painting to work properly. This method also
450 * removes the old content pane from the layered pane.
452 * @param p the Container that will be the content pane
453 * @throws IllegalComponentStateException if p is null
455 public void setContentPane(Container p)
457 if (p == null)
458 throw new IllegalComponentStateException ("cannot " +
459 "have a null content pane");
460 else
462 if (contentPane != null && contentPane.getParent() == layeredPane)
463 layeredPane.remove(contentPane);
464 contentPane = p;
465 getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
470 * DOCUMENT ME!
472 * @param comp DOCUMENT ME!
473 * @param constraints DOCUMENT ME!
474 * @param index DOCUMENT ME!
476 protected void addImpl(Component comp, Object constraints, int index)
478 super.addImpl(comp, constraints, index);
482 * DOCUMENT ME!
484 * @return DOCUMENT ME!
486 public Component getGlassPane()
488 if (glassPane == null)
489 setGlassPane(createGlassPane());
490 return glassPane;
494 * DOCUMENT ME!
496 * @param f DOCUMENT ME!
498 public void setGlassPane(Component f)
500 if (glassPane != null)
501 remove(glassPane);
503 glassPane = f;
505 glassPane.setVisible(false);
506 add(glassPane, 0);
510 * DOCUMENT ME!
512 * @return DOCUMENT ME!
514 public JLayeredPane getLayeredPane()
516 if (layeredPane == null)
517 setLayeredPane(createLayeredPane());
518 return layeredPane;
522 * DOCUMENT ME!
524 * @param f DOCUMENT ME!
526 public void setLayeredPane(JLayeredPane f)
528 if (layeredPane != null)
529 remove(layeredPane);
531 layeredPane = f;
532 add(f, -1);
536 * Creates a new <code>JRootPane</code> object.
538 public JRootPane()
540 setLayout(createRootLayout());
541 getGlassPane();
542 getLayeredPane();
543 getContentPane();
544 updateUI();
548 * DOCUMENT ME!
550 * @return DOCUMENT ME!
552 protected LayoutManager createRootLayout()
554 return new RootLayout();
558 * DOCUMENT ME!
560 * @return DOCUMENT ME!
562 protected Container createContentPane()
564 JPanel p = new JPanel();
565 p.setName(this.getName() + ".contentPane");
566 p.setLayout(new BorderLayout());
567 return p;
571 * DOCUMENT ME!
573 * @return DOCUMENT ME!
575 protected Component createGlassPane()
577 JPanel p = new JPanel();
578 p.setName(this.getName() + ".glassPane");
579 p.setVisible(false);
580 p.setOpaque(false);
581 return p;
585 * DOCUMENT ME!
587 * @return DOCUMENT ME!
589 protected JLayeredPane createLayeredPane()
591 JLayeredPane l = new JLayeredPane();
592 l.setLayout(null);
593 return l;
597 * DOCUMENT ME!
599 * @return DOCUMENT ME!
601 public RootPaneUI getUI()
603 return (RootPaneUI) ui;
607 * DOCUMENT ME!
609 * @param ui DOCUMENT ME!
611 public void setUI(RootPaneUI ui)
613 super.setUI(ui);
617 * DOCUMENT ME!
619 public void updateUI()
621 setUI((RootPaneUI) UIManager.getUI(this));
625 * DOCUMENT ME!
627 * @return DOCUMENT ME!
629 public String getUIClassID()
631 return "RootPaneUI";
634 public JButton getDefaultButton()
636 return defaultButton;
639 public void setDefaultButton(JButton newButton)
641 if (defaultButton == newButton)
642 return;
644 JButton oldButton = defaultButton;
645 defaultButton = newButton;
646 firePropertyChange("defaultButton", oldButton, newButton);
650 * @since 1.4
652 public int getWindowDecorationStyle()
654 return windowDecorationStyle;
658 * @since 1.4
660 public void setWindowDecorationStyle(int style)
662 if (style != NONE
663 && style != FRAME
664 && style != INFORMATION_DIALOG
665 && style != ERROR_DIALOG
666 && style != COLOR_CHOOSER_DIALOG
667 && style != FILE_CHOOSER_DIALOG
668 && style != QUESTION_DIALOG
669 && style != WARNING_DIALOG
670 && style != PLAIN_DIALOG)
671 throw new IllegalArgumentException("invalid style");
673 int oldStyle = windowDecorationStyle;
674 windowDecorationStyle = style;
675 firePropertyChange("windowDecorationStyle", oldStyle, style);