/// <summary> /// Output 3 integer values to validate avaliable index in the tree /// item 1: Avaliable leaf index for button mapping /// Item 2: Avaliable trunk and leaf row for button placement /// Item 3: Avaliable trunk and leaf column for button placement /// </summary> private static Tuple <int, int, int> TreeIndex(treeParts part) { // Store index that is currently avaliable, starting from 1. int index = 1; // Iterate through every row in the two dimensional _treeIndices array. for (int row = 0; row < 14; row++) { // Iterate through every column in the two dimensional _treeIndices array. for (int column = 0; column < 7; column++) { // Increment index for every position in the array that is in use, excluding those in the tree trunk column. if (_treeIndices[row, column].Equals((int)treeParts.used) && column != 3) { index++; } // Avaliable index found. if (_treeIndices[row, column].Equals((int)part)) { // Set index to in use. _treeIndices[row, column] = (int)treeParts.used; // Output the data. return(Tuple.Create(index, row, column)); } } } return(null); }
/// <summary> /// One time timer to execute timed events. /// </summary> private void StartTimer(treeParts part, int interval, CustomizedButton cb) { _timer = new Timer(); _timer.Interval = interval += 100; _timer.AutoReset = false; if (part.Equals(treeParts.leaf)) { _timer.Elapsed += (sender, e) => timer_Reassign_Leaf_Tick(sender, e, cb); } else { _timer.Elapsed += timer_Create_Trunk_Tick; } _timer.Start(); }
/// <summary> /// Creates a specified part of the tree. /// </summary> void CreateTreePart(treeParts part) { // Store data of avaliable tree index. Tuple <int, int, int> treeIndex = TreeIndex(part); // When treeIndex returns nothing or sorting hasn't finished, terminate here. if (treeIndex == null || _finishedSorting == false) { return; } // Create Button. Button button = new Button(); button.Width = 50; button.Height = 25; // Add button to the grid. grid.Children.Add(button); switch (part) { case treeParts.leaf: // Customize Button CustomizedButton cb = new CustomizedButton(button, _client.Sentiment(null, TextBox.Text)); cb.MainWindow = this; cb.UpdateProperties(treeIndex.Item1, treeIndex.Item2, treeIndex.Item3); // Register button for reference. RegisterName(button.Name, button); // Add Button to SortedTupleCollection bag for later manipulation. _bag.Add(cb.SentimentValue, cb); // Update sentiment percentages. UpdateStatistics(cb.SentimentValue, cb.Sentiment.Polarity, false); break; case treeParts.trunk: button.SetValue(Grid.RowProperty, treeIndex.Item2); button.SetValue(Grid.ColumnProperty, treeIndex.Item3); button.Background = Brushes.SandyBrown; break; } }