Back to index

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

List of all members.

Public Member Functions

void init ()
String ReadApplet (String arg)
boolean point_near_line (int lx1, int ly1, int lx2, int ly2, int px, int py, String text)
void start ()
void stop ()
void destroy ()

Static Public Member Functions

static String replace (String source, String pattern, String replace)
static void main (String argv[])

Public Attributes

String t_line = "Line"
String t_arrow = "Arrow"
String t_rectangle = "Rectangle"
String t_ellipse = "Ellipse"
String t_text = "Text"
String t_circle = "Circle"
String t_destroy = "Delete"
String t_move = "Move"

Package Attributes

Diagram diagram
DiagramControls controls
DiagramDisplay display
MessageArea message
EventConsumer current_event_consumer

Static Package Attributes

static int xsize = 640
static int ysize = 480
static int ygrid = 50
static Color bgcolor = new Color(250,250,250)
static Color textcolor = new Color(255,0,0)
static Color drawcolor = new Color(150,0,250)
static float thickness = 2.0f
static int penfontsize = 16
static String fontfamily = "Helvetica"
static Font penfont = new Font(fontfamily, Font.BOLD, penfontsize)
static Font zoomfont = new Font(fontfamily, Font.BOLD,penfontsize+6)
static Font messagefont = new Font(fontfamily, Font.BOLD,16)
static String t_press = "Press return to finish the text"
static boolean textalign = false
static int textcounter = 0
static int linecounter = 0
static boolean original = false

Detailed Description

Definition at line 77 of file KansBoom.java.


Member Function Documentation

void KansBoom.destroy ( ) [inline]

Definition at line 484 of file KansBoom.java.

                          {
    }
void KansBoom.init ( ) [inline]

Definition at line 112 of file KansBoom.java.

                       {
       String param;
       param = getParameter("language");
       if(param != null) {
           if(param.equalsIgnoreCase("nl")){
              t_line="lijn";
              t_arrow="pijl";
              t_rectangle="rechthoek";
              t_ellipse="ellips";
              t_text="tekst";
              t_circle="cirkel";
              t_destroy="wissen";
              t_move="verplaatsen";
              t_press="Druk op enter als de tekst klaar is";
           }
           if(param.equalsIgnoreCase("de")){
              t_line="Linie";
              t_arrow="Pfeil";
              t_rectangle="Rechteck";
              t_ellipse="Ellipse";
              t_text="Text";
              t_circle="Kreis";
              t_destroy="löschen";
              t_move="verlagern";
              t_press="Drücken Sie auf \"Eingabe\" am Ende des Textes";
           }
           if(param.equalsIgnoreCase("fr")){
              t_line="droite";
              t_arrow="flèche";
              t_rectangle="rectangle";
              t_ellipse="ellips";
              t_text="texte";
              t_circle="cercle ";
              t_destroy="effacer";
              t_move="déplacer";
              t_press="Press return to finish the text";
           }
       }
       param = getParameter("penfontsize");
       if(param != null) {penfontsize=Integer.parseInt(param,10); penfont= new Font("Helvetica", Font.BOLD, penfontsize);}
       param = getParameter("penfontfamily");
       if(param != null) {penfont= new Font(param, Font.BOLD, penfontsize);}
       param = getParameter("penfontstyle");
       if(param != null) {
           if(param.equalsIgnoreCase("bold")){penfont= new Font(param, Font.BOLD , penfontsize);}
           else if(param.equalsIgnoreCase("italic")){penfont= new Font(param, Font.ITALIC , penfontsize);}
           else if(param.equalsIgnoreCase("plain")){penfont= new Font(param, Font.PLAIN , penfontsize);}
       }
       param = getParameter("penthickness");
       if(param != null) {thickness=Float.parseFloat(param);}
       param = getParameter("xsize");
       if(param != null) {xsize=Integer.parseInt(param,10);}
       param = getParameter("ysize");
       if(param != null) {ysize=Integer.parseInt(param,10);}
       param = getParameter("textlines");
       if(param != null) {ygrid=Integer.parseInt(param,10);}
       param = getParameter("textalign");
       if(param == null || param.length()==0){original=true;}else{original=false;if(param.equalsIgnoreCase("vertical")){textalign=true;}else{textalign=false;}}
       resize(xsize,ysize);
       param=getParameter("bgcolor"); // Background color of inputfield "input"
       if (param != null && param.length()>0){
           int R1=255;int G1=255;int B1=255;
           param=param.replace(':',',');param=param.replace(';',',');
           StringTokenizer q = new StringTokenizer(param, ",");
           String k;int rgb;
           for( int a=0; a<3 ; a++){
              k=q.nextToken();
              rgb=Integer.parseInt(k, 10);
              if(rgb<0){rgb=0;}
              if(rgb>255){rgb=255;}
              if(a == 0){R1 = rgb;}
              else if(a == 1){G1 = rgb;}
              else if(a == 2){B1 = rgb;}
           }
           bgcolor=new Color(R1,G1,B1);
       }
       param=getParameter("textcolor"); // Background color of inputfield "input"
       if (param != null && param.length()>0){
           int R2=255;int G2=0;int B2=0;
           param=param.replace(':',',');param=param.replace(';',',');
           StringTokenizer q = new StringTokenizer(param, ",");
           String k;int rgb;
           for( int a=0; a<3 ; a++){
              k=q.nextToken();
              rgb=Integer.parseInt(k, 10);
              if(rgb<0){rgb=0;}
              if(rgb>255){rgb=255;}
              if(a == 0){R2 = rgb;}
              else if(a == 1){G2 = rgb;}
              else if(a == 2){B2 = rgb;}
           }
           textcolor=new Color(R2,G2,B2);
       }

       param=getParameter("drawcolor"); // Background color of inputfield "input"
       if (param != null && param.length()>0){
           int R3=255;int G3=255;int B3=0;
           param=param.replace(':',',');param=param.replace(';',',');
           StringTokenizer q = new StringTokenizer(param, ",");
           String k;int rgb;
           for( int a=0; a<3 ; a++){
              k=q.nextToken();
              rgb=Integer.parseInt(k, 10);
              if(rgb<0){rgb=0;}
              if(rgb>255){rgb=255;}
              if(a == 0){R3 = rgb;}
              else if(a == 1){G3 = rgb;}
              else if(a == 2){B3 = rgb;}
           }
           drawcolor=new Color(R3,G3,B3);
       }
       
       diagram = new Diagram();
       diagram.editor = this;
       // no idea how to tell this class that the names are passed on as params in init...
       add(controls = new DiagramControls(this ,t_line,t_arrow,t_rectangle,t_ellipse,t_text,t_circle,t_destroy,t_move));
       add(display = new DiagramDisplay(this ,penfont,thickness,textcolor,drawcolor,zoomfont));
       current_event_consumer = controls;
       
    }

Here is the caller graph for this function:

static void KansBoom.main ( String  argv[]) [inline, static]

Definition at line 487 of file KansBoom.java.

                                           {
       /* This more-or-less replicates what happens when we  are run as an applet. */
       Frame f = new Frame();
       KansBoom d = new KansBoom();
       d.init();
       d.start();
       f.add("Center", d);
       f.show();
    }

Here is the call graph for this function:

boolean KansBoom.point_near_line ( int  lx1,
int  ly1,
int  lx2,
int  ly2,
int  px,
int  py,
String  text 
) [inline]

Definition at line 442 of file KansBoom.java.

                                                                                                    {
       // measure distance from point...eg text to a line ,describe by the two end-points
       // close enough ? is 4 times the fontsize in pixels: so the margin would be 8xfm ??
       // very likely to interfere with sloppy drawings, expected from pupils...
       FontMetrics fm =getFontMetrics(penfont);
       int w = fm.stringWidth(text);
       w=(int)(Math.ceil(w/2));
       //System.out.println("x-center begin = "+px);
       px=px+w;// px is now the x-center of the string
       //System.out.println("x-center  = "+px);
       int distance;double ys;double xs;
       if( (py > (ly1 - w) && py < (ly2 + w)) || (py > (ly2 - w) && py < (ly1 + w)) ){
           if( (px > (lx1 - 2*w) && px < (lx2 + 2*w)) || ( px > (lx2 - 2*w) && px < (lx1 + 2*w)) ){
              // the point is in the rect x1y1,x2y2
              if( (ly2 - ly1) == 0){
                  System.out.println("Horizontal line "); return false;
              }
              else
              {
                  if( (lx2 - lx1) == 0 ){
                     System.out.println("Vertical line "); return false;
                  }
                  else
                  {  
                     ys = (double)(((double)( (px-lx1)*(ly2-ly1)*(lx2-lx1)+(ly2-ly1)*(ly2-ly1)*py+(lx2-lx1)*(lx2-lx1)*ly1 ))/((double)((lx2-lx1)*(lx2-lx1)+(ly2-ly1)*(ly2-ly1))));
                     xs = (double)((double)(px))+ys*((double)( (double)(ly1-ly2))/((double)(lx2-lx1))) + ((double)py)*((double)( (double)(ly2-ly1))/((double)(lx2-lx1)));
                     distance=(int)(Math.sqrt( (ys - py)*(ys - py) + (xs - px)*(xs - px) ));
                     if(distance < 2*w ){return true;}else{return false;}
                  }
              }
           }
       }
       return false;
    }

Here is the caller graph for this function:

String KansBoom.ReadApplet ( String  arg) [inline]

Definition at line 234 of file KansBoom.java.

                                        {
       String reply="";
       if(arg.equals("1")){
           // we sort the text, that should depict a probability tree
           // if textaling=true the orientation of the drawing is vertical [left to right ,top to bottom]
           //        a
           //     b     c
           //  d    e f    g 
           // becomes: a \n b,c \n d,e,f,g 
           // else we expect a horizontal probability tree [top to bottom, left to right]
           //       d
           //     b  
           //       e
           //  a     
           //       f
           //     c  
           //       g 
           // becomes: a \n b,c \n d,e,f,g 
           String line_analysis="";
           int[] text_x=new int[textcounter];
           int[] text_y=new int[textcounter];
           int[] line_x1=new int[linecounter];
           int[] line_y1=new int[linecounter];
           int[] line_x2=new int[linecounter];
           int[] line_y2=new int[linecounter];
           String[] tekst=new String[textcounter];
           int real_text_length=0;String tmp="";
           int real_line_length=0;int x1;int x2;int y1;int y2;
           for(Enumeration e = diagram.elements(); e.hasMoreElements(); ){                                                                            
              DiagramItem item = (DiagramItem)e.nextElement();
              if(item.specify_line_x1() != -1){
                  x1=item.specify_line_x1();
                  y1=item.specify_line_y1();
                  x2=item.specify_line_x2();
                  y2=item.specify_line_y2();
                  if( x1 != x2 && y1 != y2 ){// avoid line-dots to be send as lines/branches
                     line_x1[real_line_length] = x1;
                     line_y1[real_line_length] = y1;
                     line_x2[real_line_length] = x2;
                     line_y2[real_line_length] = y2;
                     real_line_length++;
                  }
              }
              if(item.specify_text() != null){
                  tmp = item.specify_text();
                  // remove the forgotten '_' and we can't use komma's in the reply...replace them by points ?
                  tmp =replace(tmp,"_"," ");
                  tekst[real_text_length] =replace(tmp,",",".");
                  text_x[real_text_length] = item.specify_text_x();
                  text_y[real_text_length] = item.specify_text_y();
                  real_text_length++;
              }
           }
           boolean online=false;
           String[] isonline=new String[real_line_length];boolean found=false;
           int items=0;
           for(int s=0;s<real_line_length;s++){
              found=false;items=0;
              for(int r=0;r<real_text_length;r++){
                  online=point_near_line(line_x1[s],line_y1[s],line_x2[s],line_y2[s],text_x[r],text_y[r],tekst[r]);
                  //System.out.println("tekst "+tekst[r]+" ligt op lijn "+s+" ? : "+online);
                  if(online){
                     found=true;
                     items++;
                     if(isonline[s] == null){
                         isonline[s]=tekst[r];
                     }
                     else
                     {
                         isonline[s]=tekst[r]+","+isonline[s];               
                     }
                  }
              }
              if(!found){
                  isonline[s]="error_1";//unused_line_error
              }
// this gives too many user_errors jm.evers 18/1/2009          
//            else
//            {
//                if(items==1){
//                   isonline[s]=isonline[s]+",error_2";//too_few_items_per_line
//                }
//                else
//                {
//                   if(items>3){
//                       isonline[s]=isonline[s]+",error_3";}//too_many_items_per_line
//                }
//            }
           }
           
           for(int s=0;s<real_line_length;s++){
              //System.out.println("line"+s+" : "+isonline[s]);
              line_analysis=isonline[s]+"\n"+line_analysis;
           }
           
           if(real_text_length != 2*real_line_length){
              if(real_text_length> 2*real_line_length){
                  line_analysis=line_analysis+"\nerror_4";//inbalance_too_few_lines
              }
              else
              {
                  line_analysis=line_analysis+"\nerror_5";//inbalance_too_many_lines
              }
           }
           if(real_text_length == 0){line_analysis=line_analysis+"\nerror_6";}//text_missing
           if(real_line_length == 0){line_analysis=line_analysis+"\nerror_7";}//lines_missing
           
           boolean nog_meer = true;int i=0;int temp_x;int temp_y;String temp_txt;
           nog_meer = true;
           String[] sameline = new String[real_text_length];
           if(textalign){//horizonal probability tree
              while (nog_meer) {
                  nog_meer = false;
                  for ( i=0; i<real_text_length-1; i++ ){
                     if ( text_y[i] < text_y[i+1] ){ sameline[i]="\n";}
                     if ( text_y[i] > text_y[i+1] ){
                         temp_y = text_y[i]; text_y[i] = text_y[i+1];  text_y[i+1] = temp_y;
                         temp_x = text_x[i];  text_x[i] = text_x[i+1];  text_x[i+1] = temp_x;
                         temp_txt = tekst[i];  tekst[i] = tekst[i+1];  tekst[i+1] = temp_txt;
                         nog_meer = true;
                         sameline[i]="\n";
                     }
                     if ( text_y[i] == text_y[i+1] ){
                         sameline[i]=",";
                         if( text_x[i] > text_x[i+1] ){
                            temp_y = text_y[i]; text_y[i] = text_y[i+1];  text_y[i+1] = temp_y;
                             temp_x = text_x[i]; text_x[i] = text_x[i+1];  text_x[i+1] = temp_x;
                             temp_txt = tekst[i];  tekst[i] = tekst[i+1];  tekst[i+1] = temp_txt;
                            nog_meer = true;
                         }
                     }
                  }
              }
           }
           else
           {//vertical probability tree
              while (nog_meer) {
                  nog_meer = false;
                  for ( i=0; i<real_text_length-1; i++ ){
                     if ( text_x[i] < text_x[i+1] ){ sameline[i]="\n";}
                     if ( text_x[i] > text_x[i+1] ){
                         temp_y = text_y[i]; text_y[i] = text_y[i+1];  text_y[i+1] = temp_y;
                         temp_x = text_x[i];  text_x[i] = text_x[i+1];  text_x[i+1] = temp_x;
                         temp_txt = tekst[i];  tekst[i] = tekst[i+1];  tekst[i+1] = temp_txt;
                         nog_meer = true;
                         sameline[i]="\n";
                     }
                     if ( text_x[i] == text_x[i+1] ){
                         sameline[i]=",";
                         if( text_y[i] > text_y[i+1] ){
                            temp_y = text_y[i]; text_y[i] = text_y[i+1];  text_y[i+1] = temp_y;
                             temp_x = text_x[i]; text_x[i] = text_x[i+1];  text_x[i+1] = temp_x;
                             temp_txt = tekst[i];  tekst[i] = tekst[i+1];  tekst[i+1] = temp_txt;
                            nog_meer = true;
                         }
                     }
                  }
              }
           
           }

           for(i=0;i<real_text_length;i++){
              if(sameline[i] == null){sameline[i]="\n";}
              //reply=reply+tekst[i]+","+text_x[i]+","+text_y[i]+sameline[i];
              reply=reply+tekst[i]+sameline[i];
           }
           reply=reply+"\n@\n"+line_analysis;
       }
       else
       {
           //alldata...no special sorting of the text
           for(Enumeration e = diagram.elements(); e.hasMoreElements(); ){                                                                            
              DiagramItem item = (DiagramItem)e.nextElement();
              reply=reply+item.describe()+"\n";
           }
        }

       return reply;
    }

