

//
// Core Program for TETDM 
// PopUpWindow.java Version 0.44
// Copyright(C) 2012-2014 TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//

package source;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.*;
import javax.imageio.ImageIO;

public class PopUpForStar extends JFrame implements MouseListener,MouseMotionListener  ////////////////////////
{
	Container pane = getContentPane();
	StarPanel starPanel;

	int posX, posY;
	int sizeX,sizeY;
	
	Image image;
		
	PopUpForStar(int X, int Y, int width, int height, Image image, boolean decolation)
	{
		this.image = image;
		
		pane.setLayout(new BorderLayout());
		/////////////////////
		pane.addMouseListener(this);
		pane.addMouseMotionListener(this);
		/////////////////////
		setBounds(X, Y, width, height);
		
		setAlwaysOnTop(true);
		pane.setBackground(Color.white);
		setUndecorated(decolation);
		
		starPanel = new StarPanel();
        pane.add(starPanel);
		
		setVisible(true);
	}
	
	
	///////////////////////////////////////////
	int mousex ,mousey;
    int positionx, positiony;
	int incompox,incompoy;
	
	public void mouseEntered(MouseEvent e){}
	public void mouseExited(MouseEvent e){}
	public void mouseClicked(MouseEvent e){}
	
	public void mousePressed(MouseEvent e){		
		incompox = 0;
		incompoy = 0;
		incompox = e.getPoint().x;
		incompoy = e.getPoint().y;
	}
	
	public void mouseReleased(MouseEvent e){}

	public void mouseDragged(MouseEvent e){
		mousex = e.getLocationOnScreen().x;
		mousey = e.getLocationOnScreen().y;
				
		positionx = mousex - incompox;
		positiony = mousey - incompoy;
	
		positionx -= getInsets().left;
		positiony -= getInsets().top;

		setLocation(positionx, positiony);
	}	
	public void mouseMoved(MouseEvent e){}
	/////////////////////////////////////////////////////
	
	
	
	public void getPosition()
	{
		Point position = starPanel.getLocationOnScreen();
		
		posX = (int)position.getX();
		posY = (int)position.getY();
	}	
	
	public void getLocalSize()
	{
		sizeX = starPanel.getWidth();
		sizeY = starPanel.getHeight();
	}
	
	class StarPanel extends JPanel
	{
		StarPanel(){}
		
		public void update(Graphics g)		//Avoid from blinking
		{
			paintComponent(g);
		}
		
		public void paintComponent(Graphics g)
		{
			Graphics2D g2 = (Graphics2D)g;
			
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// Anti aliasing
			g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);			
			
			getLocalSize();
			
			g2.drawImage(image,0,0,sizeX,sizeY,this);		
		}	
		
	}	
}


