< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WPopupMenuPeer.java

Print this page




  53             if (parentPeer == null) {
  54                 // because the menu isn't a component (sigh) we first have to wait
  55                 // for a failure to map the peer which should only happen for a
  56                 // lightweight container, then find the actual native parent from
  57                 // that component.
  58                 parent = WToolkit.getNativeContainer((Component)parent);
  59                 parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent);
  60             }
  61             parentPeer.addChildPeer(this);
  62             createMenu(parentPeer);
  63             // fix for 5088782: check if menu object is created successfully
  64             checkMenuCreation();
  65         } else {
  66             throw new IllegalArgumentException(
  67                 "illegal popup menu container class");
  68         }
  69     }
  70 
  71     private native void createMenu(WComponentPeer parent);
  72 

  73     public void show(Event e) {
  74         Component origin = (Component)e.target;
  75         WComponentPeer peer = (WComponentPeer) WToolkit.targetToPeer(origin);
  76         if (peer == null) {
  77             // A failure to map the peer should only happen for a
  78             // lightweight component, then find the actual native parent from
  79             // that component.  The event coorinates are going to have to be
  80             // remapped as well.
  81             Component nativeOrigin = WToolkit.getNativeContainer(origin);
  82             e.target = nativeOrigin;
  83 
  84             // remove the event coordinates
  85             for (Component c = origin; c != nativeOrigin; c = c.getParent()) {
  86                 Point p = c.getLocation();
  87                 e.x += p.x;
  88                 e.y += p.y;
  89             }
  90         }
  91         _show(e);
  92     }
  93 
  94     /*
  95      * This overloaded method is for TrayIcon.
  96      * Its popup has special parent.
  97      */
  98     void show(Component origin, Point p) {
  99         WComponentPeer peer = (WComponentPeer) WToolkit.targetToPeer(origin);

 100         Event e = new Event(origin, 0, Event.MOUSE_DOWN, p.x, p.y, 0, 0);
 101         if (peer == null) {
 102             Component nativeOrigin = WToolkit.getNativeContainer(origin);
 103             e.target = nativeOrigin;
 104         }
 105         e.x = p.x;
 106         e.y = p.y;
 107         _show(e);
 108     }
 109 

 110     private native void _show(Event e);
 111 }


  53             if (parentPeer == null) {
  54                 // because the menu isn't a component (sigh) we first have to wait
  55                 // for a failure to map the peer which should only happen for a
  56                 // lightweight container, then find the actual native parent from
  57                 // that component.
  58                 parent = WToolkit.getNativeContainer((Component)parent);
  59                 parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent);
  60             }
  61             parentPeer.addChildPeer(this);
  62             createMenu(parentPeer);
  63             // fix for 5088782: check if menu object is created successfully
  64             checkMenuCreation();
  65         } else {
  66             throw new IllegalArgumentException(
  67                 "illegal popup menu container class");
  68         }
  69     }
  70 
  71     private native void createMenu(WComponentPeer parent);
  72 
  73     @SuppressWarnings("deprecation")
  74     public void show(Event e) {
  75         Component origin = (Component)e.target;
  76         WComponentPeer peer = (WComponentPeer) WToolkit.targetToPeer(origin);
  77         if (peer == null) {
  78             // A failure to map the peer should only happen for a
  79             // lightweight component, then find the actual native parent from
  80             // that component.  The event coorinates are going to have to be
  81             // remapped as well.
  82             Component nativeOrigin = WToolkit.getNativeContainer(origin);
  83             e.target = nativeOrigin;
  84 
  85             // remove the event coordinates
  86             for (Component c = origin; c != nativeOrigin; c = c.getParent()) {
  87                 Point p = c.getLocation();
  88                 e.x += p.x;
  89                 e.y += p.y;
  90             }
  91         }
  92         _show(e);
  93     }
  94 
  95     /*
  96      * This overloaded method is for TrayIcon.
  97      * Its popup has special parent.
  98      */
  99     void show(Component origin, Point p) {
 100         WComponentPeer peer = (WComponentPeer) WToolkit.targetToPeer(origin);
 101         @SuppressWarnings("deprecation")
 102         Event e = new Event(origin, 0, Event.MOUSE_DOWN, p.x, p.y, 0, 0);
 103         if (peer == null) {
 104             Component nativeOrigin = WToolkit.getNativeContainer(origin);
 105             e.target = nativeOrigin;
 106         }
 107         e.x = p.x;
 108         e.y = p.y;
 109         _show(e);
 110     }
 111 
 112     @SuppressWarnings("deprecation")
 113     private native void _show(Event e);
 114 }
< prev index next >