Back to index

wims  3.65+svn20090927
Public Member Functions | Public Attributes | Package Attributes | Static Private Attributes
Clicktile Class Reference
Inheritance diagram for Clicktile:
Inheritance graph
[legend]
Collaboration diagram for Clicktile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void init ()
void paint (Graphics g)
void start ()
void stop ()
void run ()
void update (Graphics g)
String ReadApplet ()
int GetInternalColorCode (String c, int defaultcode)
int X_ConvertToInternalCoordinates (int x)
int Y_ConvertToInternalCoordinates (int y)
void Retreive_values_from_coordinates (String c, int type)
void Determine_Range (String c, String type)
void Determine_Color_Names (String lang)
int[] ListUniq (int[] array)

Public Attributes

String COLORS [] = new String[max]

Package Attributes

int Clicktile [][]
int MAX
int dx
int dy
Thread thread = null
Image canvas
Graphics drawing
int xmin = -10
int xmax = 10
int ymin = -10
int ymax = 10
int xsize
int ysize
int x_rect
int y_rect
int Rx
int Ry
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}}
final int max = palette.length
int[] color = new int[max]
int objects = 0
int[][] xcoords
int[][] ycoords
int[] length
int linewidth = 5
int TYPE = 0
int[] xpoints
int[] ypoints
int point_color = 0
String language = "en"
boolean status = true
int[] used_colors
int this_color = 0
Image bg
URL url
int copy_x = 0
int copy_y = 0

Static Private Attributes

static final int serialVersionUID = 1

Detailed Description

Definition at line 72 of file Clicktile.java.


Member Function Documentation

void Clicktile.Determine_Color_Names ( String  lang) [inline]

Definition at line 501 of file Clicktile.java.

                                                  {
       if(lang.equalsIgnoreCase("nl")){ 
           COLORS[0]="wit";COLORS[1]="rood";COLORS[2]="groen";COLORS[3]="blauw";
           COLORS[4]="oranje";COLORS[5]="geel";COLORS[6]="paars";COLORS[7]="licht groen";
           COLORS[8]="licht blauw";COLORS[9]="cyaan";COLORS[10]="bruiwn";COLORS[11]="zalmroze";
           COLORS[12]="roze";COLORS[13]="zwart";// max = 13 
       }
       else
       { // TO DO : TRANSLATION ?
       
           if(lang.equalsIgnoreCase("fr")){
              COLORS[0]="blanc";COLORS[1]="rouge";COLORS[2]="vert";COLORS[3]="bleu";
              COLORS[4]="orange";COLORS[5]="jaune";COLORS[6]="violet";COLORS[7]="vert pâle";
              COLORS[8]="bleu clair";COLORS[9]="cyan";COLORS[10]="marron";COLORS[11]="saumon";
              COLORS[12]="rose";COLORS[13]="noir";
           }
           else
           {
              if(lang.equalsIgnoreCase("de")){
                  COLORS[0]="weiß";COLORS[1]="rot";COLORS[2]="grun";COLORS[3]="blau";
                  COLORS[4]="orange";COLORS[5]="gelb";COLORS[6]="violett";COLORS[7]="hellgrün";
                  COLORS[8]="hellblau";COLORS[9]="cyan";COLORS[10]="braun";COLORS[11]="Lachsfarbig";
                  COLORS[12]="rosa";COLORS[13]="schwartz";
              }
              else
              {
                  COLORS[0]="white";COLORS[1]="red";COLORS[2]="green";COLORS[3]="blue";
                  COLORS[4]="orange";COLORS[5]="yellow";COLORS[6]="purple";COLORS[7]="lightgreen";
                  COLORS[8]="lightblue";COLORS[9]="cyan";COLORS[10]="brown";COLORS[11]="salmon";
                  COLORS[12]="pink";COLORS[13]="black";
              }
           }  
       }
    }

Here is the caller graph for this function:

void Clicktile.Determine_Range ( String  c,
String  type 
) [inline]

