package viewer.toggle;

import controller.Controller;
import controller.TurtleCommand;

public class LoadPreferencesButton extends SelectableListButton {

	private static final String BUTTON_TITLE = "Load Preferences";
	private static final String DIALOG_MESSAGE = "Please select preferences to load.";
	protected static String[] PREFERENCES = {};
	//protected TurtleCommand turtleCmd;
	
//	public LoadPreferencesButton(Controller controller, TurtleCommand turtleCmd) {
//		super(PREFERENCES, PREFERENCES, COMMAND, BUTTON_TITLE, DIALOG_MESSAGE, controller);
//		this.turtleCmd = turtleCmd;
//	}
	public LoadPreferencesButton(Controller controller) {
		super(PREFERENCES, PREFERENCES, BUTTON_TITLE, DIALOG_MESSAGE, controller);
	}
	
	private String[] getAllPreferenceNames() {
		String[] preferenceNames = new String[this.myController.getAllPreferences().size()];
		for (Integer i = 0; i < preferenceNames.length; i++) {
			preferenceNames[i] = i.toString();
		}
		return preferenceNames;
	}
	
	@Override
	public void buttonPushed() {
		this.myListModel.clear();
		String[] preferenceNames = getAllPreferenceNames();
		for (int i = 0; i < preferenceNames.length; i++) {
			myListModel.addElement(preferenceNames[i]);
		}
		if (!myListModel.isEmpty()) {
			System.out.println(preferenceNames.length);
			System.out.println(preferenceNames[0]);
		    this.myController.loadPreferences(Integer.parseInt(preferenceNames[myList.getSelectedIndex()]));
		}
	}

}

@@ -734,24 +734,19 @@
 private 
-String%5B%5D
+int
  getAllP
@@ -764,24 +764,23 @@
 mes() %7B%0A
+//
 %09%09
-Str
 in
-g
+t
 %5B%5D prefe
@@ -796,22 +796,19 @@
 s = new 
-Str
 in
-g
+t
 %5Bthis.my
@@ -847,16 +847,18 @@
 ize()%5D;%0A
+//
 %09%09for (I
@@ -906,16 +906,18 @@
  i++) %7B%0A
+//
 %09%09%09prefe
@@ -937,25 +937,73 @@
  = i
-.toString();%0A%09%09%7D%0A
+;%0A//%09%09%7D%0A%09%09return this.myController.getAllPreferences().size();%0A//
 %09%09re
@@ -1022,16 +1022,23 @@
 nceNames
+.length
 ;%0A%09%7D%0A%09%0A%09
@@ -1111,31 +1111,21 @@
 ;%0A%09%09
-String%5B%5D preferenceName
+int numOption
 s = 
@@ -1171,38 +1171,26 @@
  0; i %3C 
-preferenceNames.length
+numOptions
 ; i++) %7B
@@ -1220,264 +1220,285 @@
 ent(
-preferenceNames%5Bi%5D);%0A%09%09%7D%0A%09%09if (!myListModel.isEmpty()) %7B%0A%09%09%09System.out.println(preferenceNames.length);%0A%09%09%09System.out.println(preferenceNames%5B0%5D);%0A%09%09    this.myController.loadPreferences(Integer.parseInt(preferenceNames%5BmyList.getSelectedIndex()%5D));
+String.valueOf(i));%0A%09%09%09System.out.println(i);%0A%09%09%7D%0A%09%09super.buttonPushed();%0A%09%09if (!myListModel.isEmpty()) %7B%0A%09%09%09System.out.println(numOptions);%0A%09%09%09int selected = myList.getSelectedIndex();%0A%09%09%09if (selected %3E -1) %7B%0A%09%09%09    this.myController.loadPreferences(selected);%09%09%09%09%0A%09%09%09%7D
 %0A%09%09%7D%0A%09%7D%0A
 %0A%7D%0A
@@ -1494,11 +1494,10 @@
 %0A%09%09%7D%0A%09%7D%0A
-%0A
 %7D%0A

load save