advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

XYMeter


/* ===================================================================================================*/
/* xymeter-Applet                                                                                     */
/*            V. 1.0                15.07.1997                                                        */
/*  JaR:/ R. Moros :                                                    				            */
/*    University of Leipzig                                       					     */
/*    Inst. of Technical Chemistry   (ITC-Leipzig)                        			   	     */
/*    e-mail:           moros@sonne.tachemie.uni-leipzig.de       					     */
/*    Home-Page:     http://cerius.tachemie.uni-leipzig.de/~jar/      			             */
/*    ITC-Page:      http://cerius.tachemie.uni-leipzig.de        					     */
/*                                                                					     */
/* --------------------------------------------------------------------------------------------------- */
/*                                                                             			      */
/*                                                                             			      */
/* Permission to use, copy, modify and distribute this software or a part of this 			      */
/* and its documentation without fee for NON-COMMERCIAL purposes is hereby             		      */
/* granted provided that this notice with a reference to the original source   			      */
/* andthe author appears in all copies or derivatives of this software.        			      */
/*                                                                             			      */
/* -----------------------------------------------------------------------------------------------------*/
/* Set the main parameters of the XY-Meter by using                                                     */
/*      1)Applet-Parameter                                                                              */
/*                                       NAME  TYPE                                       DEFAULT       */
/*                                      header [String]                                     ""          */
/*                                      xtitle [String]                                     ""          */
/*                                      ytitle [String]                                     ""          */
/*                                      onlyy  [String]  true: only y-values are           false        */
/*                                                             x is calculated based on the             */
/*                                                             xold + Period                            */
/*                                                       false:x-y-pairs are used                       */
/*                                      yfrom  [float]   begin of range  y (Y-Min)            0         */
/*                                      yto    [float]   end of range    y (Y-Max)           100        */
/*                                      xfrom  [float]   begin of range x                     0         */
/*																						  xto    [float]   end of range x                      100        */
/*                                      xperiod[float]   set the period of x (if onlyy=true)  1         */
/*                                      hbgcol [String]   backgr.-color header            "lightgray"   */
/*                                      hfgcol [String]   foregroundcol. header            "black"      */
/*                                      abgcol [String]   backgroundcol. analog           "lightgray"   */
/*                                      afgcol [String]   foregroundcol. analog            "black"      */
/*                                      maxlin [int]      number of lines                     1         */
/*                                      lincol [String]   color of lines xy-pairs           "blue"      */
/*                                                        example: maxlin=3 lincol="blue,red,green"     */
/*                                                                                                      */
/*     2) - a number of methods that can be used via JavaScript                                         */
/*           SetParameter, SetColors, SetLineColor, ..                                                  */
/*           detailed description http://cerius.tachemie.uni-leipzig.de/~jar/jjsappl_e.html             */
/*                                                                                                      */
/*  LIST of COLORS are used for SetLineColor, SetColors  :                                              */
/*      "white","black","lightgray","gray","darkgray","red","green","blue"                              */
/*      "yellow","magenta","cyan","pink","orange"                                                       */
/*                                                                                                      */
/*                                                                                                      */
/*          --------------------------------------------------------------------------------            */
/*  Draw a function                                                                                     */
/*      Using the methods SetMeterXY, SetMeterY, DrawMeterXY, DrawMeterY via JavaScript                 */
/*      detailed description: http://cerius.tachemie.uni-leipzig.de/~jar/jjsappl_e.html                 */
/*                                                                                                      */
/*      1) document.utmeter.DrawMeterXY(int lin, double x, double y);                                   */
/*         draw from xold, yold to x,y / lin: number of line                                            */
/*                                                                                                      */
/*      2) document.utmeter.DrawMeterY(int lin, double y);                                              */
/*         if the mode is "onlyy=true" (Set by using SetXYMode) then this methode is be used for drawing*/
/*         x will be calculated by using the former value of x and the "XPeriod"  x=xold+XPeriod        */
/*                                                                                                      */
/* ==================================================================================================== */
import java.awt.*;
import java.applet.Applet;
import java.util.StringTokenizer;


public class xymeter extends Applet  implements Runnable
{
  Thread   runner;
  int      delayGlb= 0;            // the refresh/update time
  int      Mhe;
  int      Mwi;
  int      Hhe;                   //height of Header
  int      Hhemax = 20;
  int      Ahe;                   // height of Analog



                                  //the borders of the y-axis and x-axis
  int borderY0;                           //Y-down
  int borderY1;                           //Y-up
  int borderX0;                           //X-left
  int borderX1;                           //X-right


  int wborder_l,wborder_r;                //free space left,right
  int hborder;																	// free space top
  int xaroot         = 0;                 //the point 0,0 of the analog part
  int yaroot         = 0;
  int xs0,ys0;
  int xs1,ys1;
  int xs2,ys2;
  int XMarkerSpace   = 0;                 //between 2 x-markers
  int XMarkerLength  = 0;
  int YMarkerSpace   = 0;                 //between 2 y-markers
  int YMarkerLength  = 0;


  double   YMin;
  double   YMax;
  double   DeltaY;                        //the range of y
  double   yfak;                          // to transsform WC->BC
  double   DeltaX;
  double   XMin;
  double   XMax;
  double   XPeriod;                       //if onlyy=true -> memory of the period between 2 x
  double   xfak;                          //to transform WC->BC
  boolean  WHeader   = true;              // true : with header
  boolean	 WXTitle   = false;							  // true:  with X-Title
  boolean  WYTitle   = false;								//  true:	with Y-Title
  boolean  WFloatingX= true;              // true:
  boolean  XYPairs   = true;              // true: x-y pairs
  String   Header;
  String   XTitle;
  String   YTitle;

