changeset 6430:964e022be8dc

RT-36100 [Layout] Ensemble8 ChoiceBox control starts out at smaller size Reviewed by: dgrieve
author Martin Sladecek <martin.sladecek@oracle.com>
date Thu, 06 Mar 2014 08:12:36 +0100
parents e605558a26a6
children 8cc4b8c100f7
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java
diffstat 1 files changed, 1 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Wed Mar 05 15:28:44 2014 -0800
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Thu Mar 06 08:12:36 2014 +0100
@@ -127,9 +127,9 @@
         getChildren().add(itemsContainer);
         getChildren().add(upArrow);
         getChildren().add(downArrow);
-        computeInitialSize();
         initialize();
         setUpBinds();
+        updateItems();
         // RT-20197 add menuitems only on first show.
         popupMenu.showingProperty().addListener(weakPopupShowingListener);
 
@@ -413,40 +413,6 @@
     private boolean isFirstShow = true;
     private double ty;
 
-    /**
-    * Optimization part of RT-20197. In order to match the width of the choiceBox
-    * with the width of the widest menu item, we get the index of the widest 
-    * menuItem and add it to the itemsContainer so the visual metrics is calculated 
-    * correctly even though all the items are not added before show.
-    * This item will be removed when the first show happens.
-    */
-    private void computeInitialSize() {
-        int index = getLongestLabel();
-        itemsContainer.getChildren().clear();
-        if (index != -1) {
-            // We need to strip mnemonic symbols to avoid mnemonic duplicates
-            String itemText = new TextBinding(getItems().get(index).getText()).getText().
-                    replaceAll("_", "__").replaceAll("@", "@@");
-            MenuItemContainer menuItemContainer = new MenuItemContainer(new MenuItem(itemText));
-            itemsContainer.getChildren().add(menuItemContainer);
-        }
-    }
-
-    private int getLongestLabel() {
-        int len = 0;
-        int index = -1;
-        for (int row = 0; row < getItems().size(); row++) {
-            final MenuItem item = getItems().get(row);
-            if ((item instanceof CustomMenuItem && ((CustomMenuItem) item).getContent() == null) ||
-                    item instanceof SeparatorMenuItem)  continue;
-            if ( item != null && item.getText() != null && item.getText().length() > len) {
-                index = row;
-                len =  item.getText().length();
-            }
-        }
-        return index;
-    }
-
     private void initialize() {
         // keyboard navigation support. Initially focus goes to this ContextMenu,
         // but when the user first hits the up or down arrow keys, the focus