package cn.com.customization.util;

import java.awt.Dimension;
import java.awt.Toolkit;

import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.commands.open.OpenFormDialog;

public class KUtil {
	public static final int MINWIDTH = 1280;
	public static final int MINHEIGHT = 768;
	
	public static void fitToScreen(AbstractAIFDialog abstractAIFDialog) {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		double screenWidth = screenSize.getWidth();
		double screenHeight = screenSize.getHeight();
		Dimension dialogSize = abstractAIFDialog.getSize();
		if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
			abstractAIFDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
			abstractAIFDialog.setLocation(10, (int) Math.floor(abstractAIFDialog.getLocation().getY()));
		}
		if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
			abstractAIFDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
			abstractAIFDialog.setLocation((int) Math.floor(abstractAIFDialog.getLocation().getX()), 10);
		}
		/*
		 * if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
		 * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new
		 * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
		 * abstractAIFDialog.setLocation(10, 10); }
		 */
	}

	public static void fitToScreen(OpenFormDialog openFormDialog) {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		double screenWidth = screenSize.getWidth();
		double screenHeight = screenSize.getHeight();
		Dimension dialogSize = openFormDialog.getSize();
		if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
			openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
			openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY()));
		}
		if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
			openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
			openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10);
		}
		/*
		 * if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
		 * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new
		 * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
		 * openFormDialog.setLocation(10, 10); }
		 */
	}
}
