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.
voting-station-gui
Vladimir ELazar Tokarev 2016-06-12 15:52:22 +03:00
parent 1fb96c8630
commit fc21a215d3
3 changed files with 61 additions and 22 deletions

View File

@ -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<String, EventHandler<Event>> eventIdToHandler;
public EventHandlerMap()
{
this.eventIdToHandler = new HashMap<>();
}
public void Add(String eventId, EventHandler<Event> eventHandler)
{
this.eventIdToHandler.put(eventId, eventHandler);
}
public void Handle(Event event)
{
this.eventIdToHandler.get(((Control)event.getSource()).getId()).handle(event);
}
}

View File

@ -1,32 +1,41 @@
package polling_station_dashboard.java; package polling_station_dashboard.java;
import javafx.event.Event; import javafx.stage.Stage;
import javafx.event.EventHandler; import polling_station_dashboard.settings.java.SettingsVisualUpdater;
import javafx.scene.control.Control; import polling_station_dashboard.settings.java.settingsLoader;
import java.util.HashMap; 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. * Created by Vladimir Eliezer Tokarev on 12/06/2016.
* EventHandlerMapper maps events ids (that are part of polling station dashboard) * EventHandlerMapper creates EventHandlerMap with objects that handles next parts:
* to the object that handles this specific event * 1. Status Log extension
* when EventHandlerMapper gets specific event it activates the handle method of the object * 2. Settings extension
* 3. Search Handling
*/ */
public class EventHandlerMapper { public class EventHandlerMapper {
private HashMap<String, EventHandler<Event>> eventIdToHandler; public static EventHandlerMap CreateEventHandlerMap(Stage primaryStage) throws IOException
public EventHandlerMapper()
{ {
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<Event> eventHandler)
{
this.eventIdToHandler.put(eventId, eventHandler);
}
public void Handle(Event event)
{
this.eventIdToHandler.get(((Control)event.getSource()).getId()).handle(event);
}
} }

View File

@ -6,8 +6,6 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.lang.reflect.Method;
/** /**
* Created by Vladimir Eliezer Tokarev on 12/06/2016. * Created by Vladimir Eliezer Tokarev on 12/06/2016.
* This object manages the visual changes of the settings panel * This object manages the visual changes of the settings panel