General SubmodelComponents can now be saved to a json format
[Mograsim.git] / net.mograsim.logic.ui / src / net / mograsim / logic / ui / model / components / params / SubComponentParams.java
1 package net.mograsim.logic.ui.model.components.params;
2
3 import java.io.IOException;
4
5 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
6
7 public class SubComponentParams
8 {
9         public final static String fileExtension = ".sc";
10         public double width, height;
11         public InterfacePinParams[] interfacePins;
12         public GeneralComponentParams composition;
13
14         public static class InterfacePinParams
15         {
16                 public Point location;
17                 public int logicWidth;
18         }
19
20         public static SubComponentParams readJson(String path) throws IOException
21         {
22                 return JsonHandler.readJson(path, SubComponentParams.class);
23         }
24
25         /**
26          * Writes this {@link SubComponentParams} object into a file in json format. The correct file extension is important! Check
27          * {@link SubComponentParams}.fileExtension
28          */
29         public void writeJson(String path)
30         {
31                 try
32                 {
33                         JsonHandler.writeJson(this, path);
34                 }
35                 catch (IOException e)
36                 {
37                         System.err.println("Failed to write SubComponentParams to file");
38                         e.printStackTrace();
39                 }
40         }
41 }