java.awt.GraphicsEnvironment Java Examples

The following examples show how to use java.awt.GraphicsEnvironment. 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: TransformedPaintTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void runTest() {
    GraphicsConfiguration gc = GraphicsEnvironment.
        getLocalGraphicsEnvironment().getDefaultScreenDevice().
            getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("8-bit desktop depth found, test passed");
        return;
    }

    VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
    BufferedImage bi = null;
    do {
        vi.validate(gc);
        Graphics2D g = vi.createGraphics();
        render(g, vi.getWidth(), vi.getHeight());
        bi = vi.getSnapshot();
    } while (vi.contentsLost());

    checkBI(bi);
    System.out.println("Test PASSED.");
}
 
Example #2
Source File: InternalFrameDemoFrame.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Computes the maximum bounds of the current screen device. If this method is called on JDK 1.4, Xinerama-aware
 * results are returned. (See Sun-Bug-ID 4463949 for details).
 *
 * @return the maximum bounds of the current screen.
 */
private static Rectangle getMaximumWindowBounds()
{
  try
  {
    final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    return localGraphicsEnvironment.getMaximumWindowBounds();
  }
  catch (Exception e)
  {
    // ignore ... will fail if this is not a JDK 1.4 ..
  }

  final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
  return new Rectangle(0, 0, s.width, s.height);
}
 
Example #3
Source File: Desktop.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the <code>Desktop</code> instance of the current
 * browser context.  On some platforms the Desktop API may not be
 * supported; use the {@link #isDesktopSupported} method to
 * determine if the current desktop is supported.
 * @return the Desktop instance of the current browser context
 * @throws HeadlessException if {@link
 * GraphicsEnvironment#isHeadless()} returns {@code true}
 * @throws UnsupportedOperationException if this class is not
 * supported on the current platform
 * @see #isDesktopSupported()
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public static synchronized Desktop getDesktop(){
    if (GraphicsEnvironment.isHeadless()) throw new HeadlessException();
    if (!Desktop.isDesktopSupported()) {
        throw new UnsupportedOperationException("Desktop API is not " +
                                                "supported on the current platform");
    }

    sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
    Desktop desktop = (Desktop)context.get(Desktop.class);

    if (desktop == null) {
        desktop = new Desktop();
        context.put(Desktop.class, desktop);
    }

    return desktop;
}
 
Example #4
Source File: CheckDisplayModes.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);

    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }

    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
 
Example #5
Source File: ResourceLocator.java    From open-ig with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
	 * Convert the image into a compatible format for local rendering.
	 * @param img the bufferedImage
	 * @return the converted image
	 */
	BufferedImage optimizeImage(BufferedImage img) {
		BufferedImage img2 = GraphicsEnvironment.getLocalGraphicsEnvironment()
				.getDefaultScreenDevice().getDefaultConfiguration()
				.createCompatibleImage(
					img.getWidth(),
					img.getHeight(),
					img.getColorModel().getTransparency()
//					img.getColorModel().hasAlpha() ? Transparency.BITMASK
//						: Transparency.OPAQUE
						);
			Graphics2D g = img2.createGraphics();
			g.drawImage(img, 0, 0, null);
			g.dispose();
		 
			return img2;
	}
 
Example #6
Source File: CheckDisplayModes.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);

    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }

    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
 
Example #7
Source File: CheckDisplayModes.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
    if (!graphicDevice.isDisplayChangeSupported()) {
        System.err.println("Display mode change is not supported on this host. Test is considered passed.");
        return;
    }
    DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
    checkDisplayMode(defaultDisplayMode);
    graphicDevice.setDisplayMode(defaultDisplayMode);

    DisplayMode[] displayModes = graphicDevice.getDisplayModes();
    boolean isDefaultDisplayModeIncluded = false;
    for (DisplayMode displayMode : displayModes) {
        checkDisplayMode(displayMode);
        graphicDevice.setDisplayMode(displayMode);
        if (defaultDisplayMode.equals(displayMode)) {
            isDefaultDisplayModeIncluded = true;
        }
    }

    if (!isDefaultDisplayModeIncluded) {
        throw new RuntimeException("Default display mode is not included");
    }
}
 
