Java Code Examples for java.awt.GraphicsEnvironment#getLocalGraphicsEnvironment()
The following examples show how to use
java.awt.GraphicsEnvironment#getLocalGraphicsEnvironment() .
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: GraphicUtils.java From Spark with Apache License 2.0 | 6 votes |
/** * Returns the ScreenBounds * * @return Array of {@link Rectangle}'s */ public static Rectangle[] getScreenBounds() { GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment .getLocalGraphicsEnvironment(); final GraphicsDevice[] screenDevices = graphicsEnvironment .getScreenDevices(); Rectangle[] screenBounds = new Rectangle[screenDevices.length]; for (int i = 0; i < screenDevices.length; i++) { GraphicsDevice screenDevice = screenDevices[i]; final GraphicsConfiguration defaultConfiguration = screenDevice .getDefaultConfiguration(); screenBounds[i] = defaultConfiguration.getBounds(); } return screenBounds; }
Example 2
Source File: HelvLtOblTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String os = System.getProperty("os.name"); if (!os.startsWith("Mac")) { return; } GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); for (int i=0; i<fonts.length; i++) { if (fonts[i].getPSName().equals("Helvetica-LightOblique")) { helvFont = fonts[i]; break; } } if (helvFont == null) { return; } final HelvLtOblTest test = new HelvLtOblTest(); SwingUtilities.invokeLater(() -> { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add("Center", test); f.pack(); f.setVisible(true); }); test.compareImages(); }
Example 3
Source File: CheckDisplayModes.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 4
Source File: JIntellitypeDemo.java From jintellitype with Apache License 2.0 | 6 votes |
/** * Centers window on desktop. * <p> * * @param aFrame the Frame to center */ private static void center(JFrame aFrame) { final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final Point centerPoint = ge.getCenterPoint(); final Rectangle bounds = ge.getMaximumWindowBounds(); final int w = Math.min(aFrame.getWidth(), bounds.width); final int h = Math.min(aFrame.getHeight(), bounds.height); final int x = centerPoint.x - (w / 2); final int y = centerPoint.y - (h / 2); aFrame.setBounds(x, y, w, h); if ((w == bounds.width) && (h == bounds.height)) { aFrame.setExtendedState(Frame.MAXIMIZED_BOTH); } aFrame.validate(); }
Example 5
Source File: JComboBoxPopupLocation.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(final String[] args) throws Exception { robot = new Robot(); robot.setAutoDelay(100); robot.setAutoWaitForIdle(true); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] sds = ge.getScreenDevices(); UIManager.LookAndFeelInfo[] lookAndFeelArray = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) { System.setProperty(PROPERTY_NAME, "true"); step(sds, lookAndFeelItem); if (lookAndFeelItem.getClassName().contains("Aqua")) { System.setProperty(PROPERTY_NAME, "false"); step(sds, lookAndFeelItem); } } }
Example 6
Source File: CheckDisplayModes.java From hottub with GNU General Public License v2.0 | 6 votes |
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: Utils.java From DroidUIBuilder with Apache License 2.0 | 5 votes |
public static void fullScreen(Window w) { GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment(); for (GraphicsDevice device : env.getScreenDevices()) { if (device.isFullScreenSupported()) { device.setFullScreenWindow(w); return; } } MainPane.getTipCom().warn("No supported device for fullscreen mode."); }
Example 8
Source File: WGLSurfaceData.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static WGLGraphicsConfig getGC(WComponentPeer peer) { if (peer != null) { return (WGLGraphicsConfig)peer.getGraphicsConfiguration(); } else { // REMIND: this should rarely (never?) happen, but what if // default config is not WGL? GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); return (WGLGraphicsConfig)gd.getDefaultConfiguration(); } }
Example 9
Source File: MaximizedToMaximized.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Frame frame = new Frame(); final Toolkit toolkit = Toolkit.getDefaultToolkit(); final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice(); final Dimension screenSize = toolkit.getScreenSize(); final Insets screenInsets = toolkit.getScreenInsets( graphicsDevice.getDefaultConfiguration()); final Rectangle availableScreenBounds = new Rectangle(screenSize); availableScreenBounds.x += screenInsets.left; availableScreenBounds.y += screenInsets.top; availableScreenBounds.width -= (screenInsets.left + screenInsets.right); availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom); frame.setBounds(availableScreenBounds.x, availableScreenBounds.y, availableScreenBounds.width, availableScreenBounds.height); frame.setVisible(true); Rectangle frameBounds = frame.getBounds(); frame.setExtendedState(Frame.MAXIMIZED_BOTH); ((SunToolkit) toolkit).realSync(); Rectangle maximizedFrameBounds = frame.getBounds(); if (maximizedFrameBounds.width < frameBounds.width || maximizedFrameBounds.height < frameBounds.height) { throw new RuntimeException("Maximized frame is smaller than non maximized"); } }
Example 10
Source File: BaseService.java From Shuffle-Move with GNU General Public License v3.0 | 5 votes |
public static final boolean isLocationInScreenBounds(int x, int y) { // From: // http://www.java2s.com/Code/Java/Swing-JFC/Verifiesifthegivenpointisvisibleonthescreen.htm // Check if the location is in the bounds of one of the graphics devices. GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices(); Rectangle graphicsConfigurationBounds = new Rectangle(); // Iterate over the graphics devices. for (int j = 0; j < graphicsDevices.length; j++) { // Get the bounds of the device. GraphicsDevice graphicsDevice = graphicsDevices[j]; graphicsConfigurationBounds.setRect(graphicsDevice.getDefaultConfiguration().getBounds()); // Is the location in this bounds? graphicsConfigurationBounds.setRect(graphicsConfigurationBounds.x, graphicsConfigurationBounds.y, graphicsConfigurationBounds.width, graphicsConfigurationBounds.height); if (graphicsConfigurationBounds.contains(x, y)) { // The location is in this screengraphics. return true; } } // We could not find a device that contains the given point. return false; }
Example 11
Source File: VolatileSurfaceManager.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
protected VolatileSurfaceManager(SunVolatileImage vImg, Object context) { this.vImg = vImg; this.context = context; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // We could have a HeadlessGE at this point, so double-check before // assuming anything. if (ge instanceof SunGraphicsEnvironment) { ((SunGraphicsEnvironment)ge).addDisplayChangedListener(this); } }
Example 12
Source File: WGLSurfaceData.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static WGLGraphicsConfig getGC(WComponentPeer peer) { if (peer != null) { return (WGLGraphicsConfig)peer.getGraphicsConfiguration(); } else { // REMIND: this should rarely (never?) happen, but what if // default config is not WGL? GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); return (WGLGraphicsConfig)gd.getDefaultConfiguration(); } }
Example 13
Source File: UnmanagedDrawImagePerformance.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static VolatileImage makeVI(final int type) { final GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); final GraphicsConfiguration gc = gd.getDefaultConfiguration(); return gc.createCompatibleVolatileImage(SIZE, SIZE, type); }
Example 14
Source File: D3DSurfaceData.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 15
Source File: IncorrectClipSurface2SW.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) throws IOException { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); AffineTransform at; for (final int size : SIZES) { for (final int scale : SCALES) { final int sw = size * scale; at = AffineTransform.getScaleInstance(sw, sw); for (Shape clip : SHAPES) { clip = at.createTransformedShape(clip); for (Shape to : SHAPES) { to = at.createTransformedShape(to); // Prepare test images VolatileImage vi = getVolatileImage(gc, size); BufferedImage bi = getBufferedImage(sw); // Prepare gold images BufferedImage goldvi = getCompatibleImage(gc, size); BufferedImage goldbi = getBufferedImage(sw); draw(clip, to, vi, bi, scale); draw(clip, to, goldvi, goldbi, scale); validate(bi, goldbi); } } } } }
Example 16
Source File: GE_init2.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { GraphicsEnvironment.getLocalGraphicsEnvironment(); }
Example 17
Source File: IncorrectClipXorModeSW2Surface.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(final String[] args) throws IOException { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); AffineTransform at; for (int size : SIZES) { at = AffineTransform.getScaleInstance(size, size); for (Shape clip : SHAPES) { clip = at.createTransformedShape(clip); for (Shape to : SHAPES) { to = at.createTransformedShape(to); // Prepare test images BufferedImage snapshot; BufferedImage bi = getBufferedImage(size); VolatileImage vi = getVolatileImage(gc, size); while (true) { vi.validate(gc); Graphics2D g2d = vi.createGraphics(); g2d.setColor(Color.GREEN); g2d.fillRect(0, 0, size, size); g2d.dispose(); if (vi.validate(gc) != VolatileImage.IMAGE_OK) { continue; } draw(clip, to, bi, vi); snapshot = vi.getSnapshot(); if (vi.contentsLost()) { continue; } break; } // Prepare gold images BufferedImage goldvi = getCompatibleImage(gc, size); BufferedImage goldbi = getBufferedImage(size); draw(clip, to, goldbi, goldvi); validate(snapshot, goldvi); vi.flush(); } } } }
Example 18
Source File: FontChooserPanel.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Standard constructor - builds a FontChooserPanel initialised with the * specified font. * * @param font the initial font to display. */ public FontChooserPanel(Font font) { GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fonts = g.getAvailableFontFamilyNames(); setLayout(new BorderLayout()); JPanel right = new JPanel(new BorderLayout()); JPanel fontPanel = new JPanel(new BorderLayout()); fontPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Font"))); this.fontlist = new JList(fonts); JScrollPane fontpane = new JScrollPane(this.fontlist); fontpane.setBorder(BorderFactory.createEtchedBorder()); fontPanel.add(fontpane); add(fontPanel); JPanel sizePanel = new JPanel(new BorderLayout()); sizePanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Size"))); this.sizelist = new JList(SIZES); JScrollPane sizepane = new JScrollPane(this.sizelist); sizepane.setBorder(BorderFactory.createEtchedBorder()); sizePanel.add(sizepane); JPanel attributes = new JPanel(new GridLayout(1, 2)); this.bold = new JCheckBox(localizationResources.getString("Bold")); this.italic = new JCheckBox(localizationResources.getString("Italic")); attributes.add(this.bold); attributes.add(this.italic); attributes.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), localizationResources.getString("Attributes"))); right.add(sizePanel, BorderLayout.CENTER); right.add(attributes, BorderLayout.SOUTH); add(right, BorderLayout.EAST); setSelectedFont(font); }
Example 19
Source File: TestSGEuseAlternateFontforJALocales.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static void main(String args[]) throws Exception { System.out.println("Default Charset = " + Charset.defaultCharset().name()); System.out.println("Locale = " + Locale.getDefault()); String os = System.getProperty("os.name"); String encoding = System.getProperty("file.encoding"); /* Want to test the JA locale uses alternate font for DialogInput. */ boolean jaTest = encoding.equalsIgnoreCase("windows-31j"); if (!os.startsWith("Win") && jaTest) { System.out.println("Skipping Windows only test"); return; } String className = "sun.java2d.SunGraphicsEnvironment"; String methodName = "useAlternateFontforJALocales"; Class sge = Class.forName(className); Method uafMethod = sge.getMethod(methodName, (Class[])null); Object ret = uafMethod.invoke(null); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.preferLocaleFonts(); ge.preferProportionalFonts(); if (jaTest) { Font msMincho = new Font("MS Mincho", Font.PLAIN, 12); if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) { System.out.println("MS Mincho not installed. Skipping test"); return; } Font dialogInput = new Font("DialogInput", Font.PLAIN, 12); Font courierNew = new Font("Courier New", Font.PLAIN, 12); Font msGothic = new Font("MS Gothic", Font.PLAIN, 12); BufferedImage bi = new BufferedImage(1,1,1); Graphics2D g2d = bi.createGraphics(); FontMetrics cnMetrics = g2d.getFontMetrics(courierNew); FontMetrics diMetrics = g2d.getFontMetrics(dialogInput); FontMetrics mmMetrics = g2d.getFontMetrics(msMincho); FontMetrics mgMetrics = g2d.getFontMetrics(msGothic); // This tests to make sure we at least have applied // "preferLocaleFonts for Japanese if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) { throw new RuntimeException ("Courier New should not be used for DialogInput"); } // This is supposed to make sure we are using MS Mincho instead // of MS Gothic. However they are metrics identical so its // not definite proof. if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) { throw new RuntimeException ("MS Mincho should be used for DialogInput"); } } }
Example 20
Source File: RSLContextInvalidationTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); VolatileImage vi = gc.createCompatibleVolatileImage(100, 100); vi.validate(gc); VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100); vi1.validate(gc); if (!(vi instanceof DestSurfaceProvider)) { System.out.println("Test considered PASSED: no HW acceleration"); return; } DestSurfaceProvider p = (DestSurfaceProvider)vi; Surface s = p.getDestSurface(); if (!(s instanceof AccelSurface)) { System.out.println("Test considered PASSED: no HW acceleration"); return; } AccelSurface dst = (AccelSurface)s; Graphics g = vi.createGraphics(); g.drawImage(vi1, 95, 95, null); g.setColor(Color.red); g.fillRect(0, 0, 100, 100); g.setColor(Color.black); g.fillRect(0, 0, 100, 100); // after this the validated context color is black RenderQueue rq = dst.getContext().getRenderQueue(); rq.lock(); try { dst.getContext().saveState(); dst.getContext().restoreState(); } finally { rq.unlock(); } // this will cause ResetPaint (it will set color to extended EA=ff, // which is ffffffff==Color.white) g.drawImage(vi1, 95, 95, null); // now try filling with black again, but it will come up as white // because this fill rect won't validate the color properly g.setColor(Color.black); g.fillRect(0, 0, 100, 100); BufferedImage bi = vi.getSnapshot(); if (bi.getRGB(50, 50) != Color.black.getRGB()) { throw new RuntimeException("Test FAILED: found color="+ Integer.toHexString(bi.getRGB(50, 50))+" instead of "+ Integer.toHexString(Color.black.getRGB())); } System.out.println("Test PASSED."); }