/*
#=======================================================================================================
#
#                   Copyright (c) 2007 Origin Enterprise Solution LTD.
#
#=======================================================================================================
# File description:  GetMessageDialog.java
#=======================================================================================================
#	 Date	       time   	   Name	 Action	   Description of Change
#	2011-1-17      下午04:01:59    tyl  	Ini	            初始化文件
#=======================================================================================================
*/
package cn.com.customization.util;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.util.PropertyLayout;
import com.teamcenter.rac.util.Separator;
import com.teamcenter.rac.util.VerticalLayout;

public class GetMessageDialog extends AbstractAIFDialog {
	/**
	 * serialVersionUID:TODO（用一句话描述这个变量表示什么）
	 * @since Ver 1.1
	 */

	private static final long	serialVersionUID	= 1L;
	private int				value				= 0;
	private String				title				= "";
	private String				info				= "";

	public GetMessageDialog(String title, String info) {
		super(true);
		this.title=title;
		this.info=info;
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
	}

	public int getValue() {
		setPersistentDisplay(true);
		setOptimalDisplay(false);
		setTitle(title);
		JPanel parentPanel;
		JPanel itemInfoPanel;
		parentPanel = new JPanel(new VerticalLayout(5, 2, 2, 2, 2));
		itemInfoPanel = new JPanel(new PropertyLayout());
		
		URL url=this.getClass().getResource("image/info.png");
		JLabel iconLabel=new JLabel();
		iconLabel.setIcon(new ImageIcon(url));
		
		itemInfoPanel.add("1.1.left.center",iconLabel);
		itemInfoPanel.add("1.2.left.center",new JLabel(info));
		JButton buttonYes = new JButton("是");
		buttonYes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				value = 0;
				GetMessageDialog.this.dispose();
			}
		});
		JButton buttonNo = new JButton("否");
		buttonNo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				value = 1;
				GetMessageDialog.this.dispose();
			}
		});
		JPanel panelButton = new JPanel(new FlowLayout());
		panelButton.add(buttonYes);
		panelButton.add(buttonNo);
		parentPanel.add("top.bin", new Separator());
		parentPanel.add("top.bind.left.top", itemInfoPanel);
		parentPanel.add("bottom.nobind.center.top", panelButton);
		getContentPane().add(parentPanel);
		pack();
		Dimension screen = getToolkit().getScreenSize(); // 得到屏幕尺寸
		setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
		setVisible(true);
		return value;
	}
}