< prev index next >

src/java.desktop/share/classes/javax/swing/MenuSelectionManager.java

Print this page




  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
  23  * questions.
  24  */
  25 package javax.swing;
  26 
  27 import java.awt.*;
  28 import java.util.*;
  29 import java.awt.event.*;
  30 import javax.swing.event.*;
  31 
  32 import sun.awt.AppContext;


  33 import sun.swing.SwingUtilities2;
  34 
  35 /**
  36  * A MenuSelectionManager owns the selection in menu hierarchy.
  37  *
  38  * @author Arnaud Weber
  39  * @since 1.2
  40  */
  41 public class MenuSelectionManager {
  42     private Vector<MenuElement> selection = new Vector<MenuElement>();
  43 
  44     /* diagnostic aids -- should be false for production builds. */
  45     private static final boolean TRACE =   false; // trace creates and disposes
  46     private static final boolean VERBOSE = false; // show reuse hits/misses
  47     private static final boolean DEBUG =   false;  // show bad params, misc.
  48 
  49     private static final StringBuilder MENU_SELECTION_MANAGER_KEY =
  50                        new StringBuilder("javax.swing.MenuSelectionManager");
  51 
  52     /**


 291                     }
 292                     path[i+1] = subElements[j];
 293                     MenuElement currentSelection[] = getSelectedPath();
 294 
 295                     // Enter/exit detection -- needs tuning...
 296                     if (currentSelection[currentSelection.length-1] !=
 297                         path[i+1] &&
 298                         (currentSelection.length < 2 ||
 299                          currentSelection[currentSelection.length-2] !=
 300                          path[i+1])) {
 301                         Component oldMC = currentSelection[currentSelection.length-1].getComponent();
 302 
 303                         MouseEvent exitEvent = new MouseEvent(oldMC, MouseEvent.MOUSE_EXITED,
 304                                                               event.getWhen(),
 305                                                               event.getModifiers(), p.x, p.y,
 306                                                               event.getXOnScreen(),
 307                                                               event.getYOnScreen(),
 308                                                               event.getClickCount(),
 309                                                               event.isPopupTrigger(),
 310                                                               MouseEvent.NOBUTTON);



 311                         currentSelection[currentSelection.length-1].
 312                             processMouseEvent(exitEvent, path, this);
 313 
 314                         MouseEvent enterEvent = new MouseEvent(mc,
 315                                                                MouseEvent.MOUSE_ENTERED,
 316                                                                event.getWhen(),
 317                                                                event.getModifiers(), p.x, p.y,
 318                                                                event.getXOnScreen(),
 319                                                                event.getYOnScreen(),
 320                                                                event.getClickCount(),
 321                                                                event.isPopupTrigger(),
 322                                                                MouseEvent.NOBUTTON);


 323                         subElements[j].processMouseEvent(enterEvent, path, this);
 324                     }
 325                     MouseEvent mouseEvent = new MouseEvent(mc, event.getID(),event. getWhen(),
 326                                                            event.getModifiers(), p.x, p.y,
 327                                                            event.getXOnScreen(),
 328                                                            event.getYOnScreen(),
 329                                                            event.getClickCount(),
 330                                                            event.isPopupTrigger(),
 331                                                            MouseEvent.NOBUTTON);



 332                     subElements[j].processMouseEvent(mouseEvent, path, this);
 333                     success = true;
 334                     event.consume();
 335                 }
 336             }
 337         }
 338     }
 339 
 340     private void printMenuElementArray(MenuElement path[]) {
 341         printMenuElementArray(path, false);
 342     }
 343 
 344     private void printMenuElementArray(MenuElement path[], boolean dumpStack) {
 345         System.out.println("Path is(");
 346         int i, j;
 347         for(i=0,j=path.length; i<j ;i++){
 348             for (int k=0; k<=i; k++)
 349                 System.out.print("  ");
 350             MenuElement me = path[i];
 351             if(me instanceof JMenuItem) {




  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
  23  * questions.
  24  */
  25 package javax.swing;
  26 
  27 import java.awt.*;
  28 import java.util.*;
  29 import java.awt.event.*;
  30 import javax.swing.event.*;
  31 
  32 import sun.awt.AppContext;
  33 import sun.awt.AWTAccessor;
  34 import sun.awt.AWTAccessor.MouseEventAccessor;
  35 import sun.swing.SwingUtilities2;
  36 
  37 /**
  38  * A MenuSelectionManager owns the selection in menu hierarchy.
  39  *
  40  * @author Arnaud Weber
  41  * @since 1.2
  42  */
  43 public class MenuSelectionManager {
  44     private Vector<MenuElement> selection = new Vector<MenuElement>();
  45 
  46     /* diagnostic aids -- should be false for production builds. */
  47     private static final boolean TRACE =   false; // trace creates and disposes
  48     private static final boolean VERBOSE = false; // show reuse hits/misses
  49     private static final boolean DEBUG =   false;  // show bad params, misc.
  50 
  51     private static final StringBuilder MENU_SELECTION_MANAGER_KEY =
  52                        new StringBuilder("javax.swing.MenuSelectionManager");
  53 
  54     /**


 293                     }
 294                     path[i+1] = subElements[j];
 295                     MenuElement currentSelection[] = getSelectedPath();
 296 
 297                     // Enter/exit detection -- needs tuning...
 298                     if (currentSelection[currentSelection.length-1] !=
 299                         path[i+1] &&
 300                         (currentSelection.length < 2 ||
 301                          currentSelection[currentSelection.length-2] !=
 302                          path[i+1])) {
 303                         Component oldMC = currentSelection[currentSelection.length-1].getComponent();
 304 
 305                         MouseEvent exitEvent = new MouseEvent(oldMC, MouseEvent.MOUSE_EXITED,
 306                                                               event.getWhen(),
 307                                                               event.getModifiers(), p.x, p.y,
 308                                                               event.getXOnScreen(),
 309                                                               event.getYOnScreen(),
 310                                                               event.getClickCount(),
 311                                                               event.isPopupTrigger(),
 312                                                               MouseEvent.NOBUTTON);
 313                         MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
 314                         meAccessor.setCausedByTouchEvent(exitEvent,
 315                             meAccessor.isCausedByTouchEvent(event));
 316                         currentSelection[currentSelection.length-1].
 317                             processMouseEvent(exitEvent, path, this);
 318 
 319                         MouseEvent enterEvent = new MouseEvent(mc,
 320                                                                MouseEvent.MOUSE_ENTERED,
 321                                                                event.getWhen(),
 322                                                                event.getModifiers(), p.x, p.y,
 323                                                                event.getXOnScreen(),
 324                                                                event.getYOnScreen(),
 325                                                                event.getClickCount(),
 326                                                                event.isPopupTrigger(),
 327                                                                MouseEvent.NOBUTTON);
 328                         meAccessor.setCausedByTouchEvent(enterEvent,
 329                             meAccessor.isCausedByTouchEvent(event));
 330                         subElements[j].processMouseEvent(enterEvent, path, this);
 331                     }
 332                     MouseEvent mouseEvent = new MouseEvent(mc, event.getID(),event. getWhen(),
 333                                                            event.getModifiers(), p.x, p.y,
 334                                                            event.getXOnScreen(),
 335                                                            event.getYOnScreen(),
 336                                                            event.getClickCount(),
 337                                                            event.isPopupTrigger(),
 338                                                            MouseEvent.NOBUTTON);
 339                     MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
 340                     meAccessor.setCausedByTouchEvent(mouseEvent,
 341                         meAccessor.isCausedByTouchEvent(event));
 342                     subElements[j].processMouseEvent(mouseEvent, path, this);
 343                     success = true;
 344                     event.consume();
 345                 }
 346             }
 347         }
 348     }
 349 
 350     private void printMenuElementArray(MenuElement path[]) {
 351         printMenuElementArray(path, false);
 352     }
 353 
 354     private void printMenuElementArray(MenuElement path[], boolean dumpStack) {
 355         System.out.println("Path is(");
 356         int i, j;
 357         for(i=0,j=path.length; i<j ;i++){
 358             for (int k=0; k<=i; k++)
 359                 System.out.print("  ");
 360             MenuElement me = path[i];
 361             if(me instanceof JMenuItem) {


< prev index next >