| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hivegui.util; |
| 16 | |
| 17 | import java.awt.Dimension; |
| 18 | import java.awt.GraphicsConfiguration; |
| 19 | import java.awt.GraphicsEnvironment; |
| 20 | import java.awt.Insets; |
| 21 | import java.awt.Point; |
| 22 | import java.awt.Rectangle; |
| 23 | import java.awt.Toolkit; |
| 24 | |
| 25 | public final class ScreenTools |
| 26 | { |
| 27 | private ScreenTools() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | static public Rectangle getMainScreenUsableBounds() |
| 32 | { |
| 33 | GraphicsConfiguration config = GraphicsEnvironment |
| 34 | .getLocalGraphicsEnvironment() |
| 35 | .getDefaultScreenDevice() |
| 36 | .getDefaultConfiguration(); |
| 37 | Rectangle bounds = config.getBounds(); |
| 38 | Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config); |
| 39 | return new Rectangle( bounds.x + insets.left, |
| 40 | bounds.y + insets.top, |
| 41 | bounds.width - insets.left - insets.right, |
| 42 | bounds.height - insets.top - insets.bottom); |
| 43 | } |
| 44 | |
| 45 | static public Point getMainScreenUsableOrigin() |
| 46 | { |
| 47 | Rectangle bounds = getMainScreenUsableBounds(); |
| 48 | return new Point(bounds.x, bounds.y); |
| 49 | } |
| 50 | |
| 51 | static public Dimension getMainScreenUsableSize() |
| 52 | { |
| 53 | Rectangle bounds = getMainScreenUsableBounds(); |
| 54 | return new Dimension(bounds.width, bounds.height); |
| 55 | } |
| 56 | |
| 57 | static public Rectangle getMainScreenBounds() |
| 58 | { |
| 59 | GraphicsConfiguration config = GraphicsEnvironment |
| 60 | .getLocalGraphicsEnvironment() |
| 61 | .getDefaultScreenDevice() |
| 62 | .getDefaultConfiguration(); |
| 63 | return new Rectangle(config.getBounds()); |
| 64 | } |
| 65 | |
| 66 | static public Dimension getMainScreenSize() |
| 67 | { |
| 68 | return getMainScreenBounds().getSize(); |
| 69 | } |
| 70 | |
| 71 | static public Point getMainScreenOrigin() |
| 72 | { |
| 73 | return getMainScreenBounds().getLocation(); |
| 74 | } |
| 75 | } |