Search in sources :

Example 46 with GraphicsDevice

use of java.awt.GraphicsDevice in project screenbird by adamhub.

the class ScreenUtilTest method testGetScreenDimension.

/**
     * Test of getScreenDimension method, of class ScreenUtil.
     */
@Test
public void testGetScreenDimension() {
    log("getScreenDimension");
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gd = ge.getScreenDevices()[0].getDefaultConfiguration();
    GraphicsDevice device = gd.getDevice();
    Dimension result = ScreenUtil.getScreenDimension(device);
    assertNotNull(result);
    assertNotSame(0, result.height);
    assertNotSame(0, result.width);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration) Test(org.junit.Test)

Example 47 with GraphicsDevice

use of java.awt.GraphicsDevice in project processing by processing.

the class PSurfaceJOGL method initDisplay.

protected void initDisplay() {
    Display tmpDisplay = NewtFactory.createDisplay(null);
    tmpDisplay.addReference();
    Screen tmpScreen = NewtFactory.createScreen(tmpDisplay, 0);
    tmpScreen.addReference();
    monitors = new ArrayList<MonitorDevice>();
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] awtDevices = environment.getScreenDevices();
    List<MonitorDevice> newtDevices = tmpScreen.getMonitorDevices();
    // tries to address the differences.
    if (PApplet.platform == PConstants.LINUX) {
        for (GraphicsDevice device : awtDevices) {
            String did = device.getIDstring();
            String[] parts = did.split("\\.");
            String id1 = "";
            if (1 < parts.length) {
                id1 = parts[1].trim();
            }
            MonitorDevice monitor = null;
            int id0 = newtDevices.size() > 0 ? newtDevices.get(0).getId() : 0;
            for (int i = 0; i < newtDevices.size(); i++) {
                MonitorDevice mon = newtDevices.get(i);
                String mid = String.valueOf(mon.getId() - id0);
                if (id1.equals(mid)) {
                    monitor = mon;
                    break;
                }
            }
            if (monitor != null) {
                monitors.add(monitor);
            }
        }
    } else if (PApplet.platform == PConstants.WINDOWS) {
        // NEWT display id is == (adapterId << 8 | monitorId),
        // should be in the same order as AWT
        monitors.addAll(newtDevices);
    } else {
        // MAC OSX and others
        for (GraphicsDevice device : awtDevices) {
            String did = device.getIDstring();
            String[] parts = did.split("Display");
            String id1 = "";
            if (1 < parts.length) {
                id1 = parts[1].trim();
            }
            MonitorDevice monitor = null;
            for (int i = 0; i < newtDevices.size(); i++) {
                MonitorDevice mon = newtDevices.get(i);
                String mid = String.valueOf(mon.getId());
                if (id1.equals(mid)) {
                    monitor = mon;
                    break;
                }
            }
            if (monitor == null) {
                // Didn't find a matching monitor, try using less stringent id check
                for (int i = 0; i < newtDevices.size(); i++) {
                    MonitorDevice mon = newtDevices.get(i);
                    String mid = String.valueOf(mon.getId());
                    if (-1 < did.indexOf(mid)) {
                        monitor = mon;
                        break;
                    }
                }
            }
            if (monitor != null) {
                monitors.add(monitor);
            }
        }
    }
    displayDevice = null;
    int displayNum = sketch.sketchDisplay();
    if (displayNum > 0) {
        // if -1, use the default device
        if (displayNum <= monitors.size()) {
            displayDevice = monitors.get(displayNum - 1);
        } else {
            System.err.format("Display %d does not exist, " + "using the default display instead.%n", displayNum);
            for (int i = 0; i < monitors.size(); i++) {
                System.err.format("Display %d is %s%n", i + 1, monitors.get(i));
            }
        }
    } else if (0 < monitors.size()) {
        displayDevice = monitors.get(0);
    }
    if (displayDevice != null) {
        screen = displayDevice.getScreen();
        display = screen.getDisplay();
    } else {
        screen = tmpScreen;
        display = tmpDisplay;
        displayDevice = screen.getPrimaryMonitor();
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Screen(com.jogamp.newt.Screen) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) Display(com.jogamp.newt.Display) MonitorDevice(com.jogamp.newt.MonitorDevice)

