package com.gx.obe.management.shell;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Timer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import com.gx.obe.VideoConfigConstants;
import com.gx.obe.business.enumeration.UserEnum;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.config.ConfigConstants;
import com.gx.obe.config.utils.PropertiesUtils;
import com.gx.obe.management.Activator;
import com.gx.obe.management.Lisener.MeetingRoomListener;
import com.gx.obe.message.Messages;
import com.gx.obe.util.thread.CountTimeThread;
import com.gx.obe.util.utils.ScreenUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.expert.Expert;
import com.gx.tools.ole.vlc.RtmpVideoWindow;
import com.gx.utils.NowTimeUtils;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

public class EvaluationRoomShell extends Shell implements MeetingRoomListener{

	private ImageResolver imageResolver = new ImageResolver();
	private Image zoomBgImage;
//	private Label projectName;
	private Composite meetingTitleComposite;
	private PaintListener titlePaintListener;
	private Image roomImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID,"icons/room/bg.jpg");
	private Timer decStartTimer;
	private Timer decEndTimer;
	private Composite topComposite;
	private Composite leftComposite;
	private Composite topCenterComposite;
	private Composite rightComposite;
	private Composite bottomComposite;
	private Canvas leftBlackborad;
	private Canvas rightBlackborad;
	private String meetingTitle;
	private int titleFontHeight = 20;
	private SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
	private String meetingTimeTitle = Messages.BidOpeningTimeOnBoard;
	private Date meetingTime;
	private String countDownTimeTitle = Messages.CountdownOnBoard;
	private boolean showNowTime = false;
	private Date countDownTime;
	private String[] countDownTimeStr = new String[]{"8", "8", ":", "8", "8", ":", "8", "8"};
	private int chairsCount = 0;
	private boolean hasManager = false;
	private boolean managerIsFemale = false;
	private boolean rightManagerIsFemale = false;
	private int peopleCount = 0;
	private List<Expert> expertList;
	private Composite loadComposite;
	private Composite operatorComposite;
	private PaintListener leftBlackboardListener;
	private PaintListener rightBlackboardListener;
	private CountTimeThread countTimeThread;
