/**
 * Copyright (C) 2012 MK124
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.gtaun.shoebill.common.dialog;

import java.util.ArrayList;
import java.util.List;

import net.gtaun.shoebill.Shoebill;
import net.gtaun.shoebill.constant.DialogStyle;
import net.gtaun.shoebill.event.dialog.DialogResponseEvent;
import net.gtaun.shoebill.object.Player;
import net.gtaun.util.event.EventManager;

/**
 * 抽象列表对话框类。
 * 
 * @author MK124
 */
public abstract class AbstractListDialog extends AbstractDialog
{
	public static abstract class DialogListItem
	{
		private final String string;
		
		public DialogListItem()
		{
			this("-");
		}
		
		public DialogListItem(String string)
		{
			this.string = string;
		}
		
		public void setItemString(String str)
		{
			string = str;
		}
		
		public String toItemString()
		{
			return string;
		}
		
		public boolean isEnabled()
		{
			return true;
		}
		
		public abstract void onItemSelect();
	}
	
	public static abstract class DialogListItemSwitch extends DialogListItem
	{
		private final String string;
		private final String onMessage;
		private final String offMessage;
		
		public DialogListItemSwitch(String string, String onMessage, String offMessage)
		{
			this.string = string;
			this.onMessage = onMessage;
			this.offMessage = offMessage;
		}
		
		public DialogListItemSwitch(String string)
		{
			this.string = string;
			this.onMessage = "ON";
			this.offMessage = "OFF";
		}
		
		public String toItemString()
		{
			return string + " [" + (isSwitched() ? onMessage : offMessage) + "]";
		}
		
		public boolean isEnabled()
		{
			return true;
		}
		
		public abstract boolean isSwitched();
		public abstract void onItemSelect();
	}
	

	protected final List<DialogListItem> dialogListItems;
	protected final List<DialogListItem> displayedItems;
	
	
	protected AbstractListDialog(Player player, Shoebill shoebill, EventManager eventManager)
	{
		super(DialogStyle.LIST, player, shoebill, eventManager);
		dialogListItems = new ArrayList<>();
		displayedItems = new ArrayList<>();
	}
	
	@Override
	public void show()
	{
		String listStr = "";
		displayedItems.clear();
		
		for (DialogListItem item : dialogListItems)
		{
			if (item.isEnabled() == false) continue;
			
			listStr += item.toItemString() + "\n";
			displayedItems.add(item);
		}
		
		show(listStr);
	}
	
	@Override
	protected void onDialogResponse(DialogResponseEvent event)
	{
		if (event.getDialogResponse() == 1)
		{
			int itemId = event.getListitem();
			DialogListItem item = displayedItems.get(itemId);
			
			item.onItemSelect();
		}
		else
		{
			destroy();
		}
	}
}

@@ -1069,38 +1069,32 @@
 em%0A%09%7B%0A%09%09private 
-final 
 String string;%0A%09

修正小问题。