/*******************************************************************************
* Copyright (c)                                                                *
*           2005   Tristan Allwood,                                            *
*           2005   Daniel Burke,                                               *
*           2005   Marc Hull,                                                  *
*           2005   Ekaterina Itskova,                                          *
*           2005   Steve Zymler                                                *
*                                                                              *
* Permission is hereby granted, free of charge, to any person obtaining a      *
* copy of this software and associated documentation files (the                *
* "Software"), to deal in the Software without restriction, including          *
* without limitation the rights to use, copy, modify, merge, publish,          *
* distribute, sublicense, and/or sell copies of the Software, and to           *
* permit persons to whom the Software is furnished to do so, subject to        *
* the following conditions:                                                    *
*                                                                              *
* The above copyright notice and this permission notice shall be included      *
* in all copies or substantial portions of the Software.                       *
*                                                                              *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS      *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF                   *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.       *
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY         *
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,         *
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE            *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                       *
*******************************************************************************/
/*
 * Created on 20-Oct-2004
 *
 */
package uk.ac.ic.doc.kevlar.gui.internal.toolbar;

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

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;

import uk.ac.ic.doc.kevlar.gui.internal.ADrawableObject;
import uk.ac.ic.doc.kevlar.gui.internal.AMouseListenerObject;
import uk.ac.ic.doc.kevlar.gui.internal.caches.ColorCache;
import uk.ac.ic.doc.kevlar.gui.internal.caches.FontCache;
import uk.ac.ic.doc.kevlar.gui.internal.caches.Utils;

/**
 * @author Kate
 *
 */
public class ToolBarManager extends AMouseListenerObject{
	
	public static final int TOOL_BAR_HEIGHT = 24;
	private static final String skin = "toolbar";
	
	private static ToolBarManager singleton;
	private List<AToolBarEntry> buttons;
	
	private ExecuteButton execute;
	private StopButton stop;
	private OutputButton output;
	private ClearCanvasButton clear;
	private SearchButton search;
	private AddToHistoryButton history;
	private LoadButton load;
	private SaveButton save;
	private ProgramsButton programs;
	private DirectoryButton directory;
	private Divider divider1;
	private Divider divider2;
	
	private boolean paneVisible;
	
	public ToolBarManager()
	{
		super();
		
		setPosition(new Point(0,0));
		setAlignment(false, false);
		setSizeFillHorizontal(new Point(0,TOOL_BAR_HEIGHT));
		
		buttons = new ArrayList<AToolBarEntry>();
		initializeToolBarItems();
		
		paneVisible = false;
			
	}
	
	public static void createSingleton()
	{
		if (singleton==null)
		{
			singleton = new ToolBarManager();
		}
	}
	
	public static ToolBarManager getSingleton()
	{
		return singleton;
	}
	
	private void initializeToolBarItems()
	{
		int positionIndex = 0;
		clear = new ClearCanvasButton(positionIndex);
		load = new LoadButton(++positionIndex);
		save = new SaveButton(++positionIndex);
		divider1 = new Divider(++positionIndex);
		execute = new ExecuteButton(++positionIndex);
		stop = new StopButton(++positionIndex);
		stop.disable();
		output = new OutputButton(++positionIndex);
		divider2 = new Divider(++positionIndex);
		history = new AddToHistoryButton(++positionIndex);
		programs = new ProgramsButton(++positionIndex);
		search = new SearchButton(++positionIndex);
		directory = new DirectoryButton(++positionIndex);
		
		addChild(clear);
		addChild(load);
		addChild(save);
		addChild(divider1);
		addChild(execute);
		addChild(stop);
		addChild(output);
		addChild(divider2);
		addChild(history);
		addChild(programs);
		addChild(search);
		addChild(directory);
	}
	
	public void drawBefore(GC gc, Rectangle redrawArea) {
		
		Utils.drawHorizontalBar(gc, skin,new Rectangle(-redrawArea.x, -redrawArea.y, area.width, TOOL_BAR_HEIGHT), true, true);
		
	}
	
	public boolean isPaneVisible()
	{
		return paneVisible;
	}
	
	public void setPaneVisible(boolean isVisible)
	{
		paneVisible = isVisible;
	}
	
	public void disableExecute() {
	    
	    execute.disable();
	    
	}
	
	public void enableExecute() {
	    
	    execute.enable();
	    
	}
	
	public void disableStop() {
	    
	    stop.disable();
	    
	}
	
	public void enableStop() {
	    
	    stop.enable();
	    
	}

}
