Jalview and Javascript

Hi,
I was wondering if it would be possible to have an embedded applet
execute some javascript. I'm embedding jalview into a larger web
application, and I need to jalview to notify javascript of some
events. It seems like it should be possible with a few tweaks. The
link-out mechanism could be used (for example) with a link url of
"javascript:doSomething();", although jalview is hard coded to open
links in new windows. I had a similar problem with an applet called
PhyloWidget, but this applet allows you to customize its context
menus. I was able to extend the standard LinkOut class and override
the opening of links to load in the same target as the applet. Can
Jalview be extended or customized in this way? If not, can you point
me to the appropriate code so that I can modify and use my own jalview
build?

ex.
<applet>
<param name="linkLabel_1" value="Set Target">
<param name="linkUrl_1"
value="javascript:PFP.Family.ProteinTarget.setTarget({protein:$SEQUENCE_ID$,domain:null});">
</applet>

···

--
Patrick

Hi Patrick.

This is an excellent idea! It took a three line code change to stop JalviewLite opening a new window if the URL starts with 'javascript:' - try it out at the automated build applet jar here:
http://www.compbio.dundee.ac.uk/user/ws-dev1/jalview/latest/applet/appletJavascript.html

(note - the applet build is here:
http://www.compbio.dundee.ac.uk/user/ws-dev1/jalview/latest/applet/jalviewApplet.jar
and you also need the latest jmol version here:
http://www.compbio.dundee.ac.uk/user/ws-dev1/jalview/latest/applet/jmolApplet.jar
)

I've also created a new issue here:
http://issues.jalview.org/browse/JAL-604

On a more general note, I want to make the UI much more configurable so you could add your own buttons in, and also be able to listen in on UI events like selections and mouse overs, but these plans are still mostly on the drawing board...
Jim.

···

On 21/07/2010 14:33, Patrick Winters wrote:

Hi,
  I was wondering if it would be possible to have an embedded applet
execute some javascript. I'm embedding jalview into a larger web
application, and I need to jalview to notify javascript of some
events. It seems like it should be possible with a few tweaks. The
link-out mechanism could be used (for example) with a link url of
"javascript:doSomething();", although jalview is hard coded to open
links in new windows. I had a similar problem with an applet called
PhyloWidget, but this applet allows you to customize its context
menus. I was able to extend the standard LinkOut class and override
the opening of links to load in the same target as the applet. Can
Jalview be extended or customized in this way? If not, can you point
me to the appropriate code so that I can modify and use my own jalview
build?

ex.
<applet>
  <param name="linkLabel_1" value="Set Target">
  <param name="linkUrl_1"
value="javascript:PFP.Family.ProteinTarget.setTarget({protein:$SEQUENCE_ID$,domain:null});">
</applet>
--
Patrick
_______________________________________________
Jalview-discuss mailing list
Jalview-discuss@jalview.org
http://www.compbio.dundee.ac.uk/mailman/listinfo/jalview-discuss

--
-------------------------------------------------------------------
J. B. Procter (JALVIEW/ENFIN) Barton Bioinformatics Research Group
Phone/Fax:+44(0)1382 388734/345764 http://www.compbio.dundee.ac.uk
The University of Dundee is a Scottish Registered Charity, No. SC015096.

Jim,
  This example doesn't seem to be working for me in an embedded
applet. I've cleared my cache and restarted the browser. But in any
case, can I ask what changes you made? It looked like the relevant
code was in "jalview.util.BrowserLauncher", where links are being
opened by system calls. I don't see how any three line modification
of this could cause the javascript to be run within the applet
context. I don't think you could have it interact with any javascript
libraries unless this was the case.

···

--
Patrick

On Wed, Jul 21, 2010 at 11:30 AM, Jim Procter <jprocter@compbio.dundee.ac.uk> wrote:

Hi Patrick.

This is an excellent idea! It took a three line code change to stop
JalviewLite opening a new window if the URL starts with 'javascript:' - try
it out at the automated build applet jar here:
http://www.compbio.dundee.ac.uk/user/ws-dev1/jalview/latest/applet/appletJavascript.html

(note - the applet build is here:
http://www.compbio.dundee.ac.uk/user/ws-dev1/jalview/latest/applet/jalviewApplet.jar
and you also need the latest jmol version here:
http://www.compbio.dundee.ac.uk/user/ws-dev1/jalview/latest/applet/jmolApplet.jar
)

I've also created a new issue here:
http://issues.jalview.org/browse/JAL-604