Example #8
Source File: RefineryUtilities.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
* Computes the maximum bounds of the current screen device. If this method is called on JDK 1.4, Xinerama-aware
* results are returned. (See Sun-Bug-ID 4463949 for details).
*
* @return the maximum bounds of the current screen.
* @deprecated this method is not useful in multi-screen environments.
*/
 public static Rectangle getMaximumWindowBounds ()
 {
   final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
   try
   {
     final Method method = GraphicsEnvironment.class.getMethod("getMaximumWindowBounds", (Class[]) null);
     return (Rectangle) method.invoke(localGraphicsEnvironment, (Object[]) null);
   }
   catch(Exception e)
   {
     // ignore ... will fail if this is not a JDK 1.4 ..
   }

   final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
   return new Rectangle (0, 0, s.width, s.height);
 }
 
Example #9
Source File: TestGuiAvailable.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) {
        throw new Error("unexpected GuiAvailable property");
    }
    Beans.setGuiAvailable(!Beans.isGuiAvailable());
    ThreadGroup group = new ThreadGroup("$$$");
    Thread thread = new Thread(group, new TestGuiAvailable());
    thread.start();
    thread.join();
}
 
Example #10
Source File: TelegraphConfig.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the screen resolution.
 * 
 * @return The screen resolution.
 */
private Rectangle getScreenResolution() {
	// get the environment
	final GraphicsEnvironment environment = GraphicsEnvironment
			.getLocalGraphicsEnvironment();
	// return the bounds
	return environment.getMaximumWindowBounds();
}
 
Example #11
Source File: IncorrectUnmanagedImageRotatedClip.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final BufferedImage bi) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(500, 200,
                                                        TRANSLUCENT);
    BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
    // draw to compatible Image
    draw(bi, gold);
    // draw to volatile image
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            continue;
        }
        draw(bi, vi);
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    // validate images
    for (int x = 0; x < gold.getWidth(); ++x) {
        for (int y = 0; y < gold.getHeight(); ++y) {
            if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(snapshot, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
 
Example #12
Source File: D3DSurfaceData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static D3DGraphicsConfig getGC(WComponentPeer peer) {
    GraphicsConfiguration gc;
    if (peer != null) {
        gc =  peer.getGraphicsConfiguration();
    } else {
        GraphicsEnvironment env =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = env.getDefaultScreenDevice();
        gc = gd.getDefaultConfiguration();
    }
    return (gc instanceof D3DGraphicsConfig) ? (D3DGraphicsConfig)gc : null;
}
 
Example #13
Source File: Win32FontManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void registerJREFontsForPrinting() {
    final String pathName;
    synchronized (Win32GraphicsEnvironment.class) {
        GraphicsEnvironment.getLocalGraphicsEnvironment();
        if (fontsForPrinting == null) {
            return;
        }
        pathName = fontsForPrinting;
        fontsForPrinting = null;
    }
    java.security.AccessController.doPrivileged(
        new java.security.PrivilegedAction<Object>() {
            public Object run() {
                File f1 = new File(pathName);
                String[] ls = f1.list(SunFontManager.getInstance().
                        getTrueTypeFilter());
                if (ls == null) {
                    return null;
                }
                for (int i=0; i <ls.length; i++ ) {
                    File fontFile = new File(f1, ls[i]);
                    registerFontWithPlatform(fontFile.getAbsolutePath());
                }
                return null;
            }
     });
}
 
Example #14
Source File: InternalWindow.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the close and minimize icons.
 */
private static void createIcons() {
	GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
	Image bg = createIconBackground(gc);

	// copy bg for drawing
	Image image = gc.createCompatibleImage(TITLEBAR_HEIGHT, TITLEBAR_HEIGHT, Transparency.OPAQUE);
	Graphics g = image.getGraphics();
	g.drawImage(bg, 0, 0, null);
	closeIcon = createCloseIcon(image);

	// now we can draw over the background image
	minimizeIcon = createMinimizeIcon(bg);
}
 
Example #15
Source File: DashZeroWidth.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    BufferedImage img = new BufferedImage(200, 40, TYPE_INT_ARGB);
    draw(img);
    validate(img);

    if (GraphicsEnvironment.isHeadless()) {
        return;
    }

    GraphicsConfiguration gc =
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getDefaultScreenDevice().getDefaultConfiguration();

    VolatileImage vi = gc.createCompatibleVolatileImage(200, 40);
    BufferedImage snapshot;
    int attempt = 0;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        draw(vi);
        snapshot = vi.getSnapshot();
        if (!vi.contentsLost()) {
            break;
        }
    }
    validate(snapshot);
}
 
Example #16
Source File: GLXSurfaceData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static GLXGraphicsConfig getGC(X11ComponentPeer peer) {
    if (peer != null) {
        return (GLXGraphicsConfig)peer.getGraphicsConfiguration();
    } else {
        // REMIND: this should rarely (never?) happen, but what if
        //         default config is not GLX?
        GraphicsEnvironment env =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = env.getDefaultScreenDevice();
        return (GLXGraphicsConfig)gd.getDefaultConfiguration();
    }
}
 
Example #17
Source File: KeyboardTest.java    From RemoteSupportTool with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        final StringBuilder text = new StringBuilder();
        for (String arg : args) {
            text.append(arg).append(StringUtils.SPACE);
        }
        String txt = text.toString().trim();
        if (StringUtils.isBlank(txt))
            txt = "test123 - äöüß / ÄÖÜ @€ \\";

        try {
            if (SystemUtils.IS_OS_WINDOWS) {
                LOGGER.debug("Send text on Windows...");
                GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
                Robot robot = new Robot(device);
                WindowsUtils.sendText(txt, robot);
            } else if (SystemUtils.IS_OS_LINUX) {
                LOGGER.debug("Send text on Linux...");
                LinuxUtils.sendText(txt);
            } else if (SystemUtils.IS_OS_MAC) {
                LOGGER.debug("Send text on macOS...");
                MacUtils.sendText(txt);
            } else {
                throw new UnsupportedOperationException("Operating system is not supported.");
            }
        } catch (Exception ex) {
            LOGGER.error("Can't send text!", ex);
        }
    }
 
