diff --git a/src/main/java/org/gcube/portlets/user/td/client/PortalViewport.java b/src/main/java/org/gcube/portlets/user/td/client/PortalViewport.java new file mode 100644 index 0000000..5bcc2cb --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/client/PortalViewport.java @@ -0,0 +1,118 @@ +/** + * + */ +package org.gcube.portlets.user.td.client; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.core.client.GWT; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.client.Window; +import com.sencha.gxt.core.client.dom.XDOM; +import com.sencha.gxt.widget.core.client.container.SimpleContainer; +import com.sencha.gxt.widget.core.client.container.Viewport.ViewportAppearance; + +/** + * @author "Federico De Faveri defaveri@isti.cnr.it" + * + */ +public class PortalViewport extends SimpleContainer { + + protected int rightScrollBarSize = 17; + + protected boolean enableScroll; + + /** + * Creates a viewport layout container with the default appearance. + */ + public PortalViewport() { + this(GWT. create(ViewportAppearance.class)); + } + + /** + * Creates a viewport layout container with the specified appearance. + * + * @param appearance the appearance of the viewport layout container + */ + public PortalViewport(ViewportAppearance appearance) { + super(true); + SafeHtmlBuilder sb = new SafeHtmlBuilder(); + appearance.render(sb); + setElement(XDOM.create(sb.toSafeHtml())); + monitorWindowResize = true; + getFocusSupport().setIgnore(false); + resize(); + } + + /** + * Returns true if window scrolling is enabled. + * + * @return true if window scrolling is enabled + */ + public boolean getEnableScroll() { + return enableScroll; + } + + /** + * Sets whether window scrolling is enabled. + * + * @param enableScroll true to enable window scrolling + */ + public void setEnableScroll(boolean enableScroll) { + this.enableScroll = enableScroll; + Window.enableScrolling(enableScroll); + } + + /** + * @return the rightScrollBarSize + */ + public int getRightScrollBarSize() { + return rightScrollBarSize; + } + + /** + * @param rightScrollBarSize the rightScrollBarSize to set + */ + public void setRightScrollBarSize(int rightScrollBarSize) { + this.rightScrollBarSize = rightScrollBarSize; + } + + @Override + protected void onAttach() { + setEnableScroll(enableScroll); + resize(); + super.onAttach(); + } + + protected void resize() + { + int viewWidth = calculateWidth() - rightScrollBarSize; + int viewHeight = calculateHeight(); + Log.trace("resize viewWidth: "+viewWidth+" viewHeight: "+viewHeight+" clientWidth: "+Window.getClientWidth()+" clientHeight: "+Window.getClientHeight()); + setPixelSize(viewWidth, viewHeight); + } + + + /** + * {@inheritDoc} + */ + @Override + protected void onWindowResize(int width, int height) { + int viewWidth = calculateWidth(); + int viewHeight = calculateHeight(); + Log.trace("onWindowResize viewWidth: "+viewWidth+" viewHeight: "+viewHeight+" clientWidth: "+Window.getClientWidth()+" clientHeight: "+Window.getClientHeight()); + setPixelSize(viewWidth, viewHeight); + } + + protected int calculateWidth() + { + int leftBorder = getAbsoluteLeft(); + return Window.getClientWidth() - 2 * leftBorder; + } + + protected int calculateHeight() + { + int topBorder = getAbsoluteTop(); + return Window.getClientHeight() - topBorder - 34; + } + +}