/* Copyright © 2007 by Christian Fuchsberger and Lukas Forer info@pedvizapi.org.
 * All rights reserved.
 *
 * 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.
 *
 * 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 <http://www.pedvizapi.org/gpl.txt>
 * for more details. 
 */

package applets.hints;

import java.awt.Color;

import javax.swing.JApplet;

import pedviz.algorithms.Sugiyama;
import pedviz.algorithms.sugiyama.SugiyamaNodeView;
import pedviz.graph.Graph;
import pedviz.loader.RessourceGraphLoader;
import pedviz.view.DefaultEdgeView;
import pedviz.view.DefaultNodeView;
import pedviz.view.GraphView;
import pedviz.view.GraphView2D;
import pedviz.view.NodeView;
import pedviz.view.rules.HintRule;
import pedviz.view.rules.ShapeRule;
import pedviz.view.symbols.SymbolSexFemale;
import pedviz.view.symbols.SymbolSexMale;

public class Hints extends JApplet {
	static GraphView graphView;

	public void init() {

		final Graph graph = new Graph();

		RessourceGraphLoader loader = new RessourceGraphLoader(
				getParameter("datasource"), ",");

		// sets columnnames for id, mom-id and dad-id
		loader.setSettings("PID", "MOM", "DAD");
		loader.load(graph);

		DefaultNodeView n = new DefaultNodeView();
		n.setColor(new Color(255, 255, 255));
		n.setHighlightedColor(new Color(200, 200, 200));

		// node look
		DefaultEdgeView e = new DefaultEdgeView();
		e.setConnectChildren(true);
		e.setColor(new Color(50, 50, 50));
		e.setColorForLongLines(new Color(200, 200, 200));
		e.setHighlightedColor(new Color(255, 0, 0));
		e.setGapBottom(5);

		// runs sugiyama
		Sugiyama sugiyama = new Sugiyama(graph, n, e);
		sugiyama.run();

		// for 2d:
		graphView = new GraphView2D(sugiyama.getLayoutedGraph());
		graphView.setSelectionEnabled(true);
		graphView.setBackgroundColor(new Color(255, 255, 255));
		graphView.addRule(new ShapeRule("sex", "2", new SymbolSexMale()));
		graphView.addRule(new ShapeRule("sex", "1", new SymbolSexFemale()));

		graphView.addRule(new HintRule() {
			@Override
			public String getHint(NodeView n) {
				return n.getNode().getId() + "\n{line}\nsex: "
						+ n.getNode().getUserData("SEX") + "\ndad: "
						+ n.getNode().getIdDad() + "\nmom:"
						+ n.getNode().getIdMom();
			}
		});

		getContentPane().add(graphView.getComponent());
	}
}

