Java Code Examples for java.awt.GraphicsEnvironment

The following are top voted examples for showing how to use java.awt.GraphicsEnvironment. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: DisplayChangeVITest.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
 
Example 2
Project: OpenJSharp   File: SurfaceManager.java   View source code 6 votes vote down vote up
public boolean isAccelerated() {
    // Note that when img.getAccelerationPriority() gets set to 0
    // we remove SurfaceDataProxy objects from the cache and the
    // answer will be false.
    GraphicsConfiguration tmpGc = gc;
    if (tmpGc == null) {
        tmpGc = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
    }
    if (tmpGc instanceof ProxiedGraphicsConfig) {
        Object proxyKey =
            ((ProxiedGraphicsConfig) tmpGc).getProxyKey();
        if (proxyKey != null) {
            SurfaceDataProxy sdp =
                (SurfaceDataProxy) getCacheData(proxyKey);
            return (sdp != null && sdp.isAccelerated());
        }
    }
    return false;
}
 
Example 3
Project: Cognizant-Intelligent-Test-Scripter   File: Canvas.java   View source code 6 votes vote down vote up
public static Image iconToImage(Icon icon) {
    if (icon instanceof ImageIcon) {
        return ((ImageIcon) icon).getImage();
    } else {
        int w = icon.getIconWidth();
        int h = icon.getIconHeight();
        GraphicsEnvironment ge
                = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        BufferedImage image = gc.createCompatibleImage(w, h);
        Graphics2D g = image.createGraphics();
        icon.paintIcon(null, g, 0, 0);
        g.dispose();
        return image;
    }
}
 
Example 4
Project: jdk8u-jdk   File: RenderingToCachedGraphicsTest.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    int depth = GraphicsEnvironment.getLocalGraphicsEnvironment().
        getDefaultScreenDevice().getDefaultConfiguration().
            getColorModel().getPixelSize();
    if (depth < 16) {
        System.out.println("Test PASSED (depth < 16bit)");
        return;
    }

    latch = new CountDownLatch(1);
    RenderingToCachedGraphicsTest t1 = new RenderingToCachedGraphicsTest();
    t1.pack();
    t1.setSize(300, 300);
    t1.setVisible(true);

    try { latch.await(); } catch (InterruptedException ex) {}
    t1.dispose();

    if (failed) {
        throw new
            RuntimeException("Failed: rendering didn't show up");
    }
    System.out.println("Test PASSED");
}
 
Example 5
Project: incubator-netbeans   File: BasicTabDisplayerUI.java   View source code 6 votes vote down vote up
@Override
public Image createImageOfTab(int index) {
    TabData td = displayer.getModel().getTab(index);
    
    JLabel lbl = new JLabel(td.getText());
    int width = lbl.getFontMetrics(lbl.getFont()).stringWidth(td.getText());
    int height = lbl.getFontMetrics(lbl.getFont()).getHeight();
    width = width + td.getIcon().getIconWidth() + 6;
    height = Math.max(height, td.getIcon().getIconHeight()) + 5;
    
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
                                    .getDefaultScreenDevice().getDefaultConfiguration();
    
    BufferedImage image = config.createCompatibleImage(width, height);
    Graphics2D g = image.createGraphics();
    g.setColor(lbl.getForeground());
    g.setFont(lbl.getFont());
    td.getIcon().paintIcon(lbl, g, 0, 0);
    g.drawString(td.getText(), 18, height / 2);
    
    
    return image;
}
 
Example 6
Project: openjdk-jdk10   File: CheckDisplayModes.java   View source code 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
Project: incubator-netbeans   File: NbiDialog.java   View source code 6 votes vote down vote up
public void setVisible(boolean visible) {
    if (owner == null) {
        final GraphicsDevice screen = GraphicsEnvironment.
                getLocalGraphicsEnvironment().
                getScreenDevices()[0];
        final GraphicsConfiguration config = screen.getDefaultConfiguration();
        
        final int screenWidth  = config.getBounds().width;
        final int screenHeight = config.getBounds().height;
        
        setLocation(
                (screenWidth - getSize().width) / 2,
                (screenHeight - getSize().height) / 2);
    } else {
        setLocation(
                owner.getLocation().x + DIALOG_FRAME_WIDTH_DELTA,
                owner.getLocation().y + DIALOG_FRAME_WIDTH_DELTA);
    }
    
    super.setVisible(visible);
}
 
