synchronized(ContextStorage.getContextLock()) {
if (ContextStorage.getGraphicsEnvironment() == null) {
if (isHeadless()) {
ContextStorage.setGraphicsEnvironment(new HeadlessGraphicsEnvironment());
} else {
final CommonGraphics2DFactory g2df =
(CommonGraphics2DFactory) Toolkit.getDefaultToolkit().getGraphicsFactory();
ContextStorage.setGraphicsEnvironment(
g2df.createGraphicsEnvironment(ContextStorage.getWindowFactory())
);
}
}
return ContextStorage.getGraphicsEnvironment();