KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > awt > JMenuPlus


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.openide.awt;
20
21 import java.awt.*;
22
23 import javax.swing.*;
24
25
26 /** A subclass of JMenu which provides workaround for pre-JDK 1.2.2 JMenu positioning problem.
27  * It assures, that the popup menu gets placed inside visible screen area.
28  * It also improves placement of popups in the case the subclass lazily changes
29  * the content from getPopupMenu().
30  * @deprecated doesn't do anything special anymore - since org.openide.awt 6.5
31  */

32 public class JMenuPlus extends JMenu {
33     static final long serialVersionUID = -7700146216422707913L;
34 // private static final boolean NO_POPUP_PLACEMENT_HACK = Boolean.getBoolean("netbeans.popup.no_hack"); // NOI18N
35

36     public JMenuPlus() {
37         this(""); // NOI18N
38
}
39
40     public JMenuPlus(String JavaDoc label) {
41         super(label);
42
43         enableInputMethods(false);
44
45         getAccessibleContext().setAccessibleDescription(label);
46     }
47
48 // /** Overriden to provide better strategy for placing the JMenu on the screen.
49
// * @param b a boolean value -- true to make the menu visible, false to hide it
50
// */
51
// public void setPopupMenuVisible(boolean b) {
52
// boolean isVisible = isPopupMenuVisible();
53
//
54
// if (b != isVisible) {
55
// if ((b == true) && isShowing()) {
56
//// // The order of calls is a provision for subclassers that
57
//// // change the content of the menu during getPopupMenu()
58
//// // We compute the origin later with properly filled popup
59
// JPopupMenu popup = getPopupMenu();
60
////
61
//// // HACK[pnejedly]: Notify all the items in the menu we're going to show
62
//// JInlineMenu.prepareItemsInContainer(popup);
63
////
64
//// // End of HACK
65
//// // HACK[mkleint]: Notify all the items in the menu we're going to show
66
//// // #40824 - when the text changes, it's too late to update in popup.show() (which triggers the updateState() in the MenuBridge.
67
//// Actions.prepareMenuBridgeItemsInContainer(popup);
68
//
69
// // End of HACK
70
//// if (NO_POPUP_PLACEMENT_HACK) {
71
// Point p = super.getPopupMenuOrigin();
72
// popup.show(this, p.x, p.y);
73
//// } else {
74
//// Point p = getPopupMenuOrigin(popup);
75
//// popup.show(this, p.x, p.y);
76
//// }
77
// } else {
78
// getPopupMenu().setVisible(false);
79
// }
80
// }
81
// }
82

83 // /** Overriden to provide better strategy for placing the JMenu on the screen.
84
// *
85
// * @return a Point in the coordinate space of the menu instance
86
// * which should be used as the origin of the JMenu's popup menu.
87
// */
88
// protected Point getPopupMenuOrigin(JPopupMenu pm) {
89
// int x = 0;
90
// int y = 0;
91
// Rectangle screenRect = JPopupMenuUtils.getScreenRect();
92
// Dimension s = getSize();
93
// Dimension pmSize = pm.getSize();
94
// int screenRight = screenRect.x + screenRect.width;
95
// int screenBottom = screenRect.y + screenRect.height;
96
//
97
// // For the first time the menu is popped up,
98
// // the size has not yet been initiated
99
// if (pmSize.width == 0) {
100
// pmSize = pm.getPreferredSize();
101
// }
102
//
103
// Point position = getLocationOnScreen();
104
//
105
// Container parent = getParent();
106
//
107
// if (parent instanceof JPopupMenu) {
108
// // We are a submenu (pull-right)
109
// // First determine x:
110
// if ((position.x + s.width + pmSize.width) < screenRight) {
111
// x = s.width; // Prefer placement to the right
112
// } else {
113
// x = 0 - pmSize.width; // Otherwise place to the left
114
// }
115
//
116
// // Then the y:
117
// if ((position.y + pmSize.height) < screenBottom) {
118
// y = 0; // Prefer dropping down
119
// } else {
120
// y = s.height - pmSize.height; // Otherwise drop 'up'
121
// }
122
// } else {
123
// // We are a toplevel menu (pull-down)
124
// // First determine the x:
125
// if ((position.x + pmSize.width) < screenRight) {
126
// x = 0; // Prefer extending to right
127
// } else {
128
// x = s.width - pmSize.width; // Otherwise extend to left
129
// }
130
//
131
// // Then the y:
132
// if ((position.y + s.height + pmSize.height) < screenBottom) {
133
// y = s.height; // Prefer dropping down
134
// } else {
135
// y = 0 - pmSize.height; // Otherwise drop 'up'
136
// }
137
// }
138
//
139
// if (y < -position.y) {
140
// y = -position.y;
141
// }
142
//
143
// if (x < -position.x) {
144
// x = -position.x;
145
// }
146
//
147
// return new Point(x, y);
148
// }
149
}
150
Popular Tags