Definition at line 483 of file Clicktile.java.

                                                       {
       c=c.replace(':',',');c=c.replace(';',',');
       StringTokenizer q = new StringTokenizer(c, ",");
       String k;
       for(int p=0;p<2;p++){
           k=q.nextToken();
           if(p==0){
              if(type.equals("x")){ xmin = Integer.parseInt(k,10);}
              else { ymin = Integer.parseInt(k,10);}
           }
           else
           {
              if(type.equals("x")){ xmax = Integer.parseInt(k,10);}
              else { ymax = Integer.parseInt(k,10);}
           }
        }
    }

Here is the caller graph for this function:

int Clicktile.GetInternalColorCode ( String  c,
int  defaultcode 
) [inline]

Definition at line 407 of file Clicktile.java.

                                                               {
       int colorcode=defaultcode;
       if(c.equalsIgnoreCase("white")) colorcode=0;
       else 
       if(c.equalsIgnoreCase("red")) colorcode=1;
       else 
       if(c.equalsIgnoreCase("green")) colorcode=2;
       else 
       if(c.equalsIgnoreCase("blue")) colorcode=3;
       else 
       if(c.equalsIgnoreCase("orange")) colorcode=4;
       else
       if(c.equalsIgnoreCase("yellow")) colorcode=5;
       else
       if(c.equalsIgnoreCase("purple")) colorcode=6;
       else
       if(c.equalsIgnoreCase("lightgreen")) colorcode=7;
       else
       if(c.equalsIgnoreCase("lightblue")) colorcode=8;
       else
       if(c.equalsIgnoreCase("cyan")) colorcode=9;
       else
       if(c.equalsIgnoreCase("brown")) colorcode=10;
       else
       if(c.equalsIgnoreCase("salmon")) colorcode=11;
       else
       if(c.equalsIgnoreCase("pink")) colorcode=12;
       else
       if(c.equalsIgnoreCase("black")) colorcode=13;
       
       return colorcode;
    }

Here is the caller graph for this function:

void Clicktile.init ( ) [inline]