Example 8
Project: powertext   File: TipUtil.java   View source code 6 votes vote down vote up
/**
 * Returns the screen coordinates for the monitor that contains the
 * specified point.  This is useful for setups with multiple monitors,
 * to ensure that popup windows are positioned properly.
 *
 * @param x The x-coordinate, in screen coordinates.
 * @param y The y-coordinate, in screen coordinates.
 * @return The bounds of the monitor that contains the specified point.
 */
public static Rectangle getScreenBoundsForPoint(int x, int y) {
	GraphicsEnvironment env = GraphicsEnvironment.
									getLocalGraphicsEnvironment();
	GraphicsDevice[] devices = env.getScreenDevices();
	for (int i=0; i<devices.length; i++) {
		GraphicsConfiguration[] configs = devices[i].getConfigurations();
		for (int j=0; j<configs.length; j++) {
			Rectangle gcBounds = configs[j].getBounds();
			if (gcBounds.contains(x, y)) {
				return gcBounds;
			}
		}
	}
	// If point is outside all monitors, default to default monitor (?)
	return env.getMaximumWindowBounds();
}
 
Example 9
Project: jdk8u-jdk   File: VolatileImageBug.java   View source code 6 votes vote down vote up
public static void main(String[] args) {

        boolean iaeThrown = false;
        GraphicsEnvironment ge = GraphicsEnvironment.
                                      getLocalGraphicsEnvironment();
        GraphicsConfiguration gc = ge.getDefaultScreenDevice().
                                           getDefaultConfiguration();
        try {
            VolatileImage volatileImage = gc.createCompatibleVolatileImage(0, 0);
        } catch (IllegalArgumentException iae) {
            iaeThrown = true;
        }
        if (!iaeThrown) {
            throw new RuntimeException ("IllegalArgumentException not thrown " +
                                        "for createCompatibleVolatileImage(0,0)");
        }
    }
 
Example 10
Project: LeagueStats   File: Assets.java   View source code 6 votes vote down vote up
/**
 * Initializes the fonts for this application.
 */
private static void initFonts() {
	final String extension = ".ttf";
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

	try {
		ge.registerFont(Font.createFont(Font.TRUETYPE_FONT,
				new File(FONT_FILE_PATH + CAVIAR_FONT_NAME.replace(" ", "") + extension)));

	} catch (FontFormatException | IOException e) {
		logger.logError("An error occured while trying to register the font: " + CAVIAR_FONT_NAME + extension);

	}
	NAME_FONT = new Font(CAVIAR_FONT_NAME, Font.BOLD, 18);
	SMALL_NAME_FONT = new Font(CAVIAR_FONT_NAME, Font.PLAIN, 15);
	STATS_FONT = new Font(CAVIAR_FONT_NAME, Font.PLAIN, 18);
}
 
Example 11
Project: incubator-netbeans   File: OutlineViewDropSupport.java   View source code 6 votes vote down vote up
/** Activates or deactivates Drag support on asociated JTree
* component
* @param active true if the support should be active, false
* otherwise
*/
public void activate(boolean active) {
    if (this.active == active) {
        return;
    }

    this.active = active;
    if (GraphicsEnvironment.isHeadless()) {
        return;
    }
    getDropTarget().setActive(active);
    //we want to support drop into scroll pane's free area and treat it as 'root node drop'
    if( null == outerDropTarget ) {
        outerDropTarget = new DropTarget(view.getViewport(), view.getAllowedDropActions(), this, false);
    }
    outerDropTarget.setActive(active);
}
 
Example 12
Project: openjdk-jdk10   File: VolatileImageBug.java   View source code 6 votes vote down vote up
public static void main(String[] args) {

        boolean iaeThrown = false;
        GraphicsEnvironment ge = GraphicsEnvironment.
                                      getLocalGraphicsEnvironment();
        GraphicsConfiguration gc = ge.getDefaultScreenDevice().
                                           getDefaultConfiguration();
        try {
            VolatileImage volatileImage = gc.createCompatibleVolatileImage(0, 0);
        } catch (IllegalArgumentException iae) {
            iaeThrown = true;
        }
        if (!iaeThrown) {
            throw new RuntimeException ("IllegalArgumentException not thrown " +
                                        "for createCompatibleVolatileImage(0,0)");
        }
    }
 