Example 48 with GraphicsDevice

use of java.awt.GraphicsDevice in project javatari by ppeccin.

the class SwingHelper method defaultScreenDevice.

public static GraphicsDevice defaultScreenDevice() {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    if (env == null)
        throw new UnsupportedOperationException("Could not get Local Graphics Environment");
    GraphicsDevice dev = env.getDefaultScreenDevice();
    if (dev == null)
        throw new UnsupportedOperationException("Could not get Default Graphics Device");
    return dev;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 49 with GraphicsDevice

use of java.awt.GraphicsDevice in project processing by processing.

the class PSurfaceAWT method initFrame.

/*
  public Frame initOffscreen() {
    Frame dummy = new Frame();
    dummy.pack();  // get legit AWT graphics
    // but don't show it
    return dummy;
  }
  */
/*
  @Override
  public Component initComponent(PApplet sketch) {
    this.sketch = sketch;

    // needed for getPreferredSize() et al
    sketchWidth = sketch.sketchWidth();
    sketchHeight = sketch.sketchHeight();

    return canvas;
  }
  */
@Override
public void initFrame(final PApplet sketch) {
    /*, int backgroundColor,
                        int deviceIndex, boolean fullScreen, boolean spanDisplays) {*/
    this.sketch = sketch;
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    int displayNum = sketch.sketchDisplay();
    //    System.out.println("display from sketch is " + displayNum);
    if (displayNum > 0) {
        // if -1, use the default device
        GraphicsDevice[] devices = environment.getScreenDevices();
        if (displayNum <= devices.length) {
            displayDevice = devices[displayNum - 1];
        } else {
            System.err.format("Display %d does not exist, " + "using the default display instead.%n", displayNum);
            for (int i = 0; i < devices.length; i++) {
                System.err.format("Display %d is %s%n", (i + 1), devices[i]);
            }
        }
    }
    if (displayDevice == null) {
        displayDevice = environment.getDefaultScreenDevice();
    }
    // Need to save the window bounds at full screen,
    // because pack() will cause the bounds to go to zero.
    // http://dev.processing.org/bugs/show_bug.cgi?id=923
    boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
    screenRect = spanDisplays ? getDisplaySpan() : displayDevice.getDefaultConfiguration().getBounds();
    // DisplayMode doesn't work here, because we can't get the upper-left
    // corner of the display, which is important for multi-display setups.
    // Set the displayWidth/Height variables inside PApplet, so that they're
    // usable and can even be returned by the sketchWidth()/Height() methods.
    sketch.displayWidth = screenRect.width;
    sketch.displayHeight = screenRect.height;
    sketchWidth = sketch.sketchWidth();
    sketchHeight = sketch.sketchHeight();
    boolean fullScreen = sketch.sketchFullScreen();
    if (fullScreen || spanDisplays) {
        sketchWidth = screenRect.width;
        sketchHeight = screenRect.height;
    }
    // Using a JFrame fixes a Windows problem with Present mode. This might
    // be our error, but usually this is the sort of crap we usually get from
    // OS X. It's time for a turnaround: Redmond is thinking different too!
    // https://github.com/processing/processing/issues/1955
    frame = new JFrame(displayDevice.getDefaultConfiguration());
    //    frame = new Frame(displayDevice.getDefaultConfiguration());
    //    // Default Processing gray, which will be replaced below if another
    //    // color is specified on the command line (i.e. in the prefs).
    //    ((JFrame) frame).getContentPane().setBackground(WINDOW_BGCOLOR);
    //    // Cannot call setResizable(false) until later due to OS X (issue #467)
    //    // Removed code above, also removed from what's now in the placeXxxx()
    //    // methods. Not sure why it was being double-set; hopefully anachronistic.
    //    if (backgroundColor == 0) {
    //      backgroundColor = WINDOW_BGCOLOR;
    //    }
    final Color windowColor = new Color(sketch.sketchWindowColor(), false);
    if (frame instanceof JFrame) {
        ((JFrame) frame).getContentPane().setBackground(windowColor);
    } else {
        frame.setBackground(windowColor);
    }
    // Put the p5 logo in the Frame's corner to override the Java coffee cup.
    setProcessingIcon(frame);
    // For 0149, moving this code (up to the pack() method) before init().
    // For OpenGL (and perhaps other renderers in the future), a peer is
    // needed before a GLDrawable can be created. So pack() needs to be
    // called on the Frame before applet.init(), which itself calls size(),
    // and launches the Thread that will kick off setup().
    // http://dev.processing.org/bugs/show_bug.cgi?id=891
    // http://dev.processing.org/bugs/show_bug.cgi?id=908
    frame.add(canvas);
    setSize(sketchWidth, sketchHeight);
    /*
    if (fullScreen) {
      // Called here because the graphics device is needed before we can
      // determine whether the sketch wants size(displayWidth, displayHeight),
      // and getting the graphics device will be PSurface-specific.
      PApplet.hideMenuBar();

      // Tried to use this to fix the 'present' mode issue.
      // Did not help, and the screenRect setup seems to work fine.
      //frame.setExtendedState(Frame.MAXIMIZED_BOTH);

      // https://github.com/processing/processing/pull/3162
      frame.dispose();  // release native resources, allows setUndecorated()
      frame.setUndecorated(true);
      // another duplicate?
//      if (backgroundColor != null) {
//        frame.getContentPane().setBackground(backgroundColor);
//      }
      // this may be the bounds of all screens
      frame.setBounds(screenRect);
      // will be set visible in placeWindow() [3.0a10]
      //frame.setVisible(true);  // re-add native resources
    }
    */
    frame.setLayout(null);
    if (fullScreen) {
        frame.invalidate();
    } else {
    //      frame.pack();
    }
    // insufficient, places the 100x100 sketches offset strangely
    //frame.validate();
    // disabling resize has to happen after pack() to avoid apparent Apple bug
    // http://code.google.com/p/processing/issues/detail?id=467
    frame.setResizable(false);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            // don't quit, need to just shut everything down (0133)
            sketch.exit();
        }
    });
