All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ingenias.editor.panels.SimulationDiagramPanel Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show 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 SimulationDiagramPanel extends JGraph {

  public SimulationDiagramPanel(SimulationDiagramDataEntity mde, 
                               String nombre, Model
                               m, BasicMarqueeHandler mh) {
    super(m, mh);
    
    this.getGraphLayoutCache().setFactory(new ingenias.editor.cellfactories.SimulationDiagramCellViewFactory());
  }


  //
  // 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("FTable");

 entities.add("SBathroom");

 entities.add("AndroidApplication");

 entities.add("SDate");

 entities.add("Human");

 entities.add("SKitchen");

 entities.add("PartOfBody");

 entities.add("FlyCamInit");

 entities.add("WorldInitialization");

 entities.add("AndroidEmulator");

 entities.add("SBedroom");

 entities.add("SCorridor");

 entities.add("PDSymtom");

 entities.add("SArea");

 entities.add("ESmartPhone");

 entities.add("HumanInitialization");

 entities.add("BActivity");

 entities.add("CameraInit");

 entities.add("SymptomInitialization");

 entities.add("SLivingroom");

   return entities;
  }

 
   
  public DefaultGraphCell createCell(String entity) throws InvalidEntity{
  
    if (entity.equalsIgnoreCase("FTable")) {
    FTable nentity=new FTable(((Model)getModel()).getNewId("FTable"));
      DefaultGraphCell vertex = new
          FTableCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("SBathroom")) {
    SBathroom nentity=new SBathroom(((Model)getModel()).getNewId("SBathroom"));
      DefaultGraphCell vertex = new
          SBathroomCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("AndroidApplication")) {
    AndroidApplication nentity=new AndroidApplication(((Model)getModel()).getNewId("AndroidApplication"));
      DefaultGraphCell vertex = new
          AndroidApplicationCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("SDate")) {
    SDate nentity=new SDate(((Model)getModel()).getNewId("SDate"));
      DefaultGraphCell vertex = new
          SDateCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    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("SKitchen")) {
    SKitchen nentity=new SKitchen(((Model)getModel()).getNewId("SKitchen"));
      DefaultGraphCell vertex = new
          SKitchenCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("PartOfBody")) {
    PartOfBody nentity=new PartOfBody(((Model)getModel()).getNewId("PartOfBody"));
      DefaultGraphCell vertex = new
          PartOfBodyCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("FlyCamInit")) {
    FlyCamInit nentity=new FlyCamInit(((Model)getModel()).getNewId("FlyCamInit"));
      DefaultGraphCell vertex = new
          FlyCamInitCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("WorldInitialization")) {
    WorldInitialization nentity=new WorldInitialization(((Model)getModel()).getNewId("WorldInitialization"));
      DefaultGraphCell vertex = new
          WorldInitializationCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("AndroidEmulator")) {
    AndroidEmulator nentity=new AndroidEmulator(((Model)getModel()).getNewId("AndroidEmulator"));
      DefaultGraphCell vertex = new
          AndroidEmulatorCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("SBedroom")) {
    SBedroom nentity=new SBedroom(((Model)getModel()).getNewId("SBedroom"));
      DefaultGraphCell vertex = new
          SBedroomCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("SCorridor")) {
    SCorridor nentity=new SCorridor(((Model)getModel()).getNewId("SCorridor"));
      DefaultGraphCell vertex = new
          SCorridorCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("PDSymtom")) {
    PDSymtom nentity=new PDSymtom(((Model)getModel()).getNewId("PDSymtom"));
      DefaultGraphCell vertex = new
          PDSymtomCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("SArea")) {
    SArea nentity=new SArea(((Model)getModel()).getNewId("SArea"));
      DefaultGraphCell vertex = new
          SAreaCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("ESmartPhone")) {
    ESmartPhone nentity=new ESmartPhone(((Model)getModel()).getNewId("ESmartPhone"));
      DefaultGraphCell vertex = new
          ESmartPhoneCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("HumanInitialization")) {
    HumanInitialization nentity=new HumanInitialization(((Model)getModel()).getNewId("HumanInitialization"));
      DefaultGraphCell vertex = new
          HumanInitializationCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("BActivity")) {
    BActivity nentity=new BActivity(((Model)getModel()).getNewId("BActivity"));
      DefaultGraphCell vertex = new
          BActivityCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("CameraInit")) {
    CameraInit nentity=new CameraInit(((Model)getModel()).getNewId("CameraInit"));
      DefaultGraphCell vertex = new
          CameraInitCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("SymptomInitialization")) {
    SymptomInitialization nentity=new SymptomInitialization(((Model)getModel()).getNewId("SymptomInitialization"));
      DefaultGraphCell vertex = new
          SymptomInitializationCell(nentity);
      // Default Size for the cell with the new entity
     return vertex;
    }
    else

    if (entity.equalsIgnoreCase("SLivingroom")) {
    SLivingroom nentity=new SLivingroom(((Model)getModel()).getNewId("SLivingroom"));
      DefaultGraphCell vertex = new
          SLivingroomCell(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("FTable")) {
      return FTableView.getSize((FTable)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SBathroom")) {
      return SBathroomView.getSize((SBathroom)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("AndroidApplication")) {
      return AndroidApplicationView.getSize((AndroidApplication)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SDate")) {
      return SDateView.getSize((SDate)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("Human")) {
      return HumanView.getSize((Human)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SKitchen")) {
      return SKitchenView.getSize((SKitchen)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("PartOfBody")) {
      return PartOfBodyView.getSize((PartOfBody)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("FlyCamInit")) {
      return FlyCamInitView.getSize((FlyCamInit)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("WorldInitialization")) {
      return WorldInitializationView.getSize((WorldInitialization)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("AndroidEmulator")) {
      return AndroidEmulatorView.getSize((AndroidEmulator)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SBedroom")) {
      return SBedroomView.getSize((SBedroom)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SCorridor")) {
      return SCorridorView.getSize((SCorridor)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("PDSymtom")) {
      return PDSymtomView.getSize((PDSymtom)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SArea")) {
      return SAreaView.getSize((SArea)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("ESmartPhone")) {
      return ESmartPhoneView.getSize((ESmartPhone)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("HumanInitialization")) {
      return HumanInitializationView.getSize((HumanInitialization)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("BActivity")) {
      return BActivityView.getSize((BActivity)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("CameraInit")) {
      return CameraInitView.getSize((CameraInit)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SymptomInitialization")) {
      return SymptomInitializationView.getSize((SymptomInitialization)entity);      
    }
    else

    if (entity.getType().equalsIgnoreCase("SLivingroom")) {
      return SLivingroomView.getSize((SLivingroom)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(FTable.class)) {
      vertex = new FTableCell( (FTable) entity);
      // Default Size for the new Vertex with the new entity within
      size = FTableView.getSize((FTable) entity);
    }
    else

    if (entity.getClass().equals(SBathroom.class)) {
      vertex = new SBathroomCell( (SBathroom) entity);
      // Default Size for the new Vertex with the new entity within
      size = SBathroomView.getSize((SBathroom) entity);
    }
    else

    if (entity.getClass().equals(AndroidApplication.class)) {
      vertex = new AndroidApplicationCell( (AndroidApplication) entity);
      // Default Size for the new Vertex with the new entity within
      size = AndroidApplicationView.getSize((AndroidApplication) entity);
    }
    else

    if (entity.getClass().equals(SDate.class)) {
      vertex = new SDateCell( (SDate) entity);
      // Default Size for the new Vertex with the new entity within
      size = SDateView.getSize((SDate) entity);
    }
    else

    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(SKitchen.class)) {
      vertex = new SKitchenCell( (SKitchen) entity);
      // Default Size for the new Vertex with the new entity within
      size = SKitchenView.getSize((SKitchen) entity);
    }
    else

    if (entity.getClass().equals(PartOfBody.class)) {
      vertex = new PartOfBodyCell( (PartOfBody) entity);
      // Default Size for the new Vertex with the new entity within
      size = PartOfBodyView.getSize((PartOfBody) entity);
    }
    else

    if (entity.getClass().equals(FlyCamInit.class)) {
      vertex = new FlyCamInitCell( (FlyCamInit) entity);
      // Default Size for the new Vertex with the new entity within
      size = FlyCamInitView.getSize((FlyCamInit) entity);
    }
    else

    if (entity.getClass().equals(WorldInitialization.class)) {
      vertex = new WorldInitializationCell( (WorldInitialization) entity);
      // Default Size for the new Vertex with the new entity within
      size = WorldInitializationView.getSize((WorldInitialization) entity);
    }
    else

    if (entity.getClass().equals(AndroidEmulator.class)) {
      vertex = new AndroidEmulatorCell( (AndroidEmulator) entity);
      // Default Size for the new Vertex with the new entity within
      size = AndroidEmulatorView.getSize((AndroidEmulator) entity);
    }
    else

    if (entity.getClass().equals(SBedroom.class)) {
      vertex = new SBedroomCell( (SBedroom) entity);
      // Default Size for the new Vertex with the new entity within
      size = SBedroomView.getSize((SBedroom) entity);
    }
    else

    if (entity.getClass().equals(SCorridor.class)) {
      vertex = new SCorridorCell( (SCorridor) entity);
      // Default Size for the new Vertex with the new entity within
      size = SCorridorView.getSize((SCorridor) entity);
    }
    else

    if (entity.getClass().equals(PDSymtom.class)) {
      vertex = new PDSymtomCell( (PDSymtom) entity);
      // Default Size for the new Vertex with the new entity within
      size = PDSymtomView.getSize((PDSymtom) entity);
    }
    else

    if (entity.getClass().equals(SArea.class)) {
      vertex = new SAreaCell( (SArea) entity);
      // Default Size for the new Vertex with the new entity within
      size = SAreaView.getSize((SArea) entity);
    }
    else

    if (entity.getClass().equals(ESmartPhone.class)) {
      vertex = new ESmartPhoneCell( (ESmartPhone) entity);
      // Default Size for the new Vertex with the new entity within
      size = ESmartPhoneView.getSize((ESmartPhone) entity);
    }
    else

    if (entity.getClass().equals(HumanInitialization.class)) {
      vertex = new HumanInitializationCell( (HumanInitialization) entity);
      // Default Size for the new Vertex with the new entity within
      size = HumanInitializationView.getSize((HumanInitialization) entity);
    }
    else

    if (entity.getClass().equals(BActivity.class)) {
      vertex = new BActivityCell( (BActivity) entity);
      // Default Size for the new Vertex with the new entity within
      size = BActivityView.getSize((BActivity) entity);
    }
    else

    if (entity.getClass().equals(CameraInit.class)) {
      vertex = new CameraInitCell( (CameraInit) entity);
      // Default Size for the new Vertex with the new entity within
      size = CameraInitView.getSize((CameraInit) entity);
    }
    else

    if (entity.getClass().equals(SymptomInitialization.class)) {
      vertex = new SymptomInitializationCell( (SymptomInitialization) entity);
      // Default Size for the new Vertex with the new entity within
      size = SymptomInitializationView.getSize((SymptomInitialization) entity);
    }
    else

    if (entity.getClass().equals(SLivingroom.class)) {
      vertex = new SLivingroomCell( (SLivingroom) entity);
      // Default Size for the new Vertex with the new entity within
      size = SLivingroomView.getSize((SLivingroom) entity);
    }
    else

   {}; // Just in case there is no allowed entity in the diagram

    if (vertex == null) {
     System.err.println(
		 "Object not allowed in SimulationDiagram 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;

  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy