/*
 * Java-Gnome Bindings Library
 *
 * Copyright 1998-2004 the Java-Gnome Team, all rights reserved.
 *
 * The Java-Gnome bindings library is free software distributed under
 * the terms of the GNU Library General Public License version 2.
 */
package org.gnu.gtk;

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

import org.gnu.glib.GObject;

/**
 */
public class RadioAction extends ToggleAction {
	
	public RadioAction(String name, String label, String tooltip, String stockId, int value) {
		super(gtk_radio_action_new(name, label, tooltip, stockId, value));
	}
	
	RadioAction(int handle) {
		super(handle);
	}


	public List getGroup(){
		int[] group = gtk_radio_action_get_group(getHandle());
		List ret = new ArrayList();
		for (int i = 0; i < group.length; i++) {
			GObject obj = retrieveGObject(group[i]);
			RadioAction action;
			if (null != obj)
				action = (RadioAction)obj;
			else
				action = new RadioAction(group[i]);
			ret.add(action);
		}
		return ret;
	}
	
	public void setGroup(List group) {
		if (null == group)
			return;
		int [] values = new int[group.size()];
		for (int i = 0; i < group.size(); i++) {
			values[i] = ((RadioAction)group.get(i)).getHandle();
		}
		gtk_radio_action_set_group(getHandle(), values);
	}
	
	public int getCurrentValue() {
		return gtk_radio_action_get_current_value(getHandle());
	}
	

	/****************************************
	 * BEGINNING OF JNI CODE
	 ****************************************/
	native static final protected int gtk_radio_action_get_type ();
	native static final protected int gtk_radio_action_new(String name, String label, String tooltip, String stockId, int value);
	native static final protected int[] gtk_radio_action_get_group(int action);
	native static final protected void gtk_radio_action_set_group(int action, int[] group);
	native static final protected int gtk_radio_action_get_current_value(int action);
	/****************************************
	 * END OF JNI CODE
	 ****************************************/
}