Here is the call graph for this function:

static String KansBoom.replace ( String  source,
String  pattern,
String  replace 
) [inline, static]

Definition at line 415 of file KansBoom.java.

                                                                               {
       if (source!=null){
           final int len = pattern.length();
           StringBuffer sb = new StringBuffer();
           int found = -1;
           int start = 0;
           while( (found = source.indexOf(pattern, start) ) != -1){
              sb.append(source.substring(start, found));
              sb.append(replace);
              start = found + len;
           }
           sb.append(source.substring(start));
           return sb.toString();
       }
        else return "";
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void KansBoom.start ( ) [inline]

Definition at line 478 of file KansBoom.java.

                        {
    }

Here is the caller graph for this function:

void KansBoom.stop ( ) [inline]

Definition at line 481 of file KansBoom.java.

                       {
    }

Member Data Documentation

Color KansBoom.bgcolor = new Color(250,250,250) [static, package]

Definition at line 88 of file KansBoom.java.

Definition at line 79 of file KansBoom.java.

Definition at line 82 of file KansBoom.java.

Definition at line 78 of file KansBoom.java.

Definition at line 80 of file KansBoom.java.

Color KansBoom.drawcolor = new Color(150,0,250) [static, package]

Definition at line 90 of file KansBoom.java.

String KansBoom.fontfamily = "Helvetica" [static, package]

Definition at line 93 of file KansBoom.java.

int KansBoom.linecounter = 0 [static, package]

Definition at line 108 of file KansBoom.java.

Definition at line 81 of file KansBoom.java.

Font KansBoom.messagefont = new Font(fontfamily, Font.BOLD,16) [static, package]

Definition at line 96 of file KansBoom.java.

boolean KansBoom.original = false [static, package]

Definition at line 109 of file KansBoom.java.

Font KansBoom.penfont = new Font(fontfamily, Font.BOLD, penfontsize) [static, package]

Definition at line 94 of file KansBoom.java.

int KansBoom.penfontsize = 16 [static, package]

Definition at line 92 of file KansBoom.java.

String KansBoom.t_arrow = "Arrow"

Definition at line 98 of file KansBoom.java.

String KansBoom.t_circle = "Circle"

Definition at line 102 of file KansBoom.java.

String KansBoom.t_destroy = "Delete"

Definition at line 103 of file KansBoom.java.

String KansBoom.t_ellipse = "Ellipse"

Definition at line 100 of file KansBoom.java.

String KansBoom.t_line = "Line"

Definition at line 97 of file KansBoom.java.

String KansBoom.t_move = "Move"

Definition at line 104 of file KansBoom.java.

String KansBoom.t_press = "Press return to finish the text" [static, package]

Definition at line 105 of file KansBoom.java.

String KansBoom.t_rectangle = "Rectangle"

Definition at line 99 of file KansBoom.java.

String KansBoom.t_text = "Text"

Definition at line 101 of file KansBoom.java.

boolean KansBoom.textalign = false [static, package]

Definition at line 106 of file KansBoom.java.

Color KansBoom.textcolor = new Color(255,0,0) [static, package]

Definition at line 89 of file KansBoom.java.

int KansBoom.textcounter = 0 [static, package]

Definition at line 107 of file KansBoom.java.

float KansBoom.thickness = 2.0f [static, package]

Definition at line 91 of file KansBoom.java.

int KansBoom.xsize = 640 [static, package]

Definition at line 85 of file KansBoom.java.

int KansBoom.ygrid = 50 [static, package]

Definition at line 87 of file KansBoom.java.

int KansBoom.ysize = 480 [static, package]

Definition at line 86 of file KansBoom.java.

Font KansBoom.zoomfont = new Font(fontfamily, Font.BOLD,penfontsize+6) [static, package]

Definition at line 95 of file KansBoom.java.


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