modules/graphics/src/main/java/com/sun/javafx/tk/quantum/GlassSystemMenu.java

Print this page




 137     private void insertMenu(final Menu parent, final MenuBase mb, int pos) {
 138         Application app = Application.GetApplication();
 139         final Menu glassMenu = app.createMenu(parseText(mb), ! mb.isDisable());
 140         glassMenu.setEventHandler(new GlassMenuEventHandler(mb));
 141 
 142         // There is no way of knowing if listener was already added.
 143         mb.visibleProperty().removeListener(visibilityListener);
 144         mb.visibleProperty().addListener(visibilityListener);
 145 
 146         if (!mb.isVisible()) {
 147             return;
 148         }
 149 
 150         final ObservableList<MenuItemBase> items = mb.getItemsBase();
 151 
 152         items.addListener((ListChangeListener.Change<? extends MenuItemBase> change) -> {
 153             while (change.next()) {
 154                 int from = change.getFrom();
 155                 int to = change.getTo();
 156                 List<? extends MenuItemBase> removed = change.getRemoved();

 157                 for (int i = from + removed.size() - 1; i >= from ; i--) {


 158                     glassMenu.remove(i);
 159                 }

 160                 for (int i = from; i < to; i++) {
 161                     MenuItemBase item = change.getList().get(i);
 162                     if (item instanceof MenuBase) {
 163                         insertMenu(glassMenu, (MenuBase)item, i);
 164                     } else {
 165                         insertMenuItem(glassMenu, item, i);
 166                     }
 167                 }
 168             }
 169         });
 170 
 171         for (MenuItemBase item : items) {
 172             if (item instanceof MenuBase) {
 173                 // submenu
 174                 addMenu(glassMenu, (MenuBase)item);
 175             } else {
 176                 // menu item
 177                 addMenuItem(glassMenu, item);
 178             }
 179         }




 137     private void insertMenu(final Menu parent, final MenuBase mb, int pos) {
 138         Application app = Application.GetApplication();
 139         final Menu glassMenu = app.createMenu(parseText(mb), ! mb.isDisable());
 140         glassMenu.setEventHandler(new GlassMenuEventHandler(mb));
 141 
 142         // There is no way of knowing if listener was already added.
 143         mb.visibleProperty().removeListener(visibilityListener);
 144         mb.visibleProperty().addListener(visibilityListener);
 145 
 146         if (!mb.isVisible()) {
 147             return;
 148         }
 149 
 150         final ObservableList<MenuItemBase> items = mb.getItemsBase();
 151 
 152         items.addListener((ListChangeListener.Change<? extends MenuItemBase> change) -> {
 153             while (change.next()) {
 154                 int from = change.getFrom();
 155                 int to = change.getTo();
 156                 List<? extends MenuItemBase> removed = change.getRemoved();
 157 
 158                 for (int i = from + removed.size() - 1; i >= from ; i--) {
 159                     List<Object> menuItemList = glassMenu.getItems();
 160                     if (i >= 0 && menuItemList.size() > i) {
 161                         glassMenu.remove(i);
 162                     }
 163                 }
 164                 for (int i = from; i < to; i++) {
 165                     MenuItemBase item = change.getList().get(i);
 166                     if (item instanceof MenuBase) {
 167                         insertMenu(glassMenu, (MenuBase)item, i);
 168                     } else {
 169                         insertMenuItem(glassMenu, item, i);
 170                     }
 171                 }
 172             }
 173         });
 174 
 175         for (MenuItemBase item : items) {
 176             if (item instanceof MenuBase) {
 177                 // submenu
 178                 addMenu(glassMenu, (MenuBase)item);
 179             } else {
 180                 // menu item
 181                 addMenuItem(glassMenu, item);
 182             }
 183         }