Author: rj...@google.com
Date: Tue Mar 17 08:17:42 2009
New Revision: 5027

Added:
     
trunk/user/src/com/google/gwt/user/client/ui/DisclosurePanelImagesRTL.java
Modified:
    trunk/user/src/com/google/gwt/user/client/ui/DisclosurePanelImages.java
    trunk/user/src/com/google/gwt/user/client/ui/MenuBar.java
    trunk/user/test/com/google/gwt/user/client/ui/MenuBarTest.java

Log:
Makes DiscloserPanelImagesRTL public, to allow apps to include it in bigger  
bundles.
Makes MenuBar#setItem public, on the road to allow keyboard control.



Modified:  
trunk/user/src/com/google/gwt/user/client/ui/DisclosurePanelImages.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/DisclosurePanelImages.java     
 
(original)
+++ trunk/user/src/com/google/gwt/user/client/ui/DisclosurePanelImages.java     
 
Tue Mar 17 08:17:42 2009
@@ -1,12 +1,12 @@
  /*
   * Copyright 2007 Google Inc.
- *
+ *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
   * use this file except in compliance with the License. You may obtain a  
copy of
   * the License at
- *
+ *
   * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -19,39 +19,18 @@
   * An {...@link ImageBundle} that provides images for {...@link 
DisclosurePanel}.
   */
  public interface DisclosurePanelImages extends ImageBundle {
-
+
    /**
     * An image indicating an open disclosure panel.
-   *
+   *
     * @return a prototype of this image
     */
    AbstractImagePrototype disclosurePanelOpen();
-
+
    /**
     * An image indicating a closed disclosure panel.
-   *
+   *
     * @return a prototype of this image
     */
    AbstractImagePrototype disclosurePanelClosed();
  }
-
-/**
- * A bundle containing the RTL versions of the images for DisclosurePanel.  
Right now, we
- * only need to override the disclosurePanelClosed() method, as the image  
that we provide
- * for disclosurePanelOpen() is direction-agnostic.
- *
- * Notice that this interface is package protected. This interface need  
not be
- * publicly exposed, as it is only used by the DisclosurePanel class to  
provide RTL
- * versions of the images in the case the the user does not pass in their  
own
- * bundle. However, we cannot make this class private, because the  
generated
- * class needs to be able to extend this class.
- */
-interface DisclosurePanelImagesRTL extends DisclosurePanelImages {
-  /**
-   * An image indicating a closed disclosure panel for a RTL context.
-   *
-   * @return a prototype of this image
-   */
-  @Resource("disclosurePanelClosed_rtl.png")
-  AbstractImagePrototype disclosurePanelClosed();
-}
\ No newline at end of file

Added:  
trunk/user/src/com/google/gwt/user/client/ui/DisclosurePanelImagesRTL.java
==============================================================================
--- (empty file)
+++  
trunk/user/src/com/google/gwt/user/client/ui/DisclosurePanelImagesRTL.java      
 
Tue Mar 17 08:17:42 2009
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.user.client.ui;
+
+/**
+ * A bundle containing the RTL versions of the images for DisclosurePanel.  
Right now, we
+ * only need to override the disclosurePanelClosed() method, as the image  
that we provide
+ * for disclosurePanelOpen() is direction-agnostic.
+ */
+public interface DisclosurePanelImagesRTL extends DisclosurePanelImages {
+  /**
+   * An image indicating a closed disclosure panel for a RTL context.
+   *
+   * @return a prototype of this image
+   */
+  @Resource("disclosurePanelClosed_rtl.png")
+  AbstractImagePrototype disclosurePanelClosed();
+}

