This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 20882
Collapse All | Expand All

(-)openide/src/org/openide/util/Utilities.java (-2 / +147 lines)
Lines 41-46 Link Here
41
import java.util.HashSet;
41
import java.util.HashSet;
42
import org.openide.util.enum.SingletonEnumeration;
42
import org.openide.util.enum.SingletonEnumeration;
43
43
44
import org.openide.modules.Dependency;
45
import org.openide.modules.SpecificationVersion;
46
44
/** Otherwise uncategorized useful static methods.
47
/** Otherwise uncategorized useful static methods.
45
*
48
*
46
* @author Jan Palka, Ian Formanek, Jaroslav Tulach
49
* @author Jan Palka, Ian Formanek, Jaroslav Tulach
Lines 1332-1342 Link Here
1332
        return m;
1335
        return m;
1333
    }
1336
    }
1334
1337
1338
    /**
1339
     * Finds out the monitor where the user currently has the input focus.
1340
     * This method is usually used to help the client code to figure out on
1341
     * which monitor it should place newly created windows/frames/dialogs.
1342
     * 
1343
     * @return the GraphicsConfiguration of the monitor which currently has the
1344
     * input focus
1345
     *
1346
     * @since 2.5
1347
     */
1348
    public static GraphicsConfiguration getCurrentGraphicsConfiguration() {
1349
        Frame[] frames = Frame.getFrames();
1350
1351
        for (int i = 0; i < frames.length; i++) {
1352
            if (javax.swing.SwingUtilities.findFocusOwner(frames[i]) != null) {
1353
                return frames[i].getGraphicsConfiguration();
1354
            }
1355
        }
1356
        return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
1357
    }
1358
    
1359
    /**
1360
     * Returns the usable area of the screen where applications can place its
1361
     * windows.  The method subtracts from the screen the area of taskbars,
1362
     * system menus and the like.
1363
     * 
1364
     * @param gconf the GraphicsConfiguration of the monitor
1365
     * @return the rectangle of the screen where one can place windows
1366
     * 
1367
     * @since 2.5
1368
     */
1369
    public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) {
1370
        if (gconf == null)
1371
            gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
1372
1373
        Rectangle bounds = new Rectangle(gconf.getBounds());
1374
        
1375
        String str;
1376
1377
        str = System.getProperty("netbeans.screen.insets"); // NOI18N
1378
        if (str != null) {
1379
            StringTokenizer st = new StringTokenizer(str, ", "); // NOI18N
1380
            if (st.countTokens() == 4) {
1381
                try {
1382
                    bounds.y = Integer.parseInt(st.nextToken());
1383
                    bounds.x = Integer.parseInt(st.nextToken());
1384
                    bounds.height -= bounds.y + Integer.parseInt(st.nextToken());
1385
                    bounds.width -= bounds.x + Integer.parseInt(st.nextToken());
1386
                }
1387
                catch (NumberFormatException ex) {
1388
                    ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
1389
                }
1390
            }
1391
            return bounds;
1392
        }
1393
        
1394
        str = System.getProperty("netbeans.taskbar.height"); // NOI18N
1395
        if (str != null) {
1396
            bounds.height -= Integer.getInteger(str, 0).intValue();
1397
            return bounds;
1398
        }
1399
1400
        // if JDK 1.4 or later
1401
1402
        if (Dependency.JAVA_SPEC.compareTo(new SpecificationVersion("1.4")) >= 0) { // NOI18N
1403
            try {
1404
                Toolkit toolkit = Toolkit.getDefaultToolkit();
1405
                Method m = Toolkit.class.getMethod("getScreenInsets", // NOI18N
1406
                                                   new Class[] { GraphicsConfiguration.class });
1407
                if (m == null)
1408
                    return bounds;
1409
                
1410
                Insets insets = (Insets) m.invoke(toolkit, new Object[] { gconf });
1411
                bounds.y += insets.top;
1412
                bounds.x += insets.left;
1413
                bounds.height -= insets.top + insets.bottom;
1414
                bounds.width -= insets.left + insets.right;
1415
            }
1416
            catch (Exception ex) {
1417
                ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
1418
            }
1419
            return bounds;
1420
        }
1421
        
1422
        if (Utilities.isWindows ()) {
1423
            bounds.height -= Utilities.TYPICAL_WINDOWS_TASKBAR_HEIGHT;
1424
            return bounds;
1425
        }
1426
1427
        if ((getOperatingSystem() & OS_MAC) != 0) {
1428
            bounds.height -= TYPICAL_MACOSX_MENU_HEIGHT;
1429
            return bounds;
1430
        }
1431
1432
        return bounds;
1433
    }
