package template;

import java.awt.AWTEvent;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;

import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.tree.DefaultMutableTreeNode;

import de.cbse.jeasy.JEFrame;
import de.cbse.jeasy.JEObject;
import de.cbse.jeasy.JEUtil;

/**
 * @author   Harry Pfohl
 */
public class Client {
	public static final int CLIENTMODE = 0;
	public static final int SERVERMODE = 1;
	private CallBack cb = null;
	boolean maximized = false;
	boolean minimized = false;
	Point mouseDraggedStart;

	public Client() {
		cb = CallBack.getInstance();
		// JEWindow jewindow = (JEWindow) JEUtil.getJO(JEIds.WI_MAIN);
		JEFrame jewindow = (JEFrame) JEUtil.getJO(JEIds.FR_MAIN);
		new CallBackAdresses();
		new CallBackPanelA();
		new CallBackPanelB();
	}

	
	public void BT_AF_TB_Previous(){
		System.out.println("Client.BT_AF_TB_Previous()");
	}
	
	/**
	 * Exits the application
	 */
	public void BT_Exit() {
		closeApplication();
	}

	/**
	 * Closes the Message dialog
	 */
	public void BT_Message_Ok() {
	//		((JEDialog) JEUtil.getJO(JEIds.DL_MESSAGE)).setVisible(false);
	}

	public void MI_Open() {
		System.out.println("Client.MI_Open() " + "MenuItem Open was pressed");
	}

	public void MI_About() {
		System.out.println("Client.MI_About() " + "MenuItem About was pressed");
	}

	public void MI_Help() {
		System.out.println("Client.MI_Help() " + "MenuItem Help was pressed");
	}

	private void closeApplication() {
		System.exit(0);
	}

	public void performDocumentEvent(DocumentEvent e, String id) {}

	public void performId(String id) {

	}

	public void performMouseEvent(MouseEvent e, String id) {
		performMouseEvent(e, id, null, null);
	}

	public void performMouseEvent(MouseEvent e, String id, String idNode) {
		performMouseEvent(e, id, idNode, null);
	}

	public void performMouseEvent(MouseEvent e, String id, String idNode, DefaultMutableTreeNode dmt) {
		// System.out.println("Client.performMouseEvent() id = " + id);
		int eid = e.getID();
		JEObject jeo = JEUtil.getJO(id);
		int button = e.getButton();
		int clicks = e.getClickCount();
		switch (eid) {
		case MouseEvent.MOUSE_PRESSED:
			if (SwingUtilities.isRightMouseButton(e)) {}
			if (SwingUtilities.isLeftMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Left Button Pressed " + clicks+" in "+id);
			}
			if (SwingUtilities.isMiddleMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Middle Button Pressed " + clicks+" in "+id);
			}
			return;
		case MouseEvent.MOUSE_RELEASED:
			mouseDraggedStart = null;
			if (SwingUtilities.isRightMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Right Button Released " + clicks+" in "+id);
			}
			if (SwingUtilities.isLeftMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Left Button Released " + clicks+" in "+id);
			}
			if (SwingUtilities.isMiddleMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Middle Button Released " + clicks+" in "+id);
			}
			return;
		case MouseEvent.MOUSE_CLICKED:
			if (SwingUtilities.isRightMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Right Button Clicked " + clicks+" in "+id);
			}
			if (SwingUtilities.isLeftMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Left Button Clicked " + clicks+" in "+id);
			}
			if (SwingUtilities.isMiddleMouseButton(e)) {
				//				System.out.println("Client.performMouseEvent() Middle Button Clicked " + clicks+" in "+id);
			}
			return;
		case MouseEvent.MOUSE_ENTERED:
			return;
		case MouseEvent.MOUSE_EXITED:
			GUIUtils.setWaitCursor(false);
			return;
		case MouseEvent.MOUSE_MOVED:
			return;
		case MouseEvent.MOUSE_DRAGGED:
			return;
		case MouseEvent.MOUSE_WHEEL:
			return;
		}
	}

	/**
	 * A tabbedpane was selected. Show the first BusinessObject if the panel is empty
	 * @param id
	 */
	public void performTabbedPane(String id) {}


	/**
	 * If the frame is indecorated the changes of the frame by the windows taskbar must passed forward to the window.
	 * @param e
	 * @param id
	 */
	public void frameChanged(AWTEvent e, String id) {
		if (e.getID() == MouseEvent.MOUSE_MOVED || e.getID() == MouseEvent.MOUSE_EXITED)
			return;
		if (e.getID() == WindowEvent.WINDOW_ACTIVATED || e.getID() == WindowEvent.WINDOW_OPENED)
			return;
		if (e.getID() == WindowEvent.WINDOW_ICONIFIED || e.getID() == WindowEvent.WINDOW_DEICONIFIED) {} else if (e.getID() == WindowEvent.WINDOW_CLOSING) {
			closeApplication();
		} else
			return;
	}
}