package org.joone.edit;

import java.awt.*;
import java.util.*;
import java.io.*;
import CH.ifa.draw.framework.*;
import CH.ifa.draw.standard.*;
import CH.ifa.draw.figures.*;
import CH.ifa.draw.util.*;
import org.joone.engine.*;

/** Graphic representation of a Layer in the net
 */
public class LayerFigure extends ConcreteGenericFigure {
    protected Vector fPostConn;
    protected Vector fPreConn;
    protected Layer myLayer;
    
        /*
         * Serialization support.
         */
    private static final long serialVersionUID = -1148000139027412009L;
    
    
    public LayerFigure() {
        super();
    }
    
    
    protected void initContent() {
        fPostConn = new Vector();
        fPreConn = new Vector();
        
        Font f = new Font("Helvetica", Font.PLAIN, 12);
        Font fb = new Font("Helvetica", Font.BOLD, 12);
        
        myLayer = (Layer)createLayer();
        
        
        TextFigure name = new UpdatableTextFigure() {
            public void setText(String newText) {
                super.setText(newText);
                Layer ly = (Layer)getLayer();
                ly.setLayerName(newText);
            }
            public void update() {
                Layer ly = (Layer)getLayer();
                setText(ly.getLayerName());
            }
        };
        
        name.setFont(fb);
        name.setText("Layer " + ++numLayers);
        name.setAttribute("TextColor", Color.blue);
        add(name);
        NumberTextFigure inputDim = new UpdatableNumberTextFigure() {
            public void setText(String newText) {
                super.setText(newText);
                Layer ly = (Layer)getLayer();
                ly.setRows(Integer.parseInt(newText));
            }
            public void update() {
                Layer ly = (Layer)getLayer();
                setValue(ly.getRows());
            }
        };
        
        inputDim.setValue(1);
        inputDim.setFont(f);
        add(inputDim);
    }
    
    public boolean hasCycle(Figure start) {
        if (start == this)
            return true;
        Enumeration i = fPreConn.elements();
        while (i.hasMoreElements()) {
            if (((LayerFigure) i.nextElement()).hasCycle(start))
                return true;
        }
        return false;
    }
    
    //-- store / load ----------------------------------------------
    
    public void write(StorableOutput dw) {
        super.write(dw);
        writeConn(dw, fPreConn);
        writeConn(dw, fPostConn);
    }
    
    public void writeConn(StorableOutput dw, Vector v) {
        dw.writeInt(v.size());
        Enumeration i = v.elements();
        while (i.hasMoreElements())
            dw.writeStorable((Storable) i.nextElement());
    }
    
    public void read(StorableInput dr) throws IOException {
        super.read(dr);
        fPreConn = readConn(dr);
        fPostConn = readConn(dr);
    }
    
    public Vector readConn(StorableInput dr) throws IOException {
        int size = dr.readInt();
        Vector v = new Vector(size);
        for (int i=0; i 

Ads help maintain this website.