summaryrefslogtreecommitdiff
path: root/scripting/java
diff options
context:
space:
mode:
authorsb <sb@openoffice.org>2011-02-18 16:02:07 +0100
committersb <sb@openoffice.org>2011-02-18 16:02:07 +0100
commitc51b48970fa092829795b0dafc9ab4deec53fa3c (patch)
tree667c3f6753a18d2a74ba780071014321f473fe88 /scripting/java
parentcd0d6a5a6775f197fdb7e78b54c8133074a7a236 (diff)
sb141: #i92926# fixed ScriptEdtiorForBeanShell/JavaScript calling Swing on Mac OS X
Diffstat (limited to 'scripting/java')
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java44
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java44
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java77
3 files changed, 94 insertions, 71 deletions
diff --git a/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java b/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java
new file mode 100644
index 000000000000..fffb78523798
--- /dev/null
+++ b/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java
@@ -0,0 +1,44 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2011 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+package com.sun.star.script.framework.provider;
+
+import javax.swing.SwingUtilities;
+
+// On Mac OS X, AWT/Swing must not be accessed from the AppKit thread, so call
+// SwingUtilities.invokeLater always on a fresh thread to avoid that problem
+// (also, the current thread must not wait for that fresh thread to terminate,
+// as that would cause a deadlock if this thread is the AppKit thread):
+public final class SwingInvocation {
+ public static void invoke(final Runnable doRun) {
+ new Thread("SwingInvocation") {
+ public void run() { SwingUtilities.invokeLater(doRun); }
+ }.start();
+ }
+
+ private SwingInvocation() {}
+}
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
index 4fd5d85ac28d..167e9297e861 100644
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
@@ -47,6 +47,7 @@ import java.util.HashMap;
import com.sun.star.script.provider.XScriptContext;
import com.sun.star.script.framework.provider.ScriptEditor;
+import com.sun.star.script.framework.provider.SwingInvocation;
import com.sun.star.script.framework.container.ScriptMetaData;
import com.sun.star.script.framework.provider.ClassLoaderFactory;
@@ -128,7 +129,9 @@ public class ScriptEditorForBeanShell
*/
public static ScriptEditorForBeanShell getEditor(URL url)
{
- return (ScriptEditorForBeanShell)BEING_EDITED.get(url);
+ synchronized (BEING_EDITED) {
+ return (ScriptEditorForBeanShell)BEING_EDITED.get(url);
+ }
}
/**
@@ -194,8 +197,7 @@ public class ScriptEditorForBeanShell
* @param context The context in which to execute the script
*
*/
- public void edit(XScriptContext context, ScriptMetaData entry) {
-
+ public void edit(final XScriptContext context, ScriptMetaData entry) {
if (entry != null ) {
try {
ClassLoader cl = null;
@@ -205,26 +207,30 @@ public class ScriptEditorForBeanShell
catch (Exception ignore) // TODO re-examine error handling
{
}
+ final ClassLoader theCl = cl;
String sUrl = entry.getParcelLocation();
if ( !sUrl.endsWith( "/" ) )
{
sUrl += "/";
}
sUrl += entry.getLanguageName();
- URL url = entry.getSourceURL();
-
- // check if there is already an editing session for this script
- if (BEING_EDITED.containsKey(url))
- {
- ScriptEditorForBeanShell editor =
- (ScriptEditorForBeanShell) BEING_EDITED.get(url);
-
- editor.frame.toFront();
- }
- else
- {
- new ScriptEditorForBeanShell(context, cl, url);
- }
+ final URL url = entry.getSourceURL();
+ SwingInvocation.invoke(
+ new Runnable() {
+ public void run() {
+ ScriptEditorForBeanShell editor;
+ synchronized (BEING_EDITED) {
+ editor = (ScriptEditorForBeanShell)
+ BEING_EDITED.get(url);
+ if (editor == null) {
+ editor = new ScriptEditorForBeanShell(
+ context, theCl, url);
+ BEING_EDITED.put(url, editor);
+ }
+ }
+ editor.frame.toFront();
+ }
+ });
}
catch (IOException ioe) {
showErrorMessage( "Error loading file: " + ioe.getMessage() );
@@ -269,8 +275,6 @@ public class ScriptEditorForBeanShell
this.model.setView(this.view);
initUI();
frame.show();
-
- BEING_EDITED.put(url, this);
}
private void showErrorMessage(String message) {
@@ -384,7 +388,7 @@ public class ScriptEditorForBeanShell
private void shutdown()
{
- if (BEING_EDITED.containsKey(scriptURL)) {
+ synchronized (BEING_EDITED) {
BEING_EDITED.remove(scriptURL);
}
}
diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java
index b9849d1e4e1d..0b62ece9cc9f 100644
--- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java
+++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java
@@ -36,6 +36,7 @@ import org.mozilla.javascript.tools.debugger.ScopeProvider;
import com.sun.star.script.provider.XScriptContext;
import com.sun.star.script.framework.container.ScriptMetaData;
import com.sun.star.script.framework.provider.ScriptEditor;
+import com.sun.star.script.framework.provider.SwingInvocation;
import com.sun.star.script.framework.log.LogUtils;
import java.io.InputStream;
@@ -45,7 +46,6 @@ import java.net.URL;
import java.util.Map;
import java.util.HashMap;
-import javax.swing.SwingUtilities;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@@ -117,7 +117,9 @@ public class ScriptEditorForJavaScript implements ScriptEditor
*/
public static ScriptEditorForJavaScript getEditor(URL url)
{
- return (ScriptEditorForJavaScript)BEING_EDITED.get(url);
+ synchronized (BEING_EDITED) {
+ return (ScriptEditorForJavaScript)BEING_EDITED.get(url);
+ }
}
/**
@@ -187,31 +189,25 @@ public class ScriptEditorForJavaScript implements ScriptEditor
sUrl += "/";
}
sUrl += entry.getLanguageName();
- URL url = entry.getSourceURL();
-
- // check if there is already an editing session for this script
- //if (BEING_EDITED.containsKey(url))
- if ( rhinoWindow != null )
- {
- ScriptEditorForJavaScript editor =
- (ScriptEditorForJavaScript) BEING_EDITED.get(url);
- if ( editor == null )
- {
- editor = new ScriptEditorForJavaScript( context, url );
- editor.edit( context, entry );
- }
- else
- {
- rhinoWindow.showScriptWindow( url );
- }
- }
- else
- {
- ScriptEditorForJavaScript editor =
- new ScriptEditorForJavaScript( context, url );
-
- }
- rhinoWindow.toFront();
+ final URL url = entry.getSourceURL();
+ SwingInvocation.invoke(
+ new Runnable() {
+ public void run() {
+ synchronized (BEING_EDITED) {
+ ScriptEditorForJavaScript editor =
+ (ScriptEditorForJavaScript) BEING_EDITED.get(
+ url);
+ if (editor == null) {
+ editor = new ScriptEditorForJavaScript(
+ context, url);
+ BEING_EDITED.put(url, editor);
+ }
+ }
+ assert rhinoWindow != null;
+ rhinoWindow.showScriptWindow(url);
+ rhinoWindow.toFront();
+ }
+ });
}
catch ( IOException e )
{
@@ -234,11 +230,6 @@ public class ScriptEditorForJavaScript implements ScriptEditor
this.scriptURL = url;
- synchronized( ScriptEditorForJavaScript.class )
- {
- BEING_EDITED.put(url, this);
- }
-
}
/**
@@ -274,13 +265,9 @@ public class ScriptEditorForJavaScript implements ScriptEditor
}
final Main sdb = new Main("Rhino JavaScript Debugger");
- swingInvoke(new Runnable() {
- public void run() {
- sdb.pack();
- sdb.setSize(640, 640);
- sdb.setVisible(true);
- }
- });
+ sdb.pack();
+ sdb.setSize(640, 640);
+ sdb.setVisible(true);
sdb.setExitAction(new Runnable() {
public void run() {
sdb.clearAllBreakpoints();
@@ -306,18 +293,6 @@ public class ScriptEditorForJavaScript implements ScriptEditor
}
}
- private static void swingInvoke(Runnable f) {
- if (SwingUtilities.isEventDispatchThread()) {
- f.run();
- return;
- }
- try {
- SwingUtilities.invokeAndWait(f);
- } catch (Exception exc) {
- LogUtils.DEBUG( LogUtils.getTrace( exc ) );
- }
- }
-
private void shutdown()
{
// dereference Rhino Debugger window