Example 13
Project: openjdk-jdk10   File: MultiScreenRobotPosition.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment()
                                              .getScreenDevices();
    for (final GraphicsDevice gd : sds) {
        fail = true;
        Robot robot = new Robot(gd);
        robot.setAutoDelay(100);
        robot.setAutoWaitForIdle(true);

        Frame frame = new Frame(gd.getDefaultConfiguration());
        frame.setUndecorated(true);
        frame.setSize(400, 400);
        frame.setVisible(true);
        robot.waitForIdle();

        frame.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("e = " + e);
                fail = false;
            }
        });

        Rectangle bounds = frame.getBounds();
        robot.mouseMove(bounds.x + bounds.width / 2,
                        bounds.y + bounds.height / 2);
        robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
        frame.dispose();
        if (fail) {
            System.err.println("Frame bounds = " + bounds);
            throw new RuntimeException("Click in the wrong location");
        }
    }
}
 
Example 14
Project: openjdk-jdk10   File: IsToolkitUseTheMainScreen.java   View source code 6 votes vote down vote up
private static void testHeadful() {
    GraphicsEnvironment ge
            = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc
            = ge.getDefaultScreenDevice().getDefaultConfiguration();
    Dimension gcSize = gc.getBounds().getSize();
    ColorModel gcCM = gc.getColorModel();

    Dimension toolkitSize = Toolkit.getDefaultToolkit().getScreenSize();
    ColorModel toolkitCM = Toolkit.getDefaultToolkit().getColorModel();

    if (!gcSize.equals(toolkitSize)) {
        System.err.println("Toolkit size = " + toolkitSize);
        System.err.println("GraphicsConfiguration size = " + gcSize);
        throw new RuntimeException("Incorrect size");
    }
    if (!gcCM.equals(toolkitCM)) {
        System.err.println("Toolkit color model = " + toolkitCM);
        System.err.println("GraphicsConfiguration color model = " + gcCM);
        throw new RuntimeException("Incorrect color model");
    }
}
 
Example 15
Project: openjdk-jdk10   File: XlibUtil.java   View source code 6 votes vote down vote up
/**
 * Xinerama-aware version of XlibWrapper.RootWindow method.
 */
public static long getRootWindow(int screenNumber)
{
    XToolkit.awtLock();
    try
    {
        X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        if (x11ge.runningXinerama())
        {
            // all the Xinerama windows share the same root window
            return XlibWrapper.RootWindow(XToolkit.getDisplay(), 0);
        }
        else
        {
            return XlibWrapper.RootWindow(XToolkit.getDisplay(), screenNumber);
        }
    }
    finally
    {
        XToolkit.awtUnlock();
    }
}
 
Example 16
Project: jdk8u-jdk   File: Desktop.java   View source code 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 17
Project: openjdk-jdk10   File: DisplayChangeVITest.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
 
Example 18
Project: openjdk-jdk10   File: MultiMonPrintDlgTest.java   View source code 6 votes vote down vote up
private void executeTest() {

        GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int x = 0;
        Frame f = null;
        for (x = 0; x < gd.length; x ++) {
            if (gd[x] != defDev) {
                secFrame = new Frame("Screen " + x + " - secondary", gd[x].getDefaultConfiguration());
                f = secFrame;
            } else {
                primaryFrame = new Frame("Screen " + x + " - primary", gd[x].getDefaultConfiguration());
                f = primaryFrame;
            }
            Button b = new Button("Print");
            b.addActionListener(this);
            f.add("South", b);
            f.addWindowListener (new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    ((Window) we.getSource()).dispose();
                }
            });
            f.setSize(200, 200);
            f.setVisible(true);
        }
    }
 
Example 19
Project: Pixie   File: Resize.java   View source code 6 votes vote down vote up
/**
 * Resize the window to user prefer size. In case the zoomed user preference
 * is not set, then resize the width and height to fit the max display size
 * In case the provided width and height are smaller than max allowed size
 * they will be zoomed in(maximized) to max allowed size. In case the width
 * and height are bigger than max allowed size they will be zoomed
 * out(minimized) to max allowed size
 *
 * @param width           object's width
 * @param height          object's height
 * @param userZoomedIndex user's prefer zoomed index
 */
