|
@@ -0,0 +1,129 @@
|
|
|
|
+package API;
|
|
|
|
+
|
|
|
|
+import java.awt.Color;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+
|
|
|
|
+import classes.CpsEdge;
|
|
|
|
+import classes.CpsObject;
|
|
|
|
+import classes.HolonObject;
|
|
|
|
+import classes.HolonSwitch;
|
|
|
|
+import classes.subNet;
|
|
|
|
+import ui.controller.Control;
|
|
|
|
+import ui.controller.SimulationManager;
|
|
|
|
+
|
|
|
|
+public class CpsAPI {
|
|
|
|
+ private Control controller;
|
|
|
|
+ private SimulationManager simManager;
|
|
|
|
+
|
|
|
|
+ public CpsAPI(Control cont){
|
|
|
|
+ this.controller = cont;
|
|
|
|
+ this.simManager = controller.getSimManager();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * a SubNet contains all Components
|
|
|
|
+ * @return all SubNets on Canvas
|
|
|
|
+ */
|
|
|
|
+ public ArrayList<subNet> getSubNets(){
|
|
|
|
+ simManager.searchForSubNets();
|
|
|
|
+ return simManager.getSubNets();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @return all Objects on Canvas in no specific order
|
|
|
|
+ */
|
|
|
|
+ public ArrayList<CpsObject> getAllObjOnCanvas(){
|
|
|
|
+
|
|
|
|
+ return controller.getModel().getObjectsOnCanvas();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @return all Edges on Canvas
|
|
|
|
+ */
|
|
|
|
+ public ArrayList<CpsEdge> getAllEdges(){
|
|
|
|
+ ArrayList<CpsEdge> result = new ArrayList<CpsEdge>();
|
|
|
|
+ for(subNet sN: getSubNets()){
|
|
|
|
+ result.addAll(sN.getEdges());
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @return all Switches on Canvas
|
|
|
|
+ */
|
|
|
|
+ public ArrayList<HolonSwitch> getAllSwitches(){
|
|
|
|
+ ArrayList<HolonSwitch> result = new ArrayList<HolonSwitch>();
|
|
|
|
+ for(subNet sN: getSubNets()){
|
|
|
|
+ result.addAll(sN.getSwitches());
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ArrayList<HolonObject> getAllHolonObjects(){
|
|
|
|
+ ArrayList<HolonObject> result = new ArrayList<HolonObject>();
|
|
|
|
+ for(subNet sN: getSubNets()){
|
|
|
|
+ result.addAll(sN.getObjects());
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * prints a given text on the console
|
|
|
|
+ * @param text
|
|
|
|
+ */
|
|
|
|
+ public void consolePrint(String text){
|
|
|
|
+ controller.addTextToConsole(text);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * prints a given text on the console with more details
|
|
|
|
+ * @param text: the text that will be printed
|
|
|
|
+ * @param color: the color the text will have
|
|
|
|
+ * @param p: font size
|
|
|
|
+ * @param bold: true or false
|
|
|
|
+ * @param italic: true or false
|
|
|
|
+ * @param nl: new line after text
|
|
|
|
+ */
|
|
|
|
+ public void consolePrint(String text, Color color, int p, boolean bold, boolean italic, boolean nl){
|
|
|
|
+ controller.addTextToConsole(text, color, p, bold, italic, nl);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * changes the bordercolor of given object to given color
|
|
|
|
+ * @param toChange
|
|
|
|
+ * @param color
|
|
|
|
+ */
|
|
|
|
+ public void setBorderColorForObj(CpsObject toChange, Color color){
|
|
|
|
+ toChange.setBorderColor(color);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * changes the borderColor for all objects in List to given color
|
|
|
|
+ * @param objects
|
|
|
|
+ * @param color
|
|
|
|
+ */
|
|
|
|
+ public void setBorderColorForMultObj(ArrayList<CpsObject> objects, Color color){
|
|
|
|
+ for(CpsObject cps: objects){
|
|
|
|
+ setBorderColorForObj(cps, color);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * resets the bordercolor of given object to default (white)
|
|
|
|
+ * @param toReset
|
|
|
|
+ */
|
|
|
|
+ public void resetBorderColor(CpsObject toReset){
|
|
|
|
+ toReset.setBorderColor(Color.WHITE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * resets the bordercolor for all objects on canvas
|
|
|
|
+ */
|
|
|
|
+ public void resetBorderColorForAll(){
|
|
|
|
+ setBorderColorForMultObj(getAllObjOnCanvas(), Color.WHITE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|