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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2008, 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


 229         int modifiers = event.getModifiers();
 230         // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
 231         if ((type==MouseEvent.MOUSE_ENTERED||
 232              type==MouseEvent.MOUSE_EXITED)
 233             && ((modifiers & (InputEvent.BUTTON1_MASK |
 234                               InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 )) {
 235             return;
 236         }
 237 
 238         if (source != null) {
 239             SwingUtilities.convertPointToScreen(p, source);
 240         }
 241 
 242         screenX = p.x;
 243         screenY = p.y;
 244 
 245         tmp = (Vector<MenuElement>)selection.clone();
 246         selectionSize = tmp.size();
 247         boolean success = false;
 248         for (i=selectionSize - 1;i >= 0 && success == false; i--) {
 249             menuElement = (MenuElement) tmp.elementAt(i);
 250             subElements = menuElement.getSubElements();
 251 
 252             path = null;
 253             for (j = 0, d = subElements.length;j < d && success == false; j++) {
 254                 if (subElements[j] == null)
 255                     continue;
 256                 mc = subElements[j].getComponent();
 257                 if(!mc.isShowing())
 258                     continue;
 259                 if(mc instanceof JComponent) {
 260                     cWidth  = mc.getWidth();
 261                     cHeight = mc.getHeight();
 262                 } else {
 263                     r2 = mc.getBounds();
 264                     cWidth  = r2.width;
 265                     cHeight = r2.height;
 266                 }
 267                 p.x = screenX;
 268                 p.y = screenY;
 269                 SwingUtilities.convertPointFromScreen(p,mc);
 270 
 271                 /** Send the event to visible menu element if menu element currently in
 272                  *  the selected path or contains the event location
 273                  */
 274                 if(
 275                    (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight)) {
 276                     int k;
 277                     if(path == null) {
 278                         path = new MenuElement[i+2];
 279                         for(k=0;k<=i;k++)
 280                             path[k] = (MenuElement)tmp.elementAt(k);
 281                     }
 282                     path[i+1] = subElements[j];
 283                     MenuElement currentSelection[] = getSelectedPath();
 284 
 285                     // Enter/exit detection -- needs tuning...
 286                     if (currentSelection[currentSelection.length-1] !=
 287                         path[i+1] &&
 288                         (currentSelection.length < 2 ||
 289                          currentSelection[currentSelection.length-2] !=
 290                          path[i+1])) {
 291                         Component oldMC = currentSelection[currentSelection.length-1].getComponent();
 292 
 293                         MouseEvent exitEvent = new MouseEvent(oldMC, MouseEvent.MOUSE_EXITED,
 294                                                               event.getWhen(),
 295                                                               event.getModifiers(), p.x, p.y,
 296                                                               event.getXOnScreen(),
 297                                                               event.getYOnScreen(),
 298                                                               event.getClickCount(),
 299                                                               event.isPopupTrigger(),
 300                                                               MouseEvent.NOBUTTON);


 371     public Component componentForPoint(Component source, Point sourcePoint) {
 372         int screenX,screenY;
 373         Point p = sourcePoint;
 374         int i,c,j,d;
 375         Component mc;
 376         Rectangle r2;
 377         int cWidth,cHeight;
 378         MenuElement menuElement;
 379         MenuElement subElements[];
 380         Vector<MenuElement> tmp;
 381         int selectionSize;
 382 
 383         SwingUtilities.convertPointToScreen(p,source);
 384 
 385         screenX = p.x;
 386         screenY = p.y;
 387 
 388         tmp = (Vector<MenuElement>)selection.clone();
 389         selectionSize = tmp.size();
 390         for(i=selectionSize - 1 ; i >= 0 ; i--) {
 391             menuElement = (MenuElement) tmp.elementAt(i);
 392             subElements = menuElement.getSubElements();
 393 
 394             for(j = 0, d = subElements.length ; j < d ; j++) {
 395                 if (subElements[j] == null)
 396                     continue;
 397                 mc = subElements[j].getComponent();
 398                 if(!mc.isShowing())
 399                     continue;
 400                 if(mc instanceof JComponent) {
 401                     cWidth  = mc.getWidth();
 402                     cHeight = mc.getHeight();
 403                 } else {
 404                     r2 = mc.getBounds();
 405                     cWidth  = r2.width;
 406                     cHeight = r2.height;
 407                 }
 408                 p.x = screenX;
 409                 p.y = screenY;
 410                 SwingUtilities.convertPointFromScreen(p,mc);
 411 


   1 /*
   2  * Copyright (c) 1997, 2014, 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


 229         int modifiers = event.getModifiers();
 230         // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
 231         if ((type==MouseEvent.MOUSE_ENTERED||
 232              type==MouseEvent.MOUSE_EXITED)
 233             && ((modifiers & (InputEvent.BUTTON1_MASK |
 234                               InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 )) {
 235             return;
 236         }
 237 
 238         if (source != null) {
 239             SwingUtilities.convertPointToScreen(p, source);
 240         }
 241 
 242         screenX = p.x;
 243         screenY = p.y;
 244 
 245         tmp = (Vector<MenuElement>)selection.clone();
 246         selectionSize = tmp.size();
 247         boolean success = false;
 248         for (i=selectionSize - 1;i >= 0 && success == false; i--) {
 249             menuElement = tmp.elementAt(i);
 250             subElements = menuElement.getSubElements();
 251 
 252             path = null;
 253             for (j = 0, d = subElements.length;j < d && success == false; j++) {
 254                 if (subElements[j] == null)
 255                     continue;
 256                 mc = subElements[j].getComponent();
 257                 if(!mc.isShowing())
 258                     continue;
 259                 if(mc instanceof JComponent) {
 260                     cWidth  = mc.getWidth();
 261                     cHeight = mc.getHeight();
 262                 } else {
 263                     r2 = mc.getBounds();
 264                     cWidth  = r2.width;
 265                     cHeight = r2.height;
 266                 }
 267                 p.x = screenX;
 268                 p.y = screenY;
 269                 SwingUtilities.convertPointFromScreen(p,mc);
 270 
 271                 /** Send the event to visible menu element if menu element currently in
 272                  *  the selected path or contains the event location
 273                  */
 274                 if(
 275                    (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight)) {
 276                     int k;
 277                     if(path == null) {
 278                         path = new MenuElement[i+2];
 279                         for(k=0;k<=i;k++)
 280                             path[k] = tmp.elementAt(k);
 281                     }
 282                     path[i+1] = subElements[j];
 283                     MenuElement currentSelection[] = getSelectedPath();
 284 
 285                     // Enter/exit detection -- needs tuning...
 286                     if (currentSelection[currentSelection.length-1] !=
 287                         path[i+1] &&
 288                         (currentSelection.length < 2 ||
 289                          currentSelection[currentSelection.length-2] !=
 290                          path[i+1])) {
 291                         Component oldMC = currentSelection[currentSelection.length-1].getComponent();
 292 
 293                         MouseEvent exitEvent = new MouseEvent(oldMC, MouseEvent.MOUSE_EXITED,
 294                                                               event.getWhen(),
 295                                                               event.getModifiers(), p.x, p.y,
 296                                                               event.getXOnScreen(),
 297                                                               event.getYOnScreen(),
 298                                                               event.getClickCount(),
 299                                                               event.isPopupTrigger(),
 300                                                               MouseEvent.NOBUTTON);


 371     public Component componentForPoint(Component source, Point sourcePoint) {
 372         int screenX,screenY;
 373         Point p = sourcePoint;
 374         int i,c,j,d;
 375         Component mc;
 376         Rectangle r2;
 377         int cWidth,cHeight;
 378         MenuElement menuElement;
 379         MenuElement subElements[];
 380         Vector<MenuElement> tmp;
 381         int selectionSize;
 382 
 383         SwingUtilities.convertPointToScreen(p,source);
 384 
 385         screenX = p.x;
 386         screenY = p.y;
 387 
 388         tmp = (Vector<MenuElement>)selection.clone();
 389         selectionSize = tmp.size();
 390         for(i=selectionSize - 1 ; i >= 0 ; i--) {
 391             menuElement = tmp.elementAt(i);
 392             subElements = menuElement.getSubElements();
 393 
 394             for(j = 0, d = subElements.length ; j < d ; j++) {
 395                 if (subElements[j] == null)
 396                     continue;
 397                 mc = subElements[j].getComponent();
 398                 if(!mc.isShowing())
 399                     continue;
 400                 if(mc instanceof JComponent) {
 401                     cWidth  = mc.getWidth();
 402                     cHeight = mc.getHeight();
 403                 } else {
 404                     r2 = mc.getBounds();
 405                     cWidth  = r2.width;
 406                     cHeight = r2.height;
 407                 }
 408                 p.x = screenX;
 409                 p.y = screenY;
 410                 SwingUtilities.convertPointFromScreen(p,mc);
 411