2626
2727namespace ORTS
2828{
29+ /// <summary>
30+ /// Holds presentation details of the current notification displayed on the panel.
31+ /// </summary>
2932 public class NotificationPage
3033 {
34+ private Panel Panel ; // Needed so that controls can be added
35+ private MainForm MainForm ; // Needed so the Retry button can raise an event which the form can catch.
36+
37+ // Holds size of items, so they can be positioned on the panel
3138 public List < NDetail > NDetailList = new List < NDetail > ( ) ;
39+
40+ // Holds the index of each button on the page and the button, so the correct action can be taken depending on the type of button and its index.
3241 public Dictionary < int , NButtonControl > ButtonDictionary = new Dictionary < int , NButtonControl > ( ) ;
33- public Panel Panel ;
34- private MainForm MainForm ; // Needed so the Retry button can raise an event which the form can catch.
35- public List < Control > ControlList = new List < Control > ( ) ;
3642
3743 public NotificationPage ( MainForm mainForm , Panel panel , NotificationManager manager )
3844 {
@@ -44,7 +50,7 @@ public NotificationPage(MainForm mainForm, Panel panel, NotificationManager mana
4450
4551 private void AddPageCountAndArrows ( NotificationManager manager )
4652 {
47- var pageCount = manager . Notifications ? . NotificationList . Count ?? 0 ; // If not Internet, then Notifications == null
53+ var pageCount = manager . Notifications ? . NotificationList . Count ?? 0 ; // If no Internet connection , then Notifications == null
4854 var pageLabel = $ "{ manager . CurrentNotificationNo + 1 } /{ pageCount } ";
4955
5056 // Swap visibility for clickable arrows and disabled ones at each end of range.
@@ -92,6 +98,9 @@ public Arrow(Panel panel, Image image, bool visible, bool enabled, int indentRig
9298 }
9399 }
94100
101+ #region NDetails
102+ // An NDetail may create one or more controls and add them to the page's panel.
103+
95104 public class NDetail
96105 {
97106 public Label Control ;
@@ -107,31 +116,28 @@ public class NDetail
107116 public const int ScrollBarWidth = 20 ;
108117 }
109118
110- /// <summary>
111- /// Title for the notification
112- /// </summary>
113119 public class NTitleControl : NDetail
114120 {
115- public NTitleControl ( NotificationPage page , int current , int total , string date , string text ) // : base(page )
121+ public NTitleControl ( Panel panel , int current , int total , string date , string text )
116122 {
117123 var title = $ "Notification { current } /{ total } : { date } - { text } ";
118124 var left = LeftPadding ;
119125 Control = new Label
120126 {
121127 Text = title ,
122128 UseMnemonic = false ,
123- Font = new Font ( page . Panel . Font , FontStyle . Bold ) ,
129+ Font = new Font ( panel . Font , FontStyle . Bold ) ,
124130 TextAlign = ContentAlignment . BottomLeft ,
125131 Height = TitleHeight ,
126- Width = page . Panel . Width - ScrollBarWidth - left ,
132+ Width = panel . Width - ScrollBarWidth - left ,
127133 Left = LeftPadding
128134 } ;
129- page . Panel . Controls . Add ( Control ) ;
135+ panel . Controls . Add ( Control ) ;
130136 }
131137 }
132138 public class NHeadingControl : NDetail
133139 {
134- public NHeadingControl ( NotificationPage page , string text , string colorName = "blue" ) //: base(page )
140+ public NHeadingControl ( Panel panel , string text , string colorName = "blue" )
135141 {
136142 var color = Color . FromName ( colorName ) ;
137143 var left = LeftPadding ;
@@ -140,19 +146,19 @@ public NHeadingControl(NotificationPage page, string text, string colorName = "b
140146 ForeColor = color ,
141147 Text = text ,
142148 UseMnemonic = false ,
143- Font = new Font ( page . Panel . Font , FontStyle . Bold ) ,
149+ Font = new Font ( panel . Font , FontStyle . Bold ) ,
144150 TextAlign = ContentAlignment . BottomLeft ,
145151 Height = HeadingHeight ,
146- Width = page . Panel . Width - ScrollBarWidth - left ,
152+ Width = panel . Width - ScrollBarWidth - left ,
147153 Left = left ,
148154 Top = TopPadding ,
149155 } ;
150- page . Panel . Controls . Add ( Control ) ;
156+ panel . Controls . Add ( Control ) ;
151157 }
152158 }
153159 public class NTextControl : NDetail
154160 {
155- public NTextControl ( NotificationPage page , string text , string colorName = "black" ) // : base(page )
161+ public NTextControl ( Panel panel , string text , string colorName = "black" )
156162 {
157163 var color = Color . FromName ( colorName ) ;
158164 var left = LeftPaddingIndented ;
@@ -161,36 +167,36 @@ public NTextControl(NotificationPage page, string text, string colorName = "blac
161167 ForeColor = color ,
162168 Text = text ,
163169 UseMnemonic = false ,
164- Font = new Font ( page . Panel . Font , FontStyle . Regular ) ,
170+ Font = new Font ( panel . Font , FontStyle . Regular ) ,
165171 TextAlign = ContentAlignment . BottomLeft ,
166172 Height = TextHeight ,
167- Width = page . Panel . Width - ScrollBarWidth - left ,
173+ Width = panel . Width - ScrollBarWidth - left ,
168174 Left = left ,
169175 } ;
170- page . Panel . Controls . Add ( Control ) ;
176+ panel . Controls . Add ( Control ) ;
171177 }
172178 }
173179 public class NButtonControl : NDetail
174180 {
175181 public static int ButtonCount = 0 ;
176182 public Button Button ;
177- public NButtonControl ( NotificationPage page , string legend , int width , string description , MainForm mainForm ) //: base(page )
183+ public NButtonControl ( Panel panel , string legend , int width , string description , MainForm mainForm )
178184 {
179185 var buttonLeft = LeftPaddingIndented ;
180186 Button = new Button
181187 {
182188 Margin = new Padding ( 20 ) ,
183189 Text = legend ,
184190 UseMnemonic = false ,
185- Font = new Font ( page . Panel . Font , FontStyle . Regular ) ,
191+ Font = new Font ( panel . Font , FontStyle . Regular ) ,
186192 TextAlign = ContentAlignment . MiddleCenter ,
187193 Height = ButtonHeight ,
188194 Width = width ,
189195 Left = buttonLeft ,
190196 Top = TopPadding ,
191197 BackColor = SystemColors . ButtonFace
192198 } ;
193- page . Panel . Controls . Add ( Button ) ;
199+ panel . Controls . Add ( Button ) ;
194200
195201 // 3 should be enough, but is there a way to get unlimited buttons?
196202 switch ( ButtonCount )
@@ -215,21 +221,21 @@ public NButtonControl(NotificationPage page, string legend, int width, string de
215221 Margin = new Padding ( 20 ) ,
216222 Text = description ,
217223 UseMnemonic = false ,
218- Font = new Font ( page . Panel . Font , FontStyle . Regular ) ,
224+ Font = new Font ( panel . Font , FontStyle . Regular ) ,
219225 TextAlign = ContentAlignment . MiddleLeft ,
220226 Height = ButtonHeight ,
221- Width = page . Panel . Width - ScrollBarWidth - labelLeft ,
227+ Width = panel . Width - ScrollBarWidth - labelLeft ,
222228 Top = TopPadding ,
223229 Left = labelLeft
224230 } ;
225- page . Panel . Controls . Add ( Control ) ;
231+ panel . Controls . Add ( Control ) ;
226232 }
227233 }
228234 public class NLinkControl : NButtonControl
229235 {
230236 public string Url ;
231237 public NLinkControl ( NotificationPage page , string legend , int width , string description , MainForm mainForm , string url )
232- : base ( page , legend , width , description , mainForm )
238+ : base ( page . Panel , legend , width , description , mainForm )
233239 {
234240 Url = url ;
235241 page . ButtonDictionary . Add ( ButtonCount , this ) ;
@@ -239,7 +245,7 @@ public NLinkControl(NotificationPage page, string legend, int width, string desc
239245 public class NUpdateControl : NButtonControl
240246 {
241247 public NUpdateControl ( NotificationPage page , string legend , int width , string description , MainForm mainForm )
242- : base ( page , legend , width , description , mainForm )
248+ : base ( page . Panel , legend , width , description , mainForm )
243249 {
244250 page . ButtonDictionary . Add ( ButtonCount , this ) ;
245251 ButtonCount ++ ;
@@ -248,7 +254,7 @@ public NUpdateControl(NotificationPage page, string legend, int width, string de
248254 public class NRetryControl : NButtonControl
249255 {
250256 public NRetryControl ( NotificationPage page , string legend , int width , string description , MainForm mainForm )
251- : base ( page , legend , width , description , mainForm )
257+ : base ( page . Panel , legend , width , description , mainForm )
252258 {
253259 page . ButtonDictionary . Add ( ButtonCount , this ) ;
254260 ButtonCount ++ ;
@@ -271,34 +277,34 @@ public class NRecordControl : NDetail
271277 {
272278 public Label Field ;
273279
274- public NRecordControl ( NotificationPage page , string label , int width , string field ) //: base(page)
280+ public NRecordControl ( Panel panel , string label , int width , string field ) //: base(page)
275281 {
276282 Control = new Label
277283 {
278284 Text = label + ":" ,
279285 UseMnemonic = false ,
280- Font = new Font ( page . Panel . Font , FontStyle . Bold ) ,
286+ Font = new Font ( panel . Font , FontStyle . Bold ) ,
281287 TextAlign = ContentAlignment . BottomRight ,
282288 Width = width ,
283289 Height = RecordHeight ,
284290 Left = LeftPadding ,
285291 Top = TopPadding
286292 } ;
287- page . Panel . Controls . Add ( Control ) ;
293+ panel . Controls . Add ( Control ) ;
288294
289295 var left = width + LeftPadding ;
290296 Field = new Label
291297 {
292298 Text = field ,
293299 UseMnemonic = false ,
294- Font = new Font ( page . Panel . Font , FontStyle . Regular ) ,
300+ Font = new Font ( panel . Font , FontStyle . Regular ) ,
295301 TextAlign = ContentAlignment . BottomLeft ,
296- Width = page . Panel . Width - ScrollBarWidth - left ,
302+ Width = panel . Width - ScrollBarWidth - left ,
297303 Height = RecordHeight ,
298304 Left = left ,
299305 Top = TopPadding
300306 } ;
301- page . Panel . Controls . Add ( Field ) ;
307+ panel . Controls . Add ( Field ) ;
302308 }
303309 }
304310
@@ -323,5 +329,6 @@ public void FlowNDetails()
323329 top += nDetail . Control . Height + NDetail . VerticalSpacing ;
324330 }
325331 }
332+ #endregion NDetails
326333 }
327334}
0 commit comments