use of java.awt.GraphicsEnvironment 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;
}
use of java.awt.GraphicsEnvironment in project processing by processing.
the class Toolkit method createFont.
/**
* Get a font from the lib/fonts folder. Our default fonts are also
* installed there so that the monospace (and others) can be used by other
* font listing calls (i.e. it appears in the list of monospace fonts in
* the Preferences window, and can be used by HTMLEditorKit for WebFrame).
*/
private static Font createFont(String filename, int size) throws IOException, FontFormatException {
boolean registerFont = false;
// try the JRE font directory first
File fontFile = new File(System.getProperty("java.home"), "lib/fonts/" + filename);
// else fall back to our own content dir
if (!fontFile.exists()) {
fontFile = Platform.getContentFile("lib/fonts/" + filename);
registerFont = true;
}
if (!fontFile.exists()) {
String msg = "Could not find required fonts. ";
// launch4j bug: https://github.com/processing/processing/issues/3543
if (Util.containsNonASCII(Platform.getJavaHome().getAbsolutePath())) {
msg += "Trying moving Processing\n" + "to a location with only ASCII characters in the path.";
} else {
msg += "Please reinstall Processing.";
}
Messages.showError("Font Sadness", msg, null);
}
BufferedInputStream input = new BufferedInputStream(new FileInputStream(fontFile));
Font font = Font.createFont(Font.TRUETYPE_FONT, input);
input.close();
if (registerFont) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
}
return font.deriveFont((float) size);
}
use of java.awt.GraphicsEnvironment 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);
}
use of java.awt.GraphicsEnvironment 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;
}
use of java.awt.GraphicsEnvironment in project processing by processing.
the class PApplet method handleSettings.
void handleSettings() {
insideSettings = true;
// Need the list of display devices to be queried already for usage below.
// https://github.com/processing/processing/issues/3295
// https://github.com/processing/processing/issues/3296
// Not doing this from a static initializer because it may cause
// PApplet to cache and the values to stick through subsequent runs.
// Instead make it a runtime thing and a local variable.
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = ge.getDefaultScreenDevice();
displayDevices = ge.getScreenDevices();
// be numbered from 1 because it's too weird to say "display 0" in prefs.
if (display > 0 && display <= displayDevices.length) {
device = displayDevices[display - 1];
}
// Set displayWidth and displayHeight for people still using those.
DisplayMode displayMode = device.getDisplayMode();
displayWidth = displayMode.getWidth();
displayHeight = displayMode.getHeight();
// Here's where size(), fullScreen(), smooth(N) and noSmooth() might
// be called, conjuring up the demons of various rendering configurations.
settings();
if (display == SPAN && platform == MACOSX) {
// Make sure "Displays have separate Spaces" is unchecked
// in System Preferences > Mission Control
Process p = exec("defaults", "read", "com.apple.spaces", "spans-displays");
BufferedReader outReader = createReader(p.getInputStream());
BufferedReader errReader = createReader(p.getErrorStream());
StringBuilder stdout = new StringBuilder();
StringBuilder stderr = new StringBuilder();
String line = null;
try {
while ((line = outReader.readLine()) != null) {
stdout.append(line);
}
while ((line = errReader.readLine()) != null) {
stderr.append(line);
}
} catch (IOException e) {
printStackTrace(e);
}
int resultCode = -1;
try {
resultCode = p.waitFor();
} catch (InterruptedException e) {
}
String result = trim(stdout.toString());
if ("0".equals(result)) {
EventQueue.invokeLater(new Runnable() {
public void run() {
checkLookAndFeel();
final String msg = "To use fullScreen(SPAN), first turn off “Displays have separate spaces”\n" + "in System Preferences → Mission Control. Then log out and log back in.";
JOptionPane.showMessageDialog(null, msg, "Apple's Defaults Stink", JOptionPane.WARNING_MESSAGE);
}
});
} else if (!"1".equals(result)) {
System.err.println("Could not check the status of “Displays have separate spaces.”");
System.err.format("Received message '%s' and result code %d.%n", trim(stderr.toString()), resultCode);
}
}
insideSettings = false;
}
Aggregations