Search in sources :

Example 11 with Toolkit

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

the class LwjglAWTInput method showCursor.

private void showCursor(boolean visible) {
    if (!visible) {
        Toolkit t = Toolkit.getDefaultToolkit();
        Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
        Cursor noCursor = t.createCustomCursor(i, new Point(0, 0), "none");
        JFrame frame = findJFrame(canvas);
        frame.setCursor(noCursor);
    } else {
        JFrame frame = findJFrame(canvas);
        frame.setCursor(Cursor.getDefaultCursor());
    }
}
Also used : JFrame(javax.swing.JFrame) Toolkit(java.awt.Toolkit) Point(java.awt.Point) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Cursor(java.awt.Cursor) BufferedImage(java.awt.image.BufferedImage)

Example 12 with Toolkit

use of java.awt.Toolkit in project h2o-2 by h2oai.

the class AwtRequestParameterDiscoverer method discoverParameters.

@Override
public DefaultRequest discoverParameters(GoogleAnalyticsConfig config, DefaultRequest request) {
    super.discoverParameters(config, request);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    if (isEmpty(request.screenResolution())) {
        Dimension screenSize = toolkit.getScreenSize();
        request.screenResolution(((int) screenSize.getWidth()) + "x" + ((int) screenSize.getHeight()) + ", " + toolkit.getScreenResolution() + " dpi");
    }
    if (isEmpty(request.screenColors())) {
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
        StringBuilder sb = new StringBuilder();
        for (GraphicsDevice graphicsDevice : graphicsDevices) {
            if (sb.length() != 0) {
                sb.append(", ");
            }
            sb.append(graphicsDevice.getDisplayMode().getBitDepth());
        }
        request.screenColors(sb.toString());
    }
    return request;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 13 with Toolkit

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

the class LinuxPlatform method initBase.

public void initBase(Base base) {
    super.initBase(base);
    String javaVendor = System.getProperty("java.vendor");
    String javaVM = System.getProperty("java.vm.name");
    if (javaVendor == null || (!javaVendor.contains("Sun") && !javaVendor.contains("Oracle")) || javaVM == null || !javaVM.contains("Java")) {
        Messages.showWarning("Not fond of this Java VM", "Processing requires Java 8 from Oracle.\n" + "Other versions such as OpenJDK, IcedTea,\n" + "and GCJ are strongly discouraged. Among other things, you're\n" + "likely to run into problems with sketch window size and\n" + "placement. For more background, please read the wiki:\n" + "https://github.com/processing/processing/wiki/Supported-Platforms#linux", null);
    }
    // https://github.com/processing/processing/issues/2534
    try {
        Toolkit xToolkit = Toolkit.getDefaultToolkit();
        java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
        awtAppClassNameField.setAccessible(true);
        awtAppClassNameField.set(xToolkit, "Processing");
    } catch (Exception e) {
        // In case the implementation details change
        e.printStackTrace();
    }
}
Also used : Toolkit(java.awt.Toolkit)

Example 14 with Toolkit

use of java.awt.Toolkit in project jgnash by ccavanaugh.

the class StaticUIMethods method fixWindowManager.

static void fixWindowManager() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    if (toolkit.getClass().getName().equals("sun.awt.X11.XToolkit")) {
        // Oracle Bug #6528430 - provide proper app name on Linux
        try {
            Field awtAppClassNameField = toolkit.getClass().getDeclaredField("awtAppClassName");
            AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
                awtAppClassNameField.setAccessible(true);
                return null;
            });
            awtAppClassNameField.set(toolkit, Version.getAppName());
        } catch (NoSuchFieldException | IllegalAccessException ex) {
            Logger.getLogger(StaticUIMethods.class.getName()).log(Level.INFO, ex.getLocalizedMessage(), ex);
        }
        // Workaround for main menu, pop-up & mouse issues for Gnome 3 shell and Cinnamon          
        if ("gnome-shell".equals(System.getenv("DESKTOP_SESSION")) || "cinnamon".equals(System.getenv("DESKTOP_SESSION")) || "gnome".equals(System.getenv("DESKTOP_SESSION")) || (System.getenv("XDG_CURRENT_DESKTOP") != null && System.getenv("XDG_CURRENT_DESKTOP").contains("GNOME"))) {
            try {
                Class<?> x11_wm = Class.forName("sun.awt.X11.XWM");
                Field awt_wMgr = x11_wm.getDeclaredField("awt_wmgr");
                awt_wMgr.setAccessible(true);
                Field other_wm = x11_wm.getDeclaredField("OTHER_WM");
                other_wm.setAccessible(true);
                if (awt_wMgr.get(null).equals(other_wm.get(null))) {
                    Field metaCity_Wm = x11_wm.getDeclaredField("METACITY_WM");
                    metaCity_Wm.setAccessible(true);
                    awt_wMgr.set(null, metaCity_Wm.get(null));
                    Logger.getLogger(StaticUIMethods.class.getName()).info("Installed window manager workaround");
                }
            } catch (ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
                Logger.getLogger(StaticUIMethods.class.getName()).log(Level.INFO, ex.getLocalizedMessage(), ex);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) Toolkit(java.awt.Toolkit)

Example 15 with Toolkit

use of java.awt.Toolkit in project jgnash by ccavanaugh.

the class CursorUtils method getCursor.

/**
     * Returns a custom cursor object of the type specified.
     *
     * @param type the type of the custom cursor as defined in this class
     * @return the specified custom cursor
     * @throws IllegalArgumentException if the specified cursor type is
     *                                  invalid
     */
public static Cursor getCursor(int type) {
    if (type < ZOOM_IN || type > ZOOM_OUT) {
        throw new IllegalArgumentException("illegal cursor type");
    }
    if (predefined[type] == null) {
        try {
            // See comment above the static variable.
            final Object[] props = cursorProperties[type];
            final String name = (String) props[0];
            final String resource = (String) props[1];
            final int[] spot = (int[]) props[2];
            final Point point = new Point(spot[0], spot[1]);
            final Toolkit tk = Toolkit.getDefaultToolkit();
            Image image = IconUtils.getImage(resource);
            predefined[type] = tk.createCustomCursor(image, point, name);
        } catch (IndexOutOfBoundsException | HeadlessException e) {
            // this would be an error in the properties
            predefined[type] = Cursor.getDefaultCursor();
            throw new RuntimeException(e);
        }
    }
    return predefined[type];
}
Also used : HeadlessException(java.awt.HeadlessException) Toolkit(java.awt.Toolkit) Point(java.awt.Point) Image(java.awt.Image)

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