Java Code Examples for java.awt.GraphicsDevice#getConfigurations()

The following examples show how to use java.awt.GraphicsDevice#getConfigurations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScreenCapture.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * 座標からスクリーンを取得します
 *
 * @param x X
 * @param y Y
 * @return スクリーン
 */
static GraphicsConfiguration detectScreenDevice(int x, int y) {
    GraphicsDevice[] gds = GraphicsEnvironment
            .getLocalGraphicsEnvironment()
            .getScreenDevices();

    for (GraphicsDevice gd : gds) {
        for (GraphicsConfiguration gc : gd.getConfigurations()) {
            Rectangle r = gc.getBounds();
            if (r.contains(x, y)) {
                return gc;
            }
        }
    }
    return null;
}
 
Example 2
Source File: BundleView.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Try to locate this Bundle window so that the underlying JNLP
 * window does not get masked by this one.
 * We try to locate the window in the upper right corner of the primary
 * physical screen.
 */
private void setSizeAndLocation ()
{
    pack();

    // Window size
    final int width = 687;
    final int height = 400;
    final int gapFromBorder = 20;
    setSize(width, height);

    // Window location
    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getScreenDevices()[0];
    GraphicsConfiguration config = device.getConfigurations()[0];
    Rectangle bounds = config.getBounds();
    logger.debug("Primary screen bounds: {}", bounds);

    Point topLeft = new Point(
            (bounds.x + bounds.width) - width - gapFromBorder,
            bounds.y + gapFromBorder);
    logger.debug("Window topLeft: {}", topLeft);
    setLocation(topLeft);
}
 
Example 3
Source File: JavaInfo.java    From haxademic with MIT License 6 votes vote down vote up
public static void printDisplayInfo() {
    int g = 0;
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        out.println("graphics device #"+(++g)+": "+gd.getIDstring()+" type "+gd.getType());
        out.println("\tavailable accelerated memory " + gd.getAvailableAcceleratedMemory());
        int c = 0;
        for (GraphicsConfiguration gc : gd.getConfigurations()) {
            out.println("\tgraphics configuration #"+(++c)+":");
            out.println("\t\twidth "+gc.getBounds().getWidth()+" height "+gc.getBounds().getHeight());
            out.println("\t\tfull screen "+gc.getBufferCapabilities().isFullScreenRequired());
            ImageCapabilities ic = gc.getImageCapabilities();
            out.println("\t\tis accelerated "+ic.isAccelerated());

        }
        DisplayMode dm = gd.getDisplayMode();   
        out.println("\tdisplay mode bit width "+dm.getWidth()+" height "+dm.getHeight()+" bit depth "+dm.getBitDepth()+" refresh rate "+dm.getRefreshRate());
        int m = 0;
        for (DisplayMode d : gd.getDisplayModes())
            out.println("\talt display mode #"+(++m)+" bit width "+d.getWidth()+" height "+d.getHeight()+" bit depth "+d.getBitDepth()+" refresh rate "+d.getRefreshRate());    
    }
}
 
Example 4
Source File: ScaledTransform.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.
            getLocalGraphicsEnvironment();

    if (ge.isHeadlessInstance()) {
        return;
    }

    for (GraphicsDevice gd : ge.getScreenDevices()) {
        for (GraphicsConfiguration gc : gd.getConfigurations()) {
            testScaleFactor(gc);
        }
    }
}
 
