/*
 * Created on 07-Mar-2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package pipe.gui;

import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;


/**
 * GuiAction class
 * @author Maxim and others
 *
 * Handles loading icon based on action name and setting up other stuff
 * 
 * Toggleable actions store the toggle state in a way that allows ChangeListeners 
 * to be notified of changes 
 */
abstract class GuiAction extends AbstractAction {
	GuiAction (String name, String tooltip, String keystroke) {
		super(name);
		String iconFileName = CreateGui.imgPath+name+ ".png";
		if(new File(iconFileName).exists())
			putValue(SMALL_ICON, new ImageIcon(iconFileName));
		
		if(tooltip != null)
			putValue(SHORT_DESCRIPTION, tooltip);
		
		if(keystroke != null)
			putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(keystroke));
	}	
  GuiAction (String name, String tooltip, String keystroke, boolean toggleable) {
    this(name,tooltip,keystroke);
    this.putValue("selected",new Boolean(false));
  }
  public boolean isSelected() {
    Boolean b=(Boolean)getValue("selected");
    if(b!=null) return b.booleanValue();
    return false; // default
  }
  public void setSelected(boolean selected) {
    Boolean b=(Boolean)getValue("selected");
    if(b!=null) {
      this.putValue("selected",null);
      this.putValue("selected",new Boolean(selected));
    }
  }
}