On a more general note, I want to make the UI much more configurable so you
could add your own buttons in, and also be able to listen in on UI events
like selections and mouse overs, but these plans are still mostly on the
drawing board...
Jim.

On 21/07/2010 14:33, Patrick Winters wrote:

Hi,
I was wondering if it would be possible to have an embedded applet
execute some javascript. I'm embedding jalview into a larger web
application, and I need to jalview to notify javascript of some
events. It seems like it should be possible with a few tweaks. The
link-out mechanism could be used (for example) with a link url of
"javascript:doSomething();", although jalview is hard coded to open
links in new windows. I had a similar problem with an applet called
PhyloWidget, but this applet allows you to customize its context
menus. I was able to extend the standard LinkOut class and override
the opening of links to load in the same target as the applet. Can
Jalview be extended or customized in this way? If not, can you point
me to the appropriate code so that I can modify and use my own jalview
build?

ex.
<applet>
<param name="linkLabel_1" value="Set Target">
<param name="linkUrl_1"

value="javascript:PFP.Family.ProteinTarget.setTarget({protein:$SEQUENCE_ID$,domain:null});">
</applet>
--
Patrick
_______________________________________________
Jalview-discuss mailing list
Jalview-discuss@jalview.org
http://www.compbio.dundee.ac.uk/mailman/listinfo/jalview-discuss

--
-------------------------------------------------------------------
J. B. Procter (JALVIEW/ENFIN) Barton Bioinformatics Research Group
Phone/Fax:+44(0)1382 388734/345764 http://www.compbio.dundee.ac.uk
The University of Dundee is a Scottish Registered Charity, No. SC015096.

Jim,
   This example doesn't seem to be working for me in an embedded
applet. I've cleared my cache and restarted the browser.

What browser are you using ? firefox and chrome work fine for me.

But in any
case, can I ask what changes you made?

Here are the changes needed to for the 2.5.1 codebase:
jalview.appletgui.AlignFrame.showURL() (around line 2581):
! viewport.applet.getAppletContext().showDocument(
! new java.net.URL(url), target);

Changed to :
         if (url.indexOf("javascript:")==0)
         {
           // no target for the javascript context
           viewport.applet.getAppletContext().showDocument(new java.net.URL(url));
         } else{
           viewport.applet.getAppletContext().showDocument(
                 new java.net.URL(url), target);
         }

Ok, not quite 3 lines, but near enough.

There is one other patch you need to make for consistency:
jalview.appletgui.AppletJmol.showUrl(String url) (around line 873) :

! try
! {
! ap.av.applet.getAppletContext().showDocument(new java.net.URL(url),
! "jmolOutput");
! } catch (java.net.MalformedURLException ex)
! {
! }

Changed to:
       ap.alignFrame.showURL(url,
               "jmolOutput");

This just makes sure that urls opened via Jmol are passed through the same javascript: protocol filter.

It looked like the relevant
code was in "jalview.util.BrowserLauncher", where links are being
opened by system calls. I don't see how any three line modification
of this could cause the javascript to be run within the applet
context. I don't think you could have it interact with any javascript
libraries unless this was the case.

jalview.util.BrowserLauncher is only used by the application. The applet uses the browser's standard java applet environment to interact with it.

I hope that clears things up for you. If you find that the patch is not sufficient, please create an account and contribute to the issue at

http://issues.jalview.org/browse/JAL-604

So I can propagate any changes to the 2.6 branch.

Thanks in advance,
Jim Procter.

···

On 21/07/2010 16:53, Patrick Winters wrote:

--
-------------------------------------------------------------------
J. B. Procter (JALVIEW/ENFIN) Barton Bioinformatics Research Group
Phone/Fax:+44(0)1382 388734/345764 http://www.compbio.dundee.ac.uk
The University of Dundee is a Scottish Registered Charity, No. SC015096.

Jim,
  I'm leaning towards the possibility of embedding jalview in a java
application. I see that at least Modview has done this successfully.
In the end I might try and place jalview within a larger program
served as an applet. Can you give me any pointers or insight into the
possibility of putting jalview into an internal AWT frame and
attaching listeners to sequence and residue selections? Can I do this
with small modifications to the jalview code? How much of the jalview
internals will be public and accessible by me?
  Ultimately I need a tighter integration with a molecular viewer than
you currently provide, and I need to build an interface with
javascript. If I can access jalview's internals with a Java wrapper,
then I can build my own applet to coordinate everything.

···

--
Patrick

