Exemplo n.º 1
0
        /// Takes the compressed text and the existing Huffman Tree and 
        /// parses the text through the tree to decode the message back into
        /// it's original format.
        private void BtnDecompressClick(object sender, RoutedEventArgs e)
        {
            if (txtCompressed.Text.Count() == 0)
            {
                MessageBox.Show("Cannot decompress text that doesn't exist!"
                                + "\nPlease compress text before decompressing");
            }
            else if (encodeDict.Count() == 0)
            {
                MessageBox.Show("No frequency table/Huffman tree provided\nPlease "
                                + "generate one by compressing some text before"
                                + " decompressing");
            }
            else
            {
                HuffmanDecoder hd = new HuffmanDecoder();
                txtPlain.Text = hd.Decode(txtCompressed.Text.ToCharArray(),
                                                    huffmanTree);

                FreqListGenerator flg = new FreqListGenerator();
                txtFreqTbl.Text = flg.CreateFreqTable(txtPlain.Text.ToCharArray());
                nodeList = flg.GetFreqList();
                txtCompressed.Text = "";
            }
        }
Exemplo n.º 2
0
 /// Takes an input string and calculates the frequency of the
 /// characters in the text. It generates a list of Nodes
 /// for each unique character symbol. This is used in 
 /// compression and decompression, and the list is stored
 /// for later.
 private void BtnFreqClick(object sender, RoutedEventArgs e)
 {
     FreqListGenerator flg = new FreqListGenerator();
     String freqTable = flg.CreateFreqTable(txtPlain.Text.ToCharArray());
     nodeList = flg.GetFreqList();
     if (freqTable.Count() == 0)
     {
         MessageBox.Show("Cannot calculate frequency of a message that"
                         + " doesn't exist!\nPlease enter (1) or more "
                         + "alphanumeric characters");
     }
     else if (!flg.CharIsValid(freqTable[0])) /// Invalid character
     {
         MessageBox.Show("One or more characters is invalid. Please"
                         + " use characters 0-9,\na-z, A-Z, space and"
                         + " new line. Invalid characters : "
                         + freqTable);
     }
     else
     {
         txtFreqTbl.Text = freqTable;
     }
 }