001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package jsx.ui.layout;
021 
022 import js.ArrayLike;
023 import js.Js;
024 import js.ObjectLike;
025 import jsx.core.ArrayLikes;
026 import jsx.ui.Component;
027 import jsx.ui.Container;
028 import jsx.ui.Widget;
029 
030 /**
031  * <p>Layouts children of a container in a flow.</p>
032  * <p>Note, A {@link FlowLayout} layout is composed of {@link BarLayout} layouts 
033  * although a {@link BarLayout} is also a {@link FlowLayout}.</p>
034  * 
035  * @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>
036  */
037 public class AbsoluteLayout extends Container.Layout
038 {
039     /**
040      * <p>The default constructor that constructs a layout manager of this type.</p>
041      * <p>This constructor invokes the default constructor of the superclass.</p>
042      * @since 1.0
043      * @see #AbsoluteLayout(ObjectLike)
044      */
045     public AbsoluteLayout() {
046     }
047 
048     /**
049      * <p>A typical constructor that constructs a layout manager of this type and forces 
050      * constructors of subclasses to pass initializing data.</p>
051      * <p>This constructor invokes the typical constructor of the superclass passing 
052      * the specified initializing object as the argument.</p>
053      * @param ini The initializing object.
054      * @since 1.0
055      * @see #AbsoluteLayout()
056      */
057     public AbsoluteLayout(ObjectLike ini) {
058         super(ini);
059     }
060 
061     /**
062      * <p>Lays out a container absolutely.</p>
063      * <p>This method lays out the children of a container in absolute positioning.</p>
064      * @param c The container to layout.
065      * @since 1.0
066      */
067     @Override
068     protected void doLayout(Container c) {
069         layout(c);
070     }
071 
072     /**
073      * <p>Lays out a container absolutely.</p>
074      * <p>This method lays out the children of a container in absolute positioning.</p>
075      * @param ct The container to layout.
076      * @since 1.0
077      */
078     public static final void layout(Container ct) {
079         ct.detach();
080         Component c = ct.unwrap();
081         ArrayLike<Widget> children = ini(ct).var(Container.CHILDREN);
082         for (int i = 0, len = ArrayLikes.length(children); i < len; i++) {
083             Widget w = children.get(i);
084             if (Js.be(w)) {
085                 Component.absolute(w.unwrap());
086                 Component.appendChild(c, w.unwrap());
087             }
088         }
089     }
090 
091     /**
092      * <p>Layouts a container when notified it has been resized.</p>
093      * <p>This method does nothing. A subclass should override this method to 
094      * perform an action if necessary.</p>
095      * @param c The container to layout on resizing.
096      * @since 1.0
097      */
098     @Override
099     protected void onResize(Container c) {
100     }
101 }