PeriodicTableVisualSettings.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. namespace OINA.Extender.Testharness
  2. {
  3. using System;
  4. using System.Drawing;
  5. using System.Windows;
  6. using System.Windows.Forms;
  7. using OINA.Extender.Controls.Styles;
  8. /// <summary>
  9. /// The PeriodicTable Visual settings form
  10. /// </summary>
  11. public partial class PeriodicTableVisualSettings : Form
  12. {
  13. /// <summary>
  14. /// Gets or sets the background colour
  15. /// </summary>
  16. private static Color BackgroundColor
  17. {
  18. get { return ColorConverter.Convert(PeriodicTableStyle.BackgroundColor); }
  19. set { PeriodicTableStyle.BackgroundColor = ColorConverter.Convert(value); }
  20. }
  21. /// <summary>
  22. /// Gets or sets the color of the included element.
  23. /// </summary>
  24. private static Color IncludedElementColor
  25. {
  26. get { return ColorConverter.Convert(PeriodicTableStyle.ElementIncludeBackgroundColor); }
  27. set { PeriodicTableStyle.ElementIncludeBackgroundColor = ColorConverter.Convert(value); }
  28. }
  29. /// <summary>
  30. /// Gets or sets the color of the excluded element.
  31. /// </summary>
  32. private static Color ExcludedElementColor
  33. {
  34. get { return ColorConverter.Convert(PeriodicTableStyle.ElementExcludeBackgroundColor); }
  35. set { PeriodicTableStyle.ElementExcludeBackgroundColor = ColorConverter.Convert(value); }
  36. }
  37. /// <summary>
  38. /// Gets or sets the color of the idle element.
  39. /// </summary>
  40. private static Color IdleElementColor
  41. {
  42. get { return ColorConverter.Convert(PeriodicTableStyle.ElementIdleBackgroundColor); }
  43. set { PeriodicTableStyle.ElementIdleBackgroundColor = ColorConverter.Convert(value); }
  44. }
  45. /// <summary>
  46. /// Gets or sets the color of the element highlight.
  47. /// </summary>
  48. private static Color ElementHighlightColor
  49. {
  50. get { return ColorConverter.Convert(PeriodicTableStyle.ElementHighlightColor); }
  51. set { PeriodicTableStyle.ElementHighlightColor = ColorConverter.Convert(value); }
  52. }
  53. /// <summary>
  54. /// Gets or sets the color of the element border.
  55. /// </summary>
  56. private static Color ElementBorderColor
  57. {
  58. get { return ColorConverter.Convert(PeriodicTableStyle.ElementBorderColor); }
  59. set { PeriodicTableStyle.ElementBorderColor = ColorConverter.Convert(value); }
  60. }
  61. /// <summary>
  62. /// Gets or sets the color of the element font.
  63. /// </summary>
  64. private static Color ElementFontColor
  65. {
  66. get { return ColorConverter.Convert(PeriodicTableStyle.ElementFontColor); }
  67. set { PeriodicTableStyle.ElementFontColor = ColorConverter.Convert(value); }
  68. }
  69. /// <summary>
  70. /// Initializes a new instance of the <see cref="PeriodicTableVisualSettings"/> class.
  71. /// </summary>
  72. public PeriodicTableVisualSettings()
  73. {
  74. this.InitializeComponent();
  75. this.UpdatePanelColors();
  76. this.InitializeCombos();
  77. this.UpdateCombos();
  78. this.backgroundColorComboBox.SelectedValueChanged += this.BackgroundColorComboBox_SelectedValueChanged;
  79. this.includedElementColorComboBox.SelectedValueChanged += this.IncludedElementColorComboBox_SelectedValueChanged;
  80. this.excludedElementsColorComboBox.SelectedValueChanged += this.ExcludedElementsColorComboBox_SelectedValueChanged;
  81. this.idleElementColorComboBox.SelectedValueChanged += this.UnsetElementColorComboBox_SelectedValueChanged;
  82. this.elementHighlightColorComboBox.SelectedValueChanged += this.ElementHighlightColorComboBox_SelectedValueChanged;
  83. this.elementBorderColorComboBox.SelectedValueChanged += this.ElementBorderColorComboBox_SelectedValueChanged;
  84. this.fontFamilyComboBox.SelectedValueChanged += this.FontFamilyComboBox_SelectedValueChanged;
  85. this.fontStyleComboBox.SelectedValueChanged += this.FontStyleComboBox_SelectedValueChanged;
  86. this.fontSizeComboBox.SelectedValueChanged += this.FontSizeComboBox_SelectedValueChanged;
  87. this.elementFontColorComboBox.SelectedIndexChanged += this.ElementFontColorComboBox_SelectedIndexChanged;
  88. }
  89. /// <summary>
  90. /// Fills the combos with items
  91. /// </summary>
  92. private void InitializeCombos()
  93. {
  94. this.backgroundColorComboBox.DataSource = ColorConverter.GetSystemDrawingColors();
  95. this.includedElementColorComboBox.DataSource = ColorConverter.GetSystemDrawingColors();
  96. this.excludedElementsColorComboBox.DataSource = ColorConverter.GetSystemDrawingColors();
  97. this.idleElementColorComboBox.DataSource = ColorConverter.GetSystemDrawingColors();
  98. this.elementBorderColorComboBox.DataSource = ColorConverter.GetSystemDrawingColors();
  99. this.elementHighlightColorComboBox.DataSource = ColorConverter.GetSystemDrawingColors();
  100. this.elementFontColorComboBox.DataSource = ColorConverter.GetSystemDrawingColors();
  101. this.fontFamilyComboBox.DataSource = System.Windows.Media.Fonts.SystemFontFamilies;
  102. this.fontFamilyComboBox.SelectedItem = PeriodicTableStyle.PeriodicTableFontFamily;
  103. this.fontSizeComboBox.SelectedItem = PeriodicTableStyle.PeriodicTableFontSize;
  104. this.fontStyleComboBox.DataSource = new[]
  105. {
  106. FontStyles.Normal,
  107. FontStyles.Italic,
  108. FontStyles.Oblique
  109. };
  110. this.fontSizeComboBox.DataSource = new[] { 8d, 10d, 12d, 14d, 16d };
  111. }
  112. /// <summary>
  113. /// Updates the combos selected items on load and after resetting styles
  114. /// </summary>
  115. private void UpdateCombos()
  116. {
  117. ColorConverter.PickColourComboItem(this.backgroundColorComboBox, BackgroundColor);
  118. ColorConverter.PickColourComboItem(this.includedElementColorComboBox, IncludedElementColor);
  119. ColorConverter.PickColourComboItem(this.excludedElementsColorComboBox, ExcludedElementColor);
  120. ColorConverter.PickColourComboItem(this.idleElementColorComboBox, IdleElementColor);
  121. ColorConverter.PickColourComboItem(this.elementBorderColorComboBox, ElementBorderColor);
  122. ColorConverter.PickColourComboItem(this.elementHighlightColorComboBox, ElementHighlightColor);
  123. this.fontFamilyComboBox.SelectedItem = PeriodicTableStyle.PeriodicTableFontFamily;
  124. this.fontStyleComboBox.SelectedItem = PeriodicTableStyle.PeriodicTableFontStyle;
  125. this.fontSizeComboBox.SelectedItem = PeriodicTableStyle.PeriodicTableFontSize;
  126. ColorConverter.PickColourComboItem(this.elementFontColorComboBox, ElementFontColor);
  127. }
  128. /// <summary>
  129. /// Updates the panel colors.
  130. /// </summary>
  131. private void UpdatePanelColors()
  132. {
  133. this.backgroundColorPanel.BackColor = BackgroundColor;
  134. this.includedElementsColorPanel.BackColor = IncludedElementColor;
  135. this.excludedElementsColorPanel.BackColor = ExcludedElementColor;
  136. this.unsetElementsColorPanel.BackColor = IdleElementColor;
  137. this.elementHighlightColorPanel.BackColor = ElementHighlightColor;
  138. this.elementBorderColorPanel.BackColor = ElementBorderColor;
  139. this.fontColorPanel.BackColor = ElementFontColor;
  140. }
  141. /// <summary>
  142. /// Handles the SelectedValueChanged event of the IncludedElementColorComboBox control.
  143. /// </summary>
  144. /// <param name="sender">The source of the event.</param>
  145. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  146. private void BackgroundColorComboBox_SelectedValueChanged(object sender, EventArgs e)
  147. {
  148. if (this.backgroundColorComboBox.SelectedValue != null)
  149. {
  150. BackgroundColor = (Color)this.backgroundColorComboBox.SelectedValue;
  151. this.UpdatePanelColors();
  152. }
  153. }
  154. /// <summary>
  155. /// Handles the SelectedValueChanged event of the IncludedElementColorComboBox control.
  156. /// </summary>
  157. /// <param name="sender">The source of the event.</param>
  158. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  159. private void IncludedElementColorComboBox_SelectedValueChanged(object sender, EventArgs e)
  160. {
  161. if (this.includedElementColorComboBox.SelectedValue != null)
  162. {
  163. IncludedElementColor = (Color)this.includedElementColorComboBox.SelectedValue;
  164. this.UpdatePanelColors();
  165. }
  166. }
  167. /// <summary>
  168. /// Handles the SelectedValueChanged event of the ExcludedElementsColorComboBox control.
  169. /// </summary>
  170. /// <param name="sender">The source of the event.</param>
  171. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  172. private void ExcludedElementsColorComboBox_SelectedValueChanged(object sender, EventArgs e)
  173. {
  174. if (this.excludedElementsColorComboBox.SelectedValue != null)
  175. {
  176. ExcludedElementColor = (Color)this.excludedElementsColorComboBox.SelectedValue;
  177. this.UpdatePanelColors();
  178. }
  179. }
  180. /// <summary>
  181. /// Handles the SelectedValueChanged event of the UnsetElementColorComboBox control.
  182. /// </summary>
  183. /// <param name="sender">The source of the event.</param>
  184. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  185. private void UnsetElementColorComboBox_SelectedValueChanged(object sender, EventArgs e)
  186. {
  187. if (this.idleElementColorComboBox.SelectedValue != null)
  188. {
  189. IdleElementColor = (Color)this.idleElementColorComboBox.SelectedValue;
  190. this.UpdatePanelColors();
  191. }
  192. }
  193. /// <summary>
  194. /// Handles the SelectedValueChanged event of the ElementHighlightColorComboBox control.
  195. /// </summary>
  196. /// <param name="sender">The source of the event.</param>
  197. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  198. private void ElementHighlightColorComboBox_SelectedValueChanged(object sender, EventArgs e)
  199. {
  200. if (this.elementHighlightColorComboBox.SelectedValue != null)
  201. {
  202. ElementHighlightColor = (Color)this.elementHighlightColorComboBox.SelectedValue;
  203. this.UpdatePanelColors();
  204. }
  205. }
  206. /// <summary>
  207. /// Handles the SelectedValueChanged event of the ElementBorderColorComboBox control.
  208. /// </summary>
  209. /// <param name="sender">The source of the event.</param>
  210. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  211. private void ElementBorderColorComboBox_SelectedValueChanged(object sender, EventArgs e)
  212. {
  213. if (this.elementBorderColorComboBox.SelectedValue != null)
  214. {
  215. ElementBorderColor = (Color)this.elementBorderColorComboBox.SelectedValue;
  216. this.UpdatePanelColors();
  217. }
  218. }
  219. /// <summary>
  220. /// Handles the SelectedIndexChanged event of the ElementFontColorComboBox control.
  221. /// </summary>
  222. /// <param name="sender">The source of the event.</param>
  223. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  224. private void ElementFontColorComboBox_SelectedIndexChanged(object sender, EventArgs e)
  225. {
  226. if (this.elementFontColorComboBox.SelectedValue != null)
  227. {
  228. ElementFontColor = (Color)this.elementFontColorComboBox.SelectedValue;
  229. this.UpdatePanelColors();
  230. }
  231. }
  232. /// <summary>
  233. /// Handles the SelectedValueChanged event of the FontFamilyComboBox control.
  234. /// </summary>
  235. /// <param name="sender">The source of the event.</param>
  236. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  237. private void FontFamilyComboBox_SelectedValueChanged(object sender, EventArgs e)
  238. {
  239. if (this.fontFamilyComboBox.SelectedValue != null)
  240. {
  241. PeriodicTableStyle.PeriodicTableFontFamily = this.fontFamilyComboBox.SelectedValue as System.Windows.Media.FontFamily;
  242. }
  243. }
  244. /// <summary>
  245. /// Handles the SelectedValueChanged event of the FontStyleComboBox control.
  246. /// </summary>
  247. /// <param name="sender">The source of the event.</param>
  248. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  249. private void FontStyleComboBox_SelectedValueChanged(object sender, EventArgs e)
  250. {
  251. if (this.fontStyleComboBox.SelectedValue != null)
  252. {
  253. PeriodicTableStyle.PeriodicTableFontStyle = (System.Windows.FontStyle)this.fontStyleComboBox.SelectedValue;
  254. }
  255. }
  256. /// <summary>
  257. /// Handles the SelectedValueChanged event of the FontSizeComboBox control.
  258. /// </summary>
  259. /// <param name="sender">The source of the event.</param>
  260. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  261. private void FontSizeComboBox_SelectedValueChanged(object sender, EventArgs e)
  262. {
  263. if (this.fontSizeComboBox.SelectedValue != null)
  264. {
  265. PeriodicTableStyle.PeriodicTableFontSize = (double)this.fontSizeComboBox.SelectedValue;
  266. }
  267. }
  268. /// <summary>
  269. /// Handles the Click event of the ResetStyleButton control.
  270. /// </summary>
  271. /// <param name="sender">The source of the event.</param>
  272. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  273. private void ResetStyleButton_Click(object sender, EventArgs e)
  274. {
  275. PeriodicTableStyle.ResetStyles();
  276. this.UpdatePanelColors();
  277. this.UpdateCombos();
  278. }
  279. }
  280. }