public Resize(int width, int height, int userZoomedIndex) {
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    int widthSc = gd.getDisplayMode().getWidth();
    int heightSc = gd.getDisplayMode().getHeight();
    double ratioW;
    double ratioH;
    double cropRatio;

    /* did the user saved its zoomed preference? */
    if (userZoomedIndex == Integer.MAX_VALUE) {
        ratioW = (double) width / (widthSc * MAX_SCREEN_PERCENT_RESIZE);
        ratioH = (double) height / (heightSc * MAX_SCREEN_PERCENT_RESIZE);
        cropRatio = (double) width / (double) height;
    } else {
        int tmpWidth = Math.abs(width) + userZoomedIndex * Math.abs(width / ZOOMING_FACTOR);
        int tmpHeight = Math.abs(height) + userZoomedIndex * Math.abs(height / ZOOMING_FACTOR);

        ratioW = (double) width / (double) tmpWidth;
        ratioH = (double) height / (double) tmpHeight;
        cropRatio = (double) width / (double) height;
    }

    computeResizeRatios(ratioW, ratioH, cropRatio, width, height, widthSc, heightSc);
}
 
Example 20
Project: OpenJSharp   File: WGLSurfaceData.java   View source code 5 votes vote down vote up
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 21
Project: JavaGraph   File: Icons.java   View source code 5 votes vote down vote up
/** Creates a named cursor from a given file. */
static private Cursor createCursor(String name, ImageIcon icon) {
    if (GraphicsEnvironment.isHeadless()) {
        // The environtment variable DISPLAY is not set. We can't call
        // createCustomCursor from the awt toolkit because this causes
        // a java.awt.HeadlessException. In any case we don't need the
        // cursor because we are running without GUI, so we just abort.
        return null;
    } else {
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image cursorImage = icon.getImage();
        return tk.createCustomCursor(cursorImage, new Point(0, 0), name);
    }
}
 
Example 22
Project: SerialPortDemo   File: MainFrame.java   View source code 5 votes vote down vote up
private void initView() {
	// 关闭程序
	setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
	// 禁止窗口最大化
	setResizable(false);

	// 设置程序窗口居中显示
	Point p = GraphicsEnvironment.getLocalGraphicsEnvironment()
			.getCenterPoint();
	setBounds(p.x - WIDTH / 2, p.y - HEIGHT / 2, WIDTH, HEIGHT);
	this.setLayout(null);

	setTitle("串口通讯");
}
 
Example 23
Project: openjdk-jdk10   File: IncorrectAlphaConversionBicubic.java   View source code 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 24
Project: OpenJSharp   File: FontPanel.java   View source code 5 votes vote down vote up
static Integer getDefaultLCDContrast() {
    if (defaultContrast == null) {
        GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
    Graphics2D g2d =
        (Graphics2D)(gc.createCompatibleImage(1,1).getGraphics());
    defaultContrast = (Integer)
        g2d.getRenderingHint(RenderingHints.KEY_TEXT_LCD_CONTRAST);
    }
    return defaultContrast;
}
 
Example 25
Project: incubator-netbeans   File: PaletteItemRegistrationProcessorTest.java   View source code 5 votes vote down vote up
public void testAnnotatedPackage() throws IOException {
    //missing body
    clearWorkDir();
    assertTrue("Headless run", GraphicsEnvironment.isHeadless());
    AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testa.package-info",
            VALID_PACKAGE_ANNOTATION
            + "\npackage testa\n;"
            + "import org.netbeans.spi.palette.PaletteItemRegistration;\n");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
    assertTrue("Compilation has to be successfull:\n" + os, r);
}
 
Example 26
Project: incubator-netbeans   File: StatusLineComponent.java   View source code 5 votes vote down vote up
public void hidePopup() {
        if (GraphicsEnvironment.isHeadless()) {
            return;
        }
        if (popupWindow != null) {
//            popupWindow.getContentPane().removeAll();
            popupWindow.setVisible(false);
        }
        Toolkit.getDefaultToolkit().removeAWTEventListener(hideListener);
        WindowManager.getDefault().getMainWindow().removeWindowStateListener(hideListener);
        WindowManager.getDefault().getMainWindow().removeComponentListener(hideListener);
        showingPopup = false;
    }
 
Example 27
Project: incubator-netbeans   File: ProjectUiModule.java   View source code 5 votes vote down vote up
@Override
public void restored() {
    if (!GraphicsEnvironment.isHeadless()) {
        Hacks.keepCurrentProjectNameUpdated();
    }
    BrokenProjectNotifier.getInstnace().start();
}
 
