Microscopic Traffic Simulator
GUIInteractions.cs
Go to the documentation of this file.
2 using Microsoft.Win32;
3 using System;
4 using System.Windows;
5 
6 namespace Microscopic_Traffic_Simulator.Views
7 {
12  {
16  private App app;
17 
22  internal GUIInteractions(App app)
23  {
24  this.app = app;
25  }
26 
33  private bool? YesNoCancel(string title, string message)
34  {
35  MessageBoxResult result = MessageBox.Show(message, title,
36  MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
37  if (result == MessageBoxResult.Yes)
38  return true;
39  else if (result == MessageBoxResult.No)
40  return false;
41  else if (result == MessageBoxResult.Cancel)
42  return null;
43  else
44  throw new
45  ApplicationException(app.FindStringResource("UnexpectedErrorMessage"));
46  }
47 
53  private string GetPathToOpenFile(string filter)
54  {
55  OpenFileDialog ofd = new OpenFileDialog();
56  ofd.Filter = filter;
57  bool? result = ofd.ShowDialog();
58  if (result == true)
59  return ofd.FileName;
60  else
61  return null;
62  }
63 
69  private string GetPathToSaveFile(string filter)
70  {
71  SaveFileDialog sfd = new SaveFileDialog();
72  sfd.Filter = filter;
73  bool? result = sfd.ShowDialog();
74  if (result == true)
75  return sfd.FileName;
76  else
77  return null;
78  }
79 
84  public bool? SaveChangesYesNoCancel()
85  {
86  return YesNoCancel(app.FindStringResource("MainWindow_Title"),
87  app.FindStringResource("SaveChanges"));
88  }
89 
94  public string GetPathToOpenTopologyFile()
95  {
96  return GetPathToOpenFile(app.FindStringResource("GeometricTopologiesFilter"));
97  }
98 
104  {
105  return GetPathToSaveFile(app.FindStringResource("GeometricTopologiesFilter"));
106  }
107 
113  {
114  return GetPathToOpenFile(app.FindStringResource("ParametersFilter"));
115  }
116 
122  {
123  return GetPathToSaveFile(app.FindStringResource("ParametersFilter"));
124  }
125 
130  public void ScreamErrorMessage(string errorMessage)
131  {
132  MessageBox.Show(errorMessage, app.FindStringResource("MainWindow_Title"),
133  MessageBoxButton.OK, MessageBoxImage.Error);
134  }
135  }
136 }
GUIInteractions logic for App.xaml
Definition: App.xaml.cs:17
string GetPathToOpenTopologyFile()
Provide OpenFileDialog to open the topology file.
Class implements IInteractions interface by message boxes or dialogs.
Interface for interactions with user.
Definition: IInteractions.cs:6
string GetPathToOpenParametersFile()
Asking which parameters file to open for loading.
bool SaveChangesYesNoCancel()
Provide MessageBoxButton to ask question whether to save changes.
void ScreamErrorMessage(string errorMessage)
Provide MessageBox to scream error message.
string GetPathToSaveParametersFile()
Asking which paramters file the data to be saved into.
string GetPathToSaveTopologyFile()
Provide SaveFileDialog to get the path to file the topology to be saved to.