Example usage for java.awt Toolkit getDefaultToolkit

List of usage examples for java.awt Toolkit getDefaultToolkit

Introduction

In this page you can find the example usage for java.awt Toolkit getDefaultToolkit.

Prototype

public static synchronized Toolkit getDefaultToolkit() 

Source Link

Document

Gets the default toolkit.

Usage

From source file:Main.java

/**
 * Returns the key mask of the menu shortcut key.
 * /*from w w  w. j  a v a  2  s  .c  om*/
 * @return a key mask, >= 0.
 */
public static final int getMenuShortcutKeyMask() {
    return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
}

From source file:Main.java

/**
 * Centra un frame e ne setta le dimensioni
 *//*  w  ww. ja  v a  2  s. c  o  m*/
public static void locateForm(JFrame f, int x, int y, int w, int h) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    x = (screenSize.width - w) / 2;
    y = (screenSize.height - h) / 2;
    f.setBounds(x, y, w, h);
}

From source file:Main.java

/**
 * Centers a Window on the screen<p>
 * Sets the window on the top left corner if the window's
 * dimensions are bigger than the screen's.
 *
 * @param window a Window object//from  w ww .  j a  va 2 s.c  o m
 */
public static void centerOnScreen(Window window) {
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    double w = Math.min(window.getWidth(), screen.width);
    double h = Math.min(window.getHeight(), screen.height);
    int x = (int) (center.x - (w / 2));
    int y = (int) (center.y - (h / 2));

    Point corner = new Point((x >= 0 ? x : 0), (y >= 0 ? y : 0));

    window.setLocation(corner);
}

From source file:Main.java

/**
 * Centers the given window on the primary screen.
 *
 * @param window//from   w  w w. j  a  v a 2s .c o m
 *            The window to center
 */
public static void center(Window window) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = window.getSize();
    window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2);
}

From source file:Main.java

/**
 * gives default modifier of the current OS.
 * /*www.j a  v a  2 s.  c  o m*/
 * @return meta (command) for OSX, control for Windows/Linux etc 
 */
public static int getSystemDefaultModifier() {
    if (!(UIManager.getLookAndFeel().getID().equals(METAL_LAF_ID))) {
        int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
        if (mask == Event.META_MASK) {
            return KeyEvent.VK_META;
        } else if (mask == Event.ALT_MASK) {
            return KeyEvent.VK_ALT;
        }
    }
    return KeyEvent.VK_CONTROL;
}

From source file:Main.java

/**
 * 
 */
public static void beep() {

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    toolkit.beep();
}

From source file:Main.java

/**
 * Gets the screen dimesion.//from   ww w.  j  a  v  a 2s .c o m
 *
 * @return the screen dimesion
 */
public static Dimension getScreenDimesion() {
    return Toolkit.getDefaultToolkit().getScreenSize();
}

From source file:Transparency.java

public static Image makeColorTransparent(Image im, final Color color) {
    ImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... Alpha bits are set to opaque
        public int markerRGB = color.getRGB() | 0xFF000000;

        @Override//  w  ww. j  a  v  a 2s. c om
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | 0xFF000000) == markerRGB) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF & rgb;
            } else {
                // nothing to do
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:Main.java

public static Dimension getFrameSize(Component c) {
    Container parent = getRootContainer(c);
    if (parent != null) {
        return parent.getSize();
    }/*  ww w.jav  a2  s .co m*/
    return Toolkit.getDefaultToolkit().getScreenSize();
}

From source file:Main.java

/** Centers the given window on the screen. */
public static void centerWindow(final Window window) {
    final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
    centerWindow(new Rectangle(0, 0, s.width, s.height), window);
}