01: /*
02: * @(#)PPCPopupMenuPeer.java 1.9 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package sun.awt.pocketpc;
28:
29: import java.awt.*;
30: import sun.awt.peer.*;
31:
32: /**
33: *
34: *
35: * @author Nicholas Allen
36: */
37:
38: class PPCPopupMenuPeer extends PPCMenuPeer implements PopupMenuPeer {
39:
40: public PPCPopupMenuPeer(PopupMenu target) {
41: this .target = target;
42:
43: if (target.getParent() instanceof Component) {
44: Component parent = (Component) target.getParent();
45: ComponentPeer peer = PPCToolkit.getComponentPeer(parent);
46: PPCComponentPeer parentPeer = null;
47: if (peer instanceof PPCComponentPeer) {
48: parentPeer = (PPCComponentPeer) peer;
49: } else {
50: // because the menu isn't a component (sigh) we first have to wait
51: // for a failure to map the peer which should only happen for a
52: // lightweight container, then find the actual native parent from
53: // that component.
54: parent = PPCToolkit.getNativeContainer(parent);
55: parentPeer = (PPCComponentPeer) PPCToolkit
56: .getComponentPeer(parent);
57: }
58: createMenu(parentPeer);
59: } else {
60: throw new IllegalArgumentException(
61: "illegal popup menu container class");
62: }
63: }
64:
65: native void createMenu(PPCComponentPeer parent);
66:
67: public void show(Component origin, int x, int y) {
68:
69: Event e = new Event(origin, 0, 0, x, y, 0, 0);
70:
71: //PPCComponentPeer peer = (PPCComponentPeer) PPCToolkit.getComponentPeer(origin);
72: if (!(PPCToolkit.getComponentPeer(origin) instanceof PPCComponentPeer)) {
73: // A failure to map the peer should only happen for a
74: // lightweight component, then find the actual native parent from
75: // that component. The event coorinates are going to have to be
76: // remapped as well.
77: Component nativeOrigin = PPCToolkit
78: .getNativeContainer(origin);
79: e.target = nativeOrigin;
80:
81: // remove the event coordinates
82: for (Component c = origin; c != nativeOrigin; c = c
83: .getParent()) {
84: Point p = c.getLocation();
85: e.x += p.x;
86: e.y += p.y;
87: }
88: }
89:
90: showPopup(e);
91: }
92:
93: public native void showPopup(Event e);
94:
95: }
|