]> source.dussan.org Git - vaadin-framework.git/commitdiff
API changes:
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 21 Aug 2008 11:59:09 +0000 (11:59 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 21 Aug 2008 11:59:09 +0000 (11:59 +0000)
Window.setResizable(boolean resizability) now allows to disable end-user sub-window resizing.
Window.center() allows to request a sub-window to be centered on screen.

Improved theming capabilities for IWindow: window borders are now calculated dynamically for every sub-window instance, previously only one final static was specified.

svn changeset:5238/svn branch:trunk

WebContent/ITMILL/themes/default/styles.css
WebContent/ITMILL/themes/default/window/window.css
src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java
src/com/itmill/toolkit/ui/Window.java

index fa22d8e52d066bafaa1360c7c66fabea5ab44148..fa5c072c9ac3f1837c765fdd66360a45235ee48a 100644 (file)
@@ -2280,6 +2280,11 @@ i-orderedlayout-margin-top {
        background: transparent url(window/img/resize.png);
 }
 
+.i-window-resizebox-disabled {
+       cursor: default;
+       background: transparent;
+}
+
 .i-window-closebox {
        position:absolute;
        top: 33px;
@@ -2355,6 +2360,9 @@ i-orderedlayout-margin-top {
        height: 12px;
        background: url(window/img/resize.png);
 }
+* html .i-window-resizebox-disabled {
+       background: transparent;
+}
 *+html .i-window-resizebox {
        bottom: 0;
        background-position: 3px 3px;
index 4460002a72d525aaedb54b7a1de0d8f113fb558c..cea46271eeeff8e2ee2fed6ea0139dd429d6da19 100644 (file)
        background: transparent url(img/resize.png);
 }
 
+.i-window-resizebox-disabled {
+       cursor: default;
+       background: transparent;
+}
+
 .i-window-closebox {
        position:absolute;
        top: 33px;
        height: 12px;
        background: url(img/resize.png);
 }
+* html .i-window-resizebox-disabled {
+       background: transparent;
+}
 *+html .i-window-resizebox {
        bottom: 0;
        background-position: 3px 3px;
index fb324f2167e72d465e3711b8f148f5dfcbd47168..6407c25f3200d2e0289877198575133e3a5d9ce1 100755 (executable)
@@ -63,7 +63,7 @@ public final class DebugConsole extends IWindow implements Console {
         // TODO stack to bottom (create window manager of some sort)
         setPixelSize(60, 60);
         setPopupPosition(Window.getClientWidth()
-                - (100 + IWindow.BORDER_WIDTH_HORIZONTAL), 0);
+                - 142, 0);
     }
 
     /*
index 8a8ffa2130fb283167566288409ae070874809ec..95dbebf47f094e49b7022e1e4a6925e539847c45 100644 (file)
@@ -42,11 +42,11 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
 
     public static final String CLASSNAME = "i-window";
 
-    /** pixels used by inner borders and paddings horizontally */
-    protected static final int BORDER_WIDTH_HORIZONTAL = 41;
-
-    /** pixels used by headers, footers, inner borders and paddings vertically */
-    protected static final int BORDER_WIDTH_VERTICAL = 58;
+    /**
+     * pixels used by inner borders and paddings horizontally (calculated on
+     * attach)
+     */
+    private int borderWidthHorizontal = 0;
 
     private static final int STACKING_OFFSET_PIXELS = 15;
 
@@ -96,6 +96,8 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
 
     private boolean modal = false;
 
+    private boolean resizable = true;
+
     private Element modalityCurtain;
     private Element draggingCurtain;
 
@@ -207,6 +209,10 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
             setModal(!modal);
         }
 
+        if (uidl.getBooleanAttribute("resizable") != resizable) {
+            setResizable(!resizable);
+        }
+
         // Initialize the position form UIDL
         try {
             final int positionx = uidl.getIntVariable("positionx");
@@ -367,6 +373,13 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
         contentPanel.setHorizontalScrollPosition(uidl
                 .getIntVariable("scrollLeft"));
 
+        // Center this window on screen if requested
+        // This has to be here because we might not know the content size before
+        // everything is painted into the window
+        if (uidl.getBooleanAttribute("center")) {
+            center();
+        }
+
     }
 
     public void show() {
@@ -490,6 +503,17 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
 
     }
 
+    private void setResizable(boolean resizability) {
+        resizable = resizability;
+        if (resizability) {
+            DOM.setElementProperty(resizeBox, "className", CLASSNAME
+                    + "-resizebox");
+        } else {
+            DOM.setElementProperty(resizeBox, "className", CLASSNAME
+                    + "-resizebox " + CLASSNAME + "-resizebox-disabled");
+        }
+    }
+
     public void setPopupPosition(int left, int top) {
         super.setPopupPosition(left, top);
         if (left != uidlPositionX && client != null) {
@@ -562,38 +586,40 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
     }
 
     private void onResizeEvent(Event event) {
-        switch (DOM.eventGetType(event)) {
-        case Event.ONMOUSEDOWN:
-            if (!isActive()) {
-                bringToFront();
-            }
-            showDraggingCurtain(true);
-            resizing = true;
-            startX = DOM.eventGetScreenX(event);
-            startY = DOM.eventGetScreenY(event);
-            origW = getWidget().getOffsetWidth();
-            origH = getWidget().getOffsetHeight();
-            DOM.setCapture(getElement());
-            DOM.eventPreventDefault(event);
-            break;
-        case Event.ONMOUSEUP:
-            showDraggingCurtain(false);
-            resizing = false;
-            DOM.releaseCapture(getElement());
-            setSize(event, true);
-            break;
-        case Event.ONLOSECAPTURE:
-            showDraggingCurtain(false);
-            resizing = false;
-        case Event.ONMOUSEMOVE:
-            if (resizing) {
-                setSize(event, false);
+        if (resizable) {
+            switch (DOM.eventGetType(event)) {
+            case Event.ONMOUSEDOWN:
+                if (!isActive()) {
+                    bringToFront();
+                }
+                showDraggingCurtain(true);
+                resizing = true;
+                startX = DOM.eventGetScreenX(event);
+                startY = DOM.eventGetScreenY(event);
+                origW = getWidget().getOffsetWidth();
+                origH = getWidget().getOffsetHeight();
+                DOM.setCapture(getElement());
+                DOM.eventPreventDefault(event);
+                break;
+            case Event.ONMOUSEUP:
+                showDraggingCurtain(false);
+                resizing = false;
+                DOM.releaseCapture(getElement());
+                setSize(event, true);
+                break;
+            case Event.ONLOSECAPTURE:
+                showDraggingCurtain(false);
+                resizing = false;
+            case Event.ONMOUSEMOVE:
+                if (resizing) {
+                    setSize(event, false);
+                    DOM.eventPreventDefault(event);
+                }
+                break;
+            default:
                 DOM.eventPreventDefault(event);
+                break;
             }
-            break;
-        default:
-            DOM.eventPreventDefault(event);
-            break;
         }
     }
 
@@ -624,7 +650,7 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
                             getElement(),
                             "width",
                             (Integer.parseInt(width.substring(0,
-                                    width.length() - 2)) + BORDER_WIDTH_HORIZONTAL)
+                                    width.length() - 2)) + borderWidthHorizontal)
                                     + "px");
         }
     }
