@Override
	public void paintTop(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		Rectangle bounds = getBounds();
		double pixelSize = getFactory().getPixelSize();
		int wt = (int) (wallthickness / pixelSize);

		g2.setStroke(new BasicStroke(wt));
		g2.setColor(Color.lightGray);
		g2.drawRect(bounds.x - wt, bounds.y - wt, bounds.width + wt * 2, bounds.height + wt * 2);
		g2.setStroke(new BasicStroke(1));

		g2.setColor(facilityError ? Color.red : Color.black);
		g2.drawRect(bounds.x - wt, bounds.y - wt, bounds.width + wt * 2, bounds.height + wt * 2);

		g2.setColor(Color.black);
		g2.drawLine((int) (bounds.x + positionx / pixelSize), bounds.y - wt, (int) (bounds.x + positionx / pixelSize), bounds.y + bounds.height + wt);
		g2.drawLine(bounds.x - wt, (int) (bounds.y + positiony / pixelSize), bounds.x + bounds.width + wt, (int) (bounds.y + positiony / pixelSize));

		g2.setStroke(new BasicStroke(2));
		g2.setColor(facilityError ? Color.red : Color.black);
		g2.drawRect((int) (bounds.x + positionx / pixelSize - 1 / pixelSize), (int) (bounds.y + positiony / pixelSize - 1 / pixelSize), (int) (2 / pixelSize), (int) (2 / pixelSize));
		g2.setStroke(new BasicStroke());

		g2.setColor(Color.pink);

		for (int i = 0; i < sensorsx; i++) {
			Point sp = getSensorBoundsX(i);
			g.fillRect(sp.x - 1, sp.y - 1, 3, 3);
		}

		for (int i = 0; i < sensorsy; i++) {
			Point sp = getSensorBoundsY(i);
			g.fillRect(sp.x - 1, sp.y - 1, 3, 3);
		}

		if (block != null) {
			block.paint(g);
		}

		paintLight(g, false, 0, getDigitalOut(0), 0);
		paintLight(g, false, 1, getDigitalOut(1), 0);
		paintLight(g, false, 2, getDigitalOut(2), 0);
		paintLight(g, false, 3, getDigitalOut(3), 0);
		paintLight(g, false, 4, getDigitalOut(4), 0);
		paintLight(g, false, 5, getDigitalOut(5), 0);

		for (int i = 0; i < sensorsx; i++)
			paintLight(g, true, i, getDigitalIn(i), 1);
		for (int i = 0; i < sensorsy; i++)
			paintLight(g, true, i, getDigitalIn(sensorsx + i), 2);

		paintLight(g, false, 0, getDigitalIn(sensorsx + sensorsy), 3);
		paintLight(g, false, 1, getDigitalIn(sensorsx + sensorsy + 1), 3);

		g.setColor(Color.white);
		g.fillRect((int) (bounds.x + positionx / pixelSize + 1 / pixelSize - 1), (int) (bounds.y + positiony / pixelSize - 1 / pixelSize + (1 - positionz) * 2 / pixelSize - 1), 3, 3);

		paintLight(g, false, 0, getDigitalOut(6), 4);
		paintLight(g, false, 1, getDigitalIn(sensorsx + sensorsy + 2), 4);
	}