Commit 560f9f21 authored by Guillaume Chomat's avatar Guillaume Chomat
Browse files

add our Graph Cell

parent 08281d38
/**
* $Id: FCGraphCell.java,v 1.1 2002-06-13 12:10:25 gchomat Exp $
*
* Transmorpher
*
* Copyright (C) 2002 Fluxmedia and INRIA Rhône-Alpes.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
* 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; either version 2
* of the License, or (at your option) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* @author Choamt Guillaume
* @author Saint-Marcel Frdric
*/
package fr.fluxmedia.flowcomposer;
import java.util.Observer;
import java.util.Observable;
import java.util.Hashtable;
import java.util.Map;
import java.awt.Point;
import com.jgraph.graph.DefaultGraphCell;
import com.jgraph.graph.ParentMap;
import com.jgraph.graph.GraphConstants;
import com.jgraph.graph.*;
import fr.fluxmedia.transmorpher.Graph.Call;
import fr.fluxmedia.transmorpher.Graph.CallImpl;
import fr.fluxmedia.transmorpher.Graph.Port;
public class FCGraphCell extends DefaultGraphCell implements Observer{
// the owner of the cell
protected ProcessGraph process;
public FCGraphCell(Object userObject, ProcessGraph process){
super(userObject);
this.process = process;
if(userObject instanceof CallImpl)
((CallImpl)userObject).addObserver(this);
}
public String getId(){
if(userObject != null && userObject instanceof Call)
return ((Call)userObject).getId();
return null;
}
public String getType(){
if(userObject != null && userObject instanceof Call)
return ((Call)userObject).getType();
return null;
}
public ProcessGraph getProcess(){
return process;
}
public void newPort(int type){
if(userObject != null && userObject instanceof CallImpl)
{
CallImpl call = (CallImpl)userObject;
Port port;
int number = call.inPorts().length();
if(type == FCConstants.PORTOUTPUT)
{
port= new Port("",call,number,FCConstants.PORTOUTPUT);
call.addOut(port);
}
else
{
port= new Port("",call,number,FCConstants.PORTINPUT);
call.addIn(port);
}
}
}
public void update(Observable obs, Object arg)
{
if(obs instanceof Call)
{
if(arg instanceof Port)
{
if(process != null)
{
PortCell pc = new PortCell((Port)arg,((Port)arg).getType());
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
GraphConstants.setOffset(map, new Point((int)(u/2),(int)(u/2)));
ParentMap parent = new ParentMap();
parent.addEntry(pc,this);
System.out.println("cell "+ this);
Map viewMap = new Hashtable();
viewMap.put(pc,map);
process.getModel().insert(new Object[]{pc},null,parent,viewMap);
process.updatePort(this,((Port)arg).getType());
}
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment