use of java.awt.GraphicsEnvironment in project processing by processing.
the class EditorState method defaultConfig.
GraphicsConfiguration defaultConfig() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = ge.getDefaultScreenDevice();
GraphicsConfiguration config = device.getDefaultConfiguration();
// deviceName = device.getIDstring();
deviceBounds = config.getBounds();
return config;
}
use of java.awt.GraphicsEnvironment 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.GraphicsEnvironment in project processing by processing.
the class Toolkit method getMonoFontList.
// Gets the plain (not bold, not italic) version of each
private static List<Font> getMonoFontList() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = ge.getAllFonts();
List<Font> outgoing = new ArrayList<Font>();
// Using AffineTransform.getScaleInstance(100, 100) doesn't change sizes
FontRenderContext frc = new FontRenderContext(new AffineTransform(), Preferences.getBoolean("editor.antialias"), // use fractional metrics
true);
for (Font font : fonts) {
if (font.getStyle() == Font.PLAIN && font.canDisplay('i') && font.canDisplay('M') && font.canDisplay(' ') && font.canDisplay('.')) {
// The old method just returns 1 or 0, and using deriveFont(size)
// is overkill. It also causes deprecation warnings
// @SuppressWarnings("deprecation")
// FontMetrics fm = awtToolkit.getFontMetrics(font);
//FontMetrics fm = awtToolkit.getFontMetrics(font.deriveFont(24));
// System.out.println(fm.charWidth('i') + " " + fm.charWidth('M'));
// if (fm.charWidth('i') == fm.charWidth('M') &&
// fm.charWidth('M') == fm.charWidth(' ') &&
// fm.charWidth(' ') == fm.charWidth('.')) {
double w = font.getStringBounds(" ", frc).getWidth();
if (w == font.getStringBounds("i", frc).getWidth() && w == font.getStringBounds("M", frc).getWidth() && w == font.getStringBounds(".", frc).getWidth()) {
// //PApplet.printArray(font.getAvailableAttributes());
// Map<TextAttribute,?> attr = font.getAttributes();
// System.out.println(font.getFamily() + " > " + font.getName());
// System.out.println(font.getAttributes());
// System.out.println(" " + attr.get(TextAttribute.WEIGHT));
// System.out.println(" " + attr.get(TextAttribute.POSTURE));
outgoing.add(font);
// System.out.println(" good " + w);
}
}
}
return outgoing;
}
use of java.awt.GraphicsEnvironment 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.GraphicsEnvironment 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;
}
Aggregations