package crushtools;
/*******************************************************************************
 * Copyright (c) 2014 Attila Kovacs <attila[AT]sigmyne.com>.
 * All rights reserved. 
 * 
 * This file is part of crushtools.
 * 
 *     crushtools is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     crushtools is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with crushtools.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Contributors:
 *     Attila Kovacs <attila[AT]sigmyne.com> - initial API and implementation
 ******************************************************************************/

import java.util.*;

import javax.swing.UIManager;

import jnum.astro.AstroTime;
import nom.tam.fits.FitsException;

public class ShowData {
	public static void main(String args[]) {
		versionInfo();

		//if(args.length == 0) usage();
		boolean hasFileArg = args.length > 0;
		if(hasFileArg) hasFileArg = args[args.length-1].charAt(0) != '-';
		
		try {		
			ImageTool.image = hasFileArg ? new SkyMap(args[args.length-1]) : new SkyMap(1,1);
			System.err.println();

			AstroTime time = new AstroTime();
			time.now();
			ImageTool.image.history.add("Processed with CRUSH/show v." + SkyMap.version + " @ " + time.getFitsTimeStamp()); 
			
			for(int i=0; i<args.length; i++) option(args[i]);
			
			//ImageTool.image.displayUnit = ImageTool.image.getUnit("Jy/beam");
			if(hasFileArg) ImageTool.image.info();
			ImageTool.image.show();
		}
		catch(FitsException e) {
		    System.err.println("ERROR reading FITS: " + e.getMessage() + "\n");
		}
		catch(Exception e) { e.printStackTrace(); }
	}

	public static boolean option(String optionString) {
		if(optionString.charAt(0) != '-') return false;
		
		StringTokenizer tokens = new StringTokenizer(optionString, "=,");

		String key = tokens.nextToken().toLowerCase();

		if(key.equals("-help")) usage();
		else if(key.equals("-nofrills")) SkyMap.isHQRendering = false;
		else if(ImageTool.option(optionString)) return true;
		else return false;

		return true;

	}

	public static void versionInfo() {
		System.out.println("show -- Display & Manipulation Utility for CRUSH maps and more.");
		System.out.println("        Author: Attila Kovacs <attila[AT]sigmyne.com>");
		System.out.println("        Version: " + SkyMap.version);
		System.out.println();
	}

	public static void usage() {
		System.out.println();
		System.out.println("Usage: show [options] <filename>");
		System.out.println();
		System.out.println("Options:");
		System.out.println();
		System.out.println("  All options of 'imagetool' are available. Additionally, 'show' defines the");
		System.out.println("  following options:");
		System.out.println();
		System.out.println("    -help      Provides this help screen.");
		System.out.println("    -nofrills  Faster but less polished graphics.");
		System.out.println();
		System.out.println("Hotkeys:");
		System.out.println();
		System.out.println("  'show' provides a range of functionality through hotkeys. For a list of ");
		System.out.println("  press '?' or 'h' in the active image window.");
		System.out.println();
		
		//ImageTool.optionsSummary();
		//System.out.println();
		
		System.exit(0);
	}
}


