Subversion Repositories wimsdev

Rev

Rev 4242 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* B. Perrin-Riou & J.M.Evers 17/2/2009
  2. *********************************************************************************
  3. * This is all amateur scriblings... So no copyrights.                           *
  4. * This source code file, and compiled classes derived from it,                  *
  5. * can be used and distributed without restriction, including for commercial use *
  6. * No warrenty whatsoever                                                        *
  7. *********************************************************************************
  8.  
  9.  Example html page:
  10. <html>
  11.     <body>
  12.         <script language="javascript" type="text/javascript">
  13.             function readthis(){
  14.                 var input=document.getElementById("Clicktile").ReadApplet();
  15.                 alert(input);
  16.             }
  17.         </script>
  18.        
  19.         <!-- INTERNAL COLOR NAMES FOR PARAMS -->
  20.         <!-- "white","red","green","blue" -->
  21.         <!-- "orange","yellow","purple","lightgreen" -->
  22.         <!-- "lightblue","cyan","brown","salmon","pink,"black" -->
  23.         <applet id="Clicktile" code="Clicktile.class" codebase="." archive="Clicktile.jar" width="500" height="500">
  24.            
  25.             <!-- status = done : display non-clickable image -->
  26.             <param name="status" value="waiting">
  27.            
  28.             <!-- choose from the 13 colors -->
  29.             <param name="point_color" value="white">
  30.  
  31.             <!-- use only one at a time : leave others blank -->
  32.             <param name="point" value="1:1,2:2,3:3,4:4,5:5,6:6,7:7">
  33.             <param name="segment" value="">
  34.             <param name="polygon" value="">
  35.             <param name="line" value="">
  36.             <!-- segment and line are the same...for now -->
  37.             <!-- but a line is a segment with 2 points outside xrange/yrange -->
  38.    
  39.             <!-- for now only usefull in point param: default 5 -->
  40.             <param name="linewidth" value="20">
  41.  
  42.             <!-- if "1" or "yes" all objects including given drawing will be returned -->
  43.             <param name="return_all_objects" value="0">
  44.  
  45.             <!-- en ,de , fr ,nl  default en -->
  46.             <param name="language" value="fr">
  47.             <param name="xrange" value="-11,11">
  48.             <param name="yrange" value="-11,11">    
  49.             <param name="background_color" value="black">
  50.  
  51.             <!-- GIVEN DRAWING  : not more than 13 colors allowed -->
  52.             <param name="square1" value="4:1,4:2,4:3,4:4,5:4,6:4,8:4,8:3,8:2,8:1,5:1,6:1,7:1">
  53.             <!-- limited only by xrange/yrange : coordinates of rectangles e.g. predefined square [teacher] -->
  54.             <param name="square1_color" value="blue">
  55.             <param name="square2" value="-4:1,-4:2,-4:3,-4:4,-5:4,-6:4,-8:4,-8:3,-8:2,-8:1,-5:1,-6:1,-7:1">
  56.             <!-- limited only by xrange/yrange : coordinates of rectangles e.g. predefined square [teacher] -->
  57.             <param name="square2_color" value="yellow">
  58.          can add some image (must be transparent)
  59.          <param name="image" value="http://...">
  60.          <param name="copy" value="0,0">
  61.          <!-- coordinates in pixels of the left top corner-->
  62.             NO JAVA INSTALLED ?
  63.         </applet>
  64.  
  65.         <p>
  66.         <input type="button" name=".....TEST......" value=".....TEST....." onclick="javascript:readthis();">
  67.     </body>
  68. </html>
  69. */
  70.  
  71. import java.applet.*;
  72. import java.awt.*;
  73. import java.awt.event.*;
  74. import java.util.*;
  75. import java.lang.Math;
  76. import java.net.*;
  77.  
  78. public class Clicktile extends Applet implements Runnable,MouseListener, MouseMotionListener, MouseWheelListener{
  79.     private static final int serialVersionUID = 1;
  80.     int Clicktile[][];int MAX;
  81.     int dx;int dy;Thread thread = null;
  82.     Image canvas;Graphics2D drawing;
  83.     int xmin=-10,xmax=10,ymin=-10,ymax=10;// xmin/xmax ymin/ymax is coordinate system... xrange/yrange
  84.     int xsize,ysize;// xsize,ysize is canvas-size
  85.     int x_rect,y_rect;// x_rect * y_rect is pixel x/y-size of an elementary rectangle
  86.     int Rx,Ry;// Rx * Ry is amount of elementary rectangles on canvas
  87.     int palette[][] = {{255,255,255},{255,0,0},{0,255,0},{0,0,255},{238,154,0},{255,255,0},{160,32,240},{144,238,144},{173,216,230},{0,255,255},{165,24,24},{250,128,114},{255,192,203},{0,0,0}};
  88.     final int max=palette.length;// 14 different colors...arraylength=13
  89.     int[] color = new int[max];// color[0] is background color
  90.     int objects=0;int[][] xcoords;int[][] ycoords;int[] length;
  91.     public String COLORS[] = new String[max];
  92.     int linewidth=1;int TYPE=0;int[] xpoints;int[] ypoints;int point_color=0;
  93.     String language="en";boolean status=true;
  94.     int[] used_colors;int this_color=0;
  95.     Image bg;URL url;int copy_x=0 ; int copy_y=0 ;
  96.    
  97.     public void init(){
  98.         String c;
  99.         xsize = getSize().width;ysize = getSize().height;
  100.         c=getParameter("status");
  101.         if(c != null && c.length()>0){
  102.             if(c.equalsIgnoreCase("waiting")) status = true;
  103.             else
  104.             if(c.equalsIgnoreCase("done")) status = false;
  105.         }
  106.         c=getParameter("language");
  107.         if(c != null && c.length()>0){
  108.             Determine_Color_Names(c); // en: COLOR[0]="white" fr: COLOR[0]="blanc"
  109.         }
  110.         c=getParameter("background_color");
  111.         if(c != null && c.length()>0){
  112.             color[0]=GetInternalColorCode( c , 0); // 0 is default white background
  113.         }
  114.         int obj=1;
  115.         c=getParameter("square"+obj+"_color");
  116.         while(c!=null && c.length()>0){ // translate param colors into internal color_array
  117.             c=getParameter("square"+obj+"_color");
  118.             if(c != null && c.length()>0){
  119.                 objects++; color[obj] = GetInternalColorCode( c , 13); // 13 default black
  120.             }
  121.             obj++;
  122.         }
  123.         c=getParameter("xrange");
  124.         if(c != null && c.length()>0){Determine_Range( c , "x");}// determine the Xrange of the square ... xmin xmax
  125.         c=getParameter("yrange");
  126.         if(c != null && c.length()>0){Determine_Range( c , "y");}// determine the Yrange of the square ... ymin ymax
  127.         Rx=Math.abs(xmax-xmin);Ry=Math.abs(ymax-ymin);
  128.         MAX=Rx*Ry;
  129.         x_rect=(int)xsize/Rx;y_rect=(int)ysize/Ry; // there are Rx squares in our square : per square x_rect pixels
  130.         Clicktile = new int[MAX][MAX]; // Clicktile[0] does not exist: it is the background of canvas !!
  131.         canvas = createImage(xsize,ysize);drawing = (Graphics2D) canvas.getGraphics();
  132.         xcoords=new int[MAX][MAX];ycoords=new int[MAX][MAX];
  133.         length=new int[MAX]; // how many squares per color
  134.         for(int i=0;i<MAX;i++){// fill array with zero's
  135.             length[i]=0;
  136.         }
  137.         for(int i=0; i<MAX;i++){
  138.             for(int ii=0;ii<MAX;ii++){
  139.                 xcoords[ii][i]=0;// fill array with zero's
  140.                 ycoords[ii][i]=0;// fill array with zero's
  141.             }
  142.         }      
  143.         for(int x=0;x<MAX;x++){
  144.             for(int y=0;y<MAX;y++){
  145.                 Clicktile[y][x] = color[0];// coloring the background color[0]
  146.             }
  147.         }
  148.         // get the supplementary colors
  149.         c=getParameter("colors");
  150.         int maxcolors = 0 ;
  151.         if(c != null && c.length()>0){
  152.            StringTokenizer q = new StringTokenizer(c, ",");
  153.            maxcolors=q.countTokens() ;
  154.         }
  155.         int[] tmpcolors=new int[objects + 1 + maxcolors];
  156.         if(c != null && c.length()>0){
  157.             StringTokenizer q = new StringTokenizer(c, ",");
  158.             maxcolors=q.countTokens();
  159.             for( int p = 0 ; p<maxcolors ; p++){
  160.                 String  k=q.nextToken();
  161.                 tmpcolors[p]=GetInternalColorCode( k, 0 );
  162.             }
  163.         }
  164.         if(maxcolors>0){this_color=maxcolors;}
  165.         // get the square
  166.         tmpcolors[maxcolors]=color[0];
  167.         for(obj=1 ; obj<=objects ;obj++){
  168.             c=getParameter("square"+obj);
  169.             int L=0;int coords=0;
  170.             if( c!=null && c.length()>0){
  171.                 // scheme 4:4,2:2,0:0  scheme 4;4,2;2,0;0  scheme 4@4,2@2,0@0 scheme 4 4,2 2,0 0
  172.                 c=c.replace(';',':');c=c.replace('@',':');c=c.replace(' ',':');
  173.                 StringTokenizer q1 = new StringTokenizer(c, ",");
  174.                 String k1;String k2;
  175.                 int array_x=0;int array_y=0;// array_x & array_y are array cell numbers
  176.                 coords=q1.countTokens();L=0;
  177.                 int tmp;
  178.                 boolean out_of_range;
  179.                 try {
  180.                     for(int p=0;p<coords;p++){
  181.                         k1=q1.nextToken();
  182.                         StringTokenizer q2 = new StringTokenizer(k1, ":");
  183.                         out_of_range=false;// jm.evers 27/12/2011 : corrected array-out-of-bound
  184.                         for(int s=0;s<2;s++){
  185.                             k2=q2.nextToken();
  186.                             tmp=Integer.parseInt(k2,10);
  187.                             if(s==0 && (tmp < xmin || tmp > xmax)){
  188.                                 out_of_range=true;
  189.                                 System.out.println("x-value : "+tmp+" will be ignored !!! it is out of xrange\n");
  190.                             }
  191.                             if(s==1 && (tmp < ymin || tmp > ymax)){
  192.                                 out_of_range=true;
  193.                                 System.out.println("y-value : "+tmp+" will be ignored !!! it is out of yrange\n");
  194.                             }
  195.                             if(!out_of_range){
  196.                                 if(s==0){
  197.                                     array_x=(int)((tmp - xmin)*(xmax - xmin)/Rx);
  198.                                     xcoords[p][obj]=array_x;
  199.                                 }
  200.                                 else
  201.                                 {
  202.                                     array_y=(int)(Ry + (tmp-ymin)*(ymax-ymin)/(-1*Ry));
  203.                                     ycoords[p][obj]=array_y;
  204.                                 }
  205.                             }
  206.                         }
  207.                         if(!out_of_range){
  208.                             tmpcolors[obj+maxcolors] = color[obj];
  209.                             // give it the appropriate square_color
  210.                             Clicktile[array_y][array_x]=color[obj];
  211.                             L++;
  212.                         }
  213.                     }
  214.                     length[obj]=L;
  215.                 } catch (Exception e){System.out.println("there is no square"+obj+"\n"+e);}
  216.             }
  217.         }
  218.         used_colors = ListUniq(tmpcolors);//list uniq array of internal colors [int]
  219.  
  220.         c=getParameter("image");
  221.         if (c!=null && c.length()>0) {
  222.             try {url=new URL(c);}
  223.             catch (MalformedURLException e) {url=null;}
  224.             if(url!=null) bg=getImage(url);
  225.             else bg=null;
  226.         }
  227.         else bg=null;
  228.  
  229.         c=getParameter("copy");
  230.         if( c != null && c.length() > 0 ){
  231.             StringTokenizer q = new StringTokenizer(c, ",");
  232.             for( int p = 0 ; p<2 ; p++){
  233.                 String  k=q.nextToken();
  234.                 if(p==0){
  235.                     copy_x=Integer.parseInt(k,10);
  236.                 }
  237.                 if(p==1){
  238.                     copy_y=Integer.parseInt(k,10);
  239.                 }
  240.             }
  241.         }
  242.        
  243.         // get  point_color, point,line or polygon
  244.         c=getParameter("point_color");
  245.         if(c != null && c.length()>0){ point_color=GetInternalColorCode( c , 0);}
  246.         c=getParameter("linewidth"); if( c != null && c.length() > 0 ){ linewidth = Integer.parseInt(c,10); }
  247.         c=getParameter("point");
  248.         if( c != null && c.length() > 0 ){
  249.             Retreive_values_from_coordinates( c , 1 );
  250.         }
  251.         else
  252.         {
  253.             c=getParameter("segment");
  254.             if( c != null && c.length() > 0 ){
  255.                 Retreive_values_from_coordinates( c , 2 );
  256.             }
  257.             else
  258.             {
  259.                 c=getParameter("line");
  260.                 if( c != null && c.length() > 0 ){
  261.                     Retreive_values_from_coordinates( c , 3 );
  262.                 }
  263.                 else
  264.                 {
  265.                     c=getParameter("polygon");
  266.                     if( c != null && c.length() > 0 ){
  267.                         Retreive_values_from_coordinates( c , 4 );
  268.                     }
  269. //                  else
  270. //                  {
  271. //                      System.out.println("NO SYMMETRY LINE,SEGMENT,POINT or POLY DEFINED");
  272. //                  }
  273.                 }
  274.             }
  275.         }
  276.        
  277.         addMouseListener(this);
  278.         addMouseMotionListener(this);
  279.         addMouseWheelListener(this);
  280.     }
  281.  
  282.     public synchronized void mouseReleased(MouseEvent evt){}
  283.     public void mouseEntered(MouseEvent evt){requestFocus();}
  284.     public void mouseExited(MouseEvent evt){}
  285.     public void mouseMoved(MouseEvent evt){requestFocus();}
  286.     public void mouseClicked(MouseEvent evt){
  287.         // right click changes color
  288.         if(status){
  289.             dx = evt.getX()/x_rect;
  290.             dy = evt.getY()/y_rect;
  291.             if( evt.getButton() == MouseEvent.BUTTON3 ||  evt.getButton() == MouseEvent.BUTTON2 ){
  292.                 this_color++;
  293.                 System.out.println("Change color : "+this_color);
  294.                 if(this_color > used_colors.length - 1){this_color=0;}
  295.                 Clicktile[dy][dx] = used_colors[this_color];
  296.                 process_mouse(dx,dy);
  297.             }
  298.         }
  299.     }
  300.    
  301.     public void mouseWheelMoved(MouseWheelEvent evt){
  302.         if(status){
  303.             dx = evt.getX()/x_rect;
  304.             dy = evt.getY()/y_rect;
  305.             this_color++;
  306.             if(this_color > used_colors.length - 1){this_color=0;}
  307.             Clicktile[dy][dx] = used_colors[this_color];
  308.             process_mouse(dx,dy);
  309.         }
  310.     }
  311.    
  312.     public void mousePressed(MouseEvent evt){
  313.         if(status){
  314.             dx = evt.getX()/x_rect;
  315.             dy = evt.getY()/y_rect;
  316.             process_mouse(dx,dy);
  317.         }
  318.     }
  319.  
  320.     public void mouseDragged(MouseEvent evt){
  321.         if(status){
  322.             dx = evt.getX()/x_rect;
  323.             dy = evt.getY()/y_rect;
  324.             process_mouse(dx,dy);
  325.         }
  326.     }
  327.     public void process_mouse(int dx,int dy){
  328.         if(dx > -1 &&  dy > -1){//array out of bound
  329.             int n = 0;boolean do_paint=true;
  330.             if(dx>=0 && dx<= Rx  && dy>=0 && dy<= Ry){
  331.                 for(int obj=0;obj<=objects && do_paint ;obj++){
  332.                     for(int p=0;p<length[obj] && do_paint ;p++){
  333.                         if(xcoords[p][obj]==dx && ycoords[p][obj]==dy){//System.out.println("CLICKED ON GIVEN DRAWING !!");
  334.                             do_paint=false;
  335.                         }      
  336.                     }
  337.                 }
  338.             }
  339.             if(do_paint){
  340.                 Clicktile[dy][dx] = used_colors[this_color];
  341.                 repaint();
  342.             }
  343.         }
  344.     }
  345.    
  346.     public void paint(Graphics g){
  347.         drawing.setColor(Color.white);
  348.         drawing.fillRect(0,0,xsize,ysize);
  349.         int k;
  350.         for(int xr = 0;xr < Rx;xr++){
  351.             for(int yr = 0;yr < Ry;yr++){
  352.                 k=Clicktile[yr][xr];
  353.                 drawing.setColor(new Color(palette[k][0],palette[k][1],palette[k][2])); // this is the student "drawing"
  354.                 drawing.fill3DRect(x_rect*xr,y_rect*yr,x_rect,y_rect,true); // use "3D effect"
  355.             }
  356.         }
  357.         if(TYPE != 0){drawing.setColor(new Color(palette[point_color][0],palette[point_color][1],palette[point_color][2]));}
  358.         if(TYPE == 1){// several points
  359.             drawing.setStroke(new BasicStroke(linewidth,BasicStroke.JOIN_ROUND,BasicStroke.JOIN_BEVEL));
  360.             for(int p = 0; p < xpoints.length ; p++){
  361.                 drawing.fillOval( (int)(xpoints[p] - 0.5*linewidth) , (int)(ypoints[p] -0.5*linewidth) , linewidth,linewidth );
  362.                 //System.out.println("points "+xpoints[p]+":"+ypoints[p]);
  363.             }
  364.         }
  365.         else if(TYPE == 2){// several lines
  366.             drawing.setStroke(new BasicStroke(linewidth,BasicStroke.JOIN_ROUND,BasicStroke.JOIN_BEVEL));
  367.             for( int p = 0 ; p< xpoints.length -1 ; p=p+2){
  368.                 drawing.drawLine( xpoints[p] , ypoints[p], xpoints[p+1], ypoints[p+1]);
  369.             }
  370.         }
  371.         else if(TYPE == 3){//for now the same as TYPE = 2
  372.             drawing.setStroke(new BasicStroke(linewidth,BasicStroke.JOIN_ROUND,BasicStroke.JOIN_BEVEL));
  373.             for( int p = 0 ; p< xpoints.length -1 ; p=p+2){
  374.                 drawing.drawLine( xpoints[p] , ypoints[p], xpoints[p+1], ypoints[p+1]);
  375.             }
  376.         }
  377.         else if(TYPE ==  4){
  378.             int lim=xpoints.length - 1; // improvised polygon...non-filled
  379.             drawing.setStroke(new BasicStroke(linewidth,BasicStroke.JOIN_ROUND,BasicStroke.JOIN_BEVEL));
  380.             for(int p = 0 ;  p < lim  ; p++){
  381.                 drawing.drawLine(xpoints[p], ypoints[p], xpoints[p+1],ypoints[p+1]);
  382.             }
  383.             drawing.drawLine(xpoints[lim], ypoints[lim], xpoints[0],ypoints[0]);
  384.         }
  385.         g.drawImage(canvas,0,0,this); // draw this square on canvas
  386.         // THIS CODE SHOULD BE LAST: paint on top of image
  387.         // jm.evers 3/10/2010
  388.         if(bg!=null) g.drawImage(bg,copy_x,copy_y,this);
  389.      }
  390.  
  391.    public void start(){
  392.       if(thread == null){
  393.          thread = new Thread(this);
  394.          thread.start();
  395.       }
  396.    }
  397.  
  398.     public void stop(){
  399.         thread =  null;
  400.     }
  401.  
  402.     public void run(){
  403.         while(thread != null){
  404.             try{
  405.                 Thread.sleep(100);
  406.             }
  407.             catch (InterruptedException e){
  408.             }
  409.         }
  410.     }
  411.    
  412.     public void update( Graphics g ){
  413.         paint( g );
  414.     }
  415.    
  416.     public String ReadApplet(){// public function to be issued by Javascript...and send to WIMS
  417.         String c=getParameter("return_all_objects");
  418.         boolean return_all=false;
  419.         boolean do_print=true;
  420.         if(c.equalsIgnoreCase("yes") || c.equals("1")){return_all=true;}
  421.         String reply="";boolean fnd=false;int repx=0;int repy=0;int k;String K="";
  422.         for(int x=0; x<Rx; x++){
  423.             for(int y=0;y<Ry;y++){
  424.                 k=Clicktile[y][x];
  425.                 // back to coordinates
  426.                 repx=(int)(xmin+x*Rx/(xmax - xmin));
  427.                 repy=(int)(Ry + (y - ymin)*(ymax-ymin)/(-1*Ry));
  428.                 if(return_all){ // <param name="return_all" value="0">
  429.                     if( k != color[0] ){// no background
  430.                         K=COLORS[k];
  431.                         if(fnd){ reply=reply+","+K+"@"+repx+":"+repy; }
  432.                         else { fnd=true; reply=K+"@"+repx+":"+repy; }
  433.                     }
  434.                 }
  435.                 else
  436.                 {  // <param name="return_all" value="1">
  437.                     do_print=true;
  438.                     for(int obj=0;obj<=objects;obj++){
  439.                         for(int p=0;p<length[obj];p++){
  440.                             if(xcoords[p][obj]==x && ycoords[p][obj]==y){// exclude the square from params stored in xcoords[] ycoords[]
  441.                                 do_print=false;
  442.                                 //System.out.println("will not print ("+x+":"+y+") with color="+color[k]);
  443.                             }
  444.                         }
  445.                     }
  446.                     if(do_print){
  447.                         if( k != color[0] ){// no background
  448.                             K=COLORS[k];
  449.                             if(fnd){ reply=reply+","+K+"@"+repx+":"+repy; }
  450.                             else { fnd=true; reply=K+"@"+repx+":"+repy; }
  451.                         }
  452.                     }
  453.                 }
  454.             }
  455.         }
  456.         if(reply.length() == 0){reply="ERROR: YOU DID NOT CLICK ANYTHING";}
  457.         return reply;
  458.     }
  459.     // jm.evers 1/2/2011
  460.     // returns only: x-values +"\n"+y_values
  461.     // e.g. no color information
  462.     public String ReadXY(){// public function to be issued by Javascript...and send to WIMS
  463.         String c=getParameter("return_all_objects");
  464.         boolean return_all=false;
  465.         boolean do_print=true;
  466.         if(c.equalsIgnoreCase("yes") || c.equals("1")){return_all=true;}
  467.         String reply_x="";String reply_y="";boolean fnd=false;int repx=0;int repy=0;int k;
  468.         for(int x=0; x<Rx; x++){
  469.             for(int y=0;y<Ry;y++){
  470.                 k=Clicktile[y][x];
  471.                 // back to coordinates
  472.                 repx=(int)(xmin+x*Rx/(xmax - xmin));
  473.                 repy=(int)(Ry + (y - ymin)*(ymax-ymin)/(-1*Ry));
  474.                 if(return_all){ // <param name="return_all" value="0">
  475.                     if( k != color[0] ){// no background
  476.                         if(fnd){ reply_x = reply_x+","+repx; reply_y = reply_y+","+repy; }
  477.                         else { fnd=true; reply_x=""+repx;reply_y=""+repy; }
  478.                     }
  479.                 }
  480.                 else
  481.                 {  // <param name="return_all" value="1">
  482.                     do_print=true;
  483.                     for(int obj=0;obj<=objects;obj++){
  484.                         for(int p=0;p<length[obj];p++){
  485.                             if(xcoords[p][obj]==x && ycoords[p][obj]==y){// exclude the square from params stored in xcoords[] ycoords[]
  486.                                 do_print=false;
  487.                             }
  488.                         }
  489.                     }
  490.                     if(do_print){
  491.                         if( k != color[0] ){// no background
  492.                             if(fnd){ reply_x=reply_x+","+repx;reply_y=reply_y+","+repy; }
  493.                             else { fnd=true; reply_x=""+repx;reply_y=""+repy; }
  494.                         }
  495.                     }
  496.                 }
  497.             }
  498.         }
  499.         if(reply_x.length() == 0){reply_x="ERROR: YOU DID NOT CLICK ANYTHING";}
  500.         return reply_x+"\n"+reply_y;
  501.     }
  502.    
  503.     public int GetInternalColorCode(String c , int defaultcode){
  504.         int colorcode=defaultcode;
  505.         if(c.equalsIgnoreCase("white")) colorcode=0;
  506.         else
  507.         if(c.equalsIgnoreCase("red")) colorcode=1;
  508.         else
  509.         if(c.equalsIgnoreCase("green")) colorcode=2;
  510.         else
  511.         if(c.equalsIgnoreCase("blue")) colorcode=3;
  512.         else
  513.         if(c.equalsIgnoreCase("orange")) colorcode=4;
  514.         else
  515.         if(c.equalsIgnoreCase("yellow")) colorcode=5;
  516.         else
  517.         if(c.equalsIgnoreCase("purple")) colorcode=6;
  518.         else
  519.         if(c.equalsIgnoreCase("lightgreen")) colorcode=7;
  520.         else
  521.         if(c.equalsIgnoreCase("lightblue")) colorcode=8;
  522.         else
  523.         if(c.equalsIgnoreCase("cyan")) colorcode=9;
  524.         else
  525.         if(c.equalsIgnoreCase("brown")) colorcode=10;
  526.         else
  527.         if(c.equalsIgnoreCase("salmon")) colorcode=11;
  528.         else
  529.         if(c.equalsIgnoreCase("pink")) colorcode=12;
  530.         else
  531.         if(c.equalsIgnoreCase("black")) colorcode=13;
  532.        
  533.         return colorcode;
  534.     }
  535.    
  536.     public int X_ConvertToInternalCoordinates(int x){
  537.         int X = (int)(x_rect*(x - xmin)*(xmax - xmin)/Rx);
  538.         return X;
  539.     }
  540.    
  541.     public int Y_ConvertToInternalCoordinates(int y){
  542.         int Y = (int)(y_rect*(Ry + (y - ymin)*(ymax - ymin)/(-1*Ry)));
  543.         return Y;
  544.     }
  545.    
  546.     public void Retreive_values_from_coordinates( String c , int type){
  547.         // typical value="-5:5,-4;4,-3:3"
  548.         TYPE=type;
  549.         c=c.replace(';',':');c=c.replace('@',':');c=c.replace(' ',':');
  550.         StringTokenizer q1 = new StringTokenizer(c, ",");
  551.         String k1;String k2;
  552.         int m0=q1.countTokens();
  553.         xpoints=new int[m0];
  554.         ypoints=new int[m0];
  555.         int tmp;int m1;boolean flipflop=true;
  556.         for(int p=0;p<m0;p++){
  557.             k1=q1.nextToken();
  558.             StringTokenizer q2 = new StringTokenizer(k1, ":");
  559.             m1 = q2.countTokens();
  560.             for(int s=0; s<m1 ; s++){
  561.                 k2=q2.nextToken();
  562.                 if(flipflop){
  563.                     try{ tmp = Integer.parseInt(k2,10); xpoints[p] = X_ConvertToInternalCoordinates(tmp); }
  564.                     catch(Exception e){System.out.println("ERROR\n"+e);}
  565.                     flipflop=false;
  566.                 }
  567.                 else
  568.                 {
  569.                     try{ tmp = Integer.parseInt(k2,10); ypoints[p] = Y_ConvertToInternalCoordinates(tmp); }
  570.                     catch(Exception e){System.out.println("ERROR\n"+e);}
  571.                     flipflop=true;
  572.                 }
  573.             }
  574.         }
  575.  
  576.  
  577.     }
  578.    
  579.     public void Determine_Range(String c , String type){
  580.         c=c.replace(':',',');c=c.replace(';',',');
  581.         StringTokenizer q = new StringTokenizer(c, ",");
  582.         String k;
  583.         for(int p=0;p<2;p++){
  584.             k=q.nextToken();
  585.             if(p==0){
  586.                 if(type.equals("x")){ xmin = Integer.parseInt(k,10);}
  587.                 else { ymin = Integer.parseInt(k,10);}
  588.             }
  589.             else
  590.             {
  591.                 if(type.equals("x")){ xmax = Integer.parseInt(k,10);}
  592.                 else { ymax = Integer.parseInt(k,10);}
  593.             }
  594.         }
  595.     }
  596.    
  597.     public void Determine_Color_Names(String lang){
  598.         if(lang.equalsIgnoreCase("nl")){
  599.             COLORS[0]="wit";COLORS[1]="rood";COLORS[2]="groen";COLORS[3]="blauw";
  600.             COLORS[4]="oranje";COLORS[5]="geel";COLORS[6]="paars";COLORS[7]="licht groen";
  601.             COLORS[8]="licht blauw";COLORS[9]="cyaan";COLORS[10]="bruiwn";COLORS[11]="zalmroze";
  602.             COLORS[12]="roze";COLORS[13]="zwart";// max = 13
  603.         }
  604.         else
  605.         { // TO DO : TRANSLATION ?
  606.        
  607.             if(lang.equalsIgnoreCase("fr")){
  608.                 COLORS[0]="blanc";COLORS[1]="rouge";COLORS[2]="vert";COLORS[3]="bleu";
  609.                 COLORS[4]="orange";COLORS[5]="jaune";COLORS[6]="violet";COLORS[7]="vert pâle";
  610.                 COLORS[8]="bleu clair";COLORS[9]="cyan";COLORS[10]="marron";COLORS[11]="saumon";
  611.                 COLORS[12]="rose";COLORS[13]="noir";
  612.             }
  613.             else
  614.             {
  615.                 if(lang.equalsIgnoreCase("de")){
  616.                     COLORS[0]="weiß";COLORS[1]="rot";COLORS[2]="grun";COLORS[3]="blau";
  617.                     COLORS[4]="orange";COLORS[5]="gelb";COLORS[6]="violett";COLORS[7]="hellgrün";
  618.                     COLORS[8]="hellblau";COLORS[9]="cyan";COLORS[10]="braun";COLORS[11]="Lachsfarbig";
  619.                     COLORS[12]="rosa";COLORS[13]="schwartz";
  620.                 }
  621.                 else
  622.                 {
  623.                     COLORS[0]="white";COLORS[1]="red";COLORS[2]="green";COLORS[3]="blue";
  624.                     COLORS[4]="orange";COLORS[5]="yellow";COLORS[6]="purple";COLORS[7]="lightgreen";
  625.                     COLORS[8]="lightblue";COLORS[9]="cyan";COLORS[10]="brown";COLORS[11]="salmon";
  626.                     COLORS[12]="pink";COLORS[13]="black";
  627.                 }
  628.             }  
  629.         }
  630.     }
  631.     // a listuniq on colors used in several square1...square_n    
  632.     public int[] ListUniq(int[] array){
  633.         Arrays.sort(array);
  634.         int k = 0;
  635.         for (int i = 0; i < array.length; i++){
  636.             if (i > 0 && array[i] == array[i -1] )
  637.             continue;
  638.             array[k++] = array[i];
  639.         }
  640.         int [] unique = new int[k];
  641.         System.arraycopy(array, 0, unique, 0, k);
  642.         return unique;
  643.     }
  644. }
  645.  
  646.  
  647. /*
  648. 0 "white" {255,255,255}
  649. 1 "red" {255,0,0}
  650. 2 "green" {0,255,0}
  651. 3 "blue" {0,0,255}
  652. 4 "orange" {238,154,0}
  653. 5 "yellow" {255,255,0}
  654. 6 "purple" {160,32,240}
  655. 7 "lightgreen" {144,238,144}
  656. 8 "lightblue" {173,216,230}
  657. 9 "cyan" {0,255,255}
  658. 10 "brown" {165,24,24}
  659. 11 "salmon" {250,128,114}
  660. 12 "pink" {255,192,203}
  661. */
  662.  
  663. //{255,255,255},{255,0,0},{0,255,0},{0,0,255},{238,154,0},{255,255,0},{160,32,240},{144,238,144},{173,216,230},{0,255,255},{165,24,24},{250,128,114},{255,192,203}
  664.