Definition at line 91 of file Clicktile.java.

                      {
       String c;
       xsize = getSize().width;ysize = getSize().height;
       c=getParameter("status");
       if(c != null && c.length()>0){
           if(c.equalsIgnoreCase("waiting")) status = true;
           else
           if(c.equalsIgnoreCase("done")) status = false;
       }
       
       c=getParameter("language");
       if(c != null && c.length()>0){
           Determine_Color_Names(c); // en: COLOR[0]="white" fr: COLOR[0]="blanc"
       }
       
       c=getParameter("background_color");
       if(c != null && c.length()>0){
           color[0]=GetInternalColorCode( c , 0); // 0 is default white background 
       }
       
       int obj=1;
       c=getParameter("square"+obj+"_color");
       while(c!=null && c.length()>0){ // translate param colors into internal color_array
           c=getParameter("square"+obj+"_color");
           if(c != null && c.length()>0){ 
              objects++; color[obj] = GetInternalColorCode( c , 13); // 13 default black
           }
           obj++;
       }
       
       c=getParameter("xrange");
       if(c != null && c.length()>0){Determine_Range( c , "x");}// determine the Xrange of the square ... xmin xmax
       
       c=getParameter("yrange");
       if(c != null && c.length()>0){Determine_Range( c , "y");}// determine the Yrange of the square ... ymin ymax
       
       Rx=Math.abs(xmax-xmin);Ry=Math.abs(ymax-ymin);
       MAX=Rx*Ry;
       x_rect=(int)xsize/Rx;y_rect=(int)ysize/Ry; // there are Rx squares in our square : per square x_rect pixels
       Clicktile = new int[MAX][MAX]; // Clicktile[0] does not exist: it is the background of canvas !!
       canvas = createImage(xsize,ysize);drawing = canvas.getGraphics();
       xcoords=new int[MAX][MAX];ycoords=new int[MAX][MAX];
       length=new int[MAX]; // how many squares per color
       for(int i=0;i<MAX;i++){// fill array with zero's
           length[i]=0;
       }
       for(int i=0; i<MAX;i++){
           for(int ii=0;ii<MAX;ii++){
              xcoords[ii][i]=0;// fill array with zero's
              ycoords[ii][i]=0;// fill array with zero's
           }
       }
       
       for(int x=0;x<MAX;x++){
           for(int y=0;y<MAX;y++){
              Clicktile[y][x] = color[0];// coloring the background color[0]
           }
       }

       // get the supplementary colors
       c=getParameter("colors");
       int maxcolors = 0 ; 
       if(c != null && c.length()>0){
          StringTokenizer q = new StringTokenizer(c, ",");
          maxcolors=q.countTokens() ;
       }
       int[] tmpcolors=new int[objects + 1 + maxcolors];
       if(c != null && c.length()>0){
          StringTokenizer q = new StringTokenizer(c, ",");
          maxcolors=q.countTokens() ;
          for( int p = 0 ; p<maxcolors ; p++){
           String  k=q.nextToken();
           tmpcolors[p]=GetInternalColorCode( k, 0 ) ; 
         }
   }
       // get the square
       tmpcolors[maxcolors]=color[0];
       for(obj=1 ; obj<=objects ;obj++){
           c=getParameter("square"+obj);
           int L=0;int coords=0;
           if( c!=null && c.length()>0){
              // 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
              c=c.replace(';',':');c=c.replace('@',':');c=c.replace(' ',':');
              StringTokenizer q1 = new StringTokenizer(c, ",");
              String k1;String k2;
              int array_x=0;int array_y=0;// array_x & array_y are array cell numbers
              coords=q1.countTokens();L=0;
              try {
                  for(int p=0;p<coords;p++){
                     k1=q1.nextToken();
                     //System.out.println("now "+k1);
                     StringTokenizer q2 = new StringTokenizer(k1, ":");
                     for(int s=0;s<2;s++){
                         k2=q2.nextToken();
                         if(s==0){
                            array_x=Integer.parseInt(k2,10);
                            array_x=(int)((array_x - xmin)*(xmax - xmin)/Rx);
                            xcoords[p][obj]=array_x;
                         }
                         if(s==1){
                            array_y=Integer.parseInt(k2,10);
                            // coordinates to square pixels
                            array_y=(int)(Ry + (array_y-ymin)*(ymax-ymin)/(-1*Ry));
                            ycoords[p][obj]=array_y;
                         }
                     }
                     tmpcolors[obj+maxcolors] = color[obj];
                     // give it the appropriate square_color
                     Clicktile[array_y][array_x]=color[obj];
                     L++;
                  }
                  length[obj]=L;
              } catch (Exception e){System.out.println("there is no square"+obj+"\n"+e);}
           }
       }
       used_colors = ListUniq(tmpcolors);//list uniq array of internal colors [int]

    c=getParameter("image");
       if (c!=null && c.length()>0) {
           try {url=new URL(c);}
           catch (MalformedURLException e) {url=null;}
           if(url!=null) bg=getImage(url);
           else bg=null;
       }
       else bg=null;

       c=getParameter("copy");
       if( c != null && c.length() > 0 ){ 
          StringTokenizer q = new StringTokenizer(c, ",");
          for( int p = 0 ; p<2 ; p++){
           String  k=q.nextToken();
           if(p==0){
                            copy_x=Integer.parseInt(k,10);
              }
              if(p==1){
                            copy_y=Integer.parseInt(k,10);
         }
   }
 }
       
       addMouseListener(
           new MouseAdapter(){
              public void mousePressed(MouseEvent e){
                  if(status){
                     dx = e.getX()/x_rect;
                  dy = e.getY()/y_rect;
                     int n = 0;boolean do_paint=true;
                     if(dx>=0 && dx<= Rx  && dy>=0 && dy<= Ry){
                         for(int obj=0;obj<=objects && do_paint ;obj++){
                            for(int p=0;p<length[obj] && do_paint ;p++){
                                if(xcoords[p][obj]==dx && ycoords[p][obj]==dy){
                                   //System.out.println("CLICKED ON GIVEN DRAWING !!");
                                   do_paint=false;
                                }  
                            }
                         }
                     }
                     if(do_paint){
                     // right mouse click changes color.
                       if( e.getButton() == MouseEvent.BUTTON3 ||  e.getButton() == MouseEvent.BUTTON2 ){
                            this_color++;
                            if(this_color > used_colors.length - 1){this_color=0;}
                         }
                        Clicktile[dy][dx] = used_colors[this_color];
                        repaint(); 
                     }
                 }
              }
           }
       );
       
       // get  point_color, point,line or polygon
       c=getParameter("point_color");
       if(c != null && c.length()>0){ point_color=GetInternalColorCode( c , 0);}
       c=getParameter("linewidth"); if( c != null && c.length() > 0 ){ linewidth = Integer.parseInt(c,10); }
       c=getParameter("point"); 
       if( c != null && c.length() > 0 ){ 
           Retreive_values_from_coordinates( c , 1 );
       }
       else
       {
           c=getParameter("segment"); 
           if( c != null && c.length() > 0 ){ 
              Retreive_values_from_coordinates( c , 2 ); 
           }
           else
           {
              c=getParameter("line"); 
              if( c != null && c.length() > 0 ){ 
                  Retreive_values_from_coordinates( c , 3 ); 
              }
              else
              {
                  c=getParameter("polygon"); 
                  if( c != null && c.length() > 0 ){ 
                     Retreive_values_from_coordinates( c , 4 ); 
                  }
                  else
                  {
                     System.out.println("NO SYMMETRY LINE,SEGMENT,POINT or POLY DEFINED");
                  }
              }
           }
       }
    }

