Search in sources :

Example 26 with Toolkit

use of java.awt.Toolkit in project JSettlers2 by jdmonin.

the class SOCFaceButton method loadImages.

private static synchronized void loadImages(Component c) {
    if (images == null) {
        tracker = new MediaTracker(c);
        Toolkit tk = c.getToolkit();
        Class<?> clazz = c.getClass();
        images = new Image[NUM_FACES];
        robotImages = new Image[NUM_ROBOT_FACES];
        /**
         * load the images
         */
        robotImages[0] = tk.getImage(clazz.getResource(IMAGEDIR + "/robot.gif"));
        tracker.addImage(robotImages[0], 0);
        for (int i = 1; i < NUM_FACES; i++) {
            images[i] = tk.getImage(clazz.getResource(IMAGEDIR + "/face" + i + ".gif"));
            tracker.addImage(images[i], 0);
        }
        for (int i = 1; i < NUM_ROBOT_FACES; i++) {
            // Client possibly only has robot.gif.
            // Check getResource vs null, and use MediaTracker;
            // drawFace can check tracker.statusID vs MediaTracker.COMPLETE.
            URL imgSrc = clazz.getResource(IMAGEDIR + "/robot" + i + ".gif");
            if (imgSrc != null) {
                robotImages[i] = tk.getImage(imgSrc);
                tracker.addImage(robotImages[i], i);
            }
        }
        try {
            tracker.waitForID(0);
        } catch (InterruptedException e) {
        }
        if (tracker.isErrorID(0)) {
            System.out.println("Error loading Face images");
        }
    }
}
Also used : MediaTracker(java.awt.MediaTracker) Toolkit(java.awt.Toolkit) URL(java.net.URL)

Example 27 with Toolkit

use of java.awt.Toolkit in project com.revolsys.open by revolsys.

the class Icons method getCursor.

public static Cursor getCursor(final String imageName, final int dx, final int dy) {
    Image image = getImage(imageName);
    if (image == null) {
        return null;
    } else {
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        if (OS.isWindows()) {
            final BufferedImage newImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
            final Graphics graphics = newImage.getGraphics();
            graphics.drawImage(image, 0, 0, null);
            graphics.dispose();
            image = newImage;
        }
        return toolkit.createCustomCursor(image, new Point(dx, dy), imageName);
    }
}
Also used : Graphics(java.awt.Graphics) Toolkit(java.awt.Toolkit) Point(java.awt.Point) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Example 28 with Toolkit

use of java.awt.Toolkit in project com.revolsys.open by revolsys.

the class SwingUtil method setSize.

static void setSize(final Window window, final int minusX, final int minusY) {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension screenSize = toolkit.getScreenSize();
    final double screenWidth = screenSize.getWidth();
    final double screenHeight = screenSize.getHeight();
    final Dimension size = new Dimension((int) (screenWidth - minusX), (int) (screenHeight - minusY));
    window.setBounds(minusX / 2, minusY / 2, size.width, size.height);
    window.setPreferredSize(size);
}
Also used : Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension)

Example 29 with Toolkit

use of java.awt.Toolkit in project freeplane by freeplane.

the class Launcher method fixX11AppName.

private static void fixX11AppName() {
    try {
        Toolkit xToolkit = Toolkit.getDefaultToolkit();
        if (xToolkit.getClass().getName().equals("sun.awt.X11.XToolkit")) {
            java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
            awtAppClassNameField.setAccessible(true);
            awtAppClassNameField.set(xToolkit, "Freeplane");
        }
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        System.err.format("Couldn't set awtAppClassName: %s%n", e.getClass().getSimpleName() + ": " + e.getMessage());
    }
}
Also used : Toolkit(java.awt.Toolkit)

Example 30 with Toolkit

use of java.awt.Toolkit in project CS3243-Project by Kangqing-Qiu.

the class TLabel method setFont.

public void setFont(Font f) {
    Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
    double x = toolkit.getScreenSize().getWidth();
    double y = toolkit.getScreenSize().getHeight();
    double xscale = x / 1400.0;
    double yscale = y / 1050.0;
    double scale = Math.sqrt((xscale * xscale + yscale * yscale) / 2);
    font = f.deriveFont((float) (f.getSize() * scale));
}
Also used : Toolkit(java.awt.Toolkit)

Aggregations

Toolkit (java.awt.Toolkit)93 Dimension (java.awt.Dimension)27 Point (java.awt.Point)20 Image (java.awt.Image)19 BufferedImage (java.awt.image.BufferedImage)14 URL (java.net.URL)14 GraphicsDevice (java.awt.GraphicsDevice)8 GraphicsEnvironment (java.awt.GraphicsEnvironment)7 Insets (java.awt.Insets)7 Rectangle (java.awt.Rectangle)6 IOException (java.io.IOException)6 Field (java.lang.reflect.Field)6 MediaTracker (java.awt.MediaTracker)5 ImageIcon (javax.swing.ImageIcon)5 Frame (java.awt.Frame)4 Clipboard (java.awt.datatransfer.Clipboard)4 Font (java.awt.Font)3 Graphics (java.awt.Graphics)3 GraphicsConfiguration (java.awt.GraphicsConfiguration)3 Method (java.lang.reflect.Method)3