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