package eu.dnetlib.enabling.graph.objects;

import java.awt.Font;

import javax.swing.BorderFactory;

import org.jgraph.graph.AttributeMap;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.GraphConstants;
import org.jgrapht.ext.JGraphModelAdapter;

import eu.dnetlib.enabling.graph.utils.DnetEdge;

abstract public class DnetVertex {

	public enum DnetGraphType {
		REPO, HDS, TDS, MDSTORE, INDEX, OTHER
	}
	
	private String id;
		
	public DnetVertex(String id) {
		super();
		this.id = id;
	}

	@SuppressWarnings("unchecked")
	public void formatVertex(JGraphModelAdapter<DnetVertex, DnetEdge> jgAdapter) {
		DefaultGraphCell cell = jgAdapter.getVertexCell(this);
		AttributeMap attr = cell.getAttributes();

		GraphConstants.setFont(attr, new Font(Font.SANS_SERIF, Font.PLAIN, 18));
		GraphConstants.setBorder(attr, BorderFactory.createEmptyBorder(15, 15, 15, 15));
		
		GraphConstants.setAutoSize(attr, true);
		GraphConstants.setEditable(attr, false);
		GraphConstants.setLink(attr, getHref());
	
		formatSpecificVertex(attr);

		AttributeMap cellAttr = new AttributeMap();
		cellAttr.put(cell, attr);
		
		jgAdapter.edit(cellAttr, null, null, null);
	}

	
	abstract protected String getHref();

	abstract protected void formatSpecificVertex(AttributeMap attr);
	

	abstract public DnetGraphType getType();
			
	public String getId() {
		return id;
	}

	@Override
	public String toString() {
		return getType().toString();
	}


	
}