//	private BidOpeningRoomOperatorShell bidOpeningRoomOperatorShell;
	private GridLayout topCentGridLayout;
	private final int  LEFT_WIDTH = 390;
	private final int  TOP_HEIGHT = 108;
	private final int  BG_WIDHT = 1920;
	private final int  BG_HEIGHT = 1080;
	private final int  BOTTOM_HEIGHT = 423;
	private final int  MEETING_TABLE_HEIGHT = 445;
	private final int  MEETING_TABLE_IN_CHAIR_HEIGHT = 257;
	private final int  MEETING_TABLE_MANAGER_HEIGHT = 300;
	private final int  MEETING_TABLE_OUT_CHAIR_HEIGHT = 323;
	private Canvas tableBlackborad;
	private Composite chairsInComposite;
	private Composite chairsOutComposite;
	private Image meetingTableImage;
	private Canvas leftManager;
	private Canvas rightManager;
	private Canvas exitBtn;
	private String managerName;
	private Properties videoProperties;
	private Map<String, RtmpVideoWindow> rtmpVideoWindowMap = new HashMap<String, RtmpVideoWindow>();
	private ScreenUtils  util = new ScreenUtils();
	
	public EvaluationRoomShell(Shell parentShell) {
		super(parentShell, SWT.NO_TRIM);
//		super(Display.getDefault(), SWT.NO_TRIM);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent arg0) {
				close();
			}
		});
		setBackgroundMode(SWT.INHERIT_FORCE);
		setBackgroundImage(roomImage);
		setLayout(new FormLayout());
		
		topComposite = new Composite(this, SWT.NONE);
		FormData topFormData = new FormData();
		topFormData.top = new FormAttachment(0, 0);
		topFormData.bottom = new FormAttachment(TOP_HEIGHT, BG_HEIGHT, 0);
		topFormData.left = new FormAttachment(0, 0);
		topFormData.right = new FormAttachment(100, 0);
		topComposite.setLayoutData(topFormData);
		
		leftComposite = new Composite(this, SWT.NONE);
		FormData leftFormData = new FormData();
		leftFormData.right = new FormAttachment(LEFT_WIDTH, BG_WIDHT, 0);
		leftFormData.top = new FormAttachment(TOP_HEIGHT, BG_HEIGHT, 0);
		leftFormData.left  = new FormAttachment(0, 0);
		leftFormData.bottom = new FormAttachment(BG_HEIGHT - BOTTOM_HEIGHT, BG_HEIGHT, 0);
		leftComposite.setLayoutData(leftFormData);
		
		leftComposite.setLayout(new FormLayout());
		
		leftBlackborad = new Canvas(leftComposite, SWT.NONE);
		FormData leftBoardFormData = new FormData();
		leftBoardFormData.left = new FormAttachment(61, LEFT_WIDTH,0);
		leftBoardFormData.right = new FormAttachment(61 + 162, LEFT_WIDTH, 0);
		leftBoardFormData.top = new FormAttachment(80, BG_HEIGHT - TOP_HEIGHT - BOTTOM_HEIGHT, 0);
		leftBoardFormData.bottom = new FormAttachment(80 + 196, BG_HEIGHT - TOP_HEIGHT - BOTTOM_HEIGHT, 0);
		leftBlackborad.setLayoutData(leftBoardFormData);
		
		topCenterComposite = new Composite(this, SWT.NONE);
		
		FormData centFormData = new FormData();
		centFormData.top = new FormAttachment(TOP_HEIGHT, BG_HEIGHT, 0);
		centFormData.left = new FormAttachment(LEFT_WIDTH, BG_WIDHT, 0);
		centFormData.right = new FormAttachment(BG_WIDHT - LEFT_WIDTH, BG_WIDHT, 0);
		centFormData.bottom = new FormAttachment(BG_HEIGHT - BOTTOM_HEIGHT, BG_HEIGHT, 0);
		topCenterComposite.setLayoutData(centFormData);
		
		topCentGridLayout = new GridLayout(1, false);
		topCentGridLayout.verticalSpacing = 0;
		topCentGridLayout.horizontalSpacing = 0;
		topCentGridLayout.marginHeight = 8;
		topCentGridLayout.marginWidth = 8;
		topCenterComposite.setLayout(topCentGridLayout);
		
		meetingTitleComposite = new Composite(topCenterComposite, SWT.NONE);
		GridData gd_project_composite = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_project_composite.heightHint = 45;
		meetingTitleComposite.setLayoutData(gd_project_composite);
		GridLayout gl_project_composite = new GridLayout(1, false);
		meetingTitleComposite.setLayout(gl_project_composite);
		
		loadComposite = new Composite(topCenterComposite, SWT.NONE);
		GridLayout gl_loadComposite = new GridLayout(1, false);
		gl_loadComposite.verticalSpacing = 0;
		gl_loadComposite.horizontalSpacing = 0;
		gl_loadComposite.marginHeight = 0;
		gl_loadComposite.marginWidth = 0;
		loadComposite.setLayout(gl_loadComposite);
		loadComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		rightComposite = new Composite(this, SWT.NONE);
		FormData rightFormData = new FormData();
		rightFormData.left = new FormAttachment(BG_WIDHT - LEFT_WIDTH, BG_WIDHT, 0);
		rightFormData.right = new FormAttachment(100, 0);
		rightFormData.top = new FormAttachment(TOP_HEIGHT, BG_HEIGHT, 0);
		rightFormData.bottom = new FormAttachment(BG_HEIGHT - BOTTOM_HEIGHT, BG_HEIGHT, 0);
		
		rightComposite.setLayoutData(rightFormData);
		rightComposite.setLayout(new FormLayout());
		
		rightBlackborad = new Canvas(rightComposite, SWT.NONE);
		FormData rightBoardFormData = new FormData();
		rightBoardFormData.left = new FormAttachment(LEFT_WIDTH -61 - 162, LEFT_WIDTH,0);
		rightBoardFormData.right = new FormAttachment(LEFT_WIDTH - 61, LEFT_WIDTH, 0);
		rightBoardFormData.top = new FormAttachment(80, BG_HEIGHT - TOP_HEIGHT - BOTTOM_HEIGHT, 0);
		rightBoardFormData.bottom = new FormAttachment(80 + 196, BG_HEIGHT - TOP_HEIGHT - BOTTOM_HEIGHT, 0);
		rightBlackborad.setLayoutData(rightBoardFormData);
		
		bottomComposite = new Composite(this, SWT.TRANSPARENT);
		FormData bottomFormData = new FormData();
		bottomFormData.left = new FormAttachment(0, 0);
		bottomFormData.right = new FormAttachment(100, 0);
		bottomFormData.top = new FormAttachment(BG_HEIGHT - MEETING_TABLE_HEIGHT, BG_HEIGHT, 0);
		bottomFormData.bottom = new FormAttachment(100, 10);
		bottomComposite.setLayoutData(bottomFormData);
		bottomComposite.setLayout(new FormLayout());
		bottomComposite.moveAbove(topCenterComposite);
		bottomComposite.moveAbove(leftComposite);
		
		chairsInComposite = new Composite(bottomComposite, SWT.TRANSPARENT);
		chairsInComposite.setLayout(new GridLayout(3, false));
		FormData chairsInFormData = new FormData();
		chairsInFormData.left = new FormAttachment(300 + 170, BG_WIDHT, 0);
		chairsInFormData.right = new FormAttachment(BG_WIDHT - (300 + 170), BG_WIDHT, 0);
		chairsInFormData.top = new FormAttachment(0, MEETING_TABLE_HEIGHT, 0);
		chairsInFormData.bottom = new FormAttachment(MEETING_TABLE_IN_CHAIR_HEIGHT, MEETING_TABLE_HEIGHT, 0);
		chairsInComposite.setLayoutData(chairsInFormData);
		
		leftManager = new Canvas(bottomComposite, SWT.TRANSPARENT);
		FormData leftManagerFormData = new FormData();
		leftManagerFormData.left = new FormAttachment(180, BG_WIDHT, 0);
		leftManagerFormData.right = new FormAttachment(180 + 259, BG_WIDHT, 0);
		leftManagerFormData.top = new FormAttachment(45, MEETING_TABLE_HEIGHT, 0);
		leftManagerFormData.bottom = new FormAttachment(45 + MEETING_TABLE_MANAGER_HEIGHT, MEETING_TABLE_HEIGHT, 0);
		leftManager.setLayoutData(leftManagerFormData);
		
		rightManager = new Canvas(bottomComposite, SWT.TRANSPARENT);
		FormData rightManagerFormData = new FormData();
		rightManagerFormData.left = new FormAttachment(BG_WIDHT - 180 - 259 , BG_WIDHT, 0);
		rightManagerFormData.right = new FormAttachment(BG_WIDHT - 180, BG_WIDHT, 0);
		rightManagerFormData.top = new FormAttachment(45, MEETING_TABLE_HEIGHT, 0);
		rightManagerFormData.bottom = new FormAttachment(45 + MEETING_TABLE_MANAGER_HEIGHT, MEETING_TABLE_HEIGHT, 0);
		rightManager.setLayoutData(rightManagerFormData);
		
		
		tableBlackborad = new Canvas(bottomComposite, SWT.TRANSPARENT);
		FormData tableBoardFormData = new FormData();
		tableBoardFormData.left = new FormAttachment(300, BG_WIDHT, 0);
		tableBoardFormData.right = new FormAttachment(BG_WIDHT - 300, BG_WIDHT, 0);
		tableBoardFormData.top = new FormAttachment(90, MEETING_TABLE_HEIGHT, 0);
		tableBoardFormData.bottom = new FormAttachment(MEETING_TABLE_HEIGHT - 50, MEETING_TABLE_HEIGHT, 0);
		tableBlackborad.setLayoutData(tableBoardFormData);
		
		chairsOutComposite = new Composite(bottomComposite, SWT.TRANSPARENT);
		chairsOutComposite.setLayout(new GridLayout(3, false));
		FormData chairsOutFormData = new FormData();
		chairsOutFormData.left = new FormAttachment(300 + 170, BG_WIDHT, 0);
		chairsOutFormData.right = new FormAttachment(BG_WIDHT - (300 + 170), BG_WIDHT, 0);
		chairsOutFormData.top = new FormAttachment(MEETING_TABLE_HEIGHT - 10 - MEETING_TABLE_OUT_CHAIR_HEIGHT, MEETING_TABLE_HEIGHT, 0);
		chairsOutFormData.bottom = new FormAttachment(MEETING_TABLE_HEIGHT -10, MEETING_TABLE_HEIGHT, 0);
		chairsOutComposite.setLayoutData(chairsOutFormData);
		chairsOutComposite.moveAbove(chairsInComposite);
		tableBlackborad.moveAbove(chairsInComposite);
		
		exitBtn = new Canvas(this, SWT.TRANSPARENT);
		FormData exitFormData = new FormData();
		exitFormData.left = new FormAttachment(100, -5 - 73);
		exitFormData.right = new FormAttachment(100, -5);
		exitFormData.bottom = new FormAttachment(BG_HEIGHT - 100, BG_HEIGHT, 20);
		exitFormData.top = new FormAttachment(BG_HEIGHT - 100, BG_HEIGHT, -73);
		exitBtn.setLayoutData(exitFormData);
		exitBtn.moveAbove(bottomComposite);
		
		operatorComposite = new Composite(this, SWT.TRANSPARENT);
		FormData operatorCompositeFormData = new FormData();
		operatorCompositeFormData.left = new FormAttachment(0);
		operatorCompositeFormData.right = new FormAttachment(100);
		operatorCompositeFormData.bottom = new FormAttachment(100);
		operatorCompositeFormData.top = new FormAttachment(100, - 40);
		operatorComposite.setLayoutData(operatorCompositeFormData);
		GridLayout gl_composite = new GridLayout(1, false);
		gl_composite.marginTop = 0;
		gl_composite.marginHeight = 0;
		gl_composite.marginBottom = 5;
		gl_composite.marginWidth = 5;
		operatorComposite.setLayout(gl_composite);
		
		createContents();
		init();
	}
	
	
	/**
	 * @Description: 初始化
	 * @author guoyr 
	 */
	private void init(){
		operatorComposite.moveAbove(bottomComposite);
		MouseDragListener mouseDragListener = new MouseDragListener(this);
		meetingTitleComposite.addListener(SWT.MouseDown, mouseDragListener);
		meetingTitleComposite.addListener(SWT.MouseUp, mouseDragListener);
		meetingTitleComposite.addListener(SWT.MouseMove, mouseDragListener);
		startNowTimeThread();
		drawMeetingBg();
		
		drawMeetingTalbe();
		
		addControlListener(new ControlAdapter() {
			public void controlResized(ControlEvent e) {
				layout();
				drawMeetingBg();
//				setOperatorLoaction();
			}
		});
		
		meetingTitleComposite.setFont(SWTResourceManager.getFont("微软雅黑", 20, SWT.BOLD));
		meetingTitleComposite.setForeground(SWTResourceManager.getColor(51, 51, 51));
		
		if(null != titlePaintListener){
			meetingTitleComposite.removePaintListener(titlePaintListener);
		}
		titlePaintListener = new PaintListener() {
			public void paintControl(PaintEvent arg0) {
				drawMeetingTitle(arg0.gc);
			}
		};
		meetingTitleComposite.addPaintListener(titlePaintListener);
		meetingTitleComposite.addControlListener(new ControlAdapter() {
			public void controlResized(ControlEvent e) {
				titleFontHeight = 20;
				meetingTitleComposite.redraw();
			}
		});
		
		if(null != leftBlackboardListener){
			leftBlackborad.removePaintListener(leftBlackboardListener);
		}
		final Image blackBoardImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/blackboard.png");
		leftBlackboardListener = new PaintListener() {
			public void paintControl(PaintEvent arg0) {
				arg0.gc.drawImage(blackBoardImage, 0, 0, blackBoardImage.getBounds().width, blackBoardImage.getBounds().height, 0, 0, leftBlackborad.getBounds().width, leftBlackborad.getBounds().height);
				drawLeftBlackboardTitle(arg0.gc);
				drawLeftBlackboardTime(arg0.gc);
			}
		};
		leftBlackborad.addPaintListener(leftBlackboardListener);
//		rightBlackborad.setVisible(false);
//		if(null != rightBlackboardListener){
//			rightBlackborad.removePaintListener(rightBlackboardListener);
//		}
//		final Image rightBlackBoardImage = imageResolver.loadImage(SWTCoreActivator.PLUGIN_ID, "icons/room/right_blackboard.png");
//		rightBlackboardListener = new PaintListener() {
//			public void paintControl(PaintEvent arg0) {
//				arg0.gc.drawImage(rightBlackBoardImage, 0, 0, rightBlackBoardImage.getBounds().width, rightBlackBoardImage.getBounds().height, 0, 0, rightBlackborad.getBounds().width, rightBlackborad.getBounds().height);
//				
//				drawRightBlackborad(arg0);
//			}
//		};
//		rightBlackborad.addPaintListener(rightBlackboardListener);
		
		leftManager.addMouseListener(new MouseAdapter() {
			public void mouseDoubleClick(MouseEvent e) {
				if(null != managerName && managerName.length() > 0){
					showExpertVideo("项目经理", managerName);
				}
			}
		});
		
		final Image exitBlueImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/exit_blue.png");
		final Image exitRedImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/exit_red.png");
		final String homeStr = Messages.Button_goToHome;
		exitBtn.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		exitBtn.setForeground(SWTResourceManager.getColor(51, 51, 51));
		exitBtn.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent arg0) {
				if(null != exitBtn.getData("mouseEnter")){
					arg0.gc.drawImage(exitRedImage, 0, 0, exitRedImage.getBounds().width, exitRedImage.getBounds().height, 0, 0, exitBtn.getBounds().width, exitBtn.getBounds().height -20);
				}else {
					arg0.gc.drawImage(exitBlueImage, 0, 0, exitBlueImage.getBounds().width, exitBlueImage.getBounds().height, 0, 0, exitBtn.getBounds().width, exitBtn.getBounds().height -20);
				}
				Point e = arg0.gc.textExtent(homeStr);
				arg0.gc.drawText(homeStr, (exitBtn.getBounds().width - e.x)/2, exitBtn.getBounds().height -e.y, true);
			}
		});
		exitBtn.addMouseTrackListener(new MouseTrackAdapter(){
			public void mouseEnter(MouseEvent e) {
				exitBtn.setData("mouseEnter", "1");
				exitBtn.redraw();
			}
			public void mouseExit(MouseEvent e) {
				exitBtn.setData("mouseEnter", null);
				exitBtn.redraw();
			}
		});
		exitBtn.addMouseListener(new MouseAdapter(){
			public void mouseUp(MouseEvent e) {
				exitMeetingRoom();
			}
			
		});
