package ls.graph;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import ls.graph.script.AlgorithmListener;
import ls.graph.script.GraphScriptEngine;
import ls.graph.script.ScriptableGraph;
import ls.graph.ui.GraphInternalFrame;
public class GraphController implements ControlListener, InternalFrameListener
{
private GraphInternalFrame graphFrame = null;
private GraphScriptEngine scriptEngine = null;
private List<ControlListener> localControlListeners = new LinkedList<ControlListener>();
private Controller globalController = null;
GraphController(GraphInternalFrame gf,Controller controller)
{
super();
if (controller == null)
throw new IllegalArgumentException("GraphController: Controller cannot be null");
if (gf == null)
throw new IllegalArgumentException("GraphController: Internal frame cannot be null");
this.globalController = controller;
this.graphFrame = gf;
gf.setGraphController(this);
gf.addInternalFrameListener(this);
this.scriptEngine = new GraphScriptEngine(this);
}
public GraphInternalFrame frame() { return graphFrame; }
public ScriptableGraph graph() { return frame().getGraph(); }
public void addControlListener(ControlListener l)
{
if (l != null) this.localControlListeners.add(l);
}
GraphScriptEngine scriptEngine() { return this.scriptEngine; }
public void addAlgorithmListener(AlgorithmListener l)
{
if (l != null)
this.frame().addAlgorithmListener(l);
}
public void graphChanged(ScriptableGraph sg)
{
for (ControlListener l : localControlListeners)
l.graphChanged(sg);
}
public void graphLoaded(File graphFile)
{
this.frame().setTitle(graphFile.getName());
for (ControlListener l : localControlListeners)
l.graphLoaded(graphFile);
}
public void scriptLoaded(File scriptFile, String scriptText)
{
for (ControlListener l : localControlListeners)
l.scriptLoaded(scriptFile, scriptText);
}
public void internalFrameActivated(InternalFrameEvent arg0)
{
this.globalController.fireGraphChanged(this.graph());
}
public void internalFrameClosed(InternalFrameEvent arg0)
{
// TODO Auto-generated method stub
}
public void internalFrameClosing(InternalFrameEvent arg0)
{
// TODO Auto-generated method stub
}
public void internalFrameDeactivated(InternalFrameEvent arg0)
{
// TODO Auto-generated method stub
}
public void internalFrameDeiconified(InternalFrameEvent arg0)
{
// TODO Auto-generated method stub
}
public void internalFrameIconified(InternalFrameEvent arg0)
{
// TODO Auto-generated method stub
}
public void internalFrameOpened(InternalFrameEvent arg0)
{
// TODO Auto-generated method stub
}
} //end of GraphController class