/**
 * 
 */
package org.concord.otrunk.view;

import java.awt.BorderLayout;
import java.util.Hashtable;

import javax.swing.JFrame;

import org.concord.framework.otrunk.OTObject;
import org.concord.framework.otrunk.view.OTFrame;
import org.concord.framework.otrunk.view.OTFrameManager;
import org.concord.framework.otrunk.view.OTViewEntry;
import org.concord.framework.otrunk.view.OTViewFactory;

public class OTFrameManagerImpl implements OTFrameManager 
{
	Hashtable frameContainers = new Hashtable();
	OTViewFactory viewFactory;
	
	public class FrameContainer
	{
		OTViewContainerPanel container;
		JFrame frame;
	}
	
	public void setViewFactory(OTViewFactory viewFactory)
	{
		this.viewFactory = viewFactory;
	}
	
	public void putObjectInFrame(OTObject otObject, 
			OTFrame otFrame) 
	{
		putObjectInFrame(otObject, null, otFrame, null);
	}
	
	public void putObjectInFrame(OTObject otObject, 
			org.concord.framework.otrunk.view.OTViewEntry viewEntry,
			OTFrame otFrame) 
	{
		putObjectInFrame(otObject, viewEntry, otFrame, null);
	}

	/* (non-Javadoc)
	 * @see org.concord.framework.otrunk.view.OTFrameManager#putObjectInFrame(org.concord.framework.otrunk.OTObject, org.concord.framework.otrunk.view.OTViewEntry, org.concord.framework.otrunk.view.OTFrame, java.lang.String)
	 */
	public void putObjectInFrame(OTObject otObject, OTViewEntry viewEntry, OTFrame otFrame, String viewMode) 
	{
		// look up view container with the frame.
		FrameContainer frameContainer = 
			(FrameContainer)frameContainers.get(otFrame.getGlobalId());
		
		if(frameContainer == null) {
			JFrame jFrame = new JFrame(otFrame.getTitle());
	
			frameContainer = new FrameContainer();
			frameContainer.frame = jFrame;
			OTViewContainerPanel otContainer = new OTViewContainerPanel(this);
			otContainer.setTopLevelContainer(true);
			
			frameContainer.container = otContainer;			
			frameContainer.container.setOTViewFactory(viewFactory.createChildViewFactory());

			jFrame.getContentPane().setLayout(new BorderLayout());
	
			jFrame.getContentPane().add(otContainer, BorderLayout.CENTER);
			jFrame.setSize(otFrame.getWidth(), otFrame.getHeight());
			
			frameContainers.put(otFrame.getGlobalId(), frameContainer);
		}
		
		// call setCurrentObject on that view container with a null
		// frame
		frameContainer.container.setViewMode(viewMode);
		frameContainer.container.setCurrentObject(otObject, viewEntry, true);
		frameContainer.frame.setVisible(true);
	}
}
@@ -525,18 +525,88 @@
 actory;%0A
+%09private JFrame jFrame;%0A%09private int oldX = 0;%0A%09private int oldY = 0;%0A
 %09%0A
-
 %09public 
@@ -1460,16 +1460,232 @@
 de) %0A%09%7B%0A
+%09%09putObjectInFrame(otObject, viewEntry, otFrame, viewMode, 30, 30);%0A%09%7D%0A%09%0A%09public void putObjectInFrame(OTObject otObject, OTViewEntry viewEntry, OTFrame otFrame, String viewMode, %0A%09%09int positionX, int positionY) %0A%09%7B%0A
 %09%09// loo
@@ -1852,22 +1852,57 @@
 null
+ %7C%7C oldX != positionX %7C%7C oldY != positionY
 ) %7B%0A%09%09%09
-JFrame 
 jFra
@@ -2390,16 +2390,20 @@
 ENTER);%0A
+%09%09%09%0A
 %09%09%09jFram
@@ -2411,13 +2411,37 @@
 .set
-Size(
+Bounds(positionX, positionY, 
 otFr
@@ -2478,24 +2478,150 @@
 ght());%0A%09%09%09%0A
+%09%09%09oldX = positionX;%0A%09%09%09oldY = positionY;%0A%09%09%09%0A%09%09%09if (otFrame.getBorderlessPopup())%7B%0A%09%09%09%09jFrame.setUndecorated(true);%0A%09%09%09%7D%0A%09%09%09%0A
 %09%09%09frameCont
@@ -2869,24 +2869,24 @@
 try, true);%0A
-
 %09%09frameConta
@@ -2917,9 +2917,63 @@
 ue);%0A%09%7D%0A
+%09%0A%09public void distroyFrame()%7B%0A%09%09jFrame.dispose();%0A%09%7D%0A
 %7D

add x, y attributes to OTFrame, OTFrameManagerImpl can now handle them