public final class Messages
	{
	private static final String MESSAGES_NAME = "org.lateralgm.libmaker.messages"; //$NON-NLS-1$
	private static final ResourceBundle MESSAGES_BUNDLE = ResourceBundle.getBundle(MESSAGES_NAME);

	private static final String ICONS_PATH = "org/lateralgm/libmaker/"; //$NON-NLS-1$
	private static final Properties ICONS_PROPS = new Properties();

	static
		{
		try
			{
			ICONS_PROPS.load(Messages.class.getResourceAsStream("icons.properties")); //$NON-NLS-1$
			}
		catch (IOException e)
			{
			System.err.println("Unable to read icons.properties"); //$NON-NLS-1$
			}
		}

	private Messages()
		{
		}

	public static String getString(String key)
		{
		try
			{
			return MESSAGES_BUNDLE.getString(key);
			}
		catch (MissingResourceException e)
			{
			return '!' + key + '!';
			}
		}

	public static String format(String key, Object...arguments)
		{
		try
			{
			String p = MESSAGES_BUNDLE.getString(key);
			return MessageFormat.format(p,arguments);
			}
		catch (MissingResourceException e)
			{
			return '!' + key + '!';
			}
		}

	protected static ImageIcon findIcon(String filename)
		{
		String location = ICONS_PATH + filename;
		ImageIcon ico = new ImageIcon(location);
		if (ico.getIconWidth() == -1)
			{
			URL url = Messages.class.getClassLoader().getResource(location);
			if (url != null) ico = new ImageIcon(url);
			}
		return ico;
		}

	public static ImageIcon getIconForKey(String key)
		{
		String filename = ICONS_PROPS.getProperty(key);
		if (filename == null || filename.isEmpty()) return null;
		return findIcon(filename);
		}

	public static BufferedImage getImageForKey(String key)
		{
		String filename = ICONS_PROPS.getProperty(key);
		if (filename == null || filename.isEmpty()) return null;
		URL url = Messages.class.getClassLoader().getResource(ICONS_PATH + filename);
		if (url == null) return null;
		try
			{
			return ImageIO.read(url);
			}
		catch (IOException e)
			{
			return null;
			}
		}
	} public class Action
	{
	//Enums
	public static enum Kind
		{
		NORMAL,BEGIN_GROUP,END_GROUP,ELSE,EXIT,REPEAT,VARIABLE,CODE,PLACEHOLDER,SEPARATOR,LABEL
		}

	public static enum InterfaceKind
		{
		NORMAL,NONE,ARROWS,CODE,TEXT
		}

	public static enum Execution
		{
		NOTHING,FUNCTION,CODE
		}

	public static int MAX_ARGS = 6;
	private static final BufferedImage DEFAULT_TILE = Messages.getImageForKey("Action.DEFAULT_TILE"); //$NON-NLS-1$

	public enum PAction
		{
		NAME,ID,IMAGE,HIDDEN,ADVANCED,REGISTERED,DESCRIPTION,LIST,HINT,KIND,EXEC_TYPE,EXEC_INFO,
		IFACE_KIND,QUESTION,APPLY,RELATIVE,ARG_NUM
		}

	private static final EnumMap<PAction,Object> DEFS = PropertyMap.makeDefaultMap(PAction.class,
			null,null,DEFAULT_TILE,false,false,false,null,null,null,Kind.NORMAL,Execution.CODE,null,
			InterfaceKind.NORMAL,false,true,true,0);

	public final PropertyMap<PAction> properties = new PropertyMap<PAction>(PAction.class,DEFS);

	//Fields
	public Library parent;
	/** .length is always MAX_ARGS. Use argNum to determine actual used argument count. */
	public Argument arguments[] = new Argument[MAX_ARGS];

	public Action()
		{
		int id = Library.lastActionId++;
		properties.put(PAction.ID,id);
		properties.put(PAction.NAME,"Action " + id);

		for (int arg = 0; arg < MAX_ARGS; arg++)
			arguments[arg] = new Argument(arg);
		}

	public void put(PAction key, Object value)
		{
		properties.put(key,value);
		}

	public <V>V get(PAction key)
		{
		return properties.get(key);
		}
	} public static enum InterfaceKind
	{
	NORMAL,NONE,ARROWS,CODE,TEXT
	} public enum PAction
	{
	NAME,ID,IMAGE,HIDDEN,ADVANCED,REGISTERED,DESCRIPTION,LIST,HINT,KIND,EXEC_TYPE,EXEC_INFO,
	IFACE_KIND,QUESTION,APPLY,RELATIVE,ARG_NUM
	} public class Argument
	{
	public static enum Kind
		{
		EXPRESSION,STRING,BOTH,BOOLEAN,MENU,COLOR,FONT_STRING,SPRITE,SOUND,BACKGROUND,PATH,SCRIPT,
		OBJECT,ROOM,FONT,TIMELINE
		}

	public enum PArgument
		{
		CAPTION,KIND,DEF_VALUE,MENU_OPTS
		}

	private static final EnumMap<PArgument,Object> DEFS = PropertyMap.makeDefaultMap(PArgument.class,
			null,Kind.EXPRESSION,"0","item 1|item 2");

	public final PropertyMap<PArgument> properties = new PropertyMap<PArgument>(PArgument.class,DEFS);

	//Only available to Action
	/*package*/Argument(int id)
		{
		properties.put(PArgument.CAPTION,"Argument " + id + ":");
		}

	public void put(PArgument key, Object value)
		{
		properties.put(key,value);
		}

	public <V>V get(PArgument key)
		{
		return properties.get(key);
		}
	} public enum PArgument
	{
	CAPTION,KIND,DEF_VALUE,MENU_OPTS
	} public class EnumRenderer extends DefaultListCellRenderer
	{
	private static final long serialVersionUID = 1L;

	String prefix;

	public EnumRenderer(String prefix)
		{
		super();
		this.prefix = prefix;
		}

	public Component getListCellRendererComponent(JList list, Object value, int index,
			boolean isSelected, boolean cellHasFocus)
		{
		if (value instanceof Enum<?>) value = Messages.getString(prefix + ((Enum<?>) value).name());
		return super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
		}
	} public static interface ActionPanel
	{
	void setAction(Action a);
	} public static abstract class GroupPanel extends JPanel
	{
	private static final long serialVersionUID = 1L;

	public GroupPanel()
		{
		super();

		GroupLayout layout = new GroupLayout(this);
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
		setLayout(layout);

		layoutComponents(layout);
		}

	protected abstract void layoutComponents(GroupLayout layout);
	} public static class PLFactory<K extends Enum<K>>
	{
	List<PropertyLink<K,?>> links = new LinkedList<PropertyLink<K,?>>();

	public PropertyLink<K,?> add(PropertyLink<K,?> pl)
		{
		links.add(pl);
		return pl;
		}

	public void setMap(PropertyMap<K> m)
		{
		for (PropertyLink<K,?> pl : links)
			pl.setMap(m);
		}

	public PropertyLink<K,?> make(JCheckBox cb, K k)
		{
		return add(new ButtonModelLink<K>(cb.getModel(),k));
		}

	public PropertyLink<K,?> make(JTextComponent tf, K k)
		{
		return add(new DocumentLink<K>(tf.getDocument(),k));
		}

	public PropertyLink<K,?> make(JFormattedTextField tf, K k)
		{
		return add(new FormattedLink<K>(tf,k));
		}

	public PropertyLink<K,?> make(JComboBox cb, K k)
		{
		return add(new ComboBoxValueLink<K>(cb,k));
		}
	}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.lateralgm.libmaker.Messages;