Modified: trunk/user/src/com/google/gwt/user/client/ui/MenuBar.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/MenuBar.java   (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/MenuBar.java   Tue Mar 17  
08:17:42 2009
@@ -1,12 +1,12 @@
  /*
   * Copyright 2009 Google Inc.
- *
+ *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
   * use this file except in compliance with the License. You may obtain a  
copy of
   * the License at
- *
+ *
   * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -37,11 +37,11 @@
   * A standard menu bar widget. A menu bar can contain any number of menu  
items,
   * each of which can either fire a {...@link  
com.google.gwt.user.client.Command} or
   * open a cascaded menu bar.
- *
+ *
   * <p>
   * <img class='gallery' src='MenuBar.png'/>
   * </p>
- *
+ *
   * <h3>CSS Style Rules</h3>
   * <dl>
   * <dd>.gwt-MenuBar</dd>
@@ -90,12 +90,13 @@
   * <dt>the bottom center cell</dt>
   * <dd>.gwt-MenuBarPopup .menuPopupBottomCenterInner</dd>
   * <dt>the inner element of the cell</dt>
+
   * <dd>.gwt-MenuBarPopup .menuPopupBottomRight</dd>
   * <dt>the bottom right cell</dt>
   * <dd>.gwt-MenuBarPopup .menuPopupBottomRightInner</dd>
   * <dt>the inner element of the cell</dt>
   * </dl>
- *
+ *
   * <p>
   * <h3>Example</h3>
   * {...@example com.google.gwt.examples.MenuBarExample}
@@ -112,7 +113,7 @@
    public interface MenuBarImages extends ImageBundle {
      /**
       * An image indicating a {...@link MenuItem} has an associated submenu.
-     *
+     *
       * @return a prototype of this image
       */
      AbstractImagePrototype menuBarSubMenuIcon();
@@ -120,7 +121,7 @@

    /**
     * A bundle containing the RTL versions of the images for MenuBar.
-   *
+   *
     * Notice that this interface is package protected. This interface need  
not be
     * publicly exposed, as it is only used by the MenuBar class to provide  
RTL
     * versions of the images in the case the the user does not pass in  
their own
@@ -131,7 +132,7 @@
      /**
       * An image indicating a {...@link MenuItem} has an associated submenu  
for a
       * RTL context.
-     *
+     *
       * @return a prototype of this image
       */
      @Resource("menuBarSubMenuIcon_rtl.gif")
@@ -169,7 +170,7 @@

    /**
     * Creates an empty menu bar.
-   *
+   *
     * @param vertical <code>true</code> to orient the menu bar vertically
     */
    public MenuBar(boolean vertical) {
@@ -184,7 +185,7 @@
    /**
     * Creates an empty menu bar that uses the specified image bundle for  
menu
     * images.
-   *
+   *
     * @param vertical <code>true</code> to orient the menu bar vertically
     * @param images a bundle that provides images for this menu
     */
@@ -195,7 +196,7 @@
    /**
     * Creates an empty horizontal menu bar that uses the specified image  
bundle
     * for menu images.
-   *
+   *
     * @param images a bundle that provides images for this menu
     */
    public MenuBar(MenuBarImages images) {
@@ -208,7 +209,7 @@

    /**
     * Adds a menu item to the bar.
-   *
+   *
     * @param item the item to be added
     * @return the {...@link MenuItem} object
     */
@@ -219,7 +220,7 @@
    /**
     * Adds a menu item to the bar, that will fire the given command when it  
is
     * selected.
-   *
+   *
     * @param text the item's text
     * @param asHTML <code>true</code> to treat the specified text as html
     * @param cmd the command to be fired
@@ -232,7 +233,7 @@
    /**
     * Adds a menu item to the bar, that will open the specified menu when  
it is
     * selected.
-   *
+   *
     * @param text the item's text
     * @param asHTML <code>true</code> to treat the specified text as html
     * @param popup the menu to be cascaded from it
@@ -245,7 +246,7 @@
    /**
     * Adds a menu item to the bar, that will fire the given command when it  
is
     * selected.
-   *
+   *
     * @param text the item's text
     * @param cmd the command to be fired
     * @return the {...@link MenuItem} object created
@@ -257,7 +258,7 @@
    /**
     * Adds a menu item to the bar, that will open the specified menu when  
it is
     * selected.
-   *
+   *
     * @param text the item's text
     * @param popup the menu to be cascaded from it
     * @return the {...@link MenuItem} object created
@@ -269,7 +270,7 @@
    /**
     * Adds a thin line to the {...@link MenuBar} to separate sections of
     * {...@link MenuItem}s.
-   *
+   *
     * @return the {...@link MenuItemSeparator} object created
     */
    public MenuItemSeparator addSeparator() {
@@ -279,7 +280,7 @@
    /**
     * Adds a thin line to the {...@link MenuBar} to separate sections of
     * {...@link MenuItem}s.
-   *
+   *
     * @param separator the {...@link MenuItemSeparator} to be added
     * @return the {...@link MenuItemSeparator} object
     */
@@ -315,9 +316,16 @@
    }

    /**
+   * Give this MenuBar focus.
+   */
+  public void focus() {
+    FocusPanel.impl.focus(getElement());
+  }
+
+  /**
     * Gets whether this menu bar's child menus will open when the mouse is  
moved
     * over it.
-   *
+   *
     * @return <code>true</code> if child menus will auto-open
     */
    public boolean getAutoOpen() {
@@ -326,7 +334,7 @@

    /**
     * Get the index of a {...@link MenuItem}.
-   *
+   *
     * @return the index of the item, or -1 if it is not contained by this  
MenuBar
     */
    public int getItemIndex(MenuItem item) {
@@ -335,7 +343,7 @@

    /**
     * Get the index of a {...@link MenuItemSeparator}.
-   *
+   *
     * @return the index of the separator, or -1 if it is not contained by  
this
     *         MenuBar
     */
@@ -345,7 +353,7 @@

    /**
     * Adds a menu item to the bar at a specific index.
-   *
+   *
     * @param item the item to be inserted
     * @param beforeIndex the index where the item should be inserted
     * @return the {...@link MenuItem} object
@@ -380,7 +388,7 @@
    /**
     * Adds a thin line to the {...@link MenuBar} to separate sections of
     * {...@link MenuItem}s at the specified index.
-   *
+   *
     * @param beforeIndex the index where the seperator should be inserted
     * @return the {...@link MenuItemSeparator} object
     * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out  
of
@@ -393,7 +401,7 @@
    /**
     * Adds a thin line to the {...@link MenuBar} to separate sections of
     * {...@link MenuItem}s at the specified index.
-   *
+   *
     * @param separator the {...@link MenuItemSeparator} to be inserted
     * @param beforeIndex the index where the seperator should be inserted
     * @return the {...@link MenuItemSeparator} object
@@ -499,7 +507,7 @@

    /**
     * Closes the menu bar.
-   *
+   *
     * @deprecated use {...@link #addCloseHandler(CloseHandler)} instead.
     */
    @Deprecated
@@ -522,7 +530,7 @@

    /**
     * Removes the specified menu item from the bar.
-   *
+   *
     * @param item the item to be removed
     */
    public void removeItem(MenuItem item) {
@@ -540,7 +548,7 @@

    /**
     * Removes the specified {...@link MenuItemSeparator} from the bar.
-   *
+   *
     * @param separator the separator to be removed
     */
    public void removeSeparator(MenuItemSeparator separator) {
@@ -549,6 +557,49 @@
      }
    }

+  /**
+   * Select the given MenuItem, which must be a direct child of this  
MenuBar.
+   * @param item the MenuItem to select, or null to clear selection
+   */
+  public void selectItem(MenuItem item) {
+    assert item == null || item.getParentMenu() == this;
+
+    if (item == selectedItem) {
+      return;
+    }
+
+    if (selectedItem != null) {
+      selectedItem.setSelectionStyle(false);
+      // Set the style of the submenu indicator
+      if (vertical) {
+        Element tr = DOM.getParent(selectedItem.getElement());
+        if (DOM.getChildCount(tr) == 2) {
+          Element td = DOM.getChild(tr, 1);
+          setStyleName(td, "subMenuIcon-selected", false);
+        }
+      }
+    }
+
+    if (item != null) {
+      item.setSelectionStyle(true);
+
+      // Set the style of the submenu indicator
+      if (vertical) {
+        Element tr = DOM.getParent(item.getElement());
+        if (DOM.getChildCount(tr) == 2) {
+          Element td = DOM.getChild(tr, 1);
+          setStyleName(td, "subMenuIcon-selected", true);
+        }
+      }
+
+      Accessibility.setState(getElement(),
+          Accessibility.STATE_ACTIVEDESCENDANT, DOM.getElementAttribute(
+              item.getElement(), "id"));
+    }
+
+    selectedItem = item;
+  }
+
    public void setAnimationEnabled(boolean enable) {
      isAnimationEnabled = enable;
    }
@@ -556,7 +607,7 @@
    /**
     * Sets whether this menu bar's child menus will open when the mouse is  
moved
     * over it.
-   *
+   *
     * @param autoOpen <code>true</code> to cause child menus to auto-open
     */
    public void setAutoOpen(boolean autoOpen) {
@@ -567,7 +618,7 @@
     * Returns a list containing the <code>MenuItem</code> objects in the  
menu
     * bar. If there are no items in the menu bar, then an empty  
<code>List</code>
     * object will be returned.
-   *
+   *
     * @return a list containing the <code>MenuItem</code> objects in the  
menu bar
     */
    protected List<MenuItem> getItems() {
@@ -578,7 +629,7 @@
     * Returns the <code>MenuItem</code> that is currently selected  
(highlighted)
     * by the user. If none of the items in the menu are currently selected,  
then
     * <code>null</code> will be returned.
-   *
+   *
     * @return the <code>MenuItem</code> that is currently selected, or
     *         <code>null</code> if no items are currently selected
     */
@@ -601,7 +652,7 @@
     * <ul>
     * <li>-item# = the {...@link MenuItem} at the specified index.</li>
     * </ul>
-   *
+   *
     * @see UIObject#onEnsureDebugId(String)
     */
    @Override
@@ -626,7 +677,7 @@
     * popup associated with it, the popup will be shown. If it has a command
     * associated with it, and 'fireCommand' is true, then the command will  
be
     * fired. Popups associated with other items will be hidden.
-   *
+   *
     * @param item the item whose popup is to be shown. @param fireCommand
     * <code>true</code> if the item's command should be fired,  
<code>false</code>
     * otherwise.
@@ -702,46 +753,9 @@
      }
    }

-  void selectItem(MenuItem item) {
-    if (item == selectedItem) {
-      return;
-    }
-
-    if (selectedItem != null) {
-      selectedItem.setSelectionStyle(false);
-      // Set the style of the submenu indicator
-      if (vertical) {
-        Element tr = DOM.getParent(selectedItem.getElement());
-        if (DOM.getChildCount(tr) == 2) {
-          Element td = DOM.getChild(tr, 1);
-          setStyleName(td, "subMenuIcon-selected", false);
-        }
-      }
-    }
-
-    if (item != null) {
-      item.setSelectionStyle(true);
-
-      // Set the style of the submenu indicator
-      if (vertical) {
-        Element tr = DOM.getParent(item.getElement());
-        if (DOM.getChildCount(tr) == 2) {
-          Element td = DOM.getChild(tr, 1);
-          setStyleName(td, "subMenuIcon-selected", true);
-        }
-      }
-
-      Accessibility.setState(getElement(),
-          Accessibility.STATE_ACTIVEDESCENDANT, DOM.getElementAttribute(
-              item.getElement(), "id"));
-    }
-
-    selectedItem = item;
-  }
-
    /**
     * Set the IDs of the menu items.
-   *
+   *
     * @param baseID the base ID
     */
    void setMenuItemDebugIds(String baseID) {
@@ -754,7 +768,7 @@

    /**
     * Show or hide the icon used for items with a submenu.
-   *
+   *
     * @param item the item with or without a submenu
     */
    void updateSubmenuIcon(MenuItem item) {
@@ -793,7 +807,7 @@
    /**
     * Physically add the td element of a {...@link MenuItem} or
     * {...@link MenuItemSeparator} to this {...@link MenuBar}.
-   *
+   *
     * @param beforeIndex the index where the seperator should be inserted
     * @param tdElem the td element to be added
     */
@@ -831,10 +845,6 @@
      return null;
    }

-  private void focus() {
-    FocusPanel.impl.focus(getElement());
-  }
-
    private Element getItemContainerElement() {
      if (vertical) {
        return body;
@@ -979,7 +989,7 @@
      // clear the selection; a keyboard user can cursor down to the first  
item
      selectItem(null);
    }
-
+
    private void openPopup(final MenuItem item) {
      // Only the last popup to be opened should preview all event
      if (parentMenu != null && parentMenu.popup != null) {
@@ -1069,7 +1079,7 @@
    /**
     * Removes the specified item from the {...@link MenuBar} and the physical  
DOM
     * structure.
-   *
+   *
     * @param item the item to be removed
     * @return true if the item was removed
     */
@@ -1088,7 +1098,7 @@
    /**
     * Selects the first item in the menu if no items are currently  
selected. This
     * method assumes that the menu has at least 1 item.
-   *
+   *
     * @return true if no item was previously selected and the first item in  
the
     *         list was selected, false otherwise
     */
@@ -1154,7 +1164,7 @@

    /**
     * Set the colspan of a {...@link MenuItem} or {...@link MenuItemSeparator}.
-   *
+   *
     * @param item the {...@link MenuItem} or {...@link MenuItemSeparator}
     * @param colspan the colspan
     */

Modified: trunk/user/test/com/google/gwt/user/client/ui/MenuBarTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/user/client/ui/MenuBarTest.java       
(original)
+++ trunk/user/test/com/google/gwt/user/client/ui/MenuBarTest.java      Tue Mar 
 
17 08:17:42 2009
@@ -1,12 +1,12 @@
  /*
   * Copyright 2008 Google Inc.
- *
+ *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
   * use this file except in compliance with the License. You may obtain a  
copy of
   * the License at
- *
+ *
   * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -74,7 +74,7 @@
      bar.removeSeparator(separator0);
      assertEquals(item1, items.get(0));
      assertNull(separator0.getParentMenu());
-
+
      // Add a bunch of items and clear them all
      MenuItem item2 = bar.addItem("test2", true, blankCommand);
      MenuItemSeparator separator1 = bar.addSeparator();
@@ -182,6 +182,29 @@
      }
    }

+  public void testSelectItem() {
+    Command emptyCommand = new Command() {
+      public void execute() {
+      }
+    };
+
+    MenuBar bar = new MenuBar(false);
+    MenuItem item1 = new MenuItem("item1", emptyCommand);
+    MenuItem item2 = new MenuItem("item2", emptyCommand);
+    MenuItem item3 = new MenuItem("item3", emptyCommand);
+    bar.addItem(item1);
+    bar.addItem(item2);
+    bar.addItem(item3);
+    RootPanel.get().add(bar);
+
+    bar.selectItem(item1);
+    assertEquals(item1, bar.getSelectedItem());
+    bar.selectItem(item3);
+    assertEquals(item3, bar.getSelectedItem());
+    bar.selectItem(null);
+    assertNull(bar.getSelectedItem());
+  }
+
    public void testDebugId() {
      Command emptyCommand = new Command() {
        public void execute() {
@@ -202,7 +225,7 @@
      bar.addItem("top1", emptyCommand);
      MenuItem top2 = bar.addItem("top2", subMenu);
      RootPanel.get().add(bar);
-
+
      // Open the item with a submenu
      bar.itemOver(top2, true);


--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to