/** * Generate the AODV animation * * @param props The properties to use for the look & feel * @param primitives The preconfigured primitives from the wizard * @return The animation as a string in AnimalScript */ public String generate(AnimationPropertiesContainer props, Hashtable<String, Object> primitives) { controller.drawStartPage(); controller.hideStartPage(); controller.drawGUIGraph(); controller.drawInfoTable(aodvGraph.getAODVNodes()); controller.drawStatisticTable(translator.translateMessage("statTableTitle")); controller.drawInfoBox(translator.translateMessage("infoBox")); AODVNode startNode; AODVNode destinationNode; // Reset the statistics Statistics.sharedInstance().reset(); for (String[] startEndNodes : routeDiscoveries) { startNode = aodvGraph.getNode(startEndNodes[0]); destinationNode = aodvGraph.getNode(startEndNodes[1]); if (startNode != null && destinationNode != null) { controller.drawNodeInfo(startNode, destinationNode); startAodvRouting(startNode, destinationNode); controller.unhighlightAll(); } } // Draws the end page with the complexity information of AODV controller.drawEndPage(); return lang.toString(); }
/** * Starts the AODV Routing Algorithm * * @param startNode Node which starts a route request to the destination node * @param destinationNode Node which is set as the destination for the route request. */ public void startAodvRouting(AODVNode startNode, AODVNode destinationNode) { startNode.startRouteDiscovery(destinationNode); int idleNodes = 0; ArrayList<AODVNode> workingNodes = new ArrayList<AODVNode>(aodvGraph.getAODVNodes().size()); // for(int i = 0; i < 4; i++) { while (idleNodes < aodvGraph.getAODVNodes().size()) { idleNodes = 0; workingNodes.clear(); for (AODVNode node : aodvGraph.getAODVNodes()) { if (node.getCachedMessage() != null) { workingNodes.add(node); } else { idleNodes++; } } for (AODVNode node : workingNodes) { controller.unhighlightAll(); node.process(); lang.nextStep(); } } }
/** * Validates the properties and constructs thereby Objects for the later animation generation * * @param animationPropertieses * @param stringObjectHashtable * @return false if the properties are not valid * @throws IllegalArgumentException */ @Override public boolean validateInput( AnimationPropertiesContainer animationPropertieses, Hashtable<String, Object> stringObjectHashtable) throws IllegalArgumentException { lang = new AnimalScript( "Ad-hoc Optimized Vector Routing", "Sascha Bleidner, Jan David Nose", 1200, 800); lang.setStepMode(true); routeDiscoveries = (String[][]) stringObjectHashtable.get("StartandEndnodes"); Graph loadedGraph = (Graph) stringObjectHashtable.get("graph"); controller = new GUIController(lang, loadedGraph, translator, animationPropertieses); aodvGraph = new AODVGraph(controller.getAnimalGraph(), controller); for (String[] startEndNodes : routeDiscoveries) { if (startEndNodes.length != 2) { showErrorMessage(translator.translateMessage("errorMessageWrongNumberNodes")); return false; } else { AODVNode startNode = aodvGraph.getNode(startEndNodes[0]); AODVNode destinationNode = aodvGraph.getNode(startEndNodes[1]); if (startNode == null || !aodvGraph.containsNode(startNode)) { showErrorMessage(translator.translateMessage("errorMessageStartNodeNotFound")); return false; } else { if (destinationNode == null || !aodvGraph.containsNode(destinationNode)) { showErrorMessage(translator.translateMessage("errorMessageDestinationNodeNotFound")); return false; } } } } return true; }
/** @param args Unused as this is a GUI */ public static void main(String[] args) { GUIController appController = new GUIController(); appController.start(); }
/** * Constructs a WorldFrame that displays the occupants of a world * * @param world the world to display */ public WorldFrame(World<T> world) { this.world = world; count++; resources = ResourceBundle.getBundle(getClass().getName() + "Resources"); try { System.setProperty("sun.awt.exception.handler", GUIExceptionHandler.class.getName()); } catch (SecurityException ex) { // will fail in an applet } addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent event) { count--; if (count == 0) System.exit(0); } }); displayMap = new DisplayMap(); String title = System.getProperty("info.gridworld.gui.frametitle"); if (title == null) title = resources.getString("frame.title"); setTitle(title); setLocation(25, 15); URL appIconUrl = getClass().getResource("GridWorld.gif"); ImageIcon appIcon = new ImageIcon(appIconUrl); setIconImage(appIcon.getImage()); makeMenus(); JPanel content = new JPanel(); content.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); content.setLayout(new BorderLayout()); setContentPane(content); display = new GridPanel(displayMap, resources); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addKeyEventDispatcher( new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent event) { if (getFocusOwner() == null) return false; String text = KeyStroke.getKeyStrokeForEvent(event).toString(); final String PRESSED = "pressed "; int n = text.indexOf(PRESSED); if (n < 0) return false; // filter out modifier keys; they are neither characters or actions if (event.getKeyChar() == KeyEvent.CHAR_UNDEFINED && !event.isActionKey()) return false; text = text.substring(0, n) + text.substring(n + PRESSED.length()); boolean consumed = getWorld().keyPressed(text, display.getCurrentLocation()); if (consumed) repaint(); return consumed; } }); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewport(new PseudoInfiniteViewport(scrollPane)); scrollPane.setViewportView(display); content.add(scrollPane, BorderLayout.CENTER); gridClasses = new TreeSet<Class>( new Comparator<Class>() { public int compare(Class a, Class b) { return a.getName().compareTo(b.getName()); } }); for (String name : world.getGridClasses()) try { gridClasses.add(Class.forName(name)); } catch (Exception ex) { ex.printStackTrace(); } Grid<T> gr = world.getGrid(); gridClasses.add(gr.getClass()); makeNewGridMenu(); control = new GUIController<T>(this, display, displayMap, resources); content.add(control.controlPanel(), BorderLayout.SOUTH); messageArea = new JTextArea(2, 35); messageArea.setEditable(false); messageArea.setFocusable(false); messageArea.setBackground(new Color(0xFAFAD2)); content.add(new JScrollPane(messageArea), BorderLayout.NORTH); pack(); repaint(); // to show message display.setGrid(gr); }
/** @param content the {@link GUIContent} to be changed. */ public void changeSelectedContent(final GUIContent content) { contentPanel.setResult(content.getURLProcessorResult()); guiController.updateContent(content); }
/** @param configuration The {@link Configuration} to be updated. */ public void updateConfiguration(final Configuration configuration) { guiController.updateConfiguration(configuration); }
public void loadProgram(File output) { _loadedProgram = output; _guiController.loadProgram(); }
public void programHalted() { _main.getExecuteFrame().programHalted((int) _guiController.getBT()); }
public void init() { _main.getExecuteFrame().insertOutputComponent(_guiController.getMonitor()); _main.getExecuteFrame().insertInputComponent(createInputPanel()); }