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
parent
1fb96c8630
commit
fc21a215d3
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<String, EventHandler<Event>> 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<Event> eventHandler)
|
||||
{
|
||||
this.eventIdToHandler.put(eventId, eventHandler);
|
||||
}
|
||||
|
||||
public void Handle(Event event)
|
||||
{
|
||||
this.eventIdToHandler.get(((Control)event.getSource()).getId()).handle(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue