1 package net.mograsim.logic.core.types;
\r
3 import net.mograsim.logic.core.wires.Wire.ReadEnd;
\r
4 import net.mograsim.preferences.ColorDefinition;
\r
5 import net.mograsim.preferences.Preferences;
\r
6 import net.mograsim.preferences.ColorDefinition.BuiltInColor;
\r
8 public class BitVectorFormatter
\r
10 public static String formatValueAsString(ReadEnd end)
\r
12 return formatAsString(end == null ? null : end.getValues());
\r
15 public static String formatAsString(BitVector bitVector)
\r
17 if (bitVector == null)
\r
19 return bitVector.toString();
\r
22 // TODO doesn't this belong to logic.ui?
\r
23 public static ColorDefinition formatAsColor(ReadEnd end)
\r
25 return formatAsColor(end == null ? null : end.getValues());
\r
28 public static ColorDefinition formatAsColor(BitVector bitVector)
\r
30 // TODO maybe find a color assignment for multiple-bit bit vectors?
\r
31 if (bitVector == null || bitVector.length() != 1)
\r
32 return new ColorDefinition(BuiltInColor.COLOR_BLACK);
\r
33 switch (bitVector.getBit(0))
\r
36 return Preferences.current().getColor("net.mograsim.logic.ui.wire.bit.one");
\r
38 return Preferences.current().getColor("net.mograsim.logic.ui.wire.bit.u");
\r
40 return Preferences.current().getColor("net.mograsim.logic.ui.wire.bit.x");
\r
42 return Preferences.current().getColor("net.mograsim.logic.ui.wire.bit.z");
\r
44 return Preferences.current().getColor("net.mograsim.logic.ui.wire.bit.zero");
\r
46 throw new IllegalArgumentException("Unknown enum constant: " + bitVector.getBit(0));
\r
50 private BitVectorFormatter()
\r
52 throw new UnsupportedOperationException("No BitVectorFormatter instances");
\r