ingenias.editor.panels.SocialSpecDiagramPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sociaalmled Show documentation
Show all versions of sociaalmled Show documentation
A editor for modelling scenarios for PHAT simulator
The newest version!
/**
* Copyright (C) 2010 Jorge J. Gomez-Sanz over original code from Ruben Fuentes and Juan Pavon
*
* Modifications over original code from jgraph.sourceforge.net
*
* 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.editor.panels;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.util.Map;
import java.util.Hashtable;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.URL;
import java.util.Map;
import java.util.Hashtable;
import java.util.ArrayList;
import javax.swing.event.UndoableEditEvent;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import org.jgraph.event.*;
import java.util.Vector;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import org.jgraph.event.*;
import org.jgraph.plaf.basic.*;
import ingenias.editor.entities.*;
import ingenias.editor.cell.*;
import ingenias.editor.events.*;
import ingenias.exception.InvalidEntity;
import ingenias.editor.*;
public class SocialSpecDiagramPanel extends JGraph {
public SocialSpecDiagramPanel(SocialSpecDiagramDataEntity mde,
String nombre, Model
m, BasicMarqueeHandler mh) {
super(m, mh);
this.getGraphLayoutCache().setFactory(new ingenias.editor.cellfactories.SocialSpecDiagramCellViewFactory());
}
//
// Adding Tooltips
//
// Return Cell Label as a Tooltip
public String getToolTipText(MouseEvent e) {
if (e != null) {
// Fetch Cell under Mousepointer
Object c = getFirstCellForLocation(e.getX(), e.getY());
if (c != null) {
// Convert Cell to String and Return
return convertValueToString(c);
}
}
return null;
}
public static Vector getAllowedEntities(){
Vector entities=new Vector();
entities.add("Human");
entities.add("Profession");
entities.add("SBuilding");
entities.add("PersonalInfo");
entities.add("SocialNetwork");
return entities;
}
public DefaultGraphCell createCell(String entity) throws InvalidEntity{
if (entity.equalsIgnoreCase("Human")) {
Human nentity=new Human(((Model)getModel()).getNewId("Human"));
DefaultGraphCell vertex = new
HumanCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("Profession")) {
Profession nentity=new Profession(((Model)getModel()).getNewId("Profession"));
DefaultGraphCell vertex = new
ProfessionCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("SBuilding")) {
SBuilding nentity=new SBuilding(((Model)getModel()).getNewId("SBuilding"));
DefaultGraphCell vertex = new
SBuildingCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("PersonalInfo")) {
PersonalInfo nentity=new PersonalInfo(((Model)getModel()).getNewId("PersonalInfo"));
DefaultGraphCell vertex = new
PersonalInfoCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
if (entity.equalsIgnoreCase("SocialNetwork")) {
SocialNetwork nentity=new SocialNetwork(((Model)getModel()).getNewId("SocialNetwork"));
DefaultGraphCell vertex = new
SocialNetworkCell(nentity);
// Default Size for the cell with the new entity
return vertex;
}
else
throw new ingenias.exception.InvalidEntity("Entity type "+entity+" is not allowed in this diagram");
}
public Dimension getDefaultSize(Entity entity) throws InvalidEntity{
if (entity.getType().equalsIgnoreCase("Human")) {
return HumanView.getSize((Human)entity);
}
else
if (entity.getType().equalsIgnoreCase("Profession")) {
return ProfessionView.getSize((Profession)entity);
}
else
if (entity.getType().equalsIgnoreCase("SBuilding")) {
return SBuildingView.getSize((SBuilding)entity);
}
else
if (entity.getType().equalsIgnoreCase("PersonalInfo")) {
return PersonalInfoView.getSize((PersonalInfo)entity);
}
else
if (entity.getType().equalsIgnoreCase("SocialNetwork")) {
return SocialNetworkView.getSize((SocialNetwork)entity);
}
else
throw new ingenias.exception.InvalidEntity("Entity type "+entity+" is not allowed in this diagram");
}
public DefaultGraphCell insert(Point point, String entity) throws InvalidEntity {
// CellView information is not available after creating the cell.
// Create a Map that holds the attributes for the Vertex
Map map = new Hashtable();
// Snap the Point to the Grid
// Construct Vertex with no Label
DefaultGraphCell vertex;
Dimension size;
vertex=this.createCell(entity);
size=this.getDefaultSize((Entity)vertex.getUserObject());
// Add a Bounds Attribute to the Map
GraphConstants.setBounds(map, new Rectangle(point, size));
// Construct a Map from cells to Maps (for insert)
Hashtable attributes = new Hashtable();
// Associate the Vertex with its Attributes
attributes.put(vertex, map);
// Insert the Vertex and its Attributes
this.getModel().insert(new Object[] {vertex},attributes
, null, null, null);
return vertex;
}
public DefaultGraphCell insertDuplicated(Point point, ingenias.editor.entities.Entity
entity) {
// CellView information is not available after creating the cell.
// Create a Map that holds the attributes for the Vertex
Map map =new Hashtable();
// Snap the Point to the Grid
// Construct Vertex with no Label
DefaultGraphCell vertex = null;
Dimension size = null;
if (entity.getClass().equals(Human.class)) {
vertex = new HumanCell( (Human) entity);
// Default Size for the new Vertex with the new entity within
size = HumanView.getSize((Human) entity);
}
else
if (entity.getClass().equals(Profession.class)) {
vertex = new ProfessionCell( (Profession) entity);
// Default Size for the new Vertex with the new entity within
size = ProfessionView.getSize((Profession) entity);
}
else
if (entity.getClass().equals(SBuilding.class)) {
vertex = new SBuildingCell( (SBuilding) entity);
// Default Size for the new Vertex with the new entity within
size = SBuildingView.getSize((SBuilding) entity);
}
else
if (entity.getClass().equals(PersonalInfo.class)) {
vertex = new PersonalInfoCell( (PersonalInfo) entity);
// Default Size for the new Vertex with the new entity within
size = PersonalInfoView.getSize((PersonalInfo) entity);
}
else
if (entity.getClass().equals(SocialNetwork.class)) {
vertex = new SocialNetworkCell( (SocialNetwork) entity);
// Default Size for the new Vertex with the new entity within
size = SocialNetworkView.getSize((SocialNetwork) entity);
}
else
{}; // Just in case there is no allowed entity in the diagram
if (vertex == null) {
System.err.println(
"Object not allowed in SocialSpecDiagram diagram :"+
entity.getId()+":"+entity.getClass().getName()+
this.getClass().getName()); }
else {
// Add a Bounds Attribute to the Map
GraphConstants.setBounds(map, new Rectangle(point, size));
// Construct a Map from cells to Maps (for insert)
Hashtable attributes = new Hashtable();
// Associate the Vertex with its Attributes
attributes.put(vertex, map);
// Insert the Vertex and its Attributes
this.getModel().insert(new Object[] {vertex},attributes
, null, null, null);
}
return vertex;
}
}