Example 28
Project: jdk8u-jdk   File: GLXSurfaceData.java   View source code 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 29
Project: owa-notifier   File: Screen.java   View source code 5 votes vote down vote up
private void setupDimensions(boolean spanMultipleMonitors) {
	if (spanMultipleMonitors) {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		m_width = screenSize.width;
		m_height = screenSize.height;

	} else {
		GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
		m_width = gd.getDisplayMode().getWidth();
		m_height = gd.getDisplayMode().getHeight();
	}
}
 
Example 30
Project: incubator-netbeans   File: PaletteItemRegistrationProcessorTest.java   View source code 5 votes vote down vote up
public void testActiveEditorDropAnnotatedWithInvalidResources() throws IOException {
    clearWorkDir();
    assertTrue("Headless run", GraphicsEnvironment.isHeadless());
    AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
            "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
            + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
            + INVALIDRESOURCE_CLASS_ANNOTATION
            + "public class B implements ActiveEditorDrop {\n"
            + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
            + "}\n");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
    assertFalse("Compilation has to fail:\n" + os, r);
}
 
Example 31
Project: Luyten4Forge   File: JFontChooser.java   View source code 5 votes vote down vote up
protected String[] getFontFamilies() {
	if (fontFamilyNames == null) {
		GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
		fontFamilyNames = env.getAvailableFontFamilyNames();
	}
	return fontFamilyNames;
}
 
Example 32
Project: incubator-netbeans   File: NbEvents.java   View source code 5 votes vote down vote up
private void notify(String text, boolean warn) {
    if (GraphicsEnvironment.isHeadless() || Boolean.getBoolean("netbeans.full.hack")) { // NOI18N
        // #21773: interferes with automated GUI testing.
        logger.log(Level.WARNING, "{0}\n", text);
    } else {
        // Normal - display dialog.
        new Notifier(text, warn).show();
    }
}
 
Example 33
Project: powertext   File: Util.java   View source code 5 votes vote down vote up
/**
 * Returns the screen coordinates for the monitor that contains the
 * specified point.  This is useful for setups with multiple monitors,
 * to ensure that popup windows are positioned properly.
 *
 * @param x The x-coordinate, in screen coordinates.
 * @param y The y-coordinate, in screen coordinates.
 * @return The bounds of the monitor that contains the specified point.
 */
public static Rectangle getScreenBoundsForPoint(int x, int y) {
	GraphicsEnvironment env = GraphicsEnvironment.
									getLocalGraphicsEnvironment();
	GraphicsDevice[] devices = env.getScreenDevices();
	for (int i=0; i<devices.length; i++) {
		GraphicsConfiguration config = devices[i].getDefaultConfiguration();
		Rectangle gcBounds = config.getBounds();
		if (gcBounds.contains(x, y)) {
			return gcBounds;
		}
	}
	// If point is outside all monitors, default to default monitor (?)
	return env.getMaximumWindowBounds();
}
 
Example 34
Project: OpenJSharp   File: DragSource.java   View source code 5 votes vote down vote up
private static Cursor load(String name) {
    if (GraphicsEnvironment.isHeadless()) {
        return null;
    }

    try {
        return (Cursor)Toolkit.getDefaultToolkit().getDesktopProperty(name);
    } catch (Exception e) {
        e.printStackTrace();

        throw new RuntimeException("failed to load system cursor: " + name + " : " + e.getMessage());
    }
}
 
Example 35
Project: BaseClient   File: MinecraftServer.java   View source code 5 votes vote down vote up
public void addServerTypeToSnooper(PlayerUsageSnooper playerSnooper)
{
    playerSnooper.addStatToSnooper("singleplayer", Boolean.valueOf(this.isSinglePlayer()));
    playerSnooper.addStatToSnooper("server_brand", this.getServerModName());
    playerSnooper.addStatToSnooper("gui_supported", GraphicsEnvironment.isHeadless() ? "headless" : "supported");
    playerSnooper.addStatToSnooper("dedicated", Boolean.valueOf(this.isDedicatedServer()));
}
 