Here is the call graph for this function:

int [] Clicktile.ListUniq ( int[]  array) [inline]

Definition at line 536 of file Clicktile.java.

                                      {
       Arrays.sort(array);
       int k = 0;
        for (int i = 0; i < array.length; i++){
           if (i > 0 && array[i] == array[i -1] )
           continue;
           array[k++] = array[i];
       }
       int [] unique = new int[k];
        System.arraycopy(array, 0, unique, 0, k);
       return unique;
    }

Here is the caller graph for this function:

void Clicktile.paint ( Graphics  g) [inline]

Definition at line 297 of file Clicktile.java.

                                 {
        if(bg!=null) g.drawImage(bg,copy_x,copy_y,this);
        drawing.setColor(Color.white);
        drawing.fillRect(0,0,xsize,ysize);
        int k;
       for(int xr = 0;xr < Rx;xr++){
           for(int yr = 0;yr < Ry;yr++){
              k=Clicktile[yr][xr];
              drawing.setColor(new Color(palette[k][0],palette[k][1],palette[k][2])); // this is the student "drawing"
              drawing.fill3DRect(x_rect*xr,y_rect*yr,x_rect,y_rect,true); // use "3D effect"
           }
       }
       if(TYPE != 0){drawing.setColor(new Color(palette[point_color][0],palette[point_color][1],palette[point_color][2]));}
       if(TYPE == 1){// several points
           for(int p = 0; p < xpoints.length ; p++){
              drawing.fillOval( (int)(xpoints[p] - 0.5*linewidth) , (int)(ypoints[p] -0.5*linewidth) , linewidth,linewidth );
              //System.out.println("points "+xpoints[p]+":"+ypoints[p]);
           }
       }
       else if(TYPE == 2){// several lines
           for( int p = 0 ; p< xpoints.length -1 ; p=p+2){
              drawing.drawLine( xpoints[p] , ypoints[p], xpoints[p+1], ypoints[p+1]);
              //System.out.println("segments "+xpoints[p]+":"+ypoints[p]+"-------"+xpoints[p+1]+":"+ypoints[p+1]);
           }
       }
       else if(TYPE == 3){//for now the same as TYPE = 2
           for( int p = 0 ; p< xpoints.length -1 ; p=p+2){
              drawing.drawLine( xpoints[p] , ypoints[p], xpoints[p+1], ypoints[p+1]);
           }
       }
       else if(TYPE ==  4){
           int lim=xpoints.length - 1; // improvised polygon...non-filled
              for(int p = 0 ;  p < lim  ; p++){
                  drawing.drawLine(xpoints[p], ypoints[p], xpoints[p+1],ypoints[p+1]);
              }
              drawing.drawLine(xpoints[lim], ypoints[lim], xpoints[0],ypoints[0]);
       }
       g.drawImage(canvas,0,0,this); // draw this square on canvas

     }

