View Javadoc

1   /**********************************************
2    * Copyright (C) 2010 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.gxt.layout;
19  
20  import com.extjs.gxt.ui.client.core.El;
21  import com.extjs.gxt.ui.client.util.Point;
22  import com.extjs.gxt.ui.client.util.Size;
23  import com.extjs.gxt.ui.client.widget.Component;
24  import com.extjs.gxt.ui.client.widget.Container;
25  import com.extjs.gxt.ui.client.widget.layout.FitLayout;
26  import com.google.gwt.core.client.GWT;
27  import com.google.gwt.dom.client.Element;
28  import com.google.gwt.dom.client.Style.Position;
29  import com.google.gwt.dom.client.Style.Unit;
30  
31  /**
32   * GXT layout class to implement a multilayer layout based
33   * on several CSS absolutely positionned divs with different
34   * z-indices.
35   * @author laaglu
36   */
37  public class AbsoluteLayerLayout extends FitLayout {
38  	protected void onLayout(Container<?> container, El target) {
39  		super.onLayout(container, target);
40  		// Retrieve the first parent with absolute layout (it
41  		// ought to be the Window)
42  		Element elt = container.getElement();
43  		Point p = target.getOffsetsTo((com.google.gwt.user.client.Element)elt.cast());
44  		GWT.log("p = " + p.toString());
45  		Size windowSize = El.fly(elt).getStyleSize();
46  		for (int i = 0, count = container.getItemCount(); i < count; i++) {
47  			Component c = container.getItem(i);
48  			Size containerSize = target.getStyleSize();
49  			containerSize.width -= getSideMargins(c);
50  			containerSize.height -= c.el().getMargins("tb");
51  			c.getElement().getStyle().setPosition(Position.ABSOLUTE);
52  			AbsoluteLayerLayoutData data = (AbsoluteLayerLayoutData) c.getData("layoutData");
53  			int horizontalOffset = data.getHorizontalOffset();
54  			if (data.isAttachedLeft()) {
55  				c.getElement().getStyle().setLeft(p.x + horizontalOffset, Unit.PX);
56  			} else {
57  				c.getElement().getStyle().setRight(windowSize.width - containerSize.width - p.x + horizontalOffset, Unit.PX);
58  			}
59  			int verticalOffset = data.getVerticalOffset();
60  			if (data.isAttachedTop()) {
61  				c.getElement().getStyle().setTop(p.y + verticalOffset, Unit.PX);
62  			} else {
63  				c.getElement().getStyle().setBottom(windowSize.height - containerSize.height - p.y + verticalOffset, Unit.PX);
64  			}
65  			if (c.isRendered()) {
66  				setSize(c, 
67  						data.getWidth() > 0 ? data.getWidth() : containerSize.width, 
68  						data.getHeight() > 0 ? data.getHeight() : containerSize.height);
69  			}
70  			c.getElement().getStyle().setZIndex(data.getZIndex());
71  		}
72  	}
73  }
74