01 
02 /*
03  *  JScripter Standard 1.0 - To Script In Java
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package jsx.ui.layout;
21 
22 import js.ArrayLike;
23 import js.Initializer;
24 import js.Js;
25 import js.ObjectLike;
26 import jsx.core.ArrayLikes;
27 import jsx.ui.Container;
28 import jsx.ui.Widget;
29 
30 /**
31  * <p>Fits the last child of a container.</p>
32  * 
33  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
34  */
35 public final class CardLayout extends AbsoluteLayout
36 {
37     /**
38      * <p>The default constructor that constructs a layout manager of this type.</p>
39      * <p>This constructor invokes the default constructor of the superclass.</p>
40      * @since 1.0
41      * @see #CardLayout(ObjectLike)
42      */
43     public CardLayout() {
44     }
45 
46     /**
47      * <p>A typical constructor that constructs a layout manager of this type and forces 
48      * constructors of subclasses to pass initializing data.</p>
49      * <p>This constructor invokes the typical constructor of the superclass passing 
50      * the specified initializing object as the argument.</p>
51      * @param ini The initializing object.
52      * @since 1.0
53      * @see #CardLayout()
54      */
55     public CardLayout(ObjectLike ini) {
56         super(ini);
57     }
58 
59     /**
60      * <p>Layouts a container.</p>
61      * <p>This method fits the last child of the container it is laying out 
62      * and ignores the rest of the children the container may have.</p>
63      * @param c The container to layout.
64      * @since 1.0
65      */
66     @Override
67     protected void doLayout(Container c) {
68         c.detach();
69         ArrayLike<Widget> children = ini(c).var(Container.CHILDREN);
70         Container n = new Container(c.unwrap());
71         Widget w = ArrayLikes.getLast(children);
72         if (Js.be(w)) {
73             n.setLayout(new BarLayout(new Initializer().set(
74                     BarLayout.ALIGN, true
75             ).set(
76                     BarLayout.FIT, true
77             ).var()));
78             n.add(new Widget(w.unwrap()));
79         }
80     }
81 }