On Thu, Jul 22, 2010 at 4:25 AM, Jim Procter <jprocter@compbio.dundee.ac.uk> wrote:

On 21/07/2010 16:53, Patrick Winters wrote:

Jim,
This example doesn't seem to be working for me in an embedded
applet. I've cleared my cache and restarted the browser.

What browser are you using ? firefox and chrome work fine for me.

But in any
case, can I ask what changes you made?

Here are the changes needed to for the 2.5.1 codebase:
jalview.appletgui.AlignFrame.showURL() (around line 2581):
! viewport.applet.getAppletContext().showDocument(
! new java.net.URL(url), target);

Changed to :
if (url.indexOf("javascript:")==0)
{
// no target for the javascript context
viewport.applet.getAppletContext().showDocument(new
java.net.URL(url));
} else{
viewport.applet.getAppletContext().showDocument(
new java.net.URL(url), target);
}

Ok, not quite 3 lines, but near enough.

There is one other patch you need to make for consistency:
jalview.appletgui.AppletJmol.showUrl(String url) (around line 873) :

! try
! {
! ap.av.applet.getAppletContext().showDocument(new java.net.URL(url),
! "jmolOutput");
! } catch (java.net.MalformedURLException ex)
! {
! }

Changed to:
ap.alignFrame.showURL(url,
"jmolOutput");

This just makes sure that urls opened via Jmol are passed through the same
javascript: protocol filter.

It looked like the relevant
code was in "jalview.util.BrowserLauncher", where links are being
opened by system calls. I don't see how any three line modification
of this could cause the javascript to be run within the applet
context. I don't think you could have it interact with any javascript
libraries unless this was the case.

jalview.util.BrowserLauncher is only used by the application. The applet
uses the browser's standard java applet environment to interact with it.

I hope that clears things up for you. If you find that the patch is not
sufficient, please create an account and contribute to the issue at

http://issues.jalview.org/browse/JAL-604

So I can propagate any changes to the 2.6 branch.

Thanks in advance,
Jim Procter.

--
-------------------------------------------------------------------
J. B. Procter (JALVIEW/ENFIN) Barton Bioinformatics Research Group
Phone/Fax:+44(0)1382 388734/345764 http://www.compbio.dundee.ac.uk
The University of Dundee is a Scottish Registered Charity, No. SC015096.

Hi Patrick.

   I'm leaning towards the possibility of embedding jalview in a java
application. I see that at least Modview has done this successfully.

They did, but it was essentiall a fork from Jalview 1 - no code from the modified Jalview display in Modview has returned to the Jalview codebase.

In the end I might try and place jalview within a larger program
served as an applet. Can you give me any pointers or insight into the
possibility of putting jalview into an internal AWT frame and
attaching listeners to sequence and residue selections? Can I do this
with small modifications to the jalview code? How much of the jalview
internals will be public and accessible by me?

Unfortunately, the answers to all these questions are beyond the scope of a quick email. Even worse, most of my answers to questions about listeners and events end up with the phrase 'only a small amount of functionality is available as public methods'. Finally, the worst thing is that the applet and the application do things slightly differently. If you simply want to dive head first in to the Jalview code to do what you want, then you should follow the execution flow from jalview.bin.JalviewLite to see how a jalview.appletgui.AlignFrame is created and made visible when the 'embedded' flag is set.

   Ultimately I need a tighter integration with a molecular viewer than
you currently provide, and I need to build an interface with
javascript. If I can access jalview's internals with a Java wrapper,
then I can build my own applet to coordinate everything.

I'm *extremely interested* in adjusting Jalview's architecture to let you achieve this, and very happy to take code/advice on how to do it - particularly since my time constraints are probably quite different to yours. I'm already working on extending the jalviewLite api to enable positional mouse overs and selections to be listened for in the development branch (I think I've mentioned this several times now), and it would be useful to see what more is needed for your application. I suggest you join the jalview-dev list (its a moderated list, so your subscription notification will take a litle while to come through), so we can talk about it more there.

Jim.

ps. You never responded to my question re JAL-604 - re the failure of the javascript: URLs patch on your machine, which still bemuses me. However, since you've got some clear intentions beyond this trivial ajax capability, I'll not pester you further.

···

On 29/07/2010 17:53, Patrick Winters wrote:

--
-------------------------------------------------------------------
J. B. Procter (JALVIEW/ENFIN) Barton Bioinformatics Research Group
Phone/Fax:+44(0)1382 388734/345764 http://www.compbio.dundee.ac.uk
The University of Dundee is a Scottish Registered Charity, No. SC015096.