You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/09/16 20:59:14 UTC

svn commit: r997881 - in /pivot/trunk: tutorials/src/org/apache/pivot/tutorials/explorer/ wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/skin/

Author: gbrown
Date: Thu Sep 16 18:59:14 2010
New Revision: 997881

URL: http://svn.apache.org/viewvc?rev=997881&view=rev
Log:
Update ListButtonSkin and TerraListButtonSkin to display the popup on mouse down and key pressed rather than button pressed (this is consistent with drop-down behavior on Windows and Mac OS X).

Modified:
    pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/text_area.txt
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java

Modified: pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/text_area.txt
URL: http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/text_area.txt?rev=997881&r1=997880&r2=997881&view=diff
==============================================================================
--- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/text_area.txt (original)
+++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/text_area.txt Thu Sep 16 18:59:14 2010
@@ -1,11 +1,6 @@
-Lorem ipsum dolor sit amet, consetetur
-sadipscing elitr, sed diam nonumy eirmod
-tempor invidunt ut labore et dolore magna
-aliquyam erat, sed diam voluptua. At vero
-eos et accusam et justo duo dolores et ea
-rebum. Stet clita kasd gubergren, no sea
-takimata sanctus est Lorem ipsum dolor sit
-amet.
-
-Stet clita kasd gubergren, no sea takimata
-sanctus est Lorem ipsum dolor sit amet.
+Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
+Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
+Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
+Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
+Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
+Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java?rev=997881&r1=997880&r2=997881&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java Thu Sep 16 18:59:14 2010
@@ -53,7 +53,82 @@ import org.apache.pivot.wtk.skin.ListBut
  * Terra list button skin.
  */
 public class TerraListButtonSkin extends ListButtonSkin {
-    private WindowStateListener listViewPopupStateListener = new WindowStateListener.Adapter() {
+    private WindowStateListener listViewPopupStateListener = new WindowStateListener() {
+        @Override
+        public void windowOpened(Window window) {
+            // Determine the popup's location and preferred size, relative to the button
+            ListButton listButton = (ListButton)getComponent();
+            Display display = listButton.getDisplay();
+
+            if (display != null) {
+                int width = getWidth();
+                int height = getHeight();
+
+                // Adjust for list size
+                int listSize = listButton.getListSize();
+                if (listSize == -1) {
+                    listViewBorder.setPreferredHeight(-1);
+                } else {
+                    if (!listViewBorder.isPreferredHeightSet()) {
+                        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
+                        int borderHeight = itemRenderer.getPreferredHeight(-1) * listSize + 2;
+
+                        if (listViewBorder.getPreferredHeight() > borderHeight) {
+                            listViewBorder.setPreferredHeight(borderHeight);
+                        } else {
+                            listViewBorder.setPreferredHeight(-1);
+                        }
+                    }
+                }
+
+                // Ensure that the popup remains within the bounds of the display
+                Point buttonLocation = listButton.mapPointToAncestor(display, 0, 0);
+
+                Dimensions displaySize = display.getSize();
+
+                listViewPopup.setPreferredSize(-1, -1);
+                Dimensions popupSize = listViewPopup.getPreferredSize();
+                int popupWidth = Math.max(popupSize.width, listButton.getWidth() - TRIGGER_WIDTH - 1);
+                int popupHeight = popupSize.height;
+
+                int x = buttonLocation.x;
+                if (popupWidth > width
+                    && x + popupWidth > displaySize.width) {
+                    x = buttonLocation.x + width - popupWidth;
+                }
+
+                int y = buttonLocation.y + height - 1;
+                if (y + popupSize.height > displaySize.height) {
+                    if (buttonLocation.y - popupSize.height > 0) {
+                        y = buttonLocation.y - popupSize.height + 1;
+                    } else {
+                        popupHeight = displaySize.height - y;
+                    }
+                } else {
+                    popupHeight = -1;
+                }
+
+                listViewPopup.setLocation(x, y);
+                listViewPopup.setPreferredSize(popupWidth, popupHeight);
+
+                ApplicationContext.queueCallback(new Runnable() {
+                    @Override
+                    public void run() {
+                        int selectedIndex = listView.getSelectedIndex();
+
+                        if (selectedIndex >= 0) {
+                            Bounds itemBounds = listView.getItemBounds(selectedIndex);
+                            listView.scrollAreaToVisible(itemBounds);
+                        }
+                    }
+                });
+
+                repaintComponent();
+
+                listView.requestFocus();
+            }
+        }
+
         @Override
         public Vote previewWindowClose(final Window window) {
             Vote vote = Vote.APPROVE;
@@ -90,6 +165,11 @@ public class TerraListButtonSkin extends
         @Override
         public void windowClosed(Window window, Display display, Window owner) {
             closeTransition = null;
+
+            repaintComponent();
+
+            ListButton listButton = (ListButton)getComponent();
+            listButton.requestFocus();
         }
     };
 
@@ -652,90 +732,4 @@ public class TerraListButtonSkin extends
     public void setListHighlightBackgroundColor(Object listHighlightBackgroundColor) {
         listView.getStyles().put("highlightBackgroundColor", listHighlightBackgroundColor);
     }
-
-    // Button events
-    @Override
-    public void buttonPressed(Button button) {
-        if (listViewPopup.isOpen()) {
-            listViewPopup.close();
-        } else {
-            ListButton listButton = (ListButton)button;
-
-            if (listButton.getListData().getLength() > 0) {
-                // Determine the popup's location and preferred size, relative
-                // to the button
-                Display display = listButton.getDisplay();
-
-                if (display != null) {
-                    int width = getWidth();
-                    int height = getHeight();
-
-                    // TODO If this is a split button, check for mouse down over the trigger?
-                    // Or should we do this in mouseDown()?
-
-                    // Adjust for list size
-                    int listSize = listButton.getListSize();
-                    if (listSize == -1) {
-                        listViewBorder.setPreferredHeight(-1);
-                    } else {
-                        if (!listViewBorder.isPreferredHeightSet()) {
-                            ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
-                            int borderHeight = itemRenderer.getPreferredHeight(-1) * listSize + 2;
-
-                            if (listViewBorder.getPreferredHeight() > borderHeight) {
-                                listViewBorder.setPreferredHeight(borderHeight);
-                            } else {
-                                listViewBorder.setPreferredHeight(-1);
-                            }
-                        }
-                    }
-
-                    // Ensure that the popup remains within the bounds of the display
-                    Point buttonLocation = listButton.mapPointToAncestor(display, 0, 0);
-
-                    Dimensions displaySize = display.getSize();
-
-                    listViewPopup.setPreferredSize(-1, -1);
-                    Dimensions popupSize = listViewPopup.getPreferredSize();
-                    int popupWidth = Math.max(popupSize.width, listButton.getWidth() - TRIGGER_WIDTH - 1);
-                    int popupHeight = popupSize.height;
-
-                    int x = buttonLocation.x;
-                    if (popupWidth > width
-                        && x + popupWidth > displaySize.width) {
-                        x = buttonLocation.x + width - popupWidth;
-                    }
-
-                    int y = buttonLocation.y + height - 1;
-                    if (y + popupSize.height > displaySize.height) {
-                        if (buttonLocation.y - popupSize.height > 0) {
-                            y = buttonLocation.y - popupSize.height + 1;
-                        } else {
-                            popupHeight = displaySize.height - y;
-                        }
-                    } else {
-                        popupHeight = -1;
-                    }
-
-                    listViewPopup.setLocation(x, y);
-                    listViewPopup.setPreferredSize(popupWidth, popupHeight);
-                    listViewPopup.open(listButton.getWindow());
-
-                    ApplicationContext.queueCallback(new Runnable() {
-                        @Override
-                        public void run() {
-                            int selectedIndex = listView.getSelectedIndex();
-
-                            if (selectedIndex >= 0) {
-                                Bounds itemBounds = listView.getItemBounds(selectedIndex);
-                                listView.scrollAreaToVisible(itemBounds);
-                            }
-                        }
-                    });
-
-                    listView.requestFocus();
-                }
-            }
-        }
-    }
 }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java?rev=997881&r1=997880&r2=997881&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CalendarButtonSkin.java Thu Sep 16 18:59:14 2010
@@ -39,12 +39,6 @@ import org.apache.pivot.wtk.WindowStateL
 
 /**
  * Abstract base class for calendar button skins.
- * <p>
- * TODO Rather than blindly closing when a mouse down is received, we could
- * instead cache the selection state in the popup's container mouse down event
- * and compare it to the current state in component mouse down. If different,
- * we close the popup. This would also tie this base class less tightly to its
- * concrete subclasses.
  */
 public abstract class CalendarButtonSkin extends ButtonSkin
     implements CalendarButton.Skin, CalendarButtonListener, CalendarButtonSelectionListener {

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java?rev=997881&r1=997880&r2=997881&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ListButtonSkin.java Thu Sep 16 18:59:14 2010
@@ -36,12 +36,6 @@ import org.apache.pivot.wtk.WindowStateL
 
 /**
  * Abstract base class for list button skins.
- * <p>
- * TODO Rather than blindly closing when a mouse down is received, we could
- * instead cache the selection state in the popup's container mouse down event
- * and compare it to the current state in component mouse down. If different,
- * we close the popup. This would also tie this base class less tightly to its
- * concrete subclasses.
  */
 public abstract class ListButtonSkin extends ButtonSkin
     implements ListButton.Skin, ListButtonListener, ListButtonSelectionListener {
@@ -184,22 +178,25 @@ public abstract class ListButtonSkin ext
     public void enabledChanged(Component component) {
         super.enabledChanged(component);
 
-        listViewPopup.close();
         pressed = false;
+        repaintComponent();
+
+        listViewPopup.close();
     }
 
     @Override
     public void focusedChanged(Component component, Component obverseComponent) {
         super.focusedChanged(component, obverseComponent);
 
+        pressed = false;
+        repaintComponent();
+
         // Close the popup if focus was transferred to a component whose
         // window is not the popup
         if (!component.isFocused()
             && !listViewPopup.containsFocus()) {
             listViewPopup.close();
         }
-
-        pressed = false;
     }
 
     // Component mouse events
@@ -208,6 +205,7 @@ public abstract class ListButtonSkin ext
         super.mouseOut(component);
 
         pressed = false;
+        repaintComponent();
     }
 
     @Override
@@ -217,26 +215,30 @@ public abstract class ListButtonSkin ext
         pressed = true;
         repaintComponent();
 
+        if (listViewPopup.isOpen()) {
+            listViewPopup.close();
+        } else {
+            listViewPopup.open(component.getWindow());
+        }
+
         return consumed;
     }
 
     @Override
     public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
-        boolean consumed = super.mouseUp(component, button, x, y);
-
         pressed = false;
         repaintComponent();
 
-        return consumed;
+        return super.mouseUp(component, button, x, y);
     }
 
     @Override
     public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
         boolean consumed = super.mouseClick(component, button, x, y, count);
 
+        // TODO Only press if this is a repeatable button and the user clicked on the
+        // content area (not the trigger) (call abstract isMouseOverTrigger() method?)
         ListButton listButton = (ListButton)getComponent();
-
-        listButton.requestFocus();
         listButton.press();
 
         return consumed;
@@ -244,7 +246,7 @@ public abstract class ListButtonSkin ext
 
     /**
      * {@link Keyboard.KeyCode#SPACE} repaints the component to reflect the
-     * pressed state.<br>
+     * pressed state and opens the popup.<br>
      * {@link Keyboard.KeyCode#UP} selects the previous enabled list item.<br>
      * {@link Keyboard.KeyCode#DOWN} selects the next enabled list item.
      *
@@ -258,7 +260,13 @@ public abstract class ListButtonSkin ext
         if (keyCode == Keyboard.KeyCode.SPACE) {
             pressed = true;
             repaintComponent();
-            consumed = true;
+
+            // TODO Only open if the list button is not repeatable
+            if (listViewPopup.isOpen()) {
+                listViewPopup.close();
+            } else {
+                listViewPopup.open(component.getWindow());
+            }
         } else if (keyCode == Keyboard.KeyCode.UP) {
             ListButton listButton = (ListButton)getComponent();
             int index = listButton.getSelectedIndex();
@@ -273,18 +281,24 @@ public abstract class ListButtonSkin ext
                 consumed = true;
             }
         } else if (keyCode == Keyboard.KeyCode.DOWN) {
-            ListButton listButton = (ListButton)getComponent();
-            int index = listButton.getSelectedIndex();
-            int count = listButton.getListData().getLength();
+            if (Keyboard.isPressed(Keyboard.Modifier.ALT)) {
+                listViewPopup.open(component.getWindow());
 
-            do {
-                index++;
-            } while (index < count
-                && listView.isItemDisabled(index));
-
-            if (index < count) {
-                listButton.setSelectedIndex(index);
                 consumed = true;
+            } else {
+                ListButton listButton = (ListButton)getComponent();
+                int index = listButton.getSelectedIndex();
+                int count = listButton.getListData().getLength();
+
+                do {
+                    index++;
+                } while (index < count
+                    && listView.isItemDisabled(index));
+
+                if (index < count) {
+                    listButton.setSelectedIndex(index);
+                    consumed = true;
+                }
             }
         } else {
             consumed = super.keyPressed(component, keyCode, keyLocation);
@@ -293,9 +307,6 @@ public abstract class ListButtonSkin ext
         return consumed;
     }
 
-    /**
-     * {@link Keyboard.KeyCode#SPACE} 'presses' the button.
-     */
     @Override
     public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
         boolean consumed = false;

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java?rev=997881&r1=997880&r2=997881&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java Thu Sep 16 18:59:14 2010
@@ -33,7 +33,7 @@ class TextPaneSkinParagraphView extends 
 
     private final TextPaneSkin textPaneSkin;
 
-    private class Row {
+    private static class Row {
         public int x = 0;
         public int y = 0;
         public int width = 0;