123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809 |
- package ui.model;
- import java.awt.Color;
- import java.awt.RenderingHints;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- import javax.swing.JTable;
- import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
- import classes.Category;
- import classes.CpsEdge;
- import classes.CpsUpperNode;
- import classes.AbstractCpsObject;
- import classes.HolonElement;
- import classes.HolonObject;
- import classes.HolonSwitch;
- import interfaces.CategoryListener;
- import interfaces.GraphListener;
- import interfaces.ObjectListener;
- import ui.view.Console;
- import ui.view.DefaulTable;
- import ui.view.PropertyTable;
- import ui.view.DefaulTable;
- public class Model {
-
- private int canvasX = 1000;
- private int canvasY = 1000;
- private static int sCALE = 50;
- private static int sCALEdIV2 = sCALE / 2;
- private static int holonBodysCALE = 100;
- private static final int ITERATIONS = 100;
- private int curIteration = 0;
- private LinkedList<Color> subNetColors = new LinkedList<>();
-
- private AbstractCpsObject selectedCpsObject = null;
- private HolonElement selectedHolonElement;
- private CpsEdge selectedEdge;
- private ArrayList<AbstractCpsObject> selectedObjects = new ArrayList<AbstractCpsObject>();
- private ArrayList<AbstractCpsObject> clipboardObjects = new ArrayList<AbstractCpsObject>();
- private Console console;
- private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
-
- private float maxCapacity;
-
- private JTable tableHolonElement;
- private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
-
- private int timerSpeed = 1000;
-
- private boolean isSimulation = false;
- private int selectedID = 0;
-
- private int autoSaveNr = -1;
-
- private int numberOfSaves = 35;
-
- private ArrayList<Category> categories;
-
- private ArrayList<AbstractCpsObject> trackedObjects;
-
- private ArrayList<AbstractCpsObject> objectsOnCanvas;
- private HashMap<String, Integer> cgIdx;
- private HashMap<Integer, Integer> cvsObjIdx;
-
- private ArrayList<CpsEdge> edgesOnCanvas;
-
- private List<CategoryListener> categoryListeners;
- private List<ObjectListener> objectListeners;
- private PropertyTable tableModelHolonElementMulti;
- private PropertyTable tableModelHolonElementSingle;
- private DefaulTable tableModelProperties;
- public String[] colNames = { "Field", "Information" };
-
- private Object algorithm = null;
- private int selectedHolonBody;
-
- public Model() {
- setCategories(new ArrayList<Category>());
- setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
- setEdgesOnCanvas(new ArrayList<CpsEdge>());
- setCategoryListeners(new LinkedList<CategoryListener>());
- setObjectListeners(new LinkedList<ObjectListener>());
- setCgIdx(new HashMap<String, Integer>());
- setCvsObjIdx(new HashMap<Integer, Integer>());
- setClipboradObjects(new ArrayList<AbstractCpsObject>());
- setTrackingObj(new ArrayList<AbstractCpsObject>());
- setEleToDelete(new HashMap<Integer, ArrayList<HolonElement>>());
- setSingleTable(new PropertyTable());
- setMultiTable(new PropertyTable());
- setPropertyTable(new DefaulTable(1000, colNames.length));
- getPropertyTable().setColumnIdentifiers(colNames);
- setTableHolonElement(new JTable());
- }
-
- public ArrayList<Category> getCategories() {
- return categories;
- }
-
- public void setCategories(ArrayList<Category> categories) {
- this.categories = categories;
- }
-
- public String toStringCat() {
- String text = "";
- for (int i = 0; i < categories.size(); i++) {
- if (text == "") {
- text = categories.get(i).getName();
- } else {
- text = text + ", " + categories.get(i).getName();
- }
- }
- return text;
- }
-
- public ArrayList<AbstractCpsObject> getObjectsOnCanvas() {
- return objectsOnCanvas;
- }
-
- public void setObjectsOnCanvas(ArrayList<AbstractCpsObject> objectsOnCanvas) {
- this.objectsOnCanvas = objectsOnCanvas;
- }
-
- public ArrayList<CpsEdge> getEdgesOnCanvas() {
- return edgesOnCanvas;
- }
-
- public void addEdgeOnCanvas(CpsEdge edge) {
- this.edgesOnCanvas.add(edge);
- }
-
- public void removeEdgesOnCanvas(CpsEdge edge) {
- this.edgesOnCanvas.remove(edge);
- }
-
- public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
- this.edgesOnCanvas = arrayList;
- }
-
- public List<ObjectListener> getObjectListeners() {
- return objectListeners;
- }
-
- public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
- this.objectListeners = linkedList;
- }
-
- public List<CategoryListener> getCategoryListeners() {
- return categoryListeners;
- }
-
- public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
- this.categoryListeners = linkedList;
- }
-
- public void setSelectedObjectID(int id) {
- this.selectedID = id;
- }
-
- public int getSelectedObjectID() {
- return selectedID;
- }
-
- public AbstractCpsObject getSelectedCpsObject() {
- return selectedCpsObject;
- }
-
- public void setSelectedCpsObject(AbstractCpsObject selectedCpsObject) {
- this.selectedCpsObject = selectedCpsObject;
- }
-
- public ArrayList<AbstractCpsObject> getSelectedCpsObjects() {
- return selectedObjects;
- }
-
- public void setSelectedCpsObjects(ArrayList<AbstractCpsObject> arr) {
- this.selectedObjects = arr;
- }
-
- public HolonElement getSelectedHolonElement() {
- return selectedHolonElement;
- }
-
- public void setSelectedHolonElement(HolonElement selectedHolonElement) {
- this.selectedHolonElement = selectedHolonElement;
- }
-
- public int getScale() {
- return sCALE;
- }
-
- public int getScaleDiv2() {
- return sCALEdIV2;
- }
-
- public void setScale(int scale) {
- sCALE = scale;
- sCALEdIV2 = sCALE / 2;
- }
-
- public int getIterations() {
- return ITERATIONS;
- }
-
- public void setCurIteration(int curIT) {
- this.curIteration = curIT;
- notifyGraphListeners();
- }
- private void notifyGraphListeners() {
- for (GraphListener gl : graphListeners) {
- gl.repaintTree();
- }
- }
-
- public int getCurIteration() {
- return curIteration;
- }
-
- public void setSelectedEdge(CpsEdge edge) {
- this.selectedEdge = edge;
- }
-
- public CpsEdge getSelectedEdge() {
- return selectedEdge;
- }
-
- public HashMap<String, Integer> getCgIdx() {
- return cgIdx;
- }
-
- public void setCgIdx(HashMap<String, Integer> cgIdx) {
- this.cgIdx = cgIdx;
- }
-
- public HashMap<Integer, Integer> getCvsObjIdx() {
- return cvsObjIdx;
- }
-
- public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
- this.cvsObjIdx = cvsObjIdx;
- }
-
- public void setAutoSaveNr(int autoSaveNr) {
- this.autoSaveNr = autoSaveNr;
- }
-
- public int getAutoSaveNr() {
- return autoSaveNr;
- }
-
- public int getNumberOfSaves() {
- return numberOfSaves;
- }
-
- public void setNumberOfSaves(int numberOfSaves) {
- this.numberOfSaves = numberOfSaves;
- }
-
- public void setClipboradObjects(ArrayList<AbstractCpsObject> c) {
- this.clipboardObjects = c;
- }
-
- public ArrayList<AbstractCpsObject> getClipboradObjects() {
- return clipboardObjects;
- }
-
- public void setConsole(Console console) {
- this.console = console;
- }
-
- public Console getConsole() {
- return console;
- }
-
- public float getMaxCapacity() {
- return maxCapacity;
- }
-
- public void setMaxCapacity(float maxCapacity) {
- this.maxCapacity = maxCapacity;
- }
-
- public void setTimerSpeed(int t) {
- this.timerSpeed = t;
- }
-
- public int getTimerSpeed() {
- return this.timerSpeed;
- }
-
- public void setIsSimulation(boolean isSimulation) {
- this.isSimulation = isSimulation;
- }
-
- public boolean getIsSimulation() {
- return this.isSimulation;
- }
-
- public int getCanvasX() {
- return canvasX;
- }
-
- public void setCanvasX(int canvasX) {
- this.canvasX = canvasX;
- }
-
- public int getCanvasY() {
- return canvasY;
- }
-
- public void setCanvasY(int canvasY) {
- this.canvasY = canvasY;
- }
-
- public Object getAlgorithm() {
- return algorithm;
- }
-
- public void setAlgorithm(Object obj) {
- this.algorithm = null;
- this.algorithm = obj;
- }
-
- public void addSubNetColor(Color c) {
- this.subNetColors.add(c);
- }
-
- public LinkedList<Color> getSubNetColors() {
- return this.subNetColors;
- }
- public void setTrackingObj(ArrayList<AbstractCpsObject> toTrack) {
- trackedObjects = toTrack;
- }
- public ArrayList<AbstractCpsObject> getTrackingObj() {
- return trackedObjects;
- }
- public void addGraphListener(GraphListener gl) {
- graphListeners.add(gl);
- }
- public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
- this.eleToDelete = theHash;
- }
- public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
- return this.eleToDelete;
- }
- public void setSingleTable(PropertyTable pt) {
- this.tableModelHolonElementSingle = pt;
- }
- public PropertyTable getSingleTable() {
- return this.tableModelHolonElementSingle;
- }
- public PropertyTable getMultiTable() {
- return this.tableModelHolonElementMulti;
- }
- public void setMultiTable(PropertyTable pt) {
- this.tableModelHolonElementMulti = pt;
- }
- public void addObjectsToGraphListeners() {
- for (GraphListener gl : graphListeners) {
- gl.addTrackedObject(trackedObjects);
- gl.repaintTree();
- }
- }
- public DefaulTable getPropertyTable() {
- return this.tableModelProperties;
- }
- public void setPropertyTable(DefaulTable pt) {
- this.tableModelProperties = pt;
- }
- public JTable getTableHolonElement() {
- return tableHolonElement;
- }
- public void setTableHolonElement(JTable tableHolonElement) {
- this.tableHolonElement = tableHolonElement;
- }
-
- public void setHolonBodyScale(int scale) {
- holonBodysCALE = scale;
- }
-
- public int getHolonBodyScale() {
- return holonBodysCALE;
- }
-
- public void setSelectedHolonBody(int i) {
- selectedHolonBody = i;
- }
-
- public int getSelectedHolonBody() {
- return selectedHolonBody;
- }
-
- public ArrayList<HolonSwitch> getSwitches() {
- ArrayList<HolonSwitch> switches = new ArrayList<>();
- for (AbstractCpsObject obj : getObjectsOnCanvas()) {
- if (obj instanceof HolonSwitch) {
- switches.add((HolonSwitch) obj);
- } else if (obj instanceof CpsUpperNode) {
- getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
- }
- }
- return switches;
- }
-
- private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCpsObject> objects,
- ArrayList<HolonSwitch> switches) {
- for (AbstractCpsObject obj : objects) {
- if (obj instanceof HolonSwitch) {
- switches.add((HolonSwitch) obj);
- } else if (obj instanceof CpsUpperNode) {
- getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
- }
- }
- return switches;
- }
- }
|