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

package com.elex_project.examples.thread;

import lombok.AllArgsConstructor;

import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

public class PrintingTaskExample {

	@AllArgsConstructor
	private static class PrintingTask extends SwingWorker<Object, Object>{
		private JTextComponent textComponent;
		private MessageFormat header, footer;
		private boolean interactive;

		@Override
		protected Object doInBackground() throws Exception {
			boolean completed = textComponent.print(header,footer,true,null,null,interactive);

			return null;
		}
	}

	public static void main(String... args) {
		// 컨텐트 패널에 버튼 등의 컴포넌트를 구성한다.
		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);

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

		// 어플리케이션 종료시에 처리할 내용은 셧다운 훅을 사용한다.
		Runtime.getRuntime().addShutdownHook(new Thread(() -> {
			// do something
		}));

	}
}