Example #18
Source File: IncorrectAlphaConversionBicubic.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    final GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final VolatileImage vi =
            gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
    final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
    final int expected = bi.getRGB(2, 2);

    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        final Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.scale(2, 2);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                             RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.drawImage(bi, 0, 0, null);
        g2d.dispose();

        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    final int actual = snapshot.getRGB(2, 2);
    if (actual != expected) {
        System.err.println("Actual: " + Integer.toHexString(actual));
        System.err.println("Expected: " + Integer.toHexString(expected));
        throw new RuntimeException("Test failed");
    }
}
 
Example #19
Source File: BufferStrategyExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();

    for (int i = 0; i < TEST_REPS; i++) {
        TestFrame f = new TestFrame();
        f.pack();
        f.setSize(400, 400);
        f.setVisible(true);
        if (i % 2 == 0) {
            gd.setFullScreenWindow(f);
        }
        // generate a resize event which will invalidate the peer's
        // surface data and hopefully cause an exception during
        // BufferStrategy creation in TestFrame.render()
        Dimension d = f.getSize();
        d.width -= 5; d.height -= 5;
        f.setSize(d);

        f.render();
        gd.setFullScreenWindow(null);
        sleep(100);
        f.dispose();
    }
    System.out.println("Test passed.");
}
 
Example #20
Source File: OpenRTSApplication.java    From OpenRTS with MIT License 5 votes vote down vote up
public void toggleToFullscreen() {
	GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
	DisplayMode[] modes = device.getDisplayModes();
	int i = 0; // note: there are usually several, let's pick the first
	settings.setResolution(modes[i].getWidth(), modes[i].getHeight());
	settings.setFrequency(modes[i].getRefreshRate());
	settings.setBitsPerPixel(modes[i].getBitDepth());
	settings.setFullscreen(device.isFullScreenSupported());
	appInstance.setSettings(settings);
	appInstance.restart(); // restart the context to apply changes
}
 
Example #21
Source File: CameraJpeg.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
private static BufferedImage getCompatibleImage(int w, int h) {
  GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice gd = ge.getDefaultScreenDevice();
  GraphicsConfiguration gc = gd.getDefaultConfiguration();
  BufferedImage image = gc.createCompatibleImage(w, h);
  return image;
}
 
