Added Ecent Handler Mapper

Polling Station Dashboard have a lot of logics extend or close some
pannels (Settings and the Status log), search for users, and eddit those
users.
In order to simplfy the logic of Polling Station Dashboard Controler this
class was invented, the idea behind is simple every time some event is
trigered we will activate the apropriate handle method of the apropriate
object, this way if tomorow for say i want to implement different search
algoritm of users i will only change the UserSearch part.
voting-station-gui
Vladimir ELazar Tokarev 2016-06-12 15:20:29 +03:00
parent c80aa8efc1
commit 1fb96c8630
12 changed files with 55 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 805 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,11 +1,12 @@
package polling_station_dashboard.statusLog.java;
import javafx.event.EventHandler;
/**
* Created by Vladimir Eliezer Tokarev on 04/06/2016.
* StatusLogUpdate gives the ability to update the status log object
* decouple status log from polling station dashboard
*/
public interface StatusLogUpdate {
public interface StatusLogUpdate extends EventHandler {
void UpdateStatusLog();
}

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.
* 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
*/
public class EventHandlerMapper {
private HashMap<String, EventHandler<Event>> eventIdToHandler;
public EventHandlerMapper()
{
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,6 +1,7 @@
package polling_station_dashboard.java;
import javafx.fxml.FXML;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import polling_station_dashboard.statusLog.java.StatusLogUpdate;
import polling_station_dashboard.settings.java.SettingsUpdate;
@ -31,7 +32,7 @@ public class PollingStationDashboardController {
}
@FXML
private void OnStatusLogPressed()
private void OnStatusLogPressed(MouseEvent mousePresed)
{
StatusLogVisualUpdater.UpdateStatusLog();
}

View File

@ -1,11 +1,13 @@
package polling_station_dashboard.settings.java;
import javafx.event.EventHandler;
/**
* Created by Vladimir Eliezer Tokarev on 04/06/2016.
* SettingsUpdate gives the ability to update the settings object
* decouple settings from polling station dashboard
* this interface extends InvocationHandler in order to be able to be called
*/
public interface SettingsUpdate {
public interface SettingsUpdate extends EventHandler {
void UpdateSettings();
}

View File

@ -1,10 +1,13 @@
package polling_station_dashboard.settings.java;
import javafx.event.Event;
import javafx.scene.control.Button;
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
@ -57,4 +60,9 @@ public class SettingsVisualUpdater implements SettingsUpdate {
Pane settingsPane = (Pane) currentStage.getScene().lookup("#Settings");
settingsPane.getChildren().remove(settings);
}
@Override
public void handle(Event event) {
UpdateSettings();
}
}

View File

@ -1,5 +1,6 @@
package polling_station_dashboard.statusLog.java;
import javafx.event.Event;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
@ -60,4 +61,8 @@ public class StatusLogVisualUpdater implements StatusLogUpdate {
}
@Override
public void handle(Event event) {
UpdateStatusLog();
}
}