/*
 * Created on Jan 25, 2004
 *
 */
package LumiSoft.UI.Controls;

import java.awt.*;
import javax.swing.*;

/**
 * Drag popup window.
 */
public class WDragWindow extends JWindow
{
	private Image  m_pImage = null;
	private Color  m_pColor = Color.BLACK;
	private Object m_pTag   = null;
	
	/**
	 * Default constructor.
	 * @param parent
	 */
	public WDragWindow(Component parent)
	{	
		super(SwingUtilities.getWindowAncestor(parent));
		
		this.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
	}
	
	
	/**
	 * Is called by system when control need to repaint.
	 */
	public void paint(Graphics g)
	{
		g.setColor(m_pColor);
		g.fillRect(0,0,this.getWidth(),this.getHeight());
		
		if(m_pImage != null){
			g.drawImage(m_pImage,0,0,this);
		}
	}
	
	
	/**
	 * Shows drag window with specified location,size and image.
	 * @param x X position in screen cordinates.
	 * @param y Y position in screen cordinates.
	 * @param width Window width.
	 * @param height Window height.
	 * @param image Image to display in window.
	 */
	public void Show(int x, int y,int width,int height,Image image)
	{
		m_pImage = image;
		
		this.setFocusable(false);		
		this.setLocation(x,y);
		this.setSize(width,height);
		this.setVisible(true);
	}
	
	/**
	 * Shows drag window with specified location,size and with specified bacround color.
	 * @param x X position in screen cordinates.
	 * @param y Y position in screen cordinates.
	 * @param width Window width.
	 * @param height Window height.
	 * @param color Window backround color.
	 */
	public void Show(int x, int y,int width,int height,Color color)
	{
		m_pColor = color;
		
		this.setFocusable(false);
		this.setLocation(x,y);
		this.setSize(width,height);
		this.setVisible(true);
	}
	
	/**
	 * Updates drag window location.
	 * @param x X position in screen cordinates.
	 */
	public void UpdatePosition(int x)
	{
		this.setLocation(x,this.getLocation().y);
	}
	
	/**
	 * Updates drag window location.
	 * @param x X position in screen cordinates.
	 * @param y Y position in screen cordinates.
	 */
	public void UpdatePosition(int x, int y)
	{
		this.setLocation(x,y);
	}
	
	
	/**
	 * Gets tag.
	 * @return
	 */
	public Object getTag()
	{
		return m_pTag;
	}
	/**
	 * Sets tag.
	 * @param value
	 */
	public void setTag(Object value)
	{
		m_pTag = value;
	}

}
