use of com.jme3.app.SettingsDialog in project jmonkeyengine by jMonkeyEngine.
the class JmeDesktopSystem method showSettingsDialog.
@Override
public boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) {
if (SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("Cannot run from EDT");
}
if (GraphicsEnvironment.isHeadless()) {
throw new IllegalStateException("Cannot show dialog in headless environment");
}
final AppSettings settings = new AppSettings(false);
settings.copyFrom(sourceSettings);
String iconPath = sourceSettings.getSettingsDialogImage();
if (iconPath == null) {
iconPath = "";
}
final URL iconUrl = JmeSystem.class.getResource(iconPath.startsWith("/") ? iconPath : "/" + iconPath);
if (iconUrl == null) {
throw new AssetNotFoundException(sourceSettings.getSettingsDialogImage());
}
final AtomicBoolean done = new AtomicBoolean();
final AtomicInteger result = new AtomicInteger();
final Object lock = new Object();
final SelectionListener selectionListener = new SelectionListener() {
public void onSelection(int selection) {
synchronized (lock) {
done.set(true);
result.set(selection);
lock.notifyAll();
}
}
};
SwingUtilities.invokeLater(new Runnable() {
public void run() {
synchronized (lock) {
SettingsDialog dialog = new SettingsDialog(settings, iconUrl, loadFromRegistry);
dialog.setSelectionListener(selectionListener);
dialog.showDialog();
}
}
});
synchronized (lock) {
while (!done.get()) {
try {
lock.wait();
} catch (InterruptedException ex) {
}
}
}
sourceSettings.copyFrom(settings);
return result.get() == SettingsDialog.APPROVE_SELECTION;
}
Aggregations