

//
// Core Program for TETDM 
// PopUpForStar.java Version 1.00
// Copyright(C) 2012-2018 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;

//import com.sun.awt.AWTUtilities;//
import java.awt.geom.RoundRectangle2D;

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

	int posX, posY;
	int sizeX,sizeY;
	
	Image image;
	

	String windowName = "STAR";	

		
	PopUpForStar(int X, int Y, int width, int height, Image image, boolean decolation, Control control, int starNumber)
//PopUpForStar(int X, int Y, int width, int height, Image image)	
	{
		this.image = image;
		
		windowName = "STAR-"+starNumber;
		
        WINDOWACTIONLOG windowActionLog = new WINDOWACTIONLOG(this, windowName);
        this.addComponentListener(windowActionLog.componentListener);                    //FOR LOG
        this.addWindowListener(windowActionLog.windowListener);
		
		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);
		
//		setVisible(false);		
		
/////		AWTUtilities.setWindowOpaque(this, false); /////
//		AWTUtilities.setWindowShape(this, new RoundRectangle2D.Double(0, 0, 100, 100, 50, 50));
//		starPanel.setBorder(null);

	}

	
	///////////////////////////////////////////
	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);		
		}	
		
	}	
}


