Logo der AG Geom webMathematica and JavaView
Powered by webMathematica 2
Home » Getting Started » How to include MSPJavaView[g] in webMathematica

How to include MSPJavaView[g] in webMathematica

All there is to do is to include the command in you MSP.m package.

  1. Add MSPJavaView to the list of command declarations.
    Example:
    MSPShow
    MSPShowAnimation
    (********* start of modification *)

    MSPJavaView::usage = "MSPJavaView[g] displays a Mathematica graphics object in a JavaView applet in the resulting HTML page. Graphics objects may be Graphics, Graphics3D, SurfaceGraphics, and others. "
    (********* end of modification *)
    MSPInputValue
    MSPValue
    MSPValueQ
  2. Add Options[MSPJavaView]:={ Project->"null", Animatable->False,Boxed->True}; before Begin["`Private`"].
    Example:
    (********* start of modification *)

    Options[MSPJavaView]:={
      Project->"null",
      Animatable->False,
      Boxed->True,
      Width->400,
      Height->400
    };

    (********* end of modification *)
    Begin["`Private`"]
  3. The following text defines the command MSPJavaView. Add this to the definitions of the other commands.

    Remark: The JavaView archives can be downloaded for free from www.javaview.de. If you want to use your own classes with JavaView, you need to change the codebase (printed bold below), that it points to your classes.

    MSPJavaView[ body_Graphics,opt___] := Module[{proj,anim,bbox,wid,hei},
    {proj,anim,bbox,wid,hei}={Project,Animatable,Boxed,Width,Height}/.   Flatten[{opt,Options[MSPJavaView]}];
    JavaViewHTML[body,proj,anim,bbox,wid,hei]]
    MSPJavaView[ body_SurfaceGraphics,opt___] :=Module[{proj,anim,bbox,wid,hei},
    {proj,anim,bbox,wid,hei}={Project,Animatable,Boxed,Width,Height}/.   Flatten[{opt,Options[MSPJavaView]}];
    JavaViewHTML[body,proj,anim,bbox,wid,hei]]
    MSPJavaView[ body_Graphics3D,opt___]:=Module[{proj,anim,bbox,wid,hei},
    {proj,anim,bbox,wid,hei}={Project,Animatable,Boxed,Width,Height}/.   Flatten[{opt,Options[MSPJavaView]}];
    JavaViewHTML[body,proj,anim,bbox,wid,hei]]
    MSPJavaView[ body_DensityPlot,opt___]:=Module[{proj,anim,bbox,wid,hei},
    {proj,anim,bbox,wid,hei}={Project,Animatable,Boxed,Width,Height}/.   Flatten[{opt,Options[MSPJavaView]}];
    JavaViewHTML[body,proj,anim,bbox,wid,hei]]
    MSPJavaView[ body_List,opt___]:=Module[{proj,anim,bbox,wid,hei},
    {proj,anim,bbox,wid,hei}={Project,Animatable,Boxed,Width,Height}/.   Flatten[{opt,Options[MSPJavaView]}];
    JavaViewHTML[body,proj,anim,bbox,wid,hei]]

    JavaViewHTMLPre :=
    "\<
    <APPLET CODEBASE=\"http://www.mi.fu-berlin.de/javaview/\" ARCHIVE=\"jars/javaview.jar,jars/jvx.jar\" CODE=\"javaview.class\" 
    WIDTH=XWIDTH HEIGHT=XHEIGHT ALIGN=TOP>
    <PARAM NAME=BACKGROUND VALUE=\"255 255 255\">
    <PARAM NAME=Border VALUE=\"Hide\">
    <PARAM NAME=Animate VALUE=\"XANIM\">
    <PARAM NAME=BoundingBox VALUE=\"XBBOX\">
    <PARAM NAME=mathematica VALUE= \"\>"

    JavaViewHTMLPost =
    "\< \"> </APPLET> \>"


    JavaViewHTML[g_,project_:"null",anim_:False,bbox_:True,wid_:400,hei_:400] :=
    Module[{},
    s= StringReplace[ JavaViewHTMLPre, 
                 {"XWIDTH" ->ToString[wid], 
                 "XHEIGHT" ->ToString[hei]}] <>
                   ToString[InputForm[
                  N[g/.x_Real\[RuleDelayed]
                  CForm[Chop[x]]]]] <> JavaViewHTMLPost;
                  If[anim==True,
                        s=StringReplace[ s, "XANIM"->"Show"];,
                        s=StringReplace[ s, "XANIM"->"Hide"];
                  ];
                  If[bbox==True,
                       s=StringReplace[ s, "XBBOX"->"Show"];,
                       s=StringReplace[ s, "XBBOX"->"Hide"];
                  ];
                  If[project!="null",s=StringReplace[s,
                        {"javaview.class"->project}];
                  ];
                  s
    ]

If you have any questions, commands or if you want a copy of my MSP.m file as a reference, please send me an email. hildebrandt@mi.fu-berlin.de

© 2006 Freie Universität Berlin | Feedback |
Stand: 21.04.2008