Example 36
Project: incubator-netbeans   File: DragWindow.java   View source code 5 votes vote down vote up
private BufferedImage createTabImage() {
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    //the tab rectangle must be painted by top-level window otherwise the transparent 
    //button icons will be messed up
    Window parentWindow = SwingUtilities.getWindowAncestor(container.getComponent());
    Rectangle rect = SwingUtilities.convertRectangle(container.getComponent(), tabRectangle, parentWindow);
    BufferedImage res = config.createCompatibleImage(tabRectangle.width, tabRectangle.height);
    Graphics2D g = res.createGraphics();
    g.translate(-rect.x, -rect.y);
    g.setClip(rect);
    parentWindow.paint(g);
    return res;
}
 
Example 37
Project: sbc-qsystem   File: ABoardFX.java   View source code 5 votes vote down vote up
/**
 */
public void showBoard() {
    if (0 != cfg.getInt("device", 0)) {

        GraphicsDevice[] screenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getScreenDevices();
        int i = 1;
        for (GraphicsDevice graphicsDevice : screenDevices) {
            System.out.println(
                "graphicsDevice = " + graphicsDevice.getIDstring() + " " + graphicsDevice
                    .toString()
                    + "\nРазрешение экрана " + graphicsDevice.getDefaultConfiguration()
                    .getBounds().height + "x" + graphicsDevice.getDefaultConfiguration()
                    .getBounds().width
                    + "\nГлубина цвета " + graphicsDevice.getDisplayMode().getBitDepth()
                    + "\nЧастота " + graphicsDevice.getDisplayMode().getRefreshRate()
                    + "\nНачало координат " + graphicsDevice.getDefaultConfiguration()
                    .getBounds().x
                    + "-" + graphicsDevice.getDefaultConfiguration().getBounds().y);
            if (i == cfg.getInt("device")) {
                win_x = graphicsDevice.getDefaultConfiguration().getBounds().x;
                win_y = graphicsDevice.getDefaultConfiguration().getBounds().y;
                win_w = graphicsDevice.getDefaultConfiguration().getBounds().width;
                win_h = graphicsDevice.getDefaultConfiguration().getBounds().height;
            }
            i++;
        }

        SwingUtilities.invokeLater(() -> {
            initAndShowGUI();
        });
    }
}
 
Example 38
Project: jdk8u-jdk   File: SurfaceDataProxy.java   View source code 5 votes vote down vote up
/**
 * This method should be called from subclasses which create
 * cached SurfaceData objects that depend on the current
 * properties of the display.
 */
protected void activateDisplayListener() {
    GraphicsEnvironment ge =
        GraphicsEnvironment.getLocalGraphicsEnvironment();
    // We could have a HeadlessGE at this point, so double-check before
    // assuming anything.
    // Also, no point in listening to display change events if
    // the image is never going to be accelerated.
    if (ge instanceof SunGraphicsEnvironment) {
        ((SunGraphicsEnvironment)ge).addDisplayChangedListener(this);
    }
}
 
Example 39
Project: incubator-netbeans   File: PropertyPanel.java   View source code 5 votes vote down vote up
/** The constructor all the other constructors call */
private PropertyPanel(Node.Property p, int preferences, PropertyModel mdl) {
    if (p == null) {
        prop = ModelProperty.toProperty(mdl);
    } else {
        prop = p;
    }

    this.preferences = preferences;
    initializing = true;
    setModel(mdl);
    initializing = false;
    setOpaque(true);

    if (!GraphicsEnvironment.isHeadless()) {
        //for debugging, allow CTRL-. to dump the state to stderr
        getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
            KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "dump"
        );
    }
    getActionMap().put(
        "dump",
        new AbstractAction() { //NOI18N
            public void actionPerformed(ActionEvent ae) {
                System.err.println(""); //NOI18N
                System.err.println(PropertyPanel.this);
                System.err.println(""); //NOI18N
            }
        }
    );

    //#44226 - Unpretty, but this allows the TreeTableView to invoke a custom editor dialog when
    //necessary - with the TTV rewrite, all cell editor infrastructure will be moved to
    //org.netbeans.modules.openide.explorer, and they will simply share editor classes.  Since that
    //involves an API change (some package private methods of PropertyEnv need to be accessible to
    //the editor classes), this will have to wait for after 4.0 - Tim
    getActionMap().put("invokeCustomEditor", new CustomEditorProxyAction()); //NOI18N

    PropertyPanelBridge.register(this, new BridgeAccessor(this));
}
 
Example 40
Project: jdk8u-jdk   File: WGLSurfaceData.java   View source code 5 votes vote down vote up
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();
    }
}