Example 5
Source File: UiUtils.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
private static Pair<GraphicsDevice, GraphicsConfiguration> determineGraphicsDeviceByWindow(
		GraphicsEnvironment graphicsEnvironment, List<GraphicsDevice> graphicsDevices, Window window) {
	log.debug("determineGraphicsDeviceByWindow " + format(window.getBounds()));

	Rectangle windowBounds = window.getBounds();
	int lastArea = 0;
	Pair<GraphicsDevice, GraphicsConfiguration> ret = null;
	for (int i = 0; i < graphicsDevices.size(); ++i) {
		GraphicsDevice graphicsDevice = graphicsDevices.get(i);
		log.debug("- Checking GraphicsDevice: "
				+ format(i, graphicsDevice, graphicsDevice.getDefaultConfiguration()));
		GraphicsConfiguration[] graphicsConfigurations = graphicsDevice.getConfigurations();
		Set<Rectangle> seen = new HashSet<>();
		for (int j = 0; j < graphicsConfigurations.length; ++j) {
			GraphicsConfiguration graphicsConfiguration = graphicsConfigurations[j];
			Rectangle graphicsBounds = graphicsConfiguration.getBounds();
			if (!seen.add(graphicsBounds)) {
				continue;
			}

			log.debug("  - Checking GraphicsConfiguration: " + format(graphicsBounds));
			Rectangle intersection = windowBounds.intersection(graphicsBounds);
			int area = intersection.width * intersection.height;
			if (area != 0 && area > lastArea) {
				lastArea = area;
				ret = Pair.of(graphicsDevice, graphicsConfiguration);
			}
		}
	}

	return ret;
}
 
Example 6
Source File: CGLGraphicsConfig.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void updateTotalDisplayBounds() {
    synchronized (totalDisplayBounds) {
        Rectangle virtualBounds = new Rectangle();
        for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
            for (GraphicsConfiguration gc : gd.getConfigurations()) {
                virtualBounds = virtualBounds.union(gc.getBounds());
            }
        }
        totalDisplayBounds.setBounds(virtualBounds);
    }
}
 
Example 7
Source File: CGLGraphicsConfig.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void updateTotalDisplayBounds() {
    synchronized (totalDisplayBounds) {
        Rectangle virtualBounds = new Rectangle();
        for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
            for (GraphicsConfiguration gc : gd.getConfigurations()) {
                virtualBounds = virtualBounds.union(gc.getBounds());
            }
        }
        totalDisplayBounds.setBounds(virtualBounds);
    }
}
 
Example 8
Source File: QPopup.java    From pumpernickel with MIT License 5 votes vote down vote up
private boolean isScreenRectVisible(Rectangle screenRect) {
	GraphicsEnvironment ge = GraphicsEnvironment
			.getLocalGraphicsEnvironment();
	GraphicsDevice[] gds = ge.getScreenDevices();
	for (GraphicsDevice gd : gds) {
		for (GraphicsConfiguration gc : gd.getConfigurations()) {
			if (gc.getBounds().contains(screenRect)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 9
Source File: ScaledTransform.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.
            getLocalGraphicsEnvironment();

    if (ge.isHeadlessInstance()) {
        return;
    }

    for (GraphicsDevice gd : ge.getScreenDevices()) {
        for (GraphicsConfiguration gc : gd.getConfigurations()) {
            testScaleFactor(gc);
        }
    }
}
 
Example 10
Source File: SkinEditorMainGUI.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the 'virtual bounds' of the screen.  That is, the union of the
 * displayable space on all available screen devices.
 *
 * @return
 */
private Rectangle getVirtualBounds() {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
        GraphicsConfiguration[] gc = gd.getConfigurations();
        for (GraphicsConfiguration element : gc) {
            virtualBounds = virtualBounds.union(element.getBounds());
        }
    }
    return virtualBounds;
}
 
Example 11
Source File: ClientGUI.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the 'virtual bounds' of the screen.  That is, the union of the
 * displayable space on all available screen devices.
 * 
 * @return
 */
private Rectangle getVirtualBounds() {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
        GraphicsConfiguration[] gc = gd.getConfigurations();
        for (GraphicsConfiguration element : gc) {
            virtualBounds = virtualBounds.union(element.getBounds());
        }
    }
    return virtualBounds;
}
 
Example 12
Source File: MainFrame.java    From ios-image-util with MIT License 5 votes vote down vote up
/**
 * Get virtual screen bounds. (For multi display)
 *
 * @return
 */
private static Rectangle getVirtualScreenBounds() {
	Rectangle virtualBounds = new Rectangle();
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	GraphicsDevice[] gs = ge.getScreenDevices();
	for (int j = 0; j < gs.length; j++) {
	    GraphicsDevice gd = gs[j];
	    GraphicsConfiguration[] gc = gd.getConfigurations();
	    for (int i=0; i < gc.length; i++) {
	        virtualBounds = virtualBounds.union(gc[i].getBounds());
	    }
	}
	return virtualBounds;
}
 
Example 13
Source File: ScreenshotUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static Rectangle2D getFullScreenBounds() {
	// NOTE! main monitor must be top left, otherwise, override x+y position  
	Rectangle2D result = new Rectangle2D.Double();
	GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment();
	for (GraphicsDevice gd : localGE.getScreenDevices()) {
		for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
			Rectangle2D.union(result, graphicsConfiguration.getBounds(), result);
		}
	}
	return result;
}
 
