use of java.awt.GraphicsDevice in project processing by processing.
the class EditorState method checkConfig.
/**
* Returns a GraphicsConfiguration so that a new Editor Frame can be
* constructed. First tries to match the bounds for this state information
* to an existing config (nominally, a display) and if that doesn't work,
* then returns the default configuration/default display.
*/
GraphicsConfiguration checkConfig() {
if (deviceBounds != null) {
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices();
for (GraphicsDevice device : screenDevices) {
GraphicsConfiguration[] configurations = device.getConfigurations();
for (GraphicsConfiguration config : configurations) {
// if (config.getDevice().getIDstring().equals(deviceName)) {
if (config.getBounds().equals(deviceBounds)) {
return config;
}
}
}
}
// otherwise go to the default config
return defaultConfig();
}
use of java.awt.GraphicsDevice in project processing by processing.
the class PSurfaceAWT method getDisplaySpan.
//public void initImage(PGraphics gr, int wide, int high) {
/*
@Override
public void initImage(PGraphics graphics) {
GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
// If not realized (off-screen, i.e the Color Selector Tool), gc will be null.
if (gc == null) {
System.err.println("GraphicsConfiguration null in initImage()");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
}
// Formerly this was broken into separate versions based on offscreen or
// not, but we may as well create a compatible image; it won't hurt, right?
int wide = graphics.width * graphics.pixelFactor;
int high = graphics.height * graphics.pixelFactor;
graphics.image = gc.createCompatibleImage(wide, high);
}
*/
// @Override
// public Component getComponent() {
// return canvas;
// }
// @Override
// public void setSmooth(int level) {
// }
/*
private boolean checkRetina() {
if (PApplet.platform == PConstants.MACOSX) {
// 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 7 API.
// Also, should we use the Toolkit associated with the editor window?
final String javaVendor = System.getProperty("java.vendor");
if (javaVendor.contains("Oracle")) {
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;
}
*/
/** Get the bounds rectangle for all displays. */
static Rectangle getDisplaySpan() {
Rectangle bounds = new Rectangle();
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (GraphicsDevice device : environment.getScreenDevices()) {
for (GraphicsConfiguration config : device.getConfigurations()) {
Rectangle2D.union(bounds, config.getBounds(), bounds);
}
}
return bounds;
}
use of java.awt.GraphicsDevice in project processing by processing.
the class Runner method getSketchParams.
protected StringList getSketchParams(boolean present, String[] args) {
StringList params = new StringList();
// http://processing.org/bugs/bugzilla/1446.html
if (build.getFoundMain()) {
params.append(build.getSketchClassName());
} else {
params.append("processing.core.PApplet");
// get the stored device index (starts at 1)
int runDisplay = Preferences.getInteger("run.display");
// --editor-location=150,20
if (editor != null) {
// if running processing-cmd, don't do placement
GraphicsDevice editorDevice = editor.getGraphicsConfiguration().getDevice();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = ge.getScreenDevices();
// Make sure the display set in Preferences actually exists
GraphicsDevice runDevice = editorDevice;
if (runDisplay > 0 && runDisplay <= devices.length) {
runDevice = devices[runDisplay - 1];
} else {
// If a bad display is selected, use the same display as the editor
if (runDisplay > 0) {
// don't complain about -1 or 0
System.err.println("Display " + runDisplay + " not available.");
}
runDevice = editorDevice;
for (int i = 0; i < devices.length; i++) {
if (devices[i] == runDevice) {
// Wasn't setting the pref to avoid screwing things up with
// something temporary. But not setting it makes debugging one's
// setup just too damn weird, so changing that behavior.
runDisplay = i + 1;
System.err.println("Setting 'Run Sketches on Display' preference to display " + runDisplay);
Preferences.setInteger("run.display", runDisplay);
break;
}
}
}
Point windowLocation = editor.getSketchLocation();
// }
if (windowLocation == null) {
if (editorDevice == runDevice) {
// If sketches are to be shown on the same display as the editor,
// provide the editor location so the sketch's main() can place it.
Point editorLocation = editor.getLocation();
params.append(PApplet.ARGS_EDITOR_LOCATION + "=" + editorLocation.x + "," + editorLocation.y);
} else {
// The sketch's main() will set a location centered on the new
// display. It has to happen in main() because the width/height
// of the sketch are not known here.
// Set a location centered on the other display
// Rectangle screenRect =
// runDevice.getDefaultConfiguration().getBounds();
// int runX =
// params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
}
} else {
params.append(PApplet.ARGS_LOCATION + "=" + windowLocation.x + "," + windowLocation.y);
}
params.append(PApplet.ARGS_EXTERNAL);
}
params.append(PApplet.ARGS_DISPLAY + "=" + runDisplay);
if (present) {
params.append(PApplet.ARGS_PRESENT);
// if (Preferences.getBoolean("run.present.exclusive")) {
// params.add(PApplet.ARGS_EXCLUSIVE);
// }
params.append(PApplet.ARGS_STOP_COLOR + "=" + Preferences.get("run.present.stop.color"));
params.append(PApplet.ARGS_WINDOW_COLOR + "=" + Preferences.get("run.present.bgcolor"));
}
// There was a PDE X hack that put this after the class name, but it was
// removed for 3.0a6 because it would break the args passed to sketches.
params.append(PApplet.ARGS_SKETCH_FOLDER + "=" + build.getSketchPath());
params.append(build.getSketchClassName());
}
// Add command-line arguments to be given to the sketch itself
if (args != null) {
params.append(args);
}
// Pass back the whole list
return params;
}
use of java.awt.GraphicsDevice in project javatari by ppeccin.
the class SwingHelper method getGraphicsConfigurationForCurrentLocation.
public static GraphicsConfiguration getGraphicsConfigurationForCurrentLocation(Window window) {
GraphicsConfiguration ownedConfig = window.getGraphicsConfiguration();
Point currLocation = window.getLocation();
// Shortcut for "owned" case
if (ownedConfig.getBounds().contains(currLocation))
return ownedConfig;
// Search for the right screen
GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
for (GraphicsDevice screen : screens) for (GraphicsConfiguration config : screen.getConfigurations()) if (config.getBounds().contains(currLocation))
return config;
// If none found, lets return the "owned" one
return ownedConfig;
}
use of java.awt.GraphicsDevice in project jadx by skylot.
the class MainWindow method setLocationAndPosition.
public void setLocationAndPosition() {
if (this.settings.loadWindowPos(this)) {
return;
}
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode mode = gd.getDisplayMode();
int w = mode.getWidth();
int h = mode.getHeight();
setLocation((int) (w * BORDER_RATIO), (int) (h * BORDER_RATIO));
setSize((int) (w * WINDOW_RATIO), (int) (h * WINDOW_RATIO));
}
Aggregations