#######################################################################
# This software has been created by Genome Research Limited (GRL).    # 
# GRL hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# GRL neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################

# image2.pl
package FileChooser;
use Tk;
use Tk::Dialog;
use File::Basename;

sub Choose;
sub image2_load_dir;

sub Choose {

  
    my $MW = MainWindow->new;
 #   $IMAGE2 = $MW->Toplevel;
    my $w = $IMAGE2;
    my $dpos $w;
    $w->title('Crow : Choose a Gap or Caf Database');
    $w->iconname('Crow : Choose Database');

    my $w_msg = $w->Label(
        -font       => $FONT,
        -wraplength => '4i',
        -justify    => 'left',
        -text       => 'Choose the Caf file or Gap Database file you want to view\n',
    );
    $w_msg->pack;

    my $w_buttons = $w->Frame;
    $w_buttons->pack(qw(-side bottom -fill x -pady 2m));
    my $w_dismiss = $w_buttons->Button(
        -text    => 'Cancel',
        -command => [$w => 'destroy'],
    );
    $w_dismiss->pack(qw(-side left -expand 1));
    my $w_see = $w_buttons->Button(
        -text    => 'Open',
#        -command => [\&see_code, $demo],
    );
    $w_see->pack(qw(-side left -expand 1));

    my $w_dir_label = $w->Label(-text => 'Directory:');
    my $dir_name = Tk->findINC('demos/images');
    my $w_dir_name = $w->Entry(-width => 30, -textvariable => \$dir_name);
    my $w_spacer1 = $w->Frame(-height => '3m', -width => 20);
    my $w_file_label = $w->Label(-text => 'File:');
    my $w_f = $w->Frame;
    my(@pl) = (-side => 'top', -anchor => 'w');
    $w_dir_label->pack(@pl);
    $w_dir_name->pack(@pl);
    $w_spacer1->pack(@pl);
    $w_file_label->pack(@pl);
    $w_f->pack(@pl);

    my $w_f_list = $w_f->Listbox(-width => 20, -height => 10);
    $w_dir_name->bind('<Return>' => [\&image2_load_dir, $w_f_list, \$dir_name]);
    my $w_f_scroll = $w_f->Scrollbar(-command => [$w_f_list => 'yview']);
    $w_f_list->configure(-yscrollcommand => [$w_f_scroll => 'set']);
    @pl = (-side => 'left', -fill => 'y', -expand => 1);
    $w_f_list->pack(@pl);
    $w_f_scroll->pack(@pl);


#    my $image2a = $w->Photo;
#    $w_f_list->bind('<Double-1>' => [\&image2_load_image, $image2a, \$dir_name]);
#    my $w_spacer2 = $w->Frame(-height => '3m', -width => 20);
#    my $w_image_label = $w->Label(-text => 'Image:');
#    my $w_image = $w->Label(-image => $image2a);
#    @pl = (-side => 'top', -anchor => 'w');
#    $w_spacer2->pack(@pl);
#    $w_image_label->pack(@pl);
#    $w_image->pack(@pl);

} # end image2

sub image2_load_dir {

    # This procedure reloads the directory listbox from the directory
    # named in the demo's entry.
    #
    # Arguments:
    # e       -                 Reference to entry widget.
    # l       -                 Reference to listbox widget.
    # dir_name -                 Directory name reference.

    my($e, $l, $dir_name) = @ARG;

    $l->delete(0, 'end');
    my $i;
    foreach $i (sort <$$dir_name/*>) {
	$l->insert('end', basename($i));
    }

} # end image2_load_dir

##############################################################################################
1;

