Salam all, salam brother Mohsen,

Please convert the following short source code from C# to Java to support 
Direct Verse Entry
not only in CC:VV (Chapter:Verse) format but all of the following formats:

CC, CC:VV, CC-CC, CC:VV-CC, CC-CC:VV, CC:VV-CC:VV
11, 13-14, 15:55, 16:19-23, 13-14:19, 24:35-27:62

Users can enter comms between terms to get more than one range in one go.

Salam

God bless you dear brother and your team,

Ali
http://heliwave.com


C# code taken from QuranCode 
----------------------------
private void ChapterComboBox_KeyDown(object sender, KeyEventArgs e)
{
    bool SeparatorKeys = (
        ((e.KeyCode == Keys.Subtract) && (e.Modifiers != Keys.Shift))           
// HYPHEN
        || ((e.KeyCode == Keys.OemMinus) && (e.Modifiers != Keys.Shift))        
// HYPHEN
        || ((e.KeyCode == Keys.Oemcomma) && (e.Modifiers != Keys.Shift))        
// COMMA
        || ((e.KeyCode == Keys.OemSemicolon) && (e.Modifiers == Keys.Shift))    
// COLON
        );

    bool NumericKeys = (
        ((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) || (e.KeyCode >= 
Keys.NumPad0 && e.KeyCode <= Keys.NumPad9))
        && e.Modifiers != Keys.Shift);

    bool EditKeys = (
        (e.KeyCode == Keys.A && e.Modifiers == Keys.Control) ||
        (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control) ||
        (e.KeyCode == Keys.X && e.Modifiers == Keys.Control) ||
        (e.KeyCode == Keys.C && e.Modifiers == Keys.Control) ||
        (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) ||
        e.KeyCode == Keys.Delete ||
        e.KeyCode == Keys.Back);

    bool NavigationKeys = (
        e.KeyCode == Keys.Up ||
        e.KeyCode == Keys.Right ||
        e.KeyCode == Keys.Down ||
        e.KeyCode == Keys.Left ||
        e.KeyCode == Keys.Home ||
        e.KeyCode == Keys.End);

    bool ExecuteKeys = (e.KeyCode == Keys.Enter);

    if (ExecuteKeys)
    {
        if (m_client != null)
        {
            try
            {
                string text = ChapterComboBox.Text;
                if (text.Length > 0)
                {
                    // 1, 3-4, 5:55, 3-4:19, 6:19-23, 24:35-27:62
                    SelectionScope scope = SelectionScope.Verse;
                    List<int> indexes = new List<int>();

                    foreach (string part in text.Split(','))
                    {
                        string[] range_parts = part.Split('-');
                        if (range_parts.Length == 1) // 1 | 5:55
                        {
                            string[] sub_range_parts = part.Split(':');
                            if (sub_range_parts.Length == 1) // 1
                            {
                                int chapter_number;
                                if (int.TryParse(sub_range_parts[0], out 
chapter_number))
                                {
                                    foreach (Verse verse in 
m_client.Book.Chapters[chapter_number - 1].Verses)
                                    {
                                        indexes.Add(verse.Number - 1);
                                    }
                                }
                            }
                            else if (sub_range_parts.Length == 2) // 5:55
                            {
                                int chapter_number;
                                if (int.TryParse(sub_range_parts[0], out 
chapter_number)) // 5:55
                                {
                                    int verse_number_in_chapter;
                                    if (int.TryParse(sub_range_parts[1], out 
verse_number_in_chapter))
                                    {
                                        int from_verse_index = 
m_client.Book.Chapters[chapter_number - 1].Verses[verse_number_in_chapter - 
1].Number - 1;
                                        indexes.Add(from_verse_index);
                                    }
                                }
                            }
                        }
                        else if (range_parts.Length == 2) // 3-4, 3-4:19, 
6:19-23, 24:35-27:62
                        {
                            int from_chapter_number;
                            int to_chapter_number;
                            if (int.TryParse(range_parts[0], out 
from_chapter_number)) // 3-4
                            {
                                if (int.TryParse(range_parts[1], out 
to_chapter_number))
                                {
                                    if (from_chapter_number <= 
to_chapter_number)
                                    {
                                        for (int i = from_chapter_number; i <= 
to_chapter_number; i++)
                                        {
                                            foreach (Verse verse in 
m_client.Book.Chapters[i - 1].Verses)
                                            {
                                                indexes.Add(verse.Number - 1);
                                            }
                                        }
                                    }
                                }
                                else // 3-4:19
                                {
                                    // range_parts[0] == 3
                                    // range_parts[1] == 4:19
                                    string[] to_range_parts = 
range_parts[1].Split(':'); // 4:19
                                    if (to_range_parts.Length == 2)
                                    {
                                        int from_verse_number_in_chapter = 1; 
// not specified so start from beginning of chapter

                                        if (int.TryParse(to_range_parts[0], out 
to_chapter_number))  // 4
                                        {
                                            int to_verse_number_in_chapter;
                                            if (int.TryParse(to_range_parts[1], 
out to_verse_number_in_chapter)) // 19
                                            {
                                                int from_verse_index = 
m_client.Book.Chapters[from_chapter_number - 
1].Verses[from_verse_number_in_chapter - 1].Number - 1;
                                                int to_verse_index = 
m_client.Book.Chapters[to_chapter_number - 1].Verses[to_verse_number_in_chapter 
- 1].Number - 1;
                                                for (int i = from_verse_index; 
i <= to_verse_index; i++)
                                                {
                                                    indexes.Add(i);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else // "range_parts[0]" contains a colon ':'  // 
"6:19"-23, "24:35"-27:62
                            {
                                //int from_chapter_number;
                                //int to_chapter_number;
                                string[] from_parts = range_parts[0].Split(':');
                                if (from_parts.Length == 2)
                                {
                                    int from_verse_number_in_chapter;
                                    if (int.TryParse(from_parts[0], out 
from_chapter_number))
                                    {
                                        if (int.TryParse(from_parts[1], out 
from_verse_number_in_chapter))
                                        {
                                            string[] to_parts = 
range_parts[1].Split(':'); // "range_parts[1]" may or may not contain a colon 
':'  // 6:19-"23", 24:35-"27:62"
                                            if (to_parts.Length == 1) // 
6:19-"23"
                                            {
                                                int to_verse_number_in_chapter;
                                                if (int.TryParse(to_parts[0], 
out to_verse_number_in_chapter))
                                                {
                                                    if 
(from_verse_number_in_chapter <= to_verse_number_in_chapter)  // XX:19-23
                                                    {
                                                        int from_verse_index = 
m_client.Book.Chapters[from_chapter_number - 
1].Verses[from_verse_number_in_chapter - 1].Number - 1;
                                                        int to_verse_index = 
m_client.Book.Chapters[from_chapter_number - 
1].Verses[to_verse_number_in_chapter - 1].Number - 1;
                                                        for (int i = 
from_verse_index; i <= to_verse_index; i++)
                                                        {
                                                            indexes.Add(i);
                                                        }
                                                    }
                                                }
                                            }
                                            else if (to_parts.Length == 2) // 
24:35-"27:62"
                                            {
                                                int to_verse_number_in_chapter;
                                                if (int.TryParse(to_parts[0], 
out to_chapter_number))
                                                {
                                                    if 
(int.TryParse(to_parts[1], out to_verse_number_in_chapter))
                                                    {
                                                        if (from_chapter_number 
<= to_chapter_number)  // 24:XX-27:XX // only worry about chapters
                                                        {
                                                            int 
from_verse_index = m_client.Book.Chapters[from_chapter_number - 
1].Verses[from_verse_number_in_chapter - 1].Number - 1;
                                                            int to_verse_index 
= m_client.Book.Chapters[to_chapter_number - 
1].Verses[to_verse_number_in_chapter - 1].Number - 1;
                                                            for (int i = 
from_verse_index; i <= to_verse_index; i++)
                                                            {
                                                                indexes.Add(i);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    m_client.Selection = new Selection(m_client.Book, scope, 
indexes);
                    DisplaySelection(null, true);
                }
            }
            catch /*(Exception ex)*/
            {
                // silence exception
            }
        }
    }

    // reject all other keys
    if (!(SeparatorKeys || NumericKeys || EditKeys || NavigationKeys))
    {
        e.SuppressKeyPress = true;
        e.Handled = true;
    }
}
----------------------------

God > infinity


----- Original Message -----
From: "Tafsirul Alam" <explore.m...@gmail.com>
To: zekr@googlegroups.com
Sent: Sunday, December 9, 2012 10:32:09 PM
Subject: Re: [zekr] Re: Zekr 1.1.0 Final is Ready

AsSalamu Alaikum, 
I'm having problem while searching surahs and ayah numbers, I put the surah 
number and ayah number, but Zekr doesn't jump to that surah and ayah. Please 
help. 


-- 
You received this message because you are subscribed to the Google Groups 
"zekr" group. 
To post to this group, send email to zekr@googlegroups.com. 
To unsubscribe from this group, send email to 
zekr+unsubscr...@googlegroups.com. 
To view this discussion on the web visit 
https://groups.google.com/d/msg/zekr/-/3l00SNk46_gJ . 
For more options, visit https://groups.google.com/groups/opt_out . 



-- 
You received this message because you are subscribed to the Google Groups 
"zekr" group.
To post to this group, send email to zekr@googlegroups.com.
To unsubscribe from this group, send email to zekr+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to