package ls.graph.ui;
import java.lang.reflect.Constructor;
import ls.util.Utils;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.visualization.FRLayout;
import edu.uci.ics.jung.visualization.Layout;
import edu.uci.ics.jung.visualization.SpringLayout;
import edu.uci.ics.jung.visualization.contrib.CircleLayout;
import edu.uci.ics.jung.visualization.contrib.KKLayout;
public enum LayoutType
{
CIRCLE(CircleLayout.class, "Circle"),
SPRING(SpringLayout.class, "Spring"),
//TREE(TreeLayout.class,"Tree"),
FR(FRLayout.class,"FR Layout"),
KK(KKLayout.class,"KK Layout");
private Constructor<? extends Layout> constructor = null;
private String name = null;
LayoutType(Class<? extends Layout> layoutClass, String n)
{
try
{
constructor = layoutClass.getConstructor(new Class<?>[] {Graph.class});
}
catch (Exception exn) { Utils.exn(exn); constructor = null; }
name = n;
}
public String getName() { return this.name; }
public Layout createLayout(Graph g)
{
try
{
if (constructor != null)
return (Layout)(constructor.newInstance(new Object[] {g}));
else throw new Exception("Layout constructor is null");
}
catch (Exception exn)
{
Utils.exn(exn);
}
return null;
}
public String toString() { return this.getName(); }
}