PdnStatusBar.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using Resources;
  2. using SmartCoalApplication.Base;
  3. using SmartCoalApplication.SystemLayer;
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. namespace SmartCoalApplication
  8. {
  9. internal sealed class PdnStatusBar : StatusStrip, IStatusBarProgress
  10. {
  11. private System.Windows.Forms.ToolStripStatusLabel contextStatusLabel;
  12. private System.Windows.Forms.ToolStripSeparator progressStatusSeparator;
  13. private System.Windows.Forms.ToolStripProgressBar progressStatusBar;
  14. private System.Windows.Forms.ToolStripStatusLabel imageInfoStatusLabel;
  15. private System.Windows.Forms.ToolStripStatusLabel cursorInfoStatusLabel;
  16. private string progressTextFormat = PdnResources.GetString("StatusBar.Progress.Percentage.Format");
  17. private ImageResource contextStatusImage;
  18. public string ImageInfoStatusText
  19. {
  20. get
  21. {
  22. return this.imageInfoStatusLabel.Text;
  23. }
  24. set
  25. {
  26. this.imageInfoStatusLabel.Text = value;
  27. Update();
  28. }
  29. }
  30. public string ContextStatusText
  31. {
  32. get
  33. {
  34. return this.contextStatusLabel.Text;
  35. }
  36. set
  37. {
  38. this.contextStatusLabel.Text = value;
  39. Update();
  40. }
  41. }
  42. public ImageResource ContextStatusImage
  43. {
  44. get
  45. {
  46. return this.contextStatusImage;
  47. }
  48. set
  49. {
  50. this.contextStatusImage = value;
  51. if (this.contextStatusImage == null)
  52. {
  53. this.contextStatusLabel.Image = null;
  54. }
  55. else
  56. {
  57. this.contextStatusLabel.Image = this.contextStatusImage.Reference;
  58. }
  59. Update();
  60. }
  61. }
  62. public string CursorInfoText
  63. {
  64. get
  65. {
  66. return this.cursorInfoStatusLabel.Text;
  67. }
  68. set
  69. {
  70. this.cursorInfoStatusLabel.Text = value;
  71. Update();
  72. }
  73. }
  74. public void ResetProgressStatusBarAsync()
  75. {
  76. this.BeginInvoke(new Procedure(ResetProgressStatusBar));
  77. }
  78. public void EraseProgressStatusBar()
  79. {
  80. try
  81. {
  82. this.progressStatusSeparator.Visible = false;
  83. this.progressStatusBar.Visible = false;
  84. this.progressStatusBar.Value = 0;
  85. }
  86. catch (NullReferenceException)
  87. {
  88. // See bug #2212 -- appears to be a bug in the framework
  89. }
  90. }
  91. public void EraseProgressStatusBarAsync()
  92. {
  93. this.BeginInvoke(new Procedure(EraseProgressStatusBar));
  94. }
  95. public void ResetProgressStatusBar()
  96. {
  97. try
  98. {
  99. this.progressStatusBar.Value = 0;
  100. this.progressStatusSeparator.Visible = true;
  101. this.progressStatusBar.Visible = true;
  102. }
  103. catch (NullReferenceException)
  104. {
  105. }
  106. }
  107. public double GetProgressStatusBarValue()
  108. {
  109. lock (this.progressStatusBar)
  110. {
  111. return this.progressStatusBar.Value;
  112. }
  113. }
  114. public void SetProgressStatusBar(double percent)
  115. {
  116. lock (this.progressStatusBar)
  117. {
  118. this.progressStatusBar.Value = (int)percent;
  119. bool visible = (percent != 100);
  120. this.progressStatusBar.Visible = visible;
  121. this.progressStatusSeparator.Visible = visible;
  122. }
  123. }
  124. public PdnStatusBar()
  125. {
  126. InitializeComponent();
  127. this.cursorInfoStatusLabel.Image = PdnResources.GetImageResource("Icons.CursorXYIcon.png").Reference;
  128. this.cursorInfoStatusLabel.Text = string.Empty;
  129. this.imageInfoStatusLabel.Image = PdnResources.GetImageResource("Icons.ImageSizeIcon.png").Reference;
  130. this.progressStatusBar.Visible = false;
  131. this.progressStatusSeparator.Visible = false;
  132. this.progressStatusBar.Height -= 4;
  133. this.progressStatusBar.ProgressBar.Style = ProgressBarStyle.Continuous;
  134. }
  135. private void InitializeComponent()
  136. {
  137. this.contextStatusLabel = new ToolStripStatusLabel();
  138. this.progressStatusSeparator = new ToolStripSeparator();
  139. this.progressStatusBar = new ToolStripProgressBar();
  140. this.imageInfoStatusLabel = new ToolStripStatusLabel();
  141. this.cursorInfoStatusLabel = new ToolStripStatusLabel();
  142. SuspendLayout();
  143. //
  144. // contextStatusLabel
  145. //
  146. this.contextStatusLabel.Name = "contextStatusLabel";
  147. this.contextStatusLabel.Width = UI.ScaleWidth(436);
  148. this.contextStatusLabel.Spring = true;
  149. this.contextStatusLabel.TextAlign = ContentAlignment.MiddleLeft;
  150. this.contextStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
  151. //
  152. // progressStatusBar
  153. //
  154. this.progressStatusBar.Name = "progressStatusBar";
  155. this.progressStatusBar.Width = 130;
  156. this.progressStatusBar.AutoSize = false;
  157. //
  158. // imageInfoStatusLabel
  159. //
  160. this.imageInfoStatusLabel.Name = "imageInfoStatusLabel";
  161. this.imageInfoStatusLabel.Width = UI.ScaleWidth(130);
  162. this.imageInfoStatusLabel.TextAlign = ContentAlignment.MiddleLeft;
  163. this.imageInfoStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
  164. this.imageInfoStatusLabel.AutoSize = false;
  165. //
  166. // cursorInfoStatusLabel
  167. //
  168. this.cursorInfoStatusLabel.Name = "cursorInfoStatusLabel";
  169. this.cursorInfoStatusLabel.Width = UI.ScaleWidth(230);
  170. this.cursorInfoStatusLabel.TextAlign = ContentAlignment.MiddleLeft;
  171. this.cursorInfoStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
  172. this.cursorInfoStatusLabel.AutoSize = false;
  173. //
  174. // PdnStatusBar
  175. //
  176. this.Name = "PdnStatusBar";
  177. this.Items.Add(this.contextStatusLabel);
  178. this.Items.Add(this.progressStatusSeparator);
  179. this.Items.Add(this.progressStatusBar);
  180. this.Items.Add(new ToolStripSeparator());
  181. this.Items.Add(this.imageInfoStatusLabel);
  182. this.Items.Add(new ToolStripSeparator());
  183. this.Items.Add(this.cursorInfoStatusLabel);
  184. ResumeLayout(false);
  185. }
  186. }
  187. }