//----------------------------------------------------------------------- // // Copyright © 2012 Nils Hammar. All rights reserved. // //----------------------------------------------------------------------- /* * Software to access vehicle information via the OBD-II connector. * * Copyright © 2012 Nils Hammar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Alternative licensing is possible, see the licensing document. * * The above text may not be removed or modified. */ namespace Gauges { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using global::SharedObjects.DataMgmt; using global::SharedObjects.Misc; /// /// Select which gauge to use. /// public partial class TelltaleIconSelector : Form { /// /// Gets selected telltale icon. /// public string selectedIcon { get; private set; } /// /// Current telltale icon. /// private string currentIcon; /// /// Data source interface instance. /// private IDataSource iDataSource; /// /// Image list instance. /// private ImageList imageList; /// /// Initializes a new instance of the class. /// /// Data file directory path. /// Data source interface instance. /// Current telltale icon. public TelltaleIconSelector( string dataFileDir, IDataSource iDataSource, string currentIcon) { this.iDataSource = iDataSource; this.selectedIcon = currentIcon; this.currentIcon = currentIcon; this.InitializeComponent(); int imgSize = 64; this.imageList = new ImageList(); this.imageList.ImageSize = new Size(imgSize, imgSize); this.listView1.LargeImageList = this.imageList; this.listView1.MultiSelect = false; ListViewItem selectedItem = null; foreach (XmlClass.icon icon in this.iDataSource.icons) { if (!icon.key.StartsWith("_")) { Image img = Image.FromFile(dataFileDir + "Icons\\" + icon.file); Bitmap bmp = Utils.getScaledImage2(img, imgSize, imgSize, 1); this.imageList.Images.Add(icon.key, bmp); ListViewItem item = new ListViewItem(icon.file, icon.key); if (!string.IsNullOrEmpty(currentIcon) && currentIcon.Equals(icon.file)) { selectedItem = item; } this.listView1.Items.Add(item); } } if (selectedItem != null) { selectedItem.Selected = true; } this.listView1.Focus(); } /// /// Handle OK button click. /// /// Sending object. /// Event data. private void okButton_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; } /// /// Handle Cancel button click. /// /// Sending object. /// Event data. private void cancelButton_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } /// /// Telltale icon selection changed. /// /// Sending object. /// Event data. private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0) { ListViewItem item = this.listView1.SelectedItems[0]; this.selectedIcon = item.Text; } else { this.selectedIcon = this.currentIcon; } this.textBox1.Text = this.selectedIcon; this.okButton.Enabled = !string.IsNullOrEmpty(this.selectedIcon); } } }