ingenias.generator.browser.GraphFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nodereled Show documentation
Show all versions of nodereled Show documentation
A simple node-relationship editor
/**
* Copyright (C) 2010 Jorge J. Gomez-Sanz
*
* This file is part of the INGENME tool. INGENME is an open source meta-editor
* which produces customized editors for user-defined modeling languages
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 3 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
**/
package ingenias.generator.browser;
import ingenias.editor.DiagramMenuEntriesActionsFactory;
import ingenias.editor.Editor;
import ingenias.editor.GUIResources;
import ingenias.editor.IDE;
import ingenias.editor.IDEState;
import ingenias.editor.Log;
import ingenias.editor.MarqueeHandler;
import ingenias.editor.Model;
import ingenias.editor.ModelJGraph;
import ingenias.editor.ObjectManager;
import ingenias.editor.Preferences;
import ingenias.editor.TypedVector;
import ingenias.editor.cell.NAryEdge;
import ingenias.editor.cell.RenderComponentManager;
import ingenias.editor.entities.Entity;
import ingenias.editor.entities.NAryEdgeEntity;
import ingenias.editor.entities.RoleEntity;
import ingenias.exception.InvalidAttribute;
import ingenias.exception.InvalidColection;
import ingenias.exception.InvalidEntity;
import ingenias.exception.InvalidGraph;
import ingenias.exception.InvalidPath;
import ingenias.exception.NotInitialised;
import ingenias.exception.NullEntity;
import ingenias.exception.WrongParameters;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.tree.TreePath;
import org.jgraph.JGraph;
import org.jgraph.graph.BasicMarqueeHandler;
import org.jgraph.graph.ConnectionSet;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.GraphCell;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.Port;
public class GraphFactory {
private IDEState ids;
public static GraphFactory createDefaultEmptyGraphFactory(){
return new GraphFactory(IDEState.emptyIDEState());
}
public static GraphFactory createDefaultGraphFactory(Browser browser) throws NotInitialised{
return new GraphFactory(browser.getState());
}
public GraphFactory(IDEState ids){
this.ids=ids;
}
public static Vector getSupportedRelationships(String diagramType) throws InvalidGraph, NotInitialised{
try {
Class diagram = Class.forName("ingenias.editor."+diagramType+"ModelJGraph");
Method m=diagram.getMethod("getAllowedRelationships", new Class[0]);
return (Vector ) m.invoke(diagram, new Object[0]);
} catch (ClassNotFoundException e) {
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph does not exist in the classpath");
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph is not accesible for security reasons");
} catch (NoSuchMethodException e) {
// There are diagrams that do not have this method. Those diagrams
// are not generated automatically
/*e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");*/
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");
}
return new Vector();
}
public static Vector getSupportedEntities(String diagramType) throws InvalidGraph, NotInitialised{
try {
Class diagram = Class.forName("ingenias.editor."+diagramType+"ModelJGraph");
Method m=diagram.getMethod("getAllowedEntities", new Class[0]);
return (Vector ) m.invoke(diagram, new Object[0]);
} catch (ClassNotFoundException e) {
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph does not exist in the classpath");
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph is not accesible for security reasons");
} catch (NoSuchMethodException e) {
/*e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");*/
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidGraph("Graph class ingenias.editor."+diagramType+"ModelJGraph has not that method");
}
return new Vector();
}
public static Vector getDiagramTypes() {
Vector result=new Vector();
File sources=new File("src/ingenias/editor");
String[] knownFiles = sources.list();
for (int k=0;k