src/solaris/classes/sun/awt/X11/XBaseMenuWindow.java

Print this page
rev 9830 : 8039642: Fix raw and unchecked warnings in sun.awt.*
Reviewed-by: darcy, prr


 214 
 215 
 216     /**
 217      * This function is to be called if it's likely that size
 218      * of items was changed. It can be called from any thread
 219      * in any locked state, so it should not take locks
 220      */
 221     protected abstract void updateSize();
 222 
 223     /************************************************
 224      *
 225      * Initialization
 226      *
 227      ************************************************/
 228 
 229     /**
 230      * Overrides XBaseWindow.instantPreInit
 231      */
 232     void instantPreInit(XCreateWindowParams params) {
 233         super.instantPreInit(params);
 234         items = new ArrayList();
 235     }
 236 
 237     /************************************************
 238      *
 239      * General-purpose functions
 240      *
 241      ************************************************/
 242 
 243     /**
 244      * Returns static lock used for menus
 245      */
 246     static Object getMenuTreeLock() {
 247         return menuTreeLock;
 248     }
 249 
 250     /**
 251      * This function is called to clear all saved
 252      * size data.
 253      */
 254     protected void resetMapping() {


 350             if (selectedIndex == index) {
 351                 selectItem(null, false);
 352             } else if (selectedIndex > index) {
 353                 selectedIndex--;
 354             }
 355             if (index < items.size()) {
 356                 items.remove(index);
 357             } else {
 358                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 359                     log.fine("WARNING: Attempt to remove non-existing menu item, index : " + index + ", item count : " + items.size());
 360                 }
 361             }
 362         }
 363         updateSize();
 364     }
 365 
 366     /**
 367      * Clears items vector and loads specified vector
 368      * @param items vector to be loaded
 369      */
 370     public void reloadItems(Vector items) {
 371         synchronized(getMenuTreeLock()) {
 372             this.items.clear();
 373             MenuItem[] itemArray = (MenuItem[])items.toArray(new MenuItem[] {});
 374             int itemCnt = itemArray.length;
 375             for(int i = 0; i < itemCnt; i++) {
 376                 addItem(itemArray[i]);
 377             }
 378         }
 379     }
 380 
 381     /**
 382      * Select specified item and shows/hides submenus if necessary
 383      * We can not select by index, so we need to select by ref.
 384      * @param item the item to be selected, null to clear selection
 385      * @param showWindowIfMenu if the item is XMenuPeer then its
 386      * window is shown/hidden according to this param.
 387      */
 388     void selectItem(XMenuItemPeer item, boolean showWindowIfMenu) {
 389         synchronized(getMenuTreeLock()) {
 390             XMenuPeer showingSubmenu = getShowingSubmenu();
 391             int newSelectedIndex = (item != null) ? items.indexOf(item) : -1;
 392             if (this.selectedIndex != newSelectedIndex) {
 393                 if (log.isLoggable(PlatformLogger.Level.FINEST)) {




 214 
 215 
 216     /**
 217      * This function is to be called if it's likely that size
 218      * of items was changed. It can be called from any thread
 219      * in any locked state, so it should not take locks
 220      */
 221     protected abstract void updateSize();
 222 
 223     /************************************************
 224      *
 225      * Initialization
 226      *
 227      ************************************************/
 228 
 229     /**
 230      * Overrides XBaseWindow.instantPreInit
 231      */
 232     void instantPreInit(XCreateWindowParams params) {
 233         super.instantPreInit(params);
 234         items = new ArrayList<>();
 235     }
 236 
 237     /************************************************
 238      *
 239      * General-purpose functions
 240      *
 241      ************************************************/
 242 
 243     /**
 244      * Returns static lock used for menus
 245      */
 246     static Object getMenuTreeLock() {
 247         return menuTreeLock;
 248     }
 249 
 250     /**
 251      * This function is called to clear all saved
 252      * size data.
 253      */
 254     protected void resetMapping() {


 350             if (selectedIndex == index) {
 351                 selectItem(null, false);
 352             } else if (selectedIndex > index) {
 353                 selectedIndex--;
 354             }
 355             if (index < items.size()) {
 356                 items.remove(index);
 357             } else {
 358                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 359                     log.fine("WARNING: Attempt to remove non-existing menu item, index : " + index + ", item count : " + items.size());
 360                 }
 361             }
 362         }
 363         updateSize();
 364     }
 365 
 366     /**
 367      * Clears items vector and loads specified vector
 368      * @param items vector to be loaded
 369      */
 370     public void reloadItems(Vector<? extends MenuItem> items) {
 371         synchronized(getMenuTreeLock()) {
 372             this.items.clear();
 373             MenuItem[] itemArray = items.toArray(new MenuItem[] {});
 374             int itemCnt = itemArray.length;
 375             for(int i = 0; i < itemCnt; i++) {
 376                 addItem(itemArray[i]);
 377             }
 378         }
 379     }
 380 
 381     /**
 382      * Select specified item and shows/hides submenus if necessary
 383      * We can not select by index, so we need to select by ref.
 384      * @param item the item to be selected, null to clear selection
 385      * @param showWindowIfMenu if the item is XMenuPeer then its
 386      * window is shown/hidden according to this param.
 387      */
 388     void selectItem(XMenuItemPeer item, boolean showWindowIfMenu) {
 389         synchronized(getMenuTreeLock()) {
 390             XMenuPeer showingSubmenu = getShowingSubmenu();
 391             int newSelectedIndex = (item != null) ? items.indexOf(item) : -1;
 392             if (this.selectedIndex != newSelectedIndex) {
 393                 if (log.isLoggable(PlatformLogger.Level.FINEST)) {