//		this.setMaximized(true);
	}
	
	
	/**
	 * @Description: 鼠标拖动事件
	 * @author guoyr
	 */
	public class MouseDragListener implements Listener{
		Point origin = null;
		private Shell shell;
		public MouseDragListener(Shell shell){
			this.shell = shell;
		}
		public void handleEvent(Event e) {
			switch (e.type) {
			case SWT.MouseDown:
				origin = new Point(e.x, e.y);
				setCursor(new Cursor(null,SWT.CURSOR_SIZEALL));
				break;
			case SWT.MouseUp:
				setCursor(new Cursor(null,SWT.CURSOR_ARROW));
				origin = null;
				setAlpha(255);
//				shell.setMaximized(false);
				if(PropertiesUtils.getProperty(ConfigConstants.EVAL_FULL_SCREEN, "00").equals(CommonEnum.YES)) {
					shell.setSize(util.getScreenWight(),util.getScreenHight());
				}else {
					shell.setSize(util.getScreenWight(),util.getScreenHight() -util.getTaskBarHight());
				}
				shell.setLocation(0, 0);
				break;
			case SWT.MouseMove:
				if (origin != null) {
					setAlpha(100);
					setSize(800, 600);
					Point p = Display.getDefault().map(shell, null, e.x, e.y);
					int x = p.x - origin.x;
					int y =  p.y - origin.y;
					if(x < 0){
						x = 0;
					}
					if(y < 0){
						y = 0;
					}
					shell.setMaximized(false);
					setLocation(x, y);
				}
				break;
			}
		}

	}
	
	class NumPaintListener implements PaintListener{

		private int x;
		private int y;
		public NumPaintListener(int x, int y){
			this.x = x;
			this.y = y;
		}
		public void paintControl(PaintEvent arg0) {
			String num = (String)((CLabel)arg0.getSource()).getData();
			if(null == num){
				num = "0";
			}
			arg0.gc.drawImage(imageResolver.loadImage(Activator.PLUGIN_ID,"icons/time/white_"+num+".png"), x, y);
			arg0.gc.dispose();
		}
	}

	protected void createContents() {
		setText("评标工具-虚拟评标室");
		if(PropertiesUtils.getProperty(ConfigConstants.EVAL_FULL_SCREEN, "00").equals(CommonEnum.YES)) {
			Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); // 取得当前屏幕属性
			int w = d.width; // 获取屏幕宽度
			int h = d.height; // 获取屏幕高度
			setSize(w,h);
		}else {
			setSize(util.getScreenWight(),util.getScreenHight() -util.getTaskBarHight());
		}
		setLocation(0, 0);
	}

	@Override
	protected void checkSubclass() {
	}
	

	private void drawMeetingBg(){
		Rectangle rectangle = getBounds();
		Image roomBgImage = new Image(Display.getDefault(), rectangle);
		roomImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/bg.jpg");
		GC gc = new GC(roomBgImage);
		gc.drawImage(roomImage, 0, 0, roomImage.getBounds().width, roomImage.getBounds().height, 0, 0, roomBgImage.getBounds().width, roomBgImage.getBounds().height);
		
		Point centerPoint = topCenterComposite.getLocation();
		Image backBgImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/room_back.png");
		gc.drawImage(backBgImage, 0, 0, backBgImage.getBounds().width, backBgImage.getBounds().height, centerPoint.x, centerPoint.y, topCenterComposite.getBounds().width,topCenterComposite.getBounds().height + 1);
		
		Image screenImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID,"icons/room/bg_01.jpg");
		gc.drawImage(screenImage, 0, 0, screenImage.getBounds().width, screenImage.getBounds().height, centerPoint.x + topCentGridLayout.marginWidth, centerPoint.y + topCentGridLayout.marginHeight + meetingTitleComposite.getBounds().height, topCenterComposite.getBounds().width - topCentGridLayout.marginWidth * 2, Math.max(topCenterComposite.getBounds().height - topCentGridLayout.marginHeight * 2 - meetingTitleComposite.getBounds().height, 0));
//		gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
//		gc.fillRoundRectangle(centerPoint.x + topCentGridLayout.marginWidth, centerPoint.y + topCentGridLayout.marginHeight + meetingTitleComposite.getBounds().height, topCenterComposite.getBounds().width - topCentGridLayout.marginWidth * 2, topCenterComposite.getBounds().height - topCentGridLayout.marginHeight * 2 - meetingTitleComposite.getBounds().height, 5, 5);
		
		Image ledImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/led.png");
		Point titlePoint = Display.getDefault().map(meetingTitleComposite, EvaluationRoomShell.this, 0,0);
		
		gc.drawImage(ledImage, 0, 0, 20, ledImage.getBounds().height, titlePoint.x, titlePoint.y, 20, meetingTitleComposite.getBounds().height);
		gc.drawImage(ledImage, 20, 0, ledImage.getBounds().width - 40 , ledImage.getBounds().height, titlePoint.x + 20, titlePoint.y, meetingTitleComposite.getBounds().width - 40, meetingTitleComposite.getBounds().height);
		gc.drawImage(ledImage, ledImage.getBounds().width - 20, 0, 20, ledImage.getBounds().height, titlePoint.x + meetingTitleComposite.getBounds().width - 20, titlePoint.y, 20, meetingTitleComposite.getBounds().height);
		
		int videoMargin = (int)(160 / (double)roomImage.getBounds().width * rectangle.width);
		Image videoImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/video.png");
		int videoWidth = (int)(rectangle.width * (videoImage.getBounds().width /(double)roomImage.getBounds().width));
		int videoHeight = (int)(videoWidth/(videoImage.getBounds().width /(double)videoImage.getBounds().height));
		gc.drawImage(videoImage, 0, 0, videoImage.getBounds().width, videoImage.getBounds().height, leftComposite.getBounds().width - videoMargin, leftComposite.getBounds().y, videoWidth, videoHeight);
		
		Transform transform = new Transform(Display.getDefault());
	    transform.setElements(-1, 0, 0, 1, 0 ,0);
	    gc.setTransform(transform);
	    gc.drawImage(videoImage, 0, 0, videoImage.getBounds().width, videoImage.getBounds().height, -1*(rightComposite.getBounds().x + videoMargin) , rightComposite.getBounds().y, videoWidth, videoHeight);
	    transform.dispose();
	    transform = new Transform(Display.getDefault());
	    gc.setTransform(transform);
		
		gc.dispose();
