import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.KeyboardListenerCollection;
import com.google.gwt.user.client.ui.PopupPanel;
+import com.google.gwt.user.client.ui.ScrollListener;
+import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
*
* @author IT Mill Ltd
*/
-public class IWindow extends PopupPanel implements Paintable {
+public class IWindow extends PopupPanel implements Paintable, ScrollListener {
private static Vector windowOrder = new Vector();
private Element footer;
private Element resizeBox;
+
+ private ScrollPanel contentPanel = new ScrollPanel();
private boolean dragging;
constructDOM();
setPopupPosition(order * STACKING_OFFSET_PIXELS, order
* STACKING_OFFSET_PIXELS);
+ contentPanel.addScrollListener(this);
}
private void bringToFront() {
DOM.appendChild(wrapper, header);
DOM.appendChild(wrapper, contents);
DOM.appendChild(wrapper, footer);
- setPixelSize(400, 200);
+ setWidget(contentPanel);
+
+ // set default size
+ setWidth(400 + "px");
+ setHeight(300 + "px");
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
} else {
// Initialize the width from UIDL
- try {
+ if(uidl.hasVariable("width")) {
String width = uidl.getStringVariable("width");
- String height = uidl.getStringVariable("width");
- if (width != null && width.endsWith("px")) {
- uidlWidth = Integer.parseInt(width.substring(0, width
- .length() - 2));
- setPixelWidth(uidlWidth);
- }
- if (height != null && height.endsWith("px")) {
- uidlHeight = Integer.parseInt(height.substring(0, height
- .length() - 2));
- setPixelHeight(uidlHeight);
- }
- } catch (IllegalArgumentException e) {
- // Silently ignored as width and height are not required
- // parameters
+ setWidth(width);
+ }
+ if(uidl.hasVariable("height")) {
+ String height = uidl.getStringVariable("height");
+ setHeight(height);
}
+
+ contentPanel.setScrollPosition(
+ uidl.getIntVariable("scrolltop"));
+ contentPanel.setHorizontalScrollPosition(
+ uidl.getIntVariable("scrollleft"));
// Initialize the position form UIDL
try {
if (layout != lo) {
// remove old
client.unregisterPaintable(layout);
- this.remove((Widget) layout);
+ contentPanel.remove((Widget) layout);
// add new
- setWidget((Widget) lo);
+ contentPanel.setWidget((Widget) lo);
layout = lo;
}
} else {
- setWidget((Widget) lo);
+ contentPanel.setWidget((Widget) lo);
}
if (uidl.hasAttribute("caption")) {
setCaption(uidl.getStringAttribute("caption"));
public void setCaption(String c) {
DOM.setInnerHTML(header, c);
}
-
- public void setPixelSize(int width, int height) {
- setPixelHeight(height);
- setPixelWidth(width);
- }
-
- public void setPixelWidth(int width) {
- DOM.setStyleAttribute(contents, "width",
- (width - BORDER_WIDTH_HORIZONTAL) + "px");
- DOM.setStyleAttribute(header, "width",
- (width - BORDER_WIDTH_HORIZONTAL) + "px");
- DOM.setStyleAttribute(footer, "width",
- (width - BORDER_WIDTH_HORIZONTAL) + "px");
- DOM.setStyleAttribute(getElement(), "width", width + "px");
- if (width != uidlWidth && client != null) {
- client.updateVariable(id, "width", width, false);
- uidlWidth = width;
- }
- }
-
- public void setPixelHeight(int height) {
- DOM.setStyleAttribute(contents, "height",
- (height - BORDER_WIDTH_VERTICAL) + "px");
- DOM.setStyleAttribute(getElement(), "height", height + "px");
- if (height != uidlHeight && client != null) {
- client.updateVariable(id, "height", height, false);
- uidlHeight = height;
- }
-
- }
-
+
protected Element getContainerElement() {
return contents;
}
case Event.ONMOUSEUP:
resizing = false;
DOM.removeEventPreview(this);
+ setSize(event, true);
break;
case Event.ONMOUSEMOVE:
if (resizing) {
- int w = DOM.eventGetScreenX(event) - startX + origW;
- if (w < 60)
- w = 60;
- int h = DOM.eventGetScreenY(event) - startY + origH;
- if (h < 60)
- h = 60;
- setPixelSize(w, h);
+ setSize(event, false);
DOM.eventPreventDefault(event);
}
break;
break;
}
}
+
+ public void setSize(Event event, boolean updateVariables) {
+ int w = DOM.eventGetScreenX(event) - startX + origW;
+ if (w < 60)
+ w = 60;
+ int h = DOM.eventGetScreenY(event) - startY + origH;
+ if (h < 60)
+ h = 60;
+ setWidth(w + "px");
+ setHeight(h + "px");
+ if(updateVariables) {
+ // sending width back always as pixels, no need for unit
+ client.updateVariable(id, "width", w, false);
+ client.updateVariable(id, "height", h, false);
+ }
+ }
+
+ public void setWidth(String width) {
+ super.setWidth(width);
+ DOM.setStyleAttribute(header, "width", width);
+ }
private void onHeaderEvent(Event event) {
switch (DOM.eventGetType(event)) {
return true;
}
+ public void onScroll(Widget widget, int scrollLeft, int scrollTop) {
+ client.updateVariable(id, "scrolltop", scrollTop, false);
+ client.updateVariable(id, "scrollleft", scrollLeft, false);
+ }
+
}
main.addComponent(new Button("Add new subwindow", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
- final Window w = new Window("Subwindow " + System.currentTimeMillis());
+ final Window w = new Window("sw " + System.currentTimeMillis());
main.addWindow(w);
+ w.setWidth(100);
+ w.setHeight(400);
+
+
Button closebutton = new Button("Close " + w.getCaption(), new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
main.removeWindow(w);
});
w.addComponent(closebutton);
+
+ w.addComponent(new Label("<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>" +
+ "<p>Lorem ipsum dolor sit amet.</p>",
+ Label.CONTENT_XHTML));
+
}
}));
}
}));
+ main.addComponent(new Button("Commit (saves window state: size, place, scrollpos)"));
}
public Window getWindow(String name) {
* containing (main window) or -1 if unspecified .
*/
private int positionX = -1;
+
+ /**
+ * Distance scrolled from top in pixels.
+ */
+ private int scrollTop = 0;
+
+ /**
+ * Distance scrolled from left in pixels.
+ */
+ private int scrollLeft = 0;
/* ********************************************************************* */
target.addVariable(this, "positionx", getPositionX());
target.addVariable(this, "positiony", getPositionY());
+ // Window position
+ target.addVariable(this, "scrolltop", getScrollTop());
+ target.addVariable(this, "scrollleft", getScrollLeft());
+
// Window closing
target.addVariable(this, "close", false);
setPositionY(y < 0 ? -1 : y);
}
+ // Scroll position
+ Integer scrolltop = (Integer) variables.get("scrolltop");
+ if (scrolltop != null) {
+ int top = scrolltop.intValue();
+ setScrollTop(top < 0 ? 0 : top);
+ }
+ Integer scrollleft = (Integer) variables.get("scrollleft");
+ if (positiony != null) {
+ int left = scrollleft.intValue();
+ setScrollLeft(left < 0 ? 0 : left);
+ }
+
// Closing
Boolean close = (Boolean) variables.get("close");
if (close != null && close.booleanValue()) {
public Set getChildWindows() {
return Collections.unmodifiableSet(subwindows);
}
+
+ /**
+ * Gets the current vertical scroll position of window.
+ *
+ * @return pixels scrolled from top
+ */
+ public int getScrollTop() {
+ return scrollTop;
+ }
+
+ /**
+ * Scrolls window to given position.
+ *
+ * @param scrollTop pixels to be scrolled from top
+ */
+ public void setScrollTop(int scrollTop) {
+ this.scrollTop = scrollTop;
+ }
+
+ /**
+ * Gets the current horizontal scroll position of window.
+ *
+ * @return pixels scrolled from left
+ */
+ public int getScrollLeft() {
+ return scrollLeft;
+ }
+
+ /**
+ * Scrolls window to given position.
+ *
+ * @param scrollLeft pixels to be scrolled from left
+ */
+ public void setScrollLeft(int scrollLeft) {
+ this.scrollLeft = scrollLeft;
+ }
}