Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright (C) 2002 Jorge Gomez Sanz
This file is part of INGENIAS IDE, a support tool for the INGENIAS
methodology, availabe at http://grasia.fdi.ucm.es/ingenias or
http://ingenias.sourceforge.net
INGENIAS IDE 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; either version 2 of the License, or
(at your option) any later version.
INGENIAS IDE 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 INGENIAS IDE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package ingenias.editor;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.util.*;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
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.InvalidEntity;
import ingenias.exception.WrongParameters;
import org.jgraph.graph.CellView;
import org.jgraph.graph.ConnectionSet;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphCell;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.Port;
public class RelationshipManager implements java.io.Serializable {
private static Vector loadedRelationships=new Vector();
// private static Hashtable extremes=new Hashtable();
public RelationshipManager(){
}
/* public static RelationshipManager createIndependentCopy(){
RelationshiObjectManager om=new ObjectManager(gm,root,arbolObjetos);
return om;
}
public static void updateCopy(ObjectManager copyom){
om=copyom;
}*/
public static void addRelationship(Entity nedge){
if (!loadedRelationships.contains(nedge))
loadedRelationships.add(nedge);
}
/* public static void putDGC(String dgcid, DefaultGraphCell dgc){
extremes.put(dgcid,dgc);
}
public DefaultGraphCell getDGC(String dgcid){
return (DefaultGraphCell)extremes.get(dgcid);
}*/
public static void removeRelationship(Entity nedge){
loadedRelationships.remove(nedge);
}
public static Entity getRelationship(String nedge){
Enumeration enumeration=loadedRelationships.elements();
while (enumeration.hasMoreElements()){
Entity ent=(Entity)enumeration.nextElement();
if (ent.getId().equalsIgnoreCase(nedge))
return ent;
}
return null;
}
public static Vector getRelationshipsVector(GraphManager gm){
Enumeration graphs=gm.getUOModels().elements();
Vector result=new Vector();
while (graphs.hasMoreElements()){
ModelJGraph jg=(ModelJGraph) graphs.nextElement();
for (int k=0;k 1) {
JComboBox pops = new JComboBox(possibleRelationships);
JPanel temp = new JPanel();
temp.add(new JLabel("Select one of the following relationships"));
temp.add(pops);
int result = JOptionPane.showConfirmDialog(graph, temp,
"Valid Relationships",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
int sel = pops.getSelectedIndex();
if (sel >= 0 && result == JOptionPane.OK_OPTION) {
index = sel;
}
} else {
index=0;
}
return index;
}
// Connect the selected GraphCells with a relationship.
// A relationship can be binary (DefaultEdge) or n-ary (NAryEdge).
// pt where user asks for connection and ports if user selected them.
// The requested action is slightly different depending on selected items.
// According to the number of Edges in selected, the action can be:
// 0 => Propose a relationship between selected and connect them with
// a new relationship.
// 1 and it is NAryEdge => Connect the remaining GraphCells with that NAryEdge.
// other cases => Error unable to connect.
/**
* Gets the port attribute of the Editor object
*
*@param vertexNode Description of Parameter
*@return The port value
*/
public static Port getPort(Object vertexNode, ModelJGraph graph) {
GraphModel model = graph.getModel();
// Iterate over all Children
for (int i = 0; i < model.getChildCount(vertexNode); i++) {
// Fetch the Child of Vertex at Index i
Object child = model.getChild(vertexNode, i);
// Check if Child is a Port
if (child instanceof Port) {
// Return the Child as a Port
return (Port) child;
}
}
// No Ports Found
return null;
}
// Gives the ports in the model related with GraphCells in vertexList.
public static Port[] getPorts(Object[] vertexList, ModelJGraph graph) {
// Ports of argument vertexs.
Port[] ports = new Port[vertexList.length];
// Obtain the model.
GraphModel model = graph.getModel();
// Iterate over all Objects.
for (int i = 0; i < vertexList.length; i++) {
Port objectPort = null;
// Iterate over all Children
for (int j = 0; j < model.getChildCount(vertexList[i]); j++) {
// Fetch the Child of Vertex at Index i
Object child = model.getChild(vertexList[i], j);
// Check if Child is a Port
if (child instanceof Port) {
// Return the Child as a Port
objectPort = (Port) child;
}
}
ports[i] = objectPort;
}
return ports;
}
// Atributes for the binary edges of this NAryEdge according to targets and sources.
private static Hashtable edgesAttributes(DefaultEdge[] edges,
String[] roleAssignation) {
Hashtable edgesAttributes = new Hashtable();
for (int i = 0; i < roleAssignation.length; i++) {
// Create a Map that holds the attributes for the edge
RoleEntity re = (RoleEntity) edges[i].getUserObject();
Map attr = re.getAttributes();
// Source
/*if (selectedAssignation[i].indexOf("source") >= 0)
// Add a Line Begin Attribute
GraphConstants.setLineBegin(attr, GraphConstants.SIMPLE);*/
// Target
if (roleAssignation[i].toUpperCase().indexOf("TARGET") >= 0 ||
roleAssignation[i].endsWith("T")) {
// Add a Line End Attribute
GraphConstants.setLineEnd(attr, GraphConstants.ARROW_SIMPLE);
// Associate the Edge with its Attributes
}
GraphConstants.setDisconnectable(attr,false);
GraphConstants.setLineWidth(attr, 1);
GraphConstants.setEndSize(attr, 7);
GraphConstants.setBendable(attr,false);
edgesAttributes.put(edges[i], attr);
}
return edgesAttributes;
}
private static Point calculateCenter(GraphCell[] selected){
int x=0;
int y=0;
for (int k=0;k Propose a relationship between selected and connect them with
// a new relationship.
// 1 and it is NAryEdge => Connect the remaining GraphCells with that NAryEdge.
// other cases => Error unable to connect.
public static NAryEdge connect(Point pt, GraphCell[] selected, ModelJGraph graph, Vector allowedRelationships) {
// Possible edges.
Object[] nops = graph.getPossibleRelationships(selected);
Vector