Skip to content
Snippets Groups Projects
Commit 345a0de6 authored by stepan's avatar stepan
Browse files

FastR grid: check AWT support option before creating AWT based devices.

parent 771d10fc
No related branches found
No related tags found
No related merge requests found
......@@ -96,18 +96,18 @@ public final class GridContext {
public void openDefaultDevice() {
String defaultDev = RGridGraphicsAdapter.getDefaultDevice();
if (defaultDev.equals("awt") || defaultDev.startsWith("X11")) {
if (!FastRConfig.InternalGridAwtSupport) {
throw awtNotSupported();
} else {
setCurrentDevice(defaultDev, WindowDevice.createWindowDevice());
}
ensureAwtSupport();
setCurrentDevice(defaultDev, WindowDevice.createWindowDevice());
} else if (defaultDev.equals("svg")) {
setCurrentDevice(defaultDev, new SVGDevice("Rplot.svg", GridDevice.DEFAULT_WIDTH, GridDevice.DEFAULT_HEIGHT));
} else if (defaultDev.equals("png")) {
ensureAwtSupport();
setCurrentDevice(defaultDev, safeOpenImageDev("Rplot.png", "png"));
} else if (defaultDev.equals("bmp")) {
ensureAwtSupport();
setCurrentDevice(defaultDev, safeOpenImageDev("Rplot.bmp", "bmp"));
} else if (defaultDev.equals("jpg") || defaultDev.equals("jpeg")) {
ensureAwtSupport();
setCurrentDevice("jpeg", safeOpenImageDev("Rplot.jpg", "jpeg"));
} else {
throw RError.error(RError.NO_CALLER, Message.GENERIC, "FastR does not support device '" + defaultDev + "'.");
......@@ -144,6 +144,12 @@ public final class GridContext {
return RContext.getEngine().evalFunction(redrawAll, REnvironment.baseEnv().getFrame(), RCaller.topLevel, true, null, args);
}
private static void ensureAwtSupport() {
if (!FastRConfig.InternalGridAwtSupport) {
throw awtNotSupported();
}
}
private BufferedImageDevice safeOpenImageDev(String filename, String formatName) {
try {
return BufferedImageDevice.open(filename, formatName, GridDevice.DEFAULT_WIDTH, GridDevice.DEFAULT_HEIGHT);
......
......@@ -15,6 +15,7 @@
package com.oracle.truffle.r.library.fastrGrid.graphics;
import com.oracle.truffle.r.library.fastrGrid.FastRGridExternalLookup;
import com.oracle.truffle.r.runtime.FastRConfig;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RError.Message;
import com.oracle.truffle.r.runtime.ROptions;
......@@ -70,7 +71,7 @@ public final class RGridGraphicsAdapter {
if (options.getValue(DEFAULT_DEVICE_OPTION) != RNull.instance) {
return;
}
String defaultDevice = ctx.isInteractive() ? "awt" : "svg";
String defaultDevice = (ctx.isInteractive() && FastRConfig.InternalGridAwtSupport) ? "awt" : "svg";
try {
options.setValue(DEFAULT_DEVICE_OPTION, defaultDevice);
} catch (OptionsException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment