use of java.awt.GraphicsConfiguration in project javatari by ppeccin.
the class DesktopScreenWindow method openFullWindow.
private void openFullWindow() {
if (fullWindow.isVisible())
return;
// Try to set full screen in the monitor we are currently in
GraphicsConfiguration graphicsConfig = SwingHelper.getGraphicsConfigurationForCurrentLocation(this);
setVisible(false);
fullWindow.setBounds(graphicsConfig.getBounds());
fullWindow.setVisible(true);
// Try to enter FullScreen Exclusive mode if desired
if (USE_FSEM != 0) {
try {
graphicsConfig.getDevice().setFullScreenWindow(fullWindow);
} catch (Exception e) {
// Ignore. Probably FSEM is not supported
}
}
fullWindow.toFront();
fullWindow.requestFocus();
monitor.setDisplay(fullWindow);
fullScreen = true;
}
use of java.awt.GraphicsConfiguration in project javatari by ppeccin.
the class SwingHelper method getGraphicsConfigurationForCurrentLocation.
public static GraphicsConfiguration getGraphicsConfigurationForCurrentLocation(Window window) {
GraphicsConfiguration ownedConfig = window.getGraphicsConfiguration();
Point currLocation = window.getLocation();
// Shortcut for "owned" case
if (ownedConfig.getBounds().contains(currLocation))
return ownedConfig;
// Search for the right screen
GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
for (GraphicsDevice screen : screens) for (GraphicsConfiguration config : screen.getConfigurations()) if (config.getBounds().contains(currLocation))
return config;
// If none found, lets return the "owned" one
return ownedConfig;
}
use of java.awt.GraphicsConfiguration in project grounded by alejolp.
the class GameCanvas method loadGraphics.
// setIgnoreRepaint(false);
public void loadGraphics() {
BufferedImage img;
// Load the image data.
try {
img = ImageIO.read(new ByteArrayInputStream(Data.TILES_DATA));
} catch (IOException e) {
e.printStackTrace();
return;
}
// Make 0xFF00FF pixels transparent.
int w = img.getWidth(), h = img.getHeight();
int x, y, p = 0;
int[] data = img.getRGB(0, 0, w, h, null, 0, w);
for (y = 0; y < h; ++y) {
for (x = 0; x < w; ++x, ++p) {
if ((data[p] & 0xffffff) == 0xff00ff)
/* Pink, it's not even a question */
data[p] = 0x0;
}
}
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
// Update image data.
if (config != null)
tiles = config.createCompatibleImage(w, h, Transparency.BITMASK);
else
tiles = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
tiles.setRGB(0, 0, w, h, data, 0, w);
}
use of java.awt.GraphicsConfiguration in project eweb4j-framework by laiweiwei.
the class FileUtil method toBufferedImage.
private static BufferedImage toBufferedImage(Image image) {
if (image instanceof BufferedImage) {
return (BufferedImage) image;
}
// This code ensures that all the pixels in the image are loaded
image = new ImageIcon(image).getImage();
// Determine if the image has transparent pixels; for this method's
// implementation, see e661 Determining If an Image Has Transparent
// Pixels
// boolean hasAlpha = hasAlpha(image);
// Create a buffered image with a format that's compatible with the
// screen
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
// Determine the type of transparency of the new buffered image
int transparency = Transparency.OPAQUE;
/*
* if (hasAlpha) { transparency = Transparency.BITMASK; }
*/
// Create the buffered image
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
} catch (HeadlessException e) {
// The system does not have a screen
}
if (bimage == null) {
// Create a buffered image using the default color model
int type = BufferedImage.TYPE_INT_RGB;
// int type = BufferedImage.TYPE_3BYTE_BGR;//by wang
/*
* if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; }
*/
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
}
// Copy image to buffered image
Graphics g = bimage.createGraphics();
// Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);
g.dispose();
return bimage;
}
use of java.awt.GraphicsConfiguration in project gephi by gephi.
the class RichTooltip method showTooltip.
public void showTooltip(JComponent component, Point screenLocation) {
if (component == null || !component.isShowing()) {
return;
}
Dimension size;
Point location = new Point();
GraphicsConfiguration gc;
gc = component.getGraphicsConfiguration();
Rectangle sBounds = gc.getBounds();
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
// Take into account screen insets, decrease viewport
sBounds.x += screenInsets.left;
sBounds.y += screenInsets.top;
sBounds.width -= (screenInsets.left + screenInsets.right);
sBounds.height -= (screenInsets.top + screenInsets.bottom);
hideTooltip();
JRichTooltipPanel tip = new JRichTooltipPanel(this);
size = tip.getPreferredSize();
// display directly below or above it
location.x = screenLocation.x + 10;
location.y = screenLocation.y - 10;
if ((location.y + size.height) > (sBounds.y + sBounds.height)) {
location.y = screenLocation.y - size.height;
}
// Tweak the X location to not overflow the screen
if (location.x < sBounds.x) {
location.x = sBounds.x;
} else if (location.x - sBounds.x + size.width > sBounds.width) {
location.x = sBounds.x + Math.max(0, sBounds.width - size.width);
}
PopupFactory popupFactory = PopupFactory.getSharedInstance();
tipWindow = popupFactory.getPopup(component, tip, location.x, location.y);
tipWindow.show();
tipShowing = true;
}
Aggregations