1 /* 2 * Copyright (c) 2016 Helmut Neemann 3 * Use of this source code is governed by the GPL v3 license 4 * that can be found in the LICENSE file. 5 */ 6 package de.neemann.digital.draw.shapes; 7 8 import de.neemann.digital.core.Value; 9 import de.neemann.digital.core.element.ElementAttributes; 10 import de.neemann.digital.core.element.Keys; 11 import de.neemann.digital.core.element.PinDescriptions; 12 import de.neemann.digital.core.ValueFormatter; 13 import de.neemann.digital.draw.elements.IOState; 14 import de.neemann.digital.draw.elements.Pin; 15 import de.neemann.digital.draw.elements.Pins; 16 import de.neemann.digital.draw.graphics.Graphic; 17 import de.neemann.digital.draw.graphics.Orientation; 18 import de.neemann.digital.draw.graphics.Style; 19 import de.neemann.digital.draw.graphics.Vector; 20 21 /** 22 * The constant shape 23 */ 24 public class ConstShape implements Shape { 25 26 private final PinDescriptions outputs; 27 private String value; 28 29 /** 30 * Creates a new instance 31 * 32 * @param attr the attributes 33 * @param inputs the inputs 34 * @param outputs the outputs 35 */ ConstShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs)36 public ConstShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) { 37 this.outputs = outputs; 38 int bits = attr.getBits(); 39 ValueFormatter formatter = attr.getValueFormatter(); 40 this.value = formatter.formatToView(new Value(attr.get(Keys.VALUE), bits)); 41 } 42 43 @Override getPins()44 public Pins getPins() { 45 return new Pins().add(new Pin(new Vector(0, 0), outputs.get(0))); 46 } 47 48 @Override applyStateMonitor(IOState ioState)49 public Interactor applyStateMonitor(IOState ioState) { 50 return null; 51 } 52 53 @Override drawTo(Graphic graphic, Style heighLight)54 public void drawTo(Graphic graphic, Style heighLight) { 55 Vector textPos = new Vector(-3, 0); 56 graphic.drawText(textPos, value, Orientation.RIGHTCENTER, Style.NORMAL); 57 } 58 } 59