Example 14
Source File: EpsGraphics2D.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the device configuration associated with this EpsGraphics2D
 * object.
 */
public GraphicsConfiguration getDeviceConfiguration() {
  GraphicsConfiguration gc = null;
  GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice[] gds = ge.getScreenDevices();
  for(int i = 0; i<gds.length; i++) {
    GraphicsDevice gd = gds[i];
    GraphicsConfiguration[] gcs = gd.getConfigurations();
    if(gcs.length>0) {
      return gcs[0];
    }
  }
  return gc;
}
 
Example 15
Source File: DisplayHelper.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
public DisplayHelper() {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (GraphicsDevice graphicsDevice : graphicsEnvironment.getScreenDevices())
        for (GraphicsConfiguration graphicsConfiguration : graphicsDevice.getConfigurations())
            screen = screen.union(graphicsConfiguration.getBounds());
}
 
Example 16
Source File: NMONVisualizerGui.java    From nmonvisualizer with Apache License 2.0 4 votes vote down vote up
private void positionMainFrame() {
    // load the window position and sizes from the Preferences
    // use max value here so that first time users / empty prefs create a default sized window
    // centered on the primary display
    int x = getPreferences().getInt("WindowPosX", 0);
    int y = this.getPreferences().getInt("WindowPosY", 0);

    int xSize = getPreferences().getInt("WindowSizeX", Integer.MAX_VALUE);
    int ySize = this.getPreferences().getInt("WindowSizeY", Integer.MAX_VALUE);

    // check to see if the preferred window will be visible with the current screen config
    // (user could have removed / reconfigured multiple monitors or resolutions)
    boolean willBeVisible = false;
    java.awt.Rectangle preferred = new java.awt.Rectangle(x, y, xSize, ySize);

    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

    outer: for (GraphicsDevice device : devices) {
        GraphicsConfiguration[] configs = device.getConfigurations();

        for (GraphicsConfiguration config : configs) {
            if (SwingUtilities.isRectangleContainingRectangle(config.getBounds(), preferred)) {
                willBeVisible = true;
                break outer;
            }
        }
    }

    // if not visible put the window in the middle of the primary monitor
    if (!willBeVisible) {
        java.awt.Rectangle defaultScreen = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration().getBounds();

        // resize if too big
        if (xSize > defaultScreen.width) {
            xSize = 800;
        }

        if (ySize > defaultScreen.height) {
            ySize = 600;
        }

        // center the window on the screen
        x = defaultScreen.x + (defaultScreen.width / 2) - (xSize / 2);
        y = defaultScreen.y + (defaultScreen.height / 2) - (ySize / 2);
    }

    mainFrame.setLocation(new java.awt.Point(x, y));
    // set the size even if the window will not be maximized to ensure that
    // the window will be the right size if the user does un-maximize it
    mainFrame.setSize(xSize, ySize);

    if (getPreferences().getBoolean("WindowMaximized", false)) {
        mainFrame.setExtendedState(mainFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
    }
}