package de.mazdermind.MultiWiiOps.UI;

import java.awt.Color;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JLabel;

public class TestPanel extends JLabel {
	private static final long serialVersionUID = -5887360703631794529L;
	private String name = "";

	public TestPanel() {
		Color bg = new Color(
			(int) (Math.random() * Math.pow(2, 16))
		);
		init(bg);
	}

	public TestPanel(Color bg)
	{
		init(bg);
	}

	public TestPanel(String name)
	{
		this();
		this.name = name + " - ";
	}

	public TestPanel(String name, Color bg)
	{
		this(bg);
		this.name = name + " - ";
	}
	
	private int calculateBrightness(Color c)
	{
	   return (int)Math.sqrt(
	      c.getRed() * c.getRed() * .241 + 
	      c.getGreen() * c.getGreen() * .691 + 
	      c.getBlue() * c.getBlue() * .068);
	}

	private void init(Color bg) {
		setBackground(bg);
		if(calculateBrightness(bg) < 130)
			setForeground(Color.WHITE);
		
		setHorizontalAlignment(CENTER);
		setOpaque(true);
		
		addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				JLabel label = (JLabel)e.getSource();
				
				label.setText(name + label.getWidth() + "x" + label.getHeight());
			}
		});
	}
	
}

@@ -287,20 +287,21 @@
  String 
-name
+label
  = %22%22;%0A%0A
@@ -482,20 +482,21 @@
 (String 
-name
+label
 )%0A%09%7B%0A%09%09t
@@ -508,32 +508,23 @@
 ;%0A%09%09
-this.name = name + %22 - %22
+setLabel(label)
 ;%0A%09%7D
@@ -550,20 +550,21 @@
 (String 
-name
+label
 , Color 
@@ -588,24 +588,87 @@
 ;%0A%09%09
-this.name = name
+setLabel(label);%0A%09%7D%0A%0A%09public void setLabel(String label) %7B%0A%09%09this.label = label
  + %22
@@ -676,17 +676,16 @@
 - %22;%0A%09%7D%0A
-%09
 %0A%09privat
@@ -1183,21 +1183,24 @@
 %09JLabel 
-label
+componet
  = (JLab
@@ -1226,21 +1226,24 @@
 %09%09%09%0A%09%09%09%09
-label
+componet
 .setText
@@ -1247,20 +1247,24 @@
 ext(
-name + label
+label + componet
 .get
@@ -1279,21 +1279,24 @@
 + %22x%22 + 
-label
+componet
 .getHeig

allow setting the label from subclasses