use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class TestMainAppContext method main.
public static void main(String... args) throws Exception {
ThreadGroup rootTG = Thread.currentThread().getThreadGroup();
while (rootTG.getParent() != null) {
rootTG = rootTG.getParent();
}
ThreadGroup tg = new ThreadGroup(rootTG, "FakeApplet");
final Thread t1 = new Thread(tg, "createNewAppContext") {
@Override
public void run() {
try {
AppContext context = SunToolkit.createNewAppContext();
} catch (Throwable t) {
thrown = t;
}
}
};
t1.start();
t1.join();
if (thrown != null) {
throw new RuntimeException("Unexpected exception: " + thrown, thrown);
}
Thread t2 = new Thread(tg, "BugDetector") {
@Override
public void run() {
try {
Logger.getLogger("foo").info("Done");
} catch (Throwable x) {
thrown = x;
}
}
};
System.setSecurityManager(new SecurityManager());
t2.start();
t2.join();
if (thrown != null) {
throw new RuntimeException("Test failed: " + thrown, thrown);
}
}
use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class Main method main.
public static void main(String[] args) throws IOException {
mainAppContext = SunToolkit.createNewAppContext();
System.out.println("Current context class loader: " + Thread.currentThread().getContextClassLoader());
appsThreadGroup = new ThreadGroup("MyAppsThreadGroup");
File jar = new File("TestApp.jar");
if (!jar.exists()) {
System.out.println(jar.getAbsolutePath() + " was not found!\n" + "Please install the jar with test application correctly!");
throw new RuntimeException("Test failed: no TestApp.jar");
}
URL[] urls = new URL[] { jar.toURL() };
int numApps = Integer.getInteger("numApps", 20).intValue();
doneSignal = new CountDownLatch(numApps);
int cnt = 0;
while (cnt++ < numApps) {
launch(urls, "testapp.Main", "launch");
checkErrors();
}
System.out.println("Wait for apps completion....");
try {
doneSignal.await();
} catch (InterruptedException e) {
}
System.out.println("All apps finished.");
System.gc();
System.out.flush();
System.out.println("Enumerate strong refs:");
for (String is : strongRefs.keySet()) {
System.out.println("-> " + is);
}
System.out.println("=======================");
// wait few seconds
waitAndGC(gcTimeout);
doneSignal = new CountDownLatch(1);
Runnable workaround = new Runnable() {
public void run() {
AppContext ctx = null;
try {
ctx = SunToolkit.createNewAppContext();
} catch (Throwable e) {
// ignore...
} finally {
doneSignal.countDown();
}
}
};
Thread wt = new Thread(appsThreadGroup, workaround, "Workaround");
wt.setContextClassLoader(new MyClassLoader(urls, "workaround"));
wt.start();
wt = null;
workaround = null;
System.out.println("Wait for workaround completion...");
try {
doneSignal.await();
} catch (InterruptedException e) {
}
// give a chance to GC
waitAndGC(gcTimeout);
if (!refs.isEmpty()) {
System.out.println("Classloaders still alive:");
for (MyClassLoader l : refs.keySet()) {
String val = refs.get(l);
if (val == null) {
throw new RuntimeException("Test FAILED: Invalid classloader name");
}
System.out.println("->" + val + (strongRefs.get(val) != null ? " (has strong ref)" : ""));
if (strongRefs.get(val) == null) {
throw new RuntimeException("Test FAILED: exta class loader is detected! ");
}
}
} else {
System.out.println("No alive class loaders!!");
}
System.out.println("Test PASSED.");
}
use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class Main method launch.
private static void launch(URL[] urls, final String className, final String methodName) {
final String uniqClassName = "testapp/Uniq" + counter;
final boolean saveStrongRef = forgetSomeStreams ? (counter % 5 == 4) : false;
System.out.printf("%s: launch the app\n", uniqClassName);
Runnable launchIt = new Runnable() {
public void run() {
AppContext ctx = SunToolkit.createNewAppContext();
try {
Class appMain = ctx.getContextClassLoader().loadClass(className);
Method launch = appMain.getDeclaredMethod(methodName, strongRefs.getClass());
Constructor c = appMain.getConstructor(String.class, problems.getClass());
Object o = c.newInstance(uniqClassName, problems);
if (saveStrongRef) {
System.out.printf("%s: force strong ref\n", uniqClassName);
launch.invoke(o, strongRefs);
} else {
HashMap<String, ImageInputStream> empty = null;
launch.invoke(o, empty);
}
ctx = null;
} catch (Throwable e) {
problems.add(e);
} finally {
doneSignal.countDown();
}
}
};
MyClassLoader appClassLoader = new MyClassLoader(urls, uniqClassName);
refs.put(appClassLoader, uniqClassName);
Thread appThread = new Thread(appsThreadGroup, launchIt, "AppThread" + counter++);
appThread.setContextClassLoader(appClassLoader);
appThread.start();
launchIt = null;
appThread = null;
appClassLoader = null;
}
use of sun.awt.AppContext in project adempiere by adempiere.
the class PreviewPanel method setLFSelection.
/**
* Update the look list and theme list to show the current selection
*/
private void setLFSelection() {
m_setting = true;
// Search for PLAF
ValueNamePair plaf = null;
LookAndFeel lookFeel = UIManager.getLookAndFeel();
String look = lookFeel.getClass().getName();
for (int i = 0; i < AdempierePLAF.getPLAFs().length; i++) {
ValueNamePair vp = AdempierePLAF.getPLAFs()[i];
if (vp.getValue().equals(look)) {
plaf = vp;
break;
}
}
if (plaf != null)
lookList.setSelectedValue(plaf, true);
// Search for Theme
MetalTheme metalTheme = null;
ValueNamePair theme = null;
boolean metal = UIManager.getLookAndFeel() instanceof MetalLookAndFeel;
themeList.setModel(new DefaultComboBoxModel(AdempierePLAF.getThemes()));
if (metal) {
theme = null;
AppContext context = AppContext.getAppContext();
metalTheme = (MetalTheme) context.get("currentMetalTheme");
if (metalTheme != null) {
String lookTheme = metalTheme.getName();
for (int i = 0; i < AdempierePLAF.getThemes().length; i++) {
ValueNamePair vp = AdempierePLAF.getThemes()[i];
if (vp.getName().equals(lookTheme)) {
theme = vp;
break;
}
}
}
if (theme != null)
themeList.setSelectedValue(theme, true);
}
m_setting = false;
log.info(lookFeel + " - " + metalTheme);
}
use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.
the class DefaultKeyboardFocusManager method sendMessage.
/**
* Sends a synthetic AWTEvent to a Component. If the Component is in
* the current AppContext, then the event is immediately dispatched.
* If the Component is in a different AppContext, then the event is
* posted to the other AppContext's EventQueue, and this method blocks
* until the event is handled or target AppContext is disposed.
* Returns true if successfuly dispatched event, false if failed
* to dispatch.
*/
static boolean sendMessage(Component target, AWTEvent e) {
e.isPosted = true;
AppContext myAppContext = AppContext.getAppContext();
final AppContext targetAppContext = target.appContext;
final SentEvent se = new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);
if (myAppContext == targetAppContext) {
se.dispatch();
} else {
if (targetAppContext.isDisposed()) {
return false;
}
SunToolkit.postEvent(targetAppContext, se);
if (EventQueue.isDispatchThread()) {
EventDispatchThread edt = (EventDispatchThread) Thread.currentThread();
edt.pumpEvents(SentEvent.ID, new Conditional() {
public boolean evaluate() {
return !se.dispatched && !targetAppContext.isDisposed();
}
});
} else {
synchronized (se) {
while (!se.dispatched && !targetAppContext.isDisposed()) {
try {
se.wait(1000);
} catch (InterruptedException ie) {
break;
}
}
}
}
}
return se.dispatched;
}
Aggregations