Here is the caller graph for this function:

String Clicktile.ReadApplet ( ) [inline]

Definition at line 363 of file Clicktile.java.

                              {// public function to be issued by Javascript...and send to WIMS
       String c=getParameter("return_all_objects");
       boolean return_all=false;
       boolean do_print=true;
       if(c.equalsIgnoreCase("yes") || c.equals("1")){return_all=true;} 
       String reply="";boolean fnd=false;int repx=0;int repy=0;int k;String K="";
       for(int x=0; x<Rx; x++){
           for(int y=0;y<Ry;y++){
              k=Clicktile[y][x];
              // back to coordinates
              repx=(int)(xmin+x*Rx/(xmax - xmin));
              repy=(int)(Ry + (y - ymin)*(ymax-ymin)/(-1*Ry));
              if(return_all){ // <param name="return_all" value="0">
                  if( k != color[0] ){// no background
                     K=COLORS[k];
                     if(fnd){ reply=reply+","+K+"@"+repx+":"+repy; }
                     else { fnd=true; reply=K+"@"+repx+":"+repy; }
                  }
              }
              else
              {  // <param name="return_all" value="1">
                  do_print=true;
                  for(int obj=0;obj<=objects;obj++){
                     for(int p=0;p<length[obj];p++){
                         if(xcoords[p][obj]==x && ycoords[p][obj]==y){// exclude the square from params stored in xcoords[] ycoords[]
                            do_print=false;
                            //System.out.println("will not print ("+x+":"+y+") with color="+color[k]);
                         }
                     }
                  }
                  if(do_print){
                     if( k != color[0] ){// no background
                         K=COLORS[k];
                         if(fnd){ reply=reply+","+K+"@"+repx+":"+repy; }
                         else { fnd=true; reply=K+"@"+repx+":"+repy; }
                     }
                  }
              }
           }
       }
       if(reply.length() == 0){reply="ERROR: YOU DID NOT CLICK ANYTHING";}
       return reply;
    }
void Clicktile.Retreive_values_from_coordinates ( String  c,
int  type 
) [inline]

Definition at line 450 of file Clicktile.java.

                                                                      {
       // typical value="-5:5,-4;4,-3:3"
       TYPE=type;
       c=c.replace(';',':');c=c.replace('@',':');c=c.replace(' ',':');
       StringTokenizer q1 = new StringTokenizer(c, ",");
       String k1;String k2;
       int m0=q1.countTokens();
       xpoints=new int[m0];
       ypoints=new int[m0];
       int tmp;int m1;boolean flipflop=true;
       for(int p=0;p<m0;p++){
           k1=q1.nextToken();
           StringTokenizer q2 = new StringTokenizer(k1, ":");
           m1 = q2.countTokens();
           for(int s=0; s<m1 ; s++){
              k2=q2.nextToken();
              if(flipflop){
                  try{ tmp = Integer.parseInt(k2,10); xpoints[p] = X_ConvertToInternalCoordinates(tmp); }
                  catch(Exception e){System.out.println("ERROR\n"+e);}
                  flipflop=false;
              }
              else
              {
                  try{ tmp = Integer.parseInt(k2,10); ypoints[p] = Y_ConvertToInternalCoordinates(tmp); }
                  catch(Exception e){System.out.println("ERROR\n"+e);}
                  flipflop=true;
              }
           }
       }


    }

Here is the call graph for this function:

Here is the caller graph for this function:

void Clicktile.run ( ) [inline]

Definition at line 349 of file Clicktile.java.

                    {
      while(thread != null){
         try{
            Thread.sleep(100);
         }
         catch (InterruptedException e){
         }
      }
   }
void Clicktile.start ( ) [inline]

Definition at line 338 of file Clicktile.java.

                      {
      if(thread == null){
         thread = new Thread(this);
         thread.start();
      }
   }
void Clicktile.stop ( ) [inline]

Definition at line 345 of file Clicktile.java.

                     {
      thread =  null;
   }
