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

Print this page




 204             }
 205         }
 206     }
 207 
 208     /**
 209      * When a MenuElement receives an event from a MouseListener, it should never process the event
 210      * directly. Instead all MenuElements should call this method with the event.
 211      *
 212      * @param event  a MouseEvent object
 213      */
 214     public void processMouseEvent(MouseEvent event) {
 215         int screenX,screenY;
 216         Point p;
 217         int i,c,j,d;
 218         Component mc;
 219         Rectangle r2;
 220         int cWidth,cHeight;
 221         MenuElement menuElement;
 222         MenuElement subElements[];
 223         MenuElement path[];
 224         Vector<MenuElement> tmp;
 225         int selectionSize;
 226         p = event.getPoint();
 227 
 228         Component source = event.getComponent();
 229 
 230         if ((source != null) && !source.isShowing()) {
 231             // This can happen if a mouseReleased removes the
 232             // containing component -- bug 4146684
 233             return;
 234         }
 235 
 236         int type = event.getID();
 237         int modifiers = event.getModifiers();
 238         // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
 239         if ((type==MouseEvent.MOUSE_ENTERED||
 240              type==MouseEvent.MOUSE_EXITED)
 241             && ((modifiers & (InputEvent.BUTTON1_MASK |
 242                               InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 )) {
 243             return;
 244         }
 245 
 246         if (source != null) {
 247             SwingUtilities.convertPointToScreen(p, source);
 248         }
 249 
 250         screenX = p.x;
 251         screenY = p.y;
 252 
 253         tmp = (Vector<MenuElement>)selection.clone();

 254         selectionSize = tmp.size();
 255         boolean success = false;
 256         for (i=selectionSize - 1;i >= 0 && success == false; i--) {
 257             menuElement = tmp.elementAt(i);
 258             subElements = menuElement.getSubElements();
 259 
 260             path = null;
 261             for (j = 0, d = subElements.length;j < d && success == false; j++) {
 262                 if (subElements[j] == null)
 263                     continue;
 264                 mc = subElements[j].getComponent();
 265                 if(!mc.isShowing())
 266                     continue;
 267                 if(mc instanceof JComponent) {
 268                     cWidth  = mc.getWidth();
 269                     cHeight = mc.getHeight();
 270                 } else {
 271                     r2 = mc.getBounds();
 272                     cWidth  = r2.width;
 273                     cHeight = r2.height;


 368      * Returns the component in the currently selected path
 369      * which contains sourcePoint.
 370      *
 371      * @param source The component in whose coordinate space sourcePoint
 372      *        is given
 373      * @param sourcePoint The point which is being tested
 374      * @return The component in the currently selected path which
 375      *         contains sourcePoint (relative to the source component's
 376      *         coordinate space.  If sourcePoint is not inside a component
 377      *         on the currently selected path, null is returned.
 378      */
 379     public Component componentForPoint(Component source, Point sourcePoint) {
 380         int screenX,screenY;
 381         Point p = sourcePoint;
 382         int i,c,j,d;
 383         Component mc;
 384         Rectangle r2;
 385         int cWidth,cHeight;
 386         MenuElement menuElement;
 387         MenuElement subElements[];
 388         Vector<MenuElement> tmp;
 389         int selectionSize;
 390 
 391         SwingUtilities.convertPointToScreen(p,source);
 392 
 393         screenX = p.x;
 394         screenY = p.y;
 395 
 396         tmp = (Vector<MenuElement>)selection.clone();

 397         selectionSize = tmp.size();
 398         for(i=selectionSize - 1 ; i >= 0 ; i--) {
 399             menuElement = tmp.elementAt(i);
 400             subElements = menuElement.getSubElements();
 401 
 402             for(j = 0, d = subElements.length ; j < d ; j++) {
 403                 if (subElements[j] == null)
 404                     continue;
 405                 mc = subElements[j].getComponent();
 406                 if(!mc.isShowing())
 407                     continue;
 408                 if(mc instanceof JComponent) {
 409                     cWidth  = mc.getWidth();
 410                     cHeight = mc.getHeight();
 411                 } else {
 412                     r2 = mc.getBounds();
 413                     cWidth  = r2.width;
 414                     cHeight = r2.height;
 415                 }
 416                 p.x = screenX;




 204             }
 205         }
 206     }
 207 
 208     /**
 209      * When a MenuElement receives an event from a MouseListener, it should never process the event
 210      * directly. Instead all MenuElements should call this method with the event.
 211      *
 212      * @param event  a MouseEvent object
 213      */
 214     public void processMouseEvent(MouseEvent event) {
 215         int screenX,screenY;
 216         Point p;
 217         int i,c,j,d;
 218         Component mc;
 219         Rectangle r2;
 220         int cWidth,cHeight;
 221         MenuElement menuElement;
 222         MenuElement subElements[];
 223         MenuElement path[];

 224         int selectionSize;
 225         p = event.getPoint();
 226 
 227         Component source = event.getComponent();
 228 
 229         if ((source != null) && !source.isShowing()) {
 230             // This can happen if a mouseReleased removes the
 231             // containing component -- bug 4146684
 232             return;
 233         }
 234 
 235         int type = event.getID();
 236         int modifiers = event.getModifiers();
 237         // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
 238         if ((type==MouseEvent.MOUSE_ENTERED||
 239              type==MouseEvent.MOUSE_EXITED)
 240             && ((modifiers & (InputEvent.BUTTON1_MASK |
 241                               InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 )) {
 242             return;
 243         }
 244 
 245         if (source != null) {
 246             SwingUtilities.convertPointToScreen(p, source);
 247         }
 248 
 249         screenX = p.x;
 250         screenY = p.y;
 251 
 252         @SuppressWarnings("unchecked")
 253         Vector<MenuElement> tmp = (Vector<MenuElement>)selection.clone();
 254         selectionSize = tmp.size();
 255         boolean success = false;
 256         for (i=selectionSize - 1;i >= 0 && success == false; i--) {
 257             menuElement = tmp.elementAt(i);
 258             subElements = menuElement.getSubElements();
 259 
 260             path = null;
 261             for (j = 0, d = subElements.length;j < d && success == false; j++) {
 262                 if (subElements[j] == null)
 263                     continue;
 264                 mc = subElements[j].getComponent();
 265                 if(!mc.isShowing())
 266                     continue;
 267                 if(mc instanceof JComponent) {
 268                     cWidth  = mc.getWidth();
 269                     cHeight = mc.getHeight();
 270                 } else {
 271                     r2 = mc.getBounds();
 272                     cWidth  = r2.width;
 273                     cHeight = r2.height;


 368      * Returns the component in the currently selected path
 369      * which contains sourcePoint.
 370      *
 371      * @param source The component in whose coordinate space sourcePoint
 372      *        is given
 373      * @param sourcePoint The point which is being tested
 374      * @return The component in the currently selected path which
 375      *         contains sourcePoint (relative to the source component's
 376      *         coordinate space.  If sourcePoint is not inside a component
 377      *         on the currently selected path, null is returned.
 378      */
 379     public Component componentForPoint(Component source, Point sourcePoint) {
 380         int screenX,screenY;
 381         Point p = sourcePoint;
 382         int i,c,j,d;
 383         Component mc;
 384         Rectangle r2;
 385         int cWidth,cHeight;
 386         MenuElement menuElement;
 387         MenuElement subElements[];

 388         int selectionSize;
 389 
 390         SwingUtilities.convertPointToScreen(p,source);
 391 
 392         screenX = p.x;
 393         screenY = p.y;
 394 
 395         @SuppressWarnings("unchecked")
 396         Vector<MenuElement> tmp = (Vector<MenuElement>)selection.clone();
 397         selectionSize = tmp.size();
 398         for(i=selectionSize - 1 ; i >= 0 ; i--) {
 399             menuElement = tmp.elementAt(i);
 400             subElements = menuElement.getSubElements();
 401 
 402             for(j = 0, d = subElements.length ; j < d ; j++) {
 403                 if (subElements[j] == null)
 404                     continue;
 405                 mc = subElements[j].getComponent();
 406                 if(!mc.isShowing())
 407                     continue;
 408                 if(mc instanceof JComponent) {
 409                     cWidth  = mc.getWidth();
 410                     cHeight = mc.getHeight();
 411                 } else {
 412                     r2 = mc.getBounds();
 413                     cWidth  = r2.width;
 414                     cHeight = r2.height;
 415                 }
 416                 p.x = screenX;