The final restructured version for automatic build using maven tycho
[Mograsim.git] / plugins / net.mograsim.logic.core / src / net / mograsim / logic / core / types / BitVectorFormatter.java
1 package net.mograsim.logic.core.types;
2
3 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
4 import net.mograsim.preferences.ColorDefinition;
5 import net.mograsim.preferences.ColorDefinition.BuiltInColor;
6 import net.mograsim.preferences.Preferences;
7
8 public class BitVectorFormatter
9 {
10         public static String formatValueAsString(ReadEnd end)
11         {
12                 return formatAsString(end == null ? null : end.getValues());
13         }
14
15         public static String formatAsString(BitVector bitVector)
16         {
17                 if (bitVector == null)
18                         return "null";
19                 return bitVector.toString();
20         }
21
22         // TODO doesn't this belong to logic.model?
23         public static ColorDefinition formatAsColor(ReadEnd end)
24         {
25                 return formatAsColor(end == null ? null : end.getValues());
26         }
27
28         public static ColorDefinition formatAsColor(BitVector bitVector)
29         {
30                 // TODO maybe find a color assignment for multiple-bit bit vectors?
31                 if (bitVector == null || bitVector.length() != 1)
32                         return new ColorDefinition(BuiltInColor.COLOR_BLACK);
33                 switch (bitVector.getLSBit(0))
34                 {
35                 case ONE:
36                         return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.one");
37                 case U:
38                         return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.u");
39                 case X:
40                         return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.x");
41                 case Z:
42                         return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.z");
43                 case ZERO:
44                         return Preferences.current().getColorDefinition("net.mograsim.logic.model.color.bit.zero");
45                 default:
46                         throw new IllegalArgumentException("Unknown enum constant: " + bitVector.getLSBit(0));
47                 }
48         }
49
50         private BitVectorFormatter()
51         {
52                 throw new UnsupportedOperationException("No BitVectorFormatter instances");
53         }
54 }