/*
 * Copyright (c) 2024. Elex. All Rights Reesrved.
 * https://www.elex-project.com/
 */

package com.elex_project.examples.frame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.geom.Ellipse2D;
import java.io.File;

public class CustomFrameExample {

	public static void main(String... args) {
		if (Desktop.isDesktopSupported()) {
			final Desktop desktop = Desktop.getDesktop();
			if(desktop.isSupported(Desktop.Action.BROWSE_FILE_DIR)){
				desktop.browseFileDirectory(new File(System.getProperty("user.home")));
			}
		}

		// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
		final JPanel contentPane = new JPanel();
		//contentPane.setBackground(Color.PINK);

		// 프레임을 생성한다.
		final JFrame jFrame = new JFrame();
		jFrame.setTitle("Example");
		jFrame.setSize(800, 600);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.setContentPane(contentPane);
		jFrame.setUndecorated(true);

		final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
		final GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();

		if (graphicsDevice.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)){
			jFrame.setOpacity(0.7f);
			System.out.println("set opacity");
		}
		jFrame.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				jFrame.setShape(new Ellipse2D.Double(0,0, jFrame.getWidth(), jFrame.getHeight()));
			}
		});

		if(graphicsDevice.isFullScreenSupported()){
			graphicsDevice.setFullScreenWindow(jFrame);
		}

		// 이벤트 디스패치 스레드에서 프레임을 표시한다.
		SwingUtilities.invokeLater(() -> {
			jFrame.setVisible(true);
		});


	}
}
