package _umgebung;

import java.util.ArrayList;
import javax.swing.JOptionPane;


public class _Eingabe
{
	private static ArrayList<String> sEingabeListe = new ArrayList<String>();

	public static void getEingabe()
	{
		String text = JOptionPane.showInputDialog(null, "Neue Eingabe",
			"Eingabedialog", JOptionPane.PLAIN_MESSAGE);
			if (text == null)	text = "";
			sEingabeListe.add(text);
	}
	
	public static ArrayList<String> getEingabeListe()
	{
		return sEingabeListe;
	}
	
	public static void setEingabeListe(ArrayList<String> sEingabeListe)
	{
		_Eingabe.sEingabeListe = sEingabeListe;
	}	
	
	public static int getIndex()
	{
		return sEingabeListe.size()-1;
	}
	
	public static void addEingabe(String text)
	{
		sEingabeListe.add(text);
	}
	
	public static boolean removeEingabe(int index)
	{
		if (index > 0 && index <= getIndex())
		{
			sEingabeListe.remove(index);
			return true;
		}
		else
		{
			return false;
		}
	}

	public static String getString(int index)
	{
		if (getIndex() == -1) 	return "";					// Noch keine Eingabe
		if (index > getIndex())	return "Falscher Index!";	// Index zu hoch
		return sEingabeListe.get(index);
	}

	public static char getChar(int index)
	{
		char c = ' ';
		if (_Eingabe.getString(index).length() >= 1)
			c = _Eingabe.getString(index).charAt(0);
		return c;
	}

	public static double getDouble(int index)
	{
		try
		{
			return Double.parseDouble(_Eingabe.getString(index));
		} 
		catch (Exception e)
		{
			return 0.0d;
		}
	}

	public static int getInt(int index)
	{
		return (int) _Eingabe.getDouble(index);
	}

	public static String getText()
	{	
		int index = getIndex(); 
		if (index == -1) return " Noch keine Eingabe.";
		return " Index: " + index 
				+ " | String: \"" 	+ _Eingabe.getString(index) 
				+ "\" | Char: \'"	+ _Eingabe.getChar(index) 
				+ "\' | Double: " 	+ _Eingabe.getDouble(index)
				+ " | Integer: " 	+ _Eingabe.getInt(index);
	}
	
	public static void clear()
	{
		sEingabeListe.clear();		
	}
}
