[LON-CAPA-cvs] cvs: loncom(1) /homework randomlabel.pm

sakharuk lon-capa-cvs@mail.lon-capa.org
Thu, 07 Feb 2002 16:45:06 -0000


sakharuk		Thu Feb  7 21:45:06 2002 EDT

  Added files:                 (Branch: 1)
    /loncom/homework	randomlabel.pm 
  Log:
  redoing from 1.11
  
  

Index: loncom/homework/randomlabel.pm
+++ loncom/homework/randomlabel.pm
# The LearningOnline Network with CAPA
# random labelling tool
# 7/20/2001 Isaac Tsai
# 8/10/2001 Isaac Tsai
# SYNTAX:
# <randomlabel bgimg=URL code=JAVACLASS codebase=URL width=12 height=45>
#    <labelgroup name=GroupOne type=img>
#      <location x=123 y=456 />
#      <location x=321 y=654 />
#      <location x=213 y=546 />
#      <label>IMG-URL</label>
#      <label>IMG-URL</label>
#      <label>IMG-URL</label>
#    </labelgroup>
#    <labelgroup name=GroupTwo type=text>
#      <location x=12 y=45 />
#      <location x=32 y=65 />
#      <location x=21 y=54 />
#      <label>TEXT</label>
#      <label>TEXT</label>
#      <label>TEXT</label>
#    </labelgroup>
#   </randomlabel>
#  ===========================================
#    location (123,456): $GroupOne[1] = ...
#             (321,654): $GroupOne[2] = ...
#             (213,546): $GroupOne[3] = ...
#    location (12,45)  : $GroupOne[1] = ...
#             (321,654): $GroupOne[2] = ...
#             (213,546): $GroupOne[3] = ...
#  ===========================================
package Apache::randomlabel;
use strict;

sub BEGIN {
  &Apache::lonxml::register('Apache::randomlabel',('randomlabel','labelgroup','location','label'));
}

sub start_randomlabel {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  my $result='';
  my $bgimg= &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
  my $code = &Apache::lonxml::get_param('code',$parstack,$safeeval);
  my $codebase = &Apache::lonxml::get_param('codebase',$parstack,$safeeval);
  my $w= &Apache::lonxml::get_param('width',$parstack,$safeeval);
  my $h= &Apache::lonxml::get_param('height',$parstack,$safeeval);
  
  $result.="<applet code=$code codebase=$codebase width=\"$w\" height=\"$h\">";
  $result.="<param name=\"bgimg\" value=\"$bgimg\">";
  if ($target eq 'edit') {
  }
  if ($target eq 'modified') {
  }
  return $result;
}

sub end_randomlabel {
  return '</applet><BR />';
}

sub start_labelgroup {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  my $result='';
  my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
  $Apache::randomlabel::groupname=$name;
  @Apache::randomlabel::xcoord = ();
  @Apache::randomlabel::ycoord = ();
  @Apache::randomlabel::label_arr  = ();
  return '';
}

# begin to assign labels to locations
sub end_labelgroup {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  my $gname = $Apache::randomlabel::groupname;
  my $count = $#Apache::randomlabel::label_arr + 1;
  my $code;
  my $out;
  my $label;
  my $x;
  my $y;
  my $text= "<param name=\"count\" value=\"$count\">";

  my @idx_arr = (0 .. $#Apache::randomlabel::label_arr);
  &Apache::structuretags::shuffle(\@idx_arr);
  for(0 .. $#Apache::randomlabel::label_arr) {
    $label = "$Apache::randomlabel::label_arr[ $idx_arr[$_] ]";
    $x = pop @Apache::randomlabel::xcoord;
    $y = pop @Apache::randomlabel::ycoord;
    $text .= "<param name=\"LB". $_ . "\" value=\"$label\">";
    $text .= "<param name=\"X" . $_ . "\" value=\"$x\"> ";
    $text .= "<param name=\"Y" . $_ . "\" value=\"$y\">";
    $code = "push(\@$gname, $label);" ;
    # print("CODE=$code");
    # $out=Apache::run::run($code,$safeeval,$$parstack[$#$parstack]);
    $out=Apache::run::run($code,$safeeval);
  }
  
  return $text;
}

sub start_location {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  my $x= &Apache::lonxml::get_param('x',$parstack,$safeeval);
  my $y= &Apache::lonxml::get_param('y',$parstack,$safeeval);
  
  push(@Apache::randomlabel::xcoord,$x);
  push(@Apache::randomlabel::ycoord,$y); 
  return '';
}

sub end_location {
  return '';
}

sub start_label {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  my $ltext=&Apache::lonxml::get_all_text("/label",$$parser[$#$parser]);

  push(@Apache::randomlabel::label_arr,$ltext);
  return '';
}

sub end_label {
  return '';
}



1;
__END__