void cbInputSymbol_SelectionChanged(object sender, SelectionChangedEventArgs e) { isEditedHandler(sender, e); pdaRow currentRow = getRowByIndex((int)((StackPanel)((ComboBox)sender).Parent).Tag); if (currentRow.txtCurrentState.Text == "" || currentRow.cbInputSymbol.SelectedIndex == -1 || currentRow.cbStackTop.SelectedIndex == -1) { return; } foreach (StackPanel sp in ((StackPanel)canvasMain.Children[0]).Children) { pdaRow row = getRowByIndex((int)sp.Tag); if (currentRow == row) { continue; } if (row.txtCurrentState.Text == "" || row.cbInputSymbol.SelectedIndex == -1 || row.cbStackTop.SelectedIndex == -1) { continue; } if (currentRow.txtCurrentState.Text == row.txtCurrentState.Text && currentRow.cbInputSymbol.SelectedItem.ToString() == row.cbInputSymbol.SelectedItem.ToString() && currentRow.cbStackTop.SelectedItem.ToString() == row.cbStackTop.SelectedItem.ToString()) { MessageBox.Show("In Dpda, you cannot add more than one transitions on same input symbols"); currentRow.cbInputSymbol.SelectedIndex = -1; return; } } }
public void deleteSelectedRow() { if ((TextBox)selectedRow.sp.Children[(int)rowItems.currentState] == initialState) { initialState = null; } if ((TextBox)selectedRow.sp.Children[(int)rowItems.NextState] == finalState) { finalState = null; } StackPanel sp = (StackPanel)canvasMain.Children[0]; int i = sp.Children.IndexOf(selectedRow.sp); sp.Children.Remove(selectedRow.sp); this.rows.Remove(selectedRow); if (i < sp.Children.Count) { Label lbl = (Label)((StackPanel)sp.Children[i]).Children[(int)rowItems.lblArrow]; mutexSelectRow(lbl, null); } else { selectedRow = null; } }
public override pdaRow addNewRow() { if (canvasMain.Children.Count == 0) { StackPanel s = new StackPanel(); s.SetValue(Canvas.LeftProperty, (double)20); s.SetValue(Canvas.TopProperty, (double)20); canvasMain.Children.Add(s); } StackPanel sp = ((StackPanel)canvasMain.Children[0]); if (sp.Children.Count == MAX - 1) { MessageBox.Show("You can not add more than " + MAX.ToString() + " rows"); return(null); } if (sp.ActualHeight > canvasMain.ActualHeight) { canvasMain.Height = canvasMain.ActualHeight + 50; } pdaRow row = new pdaRow(); row.txtCurrentState.GotFocus += new RoutedEventHandler(txtCurrentState_GotFocus); row.txtCurrentState.LostFocus += new RoutedEventHandler(txtCurrentState_LostFocus); row.txtCurrentState.KeyUp += new KeyEventHandler(keyUpEventHandled); row.txtCurrentState.TextChanged += new TextChangedEventHandler(txtCurrentState_TextChanged); row.cbInputSymbol.ItemsSource = inputs; row.cbInputSymbol.SelectionChanged += new SelectionChangedEventHandler(cbInputSymbol_SelectionChanged); row.cbInputSymbol.KeyUp += new KeyEventHandler(keyUpEventHandled); row.cbStackTop.ItemsSource = stackSymbols; row.cbStackTop.SelectionChanged += new SelectionChangedEventHandler(cbStackTop_SelectionChanged); row.cbStackTop.KeyUp += new KeyEventHandler(keyUpEventHandled); row.lbl.MouseLeftButtonDown += new MouseButtonEventHandler(mutexSelectRow); row.lbl.MouseLeftButtonUp += new MouseButtonEventHandler(lbl_MouseLeftButtonUp);//to supress canvas's event only row.txtNextState.GotFocus += new RoutedEventHandler(txtNextState_GotFocus); row.txtNextState.LostFocus += new RoutedEventHandler(txtNextState_LostFocus); row.txtNextState.KeyDown += new KeyEventHandler(tb2_KeyDown); row.txtNextState.KeyUp += new KeyEventHandler(keyUpEventHandled); row.txtNextState.TextChanged += new TextChangedEventHandler(txtNextState_TextChanged); row.cbAction.KeyUp += new KeyEventHandler(keyUpEventHandled); row.cbAction.SelectionChanged += isEditedHandler; rows.Add(row); sp.Children.Add(row.sp); return(row); }
public void txtNextState_GotFocus(object sender, RoutedEventArgs e) { pdaRow temp = getRowByIndex((int)((StackPanel)((TextBox)sender).Parent).Tag); if (temp != selectedRow) { mutexSelectRow(temp.lbl, null); } //else the row is already selected, do not unselect it.... setFinalStateButton.IsEnabled = true; bool k = setFinalStateButton.IsEnabled; if (finalState == (TextBox)sender) { setFinalStateButton.IsChecked = true; } else { setFinalStateButton.IsChecked = false; } }
public void mutexSelectRow(object sender, MouseButtonEventArgs e) { if (e != null) //null when the function is called in the code { e.Handled = true; // written here bcoz we have returns before last statement } Label lbl = (Label)sender; if (selectedRow != null) // if a produciton is already selected { selectedRow.sp.Background = Brushes.White; if (selectedRow.sp == (StackPanel)lbl.Parent) // if selected production is clicked again { selectedRow = null; deleteRowButton.IsEnabled = false; return; } } selectedRow = getRowByIndex((int)((StackPanel)lbl.Parent).Tag); selectedRow.sp.Background = Brushes.LightBlue; deleteRowButton.IsEnabled = true; }
public virtual void loadFromFile(XDocument doc) //override it { string[] i = doc.Root.Attribute("inputs").Value.Split(';'); canvasMain.Height = Convert.ToDouble(doc.Root.Attribute("height").Value); canvasMain.Width = Convert.ToDouble(doc.Root.Attribute("width").Value); foreach (string s in i) { this.inputs.Add(s); } this.stackSymbols = this.inputs.ToList(); if (!this.inputs.Contains("^")) { this.stackSymbols.Add("^");//stack's last symbol (empty stack) } var query = from row in doc.Root.Element("Rows").Elements("Row") select row; foreach (XElement s in query) { pdaRow r = this.addNewRow(); r.txtCurrentState.Text = s.Attribute("currentState").Value; if (s.Attribute("isInitial") != null) { if (s.Attribute("isInitial").Value == "True") { r.txtCurrentState.Background = Brushes.LightGreen; initialState = r.txtCurrentState; } } if (s.Attribute("inputSymbol") != null) { r.cbInputSymbol.SelectedItem = s.Attribute("inputSymbol").Value; } if (s.Attribute("stackTopSymbol") != null) { r.cbStackTop.SelectedItem = s.Attribute("stackTopSymbol").Value; } if (s.Attribute("action") != null) { r.cbAction.SelectedItem = s.Attribute("action").Value; } r.txtNextState.Text = s.Attribute("nextState").Value; if (s.Attribute("isFinal") != null) { if (s.Attribute("isFinal").Value == "True") { r.txtNextState.Background = Brushes.LightPink; finalState = r.txtNextState; } } } }