package smart_gs.menu.action;

import java.awt.Canvas;
import java.awt.Point;
import java.awt.Rectangle;

import smart_gs.drawing_tool.ImageLabel;
import smart_gs.drawing_tool.SpreadCanvas;
import smart_gs.drawing_tool.state.UniSelectedState;
import smart_gs.drawing_tool.view.RectangleView;
import smart_gs.drawing_tool.view.View;
import smart_gs.logical.Region;
import smart_gs.logical.Spread;
import smart_gs.logical.TextSegment;
import smart_gs.logical.region.BookmarkRegion;
import smart_gs.logical.region.RectangleRegion;
import smart_gs.logical.visitor.ShowResourceVisitor;
import smart_gs.smleditor.swingui.GSEditor;
import smart_gs.swingui.WorkspaceWindow;

public class SpreadOpenAction {
	
	public static void open(Spread spread) {
		if(spread == null){
			return;
		}
		WorkspaceWindow.getInstance().tabbedPaneSave();
		GSEditor editor = new GSEditor(spread);
		editor.setVisible(true);
	}

	public static void openMarkup(Region region) {
		Spread spread = region.getSpread();
		if(spread == null){
			return;
		}
		WorkspaceWindow.getInstance().tabbedPaneSave();
		GSEditor editor = new GSEditor(spread);
		editor.setVisible(true);
		editor.getSpreadCanvas().imageLabel.moveTo(region.getCenterPoint());
		editor.getSpreadCanvas().selectRegion(region);
	}
	
	public static void openMarkup(TextSegment segment) {
		ShowResourceVisitor visitor = new ShowResourceVisitor();
		visitor.visit(segment);
	}

	public static void openTempRectangleRegion(RectangleRegion rectreg) {
		Rectangle rect = rectreg.getRectangle();
		Spread spread = rectreg.getSpread();
		WorkspaceWindow window = WorkspaceWindow.getInstance();
		if(spread == null){
			return;
		}
		WorkspaceWindow.getInstance().tabbedPaneSave();
		GSEditor editor = new GSEditor(spread);
		SpreadCanvas spreadCanvas = editor.getSpreadCanvas();
		spreadCanvas.imageLabel.moveTo(rectreg.getCenterPoint());
		View view = new RectangleView(rect);
		view.setIsEmphasized(true);
		spreadCanvas.addTempView(view);
		ImageLabel.setState(UniSelectedState.getInstance());
		spreadCanvas.selectRegion(rectreg);
		editor.setVisible(true);
	}

}
