package ckelling.baukasten;

import java.awt.*;
import java.lang.*;
import java.util.*;


// Versionsgeschichte
// 0.2.1, 01.12.96
// 0.8.0, 03.08.97  jetzt von Register16 abgeleitet

/**
 *	Zeigt einen ganzzahligen numerischen Wert ohne Rahmen an.
 *  Kennt wie alle Rechnerkomponenten die eigene Position,
 *  kann aktiviert werden und blinken. Ist editierbar.
 *
 *	@author		Carsten Kelling
 *	@version	0.8.0, 03.08.97
 */
public class EditableLabel extends Register16
{
	public EditableLabel(int x1, int y1, String str, Rechner par)
	{
		this(x1, y1, str, par, BITWIDTH);
	}

	public EditableLabel(int x1, int y1, String str, Rechner par, int bitwidth1)
	{
		super("", x1, y1, str, par, bitwidth1);

		Point p = Rechner.getCellSize(bitwidth1);
		WIDTH = p.x; HEIGHT = p.y;
		reshape(x1, y1, WIDTH, HEIGHT, str);

	} /* end EditableLabel */


	public void paint(Graphics g)
	{
		activatedAtLastPaint = activated;
		modified = false;

		// Hintergrund loeschen
		g.setColor(parent.BACKGROUND);
		g.fillRect(leftPortX, upperLeftY, WIDTH-1, HEIGHT);

		if (activated == true)
			g.setColor(parent.REG_COLOR_ACTIVATED);
		else
			g.setColor(parent.REG_COLOR);

		valueExpanded.repaint();

	} /* end paint */


	public void reshape(int x, int y, int width, int height)
	{
		WIDTH = width; HEIGHT = height;
		setCoordinates(x, y, grabMode);

        reshapePassThrough(leftPortX, upperLeftY, WIDTH+2, HEIGHT);

		modified = true;

		valueExpanded.reshape(0, 0, bounds().width, bounds().height);
		inputCell.reshape(0, 0, bounds().width, bounds().height);
	}

	public void setEditable(boolean b)
	{
		super.setEditable(b);
		
		if (editable == false)
			valueExpanded.setBackground(parent.BACKGROUND);
		else
			valueExpanded.setBackground(parent.LABEL_COLOR_EDITABLE);
		valueExpanded.invalidate();
	}

} /* end EditableLabel */

