1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
199 /************************************************
200 *
201 * Utility functions
202 *
203 ************************************************/
204
205 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
206 //near the periphery of the screen, XToolkit
207
208 /**
209 * Calculates placement of popup menu window
210 * given origin in global coordinates and
211 * size of menu window. Returns suggested
212 * rectangle for menu window in global coordinates
213 * @param origin the origin point specified in show()
214 * function converted to global coordinates
215 * @param windowSize the desired size of menu's window
216 */
217 protected Rectangle getWindowBounds(Point origin, Dimension windowSize) {
218 Rectangle globalBounds = new Rectangle(origin.x, origin.y, 0, 0);
219 Dimension screenSize = graphicsConfig.getBounds().getSize();
220 Rectangle res;
221 res = fitWindowRight(globalBounds, windowSize, screenSize);
222 if (res != null) {
223 return res;
224 }
225 res = fitWindowLeft(globalBounds, windowSize, screenSize);
226 if (res != null) {
227 return res;
228 }
229 res = fitWindowBelow(globalBounds, windowSize, screenSize);
230 if (res != null) {
231 return res;
232 }
233 res = fitWindowAbove(globalBounds, windowSize, screenSize);
234 if (res != null) {
235 return res;
236 }
237 return fitWindowToScreen(windowSize, screenSize);
238 }
239
240 /************************************************
241 *
242 * Overriden XMenuWindow caption-painting functions
243 * Necessary to fix 6267144: PIT: Popup menu label is not shown, XToolkit
244 *
245 ************************************************/
246 /**
247 * Returns height of menu window's caption.
248 * Can be overriden for popup menus and tear-off menus
249 */
250 protected Dimension getCaptionSize() {
251 String s = getTargetLabel();
252 if (s.equals("")) {
253 return null;
254 }
255 Graphics g = getGraphics();
256 if (g == null) {
257 return null;
|
1 /*
2 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
199 /************************************************
200 *
201 * Utility functions
202 *
203 ************************************************/
204
205 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened
206 //near the periphery of the screen, XToolkit
207
208 /**
209 * Calculates placement of popup menu window
210 * given origin in global coordinates and
211 * size of menu window. Returns suggested
212 * rectangle for menu window in global coordinates
213 * @param origin the origin point specified in show()
214 * function converted to global coordinates
215 * @param windowSize the desired size of menu's window
216 */
217 protected Rectangle getWindowBounds(Point origin, Dimension windowSize) {
218 Rectangle globalBounds = new Rectangle(origin.x, origin.y, 0, 0);
219 Rectangle screenBounds = getCurrentGraphicsConfiguration().getBounds();
220 Rectangle res;
221 res = fitWindowRight(globalBounds, windowSize, screenBounds);
222 if (res != null) {
223 return res;
224 }
225 res = fitWindowLeft(globalBounds, windowSize, screenBounds);
226 if (res != null) {
227 return res;
228 }
229 res = fitWindowBelow(globalBounds, windowSize, screenBounds);
230 if (res != null) {
231 return res;
232 }
233 res = fitWindowAbove(globalBounds, windowSize, screenBounds);
234 if (res != null) {
235 return res;
236 }
237 return fitWindowToScreen(windowSize, screenBounds);
238 }
239
240 /************************************************
241 *
242 * Overriden XMenuWindow caption-painting functions
243 * Necessary to fix 6267144: PIT: Popup menu label is not shown, XToolkit
244 *
245 ************************************************/
246 /**
247 * Returns height of menu window's caption.
248 * Can be overriden for popup menus and tear-off menus
249 */
250 protected Dimension getCaptionSize() {
251 String s = getTargetLabel();
252 if (s.equals("")) {
253 return null;
254 }
255 Graphics g = getGraphics();
256 if (g == null) {
257 return null;
|