1434
1435
    /**
1436
     * Helps client code place components on the center of the screen.  It
1437
     * handles multiple monitor configuration correctly
1438
     *
1439
     * @param componentSize the size of the component
1440
     * @return bounds of the centered component
1441
     *
1442
     * @since 2.5
1443
     */
1444
    public static Rectangle getCenterBounds(Dimension componentSize) {
1445
        return getCenterBounds(getCurrentGraphicsConfiguration(),
1446
                               componentSize);
1447
    }
1448
1449
    /**
1450
     * Helps client code place components on the center of the screen.  It
1451
     * handles multiple monitor configuration correctly
1452
     *
1453
     * @param gconf the GraphicsConfiguration of the monitor
1454
     * @param componentSize the size of the component
1455
     * @return bounds of the centered component
1456
     *
1457
     * @since 2.5
1458
     */
1459
    public static Rectangle getCenterBounds(GraphicsConfiguration gconf,
1460
                                            Dimension componentSize) {
1461
        if (gconf == null)
1462
            gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
1463
1464
        Rectangle bounds = gconf.getBounds();
1465
        return new Rectangle(bounds.x + (bounds.width - componentSize.width) / 2,
1466
                             bounds.y + (bounds.height - componentSize.height) / 2,
1467
                             componentSize.width,
1468
                             componentSize.height);
1469
    }
1470
    
1335
    /** @return size of the screen. The size is modified for Windows OS
1471
    /** @return size of the screen. The size is modified for Windows OS
1336
     * - some pointes are subtracted to reflect a presence of the taskbar
1472
     * - some pointes are subtracted to reflect a presence of the taskbar
1473
     *
1474
     * @deprecated this method is almost useless in multiple monitor configuration
1475
     * 
1476
     * @see #getCurrentGraphicsConfiguration
1477
     * @see #getUsableScreenBounds(GraphicsConfiguration)
1478
     * @see #getCenterBounds(Dimension)
1479
     * @see #getCenterBounds(GraphicsConfiguration, Dimension)
1337
     */
1480
     */
1338
    public static final Dimension getScreenSize() {
1481
    public static final Dimension getScreenSize() {
1339
        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
1482
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
1483
        
1340
        if (isWindows() && !Boolean.getBoolean ("netbeans.no.taskbar")) {
1484
        if (isWindows() && !Boolean.getBoolean ("netbeans.no.taskbar")) {
1341
            screenSize.height -= TYPICAL_WINDOWS_TASKBAR_HEIGHT;
1485
            screenSize.height -= TYPICAL_WINDOWS_TASKBAR_HEIGHT;
1342
        } else if ((getOperatingSystem() & OS_MAC) != 0)
1486
        } else if ((getOperatingSystem() & OS_MAC) != 0)
Lines 1382-1388 Link Here
1382
        contentPane.add(chooser, BorderLayout.CENTER);
1526
        contentPane.add(chooser, BorderLayout.CENTER);
1383
 
1527
 
1384
        dialog.pack();
1528
        dialog.pack();
1385
        dialog.setLocationRelativeTo(parent);
1529
        dialog.setBounds(getCenterBounds(parent.getGraphicsConfiguration(),
1530
                                         dialog.getSize()));
1386
1531
1387
	chooser.rescanCurrentDirectory();
1532
	chooser.rescanCurrentDirectory();
1388
        final int[] retValue = new int[] { javax.swing.JFileChooser.CANCEL_OPTION };
1533
        final int[] retValue = new int[] { javax.swing.JFileChooser.CANCEL_OPTION };

Return to bug 20882