/* $Id: UniSelectedState.java 454 2011-10-26 14:22:00Z minao $ */
package smart_gs.drawing_tool.state;

import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;

import smart_gs.connection.ConnectionCreator;
import smart_gs.drawing_tool.DrawingModeSelectionPopupMenu;
import smart_gs.drawing_tool.ImageLabel;
import smart_gs.drawing_tool.LineSegEditorRightClickMenu;
import smart_gs.drawing_tool.LineSegEditorCanvas;
import smart_gs.drawing_tool.RightClickMenu;
import smart_gs.drawing_tool.SpreadCanvas;
import smart_gs.drawing_tool.action.AddPointAction;
import smart_gs.drawing_tool.action.MemoPadTextAction;
import smart_gs.drawing_tool.drawing_mode.DefaultDrawingMode;
import smart_gs.drawing_tool.drawing_mode.EraserMode;
import smart_gs.drawing_tool.drawing_mode.LineSegEditorMode;
import smart_gs.drawing_tool.view.MemoPadView;
import smart_gs.drawing_tool.view.View;
import smart_gs.logical.Region;
import smart_gs.logical.LineSegment;
import smart_gs.logical.region.MemoPadRegion;
import smart_gs.reasoning_web.logical.GS_RWElement;
import smart_gs.reasoning_web.swingui.DirectLinkPanel;
import smart_gs.reasoning_web.swingui.GlobalViewPanel;
import smart_gs.reasoning_web.swingui.ReasoningWebFrame;
import smart_gs.swingui.GSMouseEvent;
import smart_gs.swingui.WorkspaceWindow;
import smart_gs.swingui.toolbar.ImageToolBar;
import smart_gs.swingui.toolbar.action.ShowLocalViewAction;
import smart_gs.util.ImageToolBarSetModeByMouseEvent;

public class LineSegEditorUniSelectedState implements LineSegEditorState{
	
	private static LineSegEditorUniSelectedState singleton = new LineSegEditorUniSelectedState();
	
	private boolean markupMovable = false;
	
	private Point start,end;
	private LineSegment selectedLineSeg;

	private boolean createArrowPointMode = false;
	private boolean deleteArrowPointMode = false;
	private boolean moveArrowPointMode = false;
	
	private LineSegEditorUniSelectedState(){
		
	}
	public static LineSegEditorUniSelectedState getInstance(){
		return singleton;
	}
	
	public void mouseClicked(GSMouseEvent e, LineSegEditorCanvas canvas) {
		/* this works only when a region is selected and exclusively on it */
		if(this.selectedLineSeg == null){
			return;
		}
		View view = this.selectedLineSeg.getView();
		if(e.getButton() == MouseEvent.BUTTON3){
			rightButtonClickAction(e,canvas);
		}else if(e.getButton() == MouseEvent.BUTTON1){
			if ((e.getClickCount() == 2) && 
					(view.getType() == View.MEMOPAD) && 
					(view.contains(e.getPoint2D()))) {
				new MemoPadTextAction(this.selectedLineSeg).actionPerformed(e);
			} else if (WorkspaceWindow.getInstance().onlyOneOfAltCtrlShiftIsPressed()) {
				if(WorkspaceWindow.getInstance().isAlt()){
					/* alternative for right button click */
					rightButtonClickAction(e,canvas);
				} else if(WorkspaceWindow.getInstance().isCtrl()){
					DefaultState.getInstance()
					.setMode(DefaultDrawingMode.getInstance());
					new ImageToolBarSetModeByMouseEvent().setMode(e,ImageToolBar.modeNone);
				}
			}
		}
	}

	private void rightButtonClickAction (GSMouseEvent e, LineSegEditorCanvas canvas) {
		JPopupMenu menu = new LineSegEditorRightClickMenu(this.selectedLineSeg, canvas, this);
		menu.show(e.getComponent(),e.getOriginalPoint().x,e.getOriginalPoint().y);
		GlobalViewPanel.getInstance().repaint();
	}
	
	public void mouseDragged(GSMouseEvent e, LineSegEditorCanvas canvas) {
	}

	public void mouseEntered(GSMouseEvent e, LineSegEditorCanvas canvas) {
		canvas.repaint();
	}

	public void mouseExited(GSMouseEvent e, LineSegEditorCanvas canvas) {
	}

	public void mouseMoved(GSMouseEvent e, LineSegEditorCanvas canvas) {
	}

	public void mousePressed(GSMouseEvent e, LineSegEditorCanvas canvas) {
	}


	public void mouseReleased(GSMouseEvent e, LineSegEditorCanvas canvas) {
	}

	public void paint(Graphics g, LineSegEditorCanvas canvas) {
	}
	
	@Override
	public int getType() {
		return State.UNISELECTED;
	}
	@Override
	public LineSegEditorMode getMode() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void setMode(LineSegEditorMode mode) {
		// TODO Auto-generated method stub
		
	}	
}

