/*
 * Copyright (c) 2006-2008 MiniMe. Code released under The MIT/X Window System
 * License. Full license text can be found in license.txt
 */
package minime.core;

import minime.ui.SoftBar;
import minime.ui.View;

public abstract class PopupComponent extends Component
{
	protected View view ;
	int[] softkeyBackupValue ;
	public void show(View view)
	{
		this.view = view ;
		setVisible(true);
		
		backupSoftkeyBar() ;
		
		layout() ;
		view.addToView(this) ;
		setFocus(true) ;
	}

	public void dispose()
	{
		view.removeFromView(this) ;
		setFocus(false) ;
		restoreSoftkeyBar() ;
	}
	
	public boolean isShowing()
	{
		return isFocused() ;
	}
	
	private void backupSoftkeyBar()
	{
		SoftBar softbar = SoftBar.getInstance() ;
		// test if SoftBar is activated.   we assume that is softbar has the focus,
		// it is activated and used
		if (softbar.isFocused())
		{
			softkeyBackupValue = new int[3] ;
			softkeyBackupValue[0] = softbar.getLeftKey() ;
			softkeyBackupValue[1] = softbar.getCenterKey() ;
			softkeyBackupValue[2] = softbar.getRightKey() ;
		}
	}
	
	private void restoreSoftkeyBar()
	{
		if (softkeyBackupValue!=null)
		{
			SoftBar.setLeftSoftkey(softkeyBackupValue[0]) ;
			SoftBar.setCenterSoftkey(softkeyBackupValue[1]) ;
			SoftBar.setRightSoftkey(softkeyBackupValue[2]) ;
			softkeyBackupValue = null ;
		}
	}
}