void Clicktile.update ( Graphics  g) [inline]

Definition at line 359 of file Clicktile.java.

                                   {
      paint( g ) ;
   }

Here is the call graph for this function:

Definition at line 440 of file Clicktile.java.

                                                    {
       int X = (int)(x_rect*(x - xmin)*(xmax - xmin)/Rx);
       return X;
    }

Here is the caller graph for this function:

Definition at line 445 of file Clicktile.java.

                                                    {
       int Y = (int)(y_rect*(Ry + (y - ymin)*(ymax - ymin)/(-1*Ry)));
       return Y;
    }

Here is the caller graph for this function:


Member Data Documentation

Image Clicktile.bg [package]

Definition at line 89 of file Clicktile.java.

Image Clicktile.canvas [package]

Definition at line 76 of file Clicktile.java.

int Clicktile.Clicktile[][] [package]

Definition at line 74 of file Clicktile.java.

int [] Clicktile.color = new int[max] [package]

Definition at line 83 of file Clicktile.java.

String Clicktile.COLORS[] = new String[max]

Definition at line 85 of file Clicktile.java.

int Clicktile.copy_x = 0 [package]

Definition at line 89 of file Clicktile.java.

int Clicktile.copy_y = 0 [package]

Definition at line 89 of file Clicktile.java.

Graphics Clicktile.drawing [package]

Definition at line 76 of file Clicktile.java.

int Clicktile.dx [package]

Definition at line 75 of file Clicktile.java.

int Clicktile.dy [package]

Definition at line 75 of file Clicktile.java.

String Clicktile.language = "en" [package]

Definition at line 87 of file Clicktile.java.

int [] Clicktile.length [package]

Definition at line 84 of file Clicktile.java.

int Clicktile.linewidth = 5 [package]

Definition at line 86 of file Clicktile.java.

int Clicktile.MAX [package]

Definition at line 74 of file Clicktile.java.

final int Clicktile.max = palette.length [package]

Definition at line 82 of file Clicktile.java.

int Clicktile.objects = 0 [package]

Definition at line 84 of file Clicktile.java.

int Clicktile.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}} [package]

Definition at line 81 of file Clicktile.java.

int Clicktile.point_color = 0 [package]

Definition at line 86 of file Clicktile.java.

int Clicktile.Rx [package]

Definition at line 80 of file Clicktile.java.

int Clicktile.Ry [package]

Definition at line 80 of file Clicktile.java.

final int Clicktile.serialVersionUID = 1 [static, private]

Definition at line 73 of file Clicktile.java.

Definition at line 87 of file Clicktile.java.

int Clicktile.this_color = 0 [package]

Definition at line 88 of file Clicktile.java.

Thread Clicktile.thread = null [package]

Definition at line 75 of file Clicktile.java.

int Clicktile.TYPE = 0 [package]

Definition at line 86 of file Clicktile.java.

URL Clicktile.url [package]

Definition at line 89 of file Clicktile.java.

int [] Clicktile.used_colors [package]

Definition at line 88 of file Clicktile.java.

int Clicktile.x_rect [package]

Definition at line 79 of file Clicktile.java.

int [][] Clicktile.xcoords [package]

Definition at line 84 of file Clicktile.java.

int Clicktile.xmax = 10 [package]

Definition at line 77 of file Clicktile.java.

int Clicktile.xmin = -10 [package]

Definition at line 77 of file Clicktile.java.

int [] Clicktile.xpoints [package]

Definition at line 86 of file Clicktile.java.

int Clicktile.xsize [package]

Definition at line 78 of file Clicktile.java.

int Clicktile.y_rect [package]

Definition at line 79 of file Clicktile.java.

int [][] Clicktile.ycoords [package]

Definition at line 84 of file Clicktile.java.

int Clicktile.ymax = 10 [package]

Definition at line 77 of file Clicktile.java.

int Clicktile.ymin = -10 [package]

Definition at line 77 of file Clicktile.java.

int [] Clicktile.ypoints [package]

Definition at line 86 of file Clicktile.java.

int Clicktile.ysize [package]

Definition at line 78 of file Clicktile.java.


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