Пример #1
0
 private void sceneLayoutStopped(object sender, EventArgs e)
 {
     this.layoutStartStopBTN.Text = "Start";
     if (this.bPendingGraphCreation)
     {
         IGraphCreator gc = this.graphCreatorCMB.SelectedItem as IGraphCreator;
         if (gc != null)
         {
             this.TurnOffShortPath();
             this.mScene.ClearGraph();
             if (this.graphStyleResetOnCreateCHK.Checked)
             {
                 this.nodeRadNUM.Value = (decimal)gc.DefaultNodeRad;
                 this.edgeAngNUM.Value = (decimal)gc.DefaultEdgeAng;
                 gc.CreateGraph(this.mScene,
                                gc.DefaultNodeRad, gc.DefaultEdgeAng);
             }
             else
             {
                 gc.CreateGraph(this.mScene,
                                (float)this.nodeRadNUM.Value,
                                (float)this.edgeAngNUM.Value);
             }
             this.RefreshShortPathAlgs();
             this.graphCreatorCMB.Enabled      = true;
             this.shortPathAlgCMB.Enabled      = true;
             this.shortPathDirectedCHK.Enabled = true;
             this.shortPathReversedCHK.Enabled = true;
         }
         this.bPendingGraphCreation = false;
     }
 }
Пример #2
0
        private void btnCompress_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                MessageBox.Show("Please enter Content");
                return;
            }

            _huffmannEncodedMap.Clear();
            var uniqueMap = _contentHandler.GetUniqueCharacterToFrequencyMapSortedByFreqInDescOrder(textBox1.Text);

            var result = _graphCreator.CreateGraph(uniqueMap);

            if (result)
            {
                var graph = _graphCreator.GetCreatedGraph();

                IGraphTraversal graphTraversal = new GraphTraversal();
                var             dictionary     = graphTraversal.GetHuffmannEncodingForCharacters(graph);

                foreach (var item in dictionary)
                {
                    _huffmannEncodedMap.Add(new DisplayData {
                        Key = item.Key.ToString(), Value = item.Value
                    });
                }
                listViewEncoding.DataContext = _huffmannEncodedMap;


                //get encoded bit data
                string message  = string.Empty;
                var    charList = textBox1.Text.ToCharArray().ToList();
                foreach (var item in charList)
                {
                    message += dictionary[item];
                }



                txbHuffmannCode.DataContext = new DisplayData {
                    Key = message
                };
            }
        }