package gui.status;

import java.awt.Color;
import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import utils.GUIUtils;
import utils.ObserverMessage;
import controller.Controller;

@SuppressWarnings("serial")
public class NetworkStatus extends JLabel implements Observer
{
	private ImageIcon noConnectionsIcon;
	private ImageIcon synchronizingIcon;
	private ImageIcon okeIcon;
	
	public NetworkStatus()
	{
		super();
		
		//CREATE ICONS
		this.noConnectionsIcon = this.createIcon(Color.RED);
		this.synchronizingIcon = this.createIcon(Color.ORANGE);
		this.okeIcon = this.createIcon(Color.GREEN);

		//LISTEN ON STATUS
		Controller.getInstance().addObserver(this);			
	}
	
	private ImageIcon createIcon(Color color)
	{
		return GUIUtils.createIcon(color, this.getBackground());
	}

	@Override
	public void update(Observable arg0, Object arg1) 
	{
		ObserverMessage message = (ObserverMessage) arg1;
		
		if(message.getType() == ObserverMessage.ADD_BLOCK_TYPE)
		{
			if(Controller.getInstance().getStatus() == Controller.STATUS_SYNCHRONIZING)
			{
				this.setText("Synchronizing "+ 100*Controller.getInstance().getHeight()/Controller.getInstance().getMaxPeerHeight() + "%");	
			}	
			
		}
		
		if(message.getType() == ObserverMessage.NETWORK_STATUS)
		{
			int status = (int) message.getValue();
			
			if(status == Controller.STATUS_NO_CONNECTIONS)
			{
				this.setIcon(noConnectionsIcon);
				this.setText("No connections");
			}
			if(status == Controller.STATUS_SYNCHRONIZING)
			{
				this.setIcon(synchronizingIcon);
				this.setText("Synchronizing");
			}
			if(status == Controller.STATUS_OKE)
			{
				this.setIcon(okeIcon);
				this.setText("Oke");
			}
		}		
	}
}

@@ -37,16 +37,86 @@
 .Color;%0A
+import java.awt.event.MouseAdapter;%0Aimport java.awt.event.MouseEvent;%0A
 import j
@@ -162,16 +162,54 @@
 bserver;
+%0Aimport java.util.concurrent.TimeUnit;
 %0A%0Aimport
@@ -258,16 +258,51 @@
 .JLabel;
+%0Aimport javax.swing.ToolTipManager;
 %0A%0Aimport
@@ -796,16 +796,667 @@
 REEN);%0A%0A
+%09%09ToolTipManager.sharedInstance().setDismissDelay( (int) TimeUnit.SECONDS.toMillis(5));%0A%09%09%0A%09%09this.addMouseListener(new MouseAdapter() %7B%0A%09%09%09public void mouseEntered(MouseEvent mEvt) %7B%0A%09%09%09%09if(Controller.getInstance().getStatus() == Controller.STATUS_OKE %7C%7C Controller.getInstance().getStatus() == Controller.STATUS_NO_CONNECTIONS)%0A%09%09%09%09%7B%0A%09%09%09%09%09setToolTipText(%22Block height: %22 + Controller.getInstance().getHeight());%0A%09%09%09%09%7D%0A%09%09%09%09else if (Controller.getInstance().getStatus() == Controller.STATUS_SYNCHRONIZING)%0A%09%09%09%09%7B%0A%09%09%09%09%09setToolTipText(%22Block height: %22 + Controller.getInstance().getHeight()+%22/%22+Controller.getInstance().getMaxPeerHeight());%0A%09%09%09%09%7D%09%0A%09%09%7D%7D);%0A
 %09%09//LIST

Add TooTip with block heigh on NetworkStatus