Back to index

wims  3.65+svn20090927
Public Member Functions | Protected Member Functions
ptolemy.plot.PlotLiveApplet Class Reference

An Applet for the PlotLive class. More...

Inheritance diagram for ptolemy.plot.PlotLiveApplet:
Inheritance graph
[legend]
Collaboration diagram for ptolemy.plot.PlotLiveApplet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

String getAppletInfo ()
 Return a string describing this applet.
void start ()
 Start the plot thread.
void stop ()
 Stop the plot thread.
String ReadApplet ()
 Construct a Plot applet.
String[][] getParameterInfo ()
 Return information about parameters.
synchronized void read_from_param (String data)
 Initialize the applet.
synchronized void read_function_from_param (String function, String names, String totaal, int xmin, int xmax, int plotsteps, int smooth)
void init ()
PlotBox newPlot ()
 Create a new Plot object for the applet.
PlotBox plot ()
 Return the plot object to operate on.
void setPlot (PlotBox plot)
 Set the plot object to operate on.

Protected Member Functions

void _read (InputStream in) throws IOException
 Read the specified stream.
void _setPlotSize (int appletWidth, int appletHeight)
 Given the size of the applet, set the size of the plot.

Detailed Description

An Applet for the PlotLive class.

Derived classes should redefine newPlot() to return a concrete instance of PlotLive.

Author:
Edward A. Lee, Christopher Brooks
Version:
Id:
PlotLiveApplet.java,v 1.31 2005/07/28 18:49:33 cxh Exp
Since:
Ptolemy II 0.2 .ProposedRating Yellow (cxh) .AcceptedRating Yellow (cxh)

Definition at line 45 of file PlotLiveApplet.java.


Member Function Documentation

void ptolemy.plot.PlotApplet._read ( InputStream  in) throws IOException [inline, protected, inherited]

Read the specified stream.

Derived classes may override this to support other file formats.

Parameters:
inThe input stream.
Exceptions:
IOExceptionIf the stream cannot be read.