@@ -695,4 +721,15 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener {
                 true);
     }
 
+    protected void onAttach() {
+        super.onAttach();
+        // Calculate space required by window borders, so we can accurately
+        // calculate space for content
+        final int contentWidth = DOM.getElementPropertyInt(contentPanel
+                .getElement(), "offsetWidth");
+        final int windowWidth = DOM.getElementPropertyInt(getElement(),
+                "offsetWidth");
+        borderWidthHorizontal = windowWidth - contentWidth;
+    }
+
 }
index a69ac113cad1d3fcf4e804f9b59289220eabbeba..b1e85f7f2d5929237f1e2f413b4b756d1f3428b6 100644 (file)
@@ -108,6 +108,10 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
 
     private boolean modal = false;
 
+    private boolean resizable = true;
+
+    private boolean centerRequested = false;
+
     /* ********************************************************************* */
 
     /**
@@ -470,6 +474,15 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
             target.addAttribute("modal", true);
         }
 
+        if (resizable) {
+            target.addAttribute("resizable", true);
+        }
+        
+        if(centerRequested) {
+            target.addAttribute("center", true);
+            centerRequested = false;
+        }
+
         // Marks the main window
         if (getApplication() != null
                 && this == getApplication().getMainWindow()) {
@@ -1023,12 +1036,50 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
 
     /**
      * Sets sub-window modal, so that widgets behind it cannot be accessed.
+     * <b>Note:</b> affects sub-windows only.
      * 
      * @param modality
      *                true if modality is to be turned on
      */
     public void setModal(boolean modality) {
         modal = modality;
+        center();
+        requestRepaint();
+    }
+
+    /**
+     * @return true if this window is modal.
+     */
+    public boolean isModal() {
+        return modal;
+    }
+
+    /**
+     * Sets sub-window resizable.
+     * <b>Note:</b> affects sub-windows only.
+     * 
+     * @param resizable
+     *                true if resizability is to be turned on
+     */
+    public void setResizable(boolean resizeability) {
+        resizable = resizeability;
+        requestRepaint();
+    }
+
+    /**
+     * 
+     * @return true if window is resizable by the end-user, otherwise false.
+     */
+    public boolean isResizable() {
+        return resizable;
+    }
+
+    /**
+     * Request to center this window on the screen.
+     * <b>Note:</b> affects sub-windows only.
+     */
+    public void center() {
+        centerRequested = true;
     }
 
     /**