Search in sources :

Example 1 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class Util method createEmbeddedFrame.

public static Frame createEmbeddedFrame(final Frame embedder) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InstantiationException, InvocationTargetException {
    Toolkit tk = Toolkit.getDefaultToolkit();
    FramePeer frame_peer = (FramePeer) embedder.getPeer();
    System.out.println("frame's peer = " + frame_peer);
    if ("sun.awt.windows.WToolkit".equals(tk.getClass().getName())) {
        Class comp_peer_class = Class.forName("sun.awt.windows.WComponentPeer");
        System.out.println("comp peer class = " + comp_peer_class);
        Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
        hwnd_field.setAccessible(true);
        System.out.println("hwnd_field =" + hwnd_field);
        long hwnd = hwnd_field.getLong(frame_peer);
        System.out.println("hwnd = " + hwnd);
        Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
        Constructor constructor = clazz.getConstructor(new Class[] { Long.TYPE });
        return (Frame) constructor.newInstance(new Object[] { hwnd });
    } else if ("sun.awt.X11.XToolkit".equals(tk.getClass().getName())) {
        Class x_base_window_class = Class.forName("sun.awt.X11.XBaseWindow");
        System.out.println("x_base_window_class = " + x_base_window_class);
        Method get_window = x_base_window_class.getMethod("getWindow", new Class[0]);
        System.out.println("get_window = " + get_window);
        long window = (Long) get_window.invoke(frame_peer, new Object[0]);
        System.out.println("window = " + window);
        Class clazz = Class.forName("sun.awt.X11.XEmbeddedFrame");
        Constructor constructor = clazz.getConstructor(new Class[] { Long.TYPE, Boolean.TYPE });
        return (Frame) constructor.newInstance(new Object[] { window, true });
    }
    throw new RuntimeException("Unexpected toolkit - " + tk);
}
Also used : FramePeer(java.awt.peer.FramePeer) Field(java.lang.reflect.Field) Frame(java.awt.Frame) Constructor(java.lang.reflect.Constructor) Toolkit(java.awt.Toolkit) Method(java.lang.reflect.Method)

Example 2 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageTest method testImageLoaded.

static void testImageLoaded(Image image) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    int flags = toolkit.checkImage(image, IMAGE_WIDTH, IMAGE_WIDTH, new SilentImageObserver());
    if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS)) == 0) {
        throw new RuntimeException("Image is not loaded!");
    }
}
Also used : Toolkit(java.awt.Toolkit)

Example 3 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageTest method getScalableImageMethod.

private static Method getScalableImageMethod(String name, Class... parameterTypes) throws Exception {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Method method = toolkit.getClass().getDeclaredMethod(name, parameterTypes);
    method.setAccessible(true);
    return method;
}
Also used : Toolkit(java.awt.Toolkit) Method(java.lang.reflect.Method)

Example 4 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageObserverTest method main.

public static void main(String[] args) throws Exception {
    generateImages();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = Toolkit.getDefaultToolkit().getImage(IMAGE_NAME_1X);
    LoadImageObserver sizeObserver = new LoadImageObserver(WIDTH | HEIGHT);
    toolkit.prepareImage(image, -1, -1, sizeObserver);
    waitForImageLoading(sizeObserver, "The first observer is not called");
    LoadImageObserver bitsObserver = new LoadImageObserver(SOMEBITS | FRAMEBITS | ALLBITS);
    BufferedImage buffImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) buffImage.createGraphics();
    g2d.scale(2, 2);
    g2d.drawImage(image, 0, 0, bitsObserver);
    waitForImageLoading(bitsObserver, "The second observer is not called!");
    g2d.dispose();
}
Also used : Toolkit(java.awt.Toolkit) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 5 with Toolkit

use of java.awt.Toolkit in project jdk8u_jdk by JetBrains.

the class MultiResolutionImageTest method testToolkitMultiResolutionImagePrepare.

static void testToolkitMultiResolutionImagePrepare() throws Exception {
    generateImages();
    File imageFile = new File(IMAGE_NAME_1X);
    String fileName = imageFile.getAbsolutePath();
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    toolkit.prepareImage(image, IMAGE_WIDTH, IMAGE_HEIGHT, new LoadImageObserver(image));
    testToolkitMultiResolutionImageLoad(image);
}
Also used : Toolkit(java.awt.Toolkit) MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) File(java.io.File)

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