Changed the managing of events in PSDController

Now thw evwnts management is in the EventHandlerMap
voting-station-gui
Vladimir ELazar Tokarev 2016-06-12 16:00:49 +03:00
parent fc21a215d3
commit 61c65594f5
4 changed files with 18 additions and 59 deletions

View File

@ -2,7 +2,7 @@ package polling_station_dashboard.java;
import javafx.event.Event; import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.control.Control; import javafx.scene.Parent;
import java.util.HashMap; import java.util.HashMap;
/** /**
@ -27,6 +27,6 @@ public class EventHandlerMap {
public void Handle(Event event) public void Handle(Event event)
{ {
this.eventIdToHandler.get(((Control)event.getSource()).getId()).handle(event); this.eventIdToHandler.get(((Parent)event.getSource()).getId()).handle(event);
} }
} }

View File

@ -25,17 +25,16 @@ public class EventHandlerMapper {
settingsLoader settingsLoader = new settingsLoader(primaryStage); settingsLoader settingsLoader = new settingsLoader(primaryStage);
SettingsVisualUpdater settingsVisualUpdater = SettingsVisualUpdater settingsVisualUpdater =
new SettingsVisualUpdater(settingsLoader.GetSettingsInstance(), primaryStage); new SettingsVisualUpdater(settingsLoader.GetSettingsInstance(), primaryStage);
map.Add("StatusLogButton", settingsVisualUpdater); map.Add("SettingsButton", settingsVisualUpdater);
map.Add("StatusLog", settingsVisualUpdater); map.Add("Settings", settingsVisualUpdater);
// map settings objects to status log visual updater // map settings objects to status log visual updater
StatusLogLoader statusLogLoader = new StatusLogLoader(primaryStage); StatusLogLoader statusLogLoader = new StatusLogLoader(primaryStage);
StatusLogVisualUpdater statusLogVisualUpdater = StatusLogVisualUpdater statusLogVisualUpdater =
new StatusLogVisualUpdater(statusLogLoader.GetStatusLogInstance(), primaryStage); new StatusLogVisualUpdater(statusLogLoader.GetStatusLogInstance(), primaryStage);
map.Add("SettingsButton", statusLogVisualUpdater); map.Add("StatusLogButton", statusLogVisualUpdater);
map.Add("Settings", statusLogVisualUpdater); map.Add("StatusLog", statusLogVisualUpdater);
return map;
return map
} }
} }

View File

@ -2,51 +2,34 @@ package polling_station_dashboard.java;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import polling_station_dashboard.statusLog.java.StatusLogUpdate;
import polling_station_dashboard.settings.java.SettingsUpdate;
/** /**
* Created by Vladimir Eliezer Tokarev on 28/05/2016. * Created by Vladimir Eliezer Tokarev on 28/05/2016.
* PollingStationDashboardController controls the behavior of the polling station dashboard * PollingStationDashboardController controls the behavior of the polling station dashboard
*/ */
public class PollingStationDashboardController { public class PollingStationDashboardController {
private EventHandlerMap eventHandlerMap;
private SettingsUpdate SettingsVisualUpdater; public void SetEventHandlerMap(EventHandlerMap map)
private StatusLogUpdate StatusLogVisualUpdater;
private Stage currentStage;
public void SetStage(Stage primaryStage)
{ {
this.currentStage = primaryStage; this.eventHandlerMap = map;
} }
@FXML
public void SetSettingsVisualUpdater(SettingsUpdate settingsVisualUpdater) private void OnStatusLogPressed(MouseEvent mousePressed)
{ {
this.SettingsVisualUpdater = settingsVisualUpdater; this.eventHandlerMap.Handle(mousePressed);
}
public void SetStatusLogVisualUpdater(StatusLogUpdate statusLogVisualUpdater)
{
this.StatusLogVisualUpdater = statusLogVisualUpdater;
} }
@FXML @FXML
private void OnStatusLogPressed(MouseEvent mousePresed) private void OnSettingsPressed(MouseEvent mousePressed)
{ {
StatusLogVisualUpdater.UpdateStatusLog(); this.eventHandlerMap.Handle(mousePressed);
} }
@FXML @FXML
private void OnSettingsPressed() private void SearchTrigered(MouseEvent mousePressed)
{ {
SettingsVisualUpdater.UpdateSettings(); this.eventHandlerMap.Handle(mousePressed);
}
@FXML
private void SearchTrigered(){
} }
} }

View File

@ -4,10 +4,6 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import polling_station_dashboard.settings.java.SettingsVisualUpdater;
import polling_station_dashboard.statusLog.java.StatusLogLoader;
import polling_station_dashboard.settings.java.settingsLoader;
import polling_station_dashboard.statusLog.java.StatusLogVisualUpdater;
import java.io.IOException; import java.io.IOException;
@ -35,25 +31,6 @@ public class PollingStationDashboardLoader {
currentStage.setScene(new Scene(root, 850, 615)); currentStage.setScene(new Scene(root, 850, 615));
currentStage.show(); currentStage.show();
controller.SetStage(currentStage); controller.SetEventHandlerMap(EventHandlerMapper.CreateEventHandlerMap(primaryStage));
setSettingsUpdater(controller);
setStatusLogUpdater(controller);
}
private void setSettingsUpdater(PollingStationDashboardController controller) throws IOException
{
settingsLoader settingsLoader = new settingsLoader(currentStage);
SettingsVisualUpdater settingsVisualUpdater =
new SettingsVisualUpdater(settingsLoader.GetSettingsInstance(), currentStage);
controller.SetSettingsVisualUpdater(settingsVisualUpdater);
}
private void setStatusLogUpdater(PollingStationDashboardController controller) throws IOException
{
StatusLogLoader statusLogLoader = new StatusLogLoader(currentStage);
StatusLogVisualUpdater statusLogVisualUpdater =
new StatusLogVisualUpdater(statusLogLoader.GetStatusLogInstance(), currentStage);
controller.SetStatusLogVisualUpdater(statusLogVisualUpdater);
} }
} }