|
@@ -0,0 +1,166 @@
|
|
|
|
+package api;
|
|
|
|
+
|
|
|
|
+import java.awt.Color;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+
|
|
|
|
+import classes.CpsEdge;
|
|
|
|
+import classes.AbstractCpsObject;
|
|
|
|
+import classes.HolonObject;
|
|
|
|
+import classes.HolonSwitch;
|
|
|
|
+import classes.SubNet;
|
|
|
|
+import ui.controller.Control;
|
|
|
|
+import ui.controller.SimulationManager;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Api Class for the Cps Controller.
|
|
|
|
+ *
|
|
|
|
+ * @author Gruppe14
|
|
|
|
+ */
|
|
|
|
+public class CpsAPI {
|
|
|
|
+ private Control controller;
|
|
|
|
+ private SimulationManager simManager;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Constructor.
|
|
|
|
+ *
|
|
|
|
+ * @param cont
|
|
|
|
+ * Controller
|
|
|
|
+ */
|
|
|
|
+ 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 the Canvas in no Specific order.
|
|
|
|
+ *
|
|
|
|
+ * @return all Objects on Canvas in no specific order
|
|
|
|
+ */
|
|
|
|
+ public ArrayList<AbstractCpsObject> getAllObjOnCanvas() {
|
|
|
|
+
|
|
|
|
+ return controller.getModel().getObjectsOnCanvas();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Reutn all Edges on the Canvas in no specific order.
|
|
|
|
+ *
|
|
|
|
+ * @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 Swtiches on the Canvas in no specific order.
|
|
|
|
+ *
|
|
|
|
+ * @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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Return all Holon Objects on the Canvas in no specific order.
|
|
|
|
+ *
|
|
|
|
+ * @return all Holon Objects
|
|
|
|
+ */
|
|
|
|
+ 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
|
|
|
|
+ * 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 border color of given object to given color.
|
|
|
|
+ *
|
|
|
|
+ * @param toChange
|
|
|
|
+ * CpsObject
|
|
|
|
+ * @param color
|
|
|
|
+ * Color
|
|
|
|
+ */
|
|
|
|
+ public void setBorderColorForObj(AbstractCpsObject toChange, Color color) {
|
|
|
|
+ toChange.setBorderColor(color);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * changes the borderColor for all objects in List to given color.
|
|
|
|
+ *
|
|
|
|
+ * @param objects
|
|
|
|
+ * AttayList of CpsObject
|
|
|
|
+ * @param color
|
|
|
|
+ * Color
|
|
|
|
+ */
|
|
|
|
+ public void setBorderColorForMultObj(ArrayList<AbstractCpsObject> objects, Color color) {
|
|
|
|
+ for (AbstractCpsObject cps : objects) {
|
|
|
|
+ setBorderColorForObj(cps, color);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * resets the bordercolor of given object to default (white).
|
|
|
|
+ *
|
|
|
|
+ * @param toReset
|
|
|
|
+ * CpsObject
|
|
|
|
+ */
|
|
|
|
+ public void resetBorderColor(AbstractCpsObject toReset) {
|
|
|
|
+ toReset.setBorderColor(Color.WHITE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * resets the bordercolor for all objects on canvas.
|
|
|
|
+ */
|
|
|
|
+ public void resetBorderColorForAll() {
|
|
|
|
+ setBorderColorForMultObj(getAllObjOnCanvas(), Color.WHITE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|