Example #22
Source File: DropTarget.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new DropTarget given the <code>Component</code>
 * to associate itself with, an <code>int</code> representing
 * the default acceptable action(s) to
 * support, a <code>DropTargetListener</code>
 * to handle event processing, a <code>boolean</code> indicating
 * if the <code>DropTarget</code> is currently accepting drops, and
 * a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
 * <P>
 * The Component will receive drops only if it is enabled.
 * @param c         The <code>Component</code> with which this <code>DropTarget</code> is associated
 * @param ops       The default acceptable actions for this <code>DropTarget</code>
 * @param dtl       The <code>DropTargetListener</code> for this <code>DropTarget</code>
 * @param act       Is the <code>DropTarget</code> accepting drops.
 * @param fm        The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 *            returns true
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public DropTarget(Component c, int ops, DropTargetListener dtl,
                  boolean act, FlavorMap fm)
    throws HeadlessException
{
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }

    component = c;

    setDefaultActions(ops);

    if (dtl != null) try {
        addDropTargetListener(dtl);
    } catch (TooManyListenersException tmle) {
        // do nothing!
    }

    if (c != null) {
        c.setDropTarget(this);
        setActive(act);
    }

    if (fm != null) {
        flavorMap = fm;
    } else {
        flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }
}
 
Example #23
Source File: HeadUI.java    From Forsythia with GNU General Public License v3.0 5 votes vote down vote up
private void enterFullScreenMode(){
fullscreenmode=true;
GraphicsEnvironment env = GraphicsEnvironment.
    getLocalGraphicsEnvironment();
GraphicsDevice[] devices = env.getScreenDevices();
device=devices[0];
originaldm = device.getDisplayMode();
boolean isfullscreenable = device.isFullScreenSupported();
//get rid of the frame decor
setVisible(false);
dispose();
setUndecorated(isfullscreenable);
setVisible(true);
//
setResizable(!isfullscreenable);
//hide controls
pancontrol.setVisible(false);
//get the focus on the image panel so we can exit on keypress
panimage.requestFocus();
//do fullscreen
if(isfullscreenable){
  device.setFullScreenWindow(this);
  pancontrol.setVisible(false);
//can't do fullscreen so do this other thing
}else{
  setVisible(true);}
validate();
hideMouse();}
 
Example #24
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 #25
Source File: FieldConfigFont.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Populate font family list. */
private synchronized void populateFontFamilyList() {
    if (fontFamilyList == null) {
        fontFamilyList = new ArrayList<>();

        String[] families =
                GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

        for (String fontFamily : families) {
            fontFamilyList.add(new ValueComboBoxData(fontFamily, fontFamily, getPanelId()));
        }
    }
}
 
Example #26
Source File: D3DSurfaceData.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static D3DGraphicsConfig getGC(WComponentPeer peer) {
    GraphicsConfiguration gc;
    if (peer != null) {
        gc =  peer.getGraphicsConfiguration();
    } else {
        GraphicsEnvironment env =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = env.getDefaultScreenDevice();
        gc = gd.getDefaultConfiguration();
    }
    return (gc instanceof D3DGraphicsConfig) ? (D3DGraphicsConfig)gc : null;
}
 
Example #27
Source File: IncorrectUnmanagedImageRotatedClip.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final BufferedImage bi) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(500, 200,
                                                        TRANSLUCENT);
    BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
    // draw to compatible Image
    draw(bi, gold);
    // draw to volatile image
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            continue;
        }
        draw(bi, vi);
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    // validate images
    for (int x = 0; x < gold.getWidth(); ++x) {
        for (int y = 0; y < gold.getHeight(); ++y) {
            if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(snapshot, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
 
Example #28
Source File: MiscTests.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testCompatibleFonts() {
    String s = "\u23EF";
    Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    System.out.println("Total fonts: \t" + fonts.length);
    int count = 0;
    for (Font font : fonts) {
        if (font.canDisplayUpTo(s) < 0) {
            count++;
            System.out.println(font.getName());
        }
    }
    System.out.println("Compatible fonts: \t" + count);
}
 
Example #29
Source File: IncorrectUnmanagedImageRotatedClip.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final BufferedImage bi) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(500, 200,
                                                        TRANSLUCENT);
    BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
    // draw to compatible Image
    draw(bi, gold);
    // draw to volatile image
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            continue;
        }
        draw(bi, vi);
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    // validate images
    for (int x = 0; x < gold.getWidth(); ++x) {
        for (int y = 0; y < gold.getHeight(); ++y) {
            if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(snapshot, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
 
Example #30
Source File: CGLSurfaceData.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static CGLGraphicsConfig getGC(CPlatformView pView) {
    if (pView != null) {
        return (CGLGraphicsConfig)pView.getGraphicsConfiguration();
    } else {
        // REMIND: this should rarely (never?) happen, but what if
        // default config is not CGL?
        GraphicsEnvironment env = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
        GraphicsDevice gd = env.getDefaultScreenDevice();
        return (CGLGraphicsConfig) gd.getDefaultConfiguration();
    }
}