package sim.lib.outputs;

import java.awt.*;
import sim.*;
import sim.engine.*;
import sim.lib.wires.Junction;
import sim.util.BufferedContainer;

public class NumberDisplay extends RotatableFlippableWrapperPainted
		implements EngineModule {

	private static Image ICON = GuiFileLink.getImage("sim/lib/outputs/DisplayIcon.gif");
	private Junction input = null;
	private boolean[] value = new boolean[7];
	private boolean simulating = false;

	public void loadWrapper(String[] paramArrayOfString)
			throws SimException {
		if (paramArrayOfString.length == getNumberOfSpecificParameters()) {
			if (!paramArrayOfString[0].equals("null")) {
				throw new SimException("incorrect parameter type");
			}
		} else {
			throw new SimException("incorrect number of parameters");
		}
	}

	protected void paintNormal_180(Graphics paramGraphics) {
		int i = CentralPanel.ACTIVE_GRID.getCurrentGridGap();
		int j = 2 * i;
		int k = 3 * i;
		int m = i / 4;
		paramGraphics.setColor(WrapperPainted.BACKGROUND);
		paramGraphics.fillRect(i, i, j, k);
		paramGraphics.setColor(this.brush);
		paramGraphics.drawRect(i, i, j, k);
		paramGraphics.fillRect(0, j - 1, i, 3);
		j = k + i;
		paramGraphics.setColor(WrapperPainted.BACKGROUND.brighter());
		paramGraphics.drawLine(i + 1, i + 1, k - 1, i + 1);
		paramGraphics.drawLine(i + 1, i + 1, i + 1, j - 1);
		paramGraphics.setColor(WrapperPainted.BACKGROUND.darker());
		paramGraphics.drawLine(k - 1, i + 1, k - 1, j - 1);
		paramGraphics.drawLine(i + 2, j - 1, k - 1, j - 1);
		Color localColor1 = Color.red;
		Color localColor2 = WrapperPainted.BACKGROUND.darker();
		i = k / 4;
		k = 11 * m / 2;
		j = 5 * m;
		if (this.value[0] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
		if (this.value[1] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + j, m, i);
		k += m;
		if (this.value[2] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - m, i, m);
		if (this.value[3] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + i, i, m);
		if (this.value[4] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + 7 * m, i, m);
		k += i;
		if (this.value[5] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - i, m, i);
		if (this.value[6] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
	}

	public void evaluateOutput(double paramDouble, Data[] paramArrayOfData, EnginePeer paramEnginePeer) {
		int i = 0;
		do {
			this.value[i] = ((paramArrayOfData[i].isUndefined()) || (!paramArrayOfData[i].getValue()) ? false : true);
			i++;
		} while (i < 7);
		CentralPanel.ACTIVE_GRID.paintComponent(this);
	}

	public void selected() {
		this.input.removePin();
		changeColor(Color.green);
	}

	protected void paintNormal_0(Graphics paramGraphics) {
		int i = CentralPanel.ACTIVE_GRID.getCurrentGridGap();
		int j = 2 * i;
		int k = 3 * i;
		int m = i / 4;
		paramGraphics.setColor(WrapperPainted.BACKGROUND);
		paramGraphics.fillRect(i, i, j, k);
		paramGraphics.setColor(this.brush);
		paramGraphics.drawRect(i, i, j, k);
		paramGraphics.fillRect(k, j - 1, i, 3);
		j = k + i;
		paramGraphics.setColor(WrapperPainted.BACKGROUND.brighter());
		paramGraphics.drawLine(i + 1, i + 1, k - 1, i + 1);
		paramGraphics.drawLine(i + 1, i + 1, i + 1, j - 1);
		paramGraphics.setColor(WrapperPainted.BACKGROUND.darker());
		paramGraphics.drawLine(k - 1, i + 1, k - 1, j - 1);
		paramGraphics.drawLine(i + 2, j - 1, k - 1, j - 1);
		Color localColor1 = Color.red;
		Color localColor2 = WrapperPainted.BACKGROUND.darker();
		i = k / 4;
		k = 11 * m / 2;
		j = 5 * m;
		if (this.value[0] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
		if (this.value[1] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + j, m, i);
		k += m;
		if (this.value[2] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - m, i, m);
		if (this.value[3] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + i, i, m);
		if (this.value[4] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + 7 * m, i, m);
		k += i;
		if (this.value[5] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - i, m, i);
		if (this.value[6] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
	}

	public void initializeGridSize() {
		setGridSize(4, 5);
	}

	public String getBubbleHelp() {
		return "Number display";
	}

	protected void paintFlipped_0(Graphics paramGraphics) {
		paintNormal_0(paramGraphics);
	}

	protected boolean canDropFlipped_0() {
		return canDropNormal_0();
	}

	protected void dropedFlipped_0() {
		dropedNormal_0();
	}

	protected void paintFlipped_270(Graphics paramGraphics) {
		paintNormal_90(paramGraphics);
	}

	protected boolean canDropNormal_270() {
		return Wrapper.canDropJuncion(this.gridLocation.x + 2, this.gridLocation.y + 5, 7);
	}

	protected void dropedNormal_270() {
		this.input = Wrapper.setPinAt(this.gridLocation.x + 2, this.gridLocation.y + 5, 7);
		changeColor(Color.black);
	}

	public void reset() {
		this.simulating = false;
		CentralPanel.ACTIVE_GRID.paintComponent(this);
		int i = 0;
		do {
			this.value[i] = false;
			i++;
		} while (i < 7);
	}

	public NumberDisplay() {
		int i = 0;
		do {
			this.value[i] = false;
			i++;
		} while (i < 7);
	}

	protected void paintFlipped_90(Graphics paramGraphics) {
		paintNormal_270(paramGraphics);
	}

	protected boolean canDropNormal_90() {
		return Wrapper.canDropJuncion(this.gridLocation.x + 2, this.gridLocation.y, 7);
	}

	protected void dropedNormal_90() {
		this.input = Wrapper.setPinAt(this.gridLocation.x + 2, this.gridLocation.y, 7);
		changeColor(Color.black);
	}

	protected boolean canDropFlipped_90() {
		return canDropNormal_270();
	}

	protected void dropedFlipped_90() {
		dropedNormal_270();
	}

	public void createEnginePeer(EnginePeerList paramEnginePeerList) {
		EnginePeer localEnginePeer = new EnginePeer(7, this);
		int i = 0;
		do {
			localEnginePeer.setInputPin(i, this.input.getNodes().getItemAt(i));
			i++;
		} while (i < 7);
		paramEnginePeerList.insertItem(localEnginePeer);
		this.simulating = true;
	}

	protected boolean canDropFlipped_270() {
		return canDropNormal_90();
	}

	public Image getIcon() {
		return ICON;
	}

	protected void dropedFlipped_270() {
		dropedNormal_90();
	}

	public int getNumberOfSpecificParameters() {
		return 1;
	}

	public Wrapper getParentWrapper() {
		return this;
	}

	public Wrapper createWrapper() {
		return new NumberDisplay();
	}

	public Wrapper createWrapper(Point paramPoint) {
		NumberDisplay localNumberDisplay = new NumberDisplay();
		localNumberDisplay.setGridLocation(paramPoint);
		return localNumberDisplay;
	}

	protected void paintNormal_270(Graphics paramGraphics) {
		int i = CentralPanel.ACTIVE_GRID.getCurrentGridGap();
		int j = 2 * i;
		int k = 3 * i;
		int m = i / 4;
		paramGraphics.setColor(WrapperPainted.BACKGROUND);
		paramGraphics.fillRect(i, i, j, k);
		paramGraphics.setColor(this.brush);
		paramGraphics.drawRect(i, i, j, k);
		paramGraphics.fillRect(j - 1, k + i, 3, i);
		j = k + i;
		paramGraphics.setColor(WrapperPainted.BACKGROUND.brighter());
		paramGraphics.drawLine(i + 1, i + 1, k - 1, i + 1);
		paramGraphics.drawLine(i + 1, i + 1, i + 1, j - 1);
		paramGraphics.setColor(WrapperPainted.BACKGROUND.darker());
		paramGraphics.drawLine(k - 1, i + 1, k - 1, j - 1);
		paramGraphics.drawLine(i + 2, j - 1, k - 1, j - 1);
		Color localColor1 = Color.red;
		Color localColor2 = WrapperPainted.BACKGROUND.darker();
		i = k / 4;
		k = 11 * m / 2;
		j = 5 * m;
		if (this.value[0] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
		if (this.value[1] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + j, m, i);
		k += m;
		if (this.value[2] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - m, i, m);
		if (this.value[3] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + i, i, m);
		if (this.value[4] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + 7 * m, i, m);
		k += i;
		if (this.value[5] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - i, m, i);
		if (this.value[6] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
	}

	protected void adjustToChanges() {
	}

	public String getSpecificParameters() {
		return "null" + Wrapper.SEPARATOR;
	}

	protected void paintFlipped_180(Graphics paramGraphics) {
		paintNormal_180(paramGraphics);
	}

	public void checkAfterSelected() {
		Wrapper.checkPin(this.input);
	}

	protected boolean canDropNormal_180() {
		return Wrapper.canDropJuncion(this.gridLocation.x, this.gridLocation.y + 2, 7);
	}

	protected void dropedNormal_180() {
		this.input = Wrapper.setPinAt(this.gridLocation.x, this.gridLocation.y + 2, 7);
		changeColor(Color.black);
	}

	protected boolean canDropFlipped_180() {
		return canDropNormal_180();
	}

	protected void dropedFlipped_180() {
		dropedNormal_180();
	}

	protected void dropedNormal_0() {
		this.input = Wrapper.setPinAt(this.gridLocation.x + 4, this.gridLocation.y + 2, 7);
		changeColor(Color.black);
	}

	protected void paintNormal_90(Graphics paramGraphics) {
		int i = CentralPanel.ACTIVE_GRID.getCurrentGridGap();
		int j = 2 * i;
		int k = 3 * i;
		int m = i / 4;
		paramGraphics.setColor(WrapperPainted.BACKGROUND);
		paramGraphics.fillRect(i, i, j, k);
		paramGraphics.setColor(this.brush);
		paramGraphics.drawRect(i, i, j, k);
		paramGraphics.fillRect(j - 1, 0, 3, i);
		j = k + i;
		paramGraphics.setColor(WrapperPainted.BACKGROUND.brighter());
		paramGraphics.drawLine(i + 1, i + 1, k - 1, i + 1);
		paramGraphics.drawLine(i + 1, i + 1, i + 1, j - 1);
		paramGraphics.setColor(WrapperPainted.BACKGROUND.darker());
		paramGraphics.drawLine(k - 1, i + 1, k - 1, j - 1);
		paramGraphics.drawLine(i + 2, j - 1, k - 1, j - 1);
		Color localColor1 = Color.red;
		Color localColor2 = WrapperPainted.BACKGROUND.darker();
		i = k / 4;
		k = 11 * m / 2;
		j = 5 * m;
		if (this.value[0] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
		if (this.value[1] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + j, m, i);
		k += m;
		if (this.value[2] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - m, i, m);
		if (this.value[3] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + i, i, m);
		if (this.value[4] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + 7 * m, i, m);
		k += i;
		if (this.value[5] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k - i, m, i);
		if (this.value[6] != false) {
			paramGraphics.setColor(localColor1);
		} else {
			paramGraphics.setColor(localColor2);
		}
		paramGraphics.fillRect(k, k + m, m, i);
	}

	protected boolean canDropNormal_0() {
		return Wrapper.canDropJuncion(this.gridLocation.x + 4, this.gridLocation.y + 2, 7);
	}

	@Override
	public void writeVHDLEntity(String path) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getVHDLName() {
		// TODO Auto-generated method stub
		return null;
	}
}
