1 //
2 // Copyright (c) 2010-2018 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using System;
9 using Xwt;
10 using System.Collections.Generic;
11 using Antmicro.Renode.Peripherals;
12 using Antmicro.Renode.UserInterface;
13 
14 namespace Antmicro.Renode.UI
15 {
16     public class WindowedUserInterfaceProvider : IUserInterfaceProvider
17     {
ShowAnalyser(IAnalyzableBackendAnalyzer analyzer, string name)18         public void ShowAnalyser(IAnalyzableBackendAnalyzer analyzer, string name)
19         {
20             var guiWidget = analyzer as IHasWidget;
21             if(guiWidget == null)
22             {
23                 throw new ArgumentException("Wrong analyzer provided, expected object of type 'IHasGUIWidget'");
24             }
25 
26             var window = new Window();
27             window.Title = name;
28             window.Height = 600;
29             window.Width = 800;
30 
31             window.Content = guiWidget.Widget;
32 
33             openedWindows.Add(analyzer, window);
34             window.Closed += (sender, e) => openedWindows.Remove(analyzer);
35 
36             window.Show();
37         }
38 
HideAnalyser(IAnalyzableBackendAnalyzer analyzer)39         public void HideAnalyser(IAnalyzableBackendAnalyzer analyzer)
40         {
41             var guiAnalyzer = analyzer as IHasWidget;
42             if(guiAnalyzer == null)
43             {
44                 throw new ArgumentException("Wrong analyzer provided, expected object of type 'IHasGUIWidget'");
45             }
46 
47             Window win;
48             if(openedWindows.TryGetValue(analyzer, out win))
49             {
50                 win.Close();
51                 openedWindows.Remove(analyzer);
52             }
53         }
54 
55         private readonly Dictionary<IAnalyzableBackendAnalyzer, Window> openedWindows = new Dictionary<IAnalyzableBackendAnalyzer, Window>();
56     }
57 }
58 
59