package view;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

public class LegendView extends JPanel {

	private static final long serialVersionUID = 1L;
	private static final int PADDING = 4;

	@Override
	public void paintComponent( Graphics g ) {
	
		g.setFont( RenderHelper.font );
		FontMetrics fm = g.getFontMetrics();
		setPreferredSize( new Dimension( getPreferredSize().width, fm.getHeight() + PADDING * 2 ) );
		
		int height = fm.getHeight() + PADDING * 2;
		
		int x = PADDING;
		g.drawString( "Legende:", x, fm.getMaxAscent() + PADDING );
		x += fm.stringWidth( "Legende:" ) + PADDING;
		
		g.setColor( Color.LIGHT_GRAY );
		g.fillOval( x, PADDING, height - PADDING*2, height - PADDING*2 );
		x += height;
		g.setColor( Color.BLACK );
		g.drawString( "block root", x, fm.getMaxAscent() + PADDING );
		x += fm.stringWidth( "block root" ) + PADDING * 4;
		
		g.setColor( Color.LIGHT_GRAY );
        ((Graphics2D)g).setStroke(new BasicStroke(2));
		g.drawRect( x, PADDING, height - PADDING * 2, height - PADDING * 2 );
		x += height;
		g.setColor( Color.BLACK );
		g.drawString( "node with subgraph", x, fm.getMaxAscent() + PADDING );
		x += fm.stringWidth( "node with subgraph" ) + PADDING * 4;
		
		g.setColor( Color.RED );
		g.drawLine( x, height / 2, x + height - PADDING * 2, height / 2 );
		x += height;
		g.setColor( Color.BLACK );
		g.drawString( "conflicted edge", x, fm.getMaxAscent() + PADDING );
		x += fm.stringWidth( "conflicted edge" ) + PADDING * 4;
		
		g.setColor( Color.BLUE );
		g.fillRect( x, 0, height, height );
		g.setColor( Color.LIGHT_GRAY );
		g.fillOval( x + PADDING, PADDING, height - PADDING * 2, height - PADDING * 2 );
		x += height + PADDING;
		g.setColor( Color.BLACK );
		g.drawString( "class color", x, fm.getMaxAscent() + PADDING );
		x += fm.stringWidth( "class color" ) + PADDING * 4;
		
		g.setColor( Color.LIGHT_GRAY );
		g.fillRect( x, 0, height, height );
		g.setColor( Color.BLUE );
		g.fillOval( x + PADDING, PADDING, height - PADDING * 2, height - PADDING * 2 );
		x += height + PADDING;
		g.setColor( Color.BLACK );
		g.drawString( "block color", x, fm.getMaxAscent() + PADDING );
		x += fm.stringWidth( "block color" ) + PADDING * 4;
	}
}
