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);
}
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!");
}
}
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;
}
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();
}
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);
}
Aggregations