From fc21a215d3aa1cf6f3075dff9302c03d363e6e94 Mon Sep 17 00:00:00 2001 From: Vladimir ELazar Tokarev Date: Sun, 12 Jun 2016 15:52:22 +0300 Subject: [PATCH] Created EventHandlerMapper This objects actualy creates Event Handler Map and fills it withs ids and the obhject that should manage the events with given ids. --- .../java/EventHandlerMap.java | 32 ++++++++++++ .../java/EventHandlerMapper.java | 49 +++++++++++-------- .../settings/java/SettingsVisualUpdater.java | 2 - 3 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 voting-station-gui/src/polling_station_dashboard/java/EventHandlerMap.java diff --git a/voting-station-gui/src/polling_station_dashboard/java/EventHandlerMap.java b/voting-station-gui/src/polling_station_dashboard/java/EventHandlerMap.java new file mode 100644 index 0000000..c62b47b --- /dev/null +++ b/voting-station-gui/src/polling_station_dashboard/java/EventHandlerMap.java @@ -0,0 +1,32 @@ +package polling_station_dashboard.java; + +import javafx.event.Event; +import javafx.event.EventHandler; +import javafx.scene.control.Control; +import java.util.HashMap; + +/** + * Created by Vladimir Eliezer Tokarev on 12/06/2016. + * EventHandlerMap maps events ids (that are part of polling station dashboard) + * to the object that handles this specific event + * when EventHandlerMap gets specific event it activates the handle method of the object + */ +public class EventHandlerMap { + + private HashMap> eventIdToHandler; + + public EventHandlerMap() + { + this.eventIdToHandler = new HashMap<>(); + } + + public void Add(String eventId, EventHandler eventHandler) + { + this.eventIdToHandler.put(eventId, eventHandler); + } + + public void Handle(Event event) + { + this.eventIdToHandler.get(((Control)event.getSource()).getId()).handle(event); + } +} diff --git a/voting-station-gui/src/polling_station_dashboard/java/EventHandlerMapper.java b/voting-station-gui/src/polling_station_dashboard/java/EventHandlerMapper.java index 3aa14d0..c72bfd4 100644 --- a/voting-station-gui/src/polling_station_dashboard/java/EventHandlerMapper.java +++ b/voting-station-gui/src/polling_station_dashboard/java/EventHandlerMapper.java @@ -1,32 +1,41 @@ package polling_station_dashboard.java; -import javafx.event.Event; -import javafx.event.EventHandler; -import javafx.scene.control.Control; -import java.util.HashMap; +import javafx.stage.Stage; +import polling_station_dashboard.settings.java.SettingsVisualUpdater; +import polling_station_dashboard.settings.java.settingsLoader; +import polling_station_dashboard.statusLog.java.StatusLogLoader; +import polling_station_dashboard.statusLog.java.StatusLogVisualUpdater; + +import java.io.IOException; /** * Created by Vladimir Eliezer Tokarev on 12/06/2016. - * EventHandlerMapper maps events ids (that are part of polling station dashboard) - * to the object that handles this specific event - * when EventHandlerMapper gets specific event it activates the handle method of the object + * EventHandlerMapper creates EventHandlerMap with objects that handles next parts: + * 1. Status Log extension + * 2. Settings extension + * 3. Search Handling */ public class EventHandlerMapper { - private HashMap> eventIdToHandler; - - public EventHandlerMapper() + public static EventHandlerMap CreateEventHandlerMap(Stage primaryStage) throws IOException { - this.eventIdToHandler = new HashMap<>(); + EventHandlerMap map = new EventHandlerMap(); + + // Map status log objects to settings visual updater + settingsLoader settingsLoader = new settingsLoader(primaryStage); + SettingsVisualUpdater settingsVisualUpdater = + new SettingsVisualUpdater(settingsLoader.GetSettingsInstance(), primaryStage); + map.Add("StatusLogButton", settingsVisualUpdater); + map.Add("StatusLog", settingsVisualUpdater); + + // map settings objects to status log visual updater + StatusLogLoader statusLogLoader = new StatusLogLoader(primaryStage); + StatusLogVisualUpdater statusLogVisualUpdater = + new StatusLogVisualUpdater(statusLogLoader.GetStatusLogInstance(), primaryStage); + map.Add("SettingsButton", statusLogVisualUpdater); + map.Add("Settings", statusLogVisualUpdater); + + return map } - public void Add(String eventId, EventHandler eventHandler) - { - this.eventIdToHandler.put(eventId, eventHandler); - } - - public void Handle(Event event) - { - this.eventIdToHandler.get(((Control)event.getSource()).getId()).handle(event); - } } diff --git a/voting-station-gui/src/polling_station_dashboard/settings/java/SettingsVisualUpdater.java b/voting-station-gui/src/polling_station_dashboard/settings/java/SettingsVisualUpdater.java index 996c1a1..4b32613 100644 --- a/voting-station-gui/src/polling_station_dashboard/settings/java/SettingsVisualUpdater.java +++ b/voting-station-gui/src/polling_station_dashboard/settings/java/SettingsVisualUpdater.java @@ -6,8 +6,6 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.stage.Stage; -import java.lang.reflect.Method; - /** * Created by Vladimir Eliezer Tokarev on 12/06/2016. * This object manages the visual changes of the settings panel