Definition at line 389 of file PlotApplet.java.

                                                            {
        plot().read(in);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotApplet._setPlotSize ( int  appletWidth,
int  appletHeight 
) [inline, protected, inherited]

Given the size of the applet, set the size of the plot.

Derived classes may override this to allow room for other widgets below the plot.

Parameters:
appletWidthThe width of the applet.
appletHeightThe height of the applet.

Reimplemented in ptolemy.plot.EditablePlotApplet.

Definition at line 399 of file PlotApplet.java.

                                                                   {
        plot().setSize(appletWidth, appletHeight);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Return a string describing this applet.

Returns:
A description of the applet.

Reimplemented from ptolemy.plot.PlotApplet.

Definition at line 49 of file PlotLiveApplet.java.

                                  {
        return "PlotLiveApplet "
                + PlotBox.PTPLOT_RELEASE
                + " : Demo of PlotLive.\n"
                + "By: Edward A. Lee\n"
                + "    Christopher Brooks\n"
                + "($Id: PlotLiveApplet.java,v 1.31 2005/07/28 18:49:33 cxh Exp $)";
    }
String [][] ptolemy.plot.PlotApplet.getParameterInfo ( ) [inline, inherited]

Return information about parameters.

Returns:
A array of arrays giving parameter names, the type, and the default value or description.

Definition at line 105 of file PlotApplet.java.

                                         {
        String[][] pinfo = {
                { "background", "hexcolor value", "background color" },
                { "foreground", "hexcolor value", "foreground color" },
                { "dataurl", "url", "the URL of the data to plot" },
                { "height", "integer", "100" },
              { "width", "integer", "100" }, 
              { "function", "String", "function1,function2,function3,function4 ..." }, 
              { "smooth", "integer", "0 or 1 : use with care. default=0" }, 
              { "names", "String", "names function1,name function2 ... or left blank " }, 
              { "xmin", "integer", "minimum x-value or left blank for auto detection" }, 
              { "xmax", "integer", "maximum x-value or left blank for auto detection" }, 
              { "ymin", "integer", "minimum y-value or left blank for auto detection" }, 
              { "ymax", "integer", "maximum y-value or left blank for auto detection" }, 
              { "xlog", "integer", "x-axis is log-scale: 0 or 1: default 0" }, 
              { "ylog", "integer", "y-axis is log-scale: 0 or 1: default 0" }, 
              { "color", "integer", " 0 or 1 :default 1" }, 
              { "xtics", "String", " zero 0, one 1, two 2, pi 3.1428, four 4, five 5 " }, 
              { "ytics", "String", " thing1 0, thing2 1, thing3 2, three 3, four 4, five 5 " }, 
              { "xlabel", "String", "label of the x-axis: default x-axis" }, 
              { "ylabel", "String", "label of the y-axis: default y-axis" }, 
              { "title", "String", "title of the plot" }, 
              };
        return pinfo;
    }
void ptolemy.plot.PlotApplet.init ( ) [inline, inherited]

Reimplemented in ptolemy.plot.EditablePlotApplet.

Definition at line 189 of file PlotApplet.java.

                       {
        super.init();

        // FIXME: having the mutex causes applets to hang.
        //synchronized (_mutex) {
        Runnable doActions = new Runnable() {
            public void run() {
                if (_plot == null) {
                    _plot = newPlot();
                }

                getContentPane().add(plot(), BorderLayout.NORTH);

                // Process the width and height applet parameters
                int width;

                // Process the width and height applet parameters
                int height;
                String widthspec = getParameter("width");

                if (widthspec != null) {
                    width = Integer.parseInt(widthspec);
                } else {
                    width = 400;
                }

                String heightspec = getParameter("height");

                if (heightspec != null) {
                    height = Integer.parseInt(heightspec);
                } else {
                    height = 400;
                }

                _setPlotSize(width, height);
                plot().setButtons(true);

                // Process the background parameter.
                Color background = Color.white;
                String colorspec = getParameter("background");

                if (colorspec != null) {
                    background = PlotBox.getColorByName(colorspec);
                }

                setBackground(background);
                plot().setBackground(background);
                getContentPane().setBackground(background);

                // Process the foreground parameter.
                Color foreground = Color.black;
                colorspec = getParameter("foreground");

                if (colorspec != null) {
                    foreground = PlotBox.getColorByName(colorspec);
                }

                setForeground(foreground);
                plot().setForeground(foreground);
                plot().setVisible(true);
              
              //jm.evers
              int finput=0;String data;
              // reading the function param and all other params needed for plotting.
              data=getParameter("function"); 
              if(data!=null && data.length()!=0){
                  finput=1;int xmin;int xmax;int plotsteps=500;double ymin;double ymax;
                  String param;String xlabel;String ylabel;String grid;String title;String kleur="on";String xtics="";String ytics="";
                  String names="";int smooth=0;String xlog="off";String ylog="off";
                  String bargraph="";String binwidth="";String binoffset="";
                  
                  param=getParameter("bargraph");
                  if(param!=null && param.length()!=0){ bargraph=param; }
                  param=getParameter("binwidth");
                  if(param!=null && param.length()!=0){ binwidth=param; }
                  param=getParameter("binoffset");
                  if(param!=null && param.length()!=0){ binoffset=param; }
                  
                  
                  param=getParameter("xmax");
                  if(param!=null && param.length()!=0){ xmax=(int) Integer.parseInt(param, 10); } else { xmax=10; }
                  param=getParameter("xmin");
                  if(param!=null && param.length()!=0){ xmin=(int) Integer.parseInt(param, 10); } else { xmin=-1*xmax; }

                  param=getParameter("ymax");
                  if(param!=null && param.length()!=0){ 
                     ymax=(double) Integer.parseInt(param, 10);
                     param=getParameter("ymin");
                     ymin=(double) Integer.parseInt(param, 10);
                     plot().setYRange(ymin,ymax);
                  }
                  param=getParameter("ylog");
                  if(param!=null && param.length()!=0){ if(param.equals("1")){ylog="on";}}
                  param=getParameter("xlog");
                  if(param!=null && param.length()!=0){ if(param.equals("1")){xlog="on";}}
                  param=getParameter("smooth");
                  if(param!=null && param.length()!=0){ if(param.equals("1")){smooth=1;}}
                  param=getParameter("names");
                  if(param!=null && param.length()!=0){ names=param; } else { names=""; }
                  param=getParameter("xlabel");
                  if(param!=null && param.length()!=0){ xlabel=param; } else { xlabel="x-axis"; }
                  param=getParameter("ylabel");
                  if(param!=null && param.length()!=0){ ylabel=param; } else { ylabel="y-axis"; }
                  param=getParameter("grid");
                  if(param.equalsIgnoreCase("off")){ grid="off"; } else { grid="on"; }
                  param=getParameter("title");
                  if(param!=null && param.length()!=0){ title=param; } else { title="WIMS data plotter"; }
                  param=getParameter("color");
                  if(param.equalsIgnoreCase("off")){ kleur="off"; }
                  param=getParameter("xtics");
                  if(param!=null && param.length()!=0){ xtics=param; }
                  param=getParameter("ytics");
                  if(param!=null && param.length()!=0){ ytics=param; }
                  param=getParameter("plotsteps");
                  if(param!=null && param.length()!=0){ plotsteps=(int) Integer.parseInt(param, 10); }

                  String totaal="TitleText: "+title+";xlabel: "+xlabel+";ylabel: "+ylabel+";xlog: "+xlog+";ylog: "+ylog+";grid: "+grid+";color: "+kleur+";xticks:"+xtics+";yticks:"+ytics+";bargraph: "+bargraph+";binwidth: "+binwidth+";binoffset: "+binoffset;
                  read_function_from_param(data , names , totaal, xmin , xmax , plotsteps , smooth);
              }
              
              // reading a string of data in the "plt" format. typical: the string is provided by a wims variable
              data=getParameter("data"); 
              if(data!=null){
                  finput=1;
                  read_from_param(data);
              }

                // Process the dataurl parameter.
              // the file is written by wims and stored in the session-dir/getfile/
                String dataurlspec = getParameter("dataurl");

                if (dataurlspec != null && finput==0) {
                    try {
                        showStatus("Reading data");

                        URL dataurl = new URL(getDocumentBase(), dataurlspec);
                        InputStream in = dataurl.openStream();
                        _read(in);
                        showStatus("Done");
                    } catch (MalformedURLException e) {
                        System.err.println(e.toString());
                    } catch (FileNotFoundException e) {
                        System.err.println("PlotApplet: file not found: " + e);
                    } catch (IOException e) {
                        System.err
                                .println("PlotApplet: error reading input file: "
                                        + e);
                    }
                }
            }
        };

        try {
            // NOTE: Using invokeAndWait() here risks causing
            // deadlock.  However, the Sun Tutorial recommends calling
            // invokeAndWait so that the work finishes before returning.
            // if we call invokeLater() then demo/PlotFourierSeries.java
            // has problems.
            SwingUtilities.invokeAndWait(doActions);
        } catch (Exception ex) {
            // Ignore InterruptedException.
            // Other exceptions should not occur.
        }

        //}
    }

Here is the call graph for this function:

PlotBox ptolemy.plot.PlotApplet.newPlot ( ) [inline, inherited]

Create a new Plot object for the applet.

Derived classes can redefine this method to return a different type of plot object.

Returns:
A new instance of PlotBox.

Reimplemented in ptolemy.plot.EditablePlotApplet, and ptolemy.plot.HistogramApplet.

Definition at line 360 of file PlotApplet.java.

                             {
        return new Plot();
    }

Here is the caller graph for this function:

PlotBox ptolemy.plot.PlotApplet.plot ( ) [inline, inherited]

Return the plot object to operate on.

Returns:
The plot object associated with this applet.

Definition at line 367 of file PlotApplet.java.

                          {
        return _plot;
    }

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotApplet.read_from_param ( String  data) [inline, inherited]

Initialize the applet.

Read the applet parameters.

Subclasses that extend this method and call Swing UI methods should do so in the Swing Event thread by calling SwingUtilities.invokeAndWait(). Note that some Plot methods will automatically run in the Swing Event thread, some will not. For details about SwingUtilities.invokeAndWait(), see The Sun Applet Tutorial

Definition at line 143 of file PlotApplet.java.

                                                         {
       StringTokenizer f = new StringTokenizer(data, ";");
       int max=f.countTokens();String line="";
       for(int s=0;s<max;s++){
           line=f.nextToken();
            plot().read(line);
           //System.out.println("regel "+s+" = "+line);
        }
        showStatus("Done");
       repaint(); 
    }                                                                                     

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized void ptolemy.plot.PlotApplet.read_function_from_param ( String  function,
String  names,
String  totaal,
int  xmin,
int  xmax,
int  plotsteps,
int  smooth 
) [inline, inherited]

Definition at line 155 of file PlotApplet.java.

                                                                                                                                            {
       String fun;String line="";String fff;
       Symbols symbols=new Symbols();
       double stap=(double) (xmax-xmin)/plotsteps;double org=stap;double y=0.0;double x=0.0;double dy=0.0;
       float diff;
       int s;int max;int tot=0;int n;String legenda="";
       if(names.length()!=0){ n=1; } else { n=0; }
       StringTokenizer ff = new StringTokenizer(function, ",");max=ff.countTokens();
       StringTokenizer nn = new StringTokenizer(names, ",");
       for(s=0;s<max;s++){
           if(n==0){ totaal=totaal+";dataset:"+s; } else {legenda=nn.nextToken(); totaal=totaal+";dataset:"+legenda; } 
           fff=ff.nextToken();
           System.out.println("functie "+s + "="+fff);
           for(x=xmin; x<xmax; x=x+stap){
              if(smooth==1){
                  diff=(float) Math.abs(y-dy);
                  if(diff>10*stap && stap>0.001){stap=0.5*stap;}else{stap=org;}
              }
              fun=fff.replaceAll("x","("+Double.toString(x)+")");
              try { y=symbols.eval(fun);} catch (SyntaxException e) {System.out.println("error "+e); }
              totaal=totaal+";"+x+","+y;
              tot++;
           }
       }
       System.out.println("totaal aantal punten is "+tot);
       StringTokenizer f = new StringTokenizer(totaal, ";");max=f.countTokens();
       for(s=0;s<max;s++){
           plot().read(f.nextToken());
       }
       showStatus("Done");
       repaint(); 
    }                                                                                     

Here is the call graph for this function:

Here is the caller graph for this function:

String ptolemy.plot.PlotApplet.ReadApplet ( ) [inline, inherited]

Construct a Plot applet.

Definition at line 85 of file PlotApplet.java.

                              {
                                                                                                                
        String reply="";
       reply=plot().ReadPlotApplet();                                                                                                                 
    return reply;                                                                                                                          
    }

Here is the call graph for this function:

void ptolemy.plot.PlotApplet.setPlot ( PlotBox  plot) [inline, inherited]

Set the plot object to operate on.

Parameters:
plotThe plot object to associate with this applet.

Definition at line 374 of file PlotApplet.java.

                                      {
        // FIXME: this method is necessary for PxgraphApplet to work
        // properly.  We could modify newPlot() to set _plot, but
        // that would change the newPlot() contract, so we add another method.
        _plot = plot;
    }

Here is the call graph for this function:

Start the plot thread.

Definition at line 60 of file PlotLiveApplet.java.

                        {
        ((PlotLive) plot()).start();
    }

Here is the call graph for this function:

Stop the plot thread.

Definition at line 66 of file PlotLiveApplet.java.

                       {
        ((PlotLive) plot()).stop();
    }

Here is the call graph for this function:


The documentation for this class was generated from the following file: