package background.commands;

import java.util.Timer;

import control.CommandTimerTask;
import background.CommandManager;

public class SaveImage extends Command {

	public SaveImage(CommandManager cm) {super(cm); }
	public SaveImage(Boolean viz, CommandManager cm) {super(viz, cm);}

	@Override
	public String getType() {
		return "Image";
	}
	
	@Override
	public void applyCommand() {
		commandManager.timer.cancel();				
		
		String file="x";
		if (params.containsKey("type")) file = params.get("type");
		if (!"png jpg".contains(file.toLowerCase())) file="png";
		commandManager.visualPanel.export(file, "image."+file);
    	
		CommandTimerTask ttask = new CommandTimerTask(commandManager);
		Timer timer = new Timer(true);
		
		commandManager.setTTask(timer, ttask);
    	timer.scheduleAtFixedRate(ttask, 0, 50);	        	        	

	}
	
}