//    sketch.setFrame(frame);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) JFrame(javax.swing.JFrame) Color(java.awt.Color) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point)

Example 50 with GraphicsDevice

use of java.awt.GraphicsDevice in project processing by processing.

the class Toolkit method checkRetina.

// This should probably be reset each time there's a display change.
// A 5-minute search didn't turn up any such event in the Java API.
// Also, should we use the Toolkit associated with the editor window?
private static boolean checkRetina() {
    if (Platform.isMacOS()) {
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice device = env.getDefaultScreenDevice();
        try {
            Field field = device.getClass().getDeclaredField("scale");
            if (field != null) {
                field.setAccessible(true);
                Object scale = field.get(device);
                if (scale instanceof Integer && ((Integer) scale).intValue() == 2) {
                    return true;
                }
            }
        } catch (Exception ignore) {
        }
    }
    return false;
}
Also used : Field(java.lang.reflect.Field) GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) FontFormatException(java.awt.FontFormatException) IOException(java.io.IOException)

Aggregations

GraphicsDevice (java.awt.GraphicsDevice)80 GraphicsEnvironment (java.awt.GraphicsEnvironment)46 GraphicsConfiguration (java.awt.GraphicsConfiguration)25 Point (java.awt.Point)17 Dimension (java.awt.Dimension)15 Frame (java.awt.Frame)13 DisplayMode (java.awt.DisplayMode)12 Rectangle (java.awt.Rectangle)11 Graphics (java.awt.Graphics)7 Insets (java.awt.Insets)7 Toolkit (java.awt.Toolkit)7 BufferedImage (java.awt.image.BufferedImage)7 HeadlessException (java.awt.HeadlessException)5 Window (java.awt.Window)4 JFrame (javax.swing.JFrame)4 Test (org.junit.Test)4 MouseAdapter (java.awt.event.MouseAdapter)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3 VolatileImage (java.awt.image.VolatileImage)3