2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.openide.awt;
48
/** A subclass of JMenu which provides workaround for pre-JDK 1.2.2 JMenu positioning problem.
49
* It assures, that the popup menu gets placed inside visible screen area.
50
* It also improves placement of popups in the case the subclass lazily changes
51
* the content from getPopupMenu().
52
* @deprecated doesn't do anything special anymore - since org.openide.awt 6.5
54
public class JMenuPlus extends JMenu {
55
static final long serialVersionUID = -7700146216422707913L;
56
// private static final boolean NO_POPUP_PLACEMENT_HACK = Boolean.getBoolean("netbeans.popup.no_hack"); // NOI18N
62
public JMenuPlus(String label) {
65
enableInputMethods(false);
67
getAccessibleContext().setAccessibleDescription(label);
70
// /** Overriden to provide better strategy for placing the JMenu on the screen.
71
// * @param b a boolean value -- true to make the menu visible, false to hide it
73
// public void setPopupMenuVisible(boolean b) {
74
// boolean isVisible = isPopupMenuVisible();
76
// if (b != isVisible) {
77
// if ((b == true) && isShowing()) {
78
//// // The order of calls is a provision for subclassers that
79
//// // change the content of the menu during getPopupMenu()
80
//// // We compute the origin later with properly filled popup
81
// JPopupMenu popup = getPopupMenu();
83
//// // HACK[pnejedly]: Notify all the items in the menu we're going to show
84
//// JInlineMenu.prepareItemsInContainer(popup);
87
//// // HACK[mkleint]: Notify all the items in the menu we're going to show
88
//// // #40824 - when the text changes, it's too late to update in popup.show() (which triggers the updateState() in the MenuBridge.
89
//// Actions.prepareMenuBridgeItemsInContainer(popup);
92
//// if (NO_POPUP_PLACEMENT_HACK) {
93
// Point p = super.getPopupMenuOrigin();
94
// popup.show(this, p.x, p.y);
96
//// Point p = getPopupMenuOrigin(popup);
97
//// popup.show(this, p.x, p.y);
100
// getPopupMenu().setVisible(false);
105
// /** Overriden to provide better strategy for placing the JMenu on the screen.
107
// * @return a Point in the coordinate space of the menu instance
108
// * which should be used as the origin of the JMenu's popup menu.
110
// protected Point getPopupMenuOrigin(JPopupMenu pm) {
113
// Rectangle screenRect = JPopupMenuUtils.getScreenRect();
114
// Dimension s = getSize();
115
// Dimension pmSize = pm.getSize();
116
// int screenRight = screenRect.x + screenRect.width;
117
// int screenBottom = screenRect.y + screenRect.height;
119
// // For the first time the menu is popped up,
120
// // the size has not yet been initiated
121
// if (pmSize.width == 0) {
122
// pmSize = pm.getPreferredSize();
125
// Point position = getLocationOnScreen();
127
// Container parent = getParent();
129
// if (parent instanceof JPopupMenu) {
130
// // We are a submenu (pull-right)
131
// // First determine x:
132
// if ((position.x + s.width + pmSize.width) < screenRight) {
133
// x = s.width; // Prefer placement to the right
135
// x = 0 - pmSize.width; // Otherwise place to the left
139
// if ((position.y + pmSize.height) < screenBottom) {
140
// y = 0; // Prefer dropping down
142
// y = s.height - pmSize.height; // Otherwise drop 'up'
145
// // We are a toplevel menu (pull-down)
146
// // First determine the x:
147
// if ((position.x + pmSize.width) < screenRight) {
148
// x = 0; // Prefer extending to right
150
// x = s.width - pmSize.width; // Otherwise extend to left
154
// if ((position.y + s.height + pmSize.height) < screenBottom) {
155
// y = s.height; // Prefer dropping down
157
// y = 0 - pmSize.height; // Otherwise drop 'up'
161
// if (y < -position.y) {
165
// if (x < -position.x) {
169
// return new Point(x, y);