//		removePaintListener(paintListener);
		setBackgroundImage(roomBgImage);
		
		
	}
	
	/**
	 * @Description: 画会议桌
	 * @author guoyr 
	 */
	private void drawMeetingTalbe(){
		final Image leftManagerMaleImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/left_manager_male.png");
		final Image leftManagerFemaleImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/left_manager_female.png");
		final Image leftManagerEmptyImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/left_manager_empty.png");
		leftManager.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent arg0) {
				if(hasManager){
					if(managerIsFemale){
						arg0.gc.drawImage(leftManagerFemaleImage, 0, 0, leftManagerFemaleImage.getBounds().width, leftManagerFemaleImage.getBounds().height, 0, 0, leftManager.getBounds().width, leftManager.getBounds().height);
					}else {
						arg0.gc.drawImage(leftManagerMaleImage, 0, 0, leftManagerMaleImage.getBounds().width, leftManagerMaleImage.getBounds().height, 0, 0, leftManager.getBounds().width, leftManager.getBounds().height);
					}
				}else {
					arg0.gc.drawImage(leftManagerEmptyImage, 0, 0, leftManagerEmptyImage.getBounds().width, leftManagerEmptyImage.getBounds().height, 0, 0, leftManager.getBounds().width, leftManager.getBounds().height);
				}
			}
		});
		final Image rightManagerImage = leftManagerMaleImage;
		final Image rightFemaleManagerImage = leftManagerFemaleImage;
		final Image rightManagerEmptyImage = leftManagerEmptyImage;//imageResolver.loadImage(SWTCoreActivator.PLUGIN_ID, "icons/room/left_manager.png");
		rightManager.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent arg0) {
				Transform transform = new Transform(Display.getDefault());
				transform.setElements(-1, 0, 0, 1, 0 ,0);
				arg0.gc.setTransform(transform);
				if(hasManager){
					if(rightManagerIsFemale){
						arg0.gc.drawImage(rightFemaleManagerImage, 0, 0, rightFemaleManagerImage.getBounds().width, rightFemaleManagerImage.getBounds().height, -1*rightManager.getBounds().width, 0, rightManager.getBounds().width, rightManager.getBounds().height);
					}else {
						arg0.gc.drawImage(rightManagerImage, 0, 0, rightManagerImage.getBounds().width, rightManagerImage.getBounds().height, -1*rightManager.getBounds().width, 0, rightManager.getBounds().width, rightManager.getBounds().height);
					}
				}else {
					arg0.gc.drawImage(rightManagerEmptyImage, 0, 0, rightManagerEmptyImage.getBounds().width, rightManagerEmptyImage.getBounds().height, -1*rightManager.getBounds().width, 0, rightManager.getBounds().width, rightManager.getBounds().height);
				}
			}
		});
		if(null == meetingTableImage){
			meetingTableImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/meeting_table.png");
		}
		final Image padInImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/pad_in.png");
		final Image padOutImage = imageResolver.loadImage(Activator.PLUGIN_ID, "icons/room/pad_out.png");
		tableBlackborad.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent arg0) {
				arg0.gc.drawImage(meetingTableImage, 0, 0, meetingTableImage.getBounds().width, meetingTableImage.getBounds().height, 0, 0, tableBlackborad.getBounds().width, tableBlackborad.getBounds().height);
				double tableRate = tableBlackborad.getBounds().height / (double)meetingTableImage.getBounds().height;
				Control[] inChairs = chairsInComposite.getChildren();
				Point tablePoint = tableBlackborad.getLocation();
				for(int i = 0; i < inChairs.length; i++){
					final Canvas chair = (Canvas)inChairs[i];
					Point point = Display.getDefault().map(chair, bottomComposite, new Point(0, 0));
					int chairX = point.x - tablePoint.x;
					int padWidth = (int)(padInImage.getBounds().width * (tableBlackborad.getBounds().width / (double)meetingTableImage.getBounds().width));
					int padHeight = (int)(padWidth * padInImage.getBounds().height / (double)padInImage.getBounds().width);
					arg0.gc.drawImage(padInImage, 0, 0, padInImage.getBounds().width, padInImage.getBounds().height, chairX + (chair.getBounds().width - padWidth)/2, 0, padWidth, padHeight);
					Expert expert = (Expert)chair.getData("expert");
					String userName = null;
					if(null != expert){
						AuthUser user = expert.getUser();
						userName = user.getUserName();
						// 在会议桌上为最里排专家放名字牌
						if(null != userName){
							arg0.gc.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.NORMAL));
							Point textPoint = arg0.gc.textExtent(userName);
							int nameWidth = Math.max(textPoint.x + 4, padWidth); 
							int y = point.y + (int)(tableRate * 20);
							arg0.gc.setBackground(SWTResourceManager.getColor(9, 117, 130));
							arg0.gc.fillRectangle(chairX + (chair.getBounds().width - nameWidth)/2, y -1, nameWidth, textPoint.y + 2);
							if(null != expert.getUserId() && expert.getUserId().equals(Constants.USER.getId())){
								arg0.gc.setForeground(SWTResourceManager.getColor(255, 153, 0));
								arg0.gc.drawRectangle(chairX + (chair.getBounds().width - nameWidth)/2, y -1, nameWidth, textPoint.y + 2);
							}
							arg0.gc.setForeground(SWTResourceManager.getColor(255, 255, 255));
							arg0.gc.drawText(userName, chairX + (chair.getBounds().width - textPoint.x)/2 + 2, y, true);
						}
					}
				}
				
				Control[] outChairs = chairsOutComposite.getChildren();
				for(int i = 0; i < outChairs.length; i++){
					final Canvas chair = (Canvas)outChairs[i];
					Point point = Display.getDefault().map(chair, bottomComposite, new Point(0, 0));
					int chairX = point.x - tablePoint.x;
					int padWidth = (int)(padOutImage.getBounds().width * (tableBlackborad.getBounds().width / (double)meetingTableImage.getBounds().width));
					int padHeight = (int)(padWidth * padOutImage.getBounds().height / (double)padOutImage.getBounds().width);
					arg0.gc.drawImage(padOutImage, 0, 0, padOutImage.getBounds().width, padOutImage.getBounds().height, chairX + (chair.getBounds().width - padWidth)/2, (int)(tableRate * 50), padWidth, padHeight);
				}
				String managerName = Messages.ProjectManager;
				String supervisor = Messages.Supervisor;
				if(hasManager){
					arg0.gc.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.NORMAL));
					Point textPoint = arg0.gc.textExtent(managerName);
					int textWidth = textPoint.x + 4; 
					int x = 20;
					int y = (int)(70 * tableRate);
					arg0.gc.setBackground(SWTResourceManager.getColor(9, 117, 130));
					arg0.gc.fillRectangle(x, y -1, textWidth, textPoint.y + 2);
					arg0.gc.setForeground(SWTResourceManager.getColor(255, 255, 255));
					arg0.gc.drawText(managerName, x + 2, y, true);
					
					arg0.gc.setTransform(null);
					textPoint = arg0.gc.textExtent(supervisor);
					textWidth = textPoint.x + 4; 
					x = tableBlackborad.getBounds().width - 25 - textWidth;
					arg0.gc.setBackground(SWTResourceManager.getColor(9, 117, 130));
					arg0.gc.fillRectangle(x, y -1, textWidth, textPoint.y + 2);
					arg0.gc.setForeground(SWTResourceManager.getColor(255, 255, 255));
					arg0.gc.drawText(supervisor, x + 2, y, true);
				}
				arg0.gc.dispose();
			}
		});
	}
	
	/**
	 * @Description: 刷新座位
	 * @author guoyr
	 * @param chairsCount
	 * @param hasManager 
	 */
	public void refreshChairsCount(final int chairsCount, final String manager, boolean managerIsFemale, boolean rightManagerIsFemale){
		this.managerName = manager;
		this.managerIsFemale = managerIsFemale;
		this.rightManagerIsFemale = rightManagerIsFemale;
		boolean _hasManager = null != manager && manager.length() > 0;
		if(this.chairsCount == chairsCount && this.hasManager == _hasManager){
			return;
		}
		this.chairsCount = chairsCount;
		this.hasManager = _hasManager;
		
		final Image expertMaleImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/expert_male.png");
		final Image expertMaleBackImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/expert_male_back.png");
		final Image expertFemaleImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/expert_female.png");
		final Image expertFemaleBackImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/expert_female_back.png");
		final Image chairEmptyImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/chair_empty.png");
		final Image chairEmptyBackImage = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/room/chair_empty_back.png");
		
		Display.getDefault().syncExec(new Runnable(){
			public void run(){
				if(!tableBlackborad.isDisposed()){
					leftManager.redraw();
					rightManager.redraw();
					
					int inExpertCount = chairsCount/2;
					if(chairsCount%2 != 0){
						inExpertCount += 1;
					}
					((GridLayout)chairsInComposite.getLayout()).numColumns = inExpertCount;
					
					int chairWidth = (int)((expertMaleImage.getBounds().width / (double)expertMaleImage.getBounds().height)*chairsInComposite.getBounds().height);
					
					if(!chairsInComposite.isDisposed()){
						for(Control control : chairsInComposite.getChildren()){
							control.dispose();
						}
						for(int i = 0; i < inExpertCount; i++) {
							
							final Canvas chair = new Canvas(chairsInComposite, SWT.TRANSPARENT);
							GridData gridData = new GridData(SWT.CENTER, SWT.FILL, true, true, 1, 1);
							gridData.widthHint = chairWidth;
							chair.setLayoutData(gridData);
							chair.addPaintListener(new PaintListener() {
								public void paintControl(PaintEvent arg0) {
									Expert expert = (Expert)chair.getData("expert");
									String userName = null;
									if(null != expert){
										AuthUser user = expert.getUser();
										if(null != user.getGender() && user.getGender().equals(UserEnum.FEMALE) && null != expertFemaleImage){
											arg0.gc.drawImage(expertFemaleImage, 0, 0, expertFemaleImage.getBounds().width, expertFemaleImage.getBounds().height, 2, 2, chair.getBounds().width - 4, chair.getBounds().height - 4);
										}else {
											arg0.gc.drawImage(expertMaleImage, 0, 0, expertMaleImage.getBounds().width, expertMaleImage.getBounds().height, 2, 2, chair.getBounds().width - 4, chair.getBounds().height - 4);
										}
									}else {
										arg0.gc.drawImage(chairEmptyImage, 0, 0, chairEmptyImage.getBounds().width, chairEmptyImage.getBounds().height, 2, 2, chair.getBounds().width - 4, chair.getBounds().height -4);
									}
								}
							});
							chair.addMouseListener(new MouseAdapter() {
								public void mouseDoubleClick(MouseEvent e) {
									Expert expert = (Expert)chair.getData("expert");
									if(null != expert){
										AuthUser user = expert.getUser();
										if(null != user && null != user.getUserAccount()){
											showExpertVideo(null != user.getUserName() ? user.getUserName() : user.getUserAccount(), user.getUserAccount());
										}
									}
								}
							});
							
						}
						chairsInComposite.layout();
					}
					
					if(!chairsOutComposite.isDisposed()){
						
						for(Control control : chairsOutComposite.getChildren()){
							control.dispose();
						}
						int outExpertCount = chairsCount/2;;
						((GridLayout)chairsOutComposite.getLayout()).numColumns = outExpertCount;
						chairWidth = (int)((expertMaleBackImage.getBounds().width / (double)expertMaleBackImage.getBounds().height)*chairsOutComposite.getBounds().height);
						
						for(int i = 0; i < outExpertCount; i++) {
							final Canvas chair = new Canvas(chairsOutComposite, SWT.TRANSPARENT);
							GridData gridData = new GridData(SWT.CENTER, SWT.FILL, true, true, 1, 1);
							gridData.widthHint = chairWidth;
							chair.setLayoutData(gridData);
							chair.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.NORMAL));
							chair.addPaintListener(new PaintListener() {
								public void paintControl(PaintEvent arg0) {
									Expert expert = (Expert)chair.getData("expert");
									String userName = null;
									boolean showName = false;
									if(null != expert){
										AuthUser user = expert.getUser();
										userName = user.getUserName();
										// 如果最外面排需要转过来显示
										if(null != chair.getData("back")){
											if(null != user.getGender() && user.getGender().equals(UserEnum.FEMALE) && null != expertFemaleImage){
												arg0.gc.drawImage(expertFemaleImage, 0, 0, expertFemaleImage.getBounds().width, expertFemaleImage.getBounds().height, 2, 2, chair.getBounds().width - 4, chair.getBounds().height - 4);
											}else {
												arg0.gc.drawImage(expertMaleImage, 0, 0, expertMaleImage.getBounds().width, expertMaleImage.getBounds().height, 2, 2, chair.getBounds().width - 4, chair.getBounds().height - 4);
											}
										}else {
											if(null != user.getGender() && user.getGender().equals(UserEnum.FEMALE) && null != expertFemaleImage){
												arg0.gc.drawImage(expertFemaleBackImage, 0, 0, expertFemaleBackImage.getBounds().width, expertFemaleBackImage.getBounds().height, 2, 2, chair.getBounds().width -4 , chair.getBounds().height-4);
											}else {
												arg0.gc.drawImage(expertMaleBackImage, 0, 0, expertMaleBackImage.getBounds().width, expertMaleBackImage.getBounds().height, 2, 2, chair.getBounds().width -4 , chair.getBounds().height-4);
											}
										}
										// 最外面排在椅子上放名字牌
										if(null != userName){
											Point textPoint = arg0.gc.textExtent(userName);
											int textWidth = Math.min(arg0.gc.textExtent(userName).x + 4, chair.getBounds().width);
											int nameWidth = Math.max(textWidth, (int)(chair.getBounds().width * 0.5));
											int y = (int)(chair.getBounds().height / (double)expertMaleBackImage.getBounds().height * 130);
											arg0.gc.setBackground(SWTResourceManager.getColor(9, 117, 130));
											arg0.gc.fillRectangle((chair.getBounds().width - nameWidth)/2, y -1, nameWidth, textPoint.y + 2);
											if(null != expert.getUserId() && expert.getUserId().equals(Constants.USER.getId())){
												arg0.gc.setForeground(SWTResourceManager.getColor(255, 153, 0));
												arg0.gc.drawRectangle((chair.getBounds().width - nameWidth)/2, y -1, nameWidth, textPoint.y + 2);
											}
											arg0.gc.setForeground(SWTResourceManager.getColor(255, 255, 255));
											arg0.gc.drawText(userName, (chair.getBounds().width - textWidth)/2 + 2, y, true);
										}
									}else {
										arg0.gc.drawImage(chairEmptyBackImage, 0, 0, chairEmptyBackImage.getBounds().width, chairEmptyBackImage.getBounds().height, 2, 2, chair.getBounds().width -4, chair.getBounds().height-4);
									}
								}
							});
							chair.addMouseListener(new MouseAdapter() {
								public void mouseDoubleClick(MouseEvent e) {
									Expert expert = (Expert)chair.getData("expert");
									if(null != expert){
										AuthUser user = expert.getUser();
										if(null != user && null != user.getUserAccount()){
											showExpertVideo(null != user.getUserName() ? user.getUserName() : user.getUserAccount(), user.getUserAccount());
										}
									}
								}
							});
							chair.addMouseTrackListener(new MouseTrackAdapter(){
								// 鼠标移上去转向正面显示
								public void mouseEnter(MouseEvent e) {
									Expert expert = (Expert)chair.getData("expert");
									if(null != expert){
										chair.setData("back", "1");
										chair.redraw();
									}
								}
								
								public void mouseExit(MouseEvent e) {
									Expert expert = (Expert)chair.getData("expert");
									if(null != expert){
										chair.setData("back", null);
										chair.redraw();
									}
								}
							});
						}
					}
					chairsOutComposite.layout();
					tableBlackborad.redraw();
				}
			}
		});
	}
	
	/**
	 * @Description: 查看视频
	 * @author guoyr
	 * @param videoName
	 * @param account 
	 */
	private void showExpertVideo(String videoName, String account){
//		String livingType = CommonEnum.LIVING_COM_RTMP;
		String videoLiveUrl = "";
		String livingName = account;
		if(null == videoProperties){
			videoProperties = PropertiesUtils.getProperties("videoConfig.properties");
		}
		if(null != videoProperties){
			videoLiveUrl =  videoProperties.getProperty(VideoConfigConstants.LIVING_ADDRESS_HEAD) + livingName;
		}
		if(null == videoLiveUrl || videoLiveUrl.length() == 0){
			return;
		}
		RtmpVideoWindow rtmpVideoWindow = rtmpVideoWindowMap.get(videoLiveUrl);
		if(null == rtmpVideoWindow || null == rtmpVideoWindow.getShell() || rtmpVideoWindow.getShell().isDisposed()){
			rtmpVideoWindow = new RtmpVideoWindow(videoName, videoLiveUrl);
			rtmpVideoWindowMap.put(videoLiveUrl, rtmpVideoWindow);
			rtmpVideoWindow.open();
			rtmpVideoWindowMap.remove(videoLiveUrl);
		}else {
			rtmpVideoWindow.getShell().setMinimized(false);
			rtmpVideoWindow.getShell().setVisible(true);
			rtmpVideoWindow.getShell().open();
		}
	}
	/** 
	 * @Description: 刷新专家
	 * @author guoyr
	 * @param _expertList 
	 */
	public void refreshExpert(final List<Expert> _expertList){
		this.expertList = _expertList;
		Display.getDefault().syncExec(new Runnable(){
			public void run(){
				if(!chairsInComposite.isDisposed()){
					Control[] inChairs = chairsInComposite.getChildren();
					boolean redraw = redrawExpertChair(inChairs, 0);
					
					Control[] outChairs = chairsOutComposite.getChildren();
					redrawExpertChair(outChairs, inChairs.length);
					// 只有刷新最里面的专家时才需要刷新会议桌（在会议桌上放名字牌）
					if(redraw){
						tableBlackborad.redraw();
					}
				}
			}
		});
	}
	
	/**
	 * @Description: 刷新专家的座位
	 * @author guoyr
	 * @param expertChairs
	 * @param expertIndex 
	 */
	private boolean redrawExpertChair(Control[] expertChairs, int expertIndex){
		boolean redraw = false;
		for(int i = 0; i < expertChairs.length; i++) {
			final Canvas chair = (Canvas)expertChairs[i];
			String oldExpertId = (String)chair.getData("ID");
			Expert curExpert = null;
			String curExpertId = null;
			if(null != expertList && expertIndex < expertList.size()){
				curExpert = expertList.get(expertIndex);
				if(null != curExpert){
					curExpertId = curExpert.getId();
				}
			}
			chair.setData("expert", curExpert);
			chair.setData("ID", curExpertId);
			if(null == oldExpertId){
				if(null != curExpertId){
					chair.redraw();
					redraw = true;
				}
			}else {
				if(null == curExpertId || (null != curExpertId && !curExpertId.equals(oldExpertId))){
					chair.redraw();
					redraw = true;
				}
			}
			expertIndex ++;
		}
		return redraw;
	}
	
	
	/**
	 * @Description: 刷新会议时间
	 * @author guoyr
	 * @param meetingTimeTitle
	 * @param meetingTime 
	 */
	public void refreshMeetingTime(String meetingTimeTitle, Date meetingTime){
		this.meetingTimeTitle = meetingTimeTitle;
		this.meetingTime = meetingTime;
		Display.getDefault().syncExec(new Runnable(){
			public void run(){
				if(!leftBlackborad.isDisposed()){
					leftBlackborad.redraw();
				}
			}
		});
	}
		
	private void drawLeftBlackboardTitle(GC gc){
		try {
			Rectangle leftBlackboardRectangle = leftBlackborad.getBounds();
			double rectangleWidth = leftBlackboardRectangle.width - leftBlackboardRectangle.width * (9/(double)162) - 10;
			gc.setFont(SWTResourceManager.getFont("微软雅黑", 25, SWT.BOLD));
			Point e = gc.textExtent(StringUtils.hasLength(meetingTimeTitle) ? meetingTimeTitle.substring(0, 1) : "郭");
			double maxFontHeight = e.y;
			double maxFongWidth = e.x;
			double totalSize = maxFongWidth;
			for(int i = 1; i < meetingTimeTitle.length(); i++){
				maxFongWidth = maxFongWidth * 0.9;
				totalSize += maxFongWidth;
			}
			
			maxFongWidth = e.x;
			double sep = 0;
			if(totalSize > rectangleWidth){
				maxFongWidth = maxFongWidth * rectangleWidth / totalSize;
//				maxFontHeight = maxFongWidth * e.y / e.x;
				totalSize = rectangleWidth;
			}else {
				sep = (rectangleWidth - totalSize)/(meetingTimeTitle.length() - 1);
			}
			
			double borderWidth = leftBlackboardRectangle.width * (9 / (double)162);
			double x =  borderWidth + 5;
			
			Transform transform = new Transform(Display.getDefault());
			transform.setElements(1, 0.25f, 0, 1, 0 ,0);
			gc.setTransform(transform);
			Color fontColor = SWTResourceManager.getColor(231, 22, 52);
			for(int i = 0; i < meetingTimeTitle.length(); i++){
				String str = meetingTimeTitle.substring(i, i+1);
				Image strImage = drawImage(gc, str, 0, gc.getFont(), fontColor);
				gc.drawImage(strImage, 0, 0, strImage.getBounds().width, strImage.getBounds().height, (int)x,(int) ((leftBlackboardRectangle.height /2 - maxFontHeight)/2) , (int)maxFongWidth, (int)maxFontHeight);
				strImage.dispose();
				x += maxFongWidth;
				x += sep;
				maxFongWidth = maxFongWidth * 0.9;
				maxFontHeight = maxFontHeight * 0.9;
			}
			transform.dispose();
		} catch (Exception e) {
		}
	}
	private void drawLeftBlackboardTime(GC gc){
		try {
			Rectangle leftBlackboardRectangle = leftBlackborad.getBounds();
			double rectangleWidth = leftBlackboardRectangle.width - leftBlackboardRectangle.width * (9/(double)162)- 10;
			Transform transform = new Transform(Display.getDefault());
			transform.setElements(1, 0.18f, 0, 1, 0 ,0);
			gc.setTransform(transform);
			Image numImage = imageResolver.loadImage(Activator.PLUGIN_ID,"icons/time/red_8.png");
//			Image numSImage = imageResolver.loadImage(SWTCoreActivator.PLUGIN_ID,"icons/time/red_sep.png");
			double numSize = numImage.getBounds().width;
			double numWidth = numImage.getBounds().width;
			double maxNumHeight = numImage.getBounds().height;
			double maxNumWidth = numImage.getBounds().width;
			for(int i = 1; i < 6; i++){
				numWidth = numWidth * 0.95;
				numSize += numWidth;
			}
			numSize += 5 * 2;
			double vacantSize = 0;
			if (numSize > rectangleWidth) {
				maxNumWidth = maxNumWidth * rectangleWidth / numSize;
				maxNumHeight = maxNumWidth * numImage.getBounds().height * 1.2 / numImage.getBounds().width;
				numSize = rectangleWidth;
			} else {
				vacantSize = (rectangleWidth - numSize) / 2d;
			}
			
			int borderWidth = (int)(leftBlackboardRectangle.width * (9 / (double)162));
			int bottomOffSet = leftBlackboardRectangle.height /2 - ((int)(leftBlackboardRectangle.height * (16 / (double)196)));
			int x = borderWidth + (int)(leftBlackboardRectangle.width - borderWidth - numSize)/2;
			
			String meetingTimeStr = "00:00:00";
			if(null != meetingTime){
				meetingTimeStr = timeFormat.format(meetingTime);
			}
			for(int i = 0; i < meetingTimeStr.length(); i++){
				String str = meetingTimeStr.substring(i, i+1);
				Image drawImage = null;
				if(str.equals(":")){
					drawImage = imageResolver.loadImage(Activator.PLUGIN_ID,"icons/time/red_sep.png");
				}else {
					drawImage = imageResolver.loadImage(Activator.PLUGIN_ID,"icons/time/red_"+str+".png");
				}
				if(null != drawImage){
					gc.drawImage(drawImage, 0, 0, drawImage.getBounds().width, drawImage.getBounds().height, x, bottomOffSet + (int)(leftBlackboardRectangle.height /2 - maxNumHeight)/2 , (i == 2 || i == 5) ? 5 : (int)maxNumWidth, (int)maxNumHeight);
				}
				if (i == 2 || i == 5) {
					x += 5;
				}else {
					x += maxNumWidth;
					maxNumWidth = (int)(maxNumWidth * 0.95);
					maxNumHeight = (int)(maxNumHeight * 0.95);
				}
			}
			transform.dispose();
		} catch (Exception e) {
		}
	}
	private void drawRightBlackboardTitle(GC gc){
		Rectangle rightBlackboardRectangle = leftBlackborad.getBounds();
		double rightBorderWidth = rightBlackboardRectangle.width * (9 / (double)162);
		double rectangleWidth = rightBlackboardRectangle.width - rightBorderWidth - 10;
		
		gc.setFont(SWTResourceManager.getFont("微软雅黑", 25, SWT.BOLD));
		Point e = gc.textExtent(StringUtils.hasLength(countDownTimeTitle) ? meetingTimeTitle.substring(0, 1) : "郭");
		double maxFontHeight = e.y;
		double maxFongWidth = e.x;
		double totalSize = maxFongWidth;
		for(int i = 1; i < countDownTimeTitle.length(); i++){
			maxFongWidth = maxFongWidth * 0.9;
			maxFontHeight = maxFontHeight * 0.9;
			totalSize += maxFongWidth;
		}
		
		double strRate = 0;
		double sep = 0;
		if(totalSize > rectangleWidth){
			strRate = totalSize / rectangleWidth;
			maxFongWidth = maxFongWidth/strRate;
			totalSize = rectangleWidth;
			maxFontHeight = maxFongWidth / ((double)e.x / e.y);
		}else {
			sep = (rectangleWidth - totalSize)/(countDownTimeTitle.length() - 1);
		}
		
		double topOffSet = rightBlackboardRectangle.height * (52 / (double)196);
		double x = 5;
		
		Transform transform = new Transform(Display.getDefault());
		transform.setElements(1, -0.25f, 0, 1, 0, (float) (maxFontHeight*0.25));
		gc.setTransform(transform);
		if(null == countDownTimeTitle){
		}
		Color fontColor = SWTResourceManager.getColor(231, 22, 52);
//		fontColor = SWTResourceManager.getColor(SWT.COLOR_WHITE);
		for(int i = 0; i < countDownTimeTitle.length(); i++){
			String str = countDownTimeTitle.substring(i, i+1);
			Image strImage = drawImage(gc, str, 0, gc.getFont(), fontColor);
			gc.drawImage(strImage, 0, 0, strImage.getBounds().width, strImage.getBounds().height, (int)x, (int)((topOffSet + (rightBlackboardRectangle.height)/2 - maxFontHeight)/2), (int)maxFongWidth, (int)maxFontHeight);
			strImage.dispose();
			x += maxFongWidth;
			maxFongWidth = (int)(maxFongWidth / 0.9);
			maxFontHeight = (int)(maxFontHeight/ 0.9);
			x += sep;
		}
		transform.dispose();
	}
	private Image drawRightBlackboardTime(GC gc){
		Rectangle rightBlackboardRectangle = rightBlackborad.getBounds();
		Image numImage = imageResolver.loadImage(Activator.PLUGIN_ID,"icons/time/red_8.png");
//		Image numSepImage = imageResolver.loadImage(SWTCoreActivator.PLUGIN_ID,"icons/time/red_sep.png");
		int numTotalLength = numImage.getBounds().width;
		int firstNumHeight = numImage.getBounds().height;
		int firstNumWidth = numImage.getBounds().width;
		for(int i = 1; i < 6; i++){
			firstNumHeight = (int)(firstNumHeight * 0.92);
			firstNumWidth = (int)(firstNumWidth * 0.95);
			numTotalLength += firstNumWidth;
		}
		numTotalLength += 5 *2;
		double numRate = 0;
		
		if(numTotalLength > rightBlackboardRectangle.width -10){
			numRate = (double)numTotalLength/(rightBlackboardRectangle.width -10);
			numTotalLength = rightBlackboardRectangle.width -10;
			firstNumWidth = (int)(firstNumWidth/numRate);
			firstNumHeight = (int)(firstNumWidth / ((double)numImage.getBounds().width / numImage.getBounds().height) * 1.2);
		}
		
		
		int rightBorderWidth = 0;//(int)(rightBlackboardRectangle.width * (9 / (double)162));
		int topOffSet = (int)(rightBlackboardRectangle.height * 0.82 / 2);
		int x = (int)((rightBlackboardRectangle.width - rightBorderWidth - numTotalLength)/2);
		
		Transform transform = new Transform(Display.getDefault());
		transform.setElements(1, -0.18f, 0, 1, 0, firstNumHeight*0.82f);
		gc.setTransform(transform);
		for(int i = 0; i < countDownTimeStr.length; i++){
			String str = countDownTimeStr[i];
			Image drawImage = null;
			if(str.equals(":")){
				drawImage = imageResolver.loadImage(Activator.PLUGIN_ID,"icons/time/red_sep.png");
			}else {
				drawImage = imageResolver.loadImage(Activator.PLUGIN_ID,"icons/time/red_"+str+".png");
			}
			if(null != drawImage){
				gc.drawImage(drawImage, 0, 0, drawImage.getBounds().width, drawImage.getBounds().height, x, topOffSet + (rightBlackboardRectangle.height/2 - firstNumHeight)/2 , (i == 2 || i == 5) ? 5 : firstNumWidth, firstNumHeight);
			}
			if(i == 2 || i == 5){
				x += 5;
			}else {
				x += firstNumWidth;
				firstNumWidth = (int)(firstNumWidth / 0.95);
				firstNumHeight = (int)(firstNumHeight / 0.92);
			}
		}
		transform.dispose();
		return null;
	}
	
	/**
	 * @Description: 启动当前时间线程
	 * @author guoyr
	 */
	private void startNowTimeThread(){
		showNowTime = true;
		new Thread(new Runnable(){
			public void run(){
				final String weak = NowTimeUtils.getWeakDay();
				long millis = NowTimeUtils.getNowDate().getTime();
				Calendar calendar = Calendar.getInstance();
				calendar.setTimeInMillis(millis);
				
				while(showNowTime){
					calendar.setTimeInMillis(millis);
					refreshMeetingTime(weak, calendar.getTime());
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
					}
					millis += 1000;
				}
			
			}
		}).start();
		
	}
	/**
	 * @Description: 刷新倒计时
	 * @author guoyr
	 * @param countDownTimeTitle
	 * @param countDownTime 
	 */
	public void refreshCountDownTime(String countDownTimeTitle, Date countDownTime){
		this.countDownTimeTitle = countDownTimeTitle;
		this.countDownTime = countDownTime;
		startCountTimeThread(countDownTime);
		Display.getDefault().syncExec(new Runnable(){
			public void run(){
				if(!rightBlackborad.isDisposed()){
					rightBlackborad.redraw();
				}
			}
		});
	}
	
	private void drawRightBlackborad(PaintEvent arg0){
//		Image image = new Image(Display.getDefault(), rightBlackboardImage.getImageData());
		Transform transform = new Transform(Display.getDefault());
		arg0.gc.setTransform(transform);
		arg0.gc.setFont(SWTResourceManager.getFont("微软雅黑", 25, SWT.BOLD));
		
		if(null == countDownTimeTitle || countDownTimeTitle.length() == 0){
			countDownTimeTitle = Messages.CountdownOnBoard;
		}
		drawRightBlackboardTitle(arg0.gc);
		drawRightBlackboardTime(arg0.gc);
		arg0.gc.dispose();
	}
	
	
	/**
	 * @Description: 刷新有人的座位
	 * @author guoyr 
	 */
	public void refreshPeopleCount(int peopleCount){
		if(this.peopleCount != peopleCount){
			this.peopleCount = peopleCount;
			Display.getDefault().syncExec(new Runnable(){
				public void run(){
					if(!bottomComposite.isDisposed()){
						bottomComposite.redraw();
					}
				}
			});
		}
	}
	
	
	/** 
	 * @Description: 绘制会议室标题
	 * @author guoyr
	 * @param meetingTitle 
	 */
	public void refreshMeetingTitle(String meetingTitle){
		if(null != meetingTitle && (null == this.meetingTitle || !this.meetingTitle.equals(meetingTitle))){
			this.meetingTitle = meetingTitle;
			this.titleFontHeight = 20;
			Display.getDefault().syncExec(new Runnable(){
				public void run(){
					if(!meetingTitleComposite.isDisposed()){
						meetingTitleComposite.redraw();
					}
				}
			});
		}
	}
	
	/**
	 * @Description: 绘制会议室标题
	 * @author guoyr
	 * @param gc 
	 */
	private void drawMeetingTitle(GC gc){
//		gc.setAlpha(200);
		gc.setForeground(SWTResourceManager.getColor(231, 22, 52));
//		gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
//		gc.fillRectangle(project_composite.getBounds());
		if(null != meetingTitle && meetingTitle.length() > 0){
			gc.setFont(SWTResourceManager.getFont("微软雅黑", titleFontHeight, SWT.BOLD));
			Point e = gc.textExtent(meetingTitle, SWT.DRAW_MNEMONIC | SWT.DRAW_TAB | SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
			while(e.x > meetingTitleComposite.getBounds().width -10){
				titleFontHeight --;
				gc.setFont(SWTResourceManager.getFont("微软雅黑", titleFontHeight, SWT.BOLD));
				e = gc.textExtent(meetingTitle, SWT.DRAW_MNEMONIC | SWT.DRAW_TAB | SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
			}
			
			int x = (meetingTitleComposite.getBounds().width - e.x)/2;
			int y = (meetingTitleComposite.getBounds().height - e.y)/2;
			gc.setAlpha(250);
			gc.drawText(meetingTitle, x, y, true);
		}
	}
	
	private Image drawImage(GC gc, String string, float rotate, Font font, Color fontColor){
		Point e = gc.textExtent(string);
		BufferedImage bufferedImage = new BufferedImage(e.x, e.y,BufferedImage.TYPE_INT_RGB);  
		PaletteData palette = new PaletteData(0, 0, 0);  
		ImageData imageData = new ImageData(e.x, e.y,  bufferedImage.getColorModel().getPixelSize(), palette); 
		imageData.transparentPixel = imageData.palette.getPixel(new RGB(0, 0, 0));
		Image strImage = new Image(Display.getDefault(), imageData);
		GC imageGc = new GC(strImage);
		Transform transform = new Transform(Display.getDefault());
		if(rotate != 0){
			transform.setElements(1, rotate, 0, 1, 0 ,0);
		}
		imageGc.setTransform(transform);
		imageGc.setFont(font);
		imageGc.setForeground(fontColor);
		imageGc.setBackground(fontColor);
		imageGc.drawText(string, 0, 0,true);
		imageGc.dispose();
		transform.dispose();
		return strImage;
	}
	
	public Composite getLoadParent() {
		return loadComposite;
	}
	
	public Composite getOperatorParent(){
		return operatorComposite;
	}
	
	public void refreshOperator(){
		operatorComposite.layout();
	}
	
//	public Composite getOperatorParent(){
//		if(null == bidOpeningRoomOperatorShell || bidOpeningRoomOperatorShell.isDisposed()){
//			bidOpeningRoomOperatorShell = new BidOpeningRoomOperatorShell(this);
//			bidOpeningRoomOperatorShell.open();
//			bidOpeningRoomOperatorShell.setAlpha(240);
//		}
//		return bidOpeningRoomOperatorShell.getOperatorParent();
//	}
	
//	public void clearOperator(){
//		if(null != bidOpeningRoomOperatorShell && !bidOpeningRoomOperatorShell.isDisposed()){
//			bidOpeningRoomOperatorShell.close();
//		}
//	}
//	public void refreshOperator(){
//		if(null != bidOpeningRoomOperatorShell && !bidOpeningRoomOperatorShell.isDisposed()){
//			bidOpeningRoomOperatorShell.refreshSize();
////			bidOpeningRoomOperatorShell.setAlpha(240);
////			setOperatorLoaction();
//		}
//	}
	
//	public void setOperatorRegion(Region region){
//		if(null != bidOpeningRoomOperatorShell && !bidOpeningRoomOperatorShell.isDisposed()){
//			bidOpeningRoomOperatorShell.setOperatorRegion(region);
//			bidOpeningRoomOperatorShell.setAlpha(240);
//			setOperatorLoaction();
//		}
//	}
//	private void setOperatorLoaction(){
//		if(null != bidOpeningRoomOperatorShell && !bidOpeningRoomOperatorShell.isDisposed()){
//			bidOpeningRoomOperatorShell.setLocation(Math.max((getBounds().width - bidOpeningRoomOperatorShell.getBounds().width)/2, 0), getBounds().height -  bidOpeningRoomOperatorShell.getBounds().height + 5);
//		}
//	}
//	
	/**
	 * @Description: 启动倒计时线程
	 * @author guoyr
	 */
	private void startCountTimeThread(Date countDownTime){
		if(null != countTimeThread){
			countTimeThread.stop();
			countTimeThread = null;
		}
		countTimeThread = new CountTimeThread(NowTimeUtils.getNowDate() , countDownTime, new CountTimeThread.CountTime() {
			Runnable drawRunnable = new Runnable(){
				public void run(){
					if(!rightBlackborad.isDisposed()){
						rightBlackborad.redraw();
					}
				}
			};
			public void countTime(final long day, final long hour, final long minute, final long second) {
				if(day > 0){
					countDownTimeStr[0] = "8";
					countDownTimeStr[1] = "8";
				}else {
					if(hour > 9){
						countDownTimeStr[0] = (hour+"").substring(0,1);
						countDownTimeStr[1] = (hour+"").substring(1);
					}else {
						countDownTimeStr[0] = "0";
						countDownTimeStr[1] = hour+"";
					}
				}
				if(minute > 9){
					countDownTimeStr[3] = (minute+"").substring(0,1);
					countDownTimeStr[4] = (minute+"").substring(1);
				}else {
					countDownTimeStr[3] = "0";
					countDownTimeStr[4] = minute+"";
				}
				if(second > 9){
					countDownTimeStr[6] = (second+"").substring(0,1);
					countDownTimeStr[7] = (second+"").substring(1);
				}else {
					countDownTimeStr[6] = "0";
					countDownTimeStr[7] = second+"";
				}
				Display.getDefault().asyncExec(drawRunnable);
				if(day == 0 && hour == 0 && minute == 0 && second == 0){
//					if(null != listener && null != countTimeThread){
//						listener.countTimeComplate();
//					}
					if(null != countTimeThread){
						countTimeThread.stop();
						countTimeThread = null;
					}
				}
				
			}
		});
		countTimeThread.start();
	}

	/**
	 * @Description: 退出会议室
	 * @author guoyr 
	 */
	public void exitMeetingRoom(){
		close();
	}
	
	public void close() {
		showNowTime = false;
		if(null != countTimeThread){
			countTimeThread.stop();
			countTimeThread = null;
		}
		if(null != zoomBgImage){
			zoomBgImage.dispose();
		}
		if(null != decStartTimer){
			decStartTimer.cancel();
		}
		if(null != decEndTimer){
			decEndTimer.cancel();
		}
		if(null != imageResolver){
			imageResolver.disposite();
		}
		
		super.close();
	}


	@Override
	public void clearOperator() {
		// TODO Auto-generated method stub
		
	}
}
