/** SimulationController Constructor, creates a SimulationController object. */ public SimulationController() { dataReceiver = new DataReceiver(); simulationBox = new SimulationBox(dataReceiver); simulationBox.setState(new NetworkEditing()); screen = new SimulatorScreen(simulationBox); networkHistory = new ArrayList<>(); transitHistory = new ArrayList<>(); analyser = NetworkAnalyser.getInstance(); currentNetwork = networkFactory.getNetworkElementFactory(NETWORK_NAME); currentTransit = networkFactory.getTransitFactory(NETWORK_NAME); animator = new Animator(); updateNetworkData(); RootListener root = new RootListener(simulationBox); RootWheelListener rootWheel = new RootWheelListener(simulationBox); RootMotionListener rootMotion = new RootMotionListener(simulationBox); RootKeyListener rootKey = new RootKeyListener(simulationBox); screen.getRenderer().addMouseListener(root); screen.getRenderer().addMouseWheelListener(rootWheel); screen.getRenderer().addMouseMotionListener(rootMotion); screen.getRenderer().requestFocus(); screen.getRenderer().addKeyListener(rootKey); screen.startDisplay(); }
public void updateNetworkData() { HashMap<String, HashMap<Integer, SimulationElement>> originalNetwork = new HashMap<>(); HashMap<String, HashMap<Integer, SimulationElement>> originalTransit = new HashMap<>(); HashMap<String, HashMap<Integer, SimulationElement>> networkCopy = new HashMap<>(); HashMap<String, HashMap<Integer, SimulationElement>> transitCopy = new HashMap<>(); HashMap<String, HashMap<Integer, SimulationElement>> totalCopy = new HashMap<>(); historyIndex++; removeRedo(); originalNetwork.putAll(currentNetwork.getNetworkElements()); originalTransit.putAll(currentTransit.getTransits()); for (Entry<String, HashMap<Integer, SimulationElement>> entry : originalNetwork.entrySet()) { networkCopy.put(entry.getKey(), new HashMap<>(entry.getValue())); } networkHistory.add(historyIndex, networkCopy); for (Entry<String, HashMap<Integer, SimulationElement>> entry : originalTransit.entrySet()) { transitCopy.put(entry.getKey(), new HashMap<>(entry.getValue())); } transitHistory.add(historyIndex, transitCopy); totalCopy.putAll(networkCopy); totalCopy.putAll(transitCopy); dataReceiver.updateSimulationElements(totalCopy); simulationBox.updateRendering(); }
private void deleteTransportNeed() { int transportNeedID = simulationBox.getSelectedTransportNeedID(); if (transportNeedID != -1) { currentTransit.removeTransportNeed(transportNeedID); } for (Integer transitID : simulationBox.getConcernedBySelectionTransitID()) { if (currentTransit.getTransits().get(Circuit.class.getSimpleName()).containsKey(transitID)) { currentTransit.removeCircuit(transitID); } if (currentTransit .getTransits() .get(TransportNeed.class.getSimpleName()) .containsKey(transitID)) { currentTransit.removeTransportNeed(transitID); } } }
private void parametriseAnimator() { AnimatorImage animationImage = simulationBox.getParametrisedAnimation(); int start = animationImage.getStartingTime(); int end = animationImage.getEndTime(); int replication = animationImage.getNumberOfReplication(); animator.parametrize(start, end, replication); }
public void deleteNetworkElement() { simulationBox.saveIdAndDeleteImages(); deleteTransportNeed(); deleteCircuit(); deleteSegments(); deleteStation(); deleteIntersection(); updateNetworkData(); }
/** * Use for undo and redo update. * * @param history The index of the required version of the network to reload */ public void updateHistoryData(int history) { HashMap<String, HashMap<Integer, SimulationElement>> original = new HashMap<>(); original.putAll(networkHistory.get(history)); original.putAll(transitHistory.get(history)); currentNetwork.setNetworkElements(networkHistory.get(history)); currentTransit.setTransits(transitHistory.get(history)); dataReceiver.updateSimulationElements(original); simulationBox.updateRendering(); }
private void saveNetworkElementChangement() { simulationBox.endEdition(); if (simulationBox.isElementModified()) { if (simulationBox.isAnimationModified()) { } else { SimulationElement modifiedElement = simulationBox.getModifiedElement(); if (isTransit(modifiedElement)) { Transit modifiedTransit = (Transit) modifiedElement; currentTransit.modifyTransit(modifiedTransit.getIdentifier(), modifiedTransit); } else { currentNetwork.modifyNetworkElement(modifiedElement.getIdentifier(), modifiedElement); if (simulationBox.isThereASecondSegment()) { Segment secondSegment = simulationBox.getModifiedSecondWay(); currentNetwork.modifyNetworkElement(secondSegment.getIdentifier(), secondSegment); } } updateNetworkData(); simulationBox.refreshElementsAfterModification(); } } }
private void deleteStation() { for (Integer stationID : simulationBox.getSelectedStationID()) { currentNetwork.removeStation(stationID); } }
private void deleteIntersection() { for (Integer intersectionID : simulationBox.getSelectedIntersectionID()) { currentNetwork.removeIntersection(intersectionID); } }
private void deleteSegments() { for (Integer segmentID : simulationBox.getInSelectionSegmentID()) { currentNetwork.removeSegment(segmentID); } }