version 1.2, 2001/08/29 19:48:26
|
version 1.3, 2001/08/30 19:39:12
|
Line 1
|
Line 1
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# random labelling tool |
# random labelling tool |
# 7/20/2001 Isaac Tsai |
# 7/20/2001 Isaac Tsai, initial syntax |
# 8/10/2001 Isaac Tsai |
# 8/10/2001 Isaac Tsai, |
|
# 8/30/2001 Isaac Tsai, |
# SYNTAX: |
# SYNTAX: |
# <randomlabel bgimg=URL code=JAVACLASS codebase=URL width=12 height=45> |
# <randomlabel bgimg=URL code=JAVACLASS codebase=URL width=12 height=45> |
# <labelgroup name=GroupOne type=image> |
# <labelgroup name=GroupOne type=image> |
Line 16
|
Line 17
|
# <location x=12 y=45 /> |
# <location x=12 y=45 /> |
# <location x=32 y=65 /> |
# <location x=32 y=65 /> |
# <location x=21 y=54 /> |
# <location x=21 y=54 /> |
# <label>TEXT</label> |
# <label>TEXT-1</label> |
# <label>TEXT</label> |
# <label>TEXT-2</label> |
# <label>TEXT</label> |
# <label>TEXT-3</label> |
# </labelgroup> |
# </labelgroup> |
# </randomlabel> |
# </randomlabel> |
# =========================================== |
# =========================================== |
# location (123,456): $GroupOne[1] = ... |
# side effect: |
# (321,654): $GroupOne[2] = ... |
# location (123,456): $GroupOne[0] = 2 # images give out indexes |
# (213,546): $GroupOne[3] = ... |
# (321,654): $GroupOne[1] = 1 |
# location (12,45) : $GroupOne[1] = ... |
# (213,546): $GroupOne[2] = 0 |
# (321,654): $GroupOne[2] = ... |
# location (12,45) : $GroupTwo[0] = "TEXT-3" |
# (213,546): $GroupOne[3] = ... |
# (32,65) : $GroupTwo[1] = "TEXT-1" |
|
# (21,54) : $GroupTwo[2] = "TEXT-2" |
# =========================================== |
# =========================================== |
package Apache::randomlabel; |
package Apache::randomlabel; |
use strict; |
use strict; |
Line 45 sub start_randomlabel {
|
Line 47 sub start_randomlabel {
|
my $w= &Apache::lonxml::get_param('width',$parstack,$safeeval); |
my $w= &Apache::lonxml::get_param('width',$parstack,$safeeval); |
my $h= &Apache::lonxml::get_param('height',$parstack,$safeeval); |
my $h= &Apache::lonxml::get_param('height',$parstack,$safeeval); |
|
|
$result.="<applet code=$code codebase=$codebase width=\"$w\" height=\"$h\">"; |
$Apache::randomlabel::tlabel_cnt=0; |
$result.="<param name=\"bgimg\" value=\"$bgimg\">"; |
$Apache::randomlabel::ilabel_cnt=0; |
if ($target eq 'edit') { |
if ($target eq 'web') { |
} |
$result.="<applet code=$code codebase=$codebase width=\"$w\" height=\"$h\">"; |
if ($target eq 'modified') { |
$result.="<param name=\"bgimg\" value=\"$bgimg\">"; |
|
} elsif ($target eq 'edit') { |
|
} elsif ($target eq 'modified') { |
|
} else { |
} |
} |
return $result; |
return $result; |
} |
} |
|
|
sub end_randomlabel { |
sub end_randomlabel { |
return '</applet><BR />'; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
my $count; |
|
|
|
$count = $Apache::randomlabel::tlabel_cnt; |
|
if( $count != 0) { |
|
$result.= "<param name=\"count\" value=\"$count\">"; |
|
} |
|
$count = $Apache::randomlabel::ilabel_cnt; |
|
if( $count != 0) { |
|
$result.= "<param name=\"icount\" value=\"$count\">"; |
|
} |
|
if ($target eq 'web') { |
|
$result .= "</applet><BR />"; |
|
} |
|
return $result; |
} |
} |
|
|
sub start_labelgroup { |
sub start_labelgroup { |
Line 69 sub start_labelgroup {
|
Line 89 sub start_labelgroup {
|
@Apache::randomlabel::xcoord = (); |
@Apache::randomlabel::xcoord = (); |
@Apache::randomlabel::ycoord = (); |
@Apache::randomlabel::ycoord = (); |
@Apache::randomlabel::label_arr = (); |
@Apache::randomlabel::label_arr = (); |
return ''; |
return $result; |
} |
} |
|
|
# begin to assign labels to locations |
# begin to assign labels to locations |
sub end_labelgroup { |
sub end_labelgroup { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $gname = $Apache::randomlabel::groupname; |
my $gname = $Apache::randomlabel::groupname; |
my $count = $#Apache::randomlabel::label_arr + 1; |
my $count; |
my $type = $Apache::randomlabel::type; |
my $type = $Apache::randomlabel::type; |
my $code; |
my $code; |
my $out; |
my $out; |
my $label; |
my $label; |
my $x; |
my $x; |
my $y; |
my $y; |
my $text; |
my $text=''; |
my $str; |
my $str; |
my $xstr; |
my $xstr; |
my $ystr; |
my $ystr; |
|
|
if( $type eq 'text') { |
|
$text= "<param name=\"count\" value=\"$count\">"; |
|
$str = 'LB'; |
|
$xstr = 'X'; |
|
$ystr = 'Y'; |
|
} |
|
if( $type eq 'image') { |
|
$text= "<param name=\"icount\" value=\"$count\">"; |
|
$str = 'IMG'; |
|
$xstr = 'IX'; |
|
$ystr = 'IY'; |
|
} |
|
my @idx_arr = (0 .. $#Apache::randomlabel::label_arr); |
my @idx_arr = (0 .. $#Apache::randomlabel::label_arr); |
&Apache::structuretags::shuffle(\@idx_arr); |
&Apache::structuretags::shuffle(\@idx_arr); |
for(0 .. $#Apache::randomlabel::label_arr) { |
for(0 .. $#Apache::randomlabel::label_arr) { |
$label = "$Apache::randomlabel::label_arr[ $idx_arr[$_] ]"; |
$label = "$Apache::randomlabel::label_arr[ $idx_arr[$_] ]"; |
$x = pop @Apache::randomlabel::xcoord; |
if( $type eq 'text') { |
$y = pop @Apache::randomlabel::ycoord; |
$code = "push(\@$gname, $label);" ; |
$text .= "<param name=\"" . $str . $_ . "\" value=\"$label\">"; |
$str = 'LB'.$Apache::randomlabel::tlabel_cnt; |
$text .= "<param name=\"" . $xstr . $_ . "\" value=\"$x\"> "; |
$xstr = 'X'.$Apache::randomlabel::tlabel_cnt; |
$text .= "<param name=\"" . $ystr . $_ . "\" value=\"$y\">"; |
$ystr = 'Y'.$Apache::randomlabel::tlabel_cnt; |
$code = "push(\@$gname, $label);" ; |
$Apache::randomlabel::tlabel_cnt += 1; |
|
} elsif ( $type eq 'image') { |
|
$code = "push(\@$gname, $idx_arr[$_]);" ; |
|
$str = 'LB'.$Apache::randomlabel::ilabel_cnt; |
|
$xstr = 'X'.$Apache::randomlabel::ilabel_cnt; |
|
$ystr = 'Y'.$Apache::randomlabel::ilabel_cnt; |
|
$Apache::randomlabel::ilabel_cnt += 1; |
|
} else { |
|
} |
|
# $x = pop @Apache::randomlabel::xcoord; |
|
# $y = pop @Apache::randomlabel::ycoord; |
|
$x = $Apache::randomlabel::xcoord[$_]; |
|
$y = $Apache::randomlabel::ycoord[$_]; |
|
$text .= "<param name=\"" . $str . "\" value=\"$label\">"; |
|
$text .= "<param name=\"" . $xstr . "\" value=\"$x\"> "; |
|
$text .= "<param name=\"" . $ystr . "\" value=\"$y\">"; |
$out=Apache::run::run($code,$safeeval); |
$out=Apache::run::run($code,$safeeval); |
} |
} |
|
|
return $text; |
return $text; |
} |
} |
|
|
Line 121 sub start_location {
|
Line 143 sub start_location {
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $x= &Apache::lonxml::get_param('x',$parstack,$safeeval); |
my $x= &Apache::lonxml::get_param('x',$parstack,$safeeval); |
my $y= &Apache::lonxml::get_param('y',$parstack,$safeeval); |
my $y= &Apache::lonxml::get_param('y',$parstack,$safeeval); |
|
my $result=''; |
|
|
push(@Apache::randomlabel::xcoord,$x); |
push(@Apache::randomlabel::xcoord,$x); |
push(@Apache::randomlabel::ycoord,$y); |
push(@Apache::randomlabel::ycoord,$y); |
return ''; |
return $result; |
} |
} |
|
|
sub end_location { |
sub end_location { |
return ''; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
return $result; |
} |
} |
|
|
# <label>$var_abc</label> |
# <label>$var_abc</label> |
sub start_label { |
sub start_label { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $ltext=&Apache::lonxml::get_all_text("/label",$$parser[$#$parser]); |
my $ltext=&Apache::lonxml::get_all_text("/label",$$parser[$#$parser]); |
|
my $result=''; |
|
|
push(@Apache::randomlabel::label_arr,$ltext); |
push(@Apache::randomlabel::label_arr,$ltext); |
return ''; |
return $result; |
} |
} |
|
|
sub end_label { |
sub end_label { |
return ''; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
my $result=''; |
|
|
|
return $result; |
} |
} |
|
|
|
|