< prev index next >

src/java.desktop/macosx/classes/com/apple/laf/ScreenMenu.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  50                 }
  51             });
  52     }
  53 
  54     // screen menu stuff
  55     private static native long addMenuListeners(ScreenMenu listener, long nativeMenu);
  56     private static native void removeMenuListeners(long modelPtr);
  57 
  58     private transient long fModelPtr;
  59 
  60     private final Hashtable<Component, MenuItem> fItems;
  61     private final JMenu fInvoker;
  62 
  63     private Component fLastMouseEventTarget;
  64     private Rectangle fLastTargetRect;
  65     private volatile Rectangle[] fItemBounds;
  66 
  67     private ScreenMenuPropertyListener fPropertyListener;
  68 
  69     // Array of child hashes used to see if we need to recreate the Menu.
  70     private int childHashArray[];
  71 
  72     ScreenMenu(final JMenu invoker) {
  73         super(invoker.getText());
  74         fInvoker = invoker;
  75 
  76         int count = fInvoker.getMenuComponentCount();
  77         if (count < 5) count = 5;
  78         fItems = new Hashtable<Component, MenuItem>(count);
  79         setEnabled(fInvoker.isEnabled());
  80         updateItems();
  81     }
  82 
  83     /**
  84      * Determine if we need to tear down the Menu and re-create it, since the contents may have changed in the Menu opened listener and
  85      * we do not get notified of it, because EDT is busy in our code. We only need to update if the menu contents have changed in some
  86      * way, such as the number of menu items, the text of the menuitems, icon, shortcut etc.
  87      */
  88     private static boolean needsUpdate(final Component items[], final int childHashArray[]) {
  89       if (items == null || childHashArray == null) {
  90         return true;
  91       }
  92       if (childHashArray.length != items.length) {
  93        return true;
  94       }
  95       for (int i = 0; i < items.length; i++) {
  96           final int hashCode = getHashCode(items[i]);
  97           if (hashCode != childHashArray[i]) {
  98             return true;
  99           }
 100       }
 101       return false;
 102     }
 103 
 104     /**
 105      * Used to recreate the AWT based Menu structure that implements the Screen Menu.
 106      * Also computes hashcode and stores them so that we can compare them later in needsUpdate.
 107      */
 108     private void updateItems() {


   1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  50                 }
  51             });
  52     }
  53 
  54     // screen menu stuff
  55     private static native long addMenuListeners(ScreenMenu listener, long nativeMenu);
  56     private static native void removeMenuListeners(long modelPtr);
  57 
  58     private transient long fModelPtr;
  59 
  60     private final Hashtable<Component, MenuItem> fItems;
  61     private final JMenu fInvoker;
  62 
  63     private Component fLastMouseEventTarget;
  64     private Rectangle fLastTargetRect;
  65     private volatile Rectangle[] fItemBounds;
  66 
  67     private ScreenMenuPropertyListener fPropertyListener;
  68 
  69     // Array of child hashes used to see if we need to recreate the Menu.
  70     private int[] childHashArray;
  71 
  72     ScreenMenu(final JMenu invoker) {
  73         super(invoker.getText());
  74         fInvoker = invoker;
  75 
  76         int count = fInvoker.getMenuComponentCount();
  77         if (count < 5) count = 5;
  78         fItems = new Hashtable<Component, MenuItem>(count);
  79         setEnabled(fInvoker.isEnabled());
  80         updateItems();
  81     }
  82 
  83     /**
  84      * Determine if we need to tear down the Menu and re-create it, since the contents may have changed in the Menu opened listener and
  85      * we do not get notified of it, because EDT is busy in our code. We only need to update if the menu contents have changed in some
  86      * way, such as the number of menu items, the text of the menuitems, icon, shortcut etc.
  87      */
  88     private static boolean needsUpdate(final Component[] items, final int[] childHashArray) {
  89       if (items == null || childHashArray == null) {
  90         return true;
  91       }
  92       if (childHashArray.length != items.length) {
  93        return true;
  94       }
  95       for (int i = 0; i < items.length; i++) {
  96           final int hashCode = getHashCode(items[i]);
  97           if (hashCode != childHashArray[i]) {
  98             return true;
  99           }
 100       }
 101       return false;
 102     }
 103 
 104     /**
 105      * Used to recreate the AWT based Menu structure that implements the Screen Menu.
 106      * Also computes hashcode and stores them so that we can compare them later in needsUpdate.
 107      */
 108     private void updateItems() {


< prev index next >