import org.lateralgm.libmaker.backend.Action;
import org.lateralgm.libmaker.backend.Action.InterfaceKind;
import org.lateralgm.libmaker.backend.Action.PAction;
import org.lateralgm.libmaker.backend.Argument;
import org.lateralgm.libmaker.backend.Argument.PArgument;
import org.lateralgm.libmaker.components.EnumRenderer;
import org.lateralgm.libmaker.mockui.MockUI.ActionPanel;
import org.lateralgm.libmaker.mockui.MockUI.GroupPanel;
import org.lateralgm.libmaker.uilink.PropertyLink.PLFactory;
/*
 * Copyright (C) 2012 IsmAvatar <IsmAvatar@gmail.com>
 * 
 * This file is part of LibMaker.
 * LibMaker is free software and comes with ABSOLUTELY NO WARRANTY.
 * See LICENSE for details.
 */

package org.lateralgm.libmaker.mockui;




public class InterfacePane extends GroupPanel implements ActionPanel,ChangeListener,ActionListener
	{
	private static final long serialVersionUID = 1L;

	PLFactory<PAction> plf;
	JComboBox dKind;
	JCheckBox cbQuestion, cbApply, cbRelative;
	JLabel lArgNum; //so we can toggle its visibility
	JSpinner sArgNum;
	SpinnerNumberModel smArgNum;
	ArgumentInfo args[];

	class ArgumentInfo implements ActionListener
		{
		public JTextField tName, tVal, tOpts;
		public JComboBox dType;
		PLFactory<PArgument> plf;

		public ArgumentInfo()
			{
			plf = new PLFactory<PArgument>();

			tName = new JTextField(9);
			tVal = new JTextField(8);
			tOpts = new JTextField(5);
			plf.make(tName,PArgument.CAPTION);
			plf.make(tVal,PArgument.DEF_VALUE);
			plf.make(tOpts,PArgument.MENU_OPTS);

			dType = new JComboBox(Argument.Kind.values());
			dType.setSelectedItem(Argument.Kind.MENU); //so the menu text field is initially visible
			dType.setRenderer(new EnumRenderer("ArgumentType.")); //$NON-NLS-1$