//
//  ImportViewController.m
//  VisIVOMobile
//
//  Created by Fabio Vitello on 19/03/12.
//  Copyright 2012 


#import "ImportViewController.h"
#import "CustomCellView.h"
#import "AsciiViewController.h"


@implementation ImportViewController

-(id) initWithTitle:(NSString *)aTitle andIcon:(NSString *)anIcon {
	if(self = [super init]){
        
        
        
        CGRect frame= [[UIScreen mainScreen]bounds];
        
        myTableView = [[UITableView alloc] initWithFrame:CGRectMake(frame.origin.x, 
                                                                    frame.origin.y, 
                                                                    frame.size.width, 
                                                                    frame.size.height)];
        
        myTableView.delegate = self;
        myTableView.dataSource = self;
        
        
        
		UIImage *myIcon=[UIImage imageNamed:anIcon];
		
		UITabBarItem *myItem = [[UITabBarItem alloc] initWithTitle:aTitle image:myIcon tag:0];
		
		self.tabBarItem=myItem;
		[myItem release];
        
        
        
        [self setView:myTableView];
        
        
        self.navigationItem.title=@"Select Format";
        
            
		
	}
	return self;
}


#pragma mark -
#pragma mark UITableView delegate and dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 9;
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
//    FormatCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    CustomCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
       // cell = [[[FormatCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell = [[[CustomCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier type:4] autorelease];
    }
    
    
    
    
    
    
    
    // Set up the cell…
    switch (indexPath.row) {
        case 0:
            cell.primaryLabel.text = @"Ascii";
            cell.myImageView.image = [UIImage imageNamed:@"table.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 1:
            cell.primaryLabel.text = @"Csv";
            cell.myImageView.image = [UIImage imageNamed:@"table.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 2:
            cell.primaryLabel.text = @"VoTable";
            cell.myImageView.image = [UIImage imageNamed:@"votable.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 3:
            cell.primaryLabel.text = @"Binary";
            cell.myImageView.image = [UIImage imageNamed:@"table.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 4:
            cell.primaryLabel.text = @"Fly";
            cell.myImageView.image = [UIImage imageNamed:@"fly.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 5:
            cell.primaryLabel.text = @"Fits";
            cell.myImageView.image = [UIImage imageNamed:@"fits.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 6:
            cell.primaryLabel.text = @"Gadget";
            cell.myImageView.image = [UIImage imageNamed:@"gadget.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 7:
            cell.primaryLabel.text = @"Hdf5";
            cell.myImageView.image = [UIImage imageNamed:@"hdf.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
        case 8:
            cell.primaryLabel.text = @"Raw Bin";
            cell.myImageView.image = [UIImage imageNamed:@"table.png"];
            cell.myImageViewEnd.image = [UIImage imageNamed:@"arrow.png"];
            
            break;
            
    }
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}


//Metodo eseguito quando l'utente clicca su un elemento della tabella
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
    
    // NSLog(@"row= %d", indexPath.row);
    if (indexPath.row ==0)
    {
        
            AsciiViewController *asciiVc= [[AsciiViewController alloc]init];
            [self.navigationController pushViewController:asciiVc animated:YES];
            [asciiVc release];

    }
    else if(indexPath.row==1)
    {
    }
    else if(indexPath.row==2){
    }
    else if(indexPath.row==3){
    }
    else if(indexPath.row==4){
    }
    else if(indexPath.row==5){
    }
    else if(indexPath.row==6){
    }
    else if(indexPath.row==7){
    }
    else if(indexPath.row==8){
    }

    
    
}



- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end