Search in sources :

Example 16 with Toolkit

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

the class Win32ShellFolder2 method getShell32Icon.

/**
     * Gets an icon from the Windows system icon list as an <code>Image</code>
     */
static Image getShell32Icon(int iconID, boolean getLargeIcon) {
    // Will be ignored on XP and later
    boolean useVGAColors = true;
    int size = getLargeIcon ? 32 : 16;
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    String shellIconBPP = (String) toolkit.getDesktopProperty("win.icon.shellIconBPP");
    if (shellIconBPP != null) {
        useVGAColors = shellIconBPP.equals("4");
    }
    long hIcon = getIconResource("shell32.dll", iconID, size, size, useVGAColors);
    if (hIcon != 0) {
        Image icon = makeIcon(hIcon, getLargeIcon);
        disposeIcon(hIcon);
        return icon;
    }
    return null;
}
Also used : Toolkit(java.awt.Toolkit) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage)

Example 17 with Toolkit

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

the class StyledParagraph method addInputMethodAttrs.

/**
     * Return a Map with entries from oldStyles, as well as input
     * method entries, if any.
     */
static Map<? extends Attribute, ?> addInputMethodAttrs(Map<? extends Attribute, ?> oldStyles) {
    Object value = oldStyles.get(TextAttribute.INPUT_METHOD_HIGHLIGHT);
    try {
        if (value != null) {
            if (value instanceof Annotation) {
                value = ((Annotation) value).getValue();
            }
            InputMethodHighlight hl;
            hl = (InputMethodHighlight) value;
            Map<? extends Attribute, ?> imStyles = null;
            try {
                imStyles = hl.getStyle();
            } catch (NoSuchMethodError e) {
            }
            if (imStyles == null) {
                Toolkit tk = Toolkit.getDefaultToolkit();
                imStyles = tk.mapInputMethodHighlight(hl);
            }
            if (imStyles != null) {
                HashMap<Attribute, Object> newStyles = new HashMap<>(5, (float) 0.9);
                newStyles.putAll(oldStyles);
                newStyles.putAll(imStyles);
                return newStyles;
            }
        }
    } catch (ClassCastException e) {
    }
    return oldStyles;
}
Also used : HashMap(java.util.HashMap) Attribute(java.text.AttributedCharacterIterator.Attribute) Toolkit(java.awt.Toolkit) InputMethodHighlight(java.awt.im.InputMethodHighlight) Annotation(java.text.Annotation)

Example 18 with Toolkit

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

the class DragSource method isDragImageSupported.

/**
     * Reports
     * whether or not drag
     * <code>Image</code> support
     * is available on the underlying platform.
     * <P>
     * @return if the Drag Image support is available on this platform
     */
public static boolean isDragImageSupported() {
    Toolkit t = Toolkit.getDefaultToolkit();
    Boolean supported;
    try {
        supported = (Boolean) Toolkit.getDefaultToolkit().getDesktopProperty("DnD.isDragImageSupported");
        return supported.booleanValue();
    } catch (Exception e) {
        return false;
    }
}
Also used : Toolkit(java.awt.Toolkit) IOException(java.io.IOException) HeadlessException(java.awt.HeadlessException)

Example 19 with Toolkit

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

the class JMenu method getPopupMenuOrigin.

/**
     * Computes the origin for the <code>JMenu</code>'s popup menu.
     * This method uses Look and Feel properties named
     * <code>Menu.menuPopupOffsetX</code>,
     * <code>Menu.menuPopupOffsetY</code>,
     * <code>Menu.submenuPopupOffsetX</code>, and
     * <code>Menu.submenuPopupOffsetY</code>
     * to adjust the exact location of popup.
     *
     * @return a <code>Point</code> in the coordinate space of the
     *          menu which should be used as the origin
     *          of the <code>JMenu</code>'s popup menu
     *
     * @since 1.3
     */
protected Point getPopupMenuOrigin() {
    int x;
    int y;
    JPopupMenu pm = getPopupMenu();
    // Figure out the sizes needed to caclulate the menu position
    Dimension s = getSize();
    Dimension pmSize = pm.getSize();
    // the size has not yet been initiated
    if (pmSize.width == 0) {
        pmSize = pm.getPreferredSize();
    }
    Point position = getLocationOnScreen();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    GraphicsConfiguration gc = getGraphicsConfiguration();
    Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gd = ge.getScreenDevices();
    for (int i = 0; i < gd.length; i++) {
        if (gd[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
            GraphicsConfiguration dgc = gd[i].getDefaultConfiguration();
            if (dgc.getBounds().contains(position)) {
                gc = dgc;
                break;
            }
        }
    }
    if (gc != null) {
        screenBounds = gc.getBounds();
        // take screen insets (e.g. taskbar) into account
        Insets screenInsets = toolkit.getScreenInsets(gc);
        screenBounds.width -= Math.abs(screenInsets.left + screenInsets.right);
        screenBounds.height -= Math.abs(screenInsets.top + screenInsets.bottom);
        position.x -= Math.abs(screenInsets.left);
        position.y -= Math.abs(screenInsets.top);
    }
    Container parent = getParent();
    if (parent instanceof JPopupMenu) {
        // We are a submenu (pull-right)
        int xOffset = UIManager.getInt("Menu.submenuPopupOffsetX");
        int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
        if (SwingUtilities.isLeftToRight(this)) {
            // First determine x:
            // Prefer placement to the right
            x = s.width + xOffset;
            if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
                x = 0 - xOffset - pmSize.width;
            }
        } else {
            // First determine x:
            // Prefer placement to the left
            x = 0 - xOffset - pmSize.width;
            if (position.x + x < screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
                x = s.width + xOffset;
            }
        }
        // Then the y:
        // Prefer dropping down
        y = yOffset;
        if (position.y + y + pmSize.height >= screenBounds.height + screenBounds.y && // popup doesn't fit - place it wherever there's more room
        screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
            y = s.height - yOffset - pmSize.height;
        }
    } else {
        // We are a toplevel menu (pull-down)
        int xOffset = UIManager.getInt("Menu.menuPopupOffsetX");
        int yOffset = UIManager.getInt("Menu.menuPopupOffsetY");
        if (SwingUtilities.isLeftToRight(this)) {
            // First determine the x:
            // Extend to the right
            x = xOffset;
            if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
                x = s.width - xOffset - pmSize.width;
            }
        } else {
            // First determine the x:
            // Extend to the left
            x = s.width - xOffset - pmSize.width;
            if (position.x + x < screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
                x = xOffset;
            }
        }
        // Then the y:
        // Prefer dropping down
        y = s.height + yOffset;
        if (position.y + y + pmSize.height >= screenBounds.height + screenBounds.y && // popup doesn't fit - place it wherever there's more room
        screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
            // Otherwise drop 'up'
            y = 0 - yOffset - pmSize.height;
        }
    }
    return new Point(x, y);
}
Also used : Container(java.awt.Container) GraphicsDevice(java.awt.GraphicsDevice) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 20 with Toolkit

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

the class JFileChooser method installShowFilesListener.

private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean) showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
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