KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SRootContainer


1 /*
2  * $Id: SRootContainer.java,v 1.13 2005/05/13 22:02:36 oliverscheck Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18
19
20 /**
21  * A root container.
22  * The classes derived from this class ({@link SFrame} and
23  * {@link SInternalFrame}) render in the content pane of this RootContainer.
24  *
25  * <p>The RootContainer has a stack of components. Ususally, the stack
26  * contains only <em>one</em> element, the content pane; this is the bottom-most
27  * component. When dialogs are added to the RootContainer, then these dialogs
28  * are stacked on top of this content pane, and only <em>this</em> dialog is
29  * visible then. This emulates the behaviour of modal dialogs in a windowing
30  * system.
31  *
32  * @author <a HREF="mailto:hengels@mercatis.de">Holger Engels</a>
33  * @author <a HREF="mailto:H.Zeller@acm.org">Henner Zeller</a>
34  * @author <a HREF="mailto:Haaf@mercatis.de">Armin Haaf</a>
35  */

36 public abstract class SRootContainer extends SContainer {
37     private final static transient Log log = LogFactory.getLog(SRootContainer.class);
38
39     /**
40      * The container for the contentPane.
41      */

42     protected final SContainer contentPane;
43
44     /**
45      * default constructor initializes the stack layout system of this
46      * SRootContainer.
47      */

48     public SRootContainer() {
49         contentPane = new SPanel();
50         super.setLayout(new SRootLayout());
51         super.addComponent(getContentPane(), null, getComponentCount());
52     }
53
54     /**
55      * Push a new dialog on top of the stack. If this RootContainer is
56      * rendered, then only this dialog is shown.
57      *
58      * @param dialog the SDialog that is to be shown on top.
59      */

60     public void pushDialog(SDialog dialog) {
61         log.debug("push dialog = " + dialog.getName());
62         super.addComponent(dialog, null, getComponentCount());
63         dialog.setFrame(this);
64         reload();
65     }
66
67     /**
68      * remove the dialog, that is on top of the stack.
69      *
70      * @return the dialog, that is popped from the stack.
71      */

72     public SDialog popDialog() {
73         int count = getComponentCount();
74         if (count <= 1)
75             throw new IllegalStateException JavaDoc("there's no dialog left!");
76
77         SDialog dialog = (SDialog) getComponent(count - 1);
78         super.remove(dialog);
79         dialog.setFrame(null);
80
81         reload();
82         log.debug("pop dialog = " + dialog.getName());
83         return dialog;
84     }
85
86     public void removeDialog(SDialog dialog) {
87         super.remove(dialog);
88         dialog.setFrame((SFrame) null);
89         reload();
90     }
91
92     /**
93      * @return the number of dialogs that are on the stack currently.
94      */

95     public int getDialogCount() {
96         return getComponentCount() - 1;
97     }
98
99     /**
100      * returns the content pane of this RootContainer.
101      */

102     public SContainer getContentPane() {
103         return contentPane;
104     }
105
106     /**
107      * Use getContentPane().addComponent(c) instead.
108      */

109     public SComponent addComponent(SComponent c, Object JavaDoc constraint, int index) {
110         throw new IllegalArgumentException JavaDoc("use getContentPane().addComponent()");
111     }
112
113     /**
114      * Use getContentPane().removeComponent(c) instead.
115      */

116     public void remove(SComponent c) {
117         throw new IllegalArgumentException JavaDoc("use getContentPane().removeComponent()");
118     }
119 }
120
Popular Tags