  String   iStr;
  boolean  CHANGED;
  boolean  ALLPOINTS;                     //true: print all points

   //Colors
  Color HBGColor;     // Header Background
  Color HFGColor;     // Header Foreground
  Color ABGColor;     // Analog Background
  Color AFGColor;     // Analog Foreground;
  Color LINColor[];   // Color of the lines between the xy-pairs

  //double-buffering
  Image oimg;
  Graphics og;


  //the memory of the value
  int      maxLines=1;     // number of lines/functions
  int      maxPairs=100;   // = 400;                     // the max. numbers of XY-pairs
  double   YArr[];         // = new double [maxPairs];   // the Y-Memory
  double   XArr[];         // = new double [maxPairs];   // the X-Memory
  int      Index[];        // the index of xy(k)
  int      IBegin[];
  int      IEnd[];
  double   YNew[];
  double   YOld[];
  double   XNew[];
  double   XOld[];


// Applet Info
  public String getAppletInfo() {
    return "xymeter.java, V 1.0 07.97 by Ralf Moros / JaR, http://cerius.tachemie.uni-leipzig.de/~jar/";
  }


//init 1
public void InitGlobalPar1()
{
if (WHeader==true) {Hhe  = Mhe / 6;
                       if (Hhe>Hhemax) {Hhe=Hhemax;}
                       }              // height of the header
    else Hhe=0;

    //Analog
    Ahe  = Mhe - Hhe;          // height of the analog instrument
    xaroot = 0;                // lower left corner x
    yaroot = Hhe+Ahe-1;        // lower left corner y
    wborder_l = Mwi/8;         // calculate all ness. variables
    wborder_r = Mwi/12;        // in order to print the analog values
    hborder   = Ahe / 10;      // into the yt-system
    xs0 = xaroot + wborder_l;     // borders & corners
    ys0 = yaroot - hborder;
    xs1 = Mwi - wborder_r;
    ys1 = ys0;
    xs2 = xs0;
    ys2 = yaroot - (9*hborder);
    XMarkerSpace  = (xs1-xs0)/10;            // between 2 marker sticks
    XMarkerLength = 5;                       // the length of a marker stick
    if (XMarkerLength > (hborder/2)) {XMarkerLength=hborder/2;}
    YMarkerSpace  = (ys0-ys2)/10;           //between 2 marker sticks
    YMarkerLength = 5;                      //the length of a marker stick
    if (YMarkerLength > (wborder_l/2)) {YMarkerLength= wborder_l/2;}

    borderX0 = xs0;
    borderX1 = xs0+10*XMarkerSpace;
    borderY0 = ys0;
    borderY1 = ys0-10*YMarkerSpace;
                                            //calculate the faktors tfak, yfak
                                           //in order to transform twc->tbc ywc->ybc
    xfak = (borderX1 - borderX0) / DeltaX;
    yfak = (borderY0 - borderY1) / DeltaY;
}//End InitGlobalPar1



//INIT GENERAL
 public void init()
 { StringTokenizer st;
   String st1;

    // Set Colors
       HBGColor = Color.lightGray;
       ABGColor = Color.lightGray;

       HFGColor = Color.black;
       AFGColor = Color.black;



     // INIT  - PARAMETER
       iStr = getParameter("header");
       if (iStr != null) {WHeader = true;
                          Header = iStr;
                         }
       else {WHeader = false;
             Header    = "";
            }

       iStr = getParameter("xtitle");
       if (iStr != null) {XTitle = iStr;WXTitle=true;}
       else {XTitle = "";WXTitle=false;}

       iStr = getParameter("ytitle");
       if (iStr != null) {YTitle = iStr; WYTitle=true;}
       else {YTitle = "";WYTitle=false;}



       iStr = getParameter("onlyy");
       if (iStr != null) {if (iStr.equals("false")) XYPairs = true;
                          else XYPairs = false;
                         }
       else {XYPairs = true;}


       iStr = getParameter("yfrom");
       if  (iStr != null) {YMin = Float.valueOf(iStr).floatValue();}
       else {YMin = 0;}

       iStr = getParameter("yto");
       if  (iStr != null) {YMax = Float.valueOf(iStr).floatValue();}
       else {YMax = 100;}

       //Calc. the range of Y --> DeltaY
       if ((YMax>=0) & (YMin>=0)) {DeltaY = YMax-YMin;}
       else {if ((YMax>=0) & (YMin<0)) {DeltaY = YMax-YMin;
                                       }
             else {DeltaY = Math.abs(YMin-YMax);
                  }
            }

       iStr = getParameter("xfrom");
       if  (iStr != null) {XMin = Float.valueOf(iStr).floatValue();}
       else {XMin = 0;}


       iStr = getParameter("xto");
       if  (iStr != null) {XMax = Float.valueOf(iStr).floatValue();}
       else {XMax = 100;}

       //Calc. the range of X --> DeltaX
       if ((XMax>=0) & (XMin>=0)) {DeltaX = XMax-XMin;}
       else {if ((XMax>=0) & (XMin<0)) {DeltaX = XMax-XMin;
                                       }
             else {DeltaX = Math.abs(XMin-XMax);
                  }
            }


      iStr = getParameter("xperiod");
      if (iStr != null) {XPeriod = Float.valueOf(iStr).floatValue();}
      else {XPeriod = 1;}


      iStr = getParameter("xypairs");
      if  (iStr != null) {maxPairs= Integer.valueOf(iStr).intValue();}
      else {maxPairs = 100;}



    // COLOR-Parameters
     iStr = getParameter("hbgcol");
     if (iStr != null) {HBGColor = WhichColor(HBGColor,iStr);}


     iStr = getParameter("hfgcol");
     if (iStr != null) {HFGColor = WhichColor(HFGColor,iStr);}

     iStr = getParameter("abgcol");
     if (iStr != null) {ABGColor = WhichColor(ABGColor,iStr);}

     iStr = getParameter("afgcol");
     if (iStr != null) {AFGColor = WhichColor(AFGColor,iStr);}

     iStr = getParameter("maxlin");
     if (iStr != null) {maxLines= Integer.valueOf(iStr).intValue();}
     else {maxLines=1;}

     LINColor = new Color [maxLines];
     for (int i=0; i<maxLines; i++)  {LINColor[i] = Color.blue;}


     iStr = getParameter("lincol");
     if (iStr != null) { st = new StringTokenizer(iStr,",");
                         for (int i=0; i<maxLines; i++)
                         { try {st1 = st.nextToken();
                                LINColor[i] = WhichColor(LINColor[i],st1);
                               }
                            catch (Exception e)
                               {System.out.println("Init: Error in lincol");
                               }
                         }
                       }






    //END of PARAMETER

    Mhe   = this.size().height;
    Mwi   = this.size().width;

    InitGlobalPar1();


    //double-buffering
     oimg = createImage(this.size().width,this.size().height);
     og   = oimg.getGraphics();


     WFloatingX = false;


     YNew     = new double [maxLines];
     YOld     = new double [maxLines];
     XNew     = new double [maxLines];
     XOld     = new double [maxLines];
     Index    = new int [maxLines];
     IBegin   = new int [maxLines];
     IEnd     = new int [maxLines];

     YArr     = new double [maxLines*maxPairs];   // the Y-Memory : Bildkoordinaten
     XArr     = new double [maxLines*maxPairs];   // the X-Memory : Bildkoordinaten




     for (int i=0;i<maxLines;i++)
     { YNew[i]    =YMin;
       YOld[i]    =YMin;
       XNew[i]    =0;
       XOld[i]    =0;
       Index[i]   =-1;
       IBegin[i]  = 0;
       IEnd[i]    = 0;

     }




     CHANGED   = false;
     ALLPOINTS = false;


  } // END of INIT


//WhichColor
 public Color WhichColor(Color old, String s)
 { Color c = new Color(0,0,0);
    c = old;

   String ds = s.toUpperCase();
    if (ds.equals("WHITE")==true) { c= Color.white;}
    else
    {if (ds.equals("BLACK")==true) {c =Color.black;}
      else
      {if (ds.equals("LIGHTGRAY")==true) {c = Color.lightGray;}
        else
        {if (ds.equals("GRAY")==true) {c = Color.gray;}
          else
          {if (ds.equals("DARKGRAY")==true) {c = Color.darkGray;}
            else
            {if (ds.equals("RED")==true) {c= Color.red;}
              else
              {if (ds.equals("GREEN")==true) {c= Color.green;}
                 else
                 {if (ds.equals("BLUE")==true) {c = Color.blue;}
                    else
                    {if (ds.equals("YELLOW")==true) {c = Color.yellow;}
                       else
                       {if (ds.equals("MAGENTA")==true) {c = Color.magenta;}
                         else
                          {if (ds.equals("CYAN")==true) {c = Color.cyan;}
                            else
                            {if (ds.equals("PINK")==true) {c = Color.pink;}
                               else
                               {if (ds.equals("ORANGE")==true) {c = Color.orange;}
                               }
                            }
                          }
                       }
                    }
                 }
              }
            }
          }
        }
       }
    }
  return c;
  }//END of WhichCoor




//SETCOLORS
 public void SetColors(String hbgcolor,
                       String hfgcolor,
                       String abgcolor,
                       String afgcolor)
 {
      if (hbgcolor.length()!=0) HBGColor = WhichColor(HBGColor,hbgcolor);
      if (hfgcolor.length()!=0) HFGColor = WhichColor(HFGColor,hfgcolor);
      if (abgcolor.length()!=0) ABGColor = WhichColor(ABGColor,abgcolor);
      if (afgcolor.length()!=0) AFGColor = WhichColor(AFGColor,afgcolor);



     repaint();

  }//End of SETCOLORS


//SETPARAMETER
// this method is used to set all parameters of the meter (whithout colors)
// via JavaScript by
// using document.meter.SetParameter(list of parameter)
 public void SetParameter(String head,
                       String xtitle,
                       String ytitle,
                       float  xfrom,
                       float  xto,
                       float  yfrom,
                       float  yto,
                       String onlyy,
                       float  xperiod,
                       int    maxXY
                      )
 {
    Header = head;
    if (Header.length()==0)   WHeader=false;
                        else  WHeader=true;
    XTitle = xtitle;
    if (XTitle.length()==0)   WXTitle=false;
                        else  WXTitle=true;


    YTitle = ytitle;
    if (YTitle.length()==0)   WYTitle=false;
                        else  WYTitle=true;


    if (onlyy.equals("false")==true) XYPairs=true;
                         else        XYPairs=false;



    YMin     = yfrom;
    YMax     = yto;
    XMin     = xfrom;
    XMax     = xto;
    XPeriod  = xperiod;

    maxPairs   = maxXY;


     YNew    = new double [maxLines];
     YOld    = new double [maxLines];
     XNew    = new double [maxLines];
     XOld    = new double [maxLines];
     Index   = new int [maxLines];
     IBegin  = new int [maxLines];
     IEnd    = new int [maxLines];

     YArr    = new double [maxLines*maxPairs];   // the Y-Memory : Bildkoordinaten
     XArr    = new double [maxLines*maxPairs];   // the X-Memory : Bildkoordinaten




     for (int i=0;i<maxLines;i++)
     { YNew[i]    =YMin;
       YOld[i]    =YMin;
       XNew[i]    =0;
       XOld[i]    =0;
       Index[i]   =-1;
       IBegin[i]  = 0;
       IEnd[i]    = 0;

     }



    ALLPOINTS= false;


    //Recalc. the range of Y --> DeltaY
    if ((YMax>=0) & (YMin>=0)) {DeltaY = YMax-YMin;}
    else {if ((YMax>=0) & (YMin<0)) {DeltaY = YMax-YMin;
                                    }
          else {DeltaY = Math.abs(YMin-YMax);
               }
         }


   //Recalc. the range of X --> DeltaX
    if ((XMax>=0) & (XMin>=0)) {DeltaX = XMax-XMin;}
    else {if ((XMax>=0) & (XMin<0)) {DeltaX = XMax-XMin;
                                    }
          else {DeltaX = Math.abs(XMin-XMax);
               }
         }



    //Recalculation

     InitGlobalPar1();

    //
    CHANGED  = false;

    repaint();


 } // End of SetParameter


public void SetParameter(String head,
                       String xtitle,
                       String ytitle,
                       float  xfrom,
                       float  xto,
                       float  yfrom,
                       float  yto,
                       String onlyy,
                       float  xperiod,
                       int    maxXY,
                       int    maxLin,
                       String lincols,
                       String seperator
                      )
 {StringTokenizer st;
  String st1;

  maxLines = maxLin;
  LINColor = new Color [maxLines];
  st = new StringTokenizer(lincols,seperator);
  for (int i=0; i<maxLines; i++)
  { try {st1 = st.nextToken();
         LINColor[i] = WhichColor(LINColor[i],st1);
        }
    catch (Exception e)
    {System.out.println("SetParameter: Error in parameter lincols");
    }
  }
  SetParameter(head,xtitle,ytitle,xfrom,xto,yfrom,yto,onlyy,xperiod,maxXY);

 }




//SETMaxXYPairs
// this method is used to set the max. number of xy/pairs are saved into the internal memory
// using document.meter.SetXYPairs(int MaxXY)
 public void SetMaxXYPairs(int MaxXY)
 {maxPairs   = MaxXY;

  YNew     = new double [maxLines];
  YOld     = new double [maxLines];
  XNew     = new double [maxLines];
  XOld     = new double [maxLines];
  Index    = new int [maxLines];
  IBegin   = new int [maxLines];
  IEnd     = new int [maxLines];

  YArr     = new double [maxLines*maxPairs];   // the Y-Memory : Bildkoordinaten
  XArr     = new double [maxLines*maxPairs];   // the X-Memory : Bildkoordinaten




  for (int i=0;i<maxLines;i++)
     { YNew[i]    =YMin;
       YOld[i]    =YMin;
       XNew[i]    =0;
       XOld[i]    =0;
       Index[i]   =-1;
       IBegin[i]  = 0;
       IEnd[i]    = 0;

     }



  CHANGED   = true;

  repaint();

 }//end of SetMaxXYPairs



//SetMaxLines
//this method is used to set the max. number of lines
//unsing document.meter.SetMaxLines(int MaxLines)
public void SetMaxLines(int MaxLines)
{maxLines = MaxLines;
 YNew     = new double [maxLines];
 YOld     = new double [maxLines];
 XNew     = new double [maxLines];
 XOld     = new double [maxLines];
 Index    = new int [maxLines];
 IBegin   = new int [maxLines];
 IEnd     = new int [maxLines];

 YArr     = new double [maxLines*maxPairs];   // the Y-Memory : Bildkoordinaten
 XArr     = new double [maxLines*maxPairs];   // the X-Memory : Bildkoordinaten


 LINColor = new Color [maxLines];


 for (int i=0;i<maxLines;i++)
     { YNew[i]    =YMin;
       YOld[i]    =YMin;
       XNew[i]    =0;
       XOld[i]    =0;
       Index[i]   =-1;
       IBegin[i]  = 0;
       IEnd[i]    = 0;
       LINColor[i]= Color.blue;

     }



 CHANGED   = true;

 repaint();

} //End of SetMaxLines


//SetLinesXYPairs
//this method is used to set the max. number of lines and the max. number of x/y-pairs
//using document.meter.SetLinesXYPairs(int MaxLines, int MaxXY)
public void SetLinesXYPairs(int MaxLines, int MaxXY)
{maxLines = MaxLines;
 maxPairs = MaxXY;
 YNew     = new double [maxLines];
 YOld     = new double [maxLines];
 XNew     = new double [maxLines];
 XOld     = new double [maxLines];
 Index    = new int [maxLines];
 IBegin   = new int [maxLines];
 IEnd     = new int [maxLines];
 LINColor = new Color [maxLines];

 YArr     = new double [maxLines*maxPairs];   // the Y-Memory : Bildkoordinaten
 XArr     = new double [maxLines*maxPairs];   // the X-Memory : Bildkoordinaten




for (int i=0;i<maxLines;i++)
     { YNew[i]    =YMin;
       YOld[i]    =YMin;
       XNew[i]    =0;
       XOld[i]    =0;
       Index[i]   =-1;
       IBegin[i]  = 0;
       IEnd[i]    = 0;
       LINColor[i]= Color.blue;

     }

CHANGED   = true;

repaint();


}//End of SetLinesXYPairs

//SETXYRange
//this methode is used to set the range of X and Y
//using via Javascript: doucument.meter.SetXYRange(float xfrom,xto,yfrom,yto)
public void SetXYRange(float xfrom,
                       float xto,
                       float yfrom,
                       float yto
                      )
{YMin     = yfrom;
 YMax     = yto;
 XMin     = xfrom;
 XMax     = xto;

 //Recalc. the range of Y --> DeltaY
 if ((YMax>=0) & (YMin>=0)) {DeltaY = YMax-YMin;}
 else {if ((YMax>=0) & (YMin<0)) {DeltaY = YMax-YMin;
                                 }
       else {DeltaY = Math.abs(YMin-YMax);
            }
       }


 //Recalc. the range of X --> DeltaX
 if ((XMax>=0) & (XMin>=0)) {DeltaX = XMax-XMin;}
 else {if ((XMax>=0) & (XMin<0)) {DeltaX = XMax-XMin;
                                 }
       else {DeltaX = Math.abs(XMin-XMax);
            }
      }

 //Recalc. of the scaling factors
 xfak          = (borderX1 - borderX0) / DeltaX;
 yfak          = (borderY0 - borderY1) / DeltaY;


 //Repaint
 CHANGED   = false;

 repaint();



}//End of SetXYRange


//SetXYMode
//this methode is used to set the mode of xy
// onlyy=true -> x is calculated based on xold + xperiod
//using via Javascript: document.meter.SetXYMode(onlyy,xperiod)
public void SetXYMode(String onlyy,
                      float  xperiod
                     )
{if (onlyy.equals("false")==true) XYPairs=true;
                      else        XYPairs=false;
 XPeriod = xperiod;

}//End of SetXYMode


//SetHeader
//this methode is used to set and change the header of the meter..
//using via Javascript: document.meter.SetHeader(header)
public void  SetHeader(String head)
{   Header = head;
    if (Header.length()==0)   WHeader=false;
                        else  WHeader=true;


    //Recalculation

    InitGlobalPar1();

    //
    CHANGED  = false;

    repaint();


}//End of SetHeader


//SetXYTitle
//this methode is used to set and change the title of the x and/or y axis
//using via Javascript: document.meter.SetXYTitle(xtitle,ytitle)
public void  SetXYTitle(String xtitle, String ytitle)
{   XTitle = xtitle;
    if (XTitle.length()==0)   WXTitle=false;
                        else  WXTitle=true;

    YTitle = ytitle;
    if (YTitle.length()==0)   WYTitle=false;
                        else  WYTitle=true;

    CHANGED  = false;

    repaint();


}//End of SetXYTitle




/* ================= TRANSFORM WC-> BC ======================== */

// TransformX
// transform X[double] -> X[int] ::: from xwc -> to xbc
public int TransformX(double xwc)
{ int    xn = 0;
  double x  = 0;

  xn = borderX0 + (int) Math.round(xfak * (xwc-XMin));
  return xn;

}//End of TransformT


// TransformY
// transform Y[bouble] -> Y[int] ::: ywc -> ybc
public int TransformY(double ywc)
{ int     yn = 0;
  double  y  = 0;


  yn = borderY0 - (int) Math.round(yfak*(ywc-YMin));
  return yn;

} //End of TransformY


/* ============== Set the Meter ======================================== */

// DRAWMETERY
//
// Set the y value of line "line" and draw the line
//  document.meter.DrawMeterY(int line,double V) (JavaScript)
//  if onlyy=true -> x is calculated
 public void DrawMeterY(int line,double V)
 { YNew[line-1]      = V;
   XNew[line-1]      = XOld[line-1] + XPeriod;
   ALLPOINTS    = false;

   if (Index[line-1] == (maxPairs-1)) {Index[line-1]=0;}      // too many points
   else {Index[line-1]++;}

   int i=Index[line-1]+((line-1)*maxPairs);

   YArr[i]=YNew[line-1];
   XArr[i]=XNew[line-1];


   CHANGED  =true;


   repaint();
  }// END of DRAWMETERY

// SETMETERY
// Set the y value (number of line is "line") of the meter without drawing
//  document.meter.SetMeterY(int line, double V) (JavaScript)
//  if onlyy=true -> x is calculated
 public void SetMeterY(int line,double V)
 { YNew[line-1]      = V;
   XNew[line-1]      = XOld[line-1] + XPeriod;
   ALLPOINTS    = false;

   if (Index[line-1] == (maxPairs-1)) {Index[line-1]=0;}      // too many points
   else {Index[line-1]++;}

   int i=Index[line-1]+((line-1)*maxPairs);

   YArr[i]=YNew[line-1];
   XArr[i]=XNew[line-1];


   CHANGED          = true;


  }// END of SETMETERY



// DRAWMETERXY
// Set a (x,y)-pair (number of line: "line") of the xy-meter via and draw the line
//   document.meter.DrawMeterXY(int line,double x, double y) (JavaScript)
 public void DrawMeterXY(int line, double x, double y)
 { YNew[line-1]      = y;
   XNew[line-1]      = x;
   ALLPOINTS         = false;


   if (Index[line-1]== (maxPairs-1)) {Index[line-1] = 0;                          //too many ponts
                        }
   else {Index[line-1]++;}


   int i=Index[line-1]+((line-1)*maxPairs);


   YArr[i]=YNew[line-1];
   XArr[i]=XNew[line-1];


   CHANGED          = true;


   repaint();
 }//End of DrawMeterYT



// SETMETERXY
// Set a (x,y)-pair (from line "line") of the xy-meter via without drawing
//   document.meter.SetMeterXY(int line, double x, double y) (JavaScript)
 public void SetMeterXY(int line, double x, double y)
 {

   YNew[line-1]      = y;
   XNew[line-1]      = x;
   ALLPOINTS         = false;


   if (Index[line-1]== (maxPairs-1)) {Index[line-1] = 0;                          //too many ponts
                        }
   else {Index[line-1]++;}


   int i=Index[line-1]+((line-1)*maxPairs);


   YArr[i]=YNew[line-1];
   XArr[i]=XNew[line-1];


   CHANGED          = true;



 }//End of SetMeterYT


//ResetMeter
//Clear Analog & Reset Index-1, YNew, YOld, XNew, XOld
public void ResetMeter()
{CHANGED   = true;
 ALLPOINTS = false;
 YNew     = new double [maxLines];
 YOld     = new double [maxLines];
 XNew     = new double [maxLines];
 XOld     = new double [maxLines];
 Index    = new int [maxLines];
 IBegin   = new int [maxLines];
 IEnd     = new int [maxLines];

 YArr   = new double [maxLines*maxPairs];   // the Y-Memory : Bildkoordinaten
 XArr   = new double [maxLines*maxPairs];   // the X-Memory : Bildkoordinaten




for (int i=0;i<maxLines;i++)
     { YNew[i]     =YMin;
       YOld[i]     =YMin;
       XNew[i]     =0;
       XOld[i]     =0;
       Index[i]    =-1;
       IBegin[i]   = 0;
       IEnd[i]     = 0;

     }


 repaint();

}



//SETLINECOLOR I
// Set the color of the line with number "line" is using to connect the points x,y
// document.meter.SetLineColor(String lincolor) (Javascript)
 public void SetLineColor(int line, String lincolor)
 { if ((line>0) & (line<=maxLines))
   {if (lincolor.length()!=0) LINColor[line-1] = WhichColor(LINColor[line-1],lincolor);
    repaint();
   }
  }//End of SETLINECOLOR I


//SETLINECOLOR II
  public void SetLineColor(int    maxLin,
                           String lincols,
                           String seperator)
 { StringTokenizer st;
   String st1;

   maxLines = maxLin;
   LINColor = new Color [maxLines];

   st = new StringTokenizer(lincols,seperator);
   for (int i=0; i<maxLines; i++)
   { try {st1 = st.nextToken();
          LINColor[i] = WhichColor(LINColor[i],st1);
        }
    catch (Exception e)
    {System.out.println("SetlineColor: Error in parameter lincols");
    }
  }

    repaint();

  }//End of SETLINECOLOR II

/* ====================== LineClip =================================== */
/* :::::: 30.06.1997                                                   */
/* Algorithm: Cohen-Sutherland                                         */
/* based on the TP-implementation of Haowei Hsien                      */
/* http://www.cc.gatecc.edu/gvu/people/Masters/Haowei.Hsieh.html       */
/* ====================================================================*/


boolean Top0    = false;    //used for point x0,y0
boolean Bottom0 = false;
boolean Left0   = false;
boolean Right0  = false;

boolean Top1    = false;    //used for point x1,y1
boolean Bottom1 = false;
boolean Left1   = false;
boolean Right1  = false;


int xc0,yc0,xc1,yc1;       //if clipped line these are the new coord.

//check if (x0,y0) is outside and where
public boolean CompCode0(int x, int y, int xmin,  int xmax,  int ymin,  int ymax)
{Top0    = false;
 Bottom0 = false;
 Left0   = false;
 Right0  = false;
 boolean Outside = false;

 if (y>ymax) {Top0 = true;Outside=true;}
 else {if (y < ymin) {Bottom0=true;Outside=true;}}

 if (x>xmax) {Right0=true;Outside=true;}
 else {if (x<xmin) {Left0=true;Outside=true;}}
 return Outside;
}

//check if (x1,y1) is outside and where
public boolean CompCode1(int x, int y, int xmin,  int xmax,  int ymin,  int ymax)
{Top1    = false;
 Bottom1 = false;
 Left1   = false;
 Right1  = false;
 boolean Outside = false;

 if (y>ymax) {Top1 = true;Outside=true;}
 else {if (y < ymin) {Bottom1=true;Outside=true;}}

 if (x>xmax) {Right1=true;Outside=true;}
 else {if (x<xmin) {Left1=true;Outside=true;}}
 return Outside;
}





public boolean LineClip(int x0, int y0, int x1, int y1,
                        int xmin,int xmax, int ymin, int ymax)
 {
   boolean TopOut   = false;  // used if point is outside
   boolean BottomOut= false;
   boolean LeftOut  = false;
   boolean RightOut = false;
   boolean CodeOut  = false;

   boolean Code0    = false;  // (x0,y0) outside?
   boolean Code1    = false;  // (x1,y1) outside?

   boolean DrawLine = false;  // draw the line
   boolean Fin      = false;  // the end

   boolean AllOutside= false; // both points are outside; dont draw the line

   int x,y,Code;


   xc0 = x0; yc0 = y0;                                  //the new clipped line
   xc1 = x1; yc1 = y1;


   Code0 =   CompCode0(xc0,yc0,xmin,xmax,ymin,ymax);
   Code1 =   CompCode1(xc1,yc1,xmin,xmax,ymin,ymax);



   do
    {Fin      = false;
     DrawLine = false;
     AllOutside = ((Top0 & Top1) ||
                   (Bottom0 & Bottom1) ||
                   (Right0 & Right1) ||
                   (Left0 & Left1)
                  );
     if ((Code0==false) & (Code1==false))  // both points are inside?
       { DrawLine = true;                   // points both are inside
         Fin      = true;                   // draw the line
       } //end both inside
       else
       {                                    // both points are outside?
        if (AllOutside==true)
         {                                  //both outside don't draw
           DrawLine  = false;
           Fin       = true;
         }//end both outside
         else
         { x=0;y=0;                           //Clipping of the line
           if (Code0==true)
            {                                 //CodeOut := Code0
              CodeOut    = Code0;
              TopOut     = Top0;
              BottomOut  = Bottom0;
              RightOut   = Right0;
              LeftOut    = Left0;
              Code       = 0;                 //CodeOut = Code0
            }
            else
            {                                 //CodeOut := Code1
              CodeOut    = Code1;
              TopOut     = Top1;
              BottomOut  = Bottom1;
              RightOut   = Right1;
              LeftOut    = Left1;
              Code       = 1;                //CodeOut = Code1
            }//end of else
                                              //find the intersection point
            if (TopOut==true)
            { x = xc0 + (xc1-xc0) * (ymax-yc0) / (yc1-yc0);
              y = ymax;
            }
            if (BottomOut==true)
            { x = xc0 + (xc1-xc0) * (ymin-yc0) / (yc1-yc0);
              y = ymin;

            }
            else
            {
             if (RightOut==true)
             {y = yc0 + (yc1-yc0) * (xmax-xc0) / (xc1-xc0);
              x = xmax;
             }
             else
             {if (LeftOut==true)
              { y = yc0 + (yc1-yc0) * (xmin-xc0) / (xc1-xc0);
                x = xmin;
              }
             }
            }//end of BottomOut=false

            if (Code==0)
            { xc0=x; yc0=y;
              Code0 = CompCode0(xc0,yc0,xmin,xmax,ymin,ymax);

            }//End CodeOut = Code0
            else
            { xc1=x; yc1=y;
              Code1 =   CompCode1(xc1,yc1,xmin,xmax,ymin,ymax);
            }//End CodeOut = Code1
         }//End of clipping the line
       }//End of NOT both inside

   } while (Fin==false);

   return DrawLine;


 } //End of LineClipping






/* ===================== RUN START STOP ============================== */

// RUN
 public void run()
 { repaint();

 }// End of RUN


// START
 public void start()
 {if (runner == null)
      {runner = new Thread(this);
       runner.start();
     }
  }// End of START


// STOP
 public void stop()
 {
     if (runner != null)
    {runner.stop();
     runner = null;
     }
  }// End of STOP


// Pause
   void pause(int time)
   {
     try { Thread.sleep(time);}
     catch (InterruptedException e) {}
   }




/* ============= PAINTING ============================================ */

//UPDATE
public void update(Graphics g)
{
   paint(g);


}//End of update

// PAINT
 public void paint(Graphics g)
 {   Font        f;
     FontMetrics fm;
     String      s;
     int         i,k,x,y,xe,ye;
     int         yk,yk1,xk,xk1;
     double      YN,XN;
     int         Fhe,fhe;
     int         dx,dy;
     boolean     OutOfRange;
     int         ax[] = new int[3];
     int         ay[] = new int[3];
     int 					usedSpace, freeSpace,needSpace;

/* == Init ===*/
    Fhe = 21;
    usedSpace=0; freeSpace=0;needSpace=0;
/* ============================= FRAMES =========================== */
    // draw the main frame
    og.setColor(Color.black);
    og. drawRect(0,0,Mwi,Mhe);

   // draw the  frame around the header
  if  (WHeader ==true)
  {   og.setColor(HBGColor);
       og.fillRect(0,0,Mwi-1,Hhe-1);
       og.setColor(Color.black);
       og.drawRect(0,0,Mwi-1,Hhe-1);
  }
  // draw the frame around the anal. instr.
     og.setColor(ABGColor);
     og.fillRect(0,Hhe,Mwi-1,Ahe-1);
     og.setColor(Color.black);
     og.drawRect(0,Hhe,Mwi-1,Ahe-1);


  /*===================== HEADER ===========================*/
  // HEADER
  if (WHeader == true)
  {  Fhe = 21;  // Calculate the font
     do
     { Fhe--;
        f     = new Font("TimesRoman",Font.PLAIN,Fhe);
        og.setFont(f);
        fm  = getFontMetrics(f);
        fhe= fm.getHeight();
    } while ((fhe+2)>Hhe);

       // print the header
       x = (Mwi/2) - (fm.stringWidth(Header)/2);
       y = (Hhe/2) + (fhe/2) - 2;
       if (x>0) {og.setColor(HFGColor);
	  og.drawString(Header,x,y);
                     }

  } // End of HEADER

/* ============================== ANALOG - Yt ================ */
  // analog


    og.setColor(AFGColor);

 //Draw the x-axis
    og.drawLine(xs0-2,ys0,xs1,ys1);

    //Draw the marker sticks
    dx = XMarkerSpace;                    // between 2 marker sticks
    dy = XMarkerLength;                  // the length of a marker stick
             //draw 10 markers
    y = ys0+dy;
    x = xs1;
    for (i=1; i<=10;i++)
    {x = xs0+i*dx;
     og.drawLine(x,ys0,x,y);
    }
    xe = x;
    ye = y;
    //Draw the arrow
    if (((xs1+6)<Mwi) & (hborder>8))
    {ax[0] = xs1;    ay[0]=ys1-3;
     ax[1] = xs1+5;  ay[1]=ys1;
     ax[2] = xs1;    ay[2]=ys1+3;
     og.fillPolygon(ax,ay,3);
    }

    //print min/max-values onto the t-axis
    dy = hborder - dy;
    Fhe++;  // Calculate the font
     do
     { Fhe--;
        f     = new Font("TimesRoman",Font.PLAIN,Fhe);
        og.setFont(f);
        fm  = getFontMetrics(f);
        fhe= fm.getHeight();
    } while (fhe>dy);

    x = xs0;
    y = yaroot-3;
    s = String.valueOf(XMin);
    og.drawString(s,x,y);
    if (WXTitle==true)
    {usedSpace = fm.stringWidth(s);}

    x = xe;
    y = yaroot-3;
    s = String.valueOf(XMax);
    og.drawString(s,x,y);
    if (WXTitle==true)
    {usedSpace=usedSpace+fm.stringWidth(s);}

    //print the title of the x axis
    if (WXTitle==true)
    {freeSpace= borderX1 - borderX0 - usedSpace;
     needSpace= fm.stringWidth(XTitle);
     if (needSpace< freeSpace)
     {y = yaroot-3;
      x = borderX0 + ((borderX1-borderX0)/2) - (needSpace/2);
      og.drawString(XTitle,x,y);
     }
    }


 //Draw the y-axis
    og.drawLine(xs0,ys0+3,xs2,ys2);


    //Draw the marker sticks
    dy = YMarkerSpace;              //between 2 marker sticks
    dx = YMarkerLength;                         //the length of a marker stick
         //draw 10 markers
    x = xs0-dx;
    for (i=1;i<=10;i++)
    {y = ys0-i*dy;
     og.drawLine(x,y,xs0,y);
    }
    ye = y;

    //Draw the arrow
    if (((xs1+6)<Mwi) & (hborder>8))
    {ax[0] = xs0-3;    ay[0]=ys2;
     ax[1] = xs0;      ay[1]=ys2-6;
     ax[2] = xs0+3;    ay[2]=ys2;
     og.fillPolygon(ax,ay,3);
    }

    //print min/max-values onto the y-axis
    x = xaroot +3;
    y = ys0;
    s = String.valueOf(YMin);
    if  ((x+fm.stringWidth(s))<xs0)
    {og.drawString(s,x,y);}

    y = ye;
    s = String.valueOf(YMax);
    if ((x+fm.stringWidth(s))<xs0)
    {og.drawString(s,x,y);}

    //print the title onto the y axis
    if (WYTitle==true)
    { y = borderY1-3;
      x = borderX0+5;
      if  (  (fm.stringWidth(YTitle) < (borderX1-borderX0))
         &  ((hborder-3)>= fhe ))
      {og.drawString(YTitle,x,y);
      }
    }



    //print the curves


    int j=0;
    for (int m=0;m<maxLines;m++)
    {og.setColor(LINColor[m]);            //set the color
     if (ALLPOINTS == true)
     { if (Index[m]>0)
       { for (k=1;k<=Index[m];k++)
         { j = (m*maxPairs)+k;
           yk  = TransformY(YArr[j]);
           yk1 = TransformY(YArr[j-1]);
           xk  = TransformX(XArr[j]);
           xk1 = TransformX(XArr[j-1]);
           if (LineClip(xk,yk,xk1,yk1,borderX0,borderX1,borderY1,borderY0)==true)
           {og.drawLine(xc1,yc1,xc0,yc0);}
         }//End of for
       }//End of Index>1

     }//End of ALLPOINTS=true
     else
     {if (Index[m]>0)
      { for (k=1;k<=Index[m];k++)
         { j = (m*maxPairs)+k;
           yk  = TransformY(YArr[j]);
           yk1 = TransformY(YArr[j-1]);
           xk  = TransformX(XArr[j]);
           xk1 = TransformX(XArr[j-1]);
           if (LineClip(xk,yk,xk1,yk1,borderX0,borderX1,borderY1,borderY0)==true)
           {og.drawLine(xc1,yc1,xc0,yc0);}
         }//End of for


       ALLPOINTS = true;

      }
     }//end of ALLPOINTS=false
     }//End of for maxlines





  //DOUBLE-BUFFERING
 g.drawImage(oimg,0,0,this);


 }// End of PAINT

}

Back to the XYMeter applet page

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Avaya DevConnect Center
 Service Component Architecture/Service Data Objects Solution Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 53
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Is .NET on Linux Finally Ready?
Red Hat Takes on HPC Market, Microsoft
Python's New Release Bridges the Gap
No Flash Seen on iPhone Horizon
Apple Yields to Complaints Over iPhone NDA
Microsoft Shows Some Ankle With Visual Studio
Gentoo Linux Cancels Distribution
It's Official: Windows 7 at PDC, WinHEC
Oracle Keeps Building on Spoils From BEA
Intel, Oracle Head For 'The Cloud'

C++Ox: The Dawning of a New Standard
Getting Started with Virtualization
Master Complex Builds with MSBuild
eCryptfs: Single-File Encryption in Linux
CCXML in Action: A CCXML Auto Attendant
Ballmer: Current Woes Won't Halt Tech, Microsoft
Microsoft Uses VMworld to Hype Its Hypervisor
Microsoft Charges Ahead in Virtualization
Microsoft Shows Some Ankle With Visual Studio
Top 5 Reasons to Adopt SQL Server 2008

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES